picturemodel.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef PICTUREMODEL_H
  2. #define PICTUREMODEL_H
  3. #include <QAbstractListModel>
  4. class Node {
  5. public:
  6. Node(const QString &name) : m_name(name) {}
  7. // TODO: symlink considerations
  8. // parentNode is clearly always a directory
  9. private:
  10. Node *m_parentNode;
  11. QString m_name;
  12. };
  13. class PictureModel : public QAbstractListModel
  14. {
  15. Q_OBJECT
  16. public:
  17. enum PictureRoles {
  18. PathRole = Qt::UserRole + 1
  19. };
  20. static PictureModel* instance();
  21. bool setModelRoot(const QString &root);
  22. int rowCount(const QModelIndex & parent = QModelIndex()) const;
  23. Q_INVOKABLE QString randomPicture() const;
  24. QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
  25. bool addPath(const QString &path);
  26. void addSupportedExtension(const QString &extension);
  27. protected:
  28. QHash<int, QByteArray> roleNames() const;
  29. private:
  30. static PictureModel* model;
  31. PictureModel(QObject *parent = 0);
  32. QList<Node> nodes;
  33. QStringList paths;
  34. QStringList extensions;
  35. };
  36. #endif // PICTUREMODEL_H