picturemodel.h 984 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
  24. bool addPath(const QString &path);
  25. void addSupportedExtension(const QString &extension);
  26. protected:
  27. QHash<int, QByteArray> roleNames() const;
  28. private:
  29. static PictureModel* model;
  30. PictureModel(QObject *parent = 0);
  31. QList<Node> nodes;
  32. QStringList paths;
  33. QStringList extensions;
  34. };
  35. #endif // PICTUREMODEL_H