Add PropertyMatrixItem

This commit is contained in:
Sebastian Hoogen 2012-06-12 16:55:20 +02:00 committed by wmayer
parent be4500046c
commit 750129d04c
4 changed files with 444 additions and 0 deletions

View File

@ -185,6 +185,9 @@ public:
/** This method returns a string representation of the property
*/
const Base::Matrix4D &getValue(void) const;
const char* getEditorName(void) const {
return "Gui::PropertyEditor::PropertyMatrixItem";
}
virtual PyObject *getPyObject(void);
virtual void setPyObject(PyObject *);

View File

@ -111,6 +111,7 @@ void Gui::SoFCDB::init()
PropertyBoolItem ::init();
PropertyVectorItem ::init();
PropertyDoubleVectorItem ::init();
PropertyMatrixItem ::init();
PropertyPlacementItem ::init();
PropertyEnumItem ::init();
PropertyStringListItem ::init();

View File

@ -1050,6 +1050,358 @@ void PropertyDoubleVectorItem::setZ(double z)
setData(QVariant::fromValue(Base::Vector3d(x(), y(), z)));
}
// ---------------------------------------------------------------
TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyMatrixItem, Gui::PropertyEditor::PropertyItem);
PropertyMatrixItem::PropertyMatrixItem()
{
const int decimals=16;
m_a11 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a11->setParent(this);
m_a11->setPropertyName(QLatin1String("A11"));
m_a11->setDecimals(decimals);
this->appendChild(m_a11);
m_a12 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a12->setParent(this);
m_a12->setPropertyName(QLatin1String("A12"));
m_a12->setDecimals(decimals);
this->appendChild(m_a12);
m_a13 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a13->setParent(this);
m_a13->setPropertyName(QLatin1String("A13"));
m_a13->setDecimals(decimals);
this->appendChild(m_a13);
m_a14 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a14->setParent(this);
m_a14->setPropertyName(QLatin1String("A14"));
m_a14->setDecimals(decimals);
this->appendChild(m_a14);
m_a21 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a21->setParent(this);
m_a21->setPropertyName(QLatin1String("A21"));
m_a21->setDecimals(decimals);
this->appendChild(m_a21);
m_a22 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a22->setParent(this);
m_a22->setPropertyName(QLatin1String("A22"));
m_a22->setDecimals(decimals);
this->appendChild(m_a22);
m_a23 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a23->setParent(this);
m_a23->setPropertyName(QLatin1String("A23"));
m_a23->setDecimals(decimals);
this->appendChild(m_a23);
m_a24 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a24->setParent(this);
m_a24->setPropertyName(QLatin1String("A24"));
m_a24->setDecimals(decimals);
this->appendChild(m_a24);
m_a31 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a31->setParent(this);
m_a31->setPropertyName(QLatin1String("A31"));
m_a31->setDecimals(decimals);
this->appendChild(m_a31);
m_a32 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a32->setParent(this);
m_a32->setPropertyName(QLatin1String("A32"));
m_a32->setDecimals(decimals);
this->appendChild(m_a32);
m_a33 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a33->setParent(this);
m_a33->setPropertyName(QLatin1String("A33"));
m_a33->setDecimals(decimals);
this->appendChild(m_a33);
m_a34 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a34->setParent(this);
m_a34->setPropertyName(QLatin1String("A34"));
m_a34->setDecimals(decimals);
this->appendChild(m_a34);
m_a41 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a41->setParent(this);
m_a41->setPropertyName(QLatin1String("A41"));
m_a41->setDecimals(decimals);
this->appendChild(m_a41);
m_a42 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a42->setParent(this);
m_a42->setPropertyName(QLatin1String("A42"));
m_a42->setDecimals(decimals);
this->appendChild(m_a42);
m_a43 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a43->setParent(this);
m_a43->setPropertyName(QLatin1String("A43"));
m_a43->setDecimals(decimals);
this->appendChild(m_a43);
m_a44 = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
m_a44->setParent(this);
m_a44->setPropertyName(QLatin1String("A44"));
m_a44->setDecimals(decimals);
this->appendChild(m_a44);
}
QVariant PropertyMatrixItem::toString(const QVariant& prop) const
{
const Base::Matrix4D& value = prop.value<Base::Matrix4D>();
QString text = QString::fromAscii("[%1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15 %16]")
.arg(QLocale::system().toString(value[0][0], 'f', 2)) //(unsigned short usNdx)
.arg(QLocale::system().toString(value[0][1], 'f', 2))
.arg(QLocale::system().toString(value[0][2], 'f', 2))
.arg(QLocale::system().toString(value[0][3], 'f', 2))
.arg(QLocale::system().toString(value[1][0], 'f', 2))
.arg(QLocale::system().toString(value[1][1], 'f', 2))
.arg(QLocale::system().toString(value[1][2], 'f', 2))
.arg(QLocale::system().toString(value[1][3], 'f', 2))
.arg(QLocale::system().toString(value[2][0], 'f', 2))
.arg(QLocale::system().toString(value[2][1], 'f', 2))
.arg(QLocale::system().toString(value[2][2], 'f', 2))
.arg(QLocale::system().toString(value[2][3], 'f', 2))
.arg(QLocale::system().toString(value[3][0], 'f', 2))
.arg(QLocale::system().toString(value[3][1], 'f', 2))
.arg(QLocale::system().toString(value[3][2], 'f', 2))
.arg(QLocale::system().toString(value[3][3], 'f', 2));
return QVariant(text);
}
QVariant PropertyMatrixItem::value(const App::Property* prop) const
{
assert(prop && prop->getTypeId().isDerivedFrom(App::PropertyMatrix::getClassTypeId()));
const Base::Matrix4D& value = static_cast<const App::PropertyMatrix*>(prop)->getValue();
return QVariant::fromValue<Base::Matrix4D>(value);
}
QVariant PropertyMatrixItem::toolTip(const App::Property* prop) const
{
assert(prop && prop->getTypeId().isDerivedFrom(App::PropertyMatrix::getClassTypeId()));
const Base::Matrix4D& value = static_cast<const App::PropertyMatrix*>(prop)->getValue();
return QVariant(QString::fromStdString(value.analyse()));
}
void PropertyMatrixItem::setValue(const QVariant& value)
{
if (!value.canConvert<Base::Matrix4D>())
return;
const Base::Matrix4D& val = value.value<Base::Matrix4D>();
const int decimals=16;
QString data = QString::fromAscii("FreeCAD.Matrix(%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15, %16)")
.arg(val[0][0],0, 'f', decimals)
.arg(val[0][1],0, 'f', decimals)
.arg(val[0][2],0, 'f', decimals)
.arg(val[0][3],0, 'f', decimals)
.arg(val[1][0],0, 'f', decimals)
.arg(val[1][1],0, 'f', decimals)
.arg(val[1][2],0, 'f', decimals)
.arg(val[1][3],0, 'f', decimals)
.arg(val[2][0],0, 'f', decimals)
.arg(val[2][1],0, 'f', decimals)
.arg(val[2][2],0, 'f', decimals)
.arg(val[2][3],0, 'f', decimals)
.arg(val[3][0],0, 'f', decimals)
.arg(val[3][1],0, 'f', decimals)
.arg(val[3][2],0, 'f', decimals)
.arg(val[3][3],0, 'f', decimals);
setPropertyValue(data);
}
QWidget* PropertyMatrixItem::createEditor(QWidget* parent, const QObject* /*receiver*/, const char* /*method*/) const
{
QLineEdit *le = new QLineEdit(parent);
le->setFrame(false);
le->setReadOnly(true);
return le;
}
void PropertyMatrixItem::setEditorData(QWidget *editor, const QVariant& data) const
{
QLineEdit* le = qobject_cast<QLineEdit*>(editor);
const Base::Matrix4D& value = data.value<Base::Matrix4D>();
QString text = QString::fromAscii("[%1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15 %16]")
.arg(QLocale::system().toString(value[0][0], 'f', 2)) //(unsigned short usNdx)
.arg(QLocale::system().toString(value[0][1], 'f', 2))
.arg(QLocale::system().toString(value[0][2], 'f', 2))
.arg(QLocale::system().toString(value[0][3], 'f', 2))
.arg(QLocale::system().toString(value[1][0], 'f', 2))
.arg(QLocale::system().toString(value[1][1], 'f', 2))
.arg(QLocale::system().toString(value[1][2], 'f', 2))
.arg(QLocale::system().toString(value[1][3], 'f', 2))
.arg(QLocale::system().toString(value[2][0], 'f', 2))
.arg(QLocale::system().toString(value[2][1], 'f', 2))
.arg(QLocale::system().toString(value[2][2], 'f', 2))
.arg(QLocale::system().toString(value[2][3], 'f', 2))
.arg(QLocale::system().toString(value[3][0], 'f', 2))
.arg(QLocale::system().toString(value[3][1], 'f', 2))
.arg(QLocale::system().toString(value[3][2], 'f', 2))
.arg(QLocale::system().toString(value[3][3], 'f', 2));
le->setText(text);
}
QVariant PropertyMatrixItem::editorData(QWidget *editor) const
{
QLineEdit *le = qobject_cast<QLineEdit*>(editor);
return QVariant(le->text());
}
double PropertyMatrixItem::getA11() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[0][0];
}
void PropertyMatrixItem::setA11(double A11)
{
setData(QVariant::fromValue(Base::Matrix4D(A11,getA12(),getA13(),getA14(),getA21(),getA22(),getA23(),getA24(),getA31(),getA32(),getA33(),getA34(),getA41(),getA42(),getA43(),getA44() )));
}
double PropertyMatrixItem::getA12() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[0][1];
}
void PropertyMatrixItem::setA12(double A12)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),A12,getA13(),getA14(),getA21(),getA22(),getA23(),getA24(),getA31(),getA32(),getA33(),getA34(),getA41(),getA42(),getA43(),getA44() )));
}
double PropertyMatrixItem::getA13() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[0][2];
}
void PropertyMatrixItem::setA13(double A13)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),A13,getA14(),getA21(),getA22(),getA23(),getA24(),getA31(),getA32(),getA33(),getA34(),getA41(),getA42(),getA43(),getA44() )));
}
double PropertyMatrixItem::getA14() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[0][3];
}
void PropertyMatrixItem::setA14(double A14)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),getA13(),A14,getA21(),getA22(),getA23(),getA24(),getA31(),getA32(),getA33(),getA34(),getA41(),getA42(),getA43(),getA44() )));
}
double PropertyMatrixItem::getA21() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[1][0];
}
void PropertyMatrixItem::setA21(double A21)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),getA13(),getA14(),A21,getA22(),getA23(),getA24(),getA31(),getA32(),getA33(),getA34(),getA41(),getA42(),getA43(),getA44() )));
}
double PropertyMatrixItem::getA22() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[1][1];
}
void PropertyMatrixItem::setA22(double A22)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),getA13(),getA14(),getA21(),A22,getA23(),getA24(),getA31(),getA32(),getA33(),getA34(),getA41(),getA42(),getA43(),getA44() )));
}
double PropertyMatrixItem::getA23() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[1][2];
}
void PropertyMatrixItem::setA23(double A23)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),getA13(),getA14(),getA21(),getA22(),A23,getA24(),getA31(),getA32(),getA33(),getA34(),getA41(),getA42(),getA43(),getA44() )));
}
double PropertyMatrixItem::getA24() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[1][3];
}
void PropertyMatrixItem::setA24(double A24)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),getA13(),getA14(),getA21(),getA22(),getA23(),A24,getA31(),getA32(),getA33(),getA34(),getA41(),getA42(),getA43(),getA44() )));
}
double PropertyMatrixItem::getA31() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[2][0];
}
void PropertyMatrixItem::setA31(double A31)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),getA13(),getA14(),getA21(),getA22(),getA23(),getA24(),A31,getA32(),getA33(),getA34(),getA41(),getA42(),getA43(),getA44() )));
}
double PropertyMatrixItem::getA32() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[2][1];
}
void PropertyMatrixItem::setA32(double A32)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),getA13(),getA14(),getA21(),getA22(),getA23(),getA24(),getA31(),A32,getA33(),getA34(),getA41(),getA42(),getA43(),getA44() )));
}
double PropertyMatrixItem::getA33() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[2][2];
}
void PropertyMatrixItem::setA33(double A33)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),getA13(),getA14(),getA21(),getA22(),getA23(),getA24(),getA31(),getA32(),A33,getA34(),getA41(),getA42(),getA43(),getA44() )));
}
double PropertyMatrixItem::getA34() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[2][3];
}
void PropertyMatrixItem::setA34(double A34)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),getA13(),getA14(),getA21(),getA22(),getA23(),getA24(),getA31(),getA32(),getA33(),A34,getA41(),getA42(),getA43(),getA44() )));
}
double PropertyMatrixItem::getA41() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[3][0];
}
void PropertyMatrixItem::setA41(double A41)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),getA13(),getA14(),getA21(),getA22(),getA23(),getA24(),getA31(),getA32(),getA33(),getA34(),A41,getA42(),getA43(),getA44() )));
}
double PropertyMatrixItem::getA42() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[3][1];
}
void PropertyMatrixItem::setA42(double A42)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),getA13(),getA14(),getA21(),getA22(),getA23(),getA24(),getA31(),getA32(),getA33(),getA34(),getA41(),A42,getA43(),getA44() )));
}
double PropertyMatrixItem::getA43() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[3][2];
}
void PropertyMatrixItem::setA43(double A43)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),getA13(),getA14(),getA21(),getA22(),getA23(),getA24(),getA31(),getA32(),getA33(),getA34(),getA41(),getA42(),A43,getA44() )));
}
double PropertyMatrixItem::getA44() const
{
return data(1,Qt::EditRole).value<Base::Matrix4D>()[3][3];
}
void PropertyMatrixItem::setA44(double A44)
{
setData(QVariant::fromValue(Base::Matrix4D(getA11(),getA12(),getA13(),getA14(),getA21(),getA22(),getA23(),getA24(),getA31(),getA32(),getA33(),getA34(),getA41(),getA42(),getA43(),A44 )));
}
// --------------------------------------------------------------------
PlacementEditor::PlacementEditor(const QString& name, QWidget * parent)

