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 <thomas.hartmann@qt.io>
This commit is contained in:
Rafal Stawarski
2025-02-07 13:52:34 +01:00
parent 13df04ca02
commit 777251dcb4

View File

@@ -4,6 +4,8 @@
#include "qmljscomponentnamedialog.h" #include "qmljscomponentnamedialog.h"
#include "qmljseditortr.h" #include "qmljseditortr.h"
#include <algorithm>
#include <utils/array.h>
#include <utils/classnamevalidatinglineedit.h> #include <utils/classnamevalidatinglineedit.h>
#include <utils/layoutbuilder.h> #include <utils/layoutbuilder.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
@@ -19,6 +21,58 @@
using namespace QmlJSEditor::Internal; using namespace QmlJSEditor::Internal;
namespace {
constexpr auto properitesCheckedByDefault = Utils::to_array<std::u16string_view>({
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) : ComponentNameDialog::ComponentNameDialog(QWidget *parent) :
QDialog(parent) QDialog(parent)
{ {
@@ -113,8 +167,7 @@ void ComponentNameDialog::setProperties(const QStringList &properties)
for (int i = 0; i < m_listWidget->count(); ++i) { for (int i = 0; i < m_listWidget->count(); ++i) {
QListWidgetItem *item = m_listWidget->item(i); QListWidgetItem *item = m_listWidget->item(i);
item->setFlags(Qt::ItemIsUserCheckable | Qt:: ItemIsEnabled); item->setFlags(Qt::ItemIsUserCheckable | Qt:: ItemIsEnabled);
if (item->text() == QLatin1String("x") if (isCheckedByDefault(item->text()))
|| item->text() == QLatin1String("y"))
m_listWidget->item(i)->setCheckState(Qt::Checked); m_listWidget->item(i)->setCheckState(Qt::Checked);
else else
m_listWidget->item(i)->setCheckState(Qt::Unchecked); m_listWidget->item(i)->setCheckState(Qt::Unchecked);