Skip to content

Commit

Permalink
ticket:2250
Browse files Browse the repository at this point in the history
Allow converting units from the plotting view.
  • Loading branch information
adeas31 committed May 2, 2016
1 parent 1418a48 commit a2b889d
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 44 deletions.
71 changes: 68 additions & 3 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -243,9 +243,15 @@ QSize ItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelInd
}

/*!
Shows a Qt::PointingHandCursor for simulation output links.\n
If the link is clicked then calls the SimulationOutputWidget::openTransformationBrowser(QUrl).
*/
* \brief ItemDelegate::editorEvent
* Shows a Qt::PointingHandCursor for simulation output links.\n
* If the link is clicked then calls the SimulationOutputWidget::openTransformationBrowser(QUrl).
* \param event
* \param model
* \param option
* \param index
* \return
*/
bool ItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
if (mDrawRichText && parent() && qobject_cast<SimulationOutputTree*>(parent()) &&
Expand Down Expand Up @@ -277,6 +283,65 @@ bool ItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const Q
}
}

/*!
* \brief ItemDelegate::createEditor
* Creates the editor for display units in VariablesTreeView.
* \param pParent
* \param option
* \param index
* \return
*/
QWidget* ItemDelegate::createEditor(QWidget *pParent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (parent() && qobject_cast<VariablesTreeView*>(parent()) && index.column() == 3) {
VariablesTreeView *pVariablesTreeView = qobject_cast<VariablesTreeView*>(parent());
VariableTreeProxyModel *pVariableTreeProxyModel = pVariablesTreeView->getVariablesWidget()->getVariableTreeProxyModel();
QModelIndex sourceIndex = pVariableTreeProxyModel->mapToSource(index);
VariablesTreeItem *pVariablesTreeItem = static_cast<VariablesTreeItem*>(sourceIndex.internalPointer());
// create the display units combobox
QComboBox *pComboBox = new QComboBox(pParent);
pComboBox->setEnabled(!pVariablesTreeItem->getDisplayUnits().isEmpty());
pComboBox->addItems(pVariablesTreeItem->getDisplayUnits());
connect(pComboBox, SIGNAL(currentIndexChanged(QString)), SLOT(unitComboBoxChanged(QString)));
return pComboBox;
} else {
return QItemDelegate::createEditor(pParent, option, index);
}
}

/*!
* \brief ItemDelegate::setEditorData
* Sets the value for display unit in VariablesTreeView.
* \param editor
* \param index
*/
void ItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if (parent() && qobject_cast<VariablesTreeView*>(parent()) && index.column() == 3) {
QString value = index.model()->data(index, Qt::DisplayRole).toString();
QComboBox* comboBox = static_cast<QComboBox*>(editor);
//set the index of the combo box
comboBox->setCurrentIndex(comboBox->findText(value, Qt::MatchExactly));
} else {
QItemDelegate::setEditorData(editor, index);
}
}

/*!
* \brief ItemDelegate::unitComboBoxChanged
* Handles the case when display unit is changed in the VariablesTreeView.
* \param text
*/
void ItemDelegate::unitComboBoxChanged(QString text)
{
Q_UNUSED(text);
QComboBox *pComboBox = qobject_cast<QComboBox*>(sender());
if (pComboBox) {
commitData(pComboBox);
closeEditor(pComboBox);
}
}

/*!
* \class LibraryTreeItem
* \brief Contains the information about the Modelica class.
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -60,6 +60,10 @@ class ItemDelegate : public QItemDelegate
void drawHover(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
virtual QWidget* createEditor(QWidget *pParent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
public slots:
void unitComboBoxChanged(QString text);
};

class ModelWidget;
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp
Expand Up @@ -130,6 +130,8 @@ void PlotWindowContainer::addPlotWindow(bool maximized)
pPlotWindow->setTitle("");
pPlotWindow->setLegendPosition("top");
pPlotWindow->setAutoScale(mpMainWindow->getOptionsDialog()->getPlottingPage()->getAutoScaleCheckBox()->isChecked());
pPlotWindow->setTimeUnit(mpMainWindow->getVariablesWidget()->getSimulationTimeComboBox()->currentText());
pPlotWindow->setXLabel(QString("time [%1]").arg(pPlotWindow->getTimeUnit()));
pPlotWindow->installEventFilter(this);
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/plot-window.svg"));
Expand Down

0 comments on commit a2b889d

Please sign in to comment.