forked from qt-creator/qt-creator
Wizards: Bump QtQuick import version in file wizards
Use 2.15 as default, plus a little heuristic to use the same version as other files in the project. Fixes: QTCREATORBUG-27614 Change-Id: Ic84db5da97a9f35a2ad0e57fd47b75fb32a0b7f8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import QtQuick 2.0
|
import QtQuick 2.15
|
||||||
import QtTest 1.0
|
import QtTest 1.0
|
||||||
|
|
||||||
TestCase {
|
TestCase {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import QtQuick 2.0
|
import QtQuick %{QtQuickVersion}
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
|
|
||||||
|
@@ -3,13 +3,16 @@
|
|||||||
"supportedProjectTypes": [ ],
|
"supportedProjectTypes": [ ],
|
||||||
"id": "Q.Qml.2",
|
"id": "Q.Qml.2",
|
||||||
"category": "R.Qt",
|
"category": "R.Qt",
|
||||||
"trDescription": "Creates a QML file with boilerplate code, starting with \"import QtQuick 2.0\".",
|
"trDescription": "Creates a QML file with boilerplate code, starting with \"import QtQuick\".",
|
||||||
"trDisplayName": "QML File (Qt Quick 2)",
|
"trDisplayName": "QML File (Qt Quick 2)",
|
||||||
"trDisplayCategory": "Qt",
|
"trDisplayCategory": "Qt",
|
||||||
"iconText": "qml",
|
"iconText": "qml",
|
||||||
"enabled": "%{JS: value('Plugins').indexOf('QmlJSEditor') >= 0}",
|
"enabled": "%{JS: value('Plugins').indexOf('QmlJSEditor') >= 0}",
|
||||||
|
|
||||||
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-qml')}" },
|
"options": [
|
||||||
|
{"key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-qml')}"},
|
||||||
|
{"key": "QtQuickVersion", "value": "%{JS: Util.qtQuickVersion(value('TargetPath'))}"}
|
||||||
|
],
|
||||||
|
|
||||||
"pages" :
|
"pages" :
|
||||||
[
|
[
|
||||||
|
@@ -32,8 +32,10 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QDirIterator>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
#include <QVersionNumber>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -165,5 +167,34 @@ QString UtilsJsExtension::asciify(const QString &input) const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString UtilsJsExtension::qtQuickVersion(const QString &filePath) const
|
||||||
|
{
|
||||||
|
QDirIterator dirIt(Utils::FilePath::fromString(filePath).parentDir().path(), {"*.qml"},
|
||||||
|
QDir::Files, QDirIterator::Subdirectories);
|
||||||
|
while (dirIt.hasNext()) {
|
||||||
|
Utils::FileReader reader;
|
||||||
|
if (!reader.fetch(Utils::FilePath::fromString(dirIt.next())))
|
||||||
|
continue;
|
||||||
|
const QString data = QString::fromUtf8(reader.data());
|
||||||
|
static const QString importString("import QtQuick");
|
||||||
|
const int importIndex = data.indexOf(importString);
|
||||||
|
if (importIndex == -1)
|
||||||
|
continue;
|
||||||
|
const int versionIndex = importIndex + importString.length();
|
||||||
|
const int newLineIndex = data.indexOf('\n', versionIndex);
|
||||||
|
if (newLineIndex == -1)
|
||||||
|
continue;
|
||||||
|
const QString versionString = data.mid(versionIndex,
|
||||||
|
newLineIndex - versionIndex).simplified();
|
||||||
|
if (versionString.isEmpty())
|
||||||
|
return {};
|
||||||
|
const auto version = QVersionNumber::fromString(versionString);
|
||||||
|
if (version.isNull())
|
||||||
|
return {};
|
||||||
|
return version.toString();
|
||||||
|
}
|
||||||
|
return QLatin1String("2.15");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
@@ -76,6 +76,9 @@ public:
|
|||||||
|
|
||||||
// Generate a ascii-only string:
|
// Generate a ascii-only string:
|
||||||
Q_INVOKABLE QString asciify(const QString &input) const;
|
Q_INVOKABLE QString asciify(const QString &input) const;
|
||||||
|
|
||||||
|
// Heuristic to find out which QtQuick import version to use for the given file.
|
||||||
|
Q_INVOKABLE QString qtQuickVersion(const QString &filePath) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user