Isis 3 Programmer Reference
ImportMapTemplateWorkOrder.cpp
Go to the documentation of this file.
1
24
25#include <QFile>
26#include <QFileDialog>
27#include <QMessageBox>
28#include <QRegularExpression>
29#include <QDebug>
30
31#include "Project.h"
32#include "ProjectItemModel.h"
33#include "Template.h"
34#include "TemplateList.h"
35
36namespace Isis {
43 WorkOrder(project) {
44
45 m_isUndoable = true;
46 m_list = NULL;
47
48 QAction::setText(tr("Import Map Templates..."));
49 QUndoCommand::setText(tr("Import Map Templates..."));
51
52 }
53
54
63
64
71
72
81
82
94 QString itemType = item->text();
96
97 return (itemType == "Maps");
98 }
99
100
111
113
114 QStringList templateFileNames;
115
116 templateFileNames = QFileDialog::getOpenFileNames(
117 qobject_cast<QWidget *>(parent()),
118 "Import Map Templates",
119 QString(),
120 "Maps (*.map);; All Files (*)");
121
122 if (!templateFileNames.isEmpty()) {
123 QUndoCommand::setText(tr("Import %1 Template(s)").arg(templateFileNames.count()));
124 }
125 else {
126 return false;
127 }
128
129 setInternalData(templateFileNames);
130
131 return true;
132 }
133
134
142 QDir templateFolder = project()->addTemplateFolder("maps/import");
143 QStringList templateFileNames = internalData();
144
145 m_list = new TemplateList(templateFolder.dirName(),
146 "maps",
147 "maps/" + templateFolder.dirName() );
148
149 foreach (FileName filename, templateFileNames) {
150 QFile::copy(filename.expanded(), templateFolder.path() + "/" + filename.name());
151 m_list->append(new Template(templateFolder.path() + "/" + filename.name(),
152 "maps",
153 templateFolder.dirName()));
154 }
155
156 if (!m_list->isEmpty()) {
157 project()->addTemplates(m_list);
158 project()->setClean(false);
159 }
160
161 }
162
163
171 if (m_list && project()->templates().size() > 0) {
172 m_list->deleteFromDisk( project() );
173 ProjectItem *currentItem =
174 project()->directory()->model()->findItemData(QVariant::fromValue(m_list));
175 project()->directory()->model()->removeItem(currentItem);
176 }
177 foreach ( Template *currentTemplate, *m_list) {
178 delete currentTemplate;
179 }
180 delete m_list;
181 m_list = NULL;
182 }
183
184}
ProjectItemModel * model()
Gets the ProjectItemModel for this directory.
File name manipulation and expansion.
Definition FileName.h:100
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition FileName.cpp:162
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition FileName.cpp:196
Add map templates to a project.
virtual bool isExecutable(ProjectItem *item)
This method returns true if the user clicked on a project tree node with the text "Maps".
bool setupExecution()
Sets up the work order for execution.
virtual ImportMapTemplateWorkOrder * clone() const
This method clones the current ImportMapTemplateWorkOrder and returns it.
void undoExecution()
Deletes the previously imported templates.
ImportMapTemplateWorkOrder(Project *project)
Creates a work order to import map templates.
The main project for ipce.
Definition Project.h:289
QDir addTemplateFolder(QString prefix)
Create and navigate to the appropriate template type folder in the project directory.
Definition Project.cpp:1133
Directory * directory() const
Returns the directory associated with this Project.
Definition Project.cpp:1228
void setClean(bool value)
Function to change the clean state of the project.
Definition Project.cpp:1594
void addTemplates(TemplateList *templateFiles)
Add new templates to m_mapTemplates or m_regTemplates and update project item model.
Definition Project.cpp:1112
Represents an item of a ProjectItemModel in Qt's model-view framework.
ProjectItem * findItemData(const QVariant &data, int role=Qt::UserRole+1)
Returns the first item found that contains the given data in the given role or a null pointer if no i...
virtual void removeItem(ProjectItem *item)
Removes an item and its children from the model.
void deleteFromDisk(Project *project)
Delete all of the contained Templates from disk.
Provide Undo/redo abilities, serialization, and history for an operation.
Definition WorkOrder.h:311
bool m_isUndoable
Set the workorder to be undoable/redoable This is defaulted to true - his will allow the workorder to...
Definition WorkOrder.h:523
virtual bool setupExecution()
This sets up the state for the work order.
QStringList internalData() const
Gets the internal data for this WorkOrder.
void setModifiesDiskState(bool changesProjectOnDisk)
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
Project * project() const
Returns the Project this WorkOrder is attached to.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16