33 const auto nodes = mChildrenNodes;
34 for (
const auto *node : nodes )
36 const auto settings = mChildrenSettings;
37 for (
const auto *setting : settings )
46 te->mCompleteKey = QStringLiteral(
"/" );
56 throw QgsSettingsException( QObject::tr(
"Settings tree node '%1' already holds a child setting with key '%2'." ).arg( this->
key(), key ) );
60 te->init(
this,
key );
73 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 ) );
76 throw QgsSettingsException( QObject::tr(
"Settings tree node '%1' already holds a child setting with key '%2'." ).arg( this->
key(), key ) );
80 te->init(
this,
key );
89 QList<QgsSettingsTreeNode *>::const_iterator it = mChildrenNodes.constBegin();
90 for ( ; it != mChildrenNodes.constEnd(); ++it )
92 if ( ( *it )->key() ==
key )
100 const QString testCompleteKey = QStringLiteral(
"%1%2" ).arg( mCompleteKey,
key );
101 QList<const QgsSettingsEntryBase *>::const_iterator it = mChildrenSettings.constBegin();
102 for ( ; it != mChildrenSettings.constEnd(); ++it )
104 if ( ( *it )->definitionKey() == testCompleteKey )
113 throw QgsSettingsException( QObject::tr(
"Settings tree node '%1' already holds a child tree node with key '%2'." ).arg( this->
key(), key ) );
115 throw QgsSettingsException( QObject::tr(
"Settings tree node '%1' already holds a child setting with key '%2'." ).arg( this->
key(), key ) );
117 mChildrenSettings.append( setting );
123 mChildrenNodes.append( node );
128 if ( deleteSettingValues )
129 setting->
remove( parentsNamedItems );
131 mChildrenSettings.removeAll( setting );
136 mChildrenNodes.removeAll( node );
143 mCompleteKey = QDir::cleanPath( QStringLiteral(
"%1/%2" ).arg(
parent->
completeKey(),
key ) ) +
'/';
153 mSelectedItemSetting =
new QgsSettingsEntryString( QStringLiteral(
"%1/selected" ).arg( mCompleteKey ),
nullptr );
156 mNamedNodesCount = mParent->namedNodesCount() + 1;
157 mItemsCompleteKey = QStringLiteral(
"%1items/" ).arg( mCompleteKey );
158 mCompleteKey.append( QStringLiteral(
"items/%%1/" ).arg( mNamedNodesCount ) );
163 delete mSelectedItemSetting;
175 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() ) ) );
178 const QString completeKeyParam = completeKeyWithNamedItems( mItemsCompleteKey, parentsNamedItems );
180 settings->beginGroup( completeKeyParam );
181 const QStringList res = settings->childGroups( origin );
182 settings->endGroup();
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 mSelectedItemSetting->
setValue( item, parentsNamedItems );
199 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() ) ) );
201 throw QgsSettingsException( QObject::tr(
"The named list node '%1' has no option to set the current selected entry." ).arg( mCompleteKey ) );
203 return mSelectedItemSetting->
value( parentsNamedItems );
209 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() ) );
211 QStringList args = parentsNamedItems;
213 QString
key = completeKeyWithNamedItems( mCompleteKey, args );
220 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() ) );
222 const QStringList children =
items( parentsNamedItems );
224 for (
const QString &child : children )
226 QStringList args = parentsNamedItems;
228 QString
key = completeKeyWithNamedItems( mCompleteKey, args );
229 settings->remove(
key );
233QString QgsSettingsTreeNamedListNode::completeKeyWithNamedItems(
const QString &key,
const QStringList &namedItems )
const
235 switch ( namedItems.count() )
240 return key.arg( namedItems[0] );
242 return key.arg( namedItems[0], namedItems[1] );
244 return key.arg( namedItems[0], namedItems[1], namedItems[2] );
246 return key.arg( namedItems[0], namedItems[1], namedItems[2], namedItems[3] );
248 return key.arg( namedItems[0], namedItems[1], namedItems[2], namedItems[3], namedItems[4] );
250 throw QgsSettingsException( QObject::tr(
"Current implementation of QgsSettingsTreeNamedListNode::items doesn't handle more than 5 parent named items" ) );
@ NamedList
Named List Node.
QFlags< SettingsTreeNodeOption > SettingsTreeNodeOptions
@ NamedListSelectedItemSetting
Creates a setting to store which is the current item.
SettingsOrigin
The setting origin describes where a setting is stored.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
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.
Custom exception class for settings related exceptions.
QgsSettingsTreeNamedListNode is a named list tree node for the settings tree to help organizing and i...
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.
void initNamedList(const Qgis::SettingsTreeNodeOptions &options)
Init the nodes with the specific options.
virtual ~QgsSettingsTreeNamedListNode()
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.
QgsSettingsTreeNode is a tree node for the settings tree to help organizing and introspecting the tre...
void registerChildNode(QgsSettingsTreeNode *node)
Registers a child 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
QgsSettingsTreeNode * childNode(const QString &key) const
Returns the existing child node if it exists at the given key.
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()
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.
void registerChildSetting(const QgsSettingsEntryBase *setting, const QString &key)
Registers a child setting.
const QgsSettingsEntryBase * childSetting(const QString &key) const
Returns the existing child settings if it exists at the given key.
QgsSettingsTreeNamedListNode * createNamedListNode(const QString &key, const Qgis::SettingsTreeNodeOptions &options=Qgis::SettingsTreeNodeOptions())
Creates a named list tree node.
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
static QgsSettingsProxy get()
Returns a proxy for a QgsSettings object.