Skip to content

Commit

Permalink
Fixes #7406 (#7418)
Browse files Browse the repository at this point in the history
Use the greek omega instead of Ohm
  • Loading branch information
adeas31 committed Apr 27, 2021
1 parent 6f87df7 commit f2d58ff
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 44 deletions.
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/Annotations/TextAnnotation.cpp
Expand Up @@ -559,6 +559,7 @@ void TextAnnotation::updateTextStringHelper(QRegExp regExp)
mTextString.replace(pos, regExp.matchedLength(), textValue);
pos += textValue.length();
} else {
displaytUnit = Utilities::convertUnitToSymbol(displaytUnit);
QString textValueWithDisplayUnit = QString("%1 %2").arg(textValue, displaytUnit);
mTextString.replace(pos, regExp.matchedLength(), textValueWithDisplayUnit);
pos += textValueWithDisplayUnit.length();
Expand Down
46 changes: 23 additions & 23 deletions OMEdit/OMEditLIB/Element/ElementProperties.cpp
Expand Up @@ -112,13 +112,13 @@ Parameter::Parameter(Element *pComponent, bool showStartAttribute, QString tab,
mPreviousUnit = mDisplayUnit;
mpUnitComboBox = new QComboBox;
if (!mUnit.isEmpty()) {
mpUnitComboBox->addItem(mUnit);
mpUnitComboBox->addItem(Utilities::convertUnitToSymbol(mUnit), mUnit);
if (mDisplayUnit.compare(mUnit) != 0) {
mpUnitComboBox->addItem(mDisplayUnit);
mpUnitComboBox->addItem(Utilities::convertUnitToSymbol(mDisplayUnit), mDisplayUnit);
mpUnitComboBox->setCurrentIndex(1);
}
}
connect(mpUnitComboBox, SIGNAL(currentIndexChanged(QString)), SLOT(unitComboBoxChanged(QString)));
connect(mpUnitComboBox, SIGNAL(currentIndexChanged(int)), SLOT(unitComboBoxChanged(int)));
mpCommentLabel = new Label(mpComponent->getComponentInfo()->getComment());
}

Expand Down Expand Up @@ -152,19 +152,19 @@ void Parameter::setValueWidget(QString value, bool defaultValue, QString fromUni
}
if (Utilities::isValueLiteralConstant(value)) {
// convert the value to display unit
if (!fromUnit.isEmpty() && mpUnitComboBox->currentText().compare(fromUnit) != 0) {
if (!fromUnit.isEmpty() && mpUnitComboBox->itemData(mpUnitComboBox->currentIndex()).toString().compare(fromUnit) != 0) {
bool ok = true;
qreal realValue = value.toDouble(&ok);
// if the modifier is a literal constant
if (ok) {
OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
OMCInterface::convertUnits_res convertUnit = pOMCProxy->convertUnits(fromUnit, mpUnitComboBox->currentText());
OMCInterface::convertUnits_res convertUnit = pOMCProxy->convertUnits(fromUnit, mpUnitComboBox->itemData(mpUnitComboBox->currentIndex()).toString());
if (convertUnit.unitsCompatible) {
realValue = Utilities::convertUnit(realValue, convertUnit.offset, convertUnit.scaleFactor);
value = StringHandler::number(realValue);
}
} else { // if expression
value = Utilities::arrayExpressionUnitConversion(MainWindow::instance()->getOMCProxy(), value, fromUnit, mpUnitComboBox->currentText());
value = Utilities::arrayExpressionUnitConversion(MainWindow::instance()->getOMCProxy(), value, fromUnit, mpUnitComboBox->itemData(mpUnitComboBox->currentIndex()).toString());
}
}
}
Expand Down Expand Up @@ -423,10 +423,10 @@ void Parameter::enableDisableUnitComboBox(const QString &value)
*/
if (!literalConstant) {
bool state = mpUnitComboBox->blockSignals(true);
int index = mpUnitComboBox->findText(literalConstant ? mDisplayUnit : mUnit, Qt::MatchExactly);
int index = mpUnitComboBox->findData(literalConstant ? mDisplayUnit : mUnit);
if (index > -1 && index != mpUnitComboBox->currentIndex()) {
mpUnitComboBox->setCurrentIndex(index);
mPreviousUnit = mpUnitComboBox->currentText();
mPreviousUnit = mpUnitComboBox->itemData(mpUnitComboBox->currentIndex()).toString();
}
mpUnitComboBox->blockSignals(state);
}
Expand Down Expand Up @@ -473,11 +473,11 @@ void Parameter::fileSelectorButtonClicked()

/*!
* \brief Parameter::unitComboBoxChanged
* SLOT activated when mpUnitComboBox currentIndexChanged(QString) SIGNAL is raised.\n
* SLOT activated when mpUnitComboBox currentIndexChanged(int) SIGNAL is raised.\n
* Updates the value according to the unit selected.
* \param text
*/
void Parameter::unitComboBoxChanged(QString text)
void Parameter::unitComboBoxChanged(int index)
{
if (!mDefaultValue.isEmpty()) {
setValueWidget(mDefaultValue, true, mPreviousUnit, false, true, true);
Expand All @@ -486,7 +486,7 @@ void Parameter::unitComboBoxChanged(QString text)
if (!value.isEmpty()) {
setValueWidget(value, false, mPreviousUnit, true, true, true);
}
mPreviousUnit = text;
mPreviousUnit = mpUnitComboBox->itemData(index).toString();
}

/*!
Expand Down Expand Up @@ -1108,13 +1108,13 @@ void ElementParameters::fetchComponentModifiers()
}
if (modifiersIterator.key().compare(parameterName + ".displayUnit") == 0) {
QString displayUnit = StringHandler::removeFirstLastQuotes(modifiersIterator.value());
int index = pParameter->getUnitComboBox()->findText(displayUnit, Qt::MatchExactly);
int index = pParameter->getUnitComboBox()->findData(displayUnit);
if (index < 0) {
// add modifier as additional display unit if compatible
index = pParameter->getUnitComboBox()->count() - 1;
if (index > -1 &&
(pOMCProxy->convertUnits(pParameter->getUnitComboBox()->itemText(0), displayUnit)).unitsCompatible) {
pParameter->getUnitComboBox()->addItem(displayUnit);
(pOMCProxy->convertUnits(pParameter->getUnitComboBox()->itemData(0).toString(), displayUnit)).unitsCompatible) {
pParameter->getUnitComboBox()->addItem(Utilities::convertUnitToSymbol(displayUnit), displayUnit);
index ++;
}
}
Expand Down Expand Up @@ -1169,13 +1169,13 @@ void ElementParameters::fetchExtendsModifiers()
}
if (extendsModifiersIterator.key().compare(parameterName + ".displayUnit") == 0) {
QString displayUnit = StringHandler::removeFirstLastQuotes(extendsModifiersIterator.value());
int index = pParameter->getUnitComboBox()->findText(displayUnit, Qt::MatchExactly);
int index = pParameter->getUnitComboBox()->findData(displayUnit);
if (index < 0) {
// add extends modifier as additional display unit if compatible
index = pParameter->getUnitComboBox()->count() - 1;
if (index > -1 &&
(pOMCProxy->convertUnits(pParameter->getUnitComboBox()->itemText(0), displayUnit)).unitsCompatible) {
pParameter->getUnitComboBox()->addItem(displayUnit);
(pOMCProxy->convertUnits(pParameter->getUnitComboBox()->itemData(0).toString(), displayUnit)).unitsCompatible) {
pParameter->getUnitComboBox()->addItem(Utilities::convertUnitToSymbol(displayUnit), displayUnit);
index ++;
}
}
Expand Down Expand Up @@ -1261,18 +1261,18 @@ void ElementParameters::updateComponentParameters()
QString componentModifierKey = pParameter->getNameLabel()->text();
QString componentModifierValue = pParameter->getValue();
// convert the value to display unit
if (!pParameter->getUnit().isEmpty() && pParameter->getUnit().compare(pParameter->getUnitComboBox()->currentText()) != 0) {
if (!pParameter->getUnit().isEmpty() && pParameter->getUnit().compare(pParameter->getUnitComboBox()->itemData(pParameter->getUnitComboBox()->currentIndex()).toString()) != 0) {
bool ok = true;
qreal componentModifierRealValue = componentModifierValue.toDouble(&ok);
// if the modifier is a literal constant
if (ok) {
OMCInterface::convertUnits_res convertUnit = pOMCProxy->convertUnits(pParameter->getUnitComboBox()->currentText(), pParameter->getUnit());
OMCInterface::convertUnits_res convertUnit = pOMCProxy->convertUnits(pParameter->getUnitComboBox()->itemData(pParameter->getUnitComboBox()->currentIndex()).toString(), pParameter->getUnit());
if (convertUnit.unitsCompatible) {
componentModifierRealValue = Utilities::convertUnit(componentModifierRealValue, convertUnit.offset, convertUnit.scaleFactor);
componentModifierValue = StringHandler::number(componentModifierRealValue);
}
} else { // if expression
componentModifierValue = Utilities::arrayExpressionUnitConversion(pOMCProxy, componentModifierValue, pParameter->getUnitComboBox()->currentText(), pParameter->getUnit());
componentModifierValue = Utilities::arrayExpressionUnitConversion(pOMCProxy, componentModifierValue, pParameter->getUnitComboBox()->itemData(pParameter->getUnitComboBox()->currentIndex()).toString(), pParameter->getUnit());
}
}
if (pParameter->isValueModified()) {
Expand Down Expand Up @@ -1305,14 +1305,14 @@ void ElementParameters::updateComponentParameters()
}
}
// if displayUnit is changed
if (pParameter->getUnitComboBox()->isEnabled() && pParameter->getDisplayUnit().compare(pParameter->getUnitComboBox()->currentText()) != 0) {
if (pParameter->getUnitComboBox()->isEnabled() && pParameter->getDisplayUnit().compare(pParameter->getUnitComboBox()->itemData(pParameter->getUnitComboBox()->currentIndex()).toString()) != 0) {
valueChanged = true;
/* If the component is inherited then add the modifier value into the extends. */
if (mpComponent->isInheritedComponent()) {
newComponentExtendsModifiersMap.insert(mpComponent->getName() + "." + componentModifierKey + ".displayUnit",
"\"" + pParameter->getUnitComboBox()->currentText() + "\"");
"\"" + pParameter->getUnitComboBox()->itemData(pParameter->getUnitComboBox()->currentIndex()).toString() + "\"");
} else {
newComponentModifiersMap.insert(componentModifierKey + ".displayUnit", "\"" + pParameter->getUnitComboBox()->currentText() + "\"");
newComponentModifiersMap.insert(componentModifierKey + ".displayUnit", "\"" + pParameter->getUnitComboBox()->itemData(pParameter->getUnitComboBox()->currentIndex()).toString() + "\"");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Element/ElementProperties.h
Expand Up @@ -115,7 +115,7 @@ class Parameter : public QObject
void enableDisableUnitComboBox(const QString &value);
public slots:
void fileSelectorButtonClicked();
void unitComboBoxChanged(QString text);
void unitComboBoxChanged(int index);
void valueComboBoxChanged(int index);
void valueCheckBoxChanged(bool toggle);
void valueTextBoxEdited(const QString &text);
Expand Down
14 changes: 11 additions & 3 deletions OMEdit/OMEditLIB/Modeling/ItemDelegate.cpp
Expand Up @@ -319,7 +319,9 @@ QWidget* ItemDelegate::createEditor(QWidget *pParent, const QStyleOptionViewItem
// create the display units combobox
QComboBox *pComboBox = new QComboBox(pParent);
pComboBox->setEnabled(!pVariablesTreeItem->getDisplayUnits().isEmpty());
pComboBox->addItems(pVariablesTreeItem->getDisplayUnits());
foreach (QString unit, pVariablesTreeItem->getDisplayUnits()) {
pComboBox->addItem(Utilities::convertUnitToSymbol(unit), unit);
}
connect(pComboBox, SIGNAL(currentIndexChanged(QString)), SLOT(unitComboBoxChanged(QString)));
return pComboBox;
}
Expand Down Expand Up @@ -349,10 +351,16 @@ QWidget* ItemDelegate::createEditor(QWidget *pParent, const QStyleOptionViewItem
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();
VariablesTreeView *pVariablesTreeView = qobject_cast<VariablesTreeView*>(parent());
VariableTreeProxyModel *pVariableTreeProxyModel = pVariablesTreeView->getVariablesWidget()->getVariableTreeProxyModel();
QModelIndex sourceIndex = pVariableTreeProxyModel->mapToSource(index);
VariablesTreeItem *pVariablesTreeItem = static_cast<VariablesTreeItem*>(sourceIndex.internalPointer());
QComboBox* comboBox = static_cast<QComboBox*>(editor);
//set the index of the combo box
comboBox->setCurrentIndex(comboBox->findText(value, Qt::MatchExactly));
int currentIndex = comboBox->findData(pVariablesTreeItem->getDisplayUnit());
if (currentIndex > -1) {
comboBox->setCurrentIndex(currentIndex);
}
} else if (parent() && qobject_cast<ConnectorsTreeView*>(parent()) && index.column() == 1) {
ConnectorItem *pConnectorItem = static_cast<ConnectorItem*>(index.internalPointer());
QString value = index.model()->data(index, Qt::DisplayRole).toString();
Expand Down
29 changes: 14 additions & 15 deletions OMEdit/OMEditLIB/Plotting/VariablesWidget.cpp
Expand Up @@ -220,9 +220,9 @@ bool VariablesTreeItem::setData(int column, const QVariant &value, int role)
}
return true;
} else if (column == 3 && role == Qt::EditRole) {
if (mDisplayUnit.compare(value.toString()) != 0) {
if (mDisplayUnit.compare(Utilities::convertSymbolToUnit(value.toString())) != 0) {
mPreviousUnit = mDisplayUnit;
mDisplayUnit = value.toString();
mDisplayUnit = Utilities::convertSymbolToUnit(value.toString());
}
return true;
}
Expand Down Expand Up @@ -281,15 +281,15 @@ QVariant VariablesTreeItem::data(int column, int role) const
switch (role) {
case Qt::DisplayRole:
case Qt::ToolTipRole:
return mUnit;
return Utilities::convertUnitToSymbol(mUnit);
default:
return QVariant();
}
case 3:
switch (role) {
case Qt::DisplayRole:
case Qt::ToolTipRole:
return mDisplayUnit;
return Utilities::convertUnitToSymbol(mDisplayUnit);
default:
return QVariant();
}
Expand Down Expand Up @@ -454,7 +454,7 @@ bool VariablesTreeModel::setData(const QModelIndex &index, const QVariant &value
}
}
} else if (index.column() == 3) { // display unit
if (!signalsBlocked() && displayUnit.compare(value.toString()) != 0) {
if (!signalsBlocked() && displayUnit.compare(Utilities::convertSymbolToUnit(value.toString())) != 0) {
emit unitChanged(index);
}
}
Expand Down Expand Up @@ -1907,8 +1907,8 @@ void VariablesWidget::plotVariables(const QModelIndex &index, qreal curveThickne
pPlotWindow->setCurveWidth(curveThickness);
pPlotWindow->setCurveStyle(curveStyle);
pPlotWindow->setVariablesList(QStringList(pVariablesTreeItem->getPlotVariable()));
pPlotWindow->setYUnit(pVariablesTreeItem->getUnit());
pPlotWindow->setYDisplayUnit(pVariablesTreeItem->getDisplayUnit());
pPlotWindow->setYUnit(Utilities::convertUnitToSymbol(pVariablesTreeItem->getUnit()));
pPlotWindow->setYDisplayUnit(Utilities::convertUnitToSymbol(pVariablesTreeItem->getDisplayUnit()));
if (pPlotWindow->getPlotType() == PlotWindow::PLOT) {
pPlotWindow->plot(pPlotCurve);
} else {/* ie. (pPlotWindow->getPlotType() == PlotWindow::PLOTARRAY)*/
Expand Down Expand Up @@ -2027,10 +2027,10 @@ void VariablesWidget::plotVariables(const QModelIndex &index, qreal curveThickne
pPlotWindow->setCurveWidth(curveThickness);
pPlotWindow->setCurveStyle(curveStyle);
pPlotWindow->setVariablesList(QStringList() << plotParametricCurve.xVariable.variableName << plotParametricVariable.variableName);
pPlotWindow->setXUnit(plotParametricCurve.xVariable.unit);
pPlotWindow->setXDisplayUnit(plotParametricCurve.xVariable.displayUnit);
pPlotWindow->setYUnit(plotParametricVariable.unit);
pPlotWindow->setYDisplayUnit(plotParametricVariable.displayUnit);
pPlotWindow->setXUnit(Utilities::convertUnitToSymbol(plotParametricCurve.xVariable.unit));
pPlotWindow->setXDisplayUnit(Utilities::convertUnitToSymbol(plotParametricCurve.xVariable.displayUnit));
pPlotWindow->setYUnit(Utilities::convertUnitToSymbol(plotParametricVariable.unit));
pPlotWindow->setYDisplayUnit(Utilities::convertUnitToSymbol(plotParametricVariable.displayUnit));
if (pPlotWindow->getPlotType() == PlotWindow::PLOTPARAMETRIC) {
pPlotWindow->plotParametric(pPlotCurve);
} else { /* ie. (pPlotWindow->getPlotType() == PlotWindow::PLOTARRAYPARAMETRIC)*/
Expand Down Expand Up @@ -2133,8 +2133,8 @@ void VariablesWidget::plotVariables(const QModelIndex &index, qreal curveThickne
pPlotWindow->setCurveStyle(curveStyle);
QString plotVariable = pVariablesTreeItem->getPlotVariable();
pPlotWindow->setVariablesList(QStringList(plotVariable));
pPlotWindow->setYUnit(pVariablesTreeItem->getUnit());
pPlotWindow->setYDisplayUnit(pVariablesTreeItem->getDisplayUnit());
pPlotWindow->setYUnit(Utilities::convertUnitToSymbol(pVariablesTreeItem->getUnit()));
pPlotWindow->setYDisplayUnit(Utilities::convertUnitToSymbol(pVariablesTreeItem->getDisplayUnit()));
pPlotWindow->setInteractiveModelName(pVariablesTreeItem->getFileName());
OpcUaClient *pOpcUaClient = MainWindow::instance()->getSimulationDialog()->getOpcUaClient(port);
if (pOpcUaClient) {
Expand Down Expand Up @@ -2202,8 +2202,7 @@ void VariablesWidget::unitChanged(const QModelIndex &index)
if (!pPlotWindow) {
return;
}
OMCInterface::convertUnits_res convertUnit = MainWindow::instance()->getOMCProxy()->convertUnits(pVariablesTreeItem->getPreviousUnit(),
pVariablesTreeItem->getDisplayUnit());
OMCInterface::convertUnits_res convertUnit = MainWindow::instance()->getOMCProxy()->convertUnits(pVariablesTreeItem->getPreviousUnit(), pVariablesTreeItem->getDisplayUnit());
if (convertUnit.unitsCompatible) {
/* update value */
QVariant stringValue = pVariablesTreeItem->data(1, Qt::EditRole);
Expand Down
31 changes: 31 additions & 0 deletions OMEdit/OMEditLIB/Util/Utilities.cpp
Expand Up @@ -1259,3 +1259,34 @@ QStringList Utilities::variantListToStringList(const QVariantList lst)
}
return strs;
}

/*!
* \brief Utilities::convertUnitToSymbol
* Converts the unit to a symbol.
* \param displayUnit
* \return
*/
QString Utilities::convertUnitToSymbol(const QString displayUnit)
{
if (displayUnit.compare(QStringLiteral("Ohm")) == 0) {
return QChar(937);
} else {
return displayUnit;
}
}

/*!
* \brief Utilities::convertSymbolToUnit
* Converts the symbol to unit.
* \param symbol
* \return
*/
QString Utilities::convertSymbolToUnit(const QString symbol)
{
// Greek Omega
if (symbol.compare(QChar(937)) == 0) {
return "Ohm";
} else {
return symbol;
}
}
4 changes: 2 additions & 2 deletions OMEdit/OMEditLIB/Util/Utilities.h
Expand Up @@ -541,9 +541,9 @@ namespace Utilities {
QList<QPointF> liangBarskyClipper(float xmin, float ymin, float xmax, float ymax, float x1, float y1, float x2, float y2);
void removeDirectoryRecursivly(QString path);
qreal mapToCoOrdinateSystem(qreal value, qreal startA, qreal endA, qreal startB, qreal endB);

QStringList variantListToStringList(const QVariantList lst);

QString convertUnitToSymbol(const QString displayUnit);
QString convertSymbolToUnit(const QString symbol);
} // namespace Utilities

#endif // UTILITIES_H

0 comments on commit f2d58ff

Please sign in to comment.