Skip to content

Commit

Permalink
Restrict unit selector of variables browser and use displayUnit
Browse files Browse the repository at this point in the history
- the values are shown with displayUnit
- the unit selector is restricted to displayUnit and actual unit
  to avoid possibly wrong choices resulting from getDerivedUnits
  • Loading branch information
rfranke committed Oct 10, 2016
1 parent a03d35a commit 9a9d061
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion OMEdit/OMEditGUI/Plotting/VariablesWidget.cpp
Expand Up @@ -570,8 +570,18 @@ void VariablesTreeModel::insertVariablesItems(QString fileName, QString filePath
if (!variableData[5].toString().isEmpty()) {
QStringList displayUnits;
displayUnits << variableData[5].toString();
displayUnits << mpVariablesTreeView->getVariablesWidget()->getMainWindow()->getOMCProxy()->getDerivedUnits(variableData[5].toString());
displayUnits << (QList<QString>() << variableData[6].toString());
variableData << displayUnits;
// convert value to displayUnit
OMCInterface::convertUnits_res convertUnit = mpVariablesTreeView->getVariablesWidget()->getMainWindow()->getOMCProxy()->convertUnits(variableData[5].toString(), variableData[6].toString());
if (convertUnit.unitsCompatible) {
bool ok = true;
qreal realValue = variableData[4].toDouble(&ok);
if (ok) {
realValue = Utilities::convertUnit(realValue, convertUnit.offset, convertUnit.scaleFactor);
variableData[4] = QString::number(realValue);
}
}
} else {
variableData << QStringList();
}
Expand Down Expand Up @@ -1332,6 +1342,15 @@ void VariablesWidget::unitChanged(const QModelIndex &index)
OMCInterface::convertUnits_res convertUnit = mpMainWindow->getOMCProxy()->convertUnits(pVariablesTreeItem->getPreviousUnit(),
pVariablesTreeItem->getDisplayUnit());
if (convertUnit.unitsCompatible) {
// update value
QVariant stringValue = pVariablesTreeItem->data(1, Qt::EditRole);
bool ok = true;
qreal realValue = stringValue.toDouble(&ok);
if (ok) {
realValue = Utilities::convertUnit(realValue, convertUnit.offset, convertUnit.scaleFactor);
pVariablesTreeItem->setData(1, QString::number(realValue), Qt::EditRole);
}
// update plots
foreach (PlotCurve *pPlotCurve, pPlotWindow->getPlot()->getPlotCurvesList()) {
QString curveTitle = pPlotCurve->getNameStructure();
if (curveTitle.compare(pVariablesTreeItem->getVariableName()) == 0) {
Expand Down

0 comments on commit 9a9d061

Please sign in to comment.