QGIS API Documentation 3.99.0-Master (752b475928d)
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:
108 QgsDevToolsModelNode *addChild( std::unique_ptr<QgsDevToolsModelNode> child );
109
115 int indexOf( QgsDevToolsModelNode *child ) const;
116
120 QgsDevToolsModelNode *childAt( int index );
121
125 void clear();
126
127 int childCount() const final { return mChildren.size(); }
128 QVariant data( int role = Qt::DisplayRole ) const override;
129 QVariant toVariant() const override;
130
131 protected:
135 QgsDevToolsModelGroup( const QString &title );
136
140 void addKeyValueNode( const QString &key, const QString &value, const QColor &color = QColor() );
141
142 protected:
143 std::deque<std::unique_ptr<QgsDevToolsModelNode>> mChildren;
144
145 private:
146 // Prevent copying
149
150 QString mGroupTitle;
151};
152
160{
161 public:
165 QgsDevToolsModelValueNode( const QString &key, const QString &value, const QColor &color = QColor() );
166
170 QString key() const { return mKey; }
171
175 QString value() const { return mValue; }
176
177 QVariant data( int role = Qt::DisplayRole ) const final;
178 int childCount() const final { return 0; }
179 QList<QAction *> actions( QObject *parent ) final;
180
181 private:
182 QString mKey;
183 QString mValue;
184 QColor mColor;
185};
186
187#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.