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

View File

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

View File

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

View File

@@ -49,7 +49,8 @@ Item {
property int topPadding: 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 levelShift: 10
property bool hideHeader: false
@@ -68,6 +69,39 @@ Item {
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 {
id: connection
target: section
@@ -165,6 +199,10 @@ Item {
section.expanded = !section.expanded
else
section.toggleExpand()
// Check if function 'saveExpandedState' exists in current context
if (typeof saveExpandedState === "function")
saveExpandedState(section.caption, section.expanded)
} else {
section.showContextMenu()
}
@@ -249,6 +287,10 @@ Item {
section.expanded = !section.expanded
else
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);
}
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()
{
qmlRegisterType<EasingCurveEditor>("HelperWidgets", 2, 0, "EasingCurveEditor");

View File

@@ -104,6 +104,9 @@ public:
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 };
Q_ENUM(ToolBarAction)
@@ -241,6 +244,8 @@ private:
QStringList m_insightCategories;
ModelNodes m_editorNodes; // Nodes that are being edited by PropertyEditor
inline static QHash<QString, bool> s_expandedStateHash;
};
class EasingCurveEditor : public QObject