-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtreeitemmodel.h
More file actions
53 lines (43 loc) · 1.95 KB
/
Copy pathtreeitemmodel.h
File metadata and controls
53 lines (43 loc) · 1.95 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
#pragma once
#include <QAbstractItemModel>
#include <QModelIndex>
#include <QVariant>
#include <memory>
class TreeItem;
class TreeItemModel : public QAbstractItemModel {
Q_OBJECT
public:
static constexpr int kDataRole = Qt::UserRole;
static constexpr int kBoldRole = Qt::UserRole + 1;
static constexpr int kUrlRole = Qt::UserRole + 2;
explicit TreeItemModel(QObject* parent = nullptr);
~TreeItemModel() override;
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;
// Tell the compiler we don't mean to shadow insertRows.
bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex()) override;
bool setData(const QModelIndex &a_rIndex, const QVariant &a_rValue,
int a_iRole = Qt::EditRole) override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
void insertTreeItemRows(
std::vector<std::unique_ptr<TreeItem>>&&,
int position,
const QModelIndex& parent = QModelIndex());
TreeItem* setRootItem(std::unique_ptr<TreeItem> pRootItem);
TreeItem* getRootItem() const {
return m_pRootItem.get();
}
/// Returns the QModelIndex of the Root element.
const QModelIndex getRootIndex();
// Return the underlying TreeItem.
// If the index is invalid, the root item is returned.
TreeItem* getItem(const QModelIndex &index) const;
void triggerRepaint();
void triggerRepaint(const QModelIndex& index);
private:
std::unique_ptr<TreeItem> m_pRootItem;
};