diff --git a/src/libs/utils/array.h b/src/libs/utils/array.h index c89778871ca..74a552ecc27 100644 --- a/src/libs/utils/array.h +++ b/src/libs/utils/array.h @@ -7,19 +7,18 @@ namespace Utils { -namespace Internal { -template -constexpr std::array, size> to_array_implementation( - Type (&&array)[size], std::index_sequence) +template +constexpr auto to_array(Arguments &&...arguments) { - return {{std::move(array[index])...}}; + return std::array{std::forward(arguments)...}; } -} // namespace Internal -template -constexpr std::array, size> to_array(Type (&&array)[size]) +template +constexpr auto to_sorted_array(Arguments &&...arguments) { - return Internal::to_array_implementation(std::move(array), std::make_index_sequence{}); + auto array = to_array(std::forward(arguments)...); + std::ranges::sort(array); + return array; } } // namespace Utils diff --git a/src/plugins/qmldesigner/libs/designercore/rewriter/texttomodelmerger.cpp b/src/plugins/qmldesigner/libs/designercore/rewriter/texttomodelmerger.cpp index a980c1469e0..ec506da5259 100644 --- a/src/plugins/qmldesigner/libs/designercore/rewriter/texttomodelmerger.cpp +++ b/src/plugins/qmldesigner/libs/designercore/rewriter/texttomodelmerger.cpp @@ -70,51 +70,84 @@ bool isSupportedAttachedProperties(const QString &propertyName) bool isGlobalQtEnums(QStringView value) { - static constexpr auto list = Utils::to_array( - {u"AlignBaseline", u"AlignBottom", u"AlignHCenter", u"AlignLeft", - u"AlignRight", u"AlignTop", u"AlignVCenter", u"AllButtons", - u"ArrowCursor", u"BackButton", u"BlankCursor", u"BottomEdge", - u"BottomLeft", u"BusyCursor", u"ClickFocus", u"ClosedHandCursor", - u"CrossCursor", u"DragCopyCursor", u"DragLinkCursor", u"DragMoveCursor", - u"ForbiddenCursor", u"ForwardButton", u"Horizontal", u"IBeamCursor", - u"LeftButton", u"LeftEdge", u"LeftToRight", u"MiddleButton", - u"NoFocus", u"OpenHandCursor", u"PointingHandCursor", u"RightButton", - u"RightEdge", u"RightToLeft", u"SizeAllCursor", u"SizeBDiagCursor", - u"SizeFDiagCursor", u"SizeHorCursor", u"SizeVerCursor", u"SplitHCursor", - u"SplitVCursor", u"StrongFocus", u"TabFocus", u"TopEdge", - u"TopToBottom", u"UpArrowCursor", u"Vertical", u"WaitCursor", - u"WhatsThisCursor", u"WheelFocus"}); + static constexpr auto list = Utils::to_array(u"AlignBaseline", + u"AlignBottom", + u"AlignHCenter", + u"AlignLeft", + u"AlignRight", + u"AlignTop", + u"AlignVCenter", + u"AllButtons", + u"ArrowCursor", + u"BackButton", + u"BlankCursor", + u"BottomEdge", + u"BottomLeft", + u"BusyCursor", + u"ClickFocus", + u"ClosedHandCursor", + u"CrossCursor", + u"DragCopyCursor", + u"DragLinkCursor", + u"DragMoveCursor", + u"ForbiddenCursor", + u"ForwardButton", + u"Horizontal", + u"IBeamCursor", + u"LeftButton", + u"LeftEdge", + u"LeftToRight", + u"MiddleButton", + u"NoFocus", + u"OpenHandCursor", + u"PointingHandCursor", + u"RightButton", + u"RightEdge", + u"RightToLeft", + u"SizeAllCursor", + u"SizeBDiagCursor", + u"SizeFDiagCursor", + u"SizeHorCursor", + u"SizeVerCursor", + u"SplitHCursor", + u"SplitVCursor", + u"StrongFocus", + u"TabFocus", + u"TopEdge", + u"TopToBottom", + u"UpArrowCursor", + u"Vertical", + u"WaitCursor", + u"WhatsThisCursor", + u"WheelFocus"); if (value.startsWith(u"Key_")) return true; - return std::binary_search(std::begin(list), - std::end(list), - QmlDesigner::ModelUtils::toStdStringView(value)); + return std::ranges::binary_search(list, QmlDesigner::ModelUtils::toStdStringView(value)); } bool isKnownEnumScopes(QStringView value) { static constexpr auto list = Utils::to_array( - {u"TextInput", - u"TextEdit", - u"Material", - u"Universal", - u"Font", - u"Shape", - u"ShapePath", - u"AbstractButton", - u"Text", - u"ShaderEffectSource", - u"Grid", - u"ItemLayer", - u"ImageLayer", - u"SpriteLayer", - u"Light", - u"ExtendedSceneEnvironment.GlowBlendMode"}); + u"TextInput", + u"TextEdit", + u"Material", + u"Universal", + u"Font", + u"Shape", + u"ShapePath", + u"AbstractButton", + u"Text", + u"ShaderEffectSource", + u"Grid", + u"ItemLayer", + u"ImageLayer", + u"SpriteLayer", + u"Light", + u"ExtendedSceneEnvironment.GlowBlendMode"); - return std::find(std::begin(list), std::end(list), QmlDesigner::ModelUtils::toStdStringView(value)) - != std::end(list); + return std::ranges::find(list, QmlDesigner::ModelUtils::toStdStringView(value)) != std::end(list); } QString stripQuotes(const QString &str) diff --git a/src/plugins/qmljseditor/qmljscomponentnamedialog.cpp b/src/plugins/qmljseditor/qmljscomponentnamedialog.cpp index cd1d7d8867a..46fcbd173c0 100644 --- a/src/plugins/qmljseditor/qmljscomponentnamedialog.cpp +++ b/src/plugins/qmljseditor/qmljscomponentnamedialog.cpp @@ -22,54 +22,53 @@ 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) +bool isCheckedByDefault(std::u16string_view property) { - return std::find(properitesCheckedByDefault.begin(), properitesCheckedByDefault.end(), property) - != properitesCheckedByDefault.end(); + static constexpr auto properitesCheckedByDefault = Utils::to_sorted_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"); + + return std::ranges::binary_search(properitesCheckedByDefault, property); } } // namespace @@ -167,7 +166,15 @@ 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 QT_VERSION > QT_VERSION_CHECK(6, 7, 0) if (isCheckedByDefault(item->text())) +#else + const QString text = item->text(); + const QStringView view = item->text(); + + if (isCheckedByDefault( + std::u16string_view{view.utf16(), static_cast(view.size())})) +#endif m_listWidget->item(i)->setCheckState(Qt::Checked); else m_listWidget->item(i)->setCheckState(Qt::Unchecked);