From 56bf4e7ebdb258b61eadd3563de6afbd3aaca6f1 Mon Sep 17 00:00:00 2001 From: Paddle Date: Wed, 17 Jan 2024 17:00:55 +0100 Subject: [PATCH 1/3] Core : Tree: Add 'Properties' action in contextual menu. Opens a property dialog. --- src/Gui/PropertyView.cpp | 6 ++--- src/Gui/PropertyView.h | 2 +- src/Gui/Tree.cpp | 27 +++++++++++++++++++++++ src/Gui/Tree.h | 2 ++ src/Gui/propertyeditor/PropertyEditor.cpp | 6 ++++- src/Gui/propertyeditor/PropertyEditor.h | 2 +- 6 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/Gui/PropertyView.cpp b/src/Gui/PropertyView.cpp index 535f54fa2c..fb0dda47d1 100644 --- a/src/Gui/PropertyView.cpp +++ b/src/Gui/PropertyView.cpp @@ -67,7 +67,7 @@ static ParameterGrp::handle _GetParam() { * Provides two Gui::PropertyEditor::PropertyEditor widgets, for "View" and "Data", * in two tabs. */ -PropertyView::PropertyView(QWidget *parent) +PropertyView::PropertyView(QWidget *parent, int sizeOfFirstColumn) : QWidget(parent), SelectionObserver(false, ResolveMode::NoResolve) { auto pLayout = new QGridLayout( this ); @@ -83,12 +83,12 @@ PropertyView::PropertyView(QWidget *parent) tabs->setTabPosition(QTabWidget::South); pLayout->addWidget(tabs, 0, 0); - propertyEditorView = new Gui::PropertyEditor::PropertyEditor(); + propertyEditorView = new Gui::PropertyEditor::PropertyEditor(parent, sizeOfFirstColumn); propertyEditorView->setAutomaticDocumentUpdate(_GetParam()->GetBool("AutoTransactionView", false)); propertyEditorView->setAutomaticExpand(_GetParam()->GetBool("AutoExpandView", false)); tabs->addTab(propertyEditorView, tr("View")); - propertyEditorData = new Gui::PropertyEditor::PropertyEditor(); + propertyEditorData = new Gui::PropertyEditor::PropertyEditor(parent, sizeOfFirstColumn); propertyEditorData->setAutomaticDocumentUpdate(_GetParam()->GetBool("AutoTransactionData", true)); propertyEditorData->setAutomaticExpand(_GetParam()->GetBool("AutoExpandData", false)); tabs->addTab(propertyEditorData, tr("Data")); diff --git a/src/Gui/PropertyView.h b/src/Gui/PropertyView.h index a058fcd04e..cf539df318 100644 --- a/src/Gui/PropertyView.h +++ b/src/Gui/PropertyView.h @@ -56,7 +56,7 @@ class PropertyView : public QWidget, public Gui::SelectionObserver Q_OBJECT public: - explicit PropertyView(QWidget *parent=nullptr); + explicit PropertyView(QWidget *parent=nullptr, int sizeOfFirstColumn = 0); ~PropertyView() override; Gui::PropertyEditor::PropertyEditor* propertyEditorView; diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 4a657680d4..3b2cc0717c 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -61,6 +61,7 @@ #include "Macro.h" #include "MainWindow.h" #include "MenuManager.h" +#include "PropertyView.h" #include "TreeParams.h" #include "View3DInventor.h" #include "ViewProviderDocumentObject.h" @@ -523,6 +524,13 @@ TreeWidget::TreeWidget(const char* name, QWidget* parent) connect(this->relabelObjectAction, &QAction::triggered, this, &TreeWidget::onRelabelObject); + this->objectPropertyAction = new QAction(this); +#ifndef Q_OS_MAC + this->objectPropertyAction->setShortcut(Qt::Key_F6); +#endif + connect(this->objectPropertyAction, &QAction::triggered, + this, &TreeWidget::onObjectProperty); + this->finishEditingAction = new QAction(this); connect(this->finishEditingAction, &QAction::triggered, this, &TreeWidget::onFinishEditing); @@ -961,6 +969,7 @@ void TreeWidget::contextMenuEvent(QContextMenuEvent* e) // relabeling is only possible for a single selected document if (SelectedObjectsList.size() == 1) contextMenu.addAction(this->relabelObjectAction); + contextMenu.addAction(this->objectPropertyAction); auto selItems = this->selectedItems(); // if only one item is selected, setup the edit menu @@ -1082,6 +1091,21 @@ void TreeWidget::onRelabelObject() editItem(item); } +void TreeWidget::onObjectProperty() +{ + int sizeOfFirstColumn = 200; + auto prop = new PropertyView(this, sizeOfFirstColumn); + QDialog* propertyDialog = new QDialog(this); + propertyDialog->setWindowTitle(QString::fromLatin1("Properties")); + propertyDialog->resize(700, 500); + QVBoxLayout* layout = new QVBoxLayout(propertyDialog); + layout->addWidget(prop); + propertyDialog->setLayout(layout); + QPoint cursorPos = QCursor::pos() - QPoint(0, 300); + propertyDialog->move(cursorPos); + propertyDialog->show(); +} + void TreeWidget::onStartEditing() { auto action = qobject_cast(sender()); @@ -2965,6 +2989,9 @@ void TreeWidget::setupText() this->relabelObjectAction->setText(tr("Rename")); this->relabelObjectAction->setStatusTip(tr("Rename object")); + this->objectPropertyAction->setText(tr("Properties")); + this->objectPropertyAction->setStatusTip(tr("Properties of the selected object")); + this->finishEditingAction->setText(tr("Finish editing")); this->finishEditingAction->setStatusTip(tr("Finish editing object")); diff --git a/src/Gui/Tree.h b/src/Gui/Tree.h index 6d35edfec2..877cddf664 100644 --- a/src/Gui/Tree.h +++ b/src/Gui/Tree.h @@ -154,6 +154,7 @@ protected: protected Q_SLOTS: void onCreateGroup(); void onRelabelObject(); + void onObjectProperty(); void onActivateDocument(QAction*); void onStartEditing(); void onFinishEditing(); @@ -208,6 +209,7 @@ private: private: QAction* createGroupAction; QAction* relabelObjectAction; + QAction* objectPropertyAction; QAction* finishEditingAction; QAction* selectDependentsAction; QAction* skipRecomputeAction; diff --git a/src/Gui/propertyeditor/PropertyEditor.cpp b/src/Gui/propertyeditor/PropertyEditor.cpp index b0b0e3489b..184d0420dd 100644 --- a/src/Gui/propertyeditor/PropertyEditor.cpp +++ b/src/Gui/propertyeditor/PropertyEditor.cpp @@ -51,7 +51,7 @@ FC_LOG_LEVEL_INIT("PropertyView", true, true) using namespace Gui::PropertyEditor; -PropertyEditor::PropertyEditor(QWidget *parent) +PropertyEditor::PropertyEditor(QWidget *parent, int sizeOfFirstColumn) : QTreeView(parent) , autoexpand(false) , autoupdate(false) @@ -99,6 +99,10 @@ PropertyEditor::PropertyEditor(QWidget *parent) setHeaderHidden(true); viewport()->installEventFilter(this); viewport()->setMouseTracking(true); + + if (sizeOfFirstColumn != 0) { + header()->resizeSection(0, sizeOfFirstColumn); + } } PropertyEditor::~PropertyEditor() diff --git a/src/Gui/propertyeditor/PropertyEditor.h b/src/Gui/propertyeditor/PropertyEditor.h index bd01c2f99e..5c5342d129 100644 --- a/src/Gui/propertyeditor/PropertyEditor.h +++ b/src/Gui/propertyeditor/PropertyEditor.h @@ -67,7 +67,7 @@ class PropertyEditor : public QTreeView Q_PROPERTY(QBrush itemBackground READ itemBackground WRITE setItemBackground DESIGNABLE true SCRIPTABLE true) // clazy:exclude=qproperty-without-notify public: - PropertyEditor(QWidget *parent = nullptr); + PropertyEditor(QWidget *parent = nullptr, int sizeOfFirstColumn = 0); ~PropertyEditor() override; /** Builds up the list view with the properties. */ From 21905c0d624c51013554cb2583ef090e739e7491 Mon Sep 17 00:00:00 2001 From: Paddle Date: Fri, 19 Jan 2024 10:26:00 +0100 Subject: [PATCH 2/3] Core: add property command, that shows property view. --- src/Gui/CommandDoc.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/Gui/Tree.cpp | 31 ++----------------------------- src/Gui/Tree.h | 2 -- src/Gui/Workbench.cpp | 2 +- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index 6e1ffefefc..55d4b91d64 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -50,6 +50,7 @@ #include "BitmapFactory.h" #include "Command.h" #include "Control.h" +#include "DockWindowManager.h" #include "FileDialog.h" #include "MainWindow.h" #include "Selection.h" @@ -1715,6 +1716,41 @@ bool StdCmdEdit::isActive() return (!Selection().getCompleteSelection().empty()) || (Gui::Control().activeDialog() != nullptr); } +//=========================================================================== +// Std_Properties +//=========================================================================== +DEF_STD_CMD_A(StdCmdProperties) + +StdCmdProperties::StdCmdProperties() + : Command("Std_Properties") +{ + sGroup = "Edit"; + sMenuText = QT_TR_NOOP("Properties"); + sToolTipText = QT_TR_NOOP("Show the property view, which displays the properties of the selected object."); + sWhatsThis = "Std_Properties"; + sStatusTip = sToolTipText; + sAccel = "Alt+Return"; + sPixmap = "document-properties"; + eType = Alter3DView; +} + +void StdCmdProperties::activated(int iMsg) +{ + Q_UNUSED(iMsg); + QWidget* propertyView = Gui::DockWindowManager::instance()->getDockWindow("Property view"); + if (propertyView) { + QWidget* parent = propertyView->parentWidget(); + if (parent && !parent->isVisible()) { + parent->show(); + } + } +} + +bool StdCmdProperties::isActive() +{ + return !Selection().getCompleteSelection().empty(); +} + //====================================================================== // StdCmdExpression //=========================================================================== @@ -1969,6 +2005,7 @@ void CreateDocCommands() rcCmdMgr.addCommand(new StdCmdTransformManip()); rcCmdMgr.addCommand(new StdCmdAlignment()); rcCmdMgr.addCommand(new StdCmdEdit()); + rcCmdMgr.addCommand(new StdCmdProperties()); rcCmdMgr.addCommand(new StdCmdExpression()); } diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 3b2cc0717c..212eb7db24 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -524,13 +524,6 @@ TreeWidget::TreeWidget(const char* name, QWidget* parent) connect(this->relabelObjectAction, &QAction::triggered, this, &TreeWidget::onRelabelObject); - this->objectPropertyAction = new QAction(this); -#ifndef Q_OS_MAC - this->objectPropertyAction->setShortcut(Qt::Key_F6); -#endif - connect(this->objectPropertyAction, &QAction::triggered, - this, &TreeWidget::onObjectProperty); - this->finishEditingAction = new QAction(this); connect(this->finishEditingAction, &QAction::triggered, this, &TreeWidget::onFinishEditing); @@ -889,7 +882,7 @@ void TreeWidget::contextMenuEvent(QContextMenuEvent* e) MenuItem view; Gui::Application::Instance->setupContextMenu("Tree", &view); - view << "Std_Expressions"; + view << "Std_Properties" << "Separator" << "Std_Expressions"; Workbench::createLinkMenu(&view); QMenu contextMenu; @@ -898,8 +891,7 @@ void TreeWidget::contextMenuEvent(QContextMenuEvent* e) QMenu editMenu; QActionGroup subMenuGroup(&subMenu); subMenuGroup.setExclusive(true); - connect(&subMenuGroup, &QActionGroup::triggered, - this, &TreeWidget::onActivateDocument); + connect(&subMenuGroup, &QActionGroup::triggered, this, &TreeWidget::onActivateDocument); MenuManager::getInstance()->setupContextMenu(&view, contextMenu); // get the current item @@ -969,7 +961,6 @@ void TreeWidget::contextMenuEvent(QContextMenuEvent* e) // relabeling is only possible for a single selected document if (SelectedObjectsList.size() == 1) contextMenu.addAction(this->relabelObjectAction); - contextMenu.addAction(this->objectPropertyAction); auto selItems = this->selectedItems(); // if only one item is selected, setup the edit menu @@ -1091,21 +1082,6 @@ void TreeWidget::onRelabelObject() editItem(item); } -void TreeWidget::onObjectProperty() -{ - int sizeOfFirstColumn = 200; - auto prop = new PropertyView(this, sizeOfFirstColumn); - QDialog* propertyDialog = new QDialog(this); - propertyDialog->setWindowTitle(QString::fromLatin1("Properties")); - propertyDialog->resize(700, 500); - QVBoxLayout* layout = new QVBoxLayout(propertyDialog); - layout->addWidget(prop); - propertyDialog->setLayout(layout); - QPoint cursorPos = QCursor::pos() - QPoint(0, 300); - propertyDialog->move(cursorPos); - propertyDialog->show(); -} - void TreeWidget::onStartEditing() { auto action = qobject_cast(sender()); @@ -2989,9 +2965,6 @@ void TreeWidget::setupText() this->relabelObjectAction->setText(tr("Rename")); this->relabelObjectAction->setStatusTip(tr("Rename object")); - this->objectPropertyAction->setText(tr("Properties")); - this->objectPropertyAction->setStatusTip(tr("Properties of the selected object")); - this->finishEditingAction->setText(tr("Finish editing")); this->finishEditingAction->setStatusTip(tr("Finish editing object")); diff --git a/src/Gui/Tree.h b/src/Gui/Tree.h index 877cddf664..6d35edfec2 100644 --- a/src/Gui/Tree.h +++ b/src/Gui/Tree.h @@ -154,7 +154,6 @@ protected: protected Q_SLOTS: void onCreateGroup(); void onRelabelObject(); - void onObjectProperty(); void onActivateDocument(QAction*); void onStartEditing(); void onFinishEditing(); @@ -209,7 +208,6 @@ private: private: QAction* createGroupAction; QAction* relabelObjectAction; - QAction* objectPropertyAction; QAction* finishEditingAction; QAction* selectDependentsAction; QAction* skipRecomputeAction; diff --git a/src/Gui/Workbench.cpp b/src/Gui/Workbench.cpp index 3f03d97a57..131e938f98 100644 --- a/src/Gui/Workbench.cpp +++ b/src/Gui/Workbench.cpp @@ -647,7 +647,7 @@ MenuItem* StdWorkbench::setupMenuBar() const << "Std_Refresh" << "Std_BoxSelection" << "Std_BoxElementSelection" << "Std_SelectAll" << "Std_Delete" << "Std_SendToPythonConsole" << "Separator" << "Std_Placement" << "Std_TransformManip" << "Std_Alignment" - << "Std_Edit" << "Separator" << "Std_UserEditMode" << "Separator" << "Std_DlgPreferences"; + << "Std_Edit" << "Std_Properties" << "Separator" << "Std_UserEditMode" << "Separator" << "Std_DlgPreferences"; auto axoviews = new MenuItem; axoviews->setCommand("Axonometric"); From f7798327cf9a9c35752bb45fdfd17aeed6145933 Mon Sep 17 00:00:00 2001 From: Paddle Date: Fri, 19 Jan 2024 10:47:10 +0100 Subject: [PATCH 3/3] Core: PropertyEditor : save properly the size of the first column. --- src/Gui/PropertyView.cpp | 6 +++--- src/Gui/PropertyView.h | 2 +- src/Gui/Tree.cpp | 4 ++-- src/Gui/propertyeditor/PropertyEditor.cpp | 11 ++++++++--- src/Gui/propertyeditor/PropertyEditor.h | 2 +- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Gui/PropertyView.cpp b/src/Gui/PropertyView.cpp index fb0dda47d1..535f54fa2c 100644 --- a/src/Gui/PropertyView.cpp +++ b/src/Gui/PropertyView.cpp @@ -67,7 +67,7 @@ static ParameterGrp::handle _GetParam() { * Provides two Gui::PropertyEditor::PropertyEditor widgets, for "View" and "Data", * in two tabs. */ -PropertyView::PropertyView(QWidget *parent, int sizeOfFirstColumn) +PropertyView::PropertyView(QWidget *parent) : QWidget(parent), SelectionObserver(false, ResolveMode::NoResolve) { auto pLayout = new QGridLayout( this ); @@ -83,12 +83,12 @@ PropertyView::PropertyView(QWidget *parent, int sizeOfFirstColumn) tabs->setTabPosition(QTabWidget::South); pLayout->addWidget(tabs, 0, 0); - propertyEditorView = new Gui::PropertyEditor::PropertyEditor(parent, sizeOfFirstColumn); + 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(parent, sizeOfFirstColumn); + propertyEditorData = new Gui::PropertyEditor::PropertyEditor(); propertyEditorData->setAutomaticDocumentUpdate(_GetParam()->GetBool("AutoTransactionData", true)); propertyEditorData->setAutomaticExpand(_GetParam()->GetBool("AutoExpandData", false)); tabs->addTab(propertyEditorData, tr("Data")); diff --git a/src/Gui/PropertyView.h b/src/Gui/PropertyView.h index cf539df318..a058fcd04e 100644 --- a/src/Gui/PropertyView.h +++ b/src/Gui/PropertyView.h @@ -56,7 +56,7 @@ class PropertyView : public QWidget, public Gui::SelectionObserver Q_OBJECT public: - explicit PropertyView(QWidget *parent=nullptr, int sizeOfFirstColumn = 0); + explicit PropertyView(QWidget *parent=nullptr); ~PropertyView() override; Gui::PropertyEditor::PropertyEditor* propertyEditorView; diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 212eb7db24..fe830d468f 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -61,7 +61,6 @@ #include "Macro.h" #include "MainWindow.h" #include "MenuManager.h" -#include "PropertyView.h" #include "TreeParams.h" #include "View3DInventor.h" #include "ViewProviderDocumentObject.h" @@ -891,7 +890,8 @@ void TreeWidget::contextMenuEvent(QContextMenuEvent* e) QMenu editMenu; QActionGroup subMenuGroup(&subMenu); subMenuGroup.setExclusive(true); - connect(&subMenuGroup, &QActionGroup::triggered, this, &TreeWidget::onActivateDocument); + connect(&subMenuGroup, &QActionGroup::triggered, + this, &TreeWidget::onActivateDocument); MenuManager::getInstance()->setupContextMenu(&view, contextMenu); // get the current item diff --git a/src/Gui/propertyeditor/PropertyEditor.cpp b/src/Gui/propertyeditor/PropertyEditor.cpp index 184d0420dd..e9aa88ca2d 100644 --- a/src/Gui/propertyeditor/PropertyEditor.cpp +++ b/src/Gui/propertyeditor/PropertyEditor.cpp @@ -51,7 +51,7 @@ FC_LOG_LEVEL_INIT("PropertyView", true, true) using namespace Gui::PropertyEditor; -PropertyEditor::PropertyEditor(QWidget *parent, int sizeOfFirstColumn) +PropertyEditor::PropertyEditor(QWidget *parent) : QTreeView(parent) , autoexpand(false) , autoupdate(false) @@ -100,8 +100,10 @@ PropertyEditor::PropertyEditor(QWidget *parent, int sizeOfFirstColumn) viewport()->installEventFilter(this); viewport()->setMouseTracking(true); - if (sizeOfFirstColumn != 0) { - header()->resizeSection(0, sizeOfFirstColumn); + auto hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/DockWindows/PropertyView"); + int firstColumnSize = hGrp->GetInt("FirstColumnSize", 0); + if (firstColumnSize != 0) { + header()->resizeSection(0, firstColumnSize); } } @@ -872,6 +874,9 @@ bool PropertyEditor::eventFilter(QObject* object, QEvent* event) { else if (mouse_event->type() == QEvent::MouseButtonRelease && mouse_event->button() == Qt::LeftButton && dragInProgress) { dragInProgress = false; + + auto hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/DockWindows/PropertyView"); + hGrp->SetInt("FirstColumnSize", header()->sectionSize(0)); return true; } } diff --git a/src/Gui/propertyeditor/PropertyEditor.h b/src/Gui/propertyeditor/PropertyEditor.h index 5c5342d129..bd01c2f99e 100644 --- a/src/Gui/propertyeditor/PropertyEditor.h +++ b/src/Gui/propertyeditor/PropertyEditor.h @@ -67,7 +67,7 @@ class PropertyEditor : public QTreeView Q_PROPERTY(QBrush itemBackground READ itemBackground WRITE setItemBackground DESIGNABLE true SCRIPTABLE true) // clazy:exclude=qproperty-without-notify public: - PropertyEditor(QWidget *parent = nullptr, int sizeOfFirstColumn = 0); + PropertyEditor(QWidget *parent = nullptr); ~PropertyEditor() override; /** Builds up the list view with the properties. */