Repository navigation
Expand file tree
/
Copy pathcmdtreemodel.h
More file actions
325 lines (283 loc) · 11.8 KB
/
Copy pathcmdtreemodel.h
File metadata and controls
325 lines (283 loc) · 11.8 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/**
* Copyright (C) 2021 Jo2003 (olenka.joerg@gmail.com)
* This file is part of cd2netmd_gui
*
* cd2netmd 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.
*
* cd2netmd 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
*/
#pragma once
#include <QObject>
#include <QAbstractItemModel>
#include <json.hpp>
class CTreeItem;
//------------------------------------------------------------------------------
//! @brief This class describes a md tree model.
//------------------------------------------------------------------------------
class CMDTreeModel : public QAbstractItemModel
{
Q_OBJECT
public:
/// iten role
enum class ItemRole : uint8_t
{
ROOT, ///< root item
DISC, ///< disc item
GROUP, ///< group item
TRACK ///< track item
};
/// disc config
struct SDiscConf
{
int mTocManip; ///< TOC manipulation support
int mSPUpload; ///< SP upload supported
int mOTFEnc; ///< On-The-Fly encoding support
int mPcm2Mono; ///< PCM2Mono support
int mTrkCount; ///< track count
int mTotTime; ///< total disc time
int mFreeTime; ///< free disc time
int mUsedTime; ///< used time
int mDiscFlags; ///< disc flags
QString mDevice; ///< device name
};
//--------------------------------------------------------------------------
//! @brief Constructs a new instance.
//!
//! @param[in] jsonContent The json content
//! @param parent The parent
//--------------------------------------------------------------------------
explicit CMDTreeModel(const QString& jsonContent, QObject *parent = nullptr);
//--------------------------------------------------------------------------
//! @brief Destroys the object.
//--------------------------------------------------------------------------
virtual ~CMDTreeModel();
//--------------------------------------------------------------------------
//! @brief get item data
//!
//! @param[in] index The index
//! @param[in] role The role
//!
//! @return item data
//--------------------------------------------------------------------------
QVariant data(const QModelIndex &index, int role) const override;
//--------------------------------------------------------------------------
//! @brief Sets the item data.
//!
//! @param[in] index The index
//! @param[in] value The value
//! @param[in] role The role
//!
//! @return true on success
//--------------------------------------------------------------------------
bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
//--------------------------------------------------------------------------
//! @brief item flags
//!
//! @param[in] index The index
//!
//! @return item flags
//--------------------------------------------------------------------------
Qt::ItemFlags flags(const QModelIndex &index) const override;
//--------------------------------------------------------------------------
//! @brief get header data
//!
//! @param[in] section The section
//! @param[in] orientation The orientation
//! @param[in] role The role
//!
//! @return header data
//--------------------------------------------------------------------------
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
//--------------------------------------------------------------------------
//! @brief get model index
//!
//! @param[in] row The row
//! @param[in] column The column
//! @param[in] parent The parent
//!
//! @return model index
//--------------------------------------------------------------------------
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const override;
//--------------------------------------------------------------------------
//! @brief get parents model index
//!
//! @param[in] index The index
//!
//! @return model index
//--------------------------------------------------------------------------
QModelIndex parent(const QModelIndex &index) const override;
//--------------------------------------------------------------------------
//! @brief get row count
//!
//! @param[in] parent The parent
//!
//! @return row count
//--------------------------------------------------------------------------
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
//--------------------------------------------------------------------------
//! @brief get column count
//!
//! @param[in] parent The parent
//!
//! @return column count
//--------------------------------------------------------------------------
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
//--------------------------------------------------------------------------
//! @brief export disc config
//!
//! @return pointer to disc config
//--------------------------------------------------------------------------
const SDiscConf *discConf() const;
//--------------------------------------------------------------------------
//! @brief Decreases the free time.
//!
//! @param[in] secs The seconds
//--------------------------------------------------------------------------
void decreaseFreeTime(time_t secs);
//--------------------------------------------------------------------------
//! @brief Increases the tracks.
//!
//! @param[in] tracks The tracks
//--------------------------------------------------------------------------
void increaseTracks(int tracks);
//--------------------------------------------------------------------------
//! @brief export json data
//!
//! @return json data
//--------------------------------------------------------------------------
nlohmann::json exportJson() const;
//--------------------------------------------------------------------------
//! @brief get track group
//!
//! @param[in] track The track
//!
//! @return group of track
//--------------------------------------------------------------------------
nlohmann::json& group(int track);
signals:
//--------------------------------------------------------------------------
//! @brief edit title
//!
//! @param[in] role The role
//! @param[in] title The title
//! @param[in] no number
//--------------------------------------------------------------------------
void editTitle(ItemRole role, QString title, int no);
protected:
//--------------------------------------------------------------------------
//! @brief initialize model from json data
//--------------------------------------------------------------------------
void setupModelData();
/// json data
nlohmann::json mMDJson;
/// root item
CTreeItem* mpTreeRoot;
/// root json data
nlohmann::json mRootData;
/// empty object
nlohmann::json mEmpty;
/// disc config
SDiscConf mDiscConf;
};
//------------------------------------------------------------------------------
//! @brief This class describes a tree item.
//------------------------------------------------------------------------------
class CTreeItem
{
public:
//--------------------------------------------------------------------------
//! @brief Constructs a new instance.
//!
//! @param[in] role The role
//! @param data The data
//! @param parentItem The parent item
//--------------------------------------------------------------------------
explicit CTreeItem(CMDTreeModel::ItemRole role, nlohmann::json& data, CTreeItem *parentItem = nullptr);
//--------------------------------------------------------------------------
//! @brief Destroys the object.
//--------------------------------------------------------------------------
~CTreeItem();
//--------------------------------------------------------------------------
//! @brief Appends a child.
//!
//! @param child The child
//--------------------------------------------------------------------------
void appendChild(CTreeItem *child);
//--------------------------------------------------------------------------
//! @brief get the child
//!
//! @param[in] row The row
//!
//! @return child pointer
//--------------------------------------------------------------------------
CTreeItem *child(int row);
//--------------------------------------------------------------------------
//! @brief get child count
//!
//! @return child count
//--------------------------------------------------------------------------
int childCount() const;
//--------------------------------------------------------------------------
//! @brief get column count
//!
//! @return column count
//--------------------------------------------------------------------------
int columnCount() const;
//--------------------------------------------------------------------------
//! @brief get item data
//!
//! @param[in] column The column
//!
//! @return item data
//--------------------------------------------------------------------------
QVariant data(int column) const;
//--------------------------------------------------------------------------
//! @brief get row number
//!
//! @return row number
//--------------------------------------------------------------------------
int row() const;
//--------------------------------------------------------------------------
//! @brief get parent item
//!
//! @return parent item
//--------------------------------------------------------------------------
CTreeItem *parentItem();
//--------------------------------------------------------------------------
//! @brief get item role
//!
//! @return item role
//--------------------------------------------------------------------------
CMDTreeModel::ItemRole itemRole() const;
//--------------------------------------------------------------------------
//! @brief get raw (json) data
//!
//! @return json data
//--------------------------------------------------------------------------
nlohmann::json &rawData();
//--------------------------------------------------------------------------
//! @brief get track number
//!
//! @return track number
//--------------------------------------------------------------------------
int trackNumber() const;
private:
/// child items
QVector<CTreeItem*> m_childItems;
/// json item data
nlohmann::json& mItemData;
/// parent item
CTreeItem *m_parentItem;
/// item role
CMDTreeModel::ItemRole mItRole;
};