aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAli Kianian <[email protected]>2025-08-15 12:33:29 +0300
committerAli Kianian <[email protected]>2025-08-15 12:12:18 +0000
commit940053ff85cc21ff5ff62455ea035828d2139e70 (patch)
tree3fc44f875fbf2d714d95d7b210321fa168ae2f4f
parent0a7e96ebbe9c9aeab34619c62fdcfd7e5189f88a (diff)
MultiPropertyEditor: Limit amount of property editor viewsqds/dev
- User cannot add more than a predefined number of property editor views - The maximum number of the views can be 10 - The add view button is disabled after reaching the maximum Fixes: QDS-15711 Change-Id: I15c1a9515adbfbc0622f56269a9338d976695389 Reviewed-by: Mahmoud Badri <[email protected]> Reviewed-by: Miikka Heikkinen <[email protected]>
-rw-r--r--share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/PropertyEditorToolBar.qml9
-rw-r--r--src/plugins/multipropertyeditor/multipropertyeditoraction.cpp9
-rw-r--r--src/plugins/multipropertyeditor/multipropertyeditoraction.h1
-rw-r--r--src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp19
-rw-r--r--src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h9
-rw-r--r--src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp3
-rw-r--r--src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp20
-rw-r--r--src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.h4
8 files changed, 72 insertions, 2 deletions
diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/PropertyEditorToolBar.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/PropertyEditorToolBar.qml
index ba0ac235680..432a8f30b43 100644
--- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/PropertyEditorToolBar.qml
+++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/PropertyEditorToolBar.qml
@@ -43,13 +43,18 @@ Rectangle {
HelperWidgets.AbstractButton {
id: addExtraViewButton
+
+ readonly property bool maxReached: editorInstancesCount >= maxEditorInstancesCount
+
anchors.right: lockButton.left
anchors.verticalCenter: parent.verticalCenter
visible: has3DScene && isMultiPropertyEditorPluginEnabled
buttonIcon: StudioTheme.Constants.add_medium
style: StudioTheme.Values.viewBarButtonStyle
- enabled: true
- tooltip: qsTr("Add extra property editor")
+ enabled: !maxReached
+ tooltip: maxReached
+ ? qsTr("Maximum number of property editors reached (%1)").arg(maxEditorInstancesCount)
+ : qsTr("Add property editor")
onClicked: root.toolBarAction(ToolBarAction.AddExtraWidget)
}
}
diff --git a/src/plugins/multipropertyeditor/multipropertyeditoraction.cpp b/src/plugins/multipropertyeditor/multipropertyeditoraction.cpp
index 56eba19f9ab..59a0def64f3 100644
--- a/src/plugins/multipropertyeditor/multipropertyeditoraction.cpp
+++ b/src/plugins/multipropertyeditor/multipropertyeditoraction.cpp
@@ -52,6 +52,7 @@ void MultiPropertyEditorAction::registerView(PropertyEditorView *view)
bool actionIsChecked = view->action()->isChecked();
m_viewsStatus.insert(view, actionIsChecked);
m_views.append(view);
+ updateViewsCount();
auto widget = view->widgetInfo().widget;
widget->installEventFilter(this);
@@ -81,6 +82,7 @@ void MultiPropertyEditorAction::unregisterView(PropertyEditorView *view)
return;
m_views.removeOne(view);
+ updateViewsCount();
auto widget = view->widgetInfo().widget;
widget->removeEventFilter(this);
@@ -183,4 +185,11 @@ void MultiPropertyEditorAction::ensureParentId(PropertyEditorView *view)
view->setWidgetInfo(widgetInfo);
}
+void MultiPropertyEditorAction::updateViewsCount()
+{
+ const int instancesCount = m_views.count();
+ for (PropertyEditorView *view : std::as_const(m_views))
+ view->setInstancesCount(instancesCount);
+}
+
} // namespace QmlDesigner
diff --git a/src/plugins/multipropertyeditor/multipropertyeditoraction.h b/src/plugins/multipropertyeditor/multipropertyeditoraction.h
index a311e3e4fb8..bf0f11b236c 100644
--- a/src/plugins/multipropertyeditor/multipropertyeditoraction.h
+++ b/src/plugins/multipropertyeditor/multipropertyeditoraction.h
@@ -30,6 +30,7 @@ private:
void uncheckIfAllWidgetsHidden();
void setCheckedIfWidgetRegistered(QObject *widgetObject);
void ensureParentId(PropertyEditorView *view);
+ void updateViewsCount();
QHash<PropertyEditorView *, bool> m_viewsStatus;
QList<PropertyEditorView *> m_views;
diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp
index 06e11c63656..c4ae947d319 100644
--- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp
+++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp
@@ -412,6 +412,25 @@ void PropertyEditorContextObject::setMinorVersion(int minorVersion)
emit minorVersionChanged();
}
+void PropertyEditorContextObject::setEditorInstancesCount(int n)
+{
+ NanotraceHR::Tracer tracer{"property editor context object set editor instances count",
+ category()};
+
+ if (m_editorInstancesCount == n)
+ return;
+
+ m_editorInstancesCount = n;
+ emit editorInstancesCountChanged();
+}
+
+int PropertyEditorContextObject::editorInstancesCount() const
+{
+ NanotraceHR::Tracer tracer{"property editor context object editor instances count", category()};
+
+ return m_editorInstancesCount;
+}
+
bool PropertyEditorContextObject::hasActiveTimeline() const
{
NanotraceHR::Tracer tracer{"property editor context object has active timeline", category()};
diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h
index 9d4ff6c8357..32a1dfde827 100644
--- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h
+++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h
@@ -35,6 +35,8 @@ class PropertyEditorContextObject : public QObject
Q_PROPERTY(int minorVersion READ minorVersion WRITE setMinorVersion NOTIFY minorVersionChanged)
Q_PROPERTY(int majorQtQuickVersion READ majorQtQuickVersion WRITE setMajorQtQuickVersion NOTIFY majorQtQuickVersionChanged)
Q_PROPERTY(int minorQtQuickVersion READ minorQtQuickVersion WRITE setMinorQtQuickVersion NOTIFY minorQtQuickVersionChanged)
+ Q_PROPERTY(int editorInstancesCount READ editorInstancesCount NOTIFY editorInstancesCountChanged)
+ Q_PROPERTY(int maxEditorInstancesCount READ maxEditorInstancesCount CONSTANT)
Q_PROPERTY(QString activeDragSuffix READ activeDragSuffix NOTIFY activeDragSuffixChanged)
@@ -123,6 +125,10 @@ public:
void setMinorQtQuickVersion(int minorVersion);
int minorVersion() const;
void setMinorVersion(int minorVersion);
+ void setEditorInstancesCount(int n);
+ int editorInstancesCount() const;
+
+ int maxEditorInstancesCount() const { return 10; }
bool hasActiveTimeline() const;
void setHasActiveTimeline(bool b);
@@ -173,6 +179,7 @@ signals:
void minorVersionChanged();
void majorQtQuickVersionChanged();
void minorQtQuickVersionChanged();
+ void editorInstancesCountChanged();
void specificQmlComponentChanged();
void hasAliasExportChanged();
void hasActiveTimelineChanged();
@@ -228,6 +235,8 @@ private:
int m_majorQtQuickVersion = 1;
int m_minorQtQuickVersion = -1;
+ int m_editorInstancesCount = 0;
+
bool m_hasQuick3DImport = false;
bool m_hasMaterialLibrary = false;
bool m_has3DModelSelected = false;
diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp
index 0881988c0b9..c3c47738300 100644
--- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp
+++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp
@@ -684,6 +684,9 @@ void PropertyEditorQmlBackend::setup(const ModelNodes &editorNodes,
contextObject()->setMajorQtQuickVersion(qmlObjectNode.view()->majorQtQuickVersion());
contextObject()->setMinorQtQuickVersion(qmlObjectNode.view()->minorQtQuickVersion());
#endif
+
+ contextObject()->setEditorInstancesCount(propertyEditor->instancesCount());
+
contextObject()->setHasMaterialLibrary(Utils3D::materialLibraryNode(propertyEditor).isValid());
contextObject()->setIsQt6Project(propertyEditor->externalDependencies().isQt6Project());
contextObject()->setEditorNodes(editorNodes);
diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp
index 3a792cf0d85..cee48832ad7 100644
--- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp
+++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp
@@ -956,6 +956,26 @@ void PropertyEditorView::setTargetNode(const ModelNode &node)
m_stackedWidget->setFocus();
}
+void PropertyEditorView::setInstancesCount(int n)
+{
+ NanotraceHR::Tracer tracer{"property editor view set instances count", category()};
+
+ if (m_instancesCount == n)
+ return;
+
+ m_instancesCount = n;
+
+ if (m_qmlBackEndForCurrentType)
+ m_qmlBackEndForCurrentType->contextObject()->setEditorInstancesCount(instancesCount());
+}
+
+int PropertyEditorView::instancesCount() const
+{
+ NanotraceHR::Tracer tracer{"property editor view instances count", category()};
+
+ return m_instancesCount;
+}
+
QList<ModelNode> PropertyEditorView::currentNodes() const
{
NanotraceHR::Tracer tracer{"property editor view current nodes", category()};
diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.h
index ec0b1811361..d5776958477 100644
--- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.h
+++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.h
@@ -126,6 +126,9 @@ public:
ModelNode activeNode() const;
void setTargetNode(const ModelNode &node);
+ void setInstancesCount(int n);
+ int instancesCount() const;
+
virtual void registerWidgetInfo() override;
virtual void deregisterWidgetInfo() override;
@@ -200,6 +203,7 @@ private: //variables
bool m_locked;
bool m_textureAboutToBeRemoved = false;
bool m_isSelectionLocked = false;
+ int m_instancesCount = 0;
QString m_parentWidgetId = "";
QString m_uniqueWidgetId = "Properties";
QString m_widgetTabName = tr("Properties");