QmlDesigner: Fix loading of .metainfo for versioned folders

This fixes a regression introduced by 7ea6492a17.
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 <miikka.heikkinen@qt.io>
This commit is contained in:
Thomas Hartmann
2022-02-11 17:34:27 +01:00
parent c8481710c9
commit 0d319ac3a1
8 changed files with 291 additions and 19 deletions

View File

@@ -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) {

View File

@@ -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
}
}

View File

@@ -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
}
}
}

View File

@@ -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 {
}
}
}
}
}

View File

@@ -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"; }
}
}
}

View File

@@ -0,0 +1,2 @@
MyComponent 1.0 MyComponent.qml
MyComponent2 1.0 MyComponent2.qml

View File

@@ -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}
}
##^##*/

View File

@@ -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")
}
}