37 #include <QTextStream>
40 #include "tsf-config.h"
57 QStringList ignoreParametersWithName;
58 ignoreParametersWithName <<
"centerline-vtk-file";
59 ignoreParametersWithName <<
"storage-dir";
62 QDomElement retval = doc.createElement(
"Preset");
63 retval.setAttribute(
"name", name);
64 std::map<QString, QString>::iterator it;
65 for (it = parameters.begin(); it != parameters.end(); ++it)
67 if (!ignoreParametersWithName.contains(it->first))
68 retval.setAttribute(it->first, it->second);
76 QDomNodeList presetNodes = doc.elementsByTagName(
"Preset");
77 for (
int i = 0; i < presetNodes.count(); ++i)
79 QDomNode node = presetNodes.at(i);
80 if (!node.isElement())
82 QDomElement element = node.toElement();
86 std::map<QString, QString> parameters;
87 QDomNamedNodeMap attributes = element.attributes();
88 for (
int j = 0; j < attributes.count(); ++j)
90 QDomNode attribute = attributes.item(j);
91 if (attribute.isNull())
93 if (attribute.nodeName() !=
"name")
94 parameters[attribute.nodeName()] = attribute.nodeValue();
97 this->
saveFile(folderPath, parameters);
111 std::map<QString, QString>::iterator it;
127 std::map<QString,QString>::iterator it;
128 for (it = presets.begin();it != presets.end();++it)
135 std::map<QString, QString> retval;
136 if (!QFile::exists(filePath))
141 QFile file(filePath);
142 if (file.open(QFile::ReadOnly))
144 QTextStream in(&file);
147 QString line = in.readLine();
148 QStringList lineItems = line.split(
" ");
149 if (lineItems.count() == 2)
150 retval[lineItems.at(0)] = lineItems.at(1);
160 QString customPresetName = QFileInfo(file).fileName();
161 QTextStream outPresetFile;
162 if (!file.open(QFile::WriteOnly))
164 reportError(
"Could not open the file " + file.fileName() +
" for writing.");
167 outPresetFile.setDevice(&file);
168 std::map<QString, QString>::iterator it;
169 for (it = parameters.begin(); it != parameters.end(); ++it)
171 QString line = it->first +
" " + it->second;
172 outPresetFile << line <<
"\n";
174 outPresetFile << flush;
180 QFile file(filePath);
181 QString customPresetName = QFileInfo(file).fileName();
183 reportError(
"File: " + filePath +
" not removed...");
189 QDir parametersDir(
mPresetPath +
"/centerline-gpu");
190 if (!parametersDir.exists())
191 reportError(
"Preset directory "+parametersDir.path()+
" not found.");
193 QFileInfoList fileInfoList = parametersDir.entryInfoList(QDir::Files);
194 foreach(QFileInfo info, fileInfoList){
195 QString name = info.baseName();
202 std::map<QString,QString> params = this->
readFile(it->second);
std::map< QString, QString > mPresetsMap
void convertToInternalFormat(std::map< QString, QString > &presets)
void reportError(QString msg)
void loadPresetsFromFiles()
Base class for a group of presets in the system.
void getPresetsNameAndPath()
XmlOptionFile getCustomFile()
static QString findConfigFolder(QString pathRelativeToConfigRoot, QString alternativeAbsolutePath="")
virtual void save()
Saves last custom preset (current)
void saveFile(QString folderPath, std::map< QString, QString > parameters)
QString mLastCustomPresetRemoved
< the name of the last custom preset added
void addCustomPreset(QDomElement &element)
adds a custom preset
virtual void remove()
removes the presets from file
static QDomElement createPresetElement(QString name, std::map< QString, QString > ¶meters)
void deleteFile(QString filePath)
QDomDocument getDocument()
returns the document
QString mLastCustomPresetAdded
std::map< QString, QString > readFile(QString &filePath)
void addAsCustomPreset(std::map< QString, QString >::iterator it)
virtual QStringList generatePresetList(QString tag)
internally generate the preset list
Helper class for xml files used to store ssc/cx data.