MCPcopy Create free account
hub / github.com/KDE/labplot / exampleNames

Method exampleNames

src/frontend/examples/ExamplesManager.cpp:62–132  ·  view source on GitHub ↗

! * \brief returns the list of names of the example projects for the collection \c collecitonName */

Source from the content-addressed store, hash-verified

60 * \brief returns the list of names of the example projects for the collection \c collecitonName
61 */
62QStringList ExamplesManager::exampleNames(const QString& collectionName) {
63 // load the collection if not done yet
64 if (!m_examples.contains(collectionName)) {
65 // example projects of the currently selected collection not loaded yet -> load them
66 QStringList names;
67 QDirIterator it(m_jsonDir + QLatin1Char('/') + collectionName, QStringList() << QLatin1String("*.lml"), QDir::Files, QDirIterator::Subdirectories);
68 while (it.hasNext()) {
69 const auto& fileName = it.next();
70 const auto& name = QFileInfo(fileName).baseName();
71 names << name;
72 m_paths[name] = fileName;
73
74 // check compression, s.a. Project::load()
75 QIODevice* file = new QFile(fileName);
76 if (!file->open(QIODevice::ReadOnly)) {
77 delete file;
78 continue;
79 }
80
81 QDataStream in(file);
82 quint16 magic;
83 in >> magic;
84 file->close();
85 delete file;
86
87 if (!magic) // empty file
88 continue;
89
90 if (magic == 0xfd37) // XZ compressed data
91 file = new KCompressionDevice(fileName, KCompressionDevice::Xz);
92 else // gzip or not compressed data
93 file = new KCompressionDevice(fileName, KCompressionDevice::GZip);
94
95 if (!file->open(QIODevice::ReadOnly)) {
96 file->close();
97 delete file;
98 continue;
99 }
100
101 // parse the XML and read the description and the preview pixmap of the project file
102 QXmlStreamReader reader(file);
103 reader.readNext();
104 while (!reader.atEnd()) {
105 reader.readNext();
106
107 if (reader.isEndElement())
108 break;
109
110 if (reader.isStartElement()) {
111 if (reader.name() == QLatin1String("project")) {
112 QString content = reader.attributes().value(QLatin1String("thumbnail")).toString();
113 QByteArray ba = QByteArray::fromBase64(content.toLatin1());
114 QPixmap pixmap;
115 pixmap.loadFromData(ba);
116 m_pixmaps[name] = std::move(pixmap);
117 } else if (reader.name() == QLatin1String("comment")) {
118 m_descriptions[name] = reader.readElementText();
119 break;

Callers 1

collectionChangedMethod · 0.80

Calls 8

nextMethod · 0.80
atEndMethod · 0.80
containsMethod · 0.45
openMethod · 0.45
closeMethod · 0.45
nameMethod · 0.45
toStringMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected