implementing UnitsCalculator and disable changes in Sketcher
This commit is contained in:
parent
1f96611b76
commit
3d6743a13b
|
@ -120,6 +120,35 @@ double Quantity::getUserPrefered(QString &unitString)const
|
|||
return Base::UnitsApi::schemaPrefUnit(_Unit,unitString).getValue() * _Value;
|
||||
}
|
||||
|
||||
std::string Quantity::getUserString(void)const
|
||||
{
|
||||
std::stringstream sstream;
|
||||
sstream << _Value << _Unit.getString();
|
||||
//TODO: implementing
|
||||
return sstream.str();
|
||||
}
|
||||
|
||||
/// true if it has a number without a unit
|
||||
bool Quantity::isDimensionless(void)const
|
||||
{
|
||||
return _Value != DOUBLE_MIN && _Unit.isEmpty();
|
||||
}
|
||||
// true if it has a number and a valid unit
|
||||
bool Quantity::isQuantity(void)const
|
||||
{
|
||||
return _Value != DOUBLE_MIN && !_Unit.isEmpty();
|
||||
}
|
||||
// true if it has a number with or without a unit
|
||||
bool Quantity::isValid(void)const
|
||||
{
|
||||
return _Value != DOUBLE_MIN ;
|
||||
}
|
||||
|
||||
void Quantity::setInvalid(void)
|
||||
{
|
||||
_Value = DOUBLE_MIN ;
|
||||
}
|
||||
|
||||
// === Parser & Scanner stuff ===============================================
|
||||
|
||||
// include the Scanner and the Parser for the Quantitys
|
||||
|
|
|
@ -66,6 +66,16 @@ public:
|
|||
double getValue(void) const{return _Value;}
|
||||
void setValue(double val){_Value = val;}
|
||||
|
||||
/// true if it has a number without a unit
|
||||
bool isDimensionless(void)const;
|
||||
/// true if it has a number and a valid unit
|
||||
bool isQuantity(void)const;
|
||||
/// true if it has a number with or without a unit
|
||||
bool isValid(void)const;
|
||||
/// sets the quantity invalid
|
||||
void setInvalid(void);
|
||||
|
||||
|
||||
protected:
|
||||
double _Value;
|
||||
Unit _Unit;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit">
|
||||
<widget class="Gui::InputField" name="ValueInput">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
|
@ -34,7 +34,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_2">
|
||||
<widget class="Gui::InputField" name="UnitInput">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
|
@ -51,7 +51,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_3">
|
||||
<widget class="Gui::InputField" name="ValueOutput">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
|
@ -75,7 +75,7 @@
|
|||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<widget class="QPushButton" name="pushButton_Help">
|
||||
<property name="text">
|
||||
<string>Help</string>
|
||||
</property>
|
||||
|
@ -95,14 +95,14 @@
|
|||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<widget class="QPushButton" name="pushButton_Copy">
|
||||
<property name="text">
|
||||
<string>Copy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<widget class="QPushButton" name="pushButton_Close">
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
|
@ -112,6 +112,13 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Gui::InputField</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>Gui/InputField.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -44,6 +44,14 @@ DlgUnitsCalculator::DlgUnitsCalculator( QWidget* parent, Qt::WFlags fl )
|
|||
// create widgets
|
||||
setupUi(this);
|
||||
|
||||
connect(this->ValueInput, SIGNAL(valueChanged(Base::Quantity)), this, SLOT(valueChanged(Base::Quantity)));
|
||||
connect(this->UnitInput, SIGNAL(valueChanged(Base::Quantity)), this, SLOT(unitValueChanged(Base::Quantity)));
|
||||
|
||||
connect(this->pushButton_Help, SIGNAL(pressed()), this, SLOT(help()));
|
||||
connect(this->pushButton_Close, SIGNAL(pressed()), this, SLOT(accept()));
|
||||
connect(this->pushButton_Copy, SIGNAL(pressed()), this, SLOT(copy()));
|
||||
|
||||
actUnit.setInvalid();
|
||||
}
|
||||
|
||||
/** Destroys the object and frees any allocated resources */
|
||||
|
@ -66,4 +74,37 @@ void DlgUnitsCalculator::reject()
|
|||
delete this;
|
||||
}
|
||||
|
||||
void DlgUnitsCalculator::unitValueChanged(const Base::Quantity& unit)
|
||||
{
|
||||
actUnit = unit;
|
||||
valueChanged(actValue);
|
||||
}
|
||||
|
||||
void DlgUnitsCalculator::valueChanged(const Base::Quantity& quant)
|
||||
{
|
||||
if(actUnit.isValid()){
|
||||
this->ValueOutput->setValue(Base::Quantity(quant.getValue()/actUnit.getValue(),actUnit.getUnit()));
|
||||
}else{
|
||||
this->ValueOutput->setValue(quant);
|
||||
}
|
||||
actValue = quant;
|
||||
|
||||
}
|
||||
|
||||
void DlgUnitsCalculator::copy(void)
|
||||
{
|
||||
//TODO: copy the value to the clipboard
|
||||
QDialog::accept();
|
||||
delete this;
|
||||
|
||||
}
|
||||
|
||||
void DlgUnitsCalculator::help(void)
|
||||
{
|
||||
//TODO: call help page Std_UnitsCalculator
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#include "moc_DlgUnitsCalculatorImp.cpp"
|
||||
|
|
|
@ -30,10 +30,8 @@ namespace Gui {
|
|||
namespace Dialog {
|
||||
|
||||
/**
|
||||
* The DlgUnitsCalculator class provides a dialog to activate the MDI window
|
||||
* of the main window you wish. Since there could be a lot of MDI windows in
|
||||
* an application you cannot put all of them into the "Windows" popup menu.
|
||||
* \author Werner Mayer
|
||||
* The DlgUnitsCalculator provides a unit conversion dialog
|
||||
* \author Juergen Riegel
|
||||
*/
|
||||
class DlgUnitsCalculator : public QDialog, public Ui_DlgUnitCalculator
|
||||
{
|
||||
|
@ -46,6 +44,18 @@ public:
|
|||
protected:
|
||||
void accept();
|
||||
void reject();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void unitValueChanged(const Base::Quantity&);
|
||||
void valueChanged(const Base::Quantity&);
|
||||
|
||||
void copy(void);
|
||||
void help(void);
|
||||
|
||||
private:
|
||||
Base::Quantity actValue;
|
||||
Base::Quantity actUnit;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Dialog
|
||||
|
|
|
@ -39,7 +39,7 @@ InputField::InputField ( QWidget * parent )
|
|||
{
|
||||
this->setContextMenuPolicy(Qt::DefaultContextMenu);
|
||||
|
||||
QObject::connect(this, SIGNAL(textEdited (QString)),
|
||||
QObject::connect(this, SIGNAL(textChanged (QString)),
|
||||
this, SLOT(newInput(QString)));
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,7 @@ void InputField::newInput(const QString & text)
|
|||
QPalette *palette = new QPalette();
|
||||
palette->setColor(QPalette::Base,QColor(255,200,200));
|
||||
setPalette(*palette);
|
||||
parseError(QString::fromAscii(ErrorText.c_str()));
|
||||
return;
|
||||
}
|
||||
QPalette *palette = new QPalette();
|
||||
|
@ -74,6 +75,8 @@ void InputField::newInput(const QString & text)
|
|||
setPalette(*palette);
|
||||
ErrorText = "";
|
||||
this->setToolTip(QString::fromAscii(ErrorText.c_str()));
|
||||
// signaling
|
||||
valueChanged(res);
|
||||
|
||||
}
|
||||
|
||||
|
@ -121,6 +124,59 @@ QByteArray InputField::paramGrpPath() const
|
|||
return sGroupString.c_str();
|
||||
}
|
||||
|
||||
/// sets the field with a quantity
|
||||
void InputField::setValue(const Base::Quantity& quant)
|
||||
{
|
||||
actQuantity = quant;
|
||||
if(!quant.getUnit().isEmpty())
|
||||
actUnit = quant.getUnit();
|
||||
|
||||
setText(QString::fromAscii(quant.getUserString().c_str()));
|
||||
}
|
||||
|
||||
void InputField::setUnit(const Base::Unit& unit)
|
||||
{
|
||||
actUnit = unit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// get the value of the singleStep property
|
||||
double InputField::singleStep(void)const
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/// set the value of the singleStep property
|
||||
void InputField::setSingleStep(double)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// get the value of the maximum property
|
||||
double InputField::maximum(void)const
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/// set the value of the maximum property
|
||||
void InputField::setMaximum(double)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// get the value of the minimum property
|
||||
double InputField::minimum(void)const
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/// set the value of the minimum property
|
||||
void InputField::setMinimum(double)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#define GUI_INPUTFIELD_H
|
||||
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Quantity.h>
|
||||
#include "Widgets.h"
|
||||
#include "Window.h"
|
||||
#include "SpinBox.h"
|
||||
|
@ -37,19 +38,48 @@ namespace Gui {
|
|||
* The InputField class
|
||||
* The input field widget handles all around user input of Quantities. Thats
|
||||
* include parsing and checking input. Providing a context menu for common operations
|
||||
* and managing default and history values.
|
||||
* and managing default and history values.
|
||||
* Although its derived from a QLineEdit widget, its supports most of the properties and signals
|
||||
* of a
|
||||
* \author Jürgen Riegel
|
||||
*/
|
||||
class GuiExport InputField : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
|
||||
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
|
||||
Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep )
|
||||
Q_PROPERTY(double maximum READ maximum WRITE setMaximum )
|
||||
Q_PROPERTY(double minimum READ minimum WRITE setMinimum )
|
||||
|
||||
|
||||
public:
|
||||
InputField ( QWidget * parent = 0 );
|
||||
virtual ~InputField();
|
||||
|
||||
/// sets the field with a quantity
|
||||
void setValue(const Base::Quantity&);
|
||||
/** sets the Unit this field working with.
|
||||
* After seting the Unit the field will only acceppt
|
||||
* user input with this unit type. Or if the user input
|
||||
* a value without unit, this one will be added to the resulting
|
||||
* Quantity.
|
||||
*/
|
||||
void setUnit(const Base::Unit&);
|
||||
|
||||
/// get the value of the singleStep property
|
||||
double singleStep(void)const;
|
||||
/// set the value of the singleStep property
|
||||
void setSingleStep(double);
|
||||
/// get the value of the maximum property
|
||||
double maximum(void)const;
|
||||
/// set the value of the maximum property
|
||||
void setMaximum(double);
|
||||
/// get the value of the minimum property
|
||||
double minimum(void)const;
|
||||
/// set the value of the minimum property
|
||||
void setMinimum(double);
|
||||
|
||||
/** @name history and default management */
|
||||
//@{
|
||||
/// the param group path where the widget write and read the dafault values
|
||||
|
@ -62,6 +92,26 @@ public:
|
|||
std::vector<std::string> getHistory(void);
|
||||
//@}
|
||||
|
||||
|
||||
Q_SIGNALS:
|
||||
/** gets emited if the user has entered a VALID input
|
||||
* Valid means the user inputed string obays all restrictions
|
||||
* like: minimum, maximum and/or the right Unit (if specified).
|
||||
* If you want the unfiltered/unvalidated input use valueChanged(const QString&)
|
||||
* instead:
|
||||
*/
|
||||
void valueChanged(const Base::Quantity&);
|
||||
/** gets emited if the user has entered a VALID input
|
||||
* Valid means the user inputed string obays all restrictions
|
||||
* like: minimum, maximum and/or the right Unit (if specified).
|
||||
* If you want the unfiltered/unvalidated input use valueChanged(const QString&)
|
||||
* instead:
|
||||
*/
|
||||
void valueChanged(double);
|
||||
|
||||
/// signal for an invalid user input (signals a lot while typing!)
|
||||
void parseError(const QString& errorText);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void newInput(const QString & text);
|
||||
|
||||
|
@ -75,6 +125,9 @@ private:
|
|||
/// handle to the parameter group for defaults and history
|
||||
ParameterGrp::handle _handle;
|
||||
std::string sGroupString;
|
||||
|
||||
Base::Quantity actQuantity;
|
||||
Base::Unit actUnit;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ void EditDatumDialog::exec(bool atCursor)
|
|||
Ui::InsertDatum ui_ins_datum;
|
||||
ui_ins_datum.setupUi(&dlg);
|
||||
|
||||
ui_ins_datum.lineEdit->setParamGrpPath("User parameter:History/Sketcher/SetDatum");
|
||||
//ui_ins_datum.lineEdit->setParamGrpPath("User parameter:History/Sketcher/SetDatum");
|
||||
|
||||
double init_val;
|
||||
if (Constr->Type == Sketcher::Angle ||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::InputField" name="lineEdit"/>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
|
|
Loading…
Reference in New Issue
Block a user