digiKam
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  * Copyright (C) 2010-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2010-2014 by Michael G. Hansen <mike at mghansen dot de>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_SIMPLE_TREE_MODEL_H
26 #define DIGIKAM_SIMPLE_TREE_MODEL_H
27 
28 // Qt includes
29 
30 #include <QAbstractItemModel>
31 
32 // Local includes
33 
34 #include "digikam_export.h"
35 
36 namespace Digikam
37 {
38 
39 class DIGIKAM_EXPORT SimpleTreeModel : public QAbstractItemModel
40 {
41  Q_OBJECT
42 
43 public:
44 
45  class Item
46  {
47  public:
48 
49  explicit Item()
50  : dataColumns(),
51  parent (nullptr),
52  children ()
53  {
54  }
55 
57  {
58  qDeleteAll(children);
59  }
60 
61  public:
62 
63  QString data;
64 
65  private:
66 
67  QList<QMap<int, QVariant> > dataColumns;
68  Item* parent;
69  QList<Item*> children;
70 
71  friend class SimpleTreeModel;
72  };
73 
74  explicit SimpleTreeModel(const int columnCount, QObject* const parent = nullptr);
75  ~SimpleTreeModel() override;
76 
78  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
79  bool setData(const QModelIndex& index, const QVariant& value, int role) override;
80  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
81  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
82  QModelIndex parent(const QModelIndex& index) const override;
83  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
84  bool setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, int role) override;
85  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
86  Qt::ItemFlags flags(const QModelIndex& index) const override;
87 
88  Item* addItem(Item* const parentItem = nullptr, const int rowNumber = -1);
89  Item* indexToItem(const QModelIndex& itemIndex) const;
90  Item* rootItem() const;
91  QModelIndex itemToIndex(const Item* const item) const;
92 
93 private:
94 
95  class Private;
96  Private* const d;
97 };
98 
99 } // namespace Digikam
100 
101 #endif // DIGIKAM_SIMPLE_TREE_MODEL_H
Definition: simpletreemodel.h:46
Item()
Definition: simpletreemodel.h:49
~Item()
Definition: simpletreemodel.h:56
QString data
Definition: simpletreemodel.h:63
Definition: simpletreemodel.h:40
Definition: piwigotalker.h:48
qulonglong value
Definition: itemviewutilities.cpp:592
@ Orientation
Definition: coredbfields.h:86
Definition: datefolderview.cpp:43