Isis 3 Programmer Reference
RenameProjectWorkOrder.cpp
Go to the documentation of this file.
1 
21 #include "RenameProjectWorkOrder.h"
22 
23 #include <QtDebug>
24 
25 #include <QFileDialog>
26 #include <QInputDialog>
27 #include <QMessageBox>
28 
29 #include "Directory.h"
30 #include "MosaicSceneItem.h"
31 #include "MosaicSceneWidget.h"
32 #include "Project.h"
33 
34 namespace Isis {
35 
45  WorkOrder(project) {
46 
47  m_isUndoable = true;
48 
49  QAction::setText(tr("&Rename Project..."));
50  QUndoCommand::setText(tr("Rename Project"));
51 
52 
54  internalData.append(project->name());
55  internalData.append(newName);
57  }
58 
59 
66  WorkOrder(project) {
67 
68  m_isUndoable = true;
69 
70  QAction::setText(tr("&Rename Project..."));
71  QUndoCommand::setText(tr("Rename Project"));
72  }
73 
74 
83  WorkOrder(other) {
84 
85  m_isUndoable = other.m_isUndoable;
86  }
87 
88 
95  }
96 
97 
104  return new RenameProjectWorkOrder(*this);
105  }
106 
107 
120  return (context == ProjectContext);
121  }
122 
123 
132  bool success = WorkOrder::setupExecution();
133 
134  // Prompt for new project name. This will only happen if user initiated by right-clicking on
135  // project name from the project tree or selecting "Rename Project" from the Project menu.
136  // Otherwise, they double-clicked on the project name on the tree and entered a name through
137  // Qt's line edit.
138  if (success && internalData().count() == 0) {
139  QString newName;
140 
141  do {
142  newName = QInputDialog::getText(NULL, tr("Enter Project Name"),
143  tr("Please enter the new project name"), QLineEdit::Normal,
144  project()->name(), &success);
145 
146  if (success && !isNameValid(newName)) {
147  QMessageBox::critical(NULL, tr("Invalid Project Name"),
148  tr("Project name [%1] is not valid").arg(newName));
149  }
150  }
151  while (success && !isNameValid(newName));
152 
154  internalData.append(project()->name());
155  internalData.append(newName);
157  }
158 
159  QUndoCommand::setText(tr("Rename Project from [%1] to [%2]").
160  arg(internalData()[0]).arg(internalData()[1]));
161 
162  return success && (internalData()[1] != project()->name());
163  }
164 
165 
170  bool RenameProjectWorkOrder::isNameValid(QString nameToCheck) {
171  return !nameToCheck.isEmpty();
172  }
173 
174 
184  // depend on types of ourselves only.
185  return dynamic_cast<RenameProjectWorkOrder *>(other);
186  }
187 
188 
194  project()->setName(internalData()[1]);
195  project()->setClean(false);
196  }
197 
198 
208  project()->setName(internalData()[0]);
209  }
210 }
RenameProjectWorkOrder(QString newName, Project *project)
Creates a work order to rename the project using the given new project name.
The main project for ipce.
Definition: Project.h:289
virtual bool setupExecution()
This sets up the state for the work order.
Definition: WorkOrder.cpp:1275
virtual void undoExecution()
Changes the project name back to the old name.
static bool isNameValid(QString nameToCheck)
Check the validity of the given (proposed) project name.
virtual bool setupExecution()
Setup this WorkOrder for execution.
virtual RenameProjectWorkOrder * clone() const
This method clones the current RenameProjectWorkOrder and returns it.
bool dependsOn(WorkOrder *other) const
This WorkOrder is only dependent on another RenameProjectWorkOrder.
Provide Undo/redo abilities, serialization, and history for an operation.
Definition: WorkOrder.h:322
Change the project&#39;s GUI name.
virtual void execute()
This will rename the project.
virtual bool isExecutable(Context context)
This method returns true if the user clicked on the project name on the project tree, or selected "Rename Project" from the Project menu, otherwise False.
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
QString name() const
Get the project&#39;s GUI name.
Definition: Project.cpp:1625
void setName(QString newName)
Change the project&#39;s name (GUI only, doesn&#39;t affect location on disk).
Definition: Project.cpp:1684
Context
This enumeration is for recording the context of the current Workorder (whether it is part of a proje...
Definition: WorkOrder.h:350
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
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
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
void setClean(bool value)
Function to change the clean state of the project.
Definition: Project.cpp:1595