add quantity box to unit calculator and allow to set all pre-defined units

This commit is contained in:
wmayer 2016-08-11 19:03:16 +02:00
parent e5d8871fea
commit 7f835a0c26
3 changed files with 68 additions and 6 deletions

View File

@ -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">
@ -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">
@ -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/>

View File

@ -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 */
@ -134,6 +147,9 @@ void DlgUnitsCalculator::returnPressed(void)
}
}
void DlgUnitsCalculator::on_unitsBox_activated(int index)
{
ui->quantitySpinBox->setUnit(units[index]);
}
#include "moc_DlgUnitsCalculatorImp.cpp"

View File

@ -26,6 +26,7 @@
#include <memory>
#include <Base/Quantity.h>
#include <Base/Unit.h>
namespace Gui {
namespace Dialog {
@ -50,6 +51,7 @@ protected:
protected Q_SLOTS:
void unitValueChanged(const Base::Quantity&);
void valueChanged(const Base::Quantity&);
void on_unitsBox_activated(int);
void copy(void);
void help(void);
@ -61,6 +63,7 @@ private:
Base::Quantity actValue;
Base::Quantity actUnit;
std::auto_ptr<Ui_DlgUnitCalculator> ui;
QList<Base::Unit> units;
};
} // namespace Dialog