From 6d5ceadccf0a8d4bd0bf03dcd7e1fd6229134183 Mon Sep 17 00:00:00 2001 From: Henning Gruendl Date: Fri, 15 Sep 2023 10:40:18 +0200 Subject: [PATCH] QmlDesigner: Improve type selection * Disable custom item in Connection Editor type selection * Rename Unknown to Custom Change-Id: I9fa8c9ab6284503d5ccc61813454b9d10f291a06 Reviewed-by: Qt CI Patch Build Bot Reviewed-by: Reviewed-by: Thomas Hartmann --- .../ConnectionsDialogForm.qml | 40 +++++++++++++++---- .../StudioControls/TopLevelComboBox.qml | 13 ++++-- .../connectioneditorevaluator.cpp | 4 +- .../connectioneditorstatements.h | 4 +- .../connectioneditor/tst_connectioneditor.cpp | 10 ++--- 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialogForm.qml b/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialogForm.qml index 10b1331fa68..56998fac9e0 100644 --- a/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialogForm.qml +++ b/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialogForm.qml @@ -57,14 +57,38 @@ Column { onIndexFromBackendChanged: action.currentIndex = action.indexFromBackend onActivated: backend.changeActionType(action.currentValue) - model: [ - { value: ConnectionModelStatementDelegate.CallFunction, text: qsTr("Call Function") }, - { value: ConnectionModelStatementDelegate.Assign, text: qsTr("Assign") }, - { value: ConnectionModelStatementDelegate.ChangeState, text: qsTr("Change State") }, - { value: ConnectionModelStatementDelegate.SetProperty, text: qsTr("Set Property") }, - { value: ConnectionModelStatementDelegate.PrintMessage, text: qsTr("Print Message") }, - { value: ConnectionModelStatementDelegate.Custom, text: qsTr("Unknown") } - ] + model: ListModel { + ListElement { + value: ConnectionModelStatementDelegate.CallFunction + text: qsTr("Call Function") + enabled: true + } + ListElement { + value: ConnectionModelStatementDelegate.Assign + text: qsTr("Assign") + enabled: true + } + ListElement { + value: ConnectionModelStatementDelegate.ChangeState + text: qsTr("Change State") + enabled: true + } + ListElement { + value: ConnectionModelStatementDelegate.SetProperty + text: qsTr("Set Property") + enabled: true + } + ListElement { + vvalue: ConnectionModelStatementDelegate.PrintMessage + text: qsTr("Print Message") + enabled: true + } + ListElement { + value: ConnectionModelStatementDelegate.Custom + text: qsTr("Custom") + enabled: false + } + } } } diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/TopLevelComboBox.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/TopLevelComboBox.qml index 61483feadfb..eb1a6c631d2 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/TopLevelComboBox.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/TopLevelComboBox.qml @@ -155,6 +155,7 @@ T.ComboBox { width: control.width height: control.style.controlSize.height padding: 0 + enabled: model.enabled === undefined ? true : model.enabled contentItem: Text { leftPadding: itemDelegateIconArea.width @@ -182,8 +183,13 @@ T.ComboBox { T.Label { id: itemDelegateIcon text: StudioTheme.Constants.tickIcon - color: itemDelegate.hovered ? control.style.text.selectedText - : control.style.text.idle + color: { + if (!itemDelegate.enabled) + return control.style.text.disabled + + return itemDelegate.hovered ? control.style.text.selectedText + : control.style.text.idle + } font.family: StudioTheme.Constants.iconFont.family font.pixelSize: control.style.smallIconFontSize visible: control.currentIndex === index @@ -200,7 +206,8 @@ T.ComboBox { y: 0 width: itemDelegate.width - 2 * control.style.borderWidth height: itemDelegate.height - color: itemDelegate.hovered ? control.style.interaction : "transparent" + color: itemDelegate.hovered && itemDelegate.enabled ? control.style.interaction + : "transparent" } } } diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectioneditorevaluator.cpp b/src/plugins/qmldesigner/components/connectioneditor/connectioneditorevaluator.cpp index d44077e4ff6..c7d3ae977a5 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectioneditorevaluator.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/connectioneditorevaluator.cpp @@ -760,14 +760,14 @@ QString ConnectionEditorEvaluator::getDisplayStringForType(const QString &statem newDoc->parseJavaScript(); if (!newDoc->isParsedCorrectly()) - return ConnectionEditorStatements::UNKNOWN_DISPLAY_NAME; + return ConnectionEditorStatements::CUSTOM_DISPLAY_NAME; newDoc->ast()->accept(&evaluator); const bool valid = evaluator.status() == ConnectionEditorEvaluator::Succeeded; if (!valid) - return ConnectionEditorStatements::UNKNOWN_DISPLAY_NAME; + return ConnectionEditorStatements::CUSTOM_DISPLAY_NAME; auto result = evaluator.resultNode(); diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectioneditorstatements.h b/src/plugins/qmldesigner/components/connectioneditor/connectioneditorstatements.h index 63d457a84a4..06e6434b5ab 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectioneditorstatements.h +++ b/src/plugins/qmldesigner/components/connectioneditor/connectioneditorstatements.h @@ -21,8 +21,8 @@ inline constexpr char LOG_DISPLAY_NAME[] = QT_TRANSLATE_NOOP( "QmlDesigner::ConnectionEditorStatements", "Print"); inline constexpr char EMPTY_DISPLAY_NAME[] = QT_TRANSLATE_NOOP( "QmlDesigner::ConnectionEditorStatements", "Empty"); -inline constexpr char UNKNOWN_DISPLAY_NAME[] = QT_TRANSLATE_NOOP( - "QmlDesigner::ConnectionEditorStatements", "Unknown"); +inline constexpr char CUSTOM_DISPLAY_NAME[] = QT_TRANSLATE_NOOP( + "QmlDesigner::ConnectionEditorStatements", "Custom"); struct Variable; struct MatchedFunction; diff --git a/tests/auto/qml/connectioneditor/tst_connectioneditor.cpp b/tests/auto/qml/connectioneditor/tst_connectioneditor.cpp index 61e19d1253d..8e1cd0ed6cb 100644 --- a/tests/auto/qml/connectioneditor/tst_connectioneditor.cpp +++ b/tests/auto/qml/connectioneditor/tst_connectioneditor.cpp @@ -105,10 +105,10 @@ void tst_ConnectionEditor::invalidSyntax() = "{someItem.complexCall(blah)}"; //valid QML bit not valid for ConnectionEditor QString result = ConnectionEditorEvaluator::getDisplayStringForType(statement1); - QCOMPARE(result, ConnectionEditorStatements::UNKNOWN_DISPLAY_NAME); + QCOMPARE(result, ConnectionEditorStatements::CUSTOM_DISPLAY_NAME); result = ConnectionEditorEvaluator::getDisplayStringForType(statement2); - QCOMPARE(result, ConnectionEditorStatements::UNKNOWN_DISPLAY_NAME); + QCOMPARE(result, ConnectionEditorStatements::CUSTOM_DISPLAY_NAME); auto resultHandler = ConnectionEditorEvaluator::parseStatement(statement1); auto parsedStatement = ConnectionEditorStatements::okStatement(resultHandler); @@ -169,14 +169,14 @@ void tst_ConnectionEditor::displayStrings_data() QTest::newRow("Custom function call assignment") << "{someItem.color = item.functionCall()}" - << ConnectionEditorStatements::UNKNOWN_DISPLAY_NAME; + << ConnectionEditorStatements::CUSTOM_DISPLAY_NAME; QTest::newRow("Custom function call with argument") << "{someItem.color = item.functionCall(\"test\")}" - << ConnectionEditorStatements::UNKNOWN_DISPLAY_NAME; + << ConnectionEditorStatements::CUSTOM_DISPLAY_NAME; QTest::newRow("Custom function call with argument 2") - << "{item.functionCall(\"test\")}" << ConnectionEditorStatements::UNKNOWN_DISPLAY_NAME; + << "{item.functionCall(\"test\")}" << ConnectionEditorStatements::CUSTOM_DISPLAY_NAME; } void tst_ConnectionEditor::parseAssignment()