Debian Codegraph @

include/Library/LibraryData.h

raw symbols SCIP
1 /*
2 * Copyright 2014 Mihai Niculescu <[email protected]>
3 *
4 * This file is part of EqualX Project (https://launchpad.net/equalx/)
5 *
6 * EqualX is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * EqualX is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef LIBRARYDATA_H
21 #define LIBRARYDATA_H
22
23 #include <QDebug>
24 #include <QDataStream>
25 #include <QMetaType>
26 #include <QVariant>
27
28 /** These data is intended to be used for fast viewing (and low memory consumption in models) **/
29
30 class LibraryModelData
31 {
32 public:
33 enum Type
34 {
35 TypeUndefined,
36 TypeFolder,
37 TypeHistory,
38 TypeBookmark
39 };
40
41
42 LibraryModelData();
43 LibraryModelData(const LibraryModelData& other);
44 virtual ~LibraryModelData();
45
46 bool isFolder() const;
47 bool isBookmark() const;
48 bool isHistory() const;
49 bool isValid() const; // is valid if the object is in database
50
51 operator QVariant() const
52 {
53 return QVariant::fromValue(*this);
54 }
55
56 int id;
57 int idparent;
58 QString name; // this field can be (depending on context) the title of a library folder or the absolute path to an equation file
59 LibraryModelData::Type type;
60 qint64 created;
61 };
62 Q_DECLARE_METATYPE(LibraryModelData)
63
64 typedef QList<LibraryModelData> LibraryRowsList;
65
66 inline QDataStream& operator<<(QDataStream& out, const LibraryModelData& object)
67 {
68 out << object.id;
69 out << object.idparent;
70 out << object.name;
71 out << (quint32)object.type;
72 out << object.created;
73
74 return out;
75 }
76
77 inline QDataStream& operator>>(QDataStream& in, LibraryModelData& object)
78 {
79 in >> object.id;
80 in >> object.idparent;
81 in >> object.name;
82 quint32 typeIntVal;
83
84 in >> typeIntVal;
85 object.type= (LibraryModelData::Type)typeIntVal;
86
87 in >> object.created;
88 return in;
89 }
90
91 QDebug operator<<(QDebug dbg, const LibraryModelData &data);
92
93 //_____________________________________________________________________________________________________
94 /**
95 ** The data types below are intended for complete editing/viewing of a specific library item
96 **
97 **/
98 class HistoryRow
99 {
100 public:
101 HistoryRow();
102 HistoryRow(const HistoryRow& other);
103 virtual ~HistoryRow();
104
105 LibraryModelData basicData() const;
106
107 int id;
108 QString title;
109 QString filePath;
110 qint64 created;
111 };
112 Q_DECLARE_METATYPE(HistoryRow)
113
114
115 class Bookmark
116 {
117 public:
118 Bookmark();
119 Bookmark(const Bookmark& other);
120 Bookmark(const LibraryModelData& data);
121 virtual ~Bookmark();
122
123 LibraryModelData basicData() const;
124
125 bool isValid() const;
126 QString fileExt() const;
127 void clear(); // set members to default values (invalidates the bookmark)
128
129 int id;
130 int idparent;
131 QString title;
132 QString description;
133 QString filePath;
134 QString dirPath;
135 qint64 created;
136 qint64 modified;
137 };
138 Q_DECLARE_METATYPE(Bookmark)
139
140 class BookmarkFolder
141 {
142 public:
143 BookmarkFolder();
144 BookmarkFolder(const BookmarkFolder& other);
145 BookmarkFolder(const LibraryModelData& data);
146 virtual ~BookmarkFolder();
147
148 LibraryModelData basicData() const;
149
150 bool isValid() const;
151
152 int id;
153 int idparent;
154 QString name;
155 QString description;
156 QString dirPath;
157 qint64 created;
158 qint64 modified;
159 };
160 Q_DECLARE_METATYPE(BookmarkFolder)
161
162
163 #endif // LIBRARYDATA_H