Skip to content

Commit

Permalink
add quantity box to unit calculator and allow to set all pre-defined …
Browse files Browse the repository at this point in the history
…units
  • Loading branch information
wwmayer committed Aug 11, 2016
1 parent e5d8871 commit 7f835a0
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
53 changes: 48 additions & 5 deletions src/Gui/DlgUnitsCalculator.ui
Expand Up @@ -7,14 +7,14 @@
<x>0</x>
<y>0</y>
<width>425</width>
<height>148</height>
<height>187</height>
</rect>
</property>
<property name="windowTitle">
<string>Units calculator</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="Gui::InputField" name="ValueInput">
Expand Down Expand Up @@ -65,14 +65,52 @@
</item>
</layout>
</item>
<item>
<item row="1" column="0">
<widget class="QTextEdit" name="textEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Quantity:</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::QuantitySpinBox" name="quantitySpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Units:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="unitsBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton_Help">
Expand Down Expand Up @@ -118,6 +156,11 @@
<extends>QLineEdit</extends>
<header>Gui/InputField.h</header>
</customwidget>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down
18 changes: 17 additions & 1 deletion src/Gui/DlgUnitsCalculatorImp.cpp
Expand Up @@ -64,6 +64,19 @@ DlgUnitsCalculator::DlgUnitsCalculator( QWidget* parent, Qt::WindowFlags fl )

ui->ValueInput->setParamGrpPath(QByteArray("User parameter:BaseApp/History/UnitsCalculator"));
actUnit.setInvalid();

units << Base::Unit::Length << Base::Unit::Mass << Base::Unit::Angle << Base::Unit::Density
<< Base::Unit::Area << Base::Unit::Volume << Base::Unit::TimeSpan << Base::Unit::Velocity
<< Base::Unit::Acceleration << Base::Unit::Temperature << Base::Unit::ElectricCurrent
<< Base::Unit::AmountOfSubstance << Base::Unit::LuminoseIntensity << Base::Unit::Stress
<< Base::Unit::Pressure << Base::Unit::Force << Base::Unit::Work << Base::Unit::Power
<< Base::Unit::ThermalConductivity << Base::Unit::ThermalExpansionCoefficient
<< Base::Unit::SpecificHeat << Base::Unit::ThermalTransferCoefficient;
for (QList<Base::Unit>::iterator it = units.begin(); it != units.end(); ++it) {
ui->unitsBox->addItem(it->getTypeString());
}

ui->quantitySpinBox->setUnit(units.front());
}

/** Destroys the object and frees any allocated resources */
Expand Down Expand Up @@ -134,6 +147,9 @@ void DlgUnitsCalculator::returnPressed(void)
}
}


void DlgUnitsCalculator::on_unitsBox_activated(int index)
{
ui->quantitySpinBox->setUnit(units[index]);
}

#include "moc_DlgUnitsCalculatorImp.cpp"
3 changes: 3 additions & 0 deletions src/Gui/DlgUnitsCalculatorImp.h
Expand Up @@ -26,6 +26,7 @@

#include <memory>
#include <Base/Quantity.h>
#include <Base/Unit.h>

namespace Gui {
namespace Dialog {
Expand All @@ -50,6 +51,7 @@ class DlgUnitsCalculator : public QDialog
protected Q_SLOTS:
void unitValueChanged(const Base::Quantity&);
void valueChanged(const Base::Quantity&);
void on_unitsBox_activated(int);

void copy(void);
void help(void);
Expand All @@ -61,6 +63,7 @@ protected Q_SLOTS:
Base::Quantity actValue;
Base::Quantity actUnit;
std::auto_ptr<Ui_DlgUnitCalculator> ui;
QList<Base::Unit> units;
};

} // namespace Dialog
Expand Down

0 comments on commit 7f835a0

Please sign in to comment.