add inputfield to property editor for PropertyQuantity and PropertyQuantityConstraint

This commit is contained in:
Stefan Tröger 2014-05-09 17:23:38 +02:00 committed by wmayer
parent ec442507e1
commit 58a781e5c4
5 changed files with 72 additions and 78 deletions

View File

@ -46,7 +46,8 @@ using namespace Base;
using namespace std;
const PropertyQuantityConstraint::Constraints LengthStandart = {0.0,(double)INT_MAX,1.0};
const PropertyQuantityConstraint::Constraints AngleStandart = {-360,360,1.0};
//**************************************************************************
//**************************************************************************
@ -62,7 +63,7 @@ Base::Quantity PropertyQuantity::getQuantityValue(void) const
const char* PropertyQuantity::getEditorName(void) const
{
return "Gui::PropertyEditor::PropertyUnitItem";
return "Gui::PropertyEditor::PropertyUnitItem";
}
PyObject *PropertyQuantity::getPyObject(void)
@ -127,6 +128,12 @@ void PropertyQuantityConstraint::setConstraints(const Constraints* sConstrain)
_ConstStruct = sConstrain;
}
const char* PropertyQuantityConstraint::getEditorName(void) const
{
return "Gui::PropertyEditor::PropertyUnitConstraintItem";
}
const PropertyQuantityConstraint::Constraints* PropertyQuantityConstraint::getConstraints(void) const
{
return _ConstStruct;
@ -198,11 +205,12 @@ PropertyAcceleration::PropertyAcceleration()
// PropertyLength
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TYPESYSTEM_SOURCE(App::PropertyLength, App::PropertyQuantity);
TYPESYSTEM_SOURCE(App::PropertyLength, App::PropertyQuantityConstraint);
PropertyLength::PropertyLength()
{
setUnit(Base::Unit::Length);
setConstraints( &LengthStandart );
}
//**************************************************************************
@ -215,6 +223,7 @@ TYPESYSTEM_SOURCE(App::PropertyAngle, App::PropertyQuantityConstraint);
PropertyAngle::PropertyAngle()
{
setUnit(Base::Unit::Angle);
setConstraints( &AngleStandart );
}
//**************************************************************************

View File

@ -100,9 +100,7 @@ public:
const Constraints* getConstraints(void) const;
//@}
virtual const char* getEditorName(void) const
{ return "Gui::PropertyEditor::PropertyFloatConstraintItem"; }
virtual const char* getEditorName(void) const;
virtual void setPyObject(PyObject *);
@ -126,7 +124,7 @@ public:
* This is a property for representing lengths. It is basically a float
* property which must not be negative. On the Gui it has a quantity like m or mm.
*/
class AppExport PropertyLength : public PropertyQuantity
class AppExport PropertyLength : public PropertyQuantityConstraint
{
TYPESYSTEM_HEADER();
public:
@ -157,7 +155,6 @@ class AppExport PropertySpeed: public PropertyQuantity
public:
PropertySpeed(void);
virtual ~PropertySpeed(){}
virtual const char* getEditorName(void) const { return "Gui::PropertyEditor::PropertyFloatItem"; }
};
/** Acceleration property
@ -170,7 +167,6 @@ class AppExport PropertyAcceleration: public PropertyQuantity
public:
PropertyAcceleration(void);
virtual ~PropertyAcceleration(){}
virtual const char* getEditorName(void) const { return "Gui::PropertyEditor::PropertyFloatItem"; }
};
/** Pressure property
@ -183,7 +179,6 @@ class AppExport PropertyPressure: public PropertyQuantity
public:
PropertyPressure(void);
virtual ~PropertyPressure(){}
virtual const char* getEditorName(void) const { return "Gui::PropertyEditor::PropertyFloatItem"; }
};
/** Force property
@ -196,7 +191,6 @@ class AppExport PropertyForce: public PropertyQuantity
public:
PropertyForce(void);
virtual ~PropertyForce(){}
virtual const char* getEditorName(void) const { return "Gui::PropertyEditor::PropertyFloatItem"; }
};

View File

@ -110,6 +110,7 @@ void Gui::SoFCDB::init()
PropertyFloatItem ::init();
PropertyUnitItem ::init();
PropertyFloatConstraintItem ::init();
PropertyUnitConstraintItem ::init();
PropertyAngleItem ::init();
PropertyBoolItem ::init();
PropertyVectorItem ::init();

View File

@ -547,30 +547,6 @@ QVariant PropertyFloatItem::toString(const QVariant& prop) const
{
double value = prop.toDouble();
QString data = QLocale::system().toString(value, 'f', decimals());
const std::vector<App::Property*>& props = getPropertyData();
if (!props.empty()) {
if (props.front()->getTypeId().isDerivedFrom(App::PropertyDistance::getClassTypeId())) {
QString unit = QString::fromAscii("mm");
unit.prepend(QLatin1String(" "));
data += unit;
}
else if (props.front()->getTypeId().isDerivedFrom(App::PropertyLength::getClassTypeId())) {
QString unit = QString::fromAscii("mm");
unit.prepend(QLatin1String(" "));
data += unit;
}
else if (props.front()->getTypeId().isDerivedFrom(App::PropertySpeed::getClassTypeId())) {
//QString unit = Base::UnitsApi::getPrefUnitOf(Base::Acceleration);
//unit.prepend(QLatin1String(" "));
//data += unit;
}
else if (props.front()->getTypeId().isDerivedFrom(App::PropertyAcceleration::getClassTypeId())) {
QString unit = QString::fromAscii("mm/s^2");
unit.prepend(QLatin1String(" "));
data += unit;
}
}
return QVariant(data);
}
@ -605,32 +581,6 @@ void PropertyFloatItem::setEditorData(QWidget *editor, const QVariant& data) con
QDoubleSpinBox *sb = qobject_cast<QDoubleSpinBox*>(editor);
sb->setRange((double)INT_MIN, (double)INT_MAX);
sb->setValue(data.toDouble());
const std::vector<App::Property*>& prop = getPropertyData();
if (prop.empty())
return;
else if (prop.front()->getTypeId().isDerivedFrom(App::PropertyDistance::getClassTypeId())) {
QString unit = QString::fromAscii("mm");
unit.prepend(QLatin1String(" "));
sb->setSuffix(unit);
}
else if (prop.front()->getTypeId().isDerivedFrom(App::PropertyLength::getClassTypeId())) {
sb->setMinimum(0.0);
QString unit = QString::fromAscii("mm");
unit.prepend(QLatin1String(" "));
sb->setSuffix(unit);
}
else if (prop.front()->getTypeId().isDerivedFrom(App::PropertySpeed::getClassTypeId())) {
//sb->setMinimum(0.0);
//QString unit = Base::UnitsApi::getPrefUnitOf(Base::Acceleration);
//unit.prepend(QLatin1String(" "));
//sb->setSuffix(unit);
}
else if (prop.front()->getTypeId().isDerivedFrom(App::PropertyAcceleration::getClassTypeId())) {
sb->setMinimum(0.0);
QString unit = QString::fromAscii("mm/s^2");
unit.prepend(QLatin1String(" "));
sb->setSuffix(unit);
}
}
QVariant PropertyFloatItem::editorData(QWidget *editor) const
@ -674,38 +624,64 @@ void PropertyUnitItem::setValue(const QVariant& value)
QWidget* PropertyUnitItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
{
QDoubleSpinBox *sb = new QDoubleSpinBox(parent);
sb->setFrame(false);
sb->setDecimals(std::max<int>(5,decimals()));
QObject::connect(sb, SIGNAL(valueChanged(double)), receiver, method);
return sb;
Gui::InputField *infield = new Gui::InputField(parent);
infield->setFrame(false);
infield->setMinimumHeight(0);
QObject::connect(infield, SIGNAL(valueChanged(double)), receiver, method);
return infield;
}
void PropertyUnitItem::setEditorData(QWidget *editor, const QVariant& data) const
{
const Base::Quantity& value = data.value<Base::Quantity>();
QDoubleSpinBox *sb = qobject_cast<QDoubleSpinBox*>(editor);
sb->setRange((double)INT_MIN, (double)INT_MAX);
//sb->setValue(value.getValue());
//sb->setSuffix(value.getUnit().getString());
double factor;
QString unitStr;
value.getUserString(factor, unitStr);
double unitValue = value.getValue() / factor;
sb->setValue(unitValue);
sb->setSuffix(unitStr);
Gui::InputField *infield = qobject_cast<Gui::InputField*>(editor);
infield->setValue(value);
}
QVariant PropertyUnitItem::editorData(QWidget *editor) const
{
QDoubleSpinBox *sb = qobject_cast<QDoubleSpinBox*>(editor);
Base::Quantity value = Base::Quantity::parse(sb->text());
Gui::InputField *infield = qobject_cast<Gui::InputField*>(editor);
Base::Quantity value = infield->getQuantity();
return QVariant::fromValue<Base::Quantity>(value);
}
// --------------------------------------------------------------------
TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyUnitConstraintItem, Gui::PropertyEditor::PropertyUnitItem);
PropertyUnitConstraintItem::PropertyUnitConstraintItem()
{
}
void PropertyUnitConstraintItem::setEditorData(QWidget *editor, const QVariant& data) const
{
const Base::Quantity& value = data.value<Base::Quantity>();
Gui::InputField *infield = qobject_cast<Gui::InputField*>(editor);
infield->setValue(value);
const std::vector<App::Property*>& items = getPropertyData();
App::PropertyQuantityConstraint* prop = (App::PropertyQuantityConstraint*)items[0];
const App::PropertyQuantityConstraint::Constraints* c =
((App::PropertyQuantityConstraint*)prop)->getConstraints();
if (c) {
infield->setMinimum(c->LowerBound);
infield->setMaximum(c->UpperBound);
infield->setSingleStep(c->StepSize);
}
else {
infield->setMinimum((double)INT_MIN);
infield->setMaximum((double)INT_MAX);
}
}
// --------------------------------------------------------------------
TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyFloatConstraintItem, Gui::PropertyEditor::PropertyItem);
PropertyFloatConstraintItem::PropertyFloatConstraintItem()

View File

@ -240,6 +240,20 @@ protected:
PropertyUnitItem();
};
/**
* Change a Unit based floating point number withing constraints.
* \author Stefan Troeger
*/
class GuiExport PropertyUnitConstraintItem: public PropertyUnitItem
{
TYPESYSTEM_HEADER();
virtual void setEditorData(QWidget *editor, const QVariant& data) const;
protected:
PropertyUnitConstraintItem();
};
/**
* Change a floating point number with constraints.
* \author Werner Mayer