src/librarycollection.h

changeset 1212
851ab72bb850
parent 1211
83b8ed708909
equal deleted inserted replaced
1211:83b8ed708909 1212:851ab72bb850
18 18
19 #pragma once 19 #pragma once
20 #include <QDir> 20 #include <QDir>
21 #include "main.h" 21 #include "main.h"
22 22
23 struct Library 23 /*
24 * Models an LDraw library.
25 */
26 class Library
24 { 27 {
28 public:
25 class SubdirectoryNotFoundError : public std::exception {}; 29 class SubdirectoryNotFoundError : public std::exception {};
26 30
27 enum FileType 31 enum FileType
28 { 32 {
29 Part, 33 Part,
31 Primitive, 35 Primitive,
32 HighResolutionPrimitive, 36 HighResolutionPrimitive,
33 LowResolutionPrimitive, 37 LowResolutionPrimitive,
34 }; 38 };
35 39
36 QDir path; 40 Library(const QDir& path, const QString& name, bool frozen);
37 QString name;
38 41
42 bool frozen() const;
43 QDir path() const;
44 QString name() const;
39 QDir subdirectory(FileType type) const; 45 QDir subdirectory(FileType type) const;
40 static QString subdirectoryName(FileType type); 46 static QString subdirectoryName(FileType type);
47
48 private:
49 QDir _path;
50 QString _name;
51 bool _frozen;
41 }; 52 };
42 53
43 /* 54 /*
44 * Models a collection of libraries. A library is a folder containing directories named "p" and 55 * Models a collection of libraries. A library is a folder containing directories named "p" and
45 * "parts" that contains part and subpart files. 56 * "parts" that contains part and subpart files.
46 */ 57 */
47 class LibraryCollection : public QObject, private QVector<Library> 58 class LibraryCollection : public QObject
48 { 59 {
49 Q_OBJECT 60 Q_OBJECT
50 using Super = QVector<Library>; 61 using Super = QVector<Library>;
51 62
52 public: 63 public:
54 { 65 {
55 QString name; 66 QString name;
56 Library::FileType type; 67 Library::FileType type;
57 }; 68 };
58 69
59 void addLibrary(QDir dir, QString name); 70 void addLibrary(QDir dir, QString name, bool frozen);
60 QString find(QString relativePath) const; 71 QString find(QString relativePath) const;
61 QString find(const QString& name, Library::FileType type) const; 72 QString find(const QString& name, Library::FileType type) const;
62 QString find(const FileSpec& spec) const; 73 QString find(const FileSpec& spec) const;
74 std::vector<Library>::iterator begin();
75 std::vector<Library>::iterator end();
63 76
64 static const QStringList directoryNames; 77 static const QStringList directoryNames;
78
79 private:
80 std::vector<Library> _libraries;
65 }; 81 };
82
83 #include <QAbstractTableModel>
84 class LibraryCollectionTableModel : public QAbstractTableModel
85 {
86 public:
87 LibraryCollectionTableModel(LibraryCollection& collection, QObject* parent = nullptr);
88
89 private:
90 LibraryCollection& _collection;
91 };

mercurial