Sun, 03 Nov 2019 12:56:42 +0200
added saving of splitter state and recent files
7 | 1 | #pragma once |
2 | #include <QDir> | |
3 | #include <QAbstractTableModel> | |
4 | #include "main.h" | |
5 | ||
6 | class QSettings; | |
7 | ||
8 | struct Library | |
9 | { | |
10 | enum Role | |
11 | { | |
12 | OfficialLibrary, | |
13 | UnofficialLibrary, | |
14 | WorkingLibrary, | |
15 | } role; | |
16 | QDir path; | |
17 | static QString libraryRoleName(const Role role); | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
18 | static bool isValidRole(const Role role); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
19 | constexpr static const Role allRoles[] = {OfficialLibrary, UnofficialLibrary, WorkingLibrary}; |
7 | 20 | }; |
21 | ||
22 | Q_DECLARE_METATYPE(Library) | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
23 | Q_DECLARE_METATYPE(Library::Role) |
7 | 24 | QDataStream &operator<<(QDataStream&, const Library&); |
25 | QDataStream &operator>>(QDataStream&, Library&); | |
26 | ||
27 | using Libraries = QVector<Library>; | |
28 | Q_DECLARE_METATYPE(Libraries) | |
29 | ||
30 | class LibraryManager : public QAbstractTableModel | |
31 | { | |
32 | Q_OBJECT | |
33 | public: | |
34 | LibraryManager(QObject* parent = nullptr); | |
35 | LibraryManager(QSettings* settings, QObject* parent = nullptr); | |
36 | QVector<Library>::const_iterator begin() const; | |
37 | QVector<Library>::const_iterator end() const; | |
38 | QFileInfo findFile(QString fileName) const; | |
39 | void addLibrary(const Library& library); | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
40 | void removeLibrary(const int libraryIndex); |
7 | 41 | const Library& library(int libraryIndex) const; |
42 | void setLibraryPath(int libraryIndex, const QDir& path); | |
43 | void setLibraryRole(int libraryIndex, const Library::Role role); | |
44 | void restoreFromSettings(QSettings* settings); | |
45 | void storeToSettings(QSettings* settings); | |
46 | int count() const; | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
47 | void moveLibrary(const int libraryFromIndex, const int libraryToIndex); |
7 | 48 | // Definitions for QAbstractTableModel |
49 | Qt::ItemFlags flags(const QModelIndex& index) const override; | |
50 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | |
51 | QVariant headerData( | |
52 | int section, | |
53 | Qt::Orientation orientation, | |
54 | int role = Qt::DisplayRole) const override; | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
55 | int rowCount(const QModelIndex&) const override; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
56 | int columnCount(const QModelIndex&) const override; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
57 | bool isValidIndex(const int libraryIndex) const; |
7 | 58 | private: |
59 | enum Column | |
60 | { | |
61 | RoleColumn, | |
62 | PathColumn | |
63 | }; | |
64 | void signalLibraryChange(int library); | |
65 | Libraries libraries; | |
66 | }; |