Core : Tree: Add 'Properties' action in contextual menu. Opens a property dialog.
This commit is contained in:
@@ -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"));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<QAction*>(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"));
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user