QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgssettingstreenode.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssettingstreenode.h
3 --------------------------------------
4 Date : December 2022
5 Copyright : (C) 2022 by Denis Rouzaud
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
16#ifndef QGSSETTINGSTREENODE_H
17#define QGSSETTINGSTREENODE_H
18
19#include <QObject>
20
21#include "qgis.h"
22#include "qgis_core.h"
23#include "qgis_sip.h"
24
28
29
44class CORE_EXPORT QgsSettingsTreeNode
45{
46
47#ifdef SIP_RUN
49 if ( dynamic_cast< QgsSettingsTreeNamedListNode * >( sipCpp ) )
50 sipType = sipType_QgsSettingsTreeNamedListNode;
51 else if ( dynamic_cast< QgsSettingsTreeNode * >( sipCpp ) )
52 sipType = sipType_QgsSettingsTreeNode;
53 else
54 sipType = NULL;
56#endif
57
58 Q_GADGET
59
60 public:
61
62 virtual ~QgsSettingsTreeNode();
63
68 static QgsSettingsTreeNode *createRootNode() SIP_SKIP;
69
75 QgsSettingsTreeNode *createChildNode( const QString &key ) SIP_THROW( QgsSettingsException ) SIP_KEEPREFERENCE;
76
81 QgsSettingsTreeNamedListNode *createNamedListNode( const QString &key, const Qgis::SettingsTreeNodeOptions &options = Qgis::SettingsTreeNodeOptions() ) SIP_THROW( QgsSettingsException ) SIP_KEEPREFERENCE;
82
83
85 Qgis::SettingsTreeNodeType type() const {return mType;}
86
95 void registerChildSetting( const QgsSettingsEntryBase *setting, const QString &key ) SIP_THROW( QgsSettingsException );
96
103 void unregisterChildSetting( const QgsSettingsEntryBase *setting, bool deleteSettingValues = false, const QStringList &parentsNamedItems = QStringList() );
104
106 void unregisterChildNode( QgsSettingsTreeNode *node );
107
109 QList<QgsSettingsTreeNode *> childrenNodes() const {return mChildrenNodes;}
110
112 QgsSettingsTreeNode *childNode( const QString &key );
113
115 QList<const QgsSettingsEntryBase *> childrenSettings() const {return mChildrenSettings;}
116
118 const QgsSettingsEntryBase *childSetting( const QString &key );
119
121 QgsSettingsTreeNode *parent() const {return mParent;}
122
124 QString key() const {return mKey;}
125
127 QString completeKey() const {return mCompleteKey;}
128
130 int namedNodesCount() const {return mNamedNodesCount;}
131
132#ifdef SIP_RUN
133 SIP_PYOBJECT __repr__();
134 % MethodCode
135 const QMetaEnum metaEnum = QMetaEnum::fromType<Qgis::SettingsTreeNodeType>();
136
137 QString str = QStringLiteral( "<QgsSettingsTreeNode (%1): %2>" ).arg( metaEnum.valueToKey( static_cast<int>( sipCpp->type() ) ), sipCpp->key() );
138 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
139 % End
140#endif
141
142 protected:
144 void registerChildNode( QgsSettingsTreeNode *node );
145
147
148
149 private:
150
155 QgsSettingsTreeNode() = default SIP_FORCE;
156
157 QgsSettingsTreeNode( const QgsSettingsTreeNode &other ) = default SIP_FORCE;
158
160 void init( QgsSettingsTreeNode *parent, const QString &key );
161
162 friend class QgsSettingsTree;
164
165 QgsSettingsTreeNode *childNodeAtKey( const QString &key );
166
167 QList<QgsSettingsTreeNode *> mChildrenNodes;
168 QList<const QgsSettingsEntryBase *> mChildrenSettings;
169 QgsSettingsTreeNode *mParent = nullptr;
170
171 QString mKey;
172 QString mCompleteKey;
173 int mNamedNodesCount = 0;
174};
175
176
177
192{
193 public:
195
201 QStringList items( const QStringList &parentsNamedItems = QStringList() ) const SIP_THROW( QgsSettingsException );
202
209 QStringList items( Qgis::SettingsOrigin origin, const QStringList &parentsNamedItems = QStringList() ) const SIP_THROW( QgsSettingsException );
210
211
218 void setSelectedItem( const QString &item, const QStringList &parentsNamedItems = QStringList() ) SIP_THROW( QgsSettingsException );
219
225 QString selectedItem( const QStringList &parentsNamedItems = QStringList() ) SIP_THROW( QgsSettingsException );
226
233 void deleteItem( const QString &item, const QStringList &parentsNamedItems = QStringList() ) SIP_THROW( QgsSettingsException );
234
236 const QgsSettingsEntryString *selectedItemSetting() const {return mSelectedItemSetting;}
237
238 protected:
240 void initNamedList( const Qgis::SettingsTreeNodeOptions &options );
241
242 private:
244
250
252
254 QString completeKeyWithNamedItems( const QString &key, const QStringList &namedItems ) const;
255
256 Qgis::SettingsTreeNodeOptions mOptions;
257 const QgsSettingsEntryString *mSelectedItemSetting = nullptr;
258 QString mItemsCompleteKey;
259};
260
261#endif // QGSSETTINGSTREENODE_H
SettingsTreeNodeType
Type of tree node.
Definition: qgis.h:364
SettingsOrigin
The setting origin describes where a setting is stored.
Definition: qgis.h:2702
Represent settings entry and provides methods for reading and writing settings values.
A string settings entry.
Custom exception class for settings related exceptions.
Definition: qgsexception.h:134
QgsSettingsTreeNamedListNode is a named list tree node for the settings tree to help organizing and i...
const QgsSettingsEntryString * selectedItemSetting() const
Returns the setting used to store the selected item.
QgsSettingsTreeNode is a tree node for the settings tree to help organizing and introspecting the tre...
QList< const QgsSettingsEntryBase * > childrenSettings() const
Returns the children settings.
QList< QgsSettingsTreeNode * > childrenNodes() const
Returns the children nodes.
Qgis::SettingsTreeNodeType type() const
Returns the type of node.
QString completeKey() const
Returns the complete key of the node (including its parents)
int namedNodesCount() const
Returns the number of named nodes in the complete key.
QString key() const
Returns the key of the node (without its parents)
friend class QgsSettingsTreeNamedListNode
QgsSettingsTreeNode * parent() const
Returns the parent of the node or nullptr if it does not exists.
QgsSettingsTree holds the tree structure for the settings in QGIS core.
#define str(x)
Definition: qgis.cpp:37
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
#define SIP_KEEPREFERENCE
Definition: qgis_sip.h:86
#define SIP_FORCE
Definition: qgis_sip.h:131
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_THROW(name,...)
Definition: qgis_sip.h:198
#define SIP_END
Definition: qgis_sip.h:203