From 0ec81d2760bdfd8b1a63273cb3e456e0bf1cd58e Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 5 Mar 2016 18:24:58 +0100 Subject: [PATCH] + add properties with 'hidden' mode to property editor but hide the item --- src/Gui/PropertyView.cpp | 10 ++++---- src/Gui/propertyeditor/PropertyEditor.cpp | 30 ++++++++++++++++++++++- src/Gui/propertyeditor/PropertyEditor.h | 6 ++++- src/Gui/propertyeditor/PropertyItem.cpp | 10 ++++++++ src/Gui/propertyeditor/PropertyItem.h | 1 + src/Gui/propertyeditor/PropertyModel.cpp | 1 - 6 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/Gui/PropertyView.cpp b/src/Gui/PropertyView.cpp index 172c87632..35f7f1506 100644 --- a/src/Gui/PropertyView.cpp +++ b/src/Gui/PropertyView.cpp @@ -132,7 +132,7 @@ void PropertyView::slotChangePropertyView(const Gui::ViewProvider&, const App::P void PropertyView::slotAppendDynamicProperty(const App::Property& prop) { App::PropertyContainer* parent = prop.getContainer(); - if (parent->isHidden(&prop) || prop.testStatus(App::Property::Hidden)) + if (parent->isHidden(&prop)) return; if (parent && parent->isDerivedFrom(App::DocumentObject::getClassTypeId())) { @@ -158,10 +158,10 @@ void PropertyView::slotChangePropertyEditor(const App::Property& prop) { App::PropertyContainer* parent = prop.getContainer(); if (parent && parent->isDerivedFrom(App::DocumentObject::getClassTypeId())) { - propertyEditorData->updatetEditorMode(prop); + propertyEditorData->updateEditorMode(prop); } else if (parent && parent->isDerivedFrom(Gui::ViewProvider::getClassTypeId())) { - propertyEditorView->updatetEditorMode(prop); + propertyEditorView->updateEditorMode(prop); } } @@ -220,7 +220,7 @@ void PropertyView::onSelectionChanged(const SelectionChanges& msg) nameType.propName = ob->getPropertyName(*pt); nameType.propId = (*pt)->getTypeId().getKey(); - if (!ob->isHidden(*pt) && !(*pt)->testStatus(App::Property::Hidden)) { + if (!ob->isHidden(*pt)) { std::vector::iterator pi = std::find_if(propDataMap.begin(), propDataMap.end(), PropFind(nameType)); if (pi != propDataMap.end()) { pi->propList.push_back(*pt); @@ -240,7 +240,7 @@ void PropertyView::onSelectionChanged(const SelectionChanges& msg) nameType.propName = pt->first; nameType.propId = pt->second->getTypeId().getKey(); - if (!vp->isHidden(pt->second) && !pt->second->testStatus(App::Property::Hidden)) { + if (!vp->isHidden(pt->second)) { std::vector::iterator pi = std::find_if(propViewMap.begin(), propViewMap.end(), PropFind(nameType)); if (pi != propViewMap.end()) { pi->propList.push_back(pt->second); diff --git a/src/Gui/propertyeditor/PropertyEditor.cpp b/src/Gui/propertyeditor/PropertyEditor.cpp index cf47c026d..d4578324e 100644 --- a/src/Gui/propertyeditor/PropertyEditor.cpp +++ b/src/Gui/propertyeditor/PropertyEditor.cpp @@ -131,6 +131,22 @@ void PropertyEditor::currentChanged ( const QModelIndex & current, const QModelI openPersistentEditor(model()->buddy(current)); } +void PropertyEditor::reset() +{ + QTreeView::reset(); + + QModelIndex index; + int numRows = propertyModel->rowCount(index); + if (numRows > 0) + setEditorMode(index, 0, numRows-1); +} + +void PropertyEditor::rowsInserted (const QModelIndex & parent, int start, int end) +{ + QTreeView::rowsInserted(parent, start, end); + setEditorMode(parent, start, end); +} + void PropertyEditor::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const { QTreeView::drawBranches(painter, rect, index); @@ -178,7 +194,19 @@ void PropertyEditor::updateProperty(const App::Property& prop) propertyModel->updateProperty(prop); } -void PropertyEditor::updatetEditorMode(const App::Property& prop) +void PropertyEditor::setEditorMode(const QModelIndex & parent, int start, int end) +{ + int column = 1; + for (int i=start; i<=end; i++) { + QModelIndex item = propertyModel->index(i, column, parent); + PropertyItem* propItem = static_cast(item.internalPointer()); + if (propItem && propItem->testStatus(App::Property::Hidden)) { + setRowHidden (i, parent, true); + } + } +} + +void PropertyEditor::updateEditorMode(const App::Property& prop) { // check if the parent object is selected std::string editor = prop.getEditorName(); diff --git a/src/Gui/propertyeditor/PropertyEditor.h b/src/Gui/propertyeditor/PropertyEditor.h index 0dbff391e..c4e48cb42 100644 --- a/src/Gui/propertyeditor/PropertyEditor.h +++ b/src/Gui/propertyeditor/PropertyEditor.h @@ -68,11 +68,13 @@ 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 updateEditorMode(const App::Property&); void appendProperty(const App::Property&); void removeProperty(const App::Property&); void setAutomaticDocumentUpdate(bool); bool isAutomaticDocumentUpdate(bool) const; + /*! Reset the internal state of the view. */ + virtual void reset(); QBrush groupBackground() const; void setGroupBackground(const QBrush& c); @@ -84,10 +86,12 @@ protected: virtual void commitData (QWidget * editor); virtual void editorDestroyed (QObject * editor); virtual void currentChanged (const QModelIndex & current, const QModelIndex & previous); + virtual void rowsInserted (const QModelIndex & parent, int start, int end); virtual void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const; virtual QStyleOptionViewItem viewOptions() const; private: + void setEditorMode(const QModelIndex & parent, int start, int end); void updateItemEditor(bool enable, int column, const QModelIndex& parent); private: diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index db8e4c0b2..600f844aa 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -210,6 +210,16 @@ bool PropertyItem::isReadOnly() const return readonly; } +bool PropertyItem::testStatus(App::Property::Status pos) const +{ + std::vector::const_iterator it; + for (it = propertyItems.begin(); it != propertyItems.end(); ++it) { + if ((*it)->testStatus(pos)) + return true; + } + return false; +} + void PropertyItem::setDecimals(int prec) { precision = prec; diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h index 8ce031980..cacd85ef6 100644 --- a/src/Gui/propertyeditor/PropertyItem.h +++ b/src/Gui/propertyeditor/PropertyItem.h @@ -87,6 +87,7 @@ public: void setReadOnly(bool); bool isReadOnly() const; + bool testStatus(App::Property::Status pos) const; void setDecimals(int); int decimals() const; diff --git a/src/Gui/propertyeditor/PropertyModel.cpp b/src/Gui/propertyeditor/PropertyModel.cpp index a1f2f759e..e9ec17030 100644 --- a/src/Gui/propertyeditor/PropertyModel.cpp +++ b/src/Gui/propertyeditor/PropertyModel.cpp @@ -262,7 +262,6 @@ void PropertyModel::buildUp(const PropertyModel::PropertyList& props) } endResetModel(); -// reset(); } void PropertyModel::updateProperty(const App::Property& prop)