From 777251dcb487a02f84ada12403b37eac04c5804c Mon Sep 17 00:00:00 2001 From: Rafal Stawarski Date: Fri, 7 Feb 2025 13:52:34 +0100 Subject: [PATCH] Move component without anchor/layout properties When moving the component to the separate file, properties from anchor group and Layout attached properties are checked by default on the list, so they remain in the component instance. Task-number: QDS-11901 Change-Id: Ifb456c71810cee18b870995deca9f51c7b6273ef Reviewed-by: Thomas Hartmann --- .../qmljseditor/qmljscomponentnamedialog.cpp | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmljseditor/qmljscomponentnamedialog.cpp b/src/plugins/qmljseditor/qmljscomponentnamedialog.cpp index 4917e8c59ac..a0ff5fb3b16 100644 --- a/src/plugins/qmljseditor/qmljscomponentnamedialog.cpp +++ b/src/plugins/qmljseditor/qmljscomponentnamedialog.cpp @@ -4,6 +4,8 @@ #include "qmljscomponentnamedialog.h" #include "qmljseditortr.h" +#include +#include #include #include #include @@ -19,6 +21,58 @@ using namespace QmlJSEditor::Internal; +namespace { +constexpr auto properitesCheckedByDefault = Utils::to_array({ + u"x", + u"y", + u"anchors.alignWhenCentered", + u"anchors.baseline", + u"anchors.baselineOffset", + u"anchors.bottom", + u"anchors.bottomMargin", + u"anchors.centerIn", + u"anchors.fill", + u"anchors.horizontalCenter", + u"anchors.horizontalCenterOffset", + u"anchors.left", + u"anchors.leftMargin", + u"anchors.margins", + u"anchors.right", + u"anchors.rightMargin", + u"anchors.top", + u"anchors.topMargin", + u"anchors.verticalCenter", + u"anchors.verticalCenterOffset", + u"Layout.alignment", + u"Layout.bottomMargin", + u"Layout.column", + u"Layout.columnSpan", + u"Layout.fillHeight", + u"Layout.fillWidth", + u"Layout.horizontalStretchFactor", + u"Layout.leftMargin", + u"Layout.margins", + u"Layout.maximumHeight", + u"Layout.maximumWidth", + u"Layout.minimumHeight", + u"Layout.minimumWidth", + u"Layout.preferredHeight", + u"Layout.preferredWidth", + u"Layout.rightMargin", + u"Layout.row", + u"Layout.rowSpan", + u"Layout.topMargin", + u"Layout.useDefaultSizePolicy", + u"Layout.verticalStretchFactor", +}); + +bool isCheckedByDefault(const QString &property) +{ + return std::find(properitesCheckedByDefault.begin(), properitesCheckedByDefault.end(), property) + != properitesCheckedByDefault.end(); +} +} // namespace + ComponentNameDialog::ComponentNameDialog(QWidget *parent) : QDialog(parent) { @@ -113,8 +167,7 @@ void ComponentNameDialog::setProperties(const QStringList &properties) for (int i = 0; i < m_listWidget->count(); ++i) { QListWidgetItem *item = m_listWidget->item(i); item->setFlags(Qt::ItemIsUserCheckable | Qt:: ItemIsEnabled); - if (item->text() == QLatin1String("x") - || item->text() == QLatin1String("y")) + if (isCheckedByDefault(item->text())) m_listWidget->item(i)->setCheckState(Qt::Checked); else m_listWidget->item(i)->setCheckState(Qt::Unchecked);