configurationnode.cpp
27 ConfigurationNode::ConfigurationNode(ConfigurationNode *parent, QString name, bool caseSensitive) :
30 m_name(((name == ConfigurationParameters::GroupSeparator()) || (name == ConfigurationParameters::ParentGroup())) ? QString() : name),
77 // If we have a parent, calling its getAncestorsNames and appending us to the result, otherwise returning the
105 // Not adding the node if its name is NULL, the group separator or the parent node or if this is a null node
106 if ((isNull()) || (name.isEmpty()) || (name == ConfigurationParameters::GroupSeparator()) || (name == ConfigurationParameters::ParentGroup())) {
113 if ( child.compare( name, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
129 return const_cast<ConfigurationNode*>((const_cast<const ConfigurationNode*>(this))->getNode(path));
139 QString firstNode = path.section(ConfigurationParameters::GroupSeparator(), 0, 0, QString::SectionSkipEmpty);
142 // If the first node is the empty string (i.e. the whole path is the empty string) returning this
150 // Getting the first node from the list of my children and, if it exists, calling its getNode function
152 if ( child.compare( firstNode, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
153 QString remainingPath = path.section(ConfigurationParameters::GroupSeparator(), 1, -1, QString::SectionSkipEmpty);
171 if ( child.compare( name, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
184 if (isNull() || (newName.isEmpty()) || (newName == ConfigurationParameters::GroupSeparator()) || (newName == ConfigurationParameters::ParentGroup())) {
191 if ( child.compare( oldName, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
224 bool ConfigurationNode::setObjectForNode(QString path, ParameterSettable* object, ObjectCreationStatus status)
262 // Not adding the property if its name is NULL, the group separator, the parent group or if this is a null node
263 if ((isNull()) || (name.isEmpty()) || (name == ConfigurationParameters::GroupSeparator()) || (name == ConfigurationParameters::ParentGroup())) {
269 if ( parameter.compare( name, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
289 QString firstPart = path.section(ConfigurationParameters::GroupSeparator(), 0, 0, QString::SectionSkipEmpty);
290 QString remainingPath = path.section(ConfigurationParameters::GroupSeparator(), 1, -1, QString::SectionSkipEmpty);
295 if ( parameter.compare( firstPart, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
301 // Calling the function in parent group (calling it again on ourself if we don't have any parent group)
311 QString parameterName = path.section(ConfigurationParameters::GroupSeparator(), -1, -1, QString::SectionSkipEmpty);
313 if ( parameter.compare( parameterName, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
320 // Getting the first node from the list of my children and, if it exists, calling its getValue function
322 if ( child.compare( firstPart, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
324 // If we also have to match the parameter in parents and the parameter wasn't found in children,
336 ConfigurationNode::ObjectAndStatus ConfigurationNode::getObject(QString path, bool alsoMatchParents) const
346 QString firstPart = path.section(ConfigurationParameters::GroupSeparator(), 0, 0, QString::SectionSkipEmpty);
347 QString remainingPath = path.section(ConfigurationParameters::GroupSeparator(), 1, -1, QString::SectionSkipEmpty);
351 if ( parameter.compare( firstPart, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
357 // Calling the function in parent group (calling it again on ourself if we don't have any parent group)
367 QString parameterName = path.section(ConfigurationParameters::GroupSeparator(), -1, -1, QString::SectionSkipEmpty);
369 if ( parameter.compare( parameterName, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
376 // Getting the first node from the list of my children and, if it exists, calling its getObject function
378 if ( child.compare( firstPart, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
380 // If we also have to match the parameter in parents and the parameter wasn't found in children,
400 QString firstPart = path.section(ConfigurationParameters::GroupSeparator(), 0, 0, QString::SectionSkipEmpty);
401 QString remainingPath = path.section(ConfigurationParameters::GroupSeparator(), 1, -1, QString::SectionSkipEmpty);
406 if ( parameter.compare( firstPart, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
413 // Calling the function in parent group (calling it again on ourself if we don't have any parent group)
418 // Getting the first node from the list of my children and, if it exists, calling its setValue function
420 if ( child.compare( firstPart, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
435 QString firstPart = path.section(ConfigurationParameters::GroupSeparator(), 0, 0, QString::SectionSkipEmpty);
436 QString remainingPath = path.section(ConfigurationParameters::GroupSeparator(), 1, -1, QString::SectionSkipEmpty);
441 if ( parameter.compare( firstPart, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
451 // Calling the function in parent group (calling it again on ourself if we don't have any parent group)
456 // Getting the first node from the list of my children and, if it exists, calling its setValue function
458 if ( child.compare( firstPart, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
474 if ( parameter.compare( name, (m_caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) ) == 0 ) {
512 for (QMap<QString, ConfigurationNode*>::iterator it = m_children.begin(); it != m_children.end(); it++) {
QStringList getFilteredParametersList(QRegExp filter) const
Returns the list of parameters whose name matches the given regular expression.
Definition: configurationnode.cpp:489
QStringList getParametersList() const
Returns the list of parameter names.
Definition: configurationnode.cpp:483
bool deleteNode(QString name)
Removes the child node with the given name.
Definition: configurationnode.cpp:163
QStringList getFilteredObjectParametersList(QRegExp filter) const
Returns the list of parameters referring to objects.
Definition: configurationnode.cpp:500
~ConfigurationNode()
Destructor. This also destroys child nodes.
Definition: configurationnode.cpp:42
bool renameNode(QString oldName, QString newName)
Rename the child node with the new given name.
Definition: configurationnode.cpp:182
Definition: configurationhelper.cpp:24
The class containing configuration parameters.
Definition: configurationparameters.h:259
ObjectAndStatus getObjectForNode(QString path) const
Returns the object corresponding to the given node.
Definition: configurationnode.cpp:248
The base for classes that can be configured/saved using a ConfigurationParameters object...
Definition: parametersettable.h:51
ConfigurationNode * getNode(QString path)
Returns a pointer to the node having the given path.
Definition: configurationnode.cpp:126
QString getFullName() const
Returns the full name of the node (i.e. the full path from root to this node)
Definition: configurationnode.cpp:89
ConfigurationNode(ConfigurationNode *parent, QString name=QString(), bool caseSensitive=false)
Constructor. This creates an empty node.
Definition: configurationnode.cpp:27
QList< ConfigurationNode * > getChildrenNodesList()
Returns the list of child nodes.
Definition: configurationnode.cpp:209
static QString ParentGroup()
The sequence used to indicate the parent group.
Definition: configurationparameters.h:276
QString getValue(QString path, bool alsoMatchParents=false) const
Returns the value of the parameter with the given path.
Definition: configurationnode.cpp:279
QStringList getFilteredChildrenList(QRegExp filter) const
Returns the list of child nodes whose name matches the given regular expression.
Definition: configurationnode.cpp:219
ObjectAndStatus getObject(QString path, bool alsoMatchParents=false) const
Returns the object to which the parameter with the given path refer.
Definition: configurationnode.cpp:336
QStringList getChildrenList() const
Returns the list of child nodes (the list of names)
Definition: configurationnode.cpp:214
The structure with the object for a node and its status.
Definition: configurationnode.h:70
bool setValue(QString path, QString value)
Sets the value of the parameter with the given path.
Definition: configurationnode.cpp:393
QList< const ConfigurationNode * > getAncestors() const
Returns a list of pointers to ancestor nodes.
Definition: configurationnode.cpp:51
QStringList getAncestorsNames() const
Returns a list of names of ancestor nodes.
Definition: configurationnode.cpp:69
static QString GroupSeparator()
The character used to split path in groups.
Definition: configurationparameters.h:268
ConfigurationNode * addNode(QString name)
Adds a child node with the given name and returns a pointer to it.
Definition: configurationnode.cpp:103
QStringList getObjectParametersList() const
Returns the list of parameters referring to objects.
Definition: configurationnode.cpp:494
bool setObjectForNode(QString path, ParameterSettable *object, ObjectCreationStatus status=ObjectCreatedAndConfigured)
Sets the object corresponding to the given node to object.
Definition: configurationnode.cpp:224