Skip to content

Commit db2f024

Browse files
committed
- Keep the sub windows state unchanged when switching between perspectives. - Added the cascade & tile windows options in `View->Windows` menu. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23414 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent c4afe24 commit db2f024

File tree

6 files changed

+101
-86
lines changed

6 files changed

+101
-86
lines changed

OMEdit/OMEditGUI/MainWindow.cpp

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, QWidget *parent)
151151
mpSimulationDialog = new SimulationDialog(this);
152152
// Create an object of PlotWindowContainer
153153
mpPlotWindowContainer = new PlotWindowContainer(this);
154+
mpPlotWindowContainer->addPlotWindow(true);
154155
// create an object of VariablesWidget
155156
mpVariablesWidget = new VariablesWidget(this);
156157
mpVariablesDockWidget->setWidget(mpVariablesWidget);
@@ -1300,6 +1301,40 @@ void MainWindow::showAlgorithmicDebugger()
13001301
mpDebuggerMainWindow->restoreWindows();
13011302
}
13021303

1304+
/*!
1305+
Slot activated when mpCascadeWindowsAction triggered signal is raised.\n
1306+
Arranges all child windows in a cascade pattern.
1307+
*/
1308+
void MainWindow::cascadeWindows()
1309+
{
1310+
switch (mpCentralStackedWidget->currentIndex()) {
1311+
case 1:
1312+
mpModelWidgetContainer->cascadeSubWindows();
1313+
break;
1314+
case 2:
1315+
mpPlotWindowContainer->cascadeSubWindows();
1316+
default:
1317+
break;
1318+
}
1319+
}
1320+
1321+
/*!
1322+
Slot activated when mpCascadeWindowsAction triggered signal is raised.\n
1323+
Arranges all child windows in a tile pattern.
1324+
*/
1325+
void MainWindow::tileWindows()
1326+
{
1327+
switch (mpCentralStackedWidget->currentIndex()) {
1328+
case 1:
1329+
mpModelWidgetContainer->tileSubWindows();
1330+
break;
1331+
case 2:
1332+
mpPlotWindowContainer->tileSubWindows();
1333+
default:
1334+
break;
1335+
}
1336+
}
1337+
13031338
void MainWindow::instantiatesModel()
13041339
{
13051340
ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget();
@@ -1732,7 +1767,7 @@ void MainWindow::openRecentModelWidget()
17321767
}
17331768

17341769
/*!
1735-
Slot activated when Re-simulateAction triggered signal is raised..\n
1770+
Slot activated when Re-simulateAction triggered signal is raised.\n
17361771
Re-simulates the model.
17371772
*/
17381773
void MainWindow::reSimulateModel()
@@ -2003,6 +2038,14 @@ void MainWindow::createActions()
20032038
mpShowAlgorithmicDebuggerAction->setShortcut(QKeySequence("ctrl+t"));
20042039
mpShowAlgorithmicDebuggerAction->setStatusTip(Helper::algorithmicDebugger);
20052040
connect(mpShowAlgorithmicDebuggerAction, SIGNAL(triggered()), SLOT(showAlgorithmicDebugger()));
2041+
// Cascade windows action
2042+
mpCascadeWindowsAction = new QAction(tr("Cascade Windows"), this);
2043+
mpCascadeWindowsAction->setStatusTip(tr("Arranges all the child windows in a cascade pattern"));
2044+
connect(mpCascadeWindowsAction, SIGNAL(triggered()), SLOT(cascadeWindows()));
2045+
// Tile windows action
2046+
mpTileWindowsAction = new QAction(tr("Tile Windows"), this);
2047+
mpTileWindowsAction->setStatusTip(tr("Arranges all child windows in a tile pattern"));
2048+
connect(mpTileWindowsAction, SIGNAL(triggered()), SLOT(tileWindows()));
20062049
// Simulation Menu
20072050
// instantiate model action
20082051
mpInstantiateModelAction = new QAction(QIcon(":/Resources/icons/flatmodel.svg"), tr("Instantiate Model"), this);
@@ -2271,7 +2314,6 @@ void MainWindow::createMenus()
22712314
pViewToolbarsMenu->addAction(mpSimulationToolBar->toggleViewAction());
22722315
pViewToolbarsMenu->addAction(mpPlotToolBar->toggleViewAction());
22732316
pViewToolbarsMenu->addAction(mpModelSwitcherToolBar->toggleViewAction());
2274-
pViewMenu->addAction(pViewToolbarsMenu->menuAction());
22752317
// Add Actions to Windows View Sub Menu
22762318
pViewWindowsMenu->addAction(pSearchClassAction);
22772319
pViewWindowsMenu->addAction(mpLibraryTreeDockWidget->toggleViewAction());
@@ -2280,6 +2322,10 @@ void MainWindow::createMenus()
22802322
pViewWindowsMenu->addAction(mpVariablesDockWidget->toggleViewAction());
22812323
pViewWindowsMenu->addAction(mpMessagesDockWidget->toggleViewAction());
22822324
pViewWindowsMenu->addAction(mpShowAlgorithmicDebuggerAction);
2325+
pViewWindowsMenu->addSeparator();
2326+
pViewWindowsMenu->addAction(mpCascadeWindowsAction);
2327+
pViewWindowsMenu->addAction(mpTileWindowsAction);
2328+
pViewMenu->addAction(pViewToolbarsMenu->menuAction());
22832329
pViewMenu->addAction(pViewWindowsMenu->menuAction());
22842330
pViewMenu->addSeparator();
22852331
pViewMenu->addAction(mpShowGridLinesAction);
@@ -2350,7 +2396,6 @@ void MainWindow::createMenus()
23502396

