digiKam
Loading...
Searching...
No Matches
simpletreemodel.h
Go to the documentation of this file.
1/* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2010-06-21
7 * Description : A simple model to hold a tree structure.
8 *
9 * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 * SPDX-FileCopyrightText: 2010-2014 by Michael G. Hansen <mike at mghansen dot de>
11 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 *
14 * ============================================================ */
15
16#pragma once
17
18// Qt includes
19
20#include <QAbstractItemModel>
21
22// Local includes
23
24#include "digikam_export.h"
25
26namespace Digikam
27{
28
29class DIGIKAM_EXPORT SimpleTreeModel : public QAbstractItemModel
30{
31 Q_OBJECT
32
33public:
34
35 class Item
36 {
37 public:
38
39 Item() = default;
40
42 {
43 qDeleteAll(children);
44 }
45
46 public:
47
48 QString data;
49
50 private:
51
52 QList<QMap<int, QVariant> > dataColumns;
53 Item* parent = nullptr;
54 QList<Item*> children;
55
56 private:
57
58 // Disable
59 Item(const Item&) = delete;
60 Item& operator=(const Item&) = delete;
61
62 friend class SimpleTreeModel;
63 };
64
65 explicit SimpleTreeModel(const int columnCount, QObject* const parent = nullptr);
66 ~SimpleTreeModel() override;
67
69 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
70 bool setData(const QModelIndex& index, const QVariant& value, int role) override;
71 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
72 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
73 QModelIndex parent(const QModelIndex& index) const override;
74 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
75 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, int role) override;
76 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
77 Qt::ItemFlags flags(const QModelIndex& index) const override;
78
79 Item* addItem(Item* const parentItem = nullptr, const int rowNumber = -1);
80 Item* indexToItem(const QModelIndex& itemIndex) const;
81 Item* rootItem() const;
82 QModelIndex itemToIndex(const Item* const item) const;
83
84
85private:
86
87 class Private;
88 Private* const d = nullptr;
89};
90
91} // namespace Digikam
Definition simpletreemodel.h:36
~Item()
Definition simpletreemodel.h:41
QString data
Definition simpletreemodel.h:48
Definition simpletreemodel.h:30
qulonglong value
Definition itemviewutilities.cpp:585
Definition datefolderview.cpp:34