View File

@ -31,6 +31,7 @@
#include <Base/Type.h>
#include <Base/Vector3D.h>
#include <Base/Matrix.h>
#include <Base/Placement.h>
#include <Base/UnitsApi.h>
#include <App/PropertyStandard.h>
@ -38,6 +39,7 @@
Q_DECLARE_METATYPE(Base::Vector3f)
Q_DECLARE_METATYPE(Base::Vector3d)
Q_DECLARE_METATYPE(Base::Matrix4D)
Q_DECLARE_METATYPE(Base::Placement)
namespace Gui {
@ -366,6 +368,92 @@ private:
PropertyFloatItem* m_z;
};
class GuiExport PropertyMatrixItem: public PropertyItem
{
Q_OBJECT
Q_PROPERTY(double A11 READ getA11 WRITE setA11 DESIGNABLE true USER true)
Q_PROPERTY(double A12 READ getA12 WRITE setA12 DESIGNABLE true USER true)
Q_PROPERTY(double A13 READ getA13 WRITE setA13 DESIGNABLE true USER true)
Q_PROPERTY(double A14 READ getA14 WRITE setA14 DESIGNABLE true USER true)
Q_PROPERTY(double A21 READ getA21 WRITE setA21 DESIGNABLE true USER true)
Q_PROPERTY(double A22 READ getA22 WRITE setA22 DESIGNABLE true USER true)
Q_PROPERTY(double A23 READ getA23 WRITE setA23 DESIGNABLE true USER true)
Q_PROPERTY(double A24 READ getA24 WRITE setA24 DESIGNABLE true USER true)
Q_PROPERTY(double A31 READ getA31 WRITE setA31 DESIGNABLE true USER true)
Q_PROPERTY(double A32 READ getA32 WRITE setA32 DESIGNABLE true USER true)
Q_PROPERTY(double A33 READ getA33 WRITE setA33 DESIGNABLE true USER true)
Q_PROPERTY(double A34 READ getA34 WRITE setA34 DESIGNABLE true USER true)
Q_PROPERTY(double A41 READ getA41 WRITE setA41 DESIGNABLE true USER true)
Q_PROPERTY(double A42 READ getA42 WRITE setA42 DESIGNABLE true USER true)
Q_PROPERTY(double A43 READ getA43 WRITE setA43 DESIGNABLE true USER true)
Q_PROPERTY(double A44 READ getA44 WRITE setA44 DESIGNABLE true USER true)
TYPESYSTEM_HEADER();
virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
virtual void setEditorData(QWidget *editor, const QVariant& data) const;
virtual QVariant editorData(QWidget *editor) const;
double getA11() const;
void setA11(double A11);
double getA12() const;
void setA12(double A12);
double getA13() const;
void setA13(double A13);
double getA14() const;
void setA14(double A14);
double getA21() const;
void setA21(double A21);
double getA22() const;
void setA22(double A22);
double getA23() const;
void setA23(double A23);
double getA24() const;
void setA24(double A24);
double getA31() const;
void setA31(double A31);
double getA32() const;
void setA32(double A32);
double getA33() const;
void setA33(double A33);
double getA34() const;
void setA34(double A34);
double getA41() const;
void setA41(double A41);
double getA42() const;
void setA42(double A42);
double getA43() const;
void setA43(double A43);
double getA44() const;
void setA44(double A44);
protected:
virtual QVariant toString(const QVariant&) const;
virtual QVariant value(const App::Property*) const;
virtual void setValue(const QVariant&);
protected:
PropertyMatrixItem();
virtual QVariant toolTip(const App::Property*) const;
private:
PropertyFloatItem* m_a11;
PropertyFloatItem* m_a12;
PropertyFloatItem* m_a13;
PropertyFloatItem* m_a14;
PropertyFloatItem* m_a21;
PropertyFloatItem* m_a22;
PropertyFloatItem* m_a23;
PropertyFloatItem* m_a24;
PropertyFloatItem* m_a31;
PropertyFloatItem* m_a32;
PropertyFloatItem* m_a33;
PropertyFloatItem* m_a34;
PropertyFloatItem* m_a41;
PropertyFloatItem* m_a42;
PropertyFloatItem* m_a43;
PropertyFloatItem* m_a44;
};
class PlacementEditor : public Gui::LabelButton
{
Q_OBJECT