-
Notifications
You must be signed in to change notification settings - Fork 1
/
MultiChannelTreeModel.h
82 lines (67 loc) · 2.63 KB
/
MultiChannelTreeModel.h
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
//
// MultiChannelTreeModel.h: Tree model of the multichannel forwarder
// Copyright (C) 2023 Gonzalo José Carracedo Carballal
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>
//
#ifndef MULTICHANNELTREEMODEL_H
#define MULTICHANNELTREEMODEL_H
#include <QAbstractItemModel>
#include <MultiChannelForwarder.h>
#include <QHash>
class QTreeView;
enum MultiChannelTreeItemType
{
MULTI_CHANNEL_TREE_ITEM_ROOT,
MULTI_CHANNEL_TREE_ITEM_MASTER,
MULTI_CHANNEL_TREE_ITEM_CHANNEL
};
struct MultiChannelTreeItem
{
MultiChannelTreeItemType type;
union {
MasterChannel *master;
ChannelDescription *channel;
};
MultiChannelTreeItem *parent = nullptr;
int index = -1;
QVector<MultiChannelTreeItem *> children;
};
class MultiChannelTreeModel : public QAbstractItemModel
{
Q_OBJECT
MultiChannelForwarder *m_forwarder = nullptr;
QHash<int, MultiChannelTreeItem> m_treeStructure;
QHash<QString, MultiChannelTreeItem *> m_masterHash;
MultiChannelTreeItem *m_rootItem;
public:
static MultiChannelTreeItem *indexData(const QModelIndex &);
void fastExpand(QTreeView *);
void rebuildStructure();
MultiChannelTreeItem *allocItem(MultiChannelTreeItemType type);
explicit MultiChannelTreeModel(MultiChannelForwarder *, QObject *parent = nullptr);
~MultiChannelTreeModel();
bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
QVariant data(const QModelIndex &index, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &index) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
};
#endif // MULTICHANNELTREEMODEL_H