AlbumModel.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef ALBUMMODEL_H
  2. #define ALBUMMODEL_H
  3. #include <QAbstractListModel>
  4. #include "Album.h"
  5. #include "DatabaseManager.h"
  6. #include "gallery-core_global.h"
  7. class GALLERYCORE_EXPORT AlbumModel : public QAbstractListModel {
  8. Q_OBJECT
  9. public:
  10. enum Roles {
  11. IdRole = Qt::UserRole + 1,
  12. NameRole,
  13. };
  14. AlbumModel(QObject *parent = 0);
  15. QModelIndex addAlbum(const Album &album);
  16. // QAbstractItemModel interface
  17. public:
  18. int rowCount(const QModelIndex &parent = QModelIndex()) const override;
  19. QVariant data(const QModelIndex &index,
  20. int role = Qt::DisplayRole) const override;
  21. bool setData(const QModelIndex &index, const QVariant &value,
  22. int role) override;
  23. bool removeRows(int row, int count, const QModelIndex &parent) override;
  24. QHash<int, QByteArray> roleNames() const override;
  25. private:
  26. bool isIndexValid(const QModelIndex &index) const;
  27. private:
  28. DatabaseManager &mDb;
  29. std::unique_ptr<std::vector<std::unique_ptr<Album>>> mAlbums;
  30. };
  31. #endif // ALBUMMODEL_H