Gui: Create a Property View submenu for expansion
The Property View's context menu has a submenu for property expansion that allows you set the property expansion to default (remembers state), to expand all and to collapse all. Then there are toggles for default/auto expand/auto collapse that always collapses or expands or remembers the state.
This commit is contained in:
@@ -85,15 +85,11 @@ PropertyView::PropertyView(QWidget *parent)
|
||||
propertyEditorView = new Gui::PropertyEditor::PropertyEditor();
|
||||
propertyEditorView->setObjectName(QStringLiteral("propertyEditorView"));
|
||||
propertyEditorView->setAutomaticDocumentUpdate(_GetParam()->GetBool("AutoTransactionView", false));
|
||||
propertyEditorView->setAutomaticExpand(_GetParam()->GetBool("AutoExpandView", false));
|
||||
propertyEditorView->setAutomaticCollapse(_GetParam()->GetBool("AutoCollapseView", false));
|
||||
tabs->addTab(propertyEditorView, tr("View"));
|
||||
|
||||
propertyEditorData = new Gui::PropertyEditor::PropertyEditor();
|
||||
propertyEditorData->setObjectName(QStringLiteral("propertyEditorData"));
|
||||
propertyEditorData->setAutomaticDocumentUpdate(_GetParam()->GetBool("AutoTransactionData", true));
|
||||
propertyEditorData->setAutomaticExpand(_GetParam()->GetBool("AutoExpandData", false));
|
||||
propertyEditorView->setAutomaticCollapse(_GetParam()->GetBool("AutoCollapseData", false));
|
||||
tabs->addTab(propertyEditorData, tr("Data"));
|
||||
|
||||
int preferredTab = _GetParam()->GetInt("LastTabIndex", 1);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <QHeaderView>
|
||||
#include <QMenu>
|
||||
#include <QPainter>
|
||||
#include <QActionGroup>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/AutoTransaction.h>
|
||||
@@ -52,8 +53,7 @@ using namespace Gui::PropertyEditor;
|
||||
|
||||
PropertyEditor::PropertyEditor(QWidget* parent)
|
||||
: QTreeView(parent)
|
||||
, autocollapse(false)
|
||||
, autoexpand(false)
|
||||
, expansionMode(ExpansionMode::DefaultExpand)
|
||||
, autoupdate(false)
|
||||
, committing(false)
|
||||
, delaybuild(false)
|
||||
@@ -119,24 +119,6 @@ PropertyEditor::~PropertyEditor()
|
||||
delete f;
|
||||
}
|
||||
|
||||
void PropertyEditor::setAutomaticCollapse(bool v) {
|
||||
autocollapse = v;
|
||||
}
|
||||
|
||||
bool PropertyEditor::isAutomaticCollapse(bool) const {
|
||||
return autocollapse;
|
||||
}
|
||||
|
||||
void PropertyEditor::setAutomaticExpand(bool v)
|
||||
{
|
||||
autoexpand = v;
|
||||
}
|
||||
|
||||
bool PropertyEditor::isAutomaticExpand(bool) const
|
||||
{
|
||||
return autoexpand;
|
||||
}
|
||||
|
||||
void PropertyEditor::onItemExpanded(const QModelIndex& index)
|
||||
{
|
||||
auto item = static_cast<PropertyItem*>(index.internalPointer());
|
||||
@@ -721,12 +703,16 @@ void PropertyEditor::buildUp(PropertyModel::PropertyList&& props, bool _checkDoc
|
||||
}
|
||||
}
|
||||
|
||||
if (autoexpand) {
|
||||
switch (expansionMode) {
|
||||
case ExpansionMode::DefaultExpand:
|
||||
// take the current expansion state
|
||||
break;
|
||||
case ExpansionMode::AutoExpand:
|
||||
expandAll();
|
||||
}
|
||||
|
||||
if (autocollapse) {
|
||||
break;
|
||||
case ExpansionMode::AutoCollapse:
|
||||
collapseAll();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -784,6 +770,8 @@ enum MenuAction
|
||||
{
|
||||
MA_AutoCollapse,
|
||||
MA_AutoExpand,
|
||||
MA_ExpandToDefault,
|
||||
MA_DefaultExpand,
|
||||
MA_CollapseAll,
|
||||
MA_ExpandAll,
|
||||
MA_ShowHidden,
|
||||
@@ -804,6 +792,94 @@ enum MenuAction
|
||||
MA_Copy,
|
||||
};
|
||||
|
||||
void PropertyEditor::setFirstLevelExpanded(bool doExpand)
|
||||
{
|
||||
if (!propertyModel) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::function<void(const QModelIndex&, bool)> setExpanded = [&](
|
||||
const QModelIndex& index, bool doExpand) {
|
||||
if (!index.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* item = static_cast<PropertyItem*>(index.internalPointer());
|
||||
if (item == nullptr || item->childCount() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (doExpand) {
|
||||
expand(index);
|
||||
}
|
||||
else {
|
||||
collapse(index);
|
||||
}
|
||||
|
||||
for (int row = 0; row < propertyModel->rowCount(index); ++row) {
|
||||
setExpanded(propertyModel->index(row, 0, index), false);
|
||||
}
|
||||
};
|
||||
|
||||
const QModelIndex root = QModelIndex();
|
||||
for (int row = 0; row <propertyModel->rowCount(root); ++row) {
|
||||
setExpanded(propertyModel->index(row, 0, root), doExpand);
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyEditor::expandToDefault()
|
||||
{
|
||||
setFirstLevelExpanded(true);
|
||||
}
|
||||
|
||||
void PropertyEditor::collapseAll()
|
||||
{
|
||||
setFirstLevelExpanded(false);
|
||||
}
|
||||
|
||||
QMenu* PropertyEditor::setupExpansionSubmenu(QWidget* parent)
|
||||
{
|
||||
auto* expandMenu = new QMenu(tr("Expand/Collapse Properties"), parent);
|
||||
|
||||
QAction* expandToDefault = expandMenu->addAction(tr("Expand to Default"));
|
||||
expandToDefault->setData(QVariant(MA_ExpandToDefault));
|
||||
QAction* expandAll = expandMenu->addAction(tr("Expand All"));
|
||||
expandAll->setData(QVariant(MA_ExpandAll));
|
||||
QAction* collapseAll = expandMenu->addAction(tr("Collapse All"));
|
||||
collapseAll->setData(QVariant(MA_CollapseAll));
|
||||
|
||||
auto* group = new QActionGroup(expandMenu);
|
||||
group->setExclusive(true);
|
||||
|
||||
QAction* defaultExpand = expandMenu->addAction(tr("Default Expand"));
|
||||
defaultExpand->setData(QVariant(MA_DefaultExpand));
|
||||
|
||||
QAction* autoExpand = expandMenu->addAction(tr("Auto Expand"));
|
||||
autoExpand->setData(QVariant(MA_AutoExpand));
|
||||
|
||||
QAction* autoCollapse = expandMenu->addAction(tr("Auto Collapse"));
|
||||
autoCollapse->setData(QVariant(MA_AutoCollapse));
|
||||
|
||||
for (QAction* action : {defaultExpand, autoExpand, autoCollapse}) {
|
||||
action->setCheckable(true);
|
||||
group->addAction(action);
|
||||
}
|
||||
|
||||
switch (expansionMode) {
|
||||
case ExpansionMode::DefaultExpand:
|
||||
defaultExpand->setChecked(true);
|
||||
break;
|
||||
case ExpansionMode::AutoExpand:
|
||||
autoExpand->setChecked(true);
|
||||
break;
|
||||
case ExpansionMode::AutoCollapse:
|
||||
autoCollapse->setChecked(true);
|
||||
break;
|
||||
}
|
||||
|
||||
return expandMenu;
|
||||
}
|
||||
|
||||
static App::PropertyContainer* getSelectedPropertyContainer()
|
||||
{
|
||||
auto sels = Gui::Selection().getSelection("*");
|
||||
@@ -856,9 +932,6 @@ void PropertyEditor::removeProperties(const std::unordered_set<App::Property*>&
|
||||
void PropertyEditor::contextMenuEvent(QContextMenuEvent*)
|
||||
{
|
||||
QMenu menu;
|
||||
QAction* autoExpand = nullptr;
|
||||
QAction* autoCollapse = nullptr;
|
||||
|
||||
auto contextIndex = currentIndex();
|
||||
|
||||
std::unordered_set<App::Property*> props = acquireSelectedProperties();
|
||||
@@ -915,30 +988,15 @@ void PropertyEditor::contextMenuEvent(QContextMenuEvent*)
|
||||
// add a separator between adding/removing properties and the rest
|
||||
menu.addSeparator();
|
||||
|
||||
QMenu* expandMenu = setupExpansionSubmenu(&menu);
|
||||
menu.addMenu(expandMenu);
|
||||
|
||||
// show all
|
||||
QAction* showHidden = menu.addAction(tr("Show Hidden"));
|
||||
showHidden->setCheckable(true);
|
||||
showHidden->setChecked(PropertyView::showAll());
|
||||
showHidden->setData(QVariant(MA_ShowHidden));
|
||||
|
||||
// auto collapse
|
||||
autoCollapse = menu.addAction(tr("Auto collapse"));
|
||||
autoCollapse->setCheckable(true);
|
||||
autoCollapse->setChecked(autocollapse);
|
||||
autoCollapse->setData(QVariant(MA_AutoCollapse));
|
||||
|
||||
// auto expand
|
||||
autoExpand = menu.addAction(tr("Auto-Expand"));
|
||||
autoExpand->setCheckable(true);
|
||||
autoExpand->setChecked(autoexpand);
|
||||
autoExpand->setData(QVariant(MA_AutoExpand));
|
||||
|
||||
QAction* collapseall = menu.addAction(tr("Collapse all"));
|
||||
collapseall->setData(QVariant(MA_CollapseAll));
|
||||
|
||||
QAction* expandall = menu.addAction(tr("Expand all"));
|
||||
expandall->setData(QVariant(MA_ExpandAll));
|
||||
|
||||
menu.addSeparator();
|
||||
|
||||
// expression
|
||||
@@ -1000,36 +1058,8 @@ void PropertyEditor::contextMenuEvent(QContextMenuEvent*)
|
||||
}
|
||||
|
||||
switch (action->data().toInt()) {
|
||||
case MA_AutoCollapse:
|
||||
if (autoCollapse) {
|
||||
autocollapse = autoCollapse->isChecked();
|
||||
|
||||
// uncheck auto expand
|
||||
if (autoExpand->isChecked()) {
|
||||
autoexpand = false;
|
||||
}
|
||||
|
||||
if (autocollapse) {
|
||||
collapseAll();
|
||||
}
|
||||
}
|
||||
return;
|
||||
case MA_AutoExpand:
|
||||
if (autoExpand) {
|
||||
// Variable autoExpand should not be null when we arrive here, but
|
||||
// since we explicitly initialize the variable to nullptr, a check
|
||||
// nonetheless.
|
||||
autoexpand = autoExpand->isChecked();
|
||||
|
||||
// uncheck auto collapse
|
||||
if (autoCollapse->isChecked()) {
|
||||
autocollapse = false;
|
||||
}
|
||||
|
||||
if (autoexpand) {
|
||||
expandAll();
|
||||
}
|
||||
}
|
||||
case MA_ExpandToDefault:
|
||||
expandToDefault();
|
||||
return;
|
||||
case MA_CollapseAll:
|
||||
collapseAll();
|
||||
@@ -1037,6 +1067,20 @@ void PropertyEditor::contextMenuEvent(QContextMenuEvent*)
|
||||
case MA_ExpandAll:
|
||||
expandAll();
|
||||
return;
|
||||
case MA_DefaultExpand:
|
||||
action->setChecked(true);
|
||||
expansionMode = ExpansionMode::DefaultExpand;
|
||||
return;
|
||||
case MA_AutoCollapse:
|
||||
action->setChecked(true);
|
||||
expansionMode = ExpansionMode::AutoCollapse;
|
||||
collapseAll();
|
||||
return;
|
||||
case MA_AutoExpand:
|
||||
action->setChecked(true);
|
||||
expansionMode = ExpansionMode::AutoExpand;
|
||||
expandAll();
|
||||
return;
|
||||
case MA_ShowHidden:
|
||||
PropertyView::setShowAll(action->isChecked());
|
||||
return;
|
||||
|
||||
@@ -70,6 +70,12 @@ class GuiExport PropertyEditor: public QTreeView
|
||||
// clang-format on
|
||||
|
||||
public:
|
||||
enum class ExpansionMode {
|
||||
DefaultExpand,
|
||||
AutoExpand,
|
||||
AutoCollapse
|
||||
};
|
||||
|
||||
PropertyEditor(QWidget* parent = nullptr);
|
||||
~PropertyEditor() override;
|
||||
|
||||
@@ -79,10 +85,6 @@ public:
|
||||
void updateProperty(const App::Property&);
|
||||
void removeProperty(const App::Property&);
|
||||
void renameProperty(const App::Property&);
|
||||
void setAutomaticCollapse(bool);
|
||||
bool isAutomaticCollapse(bool) const;
|
||||
void setAutomaticExpand(bool);
|
||||
bool isAutomaticExpand(bool) const;
|
||||
void setAutomaticDocumentUpdate(bool);
|
||||
bool isAutomaticDocumentUpdate(bool) const;
|
||||
/*! Reset the internal state of the view. */
|
||||
@@ -133,6 +135,10 @@ protected:
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
|
||||
private:
|
||||
void setFirstLevelExpanded(bool doExpand);
|
||||
void expandToDefault();
|
||||
QMenu* setupExpansionSubmenu(QWidget* parent);
|
||||
void collapseAll();
|
||||
void setEditorMode(const QModelIndex& parent, int start, int end);
|
||||
void closeTransaction();
|
||||
void recomputeDocument(App::Document*);
|
||||
@@ -150,8 +156,7 @@ private:
|
||||
QStringList selectedProperty;
|
||||
PropertyModel::PropertyList propList;
|
||||
std::unordered_set<const App::PropertyContainer*> propOwners;
|
||||
bool autocollapse;
|
||||
bool autoexpand;
|
||||
ExpansionMode expansionMode;
|
||||
bool autoupdate;
|
||||
bool committing;
|
||||
bool delaybuild;
|
||||
|
||||
Reference in New Issue
Block a user