QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgsdevtoolsmodelnode.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsdevtoolsmodelnode.h
3 -------------------------
4 begin : March 2020
5 copyright : (C) 2020 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSDEVTOOLSMODELNODE_H
16#define QGSDEVTOOLSMODELNODE_H
17
18#define SIP_NO_FILE
19
20#include <deque>
21#include <memory>
22
23#include "qgis_gui.h"
24
25#include <QColor>
26#include <QElapsedTimer>
27#include <QUrl>
28#include <QVariant>
29
30class QAction;
32
39class GUI_EXPORT QgsDevToolsModelNode
40{
41 public:
43
49 QgsDevToolsModelGroup *parent() { return mParent; }
50
54 virtual QVariant data( int role = Qt::DisplayRole ) const = 0;
55
59 virtual int childCount() const = 0;
60
66 virtual QList<QAction *> actions( QObject *parent );
67
71 virtual QVariant toVariant() const;
72
73 protected:
75
76 private:
77 QgsDevToolsModelGroup *mParent = nullptr;
79};
80
88{
89 public:
91
95 QgsDevToolsModelGroup( QgsDevToolsModelGroup &&other ) noexcept = default;
96
101
102 public:
103
109 QgsDevToolsModelNode *addChild( std::unique_ptr<QgsDevToolsModelNode> child );
110
116 int indexOf( QgsDevToolsModelNode *child ) const;
117
121 QgsDevToolsModelNode *childAt( int index );
122
126 void clear();
127
128 int childCount() const final { return mChildren.size(); }
129 QVariant data( int role = Qt::DisplayRole ) const override;
130 QVariant toVariant() const override;
131
132 protected:
133
137 QgsDevToolsModelGroup( const QString &title );
138
142 void addKeyValueNode( const QString &key, const QString &value, const QColor &color = QColor() );
143
144 protected:
145 std::deque<std::unique_ptr<QgsDevToolsModelNode>> mChildren;
146
147 private:
148 // Prevent copying
151
152 QString mGroupTitle;
153};
154
162{
163 public:
164
168 QgsDevToolsModelValueNode( const QString &key, const QString &value, const QColor &color = QColor() );
169
173 QString key() const { return mKey; }
174
178 QString value() const { return mValue; }
179
180 QVariant data( int role = Qt::DisplayRole ) const final;
181 int childCount() const final { return 0; }
182 QList<QAction *> actions( QObject *parent ) final;
183
184 private:
185 QString mKey;
186 QString mValue;
187 QColor mColor;
188};
189
190#endif // QGSDEVTOOLSMODELNODE_H
Base class for dev tools model "group" nodes, which contain children of their own.
int childCount() const final
Returns the number of child nodes owned by this node.
QgsDevToolsModelNode * addChild(std::unique_ptr< QgsDevToolsModelNode > child)
Adds a child node to this node.
~QgsDevToolsModelGroup() override
QgsDevToolsModelGroup(QgsDevToolsModelGroup &&other) noexcept=default
Constructor for a QgsDevToolsModelGroup.
void clear()
Clears the group, removing all its children.
std::deque< std::unique_ptr< QgsDevToolsModelNode > > mChildren
QgsDevToolsModelNode * childAt(int index)
Returns the child at the specified index.
QgsDevToolsModelGroup & operator=(QgsDevToolsModelGroup &&other) noexcept=default
Assignment operator for QgsDevToolsModelGroup.
int indexOf(QgsDevToolsModelNode *child) const
Returns the index of the specified child node.
virtual QList< QAction * > actions(QObject *parent)
Returns a list of actions relating to the node.
virtual ~QgsDevToolsModelNode()
virtual QVariant toVariant() const
Converts the node's contents to a variant.
QgsDevToolsModelGroup * parent()
Returns the node's parent node.
virtual int childCount() const =0
Returns the number of child nodes owned by this node.
virtual QVariant data(int role=Qt::DisplayRole) const =0
Returns the node's data for the specified model role.
QgsDevToolsModelValueNode(const QString &key, const QString &value, const QColor &color=QColor())
Constructor for QgsDevToolsModelValueNode, with the specified key (usually translated) and value.
int childCount() const final
Returns the number of child nodes owned by this node.
QString key() const
Returns the node's key.
QString value() const
Returns the node's value.