Thu, 29 Mar 2018 12:09:05 +0300
Branch close
1210
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
1 | /* |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
3 | * Copyright (C) 2013 - 2017 Teemu Piippo |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
4 | * |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
8 | * (at your option) any later version. |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
9 | * |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
13 | * GNU General Public License for more details. |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
14 | * |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
17 | */ |
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
18 | |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | #pragma once |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | #include <QDir> |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
21 | #include "main.h" |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | |
1212
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
23 | /* |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
24 | * Models an LDraw library. |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
25 | */ |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
26 | class Library |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
27 | { |
1212
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
28 | public: |
1211
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
29 | class SubdirectoryNotFoundError : public std::exception {}; |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
30 | |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | enum FileType |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | { |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | Part, |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | Subpart, |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | Primitive, |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | HighResolutionPrimitive, |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | LowResolutionPrimitive, |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | }; |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | |
1212
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
40 | Library(const QDir& path, const QString& name, bool frozen); |
1211
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
41 | |
1212
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
42 | bool frozen() const; |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
43 | QDir path() const; |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
44 | QString name() const; |
1211
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
45 | QDir subdirectory(FileType type) const; |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
46 | static QString subdirectoryName(FileType type); |
1212
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
47 | |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
48 | private: |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
49 | QDir _path; |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
50 | QString _name; |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
51 | bool _frozen; |
1211
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
52 | }; |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
53 | |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
54 | /* |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
55 | * Models a collection of libraries. A library is a folder containing directories named "p" and |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
56 | * "parts" that contains part and subpart files. |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
57 | */ |
1212
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
58 | class LibraryCollection : public QObject |
1211
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
59 | { |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
60 | Q_OBJECT |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
61 | using Super = QVector<Library>; |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
62 | |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
63 | public: |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | struct FileSpec |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | { |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | QString name; |
1211
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
67 | Library::FileType type; |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | }; |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
69 | |
1212
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
70 | void addLibrary(QDir dir, QString name, bool frozen); |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
71 | QString find(QString relativePath) const; |
1211
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
72 | QString find(const QString& name, Library::FileType type) const; |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | QString find(const FileSpec& spec) const; |
1212
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
74 | std::vector<Library>::iterator begin(); |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
75 | std::vector<Library>::iterator end(); |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | static const QStringList directoryNames; |
1212
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
78 | |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
79 | private: |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
80 | std::vector<Library> _libraries; |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
81 | }; |
1212
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
82 | |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
83 | #include <QAbstractTableModel> |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
84 | class LibraryCollectionTableModel : public QAbstractTableModel |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
85 | { |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
86 | public: |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
87 | LibraryCollectionTableModel(LibraryCollection& collection, QObject* parent = nullptr); |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
88 | |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
89 | private: |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
90 | LibraryCollection& _collection; |
851ab72bb850
Worked more on the library collection thing
Teemu Piippo <teemu@hecknology.net>
parents:
1211
diff
changeset
|
91 | }; |