21 #include "realfactory.h"
22 #include "configurationnode.h"
23 #include "configurationparameters.h"
24 #include "parametersfileloadersaver.h"
25 #include "parametersettable.h"
26 #include "configurationexceptions.h"
33 QMap<QString, ConfigurationParameters::FileFormat>& ConfigurationParameters::getFormatsMap()
35 static QMap<QString, ConfigurationParameters::FileFormat> formatsMap;
40 QMap<QString, QString>& ConfigurationParameters::getFileExtensionsMap()
42 static QMap<QString, QString> fileExtensionsMap;
44 return fileExtensionsMap;
50 QMap<QString, FileFormat>::iterator it = getFormatsMap().find(format);
51 if (it != getFormatsMap().end()) {
56 if (defaultExtension.isEmpty()) {
57 defaultExtension = format;
61 FileFormat f(format, fileLoaderSaver, defaultExtension);
64 getFormatsMap().insert(format, f);
65 getFileExtensionsMap().insert(defaultExtension, format);
73 m_getObjectFromGroupRecursionLevel(0),
74 m_objectsToConfigure(),
75 m_dontForgetGroupObjectAssociations(false),
83 m_getObjectFromGroupRecursionLevel(0),
84 m_objectsToConfigure(),
85 m_dontForgetGroupObjectAssociations(false),
89 copyTree(other.m_root.get());
95 if (m_getObjectFromGroupRecursionLevel != 0) {
100 if (&other ==
this) {
105 copyTree(other.m_root.get());
108 m_factory->clearObservers();
109 m_factory->addObservers(other.m_factory->getObservers());
121 return m_root->isCaseSensitive();
131 return m_root->getNode(group)->getChildrenList();
137 QRegExp filter(QString(
"^") + QRegExp::escape(prefix), (
isCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive));
144 return m_root->getNode(group)->getFilteredChildrenList(filter);
154 for (QStringList::iterator it = splittedPath.begin(); it != splittedPath.end(); it++) {
155 lastNode = lastNode->
addNode(*it);
165 return m_root->getNode(groupParent)->deleteNode(groupName);
174 return m_root->getNode(groupParent)->renameNode(groupName, newGroupName);
179 if ( sourceNode->
isNull() ) {
183 if ( destNode->
isNull() ) {
186 destNode = m_root->getNode( destGroup );
188 copyNode( sourceNode, destNode );
216 return m_root->setObjectForNode(groupPath,
object);
221 return m_root->getValue(path, alsoMatchParents);
226 return m_root->setValue(path, value);
231 return m_root->setValue(path,
object);
236 return m_root->getNode(group)->getParametersList();
242 QRegExp filter(QString(
"^") + QRegExp::escape(prefix), (
isCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive));
249 return m_root->getNode(group)->getFilteredParametersList(filter);
254 m_dontForgetGroupObjectAssociations =
true;
259 m_dontForgetGroupObjectAssociations =
false;
265 QQueue<ConfigurationNode *> nodeQueue;
266 nodeQueue.enqueue(m_root.get());
269 while (!nodeQueue.isEmpty()) {
275 #if QT_VERSION_CHECK > 0x450000
279 nodeQueue.append( an );
291 QMap<ParameterSettable *, QString> objectsMap;
292 QQueue<ConfigurationNode *> nodeQueue;
293 nodeQueue.enqueue(m_root.get());
296 while (!nodeQueue.isEmpty()) {
301 if (
object.
object != NULL) {
310 fullname.remove( 0, 1 );
312 objectsMap[
object.object] = fullname;
316 #if QT_VERSION_CHECK > 0x450000
320 nodeQueue.append( an );
327 nodeQueue.enqueue(m_root.get());
330 while (!nodeQueue.isEmpty()) {
337 for (QStringList::iterator it = params.begin(); it != params.end(); it++) {
342 if (objectsMap.contains(obj)) {
343 curNode->
setValue(*it, objectsMap[obj]);
345 curNode->
setValue(*it, QString(
""));
350 #if QT_VERSION_CHECK > 0x450000
354 nodeQueue.append( an );
363 if (format.isEmpty()) {
364 format = formatFromFilenameExtension(filename);
366 if (format.isNull()) {
372 QMap<QString, FileFormat>::iterator it = getFormatsMap().find(format);
375 if (it == getFormatsMap().end()) {
379 return it->fileLoaderSaver->load( filename, *
this, keepOld );
388 if (format.isEmpty()) {
389 format = formatFromFilenameExtension(filename);
391 if (format.isNull()) {
397 QMap<QString, FileFormat>::iterator it = getFormatsMap().find(format);
400 if (it == getFormatsMap().end()) {
404 return it->fileLoaderSaver->save( filename, *
this, append );
410 for (
int i = m_getObjectFromGroupRecursionLevel; i >= 0; i--) {
411 if (m_resourcesUserPerRecursionLevel[i].hasResource(resourceName)) {
412 return &(m_resourcesUserPerRecursionLevel[i]);
421 m_resourcesUserPerRecursionLevel.last().shareResourcesWith(resourcesUser);
426 m_factory->addObserver(observer);
430 m_factory->addObservers( params.m_factory->getObservers() );
433 QString ConfigurationParameters::formatFromFilenameExtension(QString filename)
const
435 QFileInfo info(filename);
437 QMap<QString, QString>::const_iterator it = getFileExtensionsMap().find(info.suffix());
438 if (it == getFileExtensionsMap().end()) {
445 void ConfigurationParameters::copyTree(
const ConfigurationNode *root)
448 m_root.reset(
new ConfigurationNode(NULL, root->getName(), root->isCaseSensitive()));
451 copyNode(root, m_root.get());
454 void ConfigurationParameters::copyNode(
const ConfigurationNode *source, ConfigurationNode *target)
457 QStringList params = source->getParametersList();
458 for (QStringList::const_iterator it = params.begin(); it != params.end(); it++) {
459 target->addParameter(*it);
460 target->setValue(*it, source->getValue(*it));
466 QStringList children = source->getChildrenList();
467 for (QStringList::const_iterator it = children.begin(); it != children.end(); it++) {
468 target->addNode(*it);
469 copyNode(source->getNode(*it), target->getNode(*it));
473 bool ConfigurationParameters::setObjectFromGroupStatusToCreating(QString group)
475 if (m_getObjectFromGroupRecursionLevel == 0) {
478 return m_root->setObjectForNode(group, NULL, CreatingObject);
481 bool ConfigurationParameters::setObjectFromGroupStatusToCreatedNotConfigured(QString group, ParameterSettable *
object)
483 if (m_getObjectFromGroupRecursionLevel == 0) {
486 return m_root->setObjectForNode(group,
object, ObjectCreatedNotConfigured);
489 bool ConfigurationParameters::setObjectFromGroupStatusToConfiguring(QString group)
491 if (m_getObjectFromGroupRecursionLevel == 0) {
494 return m_root->setObjectForNode(group, NULL, ConfiguringObject);
497 bool ConfigurationParameters::setObjectFromGroupStatusToCreatingAndConfiguring(QString group)
499 if (m_getObjectFromGroupRecursionLevel == 0) {
502 return m_root->setObjectForNode(group, NULL, CreatingAndConfiguringObject);
505 bool ConfigurationParameters::setObjectFromGroupStatusToCreatedAndConfigured(QString group, ParameterSettable *
object)
507 if (m_getObjectFromGroupRecursionLevel == 0) {
510 return m_root->setObjectForNode(group,
object, ObjectCreatedAndConfigured);