-----------------------------------------------------------------------------
| 23 | |
| 24 | //----------------------------------------------------------------------------- |
| 25 | pqPythonTabWidget::pqPythonTabWidget(QWidget* parent) |
| 26 | : QTabWidget(parent) |
| 27 | { |
| 28 | this->addNewTabWidget(); |
| 29 | this->createNewEmptyTab(); |
| 30 | this->setMovable(false); |
| 31 | |
| 32 | this->connect(this, &QTabWidget::tabCloseRequested, |
| 33 | [this](int index) |
| 34 | { |
| 35 | pqPythonTextArea* widget = this->getWidget<pqPythonTextArea>(index); |
| 36 | if (widget) |
| 37 | { |
| 38 | // First focus to the tab the user wants to delete |
| 39 | // and update the QTabBar |
| 40 | const int widgetId = this->indexOf(widget); |
| 41 | this->setCurrentIndex(widgetId); |
| 42 | this->repaint(); |
| 43 | |
| 44 | // We stop all display updates |
| 45 | // to avoid segfaults |
| 46 | this->setUpdatesEnabled(false); |
| 47 | if (this->count() == 2) |
| 48 | { |
| 49 | // Only delete the widget if it's not empty |
| 50 | if (widget->isEmpty()) |
| 51 | { |
| 52 | this->setUpdatesEnabled(true); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | this->createNewEmptyTab(); |
| 57 | } |
| 58 | |
| 59 | if (widget->saveOnClose()) |
| 60 | { |
| 61 | if (this->currentIndex() == index) |
| 62 | { |
| 63 | this->setCurrentIndex((index + 1) % (this->count() - 1)); |
| 64 | this->lastFocus = this->getWidget<pqPythonTextArea>(this->currentIndex()); |
| 65 | } |
| 66 | |
| 67 | this->removeTab(index); |
| 68 | widget->deleteLater(); |
| 69 | } |
| 70 | this->setUpdatesEnabled(true); |
| 71 | } |
| 72 | }); |
| 73 | } |
| 74 | |
| 75 | //----------------------------------------------------------------------------- |
| 76 | void pqPythonTabWidget::connectActions(pqPythonEditorActions& actions) |
nothing calls this directly
no test coverage detected