Skip to content

Commit

Permalink
ticket:4162 Enable the Re-simulation toolbar buttons when they are va…
Browse files Browse the repository at this point in the history
…lid.
  • Loading branch information
adeas31 committed Dec 2, 2016
1 parent 30ec275 commit 0fed15a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
17 changes: 16 additions & 1 deletion OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -279,7 +279,7 @@ void MainWindow::setUpMainWindow()
createToolbars();
createMenus();
// enable/disable re-simulation toolbar based on variables browser visibiltiy.
connect(mpVariablesDockWidget, SIGNAL(visibilityChanged(bool)), mpReSimulationToolBar, SLOT(setEnabled(bool)));
connect(mpVariablesDockWidget, SIGNAL(visibilityChanged(bool)), this, SLOT(enableReSimulationToolbar(bool)));
// Create simulation dialog when needed
mpSimulationDialog = 0;
// Create TLM co-simulation dialog when needed
Expand Down Expand Up @@ -2239,6 +2239,20 @@ void MainWindow::readInterfaceData(LibraryTreeItem *pLibraryTreeItem)
}
}

/*!
* \brief MainWindow::enableReSimulationToolbar
* * Handles the VisibilityChanged signal of Variables Dock Widget.
* \param visible
*/
void MainWindow::enableReSimulationToolbar(bool visible)
{
if (visible) {
mpReSimulationToolBar->setEnabled(!mpVariablesWidget->getVariablesTreeView()->selectionModel()->selectedIndexes().isEmpty());
} else {
mpReSimulationToolBar->setEnabled(false);
}
}

/*!
* \brief MainWindow::perspectiveTabChanged
* Handles the perspective tab changed case.
Expand Down Expand Up @@ -3267,6 +3281,7 @@ void MainWindow::createToolbars()
mpReSimulationToolBar = addToolBar(tr("Re-simulation Toolbar"));
mpReSimulationToolBar->setObjectName("Re-simulation Toolbar");
mpReSimulationToolBar->setAllowedAreas(Qt::TopToolBarArea);
mpReSimulationToolBar->setEnabled(false);
// add actions to Re-simulation Toolbar
mpReSimulationToolBar->addAction(mpReSimulateModelAction);
mpReSimulationToolBar->addAction(mpReSimulateSetupAction);
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -112,7 +112,6 @@ class MainWindow : public QMainWindow
Label* getPointerXPositionLabel() {return mpPointerXPositionLabel;}
Label* getPointerYPositionLabel() {return mpPointerYPositionLabel;}
QTabBar* getPerspectiveTabBar() {return mpPerspectiveTabbar;}
QToolBar* getPlotToolBar() {return mpPlotToolBar;}
QTimer* getAutoSaveTimer() {return mpAutoSaveTimer;}
QAction* getSaveAction() {return mpSaveAction;}
QAction* getSaveAsAction() {return mpSaveAsAction;}
Expand Down Expand Up @@ -417,6 +416,7 @@ public slots:
void updateModelSwitcherMenu(QMdiSubWindow *pSubWindow);
void toggleAutoSave();
void readInterfaceData(LibraryTreeItem *pLibraryTreeItem);
void enableReSimulationToolbar(bool visible);
private slots:
void perspectiveTabChanged(int tabIndex);
void documentationDockWidgetVisibilityChanged(bool visible);
Expand Down
26 changes: 16 additions & 10 deletions OMEdit/OMEditGUI/Plotting/VariablesWidget.cpp
Expand Up @@ -176,10 +176,11 @@ QVariant VariablesTreeItem::data(int column, int role) const
case Qt::ToolTipRole:
return mToolTip;
case Qt::CheckStateRole:
if (mChildren.size() > 0)
return QVariant();
else
if (mChildren.size() == 0 && parent()->parent()) { // do not show checkbox for top level items without children.
return isChecked() ? Qt::Checked : Qt::Unchecked;
} else {
return QVariant();
}
default:
return QVariant();
}
Expand Down Expand Up @@ -229,11 +230,6 @@ int VariablesTreeItem::row() const
return 0;
}

VariablesTreeItem* VariablesTreeItem::parent()
{
return mpParentVariablesTreeItem;
}

VariablesTreeItem* VariablesTreeItem::rootParent()
{
// since we have global mpRootVariablesTreeItem so we return one level down from this function in order to get the top level item.
Expand Down Expand Up @@ -389,7 +385,7 @@ Qt::ItemFlags VariablesTreeModel::flags(const QModelIndex &index) const

Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
VariablesTreeItem *pVariablesTreeItem = static_cast<VariablesTreeItem*>(index.internalPointer());
if (index.column() == 0 && pVariablesTreeItem && pVariablesTreeItem->getChildren().size() == 0) {
if (index.column() == 0 && pVariablesTreeItem && pVariablesTreeItem->getChildren().size() == 0 && pVariablesTreeItem->parent() != mpRootVariablesTreeItem) {
flags |= Qt::ItemIsUserCheckable;
} else if (index.column() == 1 && pVariablesTreeItem && pVariablesTreeItem->getChildren().size() == 0 && pVariablesTreeItem->isEditable()) {
flags |= Qt::ItemIsEditable;
Expand Down Expand Up @@ -662,6 +658,7 @@ void VariablesTreeModel::insertVariablesItems(QString fileName, QString filePath
* The following line selects the result tree top level item.
*/
mpVariablesTreeView->setCurrentIndex(idx);
MainWindow::instance()->enableReSimulationToolbar(MainWindow::instance()->getVariablesDockWidget()->isVisible());
}

