Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis 3 Programmer Reference
TemplateList.cpp
1
6
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "TemplateList.h"
10#include <QDir>
11
12#include "FileName.h"
13#include "IException.h"
14#include "Project.h"
15
16namespace Isis {
25 TemplateList::TemplateList(QString name, QString type, QString path, QObject *parent) : QObject(parent){
26 m_name = name;
27 m_path = path;
28 m_type = type;
29 }
30
31
38 }
39
40
47 QList<Template *>(other) {
48 m_path = other.m_path;
49 m_name = other.m_name;
50 m_type = other.m_type;
51 }
52
53
58 // At the moment, this only occurs during an ImportTemplateWorkOrder undo, where it is handled
59 }
60
61
67 QString TemplateList::name() const{
68 return m_name;
69 }
70
71
77 QString TemplateList::type() const{
78 return m_type;
79 }
80
81
87 QString TemplateList::path() const{
88 return m_path;
89 }
90
91
97 void TemplateList::setName(QString newName) {
98 m_name = newName;
99 }
100
101
107 void TemplateList::setType(QString newType) {
108 m_type = newType;
109 }
110
111
117 void TemplateList::setPath(QString newPath) {
118 m_path = newPath;
119 }
120
121
130 foreach (Template *currentTemplate, *this) {
131 currentTemplate->deleteFromDisk();
132 }
133
134 if (!m_path.isEmpty()) {
135 QFile::remove(project->templateRoot() + "/" + m_path + "/templates.xml");
136
137 QDir dir;
138 dir.rmdir(project->templateRoot() + "/" + m_path);
139 }
140 }
141
142
166 void TemplateList::save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot)
167 const {
168
169 if (m_type == "maps") {
170 stream.writeStartElement("mapTemplateList");
171 }
172 else if (m_type == "registrations") {
173 stream.writeStartElement("regTemplateList");
174 }
175 else {
176 throw IException(IException::Io,
177 QString("Attempting to save unsupported template file type: [%1]").arg(m_type),
178 _FILEINFO_);
179 }
180 stream.writeAttribute("name", m_name);
181 stream.writeAttribute("type", m_type);
182 stream.writeAttribute("path", m_path);
183
184 FileName settingsFileName(Project::templateRoot(newProjectRoot.toString())
185 + "/" + m_type + "/" + m_name + "/templates.xml");
186
187 if (!settingsFileName.dir().mkpath(settingsFileName.path())) {
188 throw IException(IException::Io,
189 QString("Failed to create directory [%1]").arg(settingsFileName.path()),
190 _FILEINFO_);
191 }
192
193 QFile templateListContentsFile(settingsFileName.toString());
194
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 "
198 "for writing")
199 .arg(m_name).arg(settingsFileName.original()),
200 _FILEINFO_);
201 }
202
203 QXmlStreamWriter templateDetailsWriter(&templateListContentsFile);
204 templateDetailsWriter.setAutoFormatting(true);
205 templateDetailsWriter.writeStartDocument();
206 templateDetailsWriter.writeStartElement("templates");
207
208 foreach (Template *currentTemplate, *this) {
209 currentTemplate->save(templateDetailsWriter, project, newProjectRoot);
210
211 QString newPath = newProjectRoot.toString() + "/templates/" + m_type + "/" + m_name;
212
213 if (currentTemplate->fileName() !=
214 newPath + "/" + FileName(currentTemplate->fileName()).name()) {
215 QFile::copy(currentTemplate->fileName(),
216 newPath + "/" + FileName(currentTemplate->fileName()).name() );
217 }
218 }
219
220 templateDetailsWriter.writeEndElement();
221 templateDetailsWriter.writeEndDocument();
222
223 stream.writeEndElement();
224 }
225}
The main project for ipce.
Definition Project.h:287
static QString templateRoot(QString projectRoot)
Appends the root directory name 'templates' to the project .
Definition Project.cpp:2187
QString fileName() const
Get the file name that this Template represents.
Definition Template.cpp:49
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Method to write this Template object's member data to an XML stream.
Definition Template.cpp:104
void deleteFromDisk()
Delete the template from disk.
Definition Template.cpp:87
void setPath(QString newPath)
Set the relative path (from the project root) to this TemplateList's folder.
TemplateList(QString name, QString type, QString path, QObject *parent=NULL)
Create a template from a file name, type, and path.
QString name() const
Get the human-readable name of this TemplateList.
~TemplateList()
Destructor.
void deleteFromDisk(Project *project)
Delete all of the contained Templates from disk.
QString path() const
Get the path to these Templates in the TemplateList (relative to project root).
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Convert this TemplateList into XML format for saving/restoring capabilities.
void setName(QString newName)
Set the human-readable name of this TemplateList.
QString type() const
Get the type of template in this TemplateList.
void setType(QString newType)
Set the type of template for of this TemplateList.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16