From 5e00309368f4f01434bbfe54cc1d1b9af2b89f48 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 8 Feb 2021 18:53:07 +0100 Subject: [PATCH] Gui: [skip ci] add possibility to auto-expand items in property editor --- src/Gui/PropertyView.cpp | 2 ++ src/Gui/propertyeditor/PropertyEditor.cpp | 31 ++++++++++++++++++++++- src/Gui/propertyeditor/PropertyEditor.h | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Gui/PropertyView.cpp b/src/Gui/PropertyView.cpp index 20a219a41b..eef9f699cb 100644 --- a/src/Gui/PropertyView.cpp +++ b/src/Gui/PropertyView.cpp @@ -96,10 +96,12 @@ PropertyView::PropertyView(QWidget *parent) propertyEditorView = new Gui::PropertyEditor::PropertyEditor(); propertyEditorView->setAutomaticDocumentUpdate(_GetParam()->GetBool("AutoTransactionView", false)); + propertyEditorView->setAutomaticExpand(_GetParam()->GetBool("AutoExpandView", false)); tabs->addTab(propertyEditorView, tr("View")); propertyEditorData = new Gui::PropertyEditor::PropertyEditor(); propertyEditorData->setAutomaticDocumentUpdate(_GetParam()->GetBool("AutoTransactionData", true)); + propertyEditorData->setAutomaticExpand(_GetParam()->GetBool("AutoExpandData", false)); tabs->addTab(propertyEditorData, tr("Data")); int preferredTab = _GetParam()->GetInt("LastTabIndex", 1); diff --git a/src/Gui/propertyeditor/PropertyEditor.cpp b/src/Gui/propertyeditor/PropertyEditor.cpp index 4f6f95e96b..99a4ed4917 100644 --- a/src/Gui/propertyeditor/PropertyEditor.cpp +++ b/src/Gui/propertyeditor/PropertyEditor.cpp @@ -51,7 +51,12 @@ FC_LOG_LEVEL_INIT("PropertyView",true,true) using namespace Gui::PropertyEditor; PropertyEditor::PropertyEditor(QWidget *parent) - : QTreeView(parent), autoupdate(false), committing(false), delaybuild(false), binding(false) + : QTreeView(parent) + , autoexpand(false) + , autoupdate(false) + , committing(false) + , delaybuild(false) + , binding(false) { propertyModel = new PropertyModel(this); setModel(propertyModel); @@ -80,6 +85,16 @@ PropertyEditor::~PropertyEditor() { } +void PropertyEditor::setAutomaticExpand(bool v) +{ + autoexpand = v; +} + +bool PropertyEditor::isAutomaticExpand(bool) const +{ + return autoexpand; +} + void PropertyEditor::setAutomaticDocumentUpdate(bool v) { autoupdate = v; @@ -359,6 +374,9 @@ void PropertyEditor::buildUp(PropertyModel::PropertyList &&props, bool checkDocu propOwners.insert(container); } } + + if (autoexpand) + expandAll(); } void PropertyEditor::updateProperty(const App::Property& prop) @@ -449,6 +467,7 @@ void PropertyEditor::removeProperty(const App::Property& prop) } enum MenuAction { + MA_AutoExpand, MA_ShowAll, MA_Expression, MA_RemoveProp, @@ -464,6 +483,11 @@ enum MenuAction { void PropertyEditor::contextMenuEvent(QContextMenuEvent *) { QMenu menu; + QAction *autoExpand = menu.addAction(tr("Auto expand")); + autoExpand->setCheckable(true); + autoExpand->setChecked(autoexpand); + autoExpand->setData(QVariant(MA_AutoExpand)); + QAction *showAll = menu.addAction(tr("Show all")); showAll->setCheckable(true); showAll->setChecked(PropertyView::showAll()); @@ -556,6 +580,11 @@ void PropertyEditor::contextMenuEvent(QContextMenuEvent *) { return; switch(action->data().toInt()) { + case MA_AutoExpand: + autoexpand = autoExpand->isChecked(); + if (autoexpand) + expandAll(); + return; case MA_ShowAll: PropertyView::setShowAll(action->isChecked()); return; diff --git a/src/Gui/propertyeditor/PropertyEditor.h b/src/Gui/propertyeditor/PropertyEditor.h index 70df5b2128..288bb4a008 100644 --- a/src/Gui/propertyeditor/PropertyEditor.h +++ b/src/Gui/propertyeditor/PropertyEditor.h @@ -77,6 +77,8 @@ public: void updateEditorMode(const App::Property&); bool appendProperty(const App::Property&); void removeProperty(const App::Property&); + void setAutomaticExpand(bool); + bool isAutomaticExpand(bool) const; void setAutomaticDocumentUpdate(bool); bool isAutomaticDocumentUpdate(bool) const; /*! Reset the internal state of the view. */ @@ -115,6 +117,7 @@ private: QStringList selectedProperty; PropertyModel::PropertyList propList; std::unordered_set propOwners; + bool autoexpand; bool autoupdate; bool committing; bool delaybuild;