/*!
Expand All @@ -680,6 +677,7 @@ bool VariablesTreeModel::removeVariableTreeItem(QString variable)
pParentVariablesTreeItem->removeChild(pVariablesTreeItem);
delete pVariablesTreeItem;
endRemoveRows();
mpVariablesTreeView->getVariablesWidget()->findVariables();
return true;
}
return false;
Expand Down Expand Up @@ -940,7 +938,8 @@ void VariablesWidget::insertVariablesItemsToTree(QString fileName, QString fileP
mpVariableTreeProxyModel->setFilterRegExp(QRegExp(""));
mpVariablesTreeView->collapseAll();
/* Show results in model diagram if it is present in ModelWidgetContainer
and if switch to plotting perspective is disabled */
* and if switch to plotting perspective is disabled
*/
ModelWidget *pModelWidget = NULL;
if (!OptionsDialog::instance()->getSimulationPage()->getSwitchToPlottingPerspectiveCheckBox()->isChecked()) {
pModelWidget = MainWindow::instance()->getModelWidgetContainer()->getModelWidget(simulationOptions.getClassName());
Expand Down Expand Up @@ -1573,6 +1572,13 @@ void VariablesWidget::findVariables()
if (!findText.isEmpty()) {
mpVariablesTreeView->expandAll();
}
if (mpVariablesTreeView->selectionModel()->selectedIndexes().isEmpty()) {
QModelIndex proxyIndex = mpVariableTreeProxyModel->index(0, 0);
if (proxyIndex.isValid()) {
mpVariablesTreeView->selectionModel()->select(proxyIndex, QItemSelectionModel::Select | QItemSelectionModel::Rows);
}
}
MainWindow::instance()->enableReSimulationToolbar(MainWindow::instance()->getVariablesDockWidget()->isVisible());
}

void VariablesWidget::directReSimulate()
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/Plotting/VariablesWidget.h
Expand Up @@ -75,7 +75,8 @@ class VariablesTreeItem
bool setData(int column, const QVariant &value, int role = Qt::EditRole);
QVariant data(int column, int role = Qt::DisplayRole) const;
int row() const;
VariablesTreeItem* parent();
VariablesTreeItem* parent() {return mpParentVariablesTreeItem;}
VariablesTreeItem* parent() const {return mpParentVariablesTreeItem;}
VariablesTreeItem* rootParent();
QVariant getValue(QString unit, OMCProxy *pOMCProxy);
private:
Expand Down

0 comments on commit 0fed15a

Please sign in to comment.