QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
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
43class CORE_EXPORT QgsSettingsTreeNode
44{
45
46#ifdef SIP_RUN
48 if ( dynamic_cast< QgsSettingsTreeNamedListNode * >( sipCpp ) )
49 sipType = sipType_QgsSettingsTreeNamedListNode;
50 else if ( dynamic_cast< QgsSettingsTreeNode * >( sipCpp ) )
51 sipType = sipType_QgsSettingsTreeNode;
52 else
53 sipType = NULL;
55#endif
56
57 Q_GADGET
58
59 public:
60
61 virtual ~QgsSettingsTreeNode();
62
67 static QgsSettingsTreeNode *createRootNode() SIP_SKIP;
68
74 QgsSettingsTreeNode *createChildNode( const QString &key ) SIP_THROW( QgsSettingsException ) SIP_KEEPREFERENCE;
75
81
82
84 Qgis::SettingsTreeNodeType type() const {return mType;}
85
94 void registerChildSetting( const QgsSettingsEntryBase *setting, const QString &key ) SIP_THROW( QgsSettingsException );
95
102 void unregisterChildSetting( const QgsSettingsEntryBase *setting, bool deleteSettingValues = false, const QStringList &parentsNamedItems = QStringList() );
103
105 void unregisterChildNode( QgsSettingsTreeNode *node );
106
108 QList<QgsSettingsTreeNode *> childrenNodes() const {return mChildrenNodes;}
109
111 QgsSettingsTreeNode *childNode( const QString &key ) const;
112
114 QList<const QgsSettingsEntryBase *> childrenSettings() const {return mChildrenSettings;}
115
117 const QgsSettingsEntryBase *childSetting( const QString &key ) const;
118
120 QgsSettingsTreeNode *parent() const {return mParent;}
121
123 QString key() const {return mKey;}
124
126 QString completeKey() const {return mCompleteKey;}
127
129 int namedNodesCount() const {return mNamedNodesCount;}
130
131#ifdef SIP_RUN
132 SIP_PYOBJECT __repr__();
133 % MethodCode
134 const QMetaEnum metaEnum = QMetaEnum::fromType<Qgis::SettingsTreeNodeType>();
135
136 QString str = QStringLiteral( "<QgsSettingsTreeNode (%1): %2>" ).arg( metaEnum.valueToKey( static_cast<int>( sipCpp->type() ) ), sipCpp->key() );
137 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
138 % End
139#endif
140
141 protected:
143 void registerChildNode( QgsSettingsTreeNode *node );
144
146
147 private:
148
153 QgsSettingsTreeNode() = default SIP_FORCE;
154
155 QgsSettingsTreeNode( const QgsSettingsTreeNode &other ) = default SIP_FORCE;
156
158 void init( QgsSettingsTreeNode *parent, const QString &key );
159
160 friend class QgsSettingsTree;
162
163 QgsSettingsTreeNode *childNodeAtKey( const QString &key );
164
165 QList<QgsSettingsTreeNode *> mChildrenNodes;
166 QList<const QgsSettingsEntryBase *> mChildrenSettings;
167 QgsSettingsTreeNode *mParent = nullptr;
168
169 QString mKey;
170 QString mCompleteKey;
171 int mNamedNodesCount = 0;
172};
173
174
175
190{
191 public:
193
199 QStringList items( const QStringList &parentsNamedItems = QStringList() ) const SIP_THROW( QgsSettingsException );
200
207 QStringList items( Qgis::SettingsOrigin origin, const QStringList &parentsNamedItems = QStringList() ) const SIP_THROW( QgsSettingsException );
208
209
216 void setSelectedItem( const QString &item, const QStringList &parentsNamedItems = QStringList() ) SIP_THROW( QgsSettingsException );
217
223 QString selectedItem( const QStringList &parentsNamedItems = QStringList() ) SIP_THROW( QgsSettingsException );
224
231 void deleteItem( const QString &item, const QStringList &parentsNamedItems = QStringList() ) SIP_THROW( QgsSettingsException );
232
239 void deleteAllItems( const QStringList &parentsNamedItems = QStringList() ) SIP_THROW( QgsSettingsException );
240
242 const QgsSettingsEntryString *selectedItemSetting() const {return mSelectedItemSetting;}
243
244 protected:
246 void initNamedList( const Qgis::SettingsTreeNodeOptions &options );
247
248 private:
250
256
258
260 QString completeKeyWithNamedItems( const QString &key, const QStringList &namedItems ) const;
261
263 const QgsSettingsEntryString *mSelectedItemSetting = nullptr;
264 QString mItemsCompleteKey;
265};
266
267#endif // QGSSETTINGSTREENODE_H
SettingsTreeNodeType
Type of tree node.
Definition qgis.h:464
QFlags< SettingsTreeNodeOption > SettingsTreeNodeOptions
Definition qgis.h:481
SettingsOrigin
The setting origin describes where a setting is stored.
Definition qgis.h:3871
Represent settings entry and provides methods for reading and writing settings values.
A string settings entry.
Custom exception class for settings related exceptions.
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)
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:38
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#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:203
#define SIP_END
Definition qgis_sip.h:208