QmlDesigner: Use ExamplesModelV2

V2 adds minQDSVersion property for model items

Change-Id: I27d36428f73b27b1d52d429e23654d094d6ff86d
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
Mahmoud Badri
2024-03-27 19:02:50 +02:00
parent ff4e33dc0a
commit c04eb4444d
2 changed files with 42 additions and 1 deletions

View File

@@ -88,7 +88,17 @@ Item {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
hover: hoverHandler.hovered hover: hoverHandler.hovered
model: ExamplesModel { id: examplesModel}
Component.onCompleted: {
// remove items with old versions from the examples model
for (let i = examplesModel.count - 1; i >= 0; --i) {
if (!projectModel.exampleVersionOk(examplesModel.get(i).minQDSVersion))
examplesModel.remove(i)
}
}
model: ExamplesModelV2 { id: examplesModel }
delegate: ThumbnailDelegate { delegate: ThumbnailDelegate {
type: ThumbnailDelegate.Type.Example type: ThumbnailDelegate.Type.Example
downloadable: showDownload downloadable: showDownload

View File

@@ -333,6 +333,37 @@ public:
Core::EditorManager::openEditor(qmlFile); Core::EditorManager::openEditor(qmlFile);
} }
Q_INVOKABLE bool exampleVersionOk(const QString &exampleVersion)
{
if (exampleVersion.isEmpty())
return true;
const QStringList exampleVersionParts = exampleVersion.split('.');
const QStringList qdsVersionParts = QCoreApplication::applicationVersion().split('.');
QList<int> exampleVerInts;
QList<int> qdsVerInts;
for (const QString &part : exampleVersionParts)
exampleVerInts.append(part.toInt());
for (const QString &part : qdsVersionParts)
qdsVerInts.append(part.toInt());
// pad zeros so both lists are same size
while (qdsVerInts.size() < exampleVerInts.size())
qdsVerInts.append(0);
while (exampleVerInts.size() < qdsVerInts.size())
exampleVerInts.append(0);
for (int i = 0; i < qdsVerInts.size(); ++i) {
if (exampleVerInts[i] < qdsVerInts[i])
return false;
}
return true;
}
public slots: public slots:
void resetProjects(); void resetProjects();
void delayedResetProjects(); void delayedResetProjects();