Skip to content

Commit

Permalink
+ add properties with 'hidden' mode to property editor but hide the item
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Mar 5, 2016
1 parent 843fbc4 commit 0ec81d2
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/Gui/PropertyView.cpp
Expand Up @@ -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())) {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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<PropInfo>::iterator pi = std::find_if(propDataMap.begin(), propDataMap.end(), PropFind(nameType));
if (pi != propDataMap.end()) {
pi->propList.push_back(*pt);
Expand All @@ -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<PropInfo>::iterator pi = std::find_if(propViewMap.begin(), propViewMap.end(), PropFind(nameType));
if (pi != propViewMap.end()) {
pi->propList.push_back(pt->second);
Expand Down
30 changes: 29 additions & 1 deletion src/Gui/propertyeditor/PropertyEditor.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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<PropertyItem*>(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();
Expand Down
6 changes: 5 additions & 1 deletion src/Gui/propertyeditor/PropertyEditor.h
Expand Up @@ -68,11 +68,13 @@ class PropertyEditor : public QTreeView
/** 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);
Expand All @@ -84,10 +86,12 @@ class PropertyEditor : public QTreeView
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:
Expand Down
10 changes: 10 additions & 0 deletions src/Gui/propertyeditor/PropertyItem.cpp
Expand Up @@ -210,6 +210,16 @@ bool PropertyItem::isReadOnly() const
return readonly;
}

bool PropertyItem::testStatus(App::Property::Status pos) const
{
std::vector<App::Property*>::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;
Expand Down
1 change: 1 addition & 0 deletions src/Gui/propertyeditor/PropertyItem.h
Expand Up @@ -87,6 +87,7 @@ class GuiExport PropertyItem : virtual public QObject, public Base::BaseClass, p

void setReadOnly(bool);
bool isReadOnly() const;
bool testStatus(App::Property::Status pos) const;
void setDecimals(int);
int decimals() const;

Expand Down
1 change: 0 additions & 1 deletion src/Gui/propertyeditor/PropertyModel.cpp
Expand Up @@ -262,7 +262,6 @@ void PropertyModel::buildUp(const PropertyModel::PropertyList& props)
}

endResetModel();
// reset();
}

void PropertyModel::updateProperty(const App::Property& prop)
Expand Down

0 comments on commit 0ec81d2

Please sign in to comment.