+ prepare property editor for items with unknown number of children

This commit is contained in:
wmayer
2014-08-17 18:36:27 +02:00
parent f0eee59283
commit 75fa3d4067
5 changed files with 51 additions and 25 deletions

View File

@@ -138,6 +138,7 @@ void Gui::SoFCDB::init()
qRegisterMetaType<Base::Vector3f>("Base::Vector3f"); qRegisterMetaType<Base::Vector3f>("Base::Vector3f");
qRegisterMetaType<Base::Vector3d>("Base::Vector3d"); qRegisterMetaType<Base::Vector3d>("Base::Vector3d");
qRegisterMetaType<Base::Quantity>("Base::Quantity"); qRegisterMetaType<Base::Quantity>("Base::Quantity");
qRegisterMetaType<QList<Base::Quantity> >("Base::QuantityList");
init_done = TRUE; init_done = TRUE;
} }

View File

@@ -68,6 +68,10 @@ PropertyItem::~PropertyItem()
qDeleteAll(childItems); qDeleteAll(childItems);
} }
void PropertyItem::initialize()
{
}
void PropertyItem::reset() void PropertyItem::reset()
{ {
qDeleteAll(childItems); qDeleteAll(childItems);
@@ -85,6 +89,7 @@ void PropertyItem::setPropertyData(const std::vector<App::Property*>& items)
ro &= (parent->isReadOnly(*it) || (*it)->StatusBits.test(2)); ro &= (parent->isReadOnly(*it) || (*it)->StatusBits.test(2));
} }
this->setReadOnly(ro); this->setReadOnly(ro);
this->initialize();
} }
const std::vector<App::Property*>& PropertyItem::getPropertyData() const const std::vector<App::Property*>& PropertyItem::getPropertyData() const
@@ -92,6 +97,20 @@ const std::vector<App::Property*>& PropertyItem::getPropertyData() const
return propertyItems; return propertyItems;
} }
App::Property* PropertyItem::getFirstProperty()
{
if (propertyItems.empty())
return 0;
return propertyItems.front();
}
const App::Property* PropertyItem::getFirstProperty() const
{
if (propertyItems.empty())
return 0;
return propertyItems.front();
}
void PropertyItem::setParent(PropertyItem* parent) void PropertyItem::setParent(PropertyItem* parent)
{ {
parentItem = parent; parentItem = parent;
@@ -512,11 +531,10 @@ QWidget* PropertyIntegerConstraintItem::createEditor(QWidget* parent, const QObj
void PropertyIntegerConstraintItem::setEditorData(QWidget *editor, const QVariant& /*data*/) const void PropertyIntegerConstraintItem::setEditorData(QWidget *editor, const QVariant& /*data*/) const
{ {
const std::vector<App::Property*>& items = getPropertyData(); const App::PropertyIntegerConstraint* prop = static_cast
App::PropertyIntegerConstraint* prop = (App::PropertyIntegerConstraint*)items[0]; <const App::PropertyIntegerConstraint*>(getFirstProperty());
const App::PropertyIntegerConstraint::Constraints* c = const App::PropertyIntegerConstraint::Constraints* c = prop->getConstraints();
((App::PropertyIntegerConstraint*)prop)->getConstraints();
QSpinBox *sb = qobject_cast<QSpinBox*>(editor); QSpinBox *sb = qobject_cast<QSpinBox*>(editor);
if (c) { if (c) {
sb->setMinimum(c->LowerBound); sb->setMinimum(c->LowerBound);
@@ -664,11 +682,10 @@ void PropertyUnitConstraintItem::setEditorData(QWidget *editor, const QVariant&
Gui::QuantitySpinBox *infield = qobject_cast<Gui::QuantitySpinBox*>(editor); Gui::QuantitySpinBox *infield = qobject_cast<Gui::QuantitySpinBox*>(editor);
infield->setValue(value); infield->setValue(value);
const std::vector<App::Property*>& items = getPropertyData(); const App::PropertyQuantityConstraint* prop = static_cast
App::PropertyQuantityConstraint* prop = (App::PropertyQuantityConstraint*)items[0]; <const App::PropertyQuantityConstraint*>(getFirstProperty());
const App::PropertyQuantityConstraint::Constraints* c = const App::PropertyQuantityConstraint::Constraints* c = prop->getConstraints();
((App::PropertyQuantityConstraint*)prop)->getConstraints();
if (c) { if (c) {
infield->setMinimum(c->LowerBound); infield->setMinimum(c->LowerBound);
@@ -724,10 +741,10 @@ QWidget* PropertyFloatConstraintItem::createEditor(QWidget* parent, const QObjec
void PropertyFloatConstraintItem::setEditorData(QWidget *editor, const QVariant& /*data*/) const void PropertyFloatConstraintItem::setEditorData(QWidget *editor, const QVariant& /*data*/) const
{ {
const std::vector<App::Property*>& items = getPropertyData(); const App::PropertyFloatConstraint* prop = static_cast
App::PropertyFloatConstraint* prop = (App::PropertyFloatConstraint*)items[0]; <const App::PropertyFloatConstraint*>(getFirstProperty());
const App::PropertyFloatConstraint::Constraints* c = ((App::PropertyFloatConstraint*)prop)->getConstraints(); const App::PropertyFloatConstraint::Constraints* c = prop->getConstraints();
QDoubleSpinBox *sb = qobject_cast<QDoubleSpinBox*>(editor); QDoubleSpinBox *sb = qobject_cast<QDoubleSpinBox*>(editor);
if (c) { if (c) {
sb->setMinimum(c->LowerBound); sb->setMinimum(c->LowerBound);
@@ -758,10 +775,11 @@ PropertyAngleItem::PropertyAngleItem()
void PropertyAngleItem::setEditorData(QWidget *editor, const QVariant& data) const void PropertyAngleItem::setEditorData(QWidget *editor, const QVariant& data) const
{ {
const App::PropertyQuantityConstraint* prop = static_cast
<const App::PropertyQuantityConstraint*>(getFirstProperty());
const App::PropertyQuantityConstraint::Constraints* c = 0; const App::PropertyQuantityConstraint::Constraints* c = 0;
const std::vector<App::Property*>& items = getPropertyData(); if (prop) {
if (!items.empty()) {
App::PropertyAngle* prop = static_cast<App::PropertyAngle*>(items[0]);
c = prop->getConstraints(); c = prop->getConstraints();
} }

View File

@@ -43,6 +43,7 @@ Q_DECLARE_METATYPE(Base::Vector3d)
Q_DECLARE_METATYPE(Base::Matrix4D) Q_DECLARE_METATYPE(Base::Matrix4D)
Q_DECLARE_METATYPE(Base::Placement) Q_DECLARE_METATYPE(Base::Placement)
Q_DECLARE_METATYPE(Base::Quantity) Q_DECLARE_METATYPE(Base::Quantity)
Q_DECLARE_METATYPE(QList<Base::Quantity>)
namespace Gui { namespace Gui {
namespace Dialog { class TaskPlacement; } namespace Dialog { class TaskPlacement; }
@@ -60,6 +61,8 @@ public:
/** Sets the current property objects. */ /** Sets the current property objects. */
void setPropertyData( const std::vector<App::Property*>& ); void setPropertyData( const std::vector<App::Property*>& );
const std::vector<App::Property*>& getPropertyData() const; const std::vector<App::Property*>& getPropertyData() const;
App::Property* getFirstProperty();
const App::Property* getFirstProperty() const;
/** Creates the appropriate editor for this item and sets the editor to the value of overrideValue(). */ /** Creates the appropriate editor for this item and sets the editor to the value of overrideValue(). */
virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const; virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
@@ -96,6 +99,7 @@ protected:
virtual QVariant toString(const QVariant&) const; virtual QVariant toString(const QVariant&) const;
virtual QVariant value(const App::Property*) const; virtual QVariant value(const App::Property*) const;
virtual void setValue(const QVariant&); virtual void setValue(const QVariant&);
virtual void initialize();
QString pythonIdentifier(const App::Property*) const; QString pythonIdentifier(const App::Property*) const;
private: private:

View File

@@ -41,29 +41,31 @@ PropertyMeshKernelItem::PropertyMeshKernelItem()
(Gui::PropertyEditor::PropertyIntegerItem::create()); (Gui::PropertyEditor::PropertyIntegerItem::create());
m_p->setParent(this); m_p->setParent(this);
m_p->setPropertyName(QLatin1String("Points")); m_p->setPropertyName(QLatin1String("Points"));
m_p->setReadOnly(true);
this->appendChild(m_p); this->appendChild(m_p);
m_e = static_cast<Gui::PropertyEditor::PropertyIntegerItem*> m_e = static_cast<Gui::PropertyEditor::PropertyIntegerItem*>
(Gui::PropertyEditor::PropertyIntegerItem::create()); (Gui::PropertyEditor::PropertyIntegerItem::create());
m_e->setParent(this); m_e->setParent(this);
m_e->setPropertyName(QLatin1String("Edges")); m_e->setPropertyName(QLatin1String("Edges"));
m_e->setReadOnly(true);
this->appendChild(m_e); this->appendChild(m_e);
m_f = static_cast<Gui::PropertyEditor::PropertyIntegerItem*> m_f = static_cast<Gui::PropertyEditor::PropertyIntegerItem*>
(Gui::PropertyEditor::PropertyIntegerItem::create()); (Gui::PropertyEditor::PropertyIntegerItem::create());
m_f->setParent(this); m_f->setParent(this);
m_f->setPropertyName(QLatin1String("Faces")); m_f->setPropertyName(QLatin1String("Faces"));
m_f->setReadOnly(true);
this->appendChild(m_f); this->appendChild(m_f);
} }
void PropertyMeshKernelItem::initialize()
{
this->setReadOnly(true);
}
QVariant PropertyMeshKernelItem::value(const App::Property*) const QVariant PropertyMeshKernelItem::value(const App::Property*) const
{ {
int ctP = 0; int ctP = 0;
int ctE = 0; int ctE = 0;
int ctF = 0; int ctF = 0;
std::vector<App::Property*> props = getPropertyData(); const std::vector<App::Property*>& props = getPropertyData();
for (std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt) { for (std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt) {
Mesh::PropertyMeshKernel* pPropMesh = (Mesh::PropertyMeshKernel*)(*pt); Mesh::PropertyMeshKernel* pPropMesh = (Mesh::PropertyMeshKernel*)(*pt);
const MeshKernel& rMesh = pPropMesh->getValue().getKernel(); const MeshKernel& rMesh = pPropMesh->getValue().getKernel();
@@ -102,7 +104,7 @@ QVariant PropertyMeshKernelItem::editorData(QWidget *editor) const
int PropertyMeshKernelItem::countPoints() const int PropertyMeshKernelItem::countPoints() const
{ {
int ctP = 0; int ctP = 0;
std::vector<App::Property*> props = getPropertyData(); const std::vector<App::Property*>& props = getPropertyData();
for (std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt) { for (std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt) {
Mesh::PropertyMeshKernel* pPropMesh = (Mesh::PropertyMeshKernel*)(*pt); Mesh::PropertyMeshKernel* pPropMesh = (Mesh::PropertyMeshKernel*)(*pt);
const MeshKernel& rMesh = pPropMesh->getValue().getKernel(); const MeshKernel& rMesh = pPropMesh->getValue().getKernel();
@@ -115,7 +117,7 @@ int PropertyMeshKernelItem::countPoints() const
int PropertyMeshKernelItem::countEdges() const int PropertyMeshKernelItem::countEdges() const
{ {
int ctE = 0; int ctE = 0;
std::vector<App::Property*> props = getPropertyData(); const std::vector<App::Property*>& props = getPropertyData();
for (std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt) { for (std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt) {
Mesh::PropertyMeshKernel* pPropMesh = (Mesh::PropertyMeshKernel*)(*pt); Mesh::PropertyMeshKernel* pPropMesh = (Mesh::PropertyMeshKernel*)(*pt);
const MeshKernel& rMesh = pPropMesh->getValue().getKernel(); const MeshKernel& rMesh = pPropMesh->getValue().getKernel();
@@ -128,7 +130,7 @@ int PropertyMeshKernelItem::countEdges() const
int PropertyMeshKernelItem::countFaces() const int PropertyMeshKernelItem::countFaces() const
{ {
int ctF = 0; int ctF = 0;
std::vector<App::Property*> props = getPropertyData(); const std::vector<App::Property*>& props = getPropertyData();
for (std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt) { for (std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt) {
Mesh::PropertyMeshKernel* pPropMesh = (Mesh::PropertyMeshKernel*)(*pt); Mesh::PropertyMeshKernel* pPropMesh = (Mesh::PropertyMeshKernel*)(*pt);
const MeshKernel& rMesh = pPropMesh->getValue().getKernel(); const MeshKernel& rMesh = pPropMesh->getValue().getKernel();

View File

@@ -54,6 +54,7 @@ protected:
protected: protected:
PropertyMeshKernelItem(); PropertyMeshKernelItem();
void initialize();
private: private:
Gui::PropertyEditor::PropertyIntegerItem* m_p; Gui::PropertyEditor::PropertyIntegerItem* m_p;