+ dynamically hide/show and enable/disable item in property editor
This commit is contained in:
parent
efdbc93e99
commit
948ccac021
|
@ -150,6 +150,8 @@ public:
|
|||
boost::signal<void (const App::Property&)> signalAppendDynamicProperty;
|
||||
/// signal on about removing a dynamic property
|
||||
boost::signal<void (const App::Property&)> signalRemoveDynamicProperty;
|
||||
/// signal on about changing the editor mode of a property
|
||||
boost::signal<void (const App::Property&)> signalChangePropertyEditor;
|
||||
//@}
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "PropertyContainer.h"
|
||||
#include "Property.h"
|
||||
#include "Application.h"
|
||||
|
||||
// inclution of the generated files (generated out of PropertyContainerPy.xml)
|
||||
#include "PropertyContainerPy.h"
|
||||
|
@ -110,9 +111,13 @@ PyObject* PropertyContainerPy::setEditorMode(PyObject *args)
|
|||
return 0;
|
||||
}
|
||||
|
||||
unsigned long status = prop->getStatus();
|
||||
prop->setStatus(Property::ReadOnly,(type & 1) > 0);
|
||||
prop->setStatus(Property::Hidden,(type & 2) > 0);
|
||||
|
||||
if (status != prop->getStatus())
|
||||
GetApplication().signalChangePropertyEditor(*prop);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
|
@ -128,6 +133,7 @@ PyObject* PropertyContainerPy::setEditorMode(PyObject *args)
|
|||
}
|
||||
|
||||
// reset all bits first
|
||||
unsigned long status = prop->getStatus();
|
||||
prop->setStatus(Property::ReadOnly, false);
|
||||
prop->setStatus(Property::Hidden, false);
|
||||
|
||||
|
@ -139,6 +145,9 @@ PyObject* PropertyContainerPy::setEditorMode(PyObject *args)
|
|||
prop->setStatus(Property::Hidden, true);
|
||||
}
|
||||
|
||||
if (status != prop->getStatus())
|
||||
GetApplication().signalChangePropertyEditor(*prop);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,6 +105,9 @@ PropertyView::PropertyView(QWidget *parent)
|
|||
this->connectPropRemove =
|
||||
App::GetApplication().signalRemoveDynamicProperty.connect(boost::bind
|
||||
(&PropertyView::slotRemoveDynamicProperty, this, _1));
|
||||
this->connectPropChange =
|
||||
App::GetApplication().signalChangePropertyEditor.connect(boost::bind
|
||||
(&PropertyView::slotChangePropertyEditor, this, _1));
|
||||
}
|
||||
|
||||
PropertyView::~PropertyView()
|
||||
|
@ -113,6 +116,7 @@ PropertyView::~PropertyView()
|
|||
this->connectPropView.disconnect();
|
||||
this->connectPropAppend.disconnect();
|
||||
this->connectPropRemove.disconnect();
|
||||
this->connectPropChange.disconnect();
|
||||
}
|
||||
|
||||
void PropertyView::slotChangePropertyData(const App::DocumentObject&, const App::Property& prop)
|
||||
|
@ -150,6 +154,17 @@ void PropertyView::slotRemoveDynamicProperty(const App::Property& prop)
|
|||
}
|
||||
}
|
||||
|
||||
void PropertyView::slotChangePropertyEditor(const App::Property& prop)
|
||||
{
|
||||
App::PropertyContainer* parent = prop.getContainer();
|
||||
if (parent && parent->isDerivedFrom(App::DocumentObject::getClassTypeId())) {
|
||||
propertyEditorData->updatetEditorMode(prop);
|
||||
}
|
||||
else if (parent && parent->isDerivedFrom(Gui::ViewProvider::getClassTypeId())) {
|
||||
propertyEditorView->updatetEditorMode(prop);
|
||||
}
|
||||
}
|
||||
|
||||
struct PropertyView::PropInfo
|
||||
{
|
||||
std::string propName;
|
||||
|
|
|
@ -78,6 +78,7 @@ private:
|
|||
void slotChangePropertyView(const Gui::ViewProvider&, const App::Property&);
|
||||
void slotAppendDynamicProperty(const App::Property&);
|
||||
void slotRemoveDynamicProperty(const App::Property&);
|
||||
void slotChangePropertyEditor(const App::Property&);
|
||||
|
||||
private:
|
||||
struct PropInfo;
|
||||
|
@ -87,6 +88,7 @@ private:
|
|||
Connection connectPropView;
|
||||
Connection connectPropAppend;
|
||||
Connection connectPropRemove;
|
||||
Connection connectPropChange;
|
||||
QTabWidget* tabs;
|
||||
};
|
||||
|
||||
|
|
|
@ -178,6 +178,49 @@ void PropertyEditor::updateProperty(const App::Property& prop)
|
|||
propertyModel->updateProperty(prop);
|
||||
}
|
||||
|
||||
void PropertyEditor::updatetEditorMode(const App::Property& prop)
|
||||
{
|
||||
// check if the parent object is selected
|
||||
std::string editor = prop.getEditorName();
|
||||
if (editor.empty())
|
||||
return;
|
||||
|
||||
bool hidden = prop.testStatus(App::Property::Hidden);
|
||||
bool readOnly = prop.testStatus(App::Property::ReadOnly);
|
||||
|
||||
int column = 1;
|
||||
int numRows = propertyModel->rowCount();
|
||||
for (int i=0; i<numRows; i++) {
|
||||
QModelIndex item = propertyModel->index(i, column);
|
||||
PropertyItem* propItem = static_cast<PropertyItem*>(item.internalPointer());
|
||||
if (propItem && propItem->hasProperty(&prop)) {
|
||||
setRowHidden (i, QModelIndex(), hidden);
|
||||
|
||||
propItem->updateData();
|
||||
if (item.isValid()) {
|
||||
updateItemEditor(!readOnly, column, item);
|
||||
dataChanged(item, item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyEditor::updateItemEditor(bool enable, int column, const QModelIndex& parent)
|
||||
{
|
||||
QWidget* editor = indexWidget(parent);
|
||||
if (editor)
|
||||
editor->setEnabled(enable);
|
||||
|
||||
int numRows = propertyModel->rowCount(parent);
|
||||
for (int i=0; i<numRows; i++) {
|
||||
QModelIndex item = propertyModel->index(i, column, parent);
|
||||
if (item.isValid()) {
|
||||
updateItemEditor(enable, column, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyEditor::appendProperty(const App::Property& prop)
|
||||
{
|
||||
// check if the parent object is selected
|
||||
|
|
|
@ -68,6 +68,7 @@ public:
|
|||
/** Builds up the list view with the properties. */
|
||||
void buildUp(const PropertyModel::PropertyList& props);
|
||||
void updateProperty(const App::Property&);
|
||||
void updatetEditorMode(const App::Property&);
|
||||
void appendProperty(const App::Property&);
|
||||
void removeProperty(const App::Property&);
|
||||
void setAutomaticDocumentUpdate(bool);
|
||||
|
@ -86,6 +87,9 @@ protected:
|
|||
virtual void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const;
|
||||
virtual QStyleOptionViewItem viewOptions() const;
|
||||
|
||||
private:
|
||||
void updateItemEditor(bool enable, int column, const QModelIndex& parent);
|
||||
|
||||
private:
|
||||
PropertyModel* propertyModel;
|
||||
QStringList selectedProperty;
|
||||
|
|
Loading…
Reference in New Issue
Block a user