Schim
projectmanager.h
Go to the documentation of this file.
1 #ifndef PROJECTMANAGER_H
3 #define PROJECTMANAGER_H
4 
5 #include "model/project.h"
6 
7 #include <QList>
8 #include <QModelIndex>
9 
18 class ProjectManager : public QAbstractItemModel
19 {
20 public:
21  // CUSTOM ROLES
22  static constexpr int EntityTypeRole = Qt::UserRole + 1;
23  enum EntityType {
24  ProjectEntity, SheetEntity
25  };
26 
27  // CONSTRUCTORS
28  ProjectManager() = default;
29  ~ProjectManager();
30 
31  // GETTERS
32  QList<Project*> &getProjects();
33  Project* getActiveProject() const;
37  QModelIndex getIndex(Entity *entity) const;
41  bool isEmpty() const;
42 
43  // SETTERS
49  void setActiveProject(Project *project);
59  void addProject(Project *project);
69  void addSheet(Sheet *sheet, int index = -1, Project *project = nullptr);
76  void removeProject(Project *project);
82  void removeSheet(Sheet *sheet);
83 
84  // OVERRIDE QAbstractItemModel
88  QVariant data(const QModelIndex &index, int role) const override;
89  int rowCount(const QModelIndex &parent) const override;
90 private: // These methods are not exposed to the interface
91  int columnCount(const QModelIndex &parent) const override;
92  QModelIndex index(int row, int column, const QModelIndex &parent)
93  const override;
94  QModelIndex parent(const QModelIndex &child) const override;
95  Qt::ItemFlags flags() const;
96 
97 private:
99  QList<Project*> projects;
101  Project *activeProject{};
102 };
103 
104 #endif // PROJECTMANAGER_H
A model that manages open projects.
Definition: projectmanager.h:18
void addSheet(Sheet *sheet, int index=-1, Project *project=nullptr)
Add a new sheet to project and register it in the manager.
QModelIndex getIndex(Entity *entity) const
Get the model index of the project or sheet that entity points to.
A project is essentially a list of sheets, along with some project properties.
Definition: project.h:16
void addProject(Project *project)
Add a project to the manager.
void removeProject(Project *project)
Remove project from the manager and destroy it.
QVariant data(const QModelIndex &index, int role) const override
Get the model data.
Base class for entities.
Definition: entity.h:32
bool isEmpty() const
Return true if no projects are open, false otherwise.
void removeSheet(Sheet *sheet)
Remove sheet from the manager and from its project.
This class models a sheet of paper.
Definition: sheet.h:16
void setActiveProject(Project *project)
Set the active project. This will notify all views that the new active project and the previous activ...