aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hartmann <thomas.hartmann@qt.io>2022-01-12 18:27:48 +0100
committerThomas Hartmann <thomas.hartmann@qt.io>2022-01-13 08:07:06 +0000
commit1c8baecaf2c33a9a5dc94d4962eb0ef1adc309cd (patch)
treee98fdb0168bf9496bece6e29f35ce0209c4b1d7c
parent146225b94b125adf374bcdfeb6873fc3deb9cf37 (diff)
StudioWelcome: Add support for version and resolution in description
Change-Id: I6e404907b96b7f7988da8622e37217a756a1ca9f Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--src/plugins/studiowelcome/studiowelcomeplugin.cpp66
1 files changed, 59 insertions, 7 deletions
diff --git a/src/plugins/studiowelcome/studiowelcomeplugin.cpp b/src/plugins/studiowelcome/studiowelcomeplugin.cpp
index e8271bb9ee..123e9154cc 100644
--- a/src/plugins/studiowelcome/studiowelcomeplugin.cpp
+++ b/src/plugins/studiowelcome/studiowelcomeplugin.cpp
@@ -268,6 +268,24 @@ int ProjectModel::rowCount(const QModelIndex &) const
return ProjectExplorer::ProjectExplorerPlugin::recentProjects().count();
}
+QString getQDSVersion(const QString &projectFilePath)
+{
+ const QString defaultReturn = "";
+ Utils::FileReader reader;
+ if (!reader.fetch(Utils::FilePath::fromString(projectFilePath)))
+ return defaultReturn;
+
+ const QByteArray data = reader.data();
+
+ QRegularExpression regexp(R"x(qdsVersion: "(.*)")x");
+ QRegularExpressionMatch match = regexp.match(QString::fromUtf8(data));
+
+ if (!match.hasMatch())
+ return defaultReturn;
+
+ return ProjectModel::tr("Created with Qt Design Studio version: %1").arg(match.captured(1));
+}
+
QString getMainQmlFile(const QString &projectFilePath)
{
const QString defaultReturn = "content/App.qml";
@@ -293,8 +311,8 @@ QString appQmlFile(const QString &projectFilePath)
static QString fromCamelCase(const QString &s) {
- static QRegularExpression regExp1 {"(.)([A-Z][a-z]+)"};
- static QRegularExpression regExp2 {"([a-z0-9])([A-Z])"};
+ const QRegularExpression regExp1 {"(.)([A-Z][a-z]+)"};
+ const QRegularExpression regExp2 {"([a-z0-9])([A-Z])"};
QString result = s;
result.replace(regExp1, "\\1 \\2");
result.replace(regExp2, "\\1 \\2");
@@ -302,15 +320,49 @@ static QString fromCamelCase(const QString &s) {
return result;
}
+static QString resolutionFromConstants(const QString &projectFilePath)
+{
+ const QFileInfo fileInfo(projectFilePath);
+ const QString fileName = fileInfo.dir().absolutePath()
+ + "/" + "imports" + "/" + fileInfo.baseName() + "/Constants.qml";
+
+ Utils::FileReader reader;
+ if (!reader.fetch(Utils::FilePath::fromString(fileName)))
+ return {};
+
+ const QByteArray data = reader.data();
+
+ const QRegularExpression regexpWidth(R"x(readonly\s+property\s+int\s+width:\s+(\d*))x");
+ const QRegularExpression regexpHeight(R"x(readonly\s+property\s+int\s+height:\s+(\d*))x");
+
+ int width = -1;
+ int height = -1;
+
+ QRegularExpressionMatch match = regexpHeight.match(QString::fromUtf8(data));
+ if (match.hasMatch())
+ height = match.captured(1).toInt();
+
+ match = regexpWidth.match(QString::fromUtf8(data));
+ if (match.hasMatch())
+ width = match.captured(1).toInt();
+
+ if (width > 0 && height > 0)
+ return ProjectModel::tr("Resolution: %1x%2").arg(width).arg(height);
+
+ return {};
+}
+
static QString description(const QString &projectFilePath)
{
- const QString created = "Created: " +
- QFileInfo(projectFilePath).fileTime(QFileDevice::FileBirthTime).toString();
- const QString lastEdited = "Last Edited: " +
- QFileInfo(projectFilePath).fileTime(QFileDevice::FileModificationTime).toString();
+ const QString created = ProjectModel::tr("Created: %1").arg(
+ QFileInfo(projectFilePath).fileTime(QFileDevice::FileBirthTime).toString());
+ const QString lastEdited = ProjectModel::tr("Last Edited: %1").arg(
+ QFileInfo(projectFilePath).fileTime(QFileDevice::FileModificationTime).toString());
- return fromCamelCase(QFileInfo(projectFilePath).baseName()) + "\n" + created + "\n" + lastEdited;
+ return fromCamelCase(QFileInfo(projectFilePath).baseName()) + "\n\n" + created + "\n" + lastEdited
+ + "\n" + resolutionFromConstants(projectFilePath)
+ + "\n" + getQDSVersion(projectFilePath);
}
static QString tags(const QString &projectFilePath)