Isis 3 Programmer Reference
ImportRegistrationTemplateWorkOrder.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 Registration Templates..."));
49  QUndoCommand::setText(tr("Import Registration Templates..."));
51 
52  }
53 
54 
61  WorkOrder(other) {
62  }
63 
64 
69  m_list = NULL;
70  }
71 
72 
79  return new ImportRegistrationTemplateWorkOrder(*this);
80  }
81 
82 
94  QString itemType = item->text();
95  setInternalData(QStringList(itemType));
96 
97  return (itemType == "Registrations");
98  }
99 
100 
111 
113 
114  QStringList templateFileNames;
115 
116  templateFileNames = QFileDialog::getOpenFileNames(
117  qobject_cast<QWidget *>(parent()),
118  "Import Registration Templates",
119  QString(),
120  "Registrations (*.def);; 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("registrations/import");
143  QStringList templateFileNames = internalData();
144 
145  m_list = new TemplateList(templateFolder.dirName(),
146  "registrations",
147  "registrations/" + 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  "registrations",
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 }
$Date$ $Revision$
The main project for ipce.
Definition: Project.h:289
File name manipulation and expansion.
Definition: FileName.h:116
virtual bool setupExecution()
This sets up the state for the work order.
Definition: WorkOrder.cpp:1275
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition: FileName.cpp:178
ImportRegistrationTemplateWorkOrder(Project *project)
Creates a work order to import registration templates.
virtual bool isExecutable(ProjectItem *item)
This method returns true if the user clicked on a project tree node with the text "Registrations"...
virtual ImportRegistrationTemplateWorkOrder * clone() const
This method clones the current ImportRegistrationTemplateWorkOrder and returns it.
void addTemplates(TemplateList *templateFiles)
Add new templates to m_mapTemplates or m_regTemplates and update project item model.
Definition: Project.cpp:1113
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...
void deleteFromDisk(Project *project)
Delete all of the contained Templates from disk.
Directory * directory() const
Returns the directory associated with this Project.
Definition: Project.cpp:1229
bool setupExecution()
Sets up the work order for execution.
ProjectItemModel * model()
Gets the ProjectItemModel for this directory.
Definition: Directory.cpp:1105
Provide Undo/redo abilities, serialization, and history for an operation.
Definition: WorkOrder.h:322
void undoExecution()
Deletes the previously imported templates.
virtual void removeItem(ProjectItem *item)
Removes an item and its children from the model.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
bool m_isUndoable
Set the workorder to be undoable/redoable This is defaulted to true - his will allow the workorder to...
Definition: WorkOrder.h:534
void setModifiesDiskState(bool changesProjectOnDisk)
Definition: WorkOrder.cpp:1688
Represents an item of a ProjectItemModel in Qt&#39;s model-view framework.
Definition: ProjectItem.h:146
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Project * project() const
Returns the Project this WorkOrder is attached to.
Definition: WorkOrder.cpp:1314
QDir addTemplateFolder(QString prefix)
Create and navigate to the appropriate template type folder in the project directory.
Definition: Project.cpp:1134
QStringList internalData() const
Gets the internal data for this WorkOrder.
Definition: WorkOrder.cpp:1391
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
Definition: WorkOrder.cpp:1332
void setClean(bool value)
Function to change the clean state of the project.
Definition: Project.cpp:1595