+ prepare property editor for items with unknown number of children
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,10 @@ PropertyItem::~PropertyItem()
|
||||
qDeleteAll(childItems);
|
||||
}
|
||||
|
||||
void PropertyItem::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void PropertyItem::reset()
|
||||
{
|
||||
qDeleteAll(childItems);
|
||||
@@ -85,6 +89,7 @@ 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
|
||||
@@ -92,6 +97,20 @@ 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;
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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; }
|
||||
@@ -60,6 +61,8 @@ public:
|
||||
/** 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;
|
||||
@@ -96,6 +99,7 @@ protected:
|
||||
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:
|
||||
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
|
||||
@@ -54,6 +54,7 @@ protected:
|
||||
|
||||
protected:
|
||||
PropertyMeshKernelItem();
|
||||
void initialize();
|
||||
|
||||
private:
|
||||
Gui::PropertyEditor::PropertyIntegerItem* m_p;
|
||||
|
||||
Reference in New Issue
Block a user