From 1c8baecaf2c33a9a5dc94d4962eb0ef1adc309cd Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Wed, 12 Jan 2022 18:27:48 +0100 Subject: [PATCH] StudioWelcome: Add support for version and resolution in description Change-Id: I6e404907b96b7f7988da8622e37217a756a1ca9f Reviewed-by: Reviewed-by: Qt CI Bot Reviewed-by: Thomas Hartmann --- .../studiowelcome/studiowelcomeplugin.cpp | 66 +++++++++++++++++-- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/src/plugins/studiowelcome/studiowelcomeplugin.cpp b/src/plugins/studiowelcome/studiowelcomeplugin.cpp index e8271bb9eed..123e9154cc1 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)