File indexing completed on 2024-05-12 15:42:34

0001 /*
0002     SPDX-FileCopyrightText: %{CURRENT_YEAR} %{AUTHOR} <%{EMAIL}>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef MYDATASYSTEM_H
0008 #define MYDATASYSTEM_H
0009 
0010 // Qt
0011 #include <QHash>
0012 #include <QStringList>
0013 #include <QByteArray>
0014 
0015 // A sample class transporting the system data structure that would be mapped onto a file
0016 class DataItem
0017 {
0018 public:
0019     QString name;
0020     QByteArray data() const;
0021     bool isValid() const { return !name.isEmpty(); }
0022 };
0023 
0024 // A sample class transporting the system data structure that would be mapped onto a directory
0025 class DataGroup
0026 {
0027 public:
0028     QHash<QString, DataGroup> subGroups;
0029     QList<DataItem> items;
0030 };
0031 
0032 
0033 // A sample data system adapter 
0034 class MyDataSystem
0035 {
0036 public:
0037     MyDataSystem();
0038 
0039 public: // sync calls querying data from the actual data system
0040     bool hasGroup(const QStringList &groupPath) const;
0041     QList<DataItem> items(const QStringList &groupPath) const;
0042     DataItem item(const QStringList& groupPath, const QString &itemName) const;
0043     QStringList subGroupNames(const QStringList &groupPath) const;
0044 
0045 private:
0046     const DataGroup* group(const QStringList& groupPath) const;
0047 
0048 private:
0049     // hardcoded sample data to simulate that in the data system
0050     DataGroup m_toplevelGroup;
0051 };
0052 
0053 #endif