Skip to content

Commit

Permalink
+ prepare property editor for items with unknown number of children
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Aug 17, 2014
1 parent f0eee59 commit 75fa3d4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/Gui/SoFCDB.cpp
Expand Up @@ -138,6 +138,7 @@ void Gui::SoFCDB::init()
qRegisterMetaType<Base::Vector3f>("Base::Vector3f");
qRegisterMetaType<Base::Vector3d>("Base::Vector3d");
qRegisterMetaType<Base::Quantity>("Base::Quantity");
qRegisterMetaType<QList<Base::Quantity> >("Base::QuantityList");
init_done = TRUE;
}

Expand Down
46 changes: 32 additions & 14 deletions src/Gui/propertyeditor/PropertyItem.cpp
Expand Up @@ -68,6 +68,10 @@ PropertyItem::~PropertyItem()
qDeleteAll(childItems);
}

void PropertyItem::initialize()
{
}

void PropertyItem::reset()
{
qDeleteAll(childItems);
Expand All @@ -85,13 +89,28 @@ void PropertyItem::setPropertyData(const std::vector<App::Property*>& items)
ro &= (parent->isReadOnly(*it) || (*it)->StatusBits.test(2));
}
this->setReadOnly(ro);
this->initialize();
}

const std::vector<App::Property*>& PropertyItem::getPropertyData() const
{
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)
{
parentItem = parent;
Expand Down Expand Up @@ -512,11 +531,10 @@ QWidget* PropertyIntegerConstraintItem::createEditor(QWidget* parent, const QObj

void PropertyIntegerConstraintItem::setEditorData(QWidget *editor, const QVariant& /*data*/) const
{
const std::vector<App::Property*>& items = getPropertyData();
App::PropertyIntegerConstraint* prop = (App::PropertyIntegerConstraint*)items[0];
const App::PropertyIntegerConstraint* prop = static_cast
<const App::PropertyIntegerConstraint*>(getFirstProperty());

const App::PropertyIntegerConstraint::Constraints* c =
((App::PropertyIntegerConstraint*)prop)->getConstraints();
const App::PropertyIntegerConstraint::Constraints* c = prop->getConstraints();
QSpinBox *sb = qobject_cast<QSpinBox*>(editor);
if (c) {
sb->setMinimum(c->LowerBound);
Expand Down Expand Up @@ -664,11 +682,10 @@ void PropertyUnitConstraintItem::setEditorData(QWidget *editor, const QVariant&
Gui::QuantitySpinBox *infield = qobject_cast<Gui::QuantitySpinBox*>(editor);
infield->setValue(value);

const std::vector<App::Property*>& items = getPropertyData();
App::PropertyQuantityConstraint* prop = (App::PropertyQuantityConstraint*)items[0];
const App::PropertyQuantityConstraint* prop = static_cast
<const App::PropertyQuantityConstraint*>(getFirstProperty());

const App::PropertyQuantityConstraint::Constraints* c =
((App::PropertyQuantityConstraint*)prop)->getConstraints();
const App::PropertyQuantityConstraint::Constraints* c = prop->getConstraints();

if (c) {
infield->setMinimum(c->LowerBound);
Expand Down Expand Up @@ -724,10 +741,10 @@ QWidget* PropertyFloatConstraintItem::createEditor(QWidget* parent, const QObjec

void PropertyFloatConstraintItem::setEditorData(QWidget *editor, const QVariant& /*data*/) const
{
const std::vector<App::Property*>& items = getPropertyData();
App::PropertyFloatConstraint* prop = (App::PropertyFloatConstraint*)items[0];
const App::PropertyFloatConstraint* prop = static_cast
<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);
if (c) {
sb->setMinimum(c->LowerBound);
Expand Down Expand Up @@ -758,10 +775,11 @@ PropertyAngleItem::PropertyAngleItem()

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 std::vector<App::Property*>& items = getPropertyData();
if (!items.empty()) {
App::PropertyAngle* prop = static_cast<App::PropertyAngle*>(items[0]);
if (prop) {
c = prop->getConstraints();
}

Expand Down
4 changes: 4 additions & 0 deletions src/Gui/propertyeditor/PropertyItem.h
Expand Up @@ -43,6 +43,7 @@ Q_DECLARE_METATYPE(Base::Vector3d)
Q_DECLARE_METATYPE(Base::Matrix4D)
Q_DECLARE_METATYPE(Base::Placement)
Q_DECLARE_METATYPE(Base::Quantity)
Q_DECLARE_METATYPE(QList<Base::Quantity>)

namespace Gui {
namespace Dialog { class TaskPlacement; }
Expand All @@ -60,6 +61,8 @@ class GuiExport PropertyItem : virtual public QObject, public Base::BaseClass
/** Sets the current property objects. */
void setPropertyData( const std::vector<App::Property*>& );
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(). */
virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
Expand Down Expand Up @@ -96,6 +99,7 @@ class GuiExport PropertyItem : virtual public QObject, public Base::BaseClass
virtual QVariant toString(const QVariant&) const;
virtual QVariant value(const App::Property*) const;
virtual void setValue(const QVariant&);
virtual void initialize();
QString pythonIdentifier(const App::Property*) const;

private:
Expand Down
24 changes: 13 additions & 11 deletions src/Mod/Mesh/Gui/PropertyEditorMesh.cpp
Expand Up @@ -41,30 +41,32 @@ PropertyMeshKernelItem::PropertyMeshKernelItem()
(Gui::PropertyEditor::PropertyIntegerItem::create());
m_p->setParent(this);
m_p->setPropertyName(QLatin1String("Points"));
m_p->setReadOnly(true);
this->appendChild(m_p);
m_e = static_cast<Gui::PropertyEditor::PropertyIntegerItem*>
(Gui::PropertyEditor::PropertyIntegerItem::create());
m_e->setParent(this);
m_e->setPropertyName(QLatin1String("Edges"));
m_e->setReadOnly(true);
this->appendChild(m_e);
m_f = static_cast<Gui::PropertyEditor::PropertyIntegerItem*>
(Gui::PropertyEditor::PropertyIntegerItem::create());
m_f->setParent(this);
m_f->setPropertyName(QLatin1String("Faces"));
m_f->setReadOnly(true);
this->appendChild(m_f);
}

void PropertyMeshKernelItem::initialize()
{
this->setReadOnly(true);
}

QVariant PropertyMeshKernelItem::value(const App::Property*) const
{
int ctP = 0;
int ctE = 0;
int ctF = 0;

std::vector<App::Property*> props = getPropertyData();
for ( std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt ) {
const std::vector<App::Property*>& props = getPropertyData();
for (std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt) {
Mesh::PropertyMeshKernel* pPropMesh = (Mesh::PropertyMeshKernel*)(*pt);
const MeshKernel& rMesh = pPropMesh->getValue().getKernel();
ctP += (int)rMesh.CountPoints();
Expand Down Expand Up @@ -102,8 +104,8 @@ QVariant PropertyMeshKernelItem::editorData(QWidget *editor) const
int PropertyMeshKernelItem::countPoints() const
{
int ctP = 0;
std::vector<App::Property*> props = getPropertyData();
for ( std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt ) {
const std::vector<App::Property*>& props = getPropertyData();
for (std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt) {
Mesh::PropertyMeshKernel* pPropMesh = (Mesh::PropertyMeshKernel*)(*pt);
const MeshKernel& rMesh = pPropMesh->getValue().getKernel();
ctP += (int)rMesh.CountPoints();
Expand All @@ -115,8 +117,8 @@ int PropertyMeshKernelItem::countPoints() const
int PropertyMeshKernelItem::countEdges() const
{
int ctE = 0;
std::vector<App::Property*> props = getPropertyData();
for ( std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt ) {
const std::vector<App::Property*>& props = getPropertyData();
for (std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt) {
Mesh::PropertyMeshKernel* pPropMesh = (Mesh::PropertyMeshKernel*)(*pt);
const MeshKernel& rMesh = pPropMesh->getValue().getKernel();
ctE += (int)rMesh.CountEdges();
Expand All @@ -128,8 +130,8 @@ int PropertyMeshKernelItem::countEdges() const
int PropertyMeshKernelItem::countFaces() const
{
int ctF = 0;
std::vector<App::Property*> props = getPropertyData();
for ( std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt ) {
const std::vector<App::Property*>& props = getPropertyData();
for (std::vector<App::Property*>::const_iterator pt = props.begin(); pt != props.end(); ++pt) {
Mesh::PropertyMeshKernel* pPropMesh = (Mesh::PropertyMeshKernel*)(*pt);
const MeshKernel& rMesh = pPropMesh->getValue().getKernel();
ctF += (int)rMesh.CountFacets();
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Mesh/Gui/PropertyEditorMesh.h
Expand Up @@ -54,6 +54,7 @@ class MeshGuiExport PropertyMeshKernelItem : public Gui::PropertyEditor::Propert

protected:
PropertyMeshKernelItem();
void initialize();

private:
Gui::PropertyEditor::PropertyIntegerItem* m_p;
Expand Down

0 comments on commit 75fa3d4

Please sign in to comment.