169 if (m_type ==
"maps") {
170 stream.writeStartElement(
"mapTemplateList");
172 else if (m_type ==
"registrations") {
173 stream.writeStartElement(
"regTemplateList");
176 throw IException(IException::Io,
177 QString(
"Attempting to save unsupported template file type: [%1]").arg(m_type),
180 stream.writeAttribute(
"name", m_name);
181 stream.writeAttribute(
"type", m_type);
182 stream.writeAttribute(
"path", m_path);
185 +
"/" + m_type +
"/" + m_name +
"/templates.xml");
187 if (!settingsFileName.dir().mkpath(settingsFileName.path())) {
188 throw IException(IException::Io,
189 QString(
"Failed to create directory [%1]").arg(settingsFileName.path()),
193 QFile templateListContentsFile(settingsFileName.toString());
195 if (!templateListContentsFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
196 throw IException(IException::Io,
197 QString(
"Unable to save template information for [%1] because [%2] could not be opened "
199 .arg(m_name).arg(settingsFileName.original()),
203 QXmlStreamWriter templateDetailsWriter(&templateListContentsFile);
204 templateDetailsWriter.setAutoFormatting(
true);
205 templateDetailsWriter.writeStartDocument();
206 templateDetailsWriter.writeStartElement(
"templates");
208 foreach (
Template *currentTemplate, *
this) {
209 currentTemplate->
save(templateDetailsWriter, project, newProjectRoot);
211 QString newPath = newProjectRoot.toString() +
"/templates/" + m_type +
"/" + m_name;
214 newPath +
"/" + FileName(currentTemplate->
fileName()).name()) {
215 QFile::copy(currentTemplate->
fileName(),
216 newPath +
"/" + FileName(currentTemplate->
fileName()).name() );
220 templateDetailsWriter.writeEndElement();
221 templateDetailsWriter.writeEndDocument();
223 stream.writeEndElement();
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Method to write this Template object's member data to an XML stream.
TemplateList(QString name, QString type, QString path, QObject *parent=NULL)
Create a template from a file name, type, and path.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Convert this TemplateList into XML format for saving/restoring capabilities.