Wed, 19 Apr 2023 22:51:56 +0300
Made library_role_e an enum class
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> | |
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
259
diff
changeset
|
22 | #include "src/basics.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
259
diff
changeset
|
23 | #include "src/colors.h" |
7 | 24 | |
25 | class QSettings; | |
26 | ||
381
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
27 | enum class library_role_e |
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
28 | { |
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
29 | official, |
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
30 | unofficial, |
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
31 | working, |
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
32 | }; |
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
33 | |
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
34 | constexpr static const library_role_e all_library_roles[] = |
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
35 | { |
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
36 | library_role_e::official, |
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
37 | library_role_e::unofficial, |
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
38 | library_role_e::working |
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
39 | }; |
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
40 | |
7 | 41 | struct Library |
42 | { | |
381
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
43 | library_role_e role; |
7 | 44 | QDir path; |
45 | }; | |
46 | ||
381
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
47 | QString library_role_name(const library_role_e role); |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
48 | bool operator==(const Library& one, const Library& other); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
49 | |
7 | 50 | Q_DECLARE_METATYPE(Library) |
381
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
51 | Q_DECLARE_METATYPE(library_role_e) |
7 | 52 | QDataStream &operator<<(QDataStream&, const Library&); |
53 | QDataStream &operator>>(QDataStream&, Library&); | |
265 | 54 | using Libraries = QVector<Library>; |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
55 | |
230
a1f3f7d9078b
rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
56 | class LibrariesModel : public QAbstractTableModel |
7 | 57 | { |
58 | Q_OBJECT | |
59 | public: | |
230
a1f3f7d9078b
rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
60 | LibrariesModel(QObject* parent = nullptr); |
259
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
61 | auto begin() const { return this->libraries.begin(); } |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
62 | auto end() const { return this->libraries.end(); } |
380
16f6717a218b
Use QFileInfo to represent paths
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
300
diff
changeset
|
63 | QFileInfo findFile(QString fileName) const; |
7 | 64 | void addLibrary(const Library& library); |
300
3a4b132b8353
Fix build warnings, size_type of QVector changes from Qt5 to Qt6 so we need an alias for it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
265
diff
changeset
|
65 | void removeLibrary(const index_t libraryIndex); |
3a4b132b8353
Fix build warnings, size_type of QVector changes from Qt5 to Qt6 so we need an alias for it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
265
diff
changeset
|
66 | const Library& library(index_t libraryIndex) const; |
3a4b132b8353
Fix build warnings, size_type of QVector changes from Qt5 to Qt6 so we need an alias for it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
265
diff
changeset
|
67 | void setLibraryPath(index_t libraryIndex, const QDir& path); |
381
80bea7a6e84f
Made library_role_e an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
380
diff
changeset
|
68 | void setLibraryRole(index_t libraryIndex, const library_role_e role); |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
69 | void restoreFromSettings(); |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
70 | void storeToSettings(); |
300
3a4b132b8353
Fix build warnings, size_type of QVector changes from Qt5 to Qt6 so we need an alias for it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
265
diff
changeset
|
71 | index_t count() const; |
3a4b132b8353
Fix build warnings, size_type of QVector changes from Qt5 to Qt6 so we need an alias for it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
265
diff
changeset
|
72 | void moveLibrary(const index_t libraryFromIndex, const index_t libraryToIndex); |
7 | 73 | // Definitions for QAbstractTableModel |
74 | Qt::ItemFlags flags(const QModelIndex& index) const override; | |
75 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | |
76 | QVariant headerData( | |
77 | int section, | |
78 | Qt::Orientation orientation, | |
79 | int role = Qt::DisplayRole) const override; | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
80 | int rowCount(const QModelIndex&) const override; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
81 | int columnCount(const QModelIndex&) const override; |
300
3a4b132b8353
Fix build warnings, size_type of QVector changes from Qt5 to Qt6 so we need an alias for it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
265
diff
changeset
|
82 | bool isValidIndex(const index_t libraryIndex) const; |
205 | 83 | ColorTable loadColorTable(QTextStream& errors) const; |
7 | 84 | private: |
85 | enum Column | |
86 | { | |
87 | RoleColumn, | |
88 | PathColumn | |
89 | }; | |
300
3a4b132b8353
Fix build warnings, size_type of QVector changes from Qt5 to Qt6 so we need an alias for it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
265
diff
changeset
|
90 | void signalLibraryChange(const index_t library); |
7 | 91 | Libraries libraries; |
92 | }; |