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>
This commit is contained in:
Thomas Hartmann
2022-01-12 18:27:48 +01:00
parent 146225b94b
commit 1c8baecaf2

View File

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