PropertyEditor: Persistent state of Property Editor sections

The state of the sections (collapsed or not) should be persistent.
This gives the user more control over the property editor.
We can e.g. provide large sections that are on the top and the user
decides wheather they are extended or not.

Task-number: QDS-14941
Change-Id: I5bb7ea1aa29c688082c17e375ea4c924403e4cdc
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Ali Kianian <ali.kianian@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Karol Herda
2025-03-17 11:33:39 +01:00
parent f7b64ee422
commit d21ed57ff5
6 changed files with 70 additions and 10 deletions

View File

@@ -247,7 +247,7 @@ Item {
: StudioTheme.Values.themeTextColor : StudioTheme.Values.themeTextColor
leftPadding: 0 leftPadding: 0
rightPadding: 0 rightPadding: 0
expanded: importExpanded defaultExpanded: importExpanded
expandOnClick: false expandOnClick: false
useDefaulContextMenu: false useDefaulContextMenu: false
category: "ItemsView" category: "ItemsView"
@@ -278,7 +278,7 @@ Item {
addBottomPadding: index !== categoryModel.rowCount() - 1 addBottomPadding: index !== categoryModel.rowCount() - 1
caption: displayNMame + " (" + itemModel.rowCount() + ")" caption: displayNMame + " (" + itemModel.rowCount() + ")"
visible: categoryVisible visible: categoryVisible
expanded: categoryExpanded defaultExpanded: categoryExpanded
expandOnClick: false expandOnClick: false
onToggleExpand: categoryExpanded = !categoryExpanded onToggleExpand: categoryExpanded = !categoryExpanded
useDefaulContextMenu: false useDefaulContextMenu: false
@@ -362,7 +362,7 @@ Item {
: StudioTheme.Values.themeTextColor : StudioTheme.Values.themeTextColor
leftPadding: 0 leftPadding: 0
rightPadding: 0 rightPadding: 0
expanded: importExpanded defaultExpanded: importExpanded
expandOnClick: false expandOnClick: false
useDefaulContextMenu: false useDefaulContextMenu: false
category: "ItemsView" category: "ItemsView"

View File

@@ -195,7 +195,8 @@ Section {
labelCapitalization: Font.MixedCase labelCapitalization: Font.MixedCase
visible: root.hasDesignerEffect visible: root.hasDesignerEffect
category: "DesignEffects" category: "DesignEffects"
expanded: false defaultExpanded: false
expanded: defaultExpanded
SectionLayout { SectionLayout {
@@ -243,7 +244,8 @@ Section {
labelCapitalization: Font.MixedCase labelCapitalization: Font.MixedCase
visible: root.hasDesignerEffect visible: root.hasDesignerEffect
category: "DesignEffects" category: "DesignEffects"
expanded: false defaultExpanded: false
expanded: defaultExpanded
SectionLayout { SectionLayout {
@@ -355,7 +357,8 @@ Section {
anchors.right: parent.right anchors.right: parent.right
category: "DesignEffects" category: "DesignEffects"
fillBackground: true fillBackground: true
expanded: false defaultExpanded: false
expanded: defaultExpanded
draggable: true draggable: true
showCloseButton: true showCloseButton: true

View File

@@ -142,15 +142,15 @@ PropertyEditorPane {
} }
EffectsSection { EffectsSection {
expanded: false defaultExpanded: false
} }
AdvancedSection { AdvancedSection {
expanded: false defaultExpanded: false
} }
LayerSection { LayerSection {
expanded: false defaultExpanded: false
} }
} }

View File

@@ -49,7 +49,8 @@ Item {
property int topPadding: StudioTheme.Values.sectionHeadSpacerHeight property int topPadding: StudioTheme.Values.sectionHeadSpacerHeight
property int bottomPadding: StudioTheme.Values.sectionHeadSpacerHeight property int bottomPadding: StudioTheme.Values.sectionHeadSpacerHeight
property bool expanded: true property bool defaultExpanded: true
property bool expanded: defaultExpanded
property int level: 0 property int level: 0
property int levelShift: 10 property int levelShift: 10
property bool hideHeader: false property bool hideHeader: false
@@ -68,6 +69,39 @@ Item {
clip: true clip: true
Component.onCompleted: {
updateExpansion()
}
function updateExpansion() {
// Check if function 'loadExpandedState' exists in current context
if (typeof loadExpandedState === "function") {
if (section.expandOnClick)
section.expanded = loadExpandedState(section.caption, section.defaultExpanded)
else if (loadExpandedState(section.caption, section.defaultExpanded))
section.expand()
else
section.collapse()
} else {
// Fallback to default value
if (section.expandOnClick)
section.expanded = section.defaultExpanded
else if (section.defaultExpanded)
section.expand()
else
section.collapse()
}
}
Connections {
target: modelNodeBackend ?? null
ignoreUnknownSignals: true
function onSelectionChanged() {
updateExpansion()
}
}
Connections { Connections {
id: connection id: connection
target: section target: section
@@ -165,6 +199,10 @@ Item {
section.expanded = !section.expanded section.expanded = !section.expanded
else else
section.toggleExpand() section.toggleExpand()
// Check if function 'saveExpandedState' exists in current context
if (typeof saveExpandedState === "function")
saveExpandedState(section.caption, section.expanded)
} else { } else {
section.showContextMenu() section.showContextMenu()
} }
@@ -249,6 +287,10 @@ Item {
section.expanded = !section.expanded section.expanded = !section.expanded
else else
section.toggleExpand() section.toggleExpand()
// Check if function 'saveExpandedState' exists in current context
if (typeof saveExpandedState === "function")
saveExpandedState(section.caption, section.expanded)
} }
} }

View File

@@ -693,6 +693,16 @@ void PropertyEditorContextObject::handleToolBarAction(int action)
emit toolBarAction(action); emit toolBarAction(action);
} }
void PropertyEditorContextObject::saveExpandedState(const QString &sectionName, bool expanded)
{
s_expandedStateHash.insert(sectionName, expanded);
}
bool PropertyEditorContextObject::loadExpandedState(const QString &sectionName, bool defaultValue) const
{
return s_expandedStateHash.value(sectionName, defaultValue);
}
void EasingCurveEditor::registerDeclarativeType() void EasingCurveEditor::registerDeclarativeType()
{ {
qmlRegisterType<EasingCurveEditor>("HelperWidgets", 2, 0, "EasingCurveEditor"); qmlRegisterType<EasingCurveEditor>("HelperWidgets", 2, 0, "EasingCurveEditor");

View File

@@ -104,6 +104,9 @@ public:
Q_INVOKABLE void handleToolBarAction(int action); Q_INVOKABLE void handleToolBarAction(int action);
Q_INVOKABLE void saveExpandedState(const QString &sectionName, bool expanded);
Q_INVOKABLE bool loadExpandedState(const QString &sectionName, bool defaultValue) const;
enum ToolBarAction { SelectionLock, SelectionUnlock }; enum ToolBarAction { SelectionLock, SelectionUnlock };
Q_ENUM(ToolBarAction) Q_ENUM(ToolBarAction)
@@ -241,6 +244,8 @@ private:
QStringList m_insightCategories; QStringList m_insightCategories;
ModelNodes m_editorNodes; // Nodes that are being edited by PropertyEditor ModelNodes m_editorNodes; // Nodes that are being edited by PropertyEditor
inline static QHash<QString, bool> s_expandedStateHash;
}; };
class EasingCurveEditor : public QObject class EasingCurveEditor : public QObject