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 
36 namespace 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 
61  WorkOrder(other) {
62  }
63 
64 
69  m_list = NULL;
70  }
71 
72 
79  return new ImportMapTemplateWorkOrder(*this);
80  }
81 
82 
94  QString itemType = item->text();
95  setInternalData(QStringList(itemType));
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 }
Isis::ImportMapTemplateWorkOrder::clone
virtual ImportMapTemplateWorkOrder * clone() const
This method clones the current ImportMapTemplateWorkOrder and returns it.
Definition: ImportMapTemplateWorkOrder.cpp:78
Isis::WorkOrder::setupExecution
virtual bool setupExecution()
This sets up the state for the work order.
Definition: WorkOrder.cpp:1261
Isis::WorkOrder
Provide Undo/redo abilities, serialization, and history for an operation.
Definition: WorkOrder.h:311
Project.h
Isis::Directory::model
ProjectItemModel * model()
Gets the ProjectItemModel for this directory.
Definition: Directory.cpp:1091
Isis::FileName::name
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition: FileName.cpp:162
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::WorkOrder::setInternalData
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
Definition: WorkOrder.cpp:1318
Isis::TemplateList
Definition: TemplateList.h:35
ImportMapTemplateWorkOrder.h
QStringList
Isis::ImportMapTemplateWorkOrder::setupExecution
bool setupExecution()
Sets up the work order for execution.
Definition: ImportMapTemplateWorkOrder.cpp:110
Isis::Project::addTemplates
void addTemplates(TemplateList *templateFiles)
Add new templates to m_mapTemplates or m_regTemplates and update project item model.
Definition: Project.cpp:1113
Isis::Project
The main project for ipce.
Definition: Project.h:289
Isis::Project::directory
Directory * directory() const
Returns the directory associated with this Project.
Definition: Project.cpp:1229
Isis::FileName::expanded
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:196
Isis::WorkOrder::m_isUndoable
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
Isis::TemplateList::deleteFromDisk
void deleteFromDisk(Project *project)
Delete all of the contained Templates from disk.
Definition: TemplateList.cpp:143
Isis::Template
Definition: Template.h:30
Isis::WorkOrder::project
Project * project() const
Returns the Project this WorkOrder is attached to.
Definition: WorkOrder.cpp:1300
Isis::ProjectItemModel::findItemData
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...
Definition: ProjectItemModel.cpp:290
Isis::ImportMapTemplateWorkOrder::execute
void execute()
Imports the templates.
Definition: ImportMapTemplateWorkOrder.cpp:141
Isis::ImportMapTemplateWorkOrder::ImportMapTemplateWorkOrder
ImportMapTemplateWorkOrder(Project *project)
Creates a work order to import map templates.
Definition: ImportMapTemplateWorkOrder.cpp:42
Isis::ImportMapTemplateWorkOrder
Add map templates to a project.
Definition: ImportMapTemplateWorkOrder.h:41
Isis::WorkOrder::internalData
QStringList internalData() const
Gets the internal data for this WorkOrder.
Definition: WorkOrder.cpp:1377
Isis::WorkOrder::setModifiesDiskState
void setModifiesDiskState(bool changesProjectOnDisk)
Definition: WorkOrder.cpp:1674
Isis::Project::addTemplateFolder
QDir addTemplateFolder(QString prefix)
Create and navigate to the appropriate template type folder in the project directory.
Definition: Project.cpp:1134
Isis::ImportMapTemplateWorkOrder::~ImportMapTemplateWorkOrder
~ImportMapTemplateWorkOrder()
Destructor.
Definition: ImportMapTemplateWorkOrder.cpp:68
Isis::ImportMapTemplateWorkOrder::undoExecution
void undoExecution()
Deletes the previously imported templates.
Definition: ImportMapTemplateWorkOrder.cpp:170
Isis::Project::setClean
void setClean(bool value)
Function to change the clean state of the project.
Definition: Project.cpp:1595
Isis::ProjectItemModel::removeItem
virtual void removeItem(ProjectItem *item)
Removes an item and its children from the model.
Definition: ProjectItemModel.cpp:315
Isis::ImportMapTemplateWorkOrder::isExecutable
virtual bool isExecutable(ProjectItem *item)
This method returns true if the user clicked on a project tree node with the text "Maps".
Definition: ImportMapTemplateWorkOrder.cpp:93
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::ProjectItem
Represents an item of a ProjectItemModel in Qt's model-view framework.
Definition: ProjectItem.h:134