Skip to content

Commit c6fab8d

Browse files
committed
Check for a DiagramWindow NULL pointer
Fixes the window title issues when showing a DiagramWindow and switching between perspectives.
1 parent 2a82201 commit c6fab8d

File tree

8 files changed

+98
-62
lines changed

8 files changed

+98
-62
lines changed

OMEdit/OMEdit/OMEditGUI/MainWindow.cpp

Lines changed: 71 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,36 @@ ThreeDViewer* MainWindow::getThreeDViewer()
423423
}
424424
#endif
425425

426+
/*!
427+
* \brief MainWindow::isModelingPerspectiveActive
428+
* Returns true if the Modeling perspective is active.
429+
* \return
430+
*/
431+
bool MainWindow::isModelingPerspectiveActive()
432+
{
433+
return mpPerspectiveTabbar->currentIndex() == 1;
434+
}
435+
436+
/*!
437+
* \brief MainWindow::isPlottingPerspectiveActive
438+
* Returns true if the Plotting perspective is active.
439+
* \return
440+
*/
441+
bool MainWindow::isPlottingPerspectiveActive()
442+
{
443+
return mpPerspectiveTabbar->currentIndex() == 2;
444+
}
445+
446+
/*!
447+
* \brief MainWindow::isDebuggingPerspectiveActive
448+
* Returns true if the Debugging perspective is active.
449+
* \return
450+
*/
451+
bool MainWindow::isDebuggingPerspectiveActive()
452+
{
453+
return mpPerspectiveTabbar->currentIndex() == 3;
454+
}
455+
426456
/*!
427457
* \brief MainWindow::addRecentFile
428458
* Adds the currently opened file to the recentFilesList settings.
@@ -648,7 +678,7 @@ void MainWindow::openResultFiles(QStringList fileNames)
648678
QFileInfo fileInfo(fileName);
649679
QStringList list = mpOMCProxy->readSimulationResultVars(fileInfo.absoluteFilePath());
650680
if (list.size() > 0) {
651-
mpPerspectiveTabbar->setCurrentIndex(2);
681+
switchToPlottingPerspectiveSlot();
652682
mpVariablesWidget->insertVariablesItemsToTree(fileInfo.fileName(), fileInfo.absoluteDir().absolutePath(), list, SimulationOptions());
653683
}
654684
}
@@ -1432,6 +1462,46 @@ void MainWindow::showMessagesBrowser()
14321462
}
14331463
}
14341464

1465+
/*!
1466+
* \brief MainWindow::switchToWelcomePerspectiveSlot
1467+
* Slot activated when Ctrl+f1 is clicked.
1468+
* Switches to welcome perspective.
1469+
*/
1470+
void MainWindow::switchToWelcomePerspectiveSlot()
1471+
{
1472+
mpPerspectiveTabbar->setCurrentIndex(0);
1473+
}
1474+
1475+
/*!
1476+
* \brief MainWindow::switchToModelingPerspectiveSlot
1477+
* Slot activated when Ctrl+f2 is clicked.
1478+
* Switches to modeling perspective.
1479+
*/
1480+
void MainWindow::switchToModelingPerspectiveSlot()
1481+
{
1482+
mpPerspectiveTabbar->setCurrentIndex(1);
1483+
}
1484+
1485+
/*!
1486+
* \brief MainWindow::switchToPlottingPerspectiveSlot
1487+
* Slot activated when Ctrl+f3 is clicked.
1488+
* Switches to plotting perspective.
1489+
*/
1490+
void MainWindow::switchToPlottingPerspectiveSlot()
1491+
{
1492+
mpPerspectiveTabbar->setCurrentIndex(2);
1493+
}
1494+
1495+
/*!
1496+
* \brief MainWindow::switchToAlgorithmicDebuggingPerspectiveSlot
1497+
* Slot activated when Ctrl+f5 is clicked.
1498+
* Switches to algorithmic debugging perspective.
1499+
*/
1500+
void MainWindow::switchToAlgorithmicDebuggingPerspectiveSlot()
1501+
{
1502+
mpPerspectiveTabbar->setCurrentIndex(3);
1503+
}
1504+
14351505
/*!
14361506
* \brief MainWindow::showSearchBrowser
14371507
* Shows the Search Browser, selects the search text if any and sets the focus on it.
@@ -2982,46 +3052,6 @@ void MainWindow::autoSave()
29823052
autoSaveHelper(mpLibraryWidget->getLibraryTreeModel()->getRootLibraryTreeItem());
29833053
}
29843054

2985-
/*!
2986-
* \brief MainWindow::switchToWelcomePerspectiveSlot
2987-
* Slot activated when Ctrl+f1 is clicked.
2988-
* Switches to welcome perspective.
2989-
*/
2990-
void MainWindow::switchToWelcomePerspectiveSlot()
2991-
{
2992-
mpPerspectiveTabbar->setCurrentIndex(0);
2993-
}
2994-
2995-
/*!
2996-
* \brief MainWindow::switchToModelingPerspectiveSlot
2997-
* Slot activated when Ctrl+f2 is clicked.
2998-
* Switches to modeling perspective.
2999-
*/
3000-
void MainWindow::switchToModelingPerspectiveSlot()
3001-
{
3002-
mpPerspectiveTabbar->setCurrentIndex(1);
3003-
}
3004-
3005-
/*!
3006-
* \brief MainWindow::switchToPlottingPerspectiveSlot
3007-
* Slot activated when Ctrl+f3 is clicked.
3008-
* Switches to plotting perspective.
3009-
*/
3010-
void MainWindow::switchToPlottingPerspectiveSlot()
3011-
{
3012-
mpPerspectiveTabbar->setCurrentIndex(2);
3013-
}
3014-
3015-
/*!
3016-
* \brief MainWindow::switchToAlgorithmicDebuggingPerspectiveSlot
3017-
* Slot activated when Ctrl+f5 is clicked.
3018-
* Switches to algorithmic debugging perspective.
3019-
*/
3020-
void MainWindow::switchToAlgorithmicDebuggingPerspectiveSlot()
3021-
{
3022-
mpPerspectiveTabbar->setCurrentIndex(3);
3023-
}
3024-
30253055
/*!
30263056
* \brief MainWindow::showDebugConfigurationsDialog
30273057
* Slot activated when mpDebugConfigurationsAction triggered signal is raised.\n

OMEdit/OMEdit/OMEditGUI/MainWindow.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ class MainWindow : public QMainWindow
139139
void showProgressBar() {mpProgressBar->setVisible(true);}
140140
void hideProgressBar() {mpProgressBar->setVisible(false);}
141141
Label* getPositionLabel() {return mpPositionLabel;}
142-
QTabBar* getPerspectiveTabBar() {return mpPerspectiveTabbar;}
142+
bool isModelingPerspectiveActive();
143+
bool isPlottingPerspectiveActive();
144+
bool isDebuggingPerspectiveActive();
143145
QTimer* getAutoSaveTimer() {return mpAutoSaveTimer;}
144146
QAction* getSaveAction() {return mpSaveAction;}
145147
QAction* getSaveAsAction() {return mpSaveAsAction;}
@@ -454,6 +456,10 @@ class MainWindow : public QMainWindow
454456
QHash<QString, TransformationsWidget*> mTransformationsWidgetHash;
455457
public slots:
456458
void showMessagesBrowser();
459+
void switchToWelcomePerspectiveSlot();
460+
void switchToModelingPerspectiveSlot();
461+
void switchToPlottingPerspectiveSlot();
462+
void switchToAlgorithmicDebuggingPerspectiveSlot();
457463
void showSearchBrowser();
458464
void createNewModelicaClass();
459465
void openModelicaFile();
@@ -540,10 +546,6 @@ private slots:
540546
void documentationDockWidgetVisibilityChanged(bool visible);
541547
void threeDViewerDockWidgetVisibilityChanged(bool visible);
542548
void autoSave();
543-
void switchToWelcomePerspectiveSlot();
544-
void switchToModelingPerspectiveSlot();
545-
void switchToPlottingPerspectiveSlot();
546-
void switchToAlgorithmicDebuggingPerspectiveSlot();
547549
void showDebugConfigurationsDialog();
548550
void showAttachToProcessDialog();
549551
void createGitRepository();

OMEdit/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,9 +1800,8 @@ void LibraryTreeModel::showModelWidget(LibraryTreeItem *pLibraryTreeItem, bool s
18001800
}
18011801
// only switch to modeling perspective if show is true and we are not in a plotting or debugging perspective.
18021802
if (show
1803-
&& MainWindow::instance()->getPerspectiveTabBar()->currentIndex() != 2
1804-
&& MainWindow::instance()->getPerspectiveTabBar()->currentIndex() != 3) {
1805-
MainWindow::instance()->getPerspectiveTabBar()->setCurrentIndex(1);
1803+
&& !MainWindow::instance()->isDebuggingPerspectiveActive()) {
1804+
MainWindow::instance()->switchToModelingPerspectiveSlot();
18061805
}
18071806
if (!pLibraryTreeItem->getModelWidget()) {
18081807
ModelWidget *pModelWidget = new ModelWidget(pLibraryTreeItem, MainWindow::instance()->getModelWidgetContainer());
@@ -3264,20 +3263,24 @@ void LibraryTreeView::libraryTreeItemDoubleClicked(const QModelIndex &index)
32643263
|| pLibraryTreeItem->getOMSTLMBusConnector())) {
32653264
return;
32663265
}
3266+
/* Check if we are in the plotting perspective
3267+
* If yes then we first load the model and switch to Modeling perspective like normal
3268+
* and then switches back to plotting perspective and show the DiagramWindow
3269+
* If we don't do that then the window title is messed up.
3270+
*/
3271+
bool isPlottingPerspectiveActive = MainWindow::instance()->isPlottingPerspectiveActive();
32673272
mpLibraryWidget->getLibraryTreeModel()->showModelWidget(pLibraryTreeItem);
32683273
// if we are in the plotting perspective then open the Diagram Window
3269-
if (MainWindow::instance()->getPerspectiveTabBar()->currentIndex() == 2) {
3274+
if (isPlottingPerspectiveActive) {
3275+
MainWindow::instance()->switchToPlottingPerspectiveSlot();
32703276
if (MainWindow::instance()->getPlotWindowContainer()->getDiagramSubWindowFromMdi()) {
32713277
if (pLibraryTreeItem->getModelWidget()) {
32723278
pLibraryTreeItem->getModelWidget()->loadDiagramView();
32733279
pLibraryTreeItem->getModelWidget()->loadConnections();
32743280
}
32753281
MainWindow::instance()->getPlotWindowContainer()->getDiagramWindow()->drawDiagram(pLibraryTreeItem->getModelWidget());
3276-
MainWindow::instance()->getPlotWindowContainer()->getDiagramWindow()->show();
3277-
MainWindow::instance()->getPlotWindowContainer()->setActiveSubWindow(MainWindow::instance()->getPlotWindowContainer()->getDiagramSubWindowFromMdi());
3278-
} else {
3279-
MainWindow::instance()->getPlotWindowContainer()->addDiagramWindow(pLibraryTreeItem->getModelWidget());
32803282
}
3283+
MainWindow::instance()->getPlotWindowContainer()->addDiagramWindow(pLibraryTreeItem->getModelWidget());
32813284
}
32823285
}
32833286
}

