| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #ifndef PatternistSDK_TreeModel_H |
| 30 | #define PatternistSDK_TreeModel_H |
| 31 | |
| 32 | #include <QAbstractItemModel> |
| 33 | #include <QObject> |
| 34 | #include <QPointer> |
| 35 | #include <QStringList> |
| 36 | |
| 37 | #include "Global.h" |
| 38 | |
| 39 | QT_BEGIN_NAMESPACE |
| 40 | |
| 41 | namespace QPatternistSDK |
| 42 | { |
| 43 | class TreeItem; |
| 44 | |
| 45 | /** |
| 46 | * @short TreeItem is a generic QAbstractItemModel tailored for |
| 47 | * representing hierarchial data. |
| 48 | * |
| 49 | * TreeModel is an item model in Qt's model/view framework. Its |
| 50 | * data consists of TreeItem instances. |
| 51 | * |
| 52 | * @see TreeItem |
| 53 | * @ingroup PatternistSDK |
| 54 | * @author Frans Englich <frans.englich@nokia.com> |
| 55 | */ |
| 56 | class TreeModel : public QAbstractItemModel |
| 57 | { |
| 58 | Q_OBJECT |
| 59 | public: |
| 60 | TreeModel(const QStringList columnData, QObject *parent); |
| 61 | virtual ~TreeModel(); |
| 62 | |
| 63 | virtual QVariant data(const QModelIndex &index, int role) const; |
| 64 | virtual Qt::ItemFlags flags(const QModelIndex &index) const; |
| 65 | virtual QVariant (int section, |
| 66 | Qt::Orientation orientation, |
| 67 | int role = Qt::DisplayRole) const; |
| 68 | virtual QModelIndex index(int row, |
| 69 | int column, |
| 70 | const QModelIndex &parent = QModelIndex()) const; |
| 71 | virtual QModelIndex parent(const QModelIndex &index) const; |
| 72 | virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; |
| 73 | virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; |
| 74 | |
| 75 | TreeItem *root() const; |
| 76 | /** |
| 77 | * Sets @p root to the new root, and deletes the old. |
| 78 | */ |
| 79 | void setRoot(TreeItem *root); |
| 80 | |
| 81 | protected Q_SLOTS: |
| 82 | void childChanged(TreeItem *child); |
| 83 | |
| 84 | private: |
| 85 | QPointer<TreeItem> m_root; |
| 86 | const QStringList m_columnData; |
| 87 | }; |
| 88 | } |
| 89 | |
| 90 | QT_END_NAMESPACE |
| 91 | |
| 92 | #endif |
| 93 | // vim: et:ts=4:sw=4:sts=4 |
| 94 | |