add inputfield to placement in property editor
This commit is contained in:
@@ -940,6 +940,113 @@ void PropertyVectorItem::setZ(double z)
|
||||
setData(QVariant::fromValue(Base::Vector3d(x(), y(), z)));
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyVectorDistanceItem, Gui::PropertyEditor::PropertyItem);
|
||||
|
||||
PropertyVectorDistanceItem::PropertyVectorDistanceItem()
|
||||
{
|
||||
m_x = static_cast<PropertyUnitItem*>(PropertyUnitItem::create());
|
||||
m_x->setParent(this);
|
||||
m_x->setPropertyName(QLatin1String("x"));
|
||||
this->appendChild(m_x);
|
||||
m_y = static_cast<PropertyUnitItem*>(PropertyUnitItem::create());
|
||||
m_y->setParent(this);
|
||||
m_y->setPropertyName(QLatin1String("y"));
|
||||
this->appendChild(m_y);
|
||||
m_z = static_cast<PropertyUnitItem*>(PropertyUnitItem::create());
|
||||
m_z->setParent(this);
|
||||
m_z->setPropertyName(QLatin1String("z"));
|
||||
this->appendChild(m_z);
|
||||
}
|
||||
|
||||
QVariant PropertyVectorDistanceItem::toString(const QVariant& prop) const
|
||||
{
|
||||
const Base::Vector3d& value = prop.value<Base::Vector3d>();
|
||||
QString data = QString::fromAscii("[") +
|
||||
Base::Quantity(value.x, Base::Unit::Length).getUserString() + QString::fromAscii(" ") +
|
||||
Base::Quantity(value.y, Base::Unit::Length).getUserString() + QString::fromAscii(" ") +
|
||||
Base::Quantity(value.z, Base::Unit::Length).getUserString() + QString::fromAscii("]");
|
||||
return QVariant(data);
|
||||
}
|
||||
|
||||
|
||||
QVariant PropertyVectorDistanceItem::value(const App::Property* prop) const
|
||||
{
|
||||
assert(prop && prop->getTypeId().isDerivedFrom(App::PropertyVector::getClassTypeId()));
|
||||
|
||||
const Base::Vector3d& value = static_cast<const App::PropertyVector*>(prop)->getValue();
|
||||
return QVariant::fromValue<Base::Vector3d>(value);
|
||||
}
|
||||
|
||||
void PropertyVectorDistanceItem::setValue(const QVariant& variant)
|
||||
{
|
||||
if (!variant.canConvert<Base::Vector3d>())
|
||||
return;
|
||||
const Base::Vector3d& value = variant.value<Base::Vector3d>();
|
||||
|
||||
Base::Quantity q = Base::Quantity(value.x, Base::Unit::Length);
|
||||
QString unit = QString::fromLatin1("('%1 %2'").arg(q.getValue()).arg(q.getUnit().getString());
|
||||
q = Base::Quantity(value.y, Base::Unit::Length);
|
||||
unit + QString::fromLatin1("'%1 %2'").arg(q.getValue()).arg(q.getUnit().getString());
|
||||
q = Base::Quantity(value.z, Base::Unit::Length);
|
||||
QString::fromLatin1("'%1 %2')").arg(q.getValue()).arg(q.getUnit().getString());
|
||||
|
||||
setPropertyValue(unit);
|
||||
}
|
||||
|
||||
void PropertyVectorDistanceItem::setEditorData(QWidget *editor, const QVariant& data) const
|
||||
{
|
||||
QLineEdit* le = qobject_cast<QLineEdit*>(editor);
|
||||
le->setText(toString(data).toString());
|
||||
}
|
||||
|
||||
QWidget* PropertyVectorDistanceItem::createEditor(QWidget* parent, const QObject* /*receiver*/, const char* /*method*/) const
|
||||
{
|
||||
QLineEdit *le = new QLineEdit(parent);
|
||||
le->setFrame(false);
|
||||
le->setReadOnly(true);
|
||||
return le;
|
||||
}
|
||||
|
||||
QVariant PropertyVectorDistanceItem::editorData(QWidget *editor) const
|
||||
{
|
||||
QLineEdit *le = qobject_cast<QLineEdit*>(editor);
|
||||
return QVariant(le->text());
|
||||
}
|
||||
|
||||
Base::Quantity PropertyVectorDistanceItem::x() const
|
||||
{
|
||||
return Base::Quantity(data(1,Qt::EditRole).value<Base::Vector3d>().x, Base::Unit::Length);
|
||||
}
|
||||
|
||||
void PropertyVectorDistanceItem::setX(Base::Quantity x)
|
||||
{
|
||||
setData(QVariant::fromValue(Base::Vector3d(x.getValue(), y().getValue(), z().getValue())));
|
||||
}
|
||||
|
||||
Base::Quantity PropertyVectorDistanceItem::y() const
|
||||
{
|
||||
return Base::Quantity(data(1,Qt::EditRole).value<Base::Vector3d>().y, Base::Unit::Length);
|
||||
}
|
||||
|
||||
void PropertyVectorDistanceItem::setY(Base::Quantity y)
|
||||
{
|
||||
setData(QVariant::fromValue(Base::Vector3d(x().getValue(), y.getValue(), z().getValue())));
|
||||
}
|
||||
|
||||
Base::Quantity PropertyVectorDistanceItem::z() const
|
||||
{
|
||||
return Base::Quantity(data(1,Qt::EditRole).value<Base::Vector3d>().z, Base::Unit::Length);
|
||||
}
|
||||
|
||||
void PropertyVectorDistanceItem::setZ(Base::Quantity z)
|
||||
{
|
||||
setData(QVariant::fromValue(Base::Vector3d(x().getValue(), y().getValue(), z.getValue())));
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyMatrixItem, Gui::PropertyEditor::PropertyItem);
|
||||
@@ -1367,7 +1474,7 @@ TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyPlacementItem, Gui::PropertyEdito
|
||||
|
||||
PropertyPlacementItem::PropertyPlacementItem() : init_axis(false), changed_value(false), rot_angle(0), rot_axis(0,0,1)
|
||||
{
|
||||
m_a = static_cast<PropertyAngleItem*>(PropertyAngleItem::create());
|
||||
m_a = static_cast<PropertyUnitItem*>(PropertyUnitItem::create());
|
||||
m_a->setParent(this);
|
||||
m_a->setPropertyName(QLatin1String("Angle"));
|
||||
this->appendChild(m_a);
|
||||
@@ -1376,7 +1483,7 @@ PropertyPlacementItem::PropertyPlacementItem() : init_axis(false), changed_value
|
||||
m_d->setPropertyName(QLatin1String("Axis"));
|
||||
m_d->setReadOnly(true);
|
||||
this->appendChild(m_d);
|
||||
m_p = static_cast<PropertyVectorItem*>(PropertyVectorItem::create());
|
||||
m_p = static_cast<PropertyVectorDistanceItem*>(PropertyVectorDistanceItem::create());
|
||||
m_p->setParent(this);
|
||||
m_p->setPropertyName(QLatin1String("Position"));
|
||||
m_p->setReadOnly(true);
|
||||
@@ -1387,7 +1494,7 @@ PropertyPlacementItem::~PropertyPlacementItem()
|
||||
{
|
||||
}
|
||||
|
||||
double PropertyPlacementItem::getAngle() const
|
||||
Base::Quantity PropertyPlacementItem::getAngle() const
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<Base::Placement>())
|
||||
@@ -1398,10 +1505,10 @@ double PropertyPlacementItem::getAngle() const
|
||||
val.getRotation().getValue(dir, angle);
|
||||
if (dir * this->rot_axis < 0.0)
|
||||
angle = -angle;
|
||||
return Base::toDegrees<double>(angle);
|
||||
return Base::Quantity(Base::toDegrees<double>(angle), Base::Unit::Angle);
|
||||
}
|
||||
|
||||
void PropertyPlacementItem::setAngle(double angle)
|
||||
void PropertyPlacementItem::setAngle(Base::Quantity angle)
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<Base::Placement>())
|
||||
@@ -1409,10 +1516,10 @@ void PropertyPlacementItem::setAngle(double angle)
|
||||
|
||||
Base::Placement val = value.value<Base::Placement>();
|
||||
Base::Rotation rot;
|
||||
rot.setValue(this->rot_axis, Base::toRadians<double>(angle));
|
||||
rot.setValue(this->rot_axis, Base::toRadians<double>(angle.getValue()));
|
||||
val.setRotation(rot);
|
||||
changed_value = true;
|
||||
rot_angle = angle;
|
||||
rot_angle = angle.getValue();
|
||||
setValue(QVariant::fromValue(val));
|
||||
}
|
||||
|
||||
@@ -1490,15 +1597,15 @@ QVariant PropertyPlacementItem::toolTip(const App::Property* prop) const
|
||||
angle = Base::toDegrees<double>(angle);
|
||||
pos = p.getPosition();
|
||||
QString data = QString::fromUtf8("Axis: (%1 %2 %3)\n"
|
||||
"Angle: %4 \xc2\xb0\n"
|
||||
"Position: (%5 %6 %7)")
|
||||
"Angle: %4\n"
|
||||
"Position: (%5 %6 %7)")
|
||||
.arg(QLocale::system().toString(dir.x,'f',decimals()))
|
||||
.arg(QLocale::system().toString(dir.y,'f',decimals()))
|
||||
.arg(QLocale::system().toString(dir.z,'f',decimals()))
|
||||
.arg(QLocale::system().toString(angle,'f',decimals()))
|
||||
.arg(QLocale::system().toString(pos.x,'f',decimals()))
|
||||
.arg(QLocale::system().toString(pos.y,'f',decimals()))
|
||||
.arg(QLocale::system().toString(pos.z,'f',decimals()));
|
||||
.arg(Base::Quantity(angle, Base::Unit::Angle).getUserString())
|
||||
.arg(Base::Quantity(pos.x, Base::Unit::Length).getUserString())
|
||||
.arg(Base::Quantity(pos.y, Base::Unit::Length).getUserString())
|
||||
.arg(Base::Quantity(pos.z, Base::Unit::Length).getUserString());
|
||||
return QVariant(data);
|
||||
}
|
||||
|
||||
@@ -1510,14 +1617,14 @@ QVariant PropertyPlacementItem::toString(const QVariant& prop) const
|
||||
p.getRotation().getValue(dir, angle);
|
||||
angle = Base::toDegrees<double>(angle);
|
||||
pos = p.getPosition();
|
||||
QString data = QString::fromUtf8("[(%1 %2 %3);%4 \xc2\xb0;(%5 %6 %7)]")
|
||||
QString data = QString::fromUtf8("[(%1 %2 %3); %4; (%5 %6 %7)]")
|
||||
.arg(QLocale::system().toString(dir.x,'f',2))
|
||||
.arg(QLocale::system().toString(dir.y,'f',2))
|
||||
.arg(QLocale::system().toString(dir.z,'f',2))
|
||||
.arg(QLocale::system().toString(angle,'f',2))
|
||||
.arg(QLocale::system().toString(pos.x,'f',2))
|
||||
.arg(QLocale::system().toString(pos.y,'f',2))
|
||||
.arg(QLocale::system().toString(pos.z,'f',2));
|
||||
.arg(Base::Quantity(angle, Base::Unit::Angle).getUserString())
|
||||
.arg(Base::Quantity(pos.x, Base::Unit::Length).getUserString())
|
||||
.arg(Base::Quantity(pos.y, Base::Unit::Length).getUserString())
|
||||
.arg(Base::Quantity(pos.z, Base::Unit::Length).getUserString());
|
||||
return QVariant(data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user