QGIS API Documentation 4.1.0-Master (60fea48833c)
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 "qgis.h"
20#include "qgis_core.h"
21#include "qgis_sip.h"
22
23#include <QObject>
24#include <QString>
25
26using namespace Qt::StringLiterals;
27
31
47class CORE_EXPORT QgsSettingsTreeNode
48{
49#ifdef SIP_RUN
51 if ( dynamic_cast< QgsSettingsTreeNamedListNode * >( sipCpp ) )
52 sipType = sipType_QgsSettingsTreeNamedListNode;
53 else if ( dynamic_cast< QgsSettingsTreeNode * >( sipCpp ) )
54 sipType = sipType_QgsSettingsTreeNode;
55 else
56 sipType = NULL;
58#endif
59
60 // clang-format off
61 Q_GADGET
62
63 public:
64 // clang-format on
65
66 virtual ~QgsSettingsTreeNode();
67
72 static QgsSettingsTreeNode *createRootNode() SIP_SKIP;
73
79 QgsSettingsTreeNode *createChildNode( const QString &key ) SIP_THROW( QgsSettingsException ) SIP_KEEPREFERENCE;
80
87
88
91
100 void registerChildSetting( const QgsSettingsEntryBase *setting, const QString &key ) SIP_THROW( QgsSettingsException );
101
108 void unregisterChildSetting( const QgsSettingsEntryBase *setting, bool deleteSettingValues = false, const QStringList &parentsNamedItems = QStringList() );
109
111 void unregisterChildNode( QgsSettingsTreeNode *node );
112
114 QList<QgsSettingsTreeNode *> childrenNodes() const { return mChildrenNodes; }
115
117 QgsSettingsTreeNode *childNode( const QString &key ) const;
118
120 QList<const QgsSettingsEntryBase *> childrenSettings() const { return mChildrenSettings; }
121
123 const QgsSettingsEntryBase *childSetting( const QString &key ) const;
124
126 QgsSettingsTreeNode *parent() const { return mParent; }
127
129 QString key() const { return mKey; }
130
132 QString completeKey() const { return mCompleteKey; }
133
135 int namedNodesCount() const { return mNamedNodesCount; }
136
137#ifdef SIP_RUN
138 // clang-format off
139 SIP_PYOBJECT __repr__();
140 % MethodCode
141 const QMetaEnum metaEnum = QMetaEnum::fromType<Qgis::SettingsTreeNodeType>();
142
143 QString str = u"<QgsSettingsTreeNode (%1): %2>"_s.arg( metaEnum.valueToKey( static_cast<int>( sipCpp->type() ) ), sipCpp->key() );
144 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
145 % End
146// clang-format on
147#endif
148
149 // clang-format off
150 protected:
151 // clang-format on
153 void registerChildNode( QgsSettingsTreeNode *node );
154
156
157 private:
164 QgsSettingsTreeNode() = default SIP_FORCE;
165
166 QgsSettingsTreeNode( const QgsSettingsTreeNode &other ) = default SIP_FORCE;
167
169 void init( QgsSettingsTreeNode *parent, const QString &key );
170
171 friend class QgsSettingsTree;
173
174 QgsSettingsTreeNode *childNodeAtKey( const QString &key );
175
176 QList<QgsSettingsTreeNode *> mChildrenNodes;
177 QList<const QgsSettingsEntryBase *> mChildrenSettings;
178 QgsSettingsTreeNode *mParent = nullptr;
179
180 QString mKey;
181 QString mCompleteKey;
182 int mNamedNodesCount = 0;
183};
184
185
200class CORE_EXPORT QgsSettingsTreeNamedListNode : public QgsSettingsTreeNode
201{
202 public:
203 ~QgsSettingsTreeNamedListNode() override;
204
210 QStringList items( const QStringList &parentsNamedItems = QStringList() ) const SIP_THROW( QgsSettingsException );
211
218 QStringList items( Qgis::SettingsOrigin origin, const QStringList &parentsNamedItems = QStringList() ) const SIP_THROW( QgsSettingsException );
219
220
227 void setSelectedItem( const QString &item, const QStringList &parentsNamedItems = QStringList() ) SIP_THROW( QgsSettingsException );
228
234 QString selectedItem( const QStringList &parentsNamedItems = QStringList() ) SIP_THROW( QgsSettingsException );
235
242 void deleteItem( const QString &item, const QStringList &parentsNamedItems = QStringList() ) SIP_THROW( QgsSettingsException );
243
250 void deleteAllItems( const QStringList &parentsNamedItems = QStringList() ) SIP_THROW( QgsSettingsException );
251
253 const QgsSettingsEntryString *selectedItemSetting() const { return mSelectedItemSetting.get(); }
254
255 protected:
257 void initNamedList( const Qgis::SettingsTreeNodeOptions &options );
258
259 private:
261
268 QgsSettingsTreeNamedListNode() SIP_FORCE;
269
270 QgsSettingsTreeNamedListNode( const QgsSettingsTreeNamedListNode &other ) = delete;
271
273 QString completeKeyWithNamedItems( const QString &key, const QStringList &namedItems ) const;
274
275 Qgis::SettingsTreeNodeOptions mOptions;
276 std::unique_ptr<const QgsSettingsEntryString> mSelectedItemSetting;
277 QString mItemsCompleteKey;
278};
279
280#endif // QGSSETTINGSTREENODE_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
SettingsTreeNodeType
Type of tree node.
Definition qgis.h:680
QFlags< SettingsTreeNodeOption > SettingsTreeNodeOptions
Definition qgis.h:697
SettingsOrigin
The setting origin describes where a setting is stored.
Definition qgis.h:4609
Represents a settings entry and provides methods for reading and writing settings values.
A string settings entry.
Custom exception class for settings related exceptions.
A named list tree node for the settings tree to help organizing and introspecting the tree.
const QgsSettingsEntryString * selectedItemSetting() const
Returns the setting used to store the selected item.
void deleteAllItems(const QStringList &parentsNamedItems=QStringList())
Deletes all items from the named list node.
void deleteItem(const QString &item, const QStringList &parentsNamedItems=QStringList())
Deletes a named item from the named list node.
QString selectedItem(const QStringList &parentsNamedItems=QStringList())
Returns the selected named item from the named list node.
void setSelectedItem(const QString &item, const QStringList &parentsNamedItems=QStringList())
Sets the selected named item from the named list node.
QStringList items(const QStringList &parentsNamedItems=QStringList()) const
Returns the list of items.
A tree node for the settings tree to help organizing and introspecting the tree.
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.
QgsSettingsTreeNode * createChildNode(const QString &key)
Creates a normal tree node It will return the existing child node if it exists at the given key.
Qgis::SettingsTreeNodeType mType
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.
static QgsSettingsTreeNode * createRootNode()
Creates a tree root node.
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.
QgsSettingsTreeNamedListNode * createNamedListNode(const QString &key, const Qgis::SettingsTreeNodeOptions &options=Qgis::SettingsTreeNodeOptions())
Creates a named list tree node.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:198
#define SIP_KEEPREFERENCE
Definition qgis_sip.h:93
#define SIP_FORCE
Definition qgis_sip.h:138
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_THROW(name,...)
Definition qgis_sip.h:210
#define SIP_END
Definition qgis_sip.h:215