From 0d319ac3a1b558fab759ede8dc2178ccdb3502ea Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Fri, 11 Feb 2022 17:34:27 +0100 Subject: [PATCH] QmlDesigner: Fix loading of .metainfo for versioned folders This fixes a regression introduced by 7ea6492a17736e079ddf192b18d061076dfbf9c7. Since we actually check if import folders exist, we did not take versioned folders into account. e.g. 'MyPlugin.1' Extended and cleaned up the manual test case. Task-number: QDS-6078 Change-Id: I3235d8fe498745903c5ca897e25e3d43222c119f Reviewed-by: Miikka Heikkinen --- .../metainfo/subcomponentmanager.cpp | 46 +++++++--- .../imports/MyPlugin2.1/MyComponent.qml | 38 +++++++++ .../imports/MyPlugin2.1/MyComponent2.qml | 43 ++++++++++ .../designer/MyComponentSpecifics.qml | 84 +++++++++++++++++++ .../MyPlugin2.1/designer/MyPlugin.metainfo | 44 ++++++++++ .../plugins/imports/MyPlugin2.1/qmldir | 2 + .../qml/testprojects/plugins/plugins.qml | 15 ++-- .../qml/testprojects/plugins/plugins2.qml | 38 +++++++++ 8 files changed, 291 insertions(+), 19 deletions(-) create mode 100644 tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/MyComponent.qml create mode 100644 tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/MyComponent2.qml create mode 100644 tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/designer/MyComponentSpecifics.qml create mode 100644 tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/designer/MyPlugin.metainfo create mode 100644 tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/qmldir create mode 100644 tests/manual/qml/testprojects/plugins/plugins2.qml diff --git a/src/plugins/qmldesigner/designercore/metainfo/subcomponentmanager.cpp b/src/plugins/qmldesigner/designercore/metainfo/subcomponentmanager.cpp index a001a8b0c29..9ff3289e459 100644 --- a/src/plugins/qmldesigner/designercore/metainfo/subcomponentmanager.cpp +++ b/src/plugins/qmldesigner/designercore/metainfo/subcomponentmanager.cpp @@ -69,10 +69,38 @@ SubComponentManager::SubComponentManager(Model *model, QObject *parent) this, [this](const QString &path) { parseDirectory(path); }); } +QString findFolderForImport(const QStringList &importPaths, const QString &url) +{ + if (url.isEmpty()) + return {}; + + QString folderUrl = url; + folderUrl.replace('.', '/'); + + for (const QString &path : importPaths) { + QFileInfo dirInfo = QFileInfo(path + QLatin1Char('/') + folderUrl); + + if (dirInfo.exists() && dirInfo.isDir()) + return dirInfo.canonicalFilePath(); + + const QDir parentDir = dirInfo.dir(); + if (parentDir.exists()) { + const QStringList parts = url.split('.'); + const QString lastFolder = parts.last(); + + const QStringList candidates = parentDir.entryList({lastFolder + ".*"}, QDir::Dirs); + if (!candidates.isEmpty()) + return parentDir.canonicalPath() + "/" + candidates.first(); + } + } + return {}; +} bool SubComponentManager::addImport(const Import &import, int index) { - if (debug) + if (debug) { qDebug() << Q_FUNC_INFO << index << import.file().toUtf8(); + qDebug() << Q_FUNC_INFO << index << import.url(); + } bool importExists = false; if (import.isFileImport()) { @@ -85,19 +113,11 @@ bool SubComponentManager::addImport(const Import &import, int index) } } else { QString url = import.url(); - - url.replace(QLatin1Char('.'), QLatin1Char('/')); - - foreach (const QString &path, importPaths()) { - QFileInfo dirInfo = QFileInfo(path + QLatin1Char('/') + url); - if (dirInfo.exists() && dirInfo.isDir()) { - const QString canonicalDirPath = dirInfo.canonicalFilePath(); - m_watcher.addPath(canonicalDirPath); - importExists = true; - //m_dirToQualifier.insertMulti(canonicalDirPath, import.qualifier()); ### todo: proper support for import as - } + const QString result = findFolderForImport(importPaths(), url); + if (!result.isEmpty()) { + m_watcher.addPath(result); + importExists = true; } - // TODO: QDeclarativeDomImport::Library } if (importExists) { diff --git a/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/MyComponent.qml b/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/MyComponent.qml new file mode 100644 index 00000000000..e52e52d7d10 --- /dev/null +++ b/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/MyComponent.qml @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 60 + height: 60 + color: "green" + property alias text: textItem.text + + Text { + id: textItem + anchors.centerIn: parent + } +} diff --git a/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/MyComponent2.qml b/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/MyComponent2.qml new file mode 100644 index 00000000000..5e2306a716f --- /dev/null +++ b/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/MyComponent2.qml @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + property alias text: textItem.text + property alias color: rect.color + property alias radius: rect.radius + + Rectangle { + id: rect + anchors.fill: parent + color: "green" + + Text { + id: textItem + anchors.centerIn: parent + } + } +} diff --git a/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/designer/MyComponentSpecifics.qml b/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/designer/MyComponentSpecifics.qml new file mode 100644 index 00000000000..c6c888e369c --- /dev/null +++ b/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/designer/MyComponentSpecifics.qml @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +import QtQuick 2.0 +import HelperWidgets 2.0 +import QtQuick.Layouts 1.0 + +Column { + anchors.left: parent.left + anchors.right: parent.right + + Section { + anchors.left: parent.left + anchors.right: parent.right + caption: qsTr("Color") + + ColorEditor { + caption: qsTr("Color") + backendValue: backendValues.color + supportGradient: true + } + + + } + + Section { + anchors.left: parent.left + anchors.right: parent.right + caption: "Rectangle" + + SectionLayout { + rows: 2 + + Label { + text: qsTr("Text") + } + + SecondColumnLayout { + LineEdit { + backendValue: backendValues.text + Layout.fillWidth: true + } + } + + Label { + text: qsTr("Radius") + } + SecondColumnLayout { + SpinBox { + backendValue: backendValues.radius + hasSlider: true + Layout.preferredWidth: 80 + minimumValue: 0 + maximumValue: Math.min(backendValues.height.value, backendValues.width.value) / 2 + } + ExpandingSpacer { + + } + } + } + } +} diff --git a/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/designer/MyPlugin.metainfo b/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/designer/MyPlugin.metainfo new file mode 100644 index 00000000000..5eef250228c --- /dev/null +++ b/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/designer/MyPlugin.metainfo @@ -0,0 +1,44 @@ +MetaInfo { + Type { + name: "MyPlugin2.MyComponent" + icon: ":/qtquickplugin/images/item-icon16.png" + + ItemLibraryEntry { + name: "My Component" + category: "My Test Plugin 2" + libraryIcon: ":/qtquickplugin/images/item-icon.png" + version: "1.0" + requiredImport: "MyPlugin2" + + Property { + name: "text" + type: "binding" + value: "qsTr(\"This is text\")" + } + } + } + + Type { + name: "MyPlugin2.MyComponent2" + icon: ":/qtquickplugin/images/item-icon16.png" + + ItemLibraryEntry { + name: "My Component 2" + category: "My Test Plugin 2" + libraryIcon: ":/qtquickplugin/images/item-icon.png" + version: "1.0" + requiredImport: "MyPlugin2" + + Property { + name: "text" + type: "binding" + value: "qsTr(\"This is text\")" + } + + Property { name: "width"; type: "int"; value: 200; } + Property { name: "height"; type: "int"; value: 200; } + Property { name: "color"; type: "QColor"; value: "red"; } + } + } + +} diff --git a/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/qmldir b/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/qmldir new file mode 100644 index 00000000000..660f6d416b0 --- /dev/null +++ b/tests/manual/qml/testprojects/plugins/imports/MyPlugin2.1/qmldir @@ -0,0 +1,2 @@ +MyComponent 1.0 MyComponent.qml +MyComponent2 1.0 MyComponent2.qml diff --git a/tests/manual/qml/testprojects/plugins/plugins.qml b/tests/manual/qml/testprojects/plugins/plugins.qml index dc3d729077e..daf85ad3892 100644 --- a/tests/manual/qml/testprojects/plugins/plugins.qml +++ b/tests/manual/qml/testprojects/plugins/plugins.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. @@ -23,13 +23,10 @@ ** ****************************************************************************/ -import QtQuick 2.3 -import QtQuick.Controls 1.2 -import QtQuick.Window 2.2 +import QtQuick import MyPlugin 1.0 -ApplicationWindow { - title: qsTr("Hello World") +Rectangle { width: 640 height: 480 @@ -38,3 +35,9 @@ ApplicationWindow { } } + +/*##^## +Designer { + D{i:0;autoSize:true;height:480;width:640} +} +##^##*/ diff --git a/tests/manual/qml/testprojects/plugins/plugins2.qml b/tests/manual/qml/testprojects/plugins/plugins2.qml new file mode 100644 index 00000000000..9e586d56f85 --- /dev/null +++ b/tests/manual/qml/testprojects/plugins/plugins2.qml @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +import QtQuick 2.3 +import MyPlugin2 1.0 + +Rectangle { + + width: 640 + height: 480 + + MyComponent { + text: qsTr("Some Text") + + } +}