forked from qt-creator/qt-creator
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:
@@ -88,7 +88,17 @@ Item {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
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 {
|
||||
type: ThumbnailDelegate.Type.Example
|
||||
downloadable: showDownload
|
||||
|
||||
@@ -333,6 +333,37 @@ public:
|
||||
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:
|
||||
void resetProjects();
|
||||
void delayedResetProjects();
|
||||
|
||||
Reference in New Issue
Block a user