Sun, 26 Jun 2022 20:54:09 +0300
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
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> | |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
205
diff
changeset
|
22 | #include "basics.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
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
41 | bool operator==(const Library& one, const Library& other); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
42 | |
7 | 43 | Q_DECLARE_METATYPE(Library) |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
44 | Q_DECLARE_METATYPE(Library::Role) |
7 | 45 | QDataStream &operator<<(QDataStream&, const Library&); |
46 | QDataStream &operator>>(QDataStream&, Library&); | |
47 | ||
259
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
48 | using Libraries = QList<Library>; |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
49 | //QDataStream &operator<<(QDataStream&, const Libraries&); |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
50 | //QDataStream &operator>>(QDataStream&, Libraries&); |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
51 | //Q_DECLARE_METATYPE(Libraries) |
7 | 52 | |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
53 | class Configuration; |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
54 | |
230
a1f3f7d9078b
rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
55 | class LibrariesModel : public QAbstractTableModel |
7 | 56 | { |
57 | Q_OBJECT | |
58 | public: | |
230
a1f3f7d9078b
rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
59 | LibrariesModel(QObject* parent = nullptr); |
259
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
60 | auto begin() const { return this->libraries.begin(); } |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
61 | auto end() const { return this->libraries.end(); } |
12 | 62 | QString findFile(QString fileName) const; |
7 | 63 | void addLibrary(const Library& library); |
259
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
64 | void removeLibrary(const std::size_t libraryIndex); |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
65 | const Library& library(std::size_t libraryIndex) const; |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
66 | void setLibraryPath(std::size_t libraryIndex, const QDir& path); |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
67 | void setLibraryRole(std::size_t libraryIndex, const Library::Role role); |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
68 | void restoreFromSettings(); |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
69 | void storeToSettings(); |
259
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
70 | std::size_t count() const; |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
71 | void moveLibrary(const std::size_t libraryFromIndex, const std::size_t libraryToIndex); |
7 | 72 | // Definitions for QAbstractTableModel |
73 | Qt::ItemFlags flags(const QModelIndex& index) const override; | |
74 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | |
75 | QVariant headerData( | |
76 | int section, | |
77 | Qt::Orientation orientation, | |
78 | int role = Qt::DisplayRole) const override; | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
79 | int rowCount(const QModelIndex&) const override; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
80 | int columnCount(const QModelIndex&) const override; |
259
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
81 | bool isValidIndex(const std::size_t libraryIndex) const; |
205 | 82 | ColorTable loadColorTable(QTextStream& errors) const; |
7 | 83 | private: |
84 | enum Column | |
85 | { | |
86 | RoleColumn, | |
87 | PathColumn | |
88 | }; | |
259
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
89 | void signalLibraryChange(std::size_t library); |
7 | 90 | Libraries libraries; |
91 | }; |