aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qtsupport/exampleslistmodel.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2023-01-16 17:20:56 +0100
committerEike Ziller <eike.ziller@qt.io>2023-01-18 10:16:46 +0000
commit6c6277bc7d47b4e98019a0f9d93cb5dabbcd3cbc (patch)
tree45b4e1c776a38fd4dbf0385af443fa1adf1a32b0 /src/plugins/qtsupport/exampleslistmodel.cpp
parente3acf9262b610a3cd01c871366c748a6a1258db1 (diff)
ExamplesListModel: Remove direct access of model items variable
Change-Id: I8dc2833f61fe0267953acfa8746151cea893c7f3 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/qtsupport/exampleslistmodel.cpp')
-rw-r--r--src/plugins/qtsupport/exampleslistmodel.cpp45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/plugins/qtsupport/exampleslistmodel.cpp b/src/plugins/qtsupport/exampleslistmodel.cpp
index d0c85ef241..cdfc6c872d 100644
--- a/src/plugins/qtsupport/exampleslistmodel.cpp
+++ b/src/plugins/qtsupport/exampleslistmodel.cpp
@@ -29,6 +29,7 @@
#include <algorithm>
#include <memory>
+using namespace Core;
using namespace Utils;
namespace QtSupport {
@@ -331,9 +332,11 @@ static bool isValidExampleOrDemo(ExampleItem *item)
return ok || debugExamples();
}
-void ExamplesListModel::parseExamples(QXmlStreamReader *reader,
- const QString &projectsOffset, const QString &examplesInstallPath)
+static QList<ListItem *> parseExamples(QXmlStreamReader *reader,
+ const QString &projectsOffset,
+ const QString &examplesInstallPath)
{
+ QList<ListItem *> result;
std::unique_ptr<ExampleItem> item;
const QChar slash = QLatin1Char('/');
while (!reader->atEnd()) {
@@ -374,20 +377,23 @@ void ExamplesListModel::parseExamples(QXmlStreamReader *reader,
case QXmlStreamReader::EndElement:
if (reader->name() == QLatin1String("example")) {
if (isValidExampleOrDemo(item.get()))
- m_items.push_back(item.release());
+ result.push_back(item.release());
} else if (reader->name() == QLatin1String("examples")) {
- return;
+ return result;
}
break;
default: // nothing
break;
}
}
+ return result;
}
-void ExamplesListModel::parseDemos(QXmlStreamReader *reader,
- const QString &projectsOffset, const QString &demosInstallPath)
+static QList<ListItem *> parseDemos(QXmlStreamReader *reader,
+ const QString &projectsOffset,
+ const QString &demosInstallPath)
{
+ QList<ListItem *> result;
std::unique_ptr<ExampleItem> item;
const QChar slash = QLatin1Char('/');
while (!reader->atEnd()) {
@@ -419,19 +425,21 @@ void ExamplesListModel::parseDemos(QXmlStreamReader *reader,
case QXmlStreamReader::EndElement:
if (reader->name() == QLatin1String("demo")) {
if (isValidExampleOrDemo(item.get()))
- m_items.push_back(item.release());
+ result.push_back(item.release());
} else if (reader->name() == QLatin1String("demos")) {
- return;
+ return result;
}
break;
default: // nothing
break;
}
}
+ return result;
}
-void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset)
+static QList<ListItem *> parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset)
{
+ QList<ListItem *> result;
std::unique_ptr<ExampleItem> item;
const QChar slash = QLatin1Char('/');
while (!reader->atEnd()) {
@@ -465,14 +473,15 @@ void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString &
break;
case QXmlStreamReader::EndElement:
if (reader->name() == QLatin1String("tutorial"))
- m_items.push_back(item.release());
+ result.push_back(item.release());
else if (reader->name() == QLatin1String("tutorials"))
- return;
+ return result;
break;
default: // nothing
break;
}
}
+ return result;
}
void ExamplesListModel::updateExamples()
@@ -482,10 +491,10 @@ void ExamplesListModel::updateExamples()
const QStringList sources = m_exampleSetModel.exampleSources(&examplesInstallPath,
&demosInstallPath);
- beginResetModel();
- qDeleteAll(m_items);
- m_items.clear();
+ clear();
+
+ QList<ListItem *> items;
for (const QString &exampleSource : sources) {
QFile exampleFile(exampleSource);
if (!exampleFile.open(QIODevice::ReadOnly)) {
@@ -506,11 +515,11 @@ void ExamplesListModel::updateExamples()
switch (reader.readNext()) {
case QXmlStreamReader::StartElement:
if (reader.name() == QLatin1String("examples"))
- parseExamples(&reader, examplesDir.path(), examplesInstallPath);
+ items += parseExamples(&reader, examplesDir.path(), examplesInstallPath);
else if (reader.name() == QLatin1String("demos"))
- parseDemos(&reader, demosDir.path(), demosInstallPath);
+ items += parseDemos(&reader, demosDir.path(), demosInstallPath);
else if (reader.name() == QLatin1String("tutorials"))
- parseTutorials(&reader, examplesDir.path());
+ items += parseTutorials(&reader, examplesDir.path());
break;
default: // nothing
break;
@@ -522,7 +531,7 @@ void ExamplesListModel::updateExamples()
<< ": " << reader.errorString();
}
}
- endResetModel();
+ appendItems(items);
}
void ExampleSetModel::updateQtVersionList()