29 qDeleteAll( mChildrenNodes );
30 qDeleteAll( mChildrenSettings );
38 te->mCompleteKey = QStringLiteral(
"/" );
48 throw QgsSettingsException( QObject::tr(
"Settings tree node '%1' already holds a child setting with key '%2'." ).arg( this->
key(), key ) );
52 te->init(
this,
key );
65 throw QgsSettingsException( QObject::tr(
"Settings tree node '%1' already holds a child node with key '%2', but it is not a named list.." ).arg( this->
key(), key ) );
68 throw QgsSettingsException( QObject::tr(
"Settings tree node '%1' already holds a child setting with key '%2'." ).arg( this->
key(), key ) );
72 te->init(
this,
key );
81 QList<QgsSettingsTreeNode *>::const_iterator it = mChildrenNodes.constBegin();
82 for ( ; it != mChildrenNodes.constEnd(); ++it )
84 if ( ( *it )->key() ==
key )
92 const QString testCompleteKey = QStringLiteral(
"%1%2" ).arg( mCompleteKey,
key );
93 QList<const QgsSettingsEntryBase *>::const_iterator it = mChildrenSettings.constBegin();
94 for ( ; it != mChildrenSettings.constEnd(); ++it )
96 if ( ( *it )->definitionKey() == testCompleteKey )
105 throw QgsSettingsException( QObject::tr(
"Settings tree node '%1' already holds a child tree node with key '%2'." ).arg( this->
key(), key ) );
107 throw QgsSettingsException( QObject::tr(
"Settings tree node '%1' already holds a child setting with key '%2'." ).arg( this->
key(), key ) );
109 mChildrenSettings.append( setting );
115 mChildrenNodes.append( node );
120 if ( deleteSettingValues )
121 setting->
remove( parentsNamedItems );
123 mChildrenSettings.removeAll( setting );
128 mChildrenNodes.removeAll( node );
135 mCompleteKey = QDir::cleanPath( QStringLiteral(
"%1/%2" ).arg(
parent->
completeKey(),
key ) ) +
'/';
145 mSelectedItemSetting =
new QgsSettingsEntryString( QStringLiteral(
"%1/selected" ).arg( mCompleteKey ),
nullptr );
148 mNamedNodesCount = mParent->namedNodesCount() + 1;
149 mItemsCompleteKey = QStringLiteral(
"%1items/" ).arg( mCompleteKey );
150 mCompleteKey.append( QStringLiteral(
"items/%%1/" ).arg( mNamedNodesCount ) );
155 delete mSelectedItemSetting;
167 throw QgsSettingsException( QObject::tr(
"The number of given parent named items (%1) for the node '%2' doesn't match with the number of named items in the key (%3)." ).arg( QString::number( parentsNamedItems.count() ), mCompleteKey, QString::number(
namedNodesCount() ) ) );
170 const QString completeKeyParam = completeKeyWithNamedItems( mItemsCompleteKey, parentsNamedItems );
179 throw QgsSettingsException( QObject::tr(
"The number of given parent named items (%1) for the node '%2' doesn't match with the number of named items in the key (%3)." ).arg( QString::number( parentsNamedItems.count() ), mCompleteKey, QString::number(
namedNodesCount() ) ) );
181 throw QgsSettingsException( QObject::tr(
"The named list node '%1' has no option to set the current selected entry." ).arg( mCompleteKey ) );
183 mSelectedItemSetting->
setValue( item, parentsNamedItems );
189 throw QgsSettingsException( QObject::tr(
"The number of given parent named items (%1) for the node '%2' doesn't match with the number of named items in the key (%3)." ).arg( QString::number( parentsNamedItems.count() ), mCompleteKey, QString::number(
namedNodesCount() ) ) );
191 throw QgsSettingsException( QObject::tr(
"The named list node '%1' has no option to set the current selected entry." ).arg( mCompleteKey ) );
193 return mSelectedItemSetting->
value( parentsNamedItems );
199 throw QgsSettingsException( QObject::tr(
"The number of given parent named items (%1) doesn't match with the number of named items in the key (%2)." ).arg( parentsNamedItems.count(),
namedNodesCount() ) );
201 QStringList args = parentsNamedItems;
203 QString
key = completeKeyWithNamedItems( mCompleteKey, args );
207QString QgsSettingsTreeNamedListNode::completeKeyWithNamedItems(
const QString &key,
const QStringList &namedItems )
const
209 switch ( namedItems.count() )
214 return key.arg( namedItems[0] );
216 return key.arg( namedItems[0], namedItems[1] );
218 return key.arg( namedItems[0], namedItems[1], namedItems[2] );
220 return key.arg( namedItems[0], namedItems[1], namedItems[2], namedItems[3] );
222 return key.arg( namedItems[0], namedItems[1], namedItems[2], namedItems[3], namedItems[4] );
224 throw QgsSettingsException( QObject::tr(
"Current implementation of QgsSettingsTreeNamedListNode::items doesn't handle more than 5 parent named items" ) );
@ NamedListSelectedItemSetting
Creates a setting to store which is the current item.
SettingsOrigin
The setting origin describes where a setting is stored.
Represent settings entry and provides methods for reading and writing settings values.
void remove(const QString &dynamicKeyPart=QString()) const
Removes the settings from the underlying QSettings.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
Custom exception class for settings related exceptions.
QgsSettingsTreeNamedListNode is a named list tree node for the settings tree to help organizing and i...
QString selectedItem(const QStringList &parentsNamedItems=QStringList()) SIP_THROW(QgsSettingsException)
Returns the selected named item from the named list node.
QStringList items(const QStringList &parentsNamedItems=QStringList()) const SIP_THROW(QgsSettingsException)
Returns the list of items.
void initNamedList(const Qgis::SettingsTreeNodeOptions &options)
Init the nodes with the specific options.
void deleteItem(const QString &item, const QStringList &parentsNamedItems=QStringList()) SIP_THROW(QgsSettingsException)
Deletes a named item from the named list node.
virtual ~QgsSettingsTreeNamedListNode()
void setSelectedItem(const QString &item, const QStringList &parentsNamedItems=QStringList()) SIP_THROW(QgsSettingsException)
Sets the selected named item from the named list node.
QgsSettingsTreeNode is a tree node for the settings tree to help organizing and introspecting the tre...
void registerChildNode(QgsSettingsTreeNode *node)
Registers a child nodes.
QgsSettingsTreeNode * createChildNode(const QString &key) SIP_THROW(QgsSettingsException)
Creates a normal tree node It will return the existing child node if it exists at the given key.
QgsSettingsTreeNamedListNode * createNamedListNode(const QString &key, const Qgis::SettingsTreeNodeOptions &options=Qgis::SettingsTreeNodeOptions()) SIP_THROW(QgsSettingsException)
Creates a named list tree node.
Qgis::SettingsTreeNodeType type() const
Returns the type of node.
const QgsSettingsEntryBase * childSetting(const QString &key)
Returns the existing child settings 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
void unregisterChildSetting(const QgsSettingsEntryBase *setting, bool deleteSettingValues=false, const QStringList &parentsNamedItems=QStringList())
Unregisters the child setting.
virtual ~QgsSettingsTreeNode()
void registerChildSetting(const QgsSettingsEntryBase *setting, const QString &key) SIP_THROW(QgsSettingsException)
Registers a child setting.
QgsSettingsTreeNode * childNode(const QString &key)
Returns the existing child node if it exists at the given key.
QgsSettingsTreeNode * parent() const
Returns the parent of the node or nullptr if it does not exists.
void unregisterChildNode(QgsSettingsTreeNode *node)
Unregisters the child tree node.
This class is a composition of two QSettings instances:
QStringList childGroups(Qgis::SettingsOrigin origin=Qgis::SettingsOrigin::Any) const
Returns a list of all key top-level groups that contain keys that can be read using the QSettings obj...
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.