Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
adeas31 committed Nov 17, 2014
1 parent c4afe24 commit db2f024
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 86 deletions.
54 changes: 48 additions & 6 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -151,6 +151,7 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, QWidget *parent)
mpSimulationDialog = new SimulationDialog(this);
// Create an object of PlotWindowContainer
mpPlotWindowContainer = new PlotWindowContainer(this);
mpPlotWindowContainer->addPlotWindow(true);
// create an object of VariablesWidget
mpVariablesWidget = new VariablesWidget(this);
mpVariablesDockWidget->setWidget(mpVariablesWidget);
Expand Down Expand Up @@ -1300,6 +1301,40 @@ void MainWindow::showAlgorithmicDebugger()
mpDebuggerMainWindow->restoreWindows();
}

/*!
Slot activated when mpCascadeWindowsAction triggered signal is raised.\n
Arranges all child windows in a cascade pattern.
*/
void MainWindow::cascadeWindows()
{
switch (mpCentralStackedWidget->currentIndex()) {
case 1:
mpModelWidgetContainer->cascadeSubWindows();
break;
case 2:
mpPlotWindowContainer->cascadeSubWindows();
default:
break;
}
}

/*!
Slot activated when mpCascadeWindowsAction triggered signal is raised.\n
Arranges all child windows in a tile pattern.
*/
void MainWindow::tileWindows()
{
switch (mpCentralStackedWidget->currentIndex()) {
case 1:
mpModelWidgetContainer->tileSubWindows();
break;
case 2:
mpPlotWindowContainer->tileSubWindows();
default:
break;
}
}

void MainWindow::instantiatesModel()
{
ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget();
Expand Down Expand Up @@ -1732,7 +1767,7 @@ void MainWindow::openRecentModelWidget()
}

/*!
Slot activated when Re-simulateAction triggered signal is raised..\n
Slot activated when Re-simulateAction triggered signal is raised.\n
Re-simulates the model.
*/
void MainWindow::reSimulateModel()
Expand Down Expand Up @@ -2003,6 +2038,14 @@ void MainWindow::createActions()
mpShowAlgorithmicDebuggerAction->setShortcut(QKeySequence("ctrl+t"));
mpShowAlgorithmicDebuggerAction->setStatusTip(Helper::algorithmicDebugger);
connect(mpShowAlgorithmicDebuggerAction, SIGNAL(triggered()), SLOT(showAlgorithmicDebugger()));
// Cascade windows action
mpCascadeWindowsAction = new QAction(tr("Cascade Windows"), this);
mpCascadeWindowsAction->setStatusTip(tr("Arranges all the child windows in a cascade pattern"));
connect(mpCascadeWindowsAction, SIGNAL(triggered()), SLOT(cascadeWindows()));
// Tile windows action
mpTileWindowsAction = new QAction(tr("Tile Windows"), this);
mpTileWindowsAction->setStatusTip(tr("Arranges all child windows in a tile pattern"));
connect(mpTileWindowsAction, SIGNAL(triggered()), SLOT(tileWindows()));
// Simulation Menu
// instantiate model action
mpInstantiateModelAction = new QAction(QIcon(":/Resources/icons/flatmodel.svg"), tr("Instantiate Model"), this);
Expand Down Expand Up @@ -2271,7 +2314,6 @@ void MainWindow::createMenus()
pViewToolbarsMenu->addAction(mpSimulationToolBar->toggleViewAction());
pViewToolbarsMenu->addAction(mpPlotToolBar->toggleViewAction());
pViewToolbarsMenu->addAction(mpModelSwitcherToolBar->toggleViewAction());
pViewMenu->addAction(pViewToolbarsMenu->menuAction());
// Add Actions to Windows View Sub Menu
pViewWindowsMenu->addAction(pSearchClassAction);
pViewWindowsMenu->addAction(mpLibraryTreeDockWidget->toggleViewAction());
Expand All @@ -2280,6 +2322,10 @@ void MainWindow::createMenus()
pViewWindowsMenu->addAction(mpVariablesDockWidget->toggleViewAction());
pViewWindowsMenu->addAction(mpMessagesDockWidget->toggleViewAction());
pViewWindowsMenu->addAction(mpShowAlgorithmicDebuggerAction);
pViewWindowsMenu->addSeparator();
pViewWindowsMenu->addAction(mpCascadeWindowsAction);
pViewWindowsMenu->addAction(mpTileWindowsAction);
pViewMenu->addAction(pViewToolbarsMenu->menuAction());
pViewMenu->addAction(pViewWindowsMenu->menuAction());
pViewMenu->addSeparator();
pViewMenu->addAction(mpShowGridLinesAction);
Expand Down Expand Up @@ -2350,7 +2396,6 @@ void MainWindow::createMenus()

