File: LibraryData.h

package info (click to toggle)
equalx 0.7.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,268 kB
  • sloc: cpp: 7,119; ansic: 98; sql: 10; makefile: 6
file content (163 lines) | stat: -rw-r--r-- 3,835 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * Copyright 2014 Mihai Niculescu <q.quark@gmail.com>
 *
 * This file is part of EqualX Project (https://launchpad.net/equalx/)
 *
 * EqualX is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * EqualX is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef LIBRARYDATA_H
#define LIBRARYDATA_H

#include <QDebug>
#include <QDataStream>
#include <QMetaType>
#include <QVariant>

/** These data is intended to be used for fast viewing (and low memory consumption in models) **/

class LibraryModelData
{
public:
    enum Type
    {
        TypeUndefined,
        TypeFolder,
        TypeHistory,
        TypeBookmark
    };


    LibraryModelData();
    LibraryModelData(const LibraryModelData& other);
    virtual ~LibraryModelData();

    bool isFolder() const;
    bool isBookmark() const;
    bool isHistory() const;
    bool isValid() const; // is valid if the object is in database

    operator QVariant() const
    {
        return QVariant::fromValue(*this);
    }

    int id;
    int idparent;
    QString name; // this field can be (depending on context) the title of a library folder or the absolute path to an equation file
    LibraryModelData::Type type;
    qint64 created;
};
Q_DECLARE_METATYPE(LibraryModelData)

typedef QList<LibraryModelData> LibraryRowsList;

inline QDataStream& operator<<(QDataStream& out, const LibraryModelData& object)
{
    out << object.id;
    out << object.idparent;
    out << object.name;
    out << (quint32)object.type;
    out << object.created;

    return out;
}

inline QDataStream& operator>>(QDataStream& in, LibraryModelData& object)
{
    in >> object.id;
    in >> object.idparent;
    in >> object.name;
    quint32 typeIntVal;

    in >> typeIntVal;
    object.type= (LibraryModelData::Type)typeIntVal;

    in >> object.created;
    return in;
}

QDebug operator<<(QDebug dbg, const LibraryModelData &data);

//_____________________________________________________________________________________________________
/**
 **  The data types below are intended for complete editing/viewing of a specific library item
 **
 **/
class HistoryRow
{
public:
    HistoryRow();
    HistoryRow(const HistoryRow& other);
    virtual ~HistoryRow();

    LibraryModelData basicData() const;

    int id;
    QString title;
    QString filePath;
    qint64 created;
};
Q_DECLARE_METATYPE(HistoryRow)


class Bookmark
{
public:
    Bookmark();
    Bookmark(const Bookmark& other);
    Bookmark(const LibraryModelData& data);
    virtual ~Bookmark();

    LibraryModelData basicData() const;

    bool isValid() const;
    QString fileExt() const;
    void clear(); // set members to default values (invalidates the bookmark)

    int id;
    int idparent;
    QString title;
    QString description;
    QString filePath;
    QString dirPath;
    qint64 created;
    qint64 modified;
};
Q_DECLARE_METATYPE(Bookmark)

class BookmarkFolder
{
public:
    BookmarkFolder();
    BookmarkFolder(const BookmarkFolder& other);
    BookmarkFolder(const LibraryModelData& data);
    virtual ~BookmarkFolder();

    LibraryModelData basicData() const;

    bool isValid() const;

    int id;
    int idparent;
    QString name;
    QString description;
    QString dirPath;
    qint64 created;
    qint64 modified;
};
Q_DECLARE_METATYPE(BookmarkFolder)


#endif // LIBRARYDATA_H