OMEdit/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6780,7 +6780,7 @@ void ModelWidgetContainer::addModelWidget(ModelWidget *pModelWidget, bool checkP
67806780
}
67816781
pModelWidget->createModelWidgetComponents();
67826782
pModelWidget->show();
6783-
if (subWindowsSize == 0 || MainWindow::instance()->getPerspectiveTabBar()->currentIndex() == 2) {
6783+
if (subWindowsSize == 0 || MainWindow::instance()->isPlottingPerspectiveActive()) {
67846784
pModelWidget->setWindowState(Qt::WindowMaximized);
67856785
}
67866786
setActiveSubWindow(pSubWindow);
@@ -7277,7 +7277,7 @@ void ModelWidgetContainer::currentModelWidgetChanged(QMdiSubWindow *pSubWindow)
72777277
/* ticket:5441 OMEdit toolbars
72787278
* Show the relevant toolbars if we are in a Modeling perspective
72797279
*/
7280-
if (MainWindow::instance()->getPerspectiveTabBar()->currentIndex() == 1) {
7280+
if (MainWindow::instance()->isModelingPerspectiveActive()) {
72817281
if (pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
72827282
MainWindow::instance()->getShapesToolBar()->setVisible(true);
72837283
MainWindow::instance()->getCheckToolBar()->setVisible(true);

OMEdit/OMEdit/OMEditGUI/OMS/OMSSimulationDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void OMSSimulationDialog::simulationFinished(OMSSimulationOptions omsSimulationO
120120
OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
121121
QStringList list = pOMCProxy->readSimulationResultVars(resultFileInfo.absoluteFilePath());
122122
if (list.size() > 0) {
123-
MainWindow::instance()->getPerspectiveTabBar()->setCurrentIndex(2);
123+
MainWindow::instance()->switchToPlottingPerspectiveSlot();
124124
pVariablesWidget->insertVariablesItemsToTree(resultFileInfo.fileName(), omsSimulationOptions.getWorkingDirectory(),
125125
list, SimulationOptions());
126126
MainWindow::instance()->getVariablesDockWidget()->show();

OMEdit/OMEdit/OMEditGUI/Plotting/VariablesWidget.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,8 @@ void VariablesWidget::updateVisualization()
21392139
double visTime = mpTimeManager->getRealTime();
21402140
// Update the DiagramWindow
21412141
emit updateDynamicSelect(mpTimeManager->getVisTime());
2142-
if (MainWindow::instance()->getPlotWindowContainer()->getDiagramWindow()) {
2142+
if (MainWindow::instance()->getPlotWindowContainer()->getDiagramWindow()
2143+
&& MainWindow::instance()->getPlotWindowContainer()->getDiagramWindow()->getGraphicsView()) {
21432144
MainWindow::instance()->getPlotWindowContainer()->getDiagramWindow()->getGraphicsView()->scene()->update();
21442145
}
21452146
mpTimeManager->updateTick(); //for real-time measurement

OMEdit/OMEdit/OMEditGUI/Simulation/SimulationDialog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ void SimulationDialog::showAlgorithmicDebugger(SimulationOptions simulationOptio
18291829
QString GDBPath = OptionsDialog::instance()->getDebuggerPage()->getGDBPath();
18301830
GDBAdapter::instance()->launch(fileName, simulationOptions.getWorkingDirectory(), simulationOptions.getSimulationFlags(),
18311831
GDBPath, simulationOptions);
1832-
MainWindow::instance()->getPerspectiveTabBar()->setCurrentIndex(3);
1832+
MainWindow::instance()->switchToAlgorithmicDebuggingPerspectiveSlot();
18331833
}
18341834
}
18351835
}
@@ -1985,7 +1985,7 @@ void SimulationDialog::createOpcUaClient(SimulationOptions simulationOptions)
19851985
}
19861986
}
19871987

1988-
MainWindow::instance()->getPerspectiveTabBar()->setCurrentIndex(2);
1988+
MainWindow::instance()->switchToPlottingPerspectiveSlot();
19891989
} else {
19901990
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, "Could not connect to the embedded server.",
19911991
Helper::scriptingKind, Helper::errorLevel));
@@ -2071,7 +2071,7 @@ void SimulationDialog::simulationProcessFinished(SimulationOptions simulationOpt
20712071
MainWindow::instance()->activateWindow();
20722072
MainWindow::instance()->setWindowState(MainWindow::instance()->windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
20732073
if (OptionsDialog::instance()->getSimulationPage()->getSwitchToPlottingPerspectiveCheckBox()->isChecked()) {
2074-
MainWindow::instance()->getPerspectiveTabBar()->setCurrentIndex(2);
2074+
MainWindow::instance()->switchToPlottingPerspectiveSlot();
20752075
} else {
20762076
// stay in current perspective and show variables browser
20772077
MainWindow::instance()->getVariablesDockWidget()->show();

OMEdit/OMEdit/OMEditGUI/TLM/TLMCoSimulationDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void TLMCoSimulationDialog::simulationProcessFinished(TLMCoSimulationOptions tlm
222222
}
223223
}
224224
#endif
225-
MainWindow::instance()->getPerspectiveTabBar()->setCurrentIndex(2);
225+
MainWindow::instance()->switchToPlottingPerspectiveSlot();
226226
pVariablesWidget->insertVariablesItemsToTree(resultFileInfo.fileName(), fileInfo.absoluteDir().absolutePath(), list, SimulationOptions());
227227
MainWindow::instance()->getVariablesDockWidget()->show();
228228
}

0 commit comments

Comments
 (0)