void MainWindow::switchToWelcomePerspective()
{
mpPlotWindowContainer->tileSubWindows();
mpCentralStackedWidget->setCurrentWidget(mpWelcomePageWidget);
mpModelWidgetContainer->currentModelWidgetChanged(0);
mpModelSwitcherToolButton->setEnabled(false);
Expand All @@ -2360,7 +2405,6 @@ void MainWindow::switchToWelcomePerspective()

void MainWindow::switchToModelingPerspective()
{
mpPlotWindowContainer->tileSubWindows();
mpCentralStackedWidget->setCurrentWidget(mpModelWidgetContainer);
mpModelWidgetContainer->currentModelWidgetChanged(mpModelWidgetContainer->getCurrentMdiSubWindow());
mpModelSwitcherToolButton->setEnabled(true);
Expand All @@ -2376,8 +2420,6 @@ void MainWindow::switchToPlottingPerspective()
// if not plotwindow is opened then open one for user
if (mpPlotWindowContainer->subWindowList().size() == 0) {
mpPlotWindowContainer->addPlotWindow();
} else {
mpPlotWindowContainer->getCurrentWindow()->setWindowState(Qt::WindowMaximized);
}
mpVariablesDockWidget->show();
mpPlotToolBar->setEnabled(true);
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -230,6 +230,8 @@ class MainWindow : public QMainWindow
QAction *mpZoomInAction;
QAction *mpZoomOutAction;
QAction *mpShowAlgorithmicDebuggerAction;
QAction *mpCascadeWindowsAction;
QAction *mpTileWindowsAction;
// Simulation Menu
QAction *mpInstantiateModelAction;
QAction *mpCheckModelAction;
Expand Down Expand Up @@ -308,6 +310,8 @@ public slots:
void zoomIn();
void zoomOut();
void showAlgorithmicDebugger();
void cascadeWindows();
void tileWindows();
void instantiatesModel();
void checkModel();
void checkAllModels();
Expand Down
72 changes: 22 additions & 50 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -2823,85 +2823,57 @@ ModelWidgetContainer::ModelWidgetContainer(MainWindow *pParent)

void ModelWidgetContainer::addModelWidget(ModelWidget *pModelWidget, bool checkPreferedView)
{
if (pModelWidget->isVisible() || pModelWidget->isMinimized())
{
if (pModelWidget->isVisible() || pModelWidget->isMinimized()) {
QList<QMdiSubWindow*> subWindowsList = subWindowList(QMdiArea::ActivationHistoryOrder);
for (int i = subWindowsList.size() - 1 ; i >= 0 ; i--)
{
for (int i = subWindowsList.size() - 1 ; i >= 0 ; i--) {
ModelWidget *pSubModelWidget = qobject_cast<ModelWidget*>(subWindowsList.at(i)->widget());
if (pSubModelWidget == pModelWidget)
{
if (pSubModelWidget == pModelWidget) {
pModelWidget->show();
pModelWidget->setWindowState(Qt::WindowMaximized);
setActiveSubWindow(subWindowsList.at(i));
}
}
}
else
{
} else {
static int firstSubWindow = 0;
QMdiSubWindow *pSubWindow = addSubWindow(pModelWidget);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/modeling.png"));
//! @note remove the Stay on &Top Menu item from subwindows. They raise strange exceptions.
if (pSubWindow->systemMenu()->actions().size() > 6)
{
if (pSubWindow->systemMenu()->actions().at(5)->text().compare("Stay on &Top") == 0)
{
pSubWindow->systemMenu()->removeAction(pSubWindow->systemMenu()->actions().at(5));
}
}
pModelWidget->show();
pModelWidget->setWindowState(Qt::WindowMaximized);
if (!firstSubWindow) {
firstSubWindow = 1;
pModelWidget->setWindowState(Qt::WindowMaximized);
}
setActiveSubWindow(pSubWindow);
}
if (!checkPreferedView || pModelWidget->getLibraryTreeNode()->getLibraryType() != LibraryTreeNode::Modelica)
if (!checkPreferedView || pModelWidget->getLibraryTreeNode()->getLibraryType() != LibraryTreeNode::Modelica) {
return;
}
// get the preferred view to display
mpMainWindow->getOMCProxy()->sendCommand(QString("getNamedAnnotation(").append(pModelWidget->getLibraryTreeNode()->getNameStructure()).append(", preferredView)"));
QStringList preferredViewList = StringHandler::unparseStrings(mpMainWindow->getOMCProxy()->getResult());
if (!preferredViewList.isEmpty())
{
if (!preferredViewList.isEmpty()) {
QString preferredView = preferredViewList.at(0);
if (preferredView.compare("info") == 0)
{
if (preferredView.compare("info") == 0) {
pModelWidget->showDocumentationView();
loadPreviousViewType(pModelWidget);
}
else if (preferredView.compare("text") == 0)
{
} else if (preferredView.compare("text") == 0) {
pModelWidget->getTextViewToolButton()->setChecked(true);
}
else
{
} else {
pModelWidget->getDiagramViewToolButton()->setChecked(true);
}
}
else if (pModelWidget->getLibraryTreeNode()->isDocumentationClass())
{
} else if (pModelWidget->getLibraryTreeNode()->isDocumentationClass()) {
pModelWidget->showDocumentationView();
loadPreviousViewType(pModelWidget);
}
else if (pModelWidget->getModelWidgetContainer()->getPreviousViewType() != StringHandler::NoView)
{
} else if (pModelWidget->getModelWidgetContainer()->getPreviousViewType() != StringHandler::NoView) {
loadPreviousViewType(pModelWidget);
}
else
{
} else {
QString defaultView = mpMainWindow->getOptionsDialog()->getGeneralSettingsPage()->getDefaultView();
if (defaultView.compare(Helper::iconView) == 0)
{
if (defaultView.compare(Helper::iconView) == 0) {
pModelWidget->getIconViewToolButton()->setChecked(true);
}
else if (defaultView.compare(Helper::textView) == 0)
{
} else if (defaultView.compare(Helper::textView) == 0) {
pModelWidget->getTextViewToolButton()->setChecked(true);
}
else if (defaultView.compare(Helper::documentationView) == 0)
{
} else if (defaultView.compare(Helper::documentationView) == 0) {
pModelWidget->showDocumentationView();
loadPreviousViewType(pModelWidget);
}
else
{
} else {
pModelWidget->getDiagramViewToolButton()->setChecked(true);
}
}
Expand Down
38 changes: 14 additions & 24 deletions OMEdit/OMEditGUI/Options/OptionsDialog.cpp
Expand Up @@ -397,10 +397,11 @@ void OptionsDialog::saveGeneralSettings()
{
// save Language option
QString language;
if (mpGeneralSettingsPage->getLanguageComboBox()->currentIndex() == 0)
if (mpGeneralSettingsPage->getLanguageComboBox()->currentIndex() == 0) {
language = QLocale::system().name();
else
} else {
language = mpGeneralSettingsPage->getLanguageComboBox()->itemData(mpGeneralSettingsPage->getLanguageComboBox()->currentIndex()).toLocale().name();
}
mpSettings->setValue("language", language);
// save working directory
mpMainWindow->getOMCProxy()->changeDirectory(mpGeneralSettingsPage->getWorkingDirectory());
Expand All @@ -421,34 +422,26 @@ void OptionsDialog::saveGeneralSettings()
getMainWindow()->getLibraryTreeWidget()->showProtectedClasses(mpGeneralSettingsPage->getShowProtectedClasses());
// save modeling view mode
mpSettings->setValue("modeling/viewmode", mpGeneralSettingsPage->getModelingViewMode());
if (mpGeneralSettingsPage->getModelingViewMode().compare(Helper::subWindow) == 0)
{
if (mpGeneralSettingsPage->getModelingViewMode().compare(Helper::subWindow) == 0) {
mpMainWindow->getModelWidgetContainer()->setViewMode(QMdiArea::SubWindowView);
ModelWidget *pModelWidget = mpMainWindow->getModelWidgetContainer()->getCurrentModelWidget();
if (pModelWidget)
{
if (pModelWidget) {
pModelWidget->show();
pModelWidget->setWindowState(Qt::WindowMaximized);
}
}
else
{
} else {
mpMainWindow->getModelWidgetContainer()->setViewMode(QMdiArea::TabbedView);
}
// save plotting view mode
mpSettings->setValue("plotting/viewmode", mpGeneralSettingsPage->getPlottingViewMode());
if (mpGeneralSettingsPage->getPlottingViewMode().compare(Helper::subWindow) == 0)
{
if (mpGeneralSettingsPage->getPlottingViewMode().compare(Helper::subWindow) == 0) {
mpMainWindow->getPlotWindowContainer()->setViewMode(QMdiArea::SubWindowView);
OMPlot::PlotWindow *pPlotWindow = mpMainWindow->getPlotWindowContainer()->getCurrentWindow();
if (pPlotWindow)
{
if (pPlotWindow) {
pPlotWindow->show();
pPlotWindow->setWindowState(Qt::WindowMaximized);
}
}
else
{
} else {
mpMainWindow->getPlotWindowContainer()->setViewMode(QMdiArea::TabbedView);
}
// save default view
Expand All @@ -460,8 +453,7 @@ void OptionsDialog::saveGeneralSettings()
mpSettings->setValue("autoSave/enableOneFilePackages", mpGeneralSettingsPage->getEnableAutoSaveForOneFilePackagesCheckBox()->isChecked());
mpMainWindow->toggleAutoSave();
// save welcome page
switch (mpGeneralSettingsPage->getWelcomePageView())
{
switch (mpGeneralSettingsPage->getWelcomePageView()) {
case 2:
mpMainWindow->getWelcomePageWidget()->getSplitter()->setOrientation(Qt::Vertical);
break;
Expand All @@ -471,16 +463,14 @@ void OptionsDialog::saveGeneralSettings()
break;
}
mpSettings->setValue("welcomePage/view", mpGeneralSettingsPage->getWelcomePageView());
if (mpGeneralSettingsPage->getShowLatestNewsCheckBox()->isChecked())
{
bool showLatestNews = mpGeneralSettingsPage->getShowLatestNewsCheckBox()->isChecked();
if (mpMainWindow->getWelcomePageWidget()->getLatestNewsFrame()->isHidden() && showLatestNews) {
mpMainWindow->getWelcomePageWidget()->getLatestNewsFrame()->show();
mpMainWindow->getWelcomePageWidget()->addLatestNewsListItems();
}
else
{
} else if (!showLatestNews) {
mpMainWindow->getWelcomePageWidget()->getLatestNewsFrame()->hide();
}
mpSettings->setValue("welcomePage/showLatestNews", mpGeneralSettingsPage->getShowLatestNewsCheckBox()->isChecked());
mpSettings->setValue("welcomePage/showLatestNews", showLatestNews);
}

//! Saves the Libraries section settings to omedit.ini
Expand Down
17 changes: 12 additions & 5 deletions OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp
Expand Up @@ -92,7 +92,11 @@ bool PlotWindowContainer::eventFilter(QObject *pObject, QEvent *pEvent)
return QMdiArea::eventFilter(pObject, pEvent);
}

void PlotWindowContainer::addPlotWindow()
/*!
Adds a new Plot Window.
\param maximized - sets the window state maximized
*/
void PlotWindowContainer::addPlotWindow(bool maximized)
{
try
{
Expand All @@ -105,8 +109,9 @@ void PlotWindowContainer::addPlotWindow()
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/plot-window.svg"));
pPlotWindow->show();
pPlotWindow->setWindowState(Qt::WindowMaximized);
setActiveSubWindow(pSubWindow);
if (maximized) {
pPlotWindow->setWindowState(Qt::WindowMaximized);
}
}
catch (PlotException &e)
{
Expand All @@ -115,6 +120,10 @@ void PlotWindowContainer::addPlotWindow()
}
}

/*!
Adds a new Plot Parametric Window.
\param maximized - sets the window state maximized
*/
void PlotWindowContainer::addParametricPlotWindow()
{
try
Expand All @@ -128,8 +137,6 @@ void PlotWindowContainer::addParametricPlotWindow()
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/parametric-plot-window.svg"));
pPlotWindow->show();
pPlotWindow->setWindowState(Qt::WindowMaximized);
setActiveSubWindow(pSubWindow);
}
catch (PlotException &e)
{
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Plotting/PlotWindowContainer.h
Expand Up @@ -53,7 +53,7 @@ class PlotWindowContainer : public MdiArea
OMPlot::PlotWindow* getCurrentWindow();
bool eventFilter(QObject *pObject, QEvent *pEvent);
public slots:
void addPlotWindow();
void addPlotWindow(bool maximized = false);
void addParametricPlotWindow();
void clearPlotWindow();
void updatePlotWindows(QString variable);
Expand Down

0 comments on commit db2f024

Please sign in to comment.