23512397
void MainWindow::switchToWelcomePerspective()
23522398
{
2353-
mpPlotWindowContainer->tileSubWindows();
23542399
mpCentralStackedWidget->setCurrentWidget(mpWelcomePageWidget);
23552400
mpModelWidgetContainer->currentModelWidgetChanged(0);
23562401
mpModelSwitcherToolButton->setEnabled(false);
@@ -2360,7 +2405,6 @@ void MainWindow::switchToWelcomePerspective()
23602405

23612406
void MainWindow::switchToModelingPerspective()
23622407
{
2363-
mpPlotWindowContainer->tileSubWindows();
23642408
mpCentralStackedWidget->setCurrentWidget(mpModelWidgetContainer);
23652409
mpModelWidgetContainer->currentModelWidgetChanged(mpModelWidgetContainer->getCurrentMdiSubWindow());
23662410
mpModelSwitcherToolButton->setEnabled(true);
@@ -2376,8 +2420,6 @@ void MainWindow::switchToPlottingPerspective()
23762420
// if not plotwindow is opened then open one for user
23772421
if (mpPlotWindowContainer->subWindowList().size() == 0) {
23782422
mpPlotWindowContainer->addPlotWindow();
2379-
} else {
2380-
mpPlotWindowContainer->getCurrentWindow()->setWindowState(Qt::WindowMaximized);
23812423
}
23822424
mpVariablesDockWidget->show();
23832425
mpPlotToolBar->setEnabled(true);

OMEdit/OMEditGUI/MainWindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ class MainWindow : public QMainWindow
230230
QAction *mpZoomInAction;
231231
QAction *mpZoomOutAction;
232232
QAction *mpShowAlgorithmicDebuggerAction;
233+
QAction *mpCascadeWindowsAction;
234+
QAction *mpTileWindowsAction;
233235
// Simulation Menu
234236
QAction *mpInstantiateModelAction;
235237
QAction *mpCheckModelAction;
@@ -308,6 +310,8 @@ public slots:
308310
void zoomIn();
309311
void zoomOut();
310312
void showAlgorithmicDebugger();
313+
void cascadeWindows();
314+
void tileWindows();
311315
void instantiatesModel();
312316
void checkModel();
313317
void checkAllModels();

OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,85 +2823,57 @@ ModelWidgetContainer::ModelWidgetContainer(MainWindow *pParent)
28232823

28242824
void ModelWidgetContainer::addModelWidget(ModelWidget *pModelWidget, bool checkPreferedView)
28252825
{
2826-
if (pModelWidget->isVisible() || pModelWidget->isMinimized())
2827-
{
2826+
if (pModelWidget->isVisible() || pModelWidget->isMinimized()) {
28282827
QList<QMdiSubWindow*> subWindowsList = subWindowList(QMdiArea::ActivationHistoryOrder);
2829-
for (int i = subWindowsList.size() - 1 ; i >= 0 ; i--)
2830-
{
2828+
for (int i = subWindowsList.size() - 1 ; i >= 0 ; i--) {
28312829
ModelWidget *pSubModelWidget = qobject_cast<ModelWidget*>(subWindowsList.at(i)->widget());
2832-
if (pSubModelWidget == pModelWidget)
2833-
{
2830+
if (pSubModelWidget == pModelWidget) {
28342831
pModelWidget->show();
2835-
pModelWidget->setWindowState(Qt::WindowMaximized);
28362832
setActiveSubWindow(subWindowsList.at(i));
28372833
}
28382834
}
2839-
}
2840-
else
2841-
{
2835+
} else {
2836+
static int firstSubWindow = 0;
28422837
QMdiSubWindow *pSubWindow = addSubWindow(pModelWidget);
28432838
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/modeling.png"));
2844-
//! @note remove the Stay on &Top Menu item from subwindows. They raise strange exceptions.
2845-
if (pSubWindow->systemMenu()->actions().size() > 6)
2846-
{
2847-
if (pSubWindow->systemMenu()->actions().at(5)->text().compare("Stay on &Top") == 0)
2848-
{
2849-
pSubWindow->systemMenu()->removeAction(pSubWindow->systemMenu()->actions().at(5));
2850-
}
2851-
}
28522839
pModelWidget->show();
2853-
pModelWidget->setWindowState(Qt::WindowMaximized);
2840+
if (!firstSubWindow) {
2841+
firstSubWindow = 1;
2842+
pModelWidget->setWindowState(Qt::WindowMaximized);
2843+
}
28542844
setActiveSubWindow(pSubWindow);
28552845
}
2856-
if (!checkPreferedView || pModelWidget->getLibraryTreeNode()->getLibraryType() != LibraryTreeNode::Modelica)
2846+
if (!checkPreferedView || pModelWidget->getLibraryTreeNode()->getLibraryType() != LibraryTreeNode::Modelica) {
28572847
return;
2848+
}
28582849
// get the preferred view to display
28592850
mpMainWindow->getOMCProxy()->sendCommand(QString("getNamedAnnotation(").append(pModelWidget->getLibraryTreeNode()->getNameStructure()).append(", preferredView)"));
28602851
QStringList preferredViewList = StringHandler::unparseStrings(mpMainWindow->getOMCProxy()->getResult());
2861-
if (!preferredViewList.isEmpty())
2862-
{
2852+
if (!preferredViewList.isEmpty()) {
28632853
QString preferredView = preferredViewList.at(0);
2864-
if (preferredView.compare("info") == 0)
2865-
{
2854+
if (preferredView.compare("info") == 0) {
28662855
pModelWidget->showDocumentationView();
28672856
loadPreviousViewType(pModelWidget);
2868-
}
2869-
else if (preferredView.compare("text") == 0)
2870-
{
2857+
} else if (preferredView.compare("text") == 0) {
28712858
pModelWidget->getTextViewToolButton()->setChecked(true);
2872-
}
2873-
else
2874-
{
2859+
} else {
28752860
pModelWidget->getDiagramViewToolButton()->setChecked(true);
28762861
}
2877-
}
2878-
else if (pModelWidget->getLibraryTreeNode()->isDocumentationClass())
2879-
{
2862+
} else if (pModelWidget->getLibraryTreeNode()->isDocumentationClass()) {
28802863
pModelWidget->showDocumentationView();
28812864
loadPreviousViewType(pModelWidget);
2882-
}
2883-
else if (pModelWidget->getModelWidgetContainer()->getPreviousViewType() != StringHandler::NoView)
2884-
{
2865+
} else if (pModelWidget->getModelWidgetContainer()->getPreviousViewType() != StringHandler::NoView) {
28852866
loadPreviousViewType(pModelWidget);
2886-
}
2887-
else
2888-
{
2867+
} else {
28892868
QString defaultView = mpMainWindow->getOptionsDialog()->getGeneralSettingsPage()->getDefaultView();
2890-
if (defaultView.compare(Helper::iconView) == 0)
2891-
{
2869+
if (defaultView.compare(Helper::iconView) == 0) {
28922870
pModelWidget->getIconViewToolButton()->setChecked(true);
2893-
}
2894-
else if (defaultView.compare(Helper::textView) == 0)
2895-
{
2871+
} else if (defaultView.compare(Helper::textView) == 0) {
28962872
pModelWidget->getTextViewToolButton()->setChecked(true);
2897-
}
2898-
else if (defaultView.compare(Helper::documentationView) == 0)
2899-
{
2873+
} else if (defaultView.compare(Helper::documentationView) == 0) {
29002874
pModelWidget->showDocumentationView();
29012875
loadPreviousViewType(pModelWidget);
2902-
}
2903-
else
2904-
{
2876+
} else {
29052877
pModelWidget->getDiagramViewToolButton()->setChecked(true);
29062878
}
29072879
}

OMEdit/OMEditGUI/Options/OptionsDialog.cpp

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,11 @@ void OptionsDialog::saveGeneralSettings()
397397
{
398398
// save Language option
399399
QString language;
400-
if (mpGeneralSettingsPage->getLanguageComboBox()->currentIndex() == 0)
400+
if (mpGeneralSettingsPage->getLanguageComboBox()->currentIndex() == 0) {
401401
language = QLocale::system().name();
402-
else
402+
} else {
403403
language = mpGeneralSettingsPage->getLanguageComboBox()->itemData(mpGeneralSettingsPage->getLanguageComboBox()->currentIndex()).toLocale().name();
404+
}
404405
mpSettings->setValue("language", language);
405406
// save working directory
406407
mpMainWindow->getOMCProxy()->changeDirectory(mpGeneralSettingsPage->getWorkingDirectory());
@@ -421,34 +422,26 @@ void OptionsDialog::saveGeneralSettings()
421422
getMainWindow()->getLibraryTreeWidget()->showProtectedClasses(mpGeneralSettingsPage->getShowProtectedClasses());
422423
// save modeling view mode
423424
mpSettings->setValue("modeling/viewmode", mpGeneralSettingsPage->getModelingViewMode());
424-
if (mpGeneralSettingsPage->getModelingViewMode().compare(Helper::subWindow) == 0)
425-
{
425+
if (mpGeneralSettingsPage->getModelingViewMode().compare(Helper::subWindow) == 0) {
426426
mpMainWindow->getModelWidgetContainer()->setViewMode(QMdiArea::SubWindowView);
427427
ModelWidget *pModelWidget = mpMainWindow->getModelWidgetContainer()->getCurrentModelWidget();
428-
if (pModelWidget)
429-
{
428+
if (pModelWidget) {
430429
pModelWidget->show();
431430
pModelWidget->setWindowState(Qt::WindowMaximized);
432431
}
433-
}
434-
else
435-
{
432+
} else {
436433
mpMainWindow->getModelWidgetContainer()->setViewMode(QMdiArea::TabbedView);
437434
}
438435
// save plotting view mode
439436
mpSettings->setValue("plotting/viewmode", mpGeneralSettingsPage->getPlottingViewMode());
440-
if (mpGeneralSettingsPage->getPlottingViewMode().compare(Helper::subWindow) == 0)
441-
{
437+
if (mpGeneralSettingsPage->getPlottingViewMode().compare(Helper::subWindow) == 0) {
442438
mpMainWindow->getPlotWindowContainer()->setViewMode(QMdiArea::SubWindowView);
443439
OMPlot::PlotWindow *pPlotWindow = mpMainWindow->getPlotWindowContainer()->getCurrentWindow();
444-
if (pPlotWindow)
445-
{
440+
if (pPlotWindow) {
446441
pPlotWindow->show();
447442
pPlotWindow->setWindowState(Qt::WindowMaximized);
448443
}
449-
}
450-
else
451-
{
444+
} else {
452445
mpMainWindow->getPlotWindowContainer()->setViewMode(QMdiArea::TabbedView);
453446
}
454447
// save default view
@@ -460,8 +453,7 @@ void OptionsDialog::saveGeneralSettings()
460453
mpSettings->setValue("autoSave/enableOneFilePackages", mpGeneralSettingsPage->getEnableAutoSaveForOneFilePackagesCheckBox()->isChecked());
461454
mpMainWindow->toggleAutoSave();
462455
// save welcome page
463-
switch (mpGeneralSettingsPage->getWelcomePageView())
464-
{
456+
switch (mpGeneralSettingsPage->getWelcomePageView()) {
465457
case 2:
466458
mpMainWindow->getWelcomePageWidget()->getSplitter()->setOrientation(Qt::Vertical);
467459
break;
@@ -471,16 +463,14 @@ void OptionsDialog::saveGeneralSettings()
471463
break;
472464
}
473465
mpSettings->setValue("welcomePage/view", mpGeneralSettingsPage->getWelcomePageView());
474-
if (mpGeneralSettingsPage->getShowLatestNewsCheckBox()->isChecked())
475-
{
466+
bool showLatestNews = mpGeneralSettingsPage->getShowLatestNewsCheckBox()->isChecked();
467+
if (mpMainWindow->getWelcomePageWidget()->getLatestNewsFrame()->isHidden() && showLatestNews) {
476468
mpMainWindow->getWelcomePageWidget()->getLatestNewsFrame()->show();
477469
mpMainWindow->getWelcomePageWidget()->addLatestNewsListItems();
478-
}
479-
else
480-
{
470+
} else if (!showLatestNews) {
481471
mpMainWindow->getWelcomePageWidget()->getLatestNewsFrame()->hide();
482472
}
483-
mpSettings->setValue("welcomePage/showLatestNews", mpGeneralSettingsPage->getShowLatestNewsCheckBox()->isChecked());
473+
mpSettings->setValue("welcomePage/showLatestNews", showLatestNews);
484474
}
485475

486476
//! Saves the Libraries section settings to omedit.ini

OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ bool PlotWindowContainer::eventFilter(QObject *pObject, QEvent *pEvent)
9292
return QMdiArea::eventFilter(pObject, pEvent);
9393
}
9494

95-
void PlotWindowContainer::addPlotWindow()
95+
/*!
96+
Adds a new Plot Window.
97+
\param maximized - sets the window state maximized
98+
*/
99+
void PlotWindowContainer::addPlotWindow(bool maximized)
96100
{
97101
try
98102
{
@@ -105,8 +109,9 @@ void PlotWindowContainer::addPlotWindow()
105109
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
106110
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/plot-window.svg"));
107111
pPlotWindow->show();
108-
pPlotWindow->setWindowState(Qt::WindowMaximized);
109-
setActiveSubWindow(pSubWindow);
112+
if (maximized) {
113+
pPlotWindow->setWindowState(Qt::WindowMaximized);
114+
}
110115
}
111116
catch (PlotException &e)
112117
{
@@ -115,6 +120,10 @@ void PlotWindowContainer::addPlotWindow()
115120
}
116121
}
117122

123+
/*!
124+
Adds a new Plot Parametric Window.
125+
\param maximized - sets the window state maximized
126+
*/
118127
void PlotWindowContainer::addParametricPlotWindow()
119128
{
120129
try
@@ -128,8 +137,6 @@ void PlotWindowContainer::addParametricPlotWindow()
128137
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
129138
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/parametric-plot-window.svg"));
130139
pPlotWindow->show();
131-
pPlotWindow->setWindowState(Qt::WindowMaximized);
132-
setActiveSubWindow(pSubWindow);
133140
}
134141
catch (PlotException &e)
135142
{

OMEdit/OMEditGUI/Plotting/PlotWindowContainer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class PlotWindowContainer : public MdiArea
5353
OMPlot::PlotWindow* getCurrentWindow();
5454
bool eventFilter(QObject *pObject, QEvent *pEvent);
5555
public slots:
56-
void addPlotWindow();
56+
void addPlotWindow(bool maximized = false);
5757
void addParametricPlotWindow();
5858
void clearPlotWindow();
5959
void updatePlotWindows(QString variable);

0 commit comments

Comments
 (0)