Mon, 27 Mar 2017 14:56:05 +0300
LibraryCollection now derives from QObject and QVector<Library>
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 | |
1211
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
23 | struct Library |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
24 | { |
1211
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
25 | class SubdirectoryNotFoundError : public std::exception {}; |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
26 | |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
27 | enum FileType |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | { |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | Part, |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
30 | Subpart, |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | Primitive, |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | HighResolutionPrimitive, |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | LowResolutionPrimitive, |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | }; |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | |
1211
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
36 | QDir path; |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
37 | QString name; |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
38 | |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
39 | QDir subdirectory(FileType type) const; |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
40 | static QString subdirectoryName(FileType type); |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
41 | }; |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
42 | |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
43 | /* |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
44 | * 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
|
45 | * "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
|
46 | */ |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
47 | class LibraryCollection : public QObject, private QVector<Library> |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
48 | { |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
49 | Q_OBJECT |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
50 | using Super = QVector<Library>; |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
51 | |
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
52 | public: |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | struct FileSpec |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | { |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | QString name; |
1211
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
56 | Library::FileType type; |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | }; |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | |
1210
0b3b35f560f2
More work on library collections
Teemu Piippo <teemu@hecknology.net>
parents:
1209
diff
changeset
|
59 | void addLibrary(QDir dir, QString name); |
1209
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | QString find(QString relativePath) const; |
1211
83b8ed708909
LibraryCollection now derives from QObject and QVector<Library>
Teemu Piippo <teemu@hecknology.net>
parents:
1210
diff
changeset
|
61 | 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
|
62 | QString find(const FileSpec& spec) const; |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | static const QStringList directoryNames; |
c2723022b173
Laid groundwork for library collection support.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | }; |