QGIS API Documentation 3.99.0-Master (c22de0620c0)
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
19#include <deque>
20#include <memory>
21
22#include "qgis_gui.h"
23
24#include <QColor>
25#include <QElapsedTimer>
26#include <QUrl>
27#include <QVariant>
28
29#define SIP_NO_FILE
30
31class QAction;
33
40class GUI_EXPORT QgsDevToolsModelNode
41{
42 public:
44
50 QgsDevToolsModelGroup *parent() { return mParent; }
51
55 virtual QVariant data( int role = Qt::DisplayRole ) const = 0;
56
60 virtual int childCount() const = 0;
61
67 virtual QList<QAction *> actions( QObject *parent );
68
72 virtual QVariant toVariant() const;
73
74 protected:
76
77 private:
78 QgsDevToolsModelGroup *mParent = nullptr;
80};
81
89{
90 public:
92
96 QgsDevToolsModelGroup( QgsDevToolsModelGroup &&other ) noexcept = default;
97
102
103 public:
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:
136 QgsDevToolsModelGroup( const QString &title );
137
141 void addKeyValueNode( const QString &key, const QString &value, const QColor &color = QColor() );
142
143 protected:
144 std::deque<std::unique_ptr<QgsDevToolsModelNode>> mChildren;
145
146 private:
147 // Prevent copying
150
151 QString mGroupTitle;
152};
153
161{
162 public:
166 QgsDevToolsModelValueNode( const QString &key, const QString &value, const QColor &color = QColor() );
167
171 QString key() const { return mKey; }
172
176 QString value() const { return mValue; }
177
178 QVariant data( int role = Qt::DisplayRole ) const final;
179 int childCount() const final { return 0; }
180 QList<QAction *> actions( QObject *parent ) final;
181
182 private:
183 QString mKey;
184 QString mValue;
185 QColor mColor;
186};
187
188#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.