Sat, 01 Feb 2020 15:33:57 +0200
wired renderstyle up
24 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 - 2020 Teemu Piippo | |
4 | * | |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
7 | 19 | #pragma once |
20 | #include <QDir> | |
21 | #include <QAbstractTableModel> | |
22 | #include "main.h" | |
26 | 23 | #include "colors.h" |
7 | 24 | |
25 | class QSettings; | |
26 | ||
27 | struct Library | |
28 | { | |
29 | enum Role | |
30 | { | |
31 | OfficialLibrary, | |
32 | UnofficialLibrary, | |
33 | WorkingLibrary, | |
34 | } role; | |
35 | QDir path; | |
36 | static QString libraryRoleName(const Role role); | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
37 | static bool isValidRole(const Role role); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
38 | constexpr static const Role allRoles[] = {OfficialLibrary, UnofficialLibrary, WorkingLibrary}; |
7 | 39 | }; |
40 | ||
41 | Q_DECLARE_METATYPE(Library) | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
42 | Q_DECLARE_METATYPE(Library::Role) |
7 | 43 | QDataStream &operator<<(QDataStream&, const Library&); |
44 | QDataStream &operator>>(QDataStream&, Library&); | |
45 | ||
46 | using Libraries = QVector<Library>; | |
47 | Q_DECLARE_METATYPE(Libraries) | |
48 | ||
49 | class LibraryManager : public QAbstractTableModel | |
50 | { | |
51 | Q_OBJECT | |
52 | public: | |
53 | LibraryManager(QObject* parent = nullptr); | |
54 | LibraryManager(QSettings* settings, QObject* parent = nullptr); | |
55 | QVector<Library>::const_iterator begin() const; | |
56 | QVector<Library>::const_iterator end() const; | |
12 | 57 | QString findFile(QString fileName) const; |
7 | 58 | void addLibrary(const Library& library); |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
59 | void removeLibrary(const int libraryIndex); |
7 | 60 | const Library& library(int libraryIndex) const; |
61 | void setLibraryPath(int libraryIndex, const QDir& path); | |
62 | void setLibraryRole(int libraryIndex, const Library::Role role); | |
63 | void restoreFromSettings(QSettings* settings); | |
64 | void storeToSettings(QSettings* settings); | |
65 | int count() const; | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
66 | void moveLibrary(const int libraryFromIndex, const int libraryToIndex); |
7 | 67 | // Definitions for QAbstractTableModel |
68 | Qt::ItemFlags flags(const QModelIndex& index) const override; | |
69 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | |
70 | QVariant headerData( | |
71 | int section, | |
72 | Qt::Orientation orientation, | |
73 | int role = Qt::DisplayRole) const override; | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
74 | int rowCount(const QModelIndex&) const override; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
75 | int columnCount(const QModelIndex&) const override; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
76 | bool isValidIndex(const int libraryIndex) const; |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
77 | ldraw::ColorTable loadColorTable(QTextStream& errors); |
7 | 78 | private: |
79 | enum Column | |
80 | { | |
81 | RoleColumn, | |
82 | PathColumn | |
83 | }; | |
84 | void signalLibraryChange(int library); | |
85 | Libraries libraries; | |
86 | }; |