Schim
database.h
1 #ifndef DATABASE_H
2 #define DATABASE_H
3 
4 #include "model/object.h"
5 
6 #include <QAbstractItemModel>
7 #include <QString>
8 
13 {
14 public:
23  explicit DatabaseItem(const QString &path, DatabaseItem *parentItem = nullptr);
24  ~DatabaseItem();
25 
26  void appendItem(DatabaseItem *child);
27 
28  // GETTERS
29  QString getName() const;
30  QString getPath() const;
37  QImage getIcon() const;
38  Object *getObject();
39  Qt::ItemFlags getFlags() const;
40  bool isDir() const;
41 
42  // SETTERS
46  void setPath(QString path);
53  void setName(const QString &name);
54 
55  // BOILERPLATE
56  DatabaseItem *getChild(int row);
57  int getChildCount() const;
58  int getColumnCount() const;
59  QVariant getData(int column) const;
60  int getRow() const;
61  DatabaseItem *getParentItem();
62 
63 private:
64  QString path, name;
65  DatabaseItem *parent;
66  QVector<DatabaseItem*> childItems;
67  CompositeObject *object{};
69  mutable QImage *icon{};
70 };
71 
77 class Database : public QAbstractItemModel
78 {
79  Q_OBJECT
80 public:
81  explicit Database(const QString &path);
82  ~Database();
83 
89  QVariant data(const QModelIndex &index, int role) const override;
93  void update();
102  bool iterateLeaves(const QModelIndex &index,
103  std::function<bool(const QModelIndex&)> fun);
104 
105  // BOILERPLATE
106  Qt::ItemFlags flags(const QModelIndex &index) const override;
107  QModelIndex index(int row, int column, const QModelIndex &parent = {}) const
108  override;
109  QModelIndex parent(const QModelIndex &index) const override;
110  int rowCount(const QModelIndex &parent = {}) const override;
111  int columnCount(const QModelIndex &parent = {}) const override;
112 
113 private:
114  // HELPERS
122  void iterate(const QString &dir, DatabaseItem *parent);
123 
124  // ATTRIBUTES
125  DatabaseItem *rootItem{};
126  QString path;
127 };
128 
129 #endif // DATABASE_H
The abstract base class for all objects in a sheet.
Definition: object.h:21
void setName(const QString &name)
Set the friendly name of the item.
A database of symbols.
Definition: database.h:77
void setPath(QString path)
Set the path of this database item.
DatabaseItem(const QString &path, DatabaseItem *parentItem=nullptr)
Construct a database item.
An item in a Database.
Definition: database.h:12
QImage getIcon() const
Return the icon used to represent the item in the component browser.
An object that consists of other child objects.
Definition: compositeobject.h:16