|
37 | 37 | #include "Modeling/MessagesWidget.h" |
38 | 38 | #include "Modeling/Commands.h" |
39 | 39 | #include "Options/OptionsDialog.h" |
| 40 | +#include "OMPlot.h" |
40 | 41 |
|
41 | 42 | #include <QApplication> |
42 | 43 | #include <QMenu> |
@@ -101,23 +102,41 @@ Parameter::Parameter(Element *pComponent, bool showStartAttribute, QString tab, |
101 | 102 | setSaveSelectorCaption("-"); |
102 | 103 | createValueWidget(); |
103 | 104 | // Get unit value |
104 | | - QString unit = mpComponent->getDerivedClassModifierValue("unit"); |
105 | | - mUnit = unit; |
| 105 | + mUnit = mpComponent->getDerivedClassModifierValue("unit");; |
106 | 106 | // Get displayUnit value |
107 | 107 | QString displayUnit = mpComponent->getDerivedClassModifierValue("displayUnit"); |
108 | 108 | if (displayUnit.isEmpty()) { |
109 | | - displayUnit = unit; |
| 109 | + displayUnit = mUnit; |
110 | 110 | } |
111 | 111 | mDisplayUnit = StringHandler::removeFirstLastQuotes(displayUnit); |
112 | 112 | mPreviousUnit = mDisplayUnit; |
113 | | - mpUnitComboBox = new QComboBox; |
| 113 | + QStringList units; |
114 | 114 | if (!mUnit.isEmpty()) { |
115 | | - mpUnitComboBox->addItem(Utilities::convertUnitToSymbol(mUnit), mUnit); |
| 115 | + units << mUnit; |
116 | 116 | if (mDisplayUnit.compare(mUnit) != 0) { |
117 | | - mpUnitComboBox->addItem(Utilities::convertUnitToSymbol(mDisplayUnit), mDisplayUnit); |
118 | | - mpUnitComboBox->setCurrentIndex(1); |
| 117 | + units << mDisplayUnit; |
| 118 | + } |
| 119 | + Utilities::addDefaultDisplayUnit(mUnit, units); |
| 120 | + // add unit prefixes |
| 121 | + if (OMPlot::Plot::prefixableUnit(mUnit)) { |
| 122 | + units << QString("k%1").arg(mUnit) |
| 123 | + << QString("M%1").arg(mUnit) |
| 124 | + << QString("G%1").arg(mUnit) |
| 125 | + << QString("T%1").arg(mUnit) |
| 126 | + << QString("m%1").arg(mUnit) |
| 127 | + << QString("u%1").arg(mUnit) |
| 128 | + << QString("n%1").arg(mUnit) |
| 129 | + << QString("p%1").arg(mUnit); |
119 | 130 | } |
120 | 131 | } |
| 132 | + mpUnitComboBox = new QComboBox; |
| 133 | + units.removeDuplicates(); |
| 134 | + foreach (QString unit, units) { |
| 135 | + mpUnitComboBox->addItem(Utilities::convertUnitToSymbol(unit), unit); |
| 136 | + } |
| 137 | + if (mDisplayUnit.compare(mUnit) != 0) { |
| 138 | + mpUnitComboBox->setCurrentIndex(1); |
| 139 | + } |
121 | 140 | connect(mpUnitComboBox, SIGNAL(currentIndexChanged(int)), SLOT(unitComboBoxChanged(int))); |
122 | 141 | mpCommentLabel = new Label(mpComponent->getComponentInfo()->getComment()); |
123 | 142 | } |
|
0 commit comments