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 }
Isis::RenameProjectWorkOrder::RenameProjectWorkOrder
RenameProjectWorkOrder(QString newName, Project *project)
Creates a work order to rename the project using the given new project name.
Definition: RenameProjectWorkOrder.cpp:44
Isis::WorkOrder::setupExecution
virtual bool setupExecution()
This sets up the state for the work order.
Definition: WorkOrder.cpp:1261
RenameProjectWorkOrder.h
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Isis::WorkOrder
Provide Undo/redo abilities, serialization, and history for an operation.
Definition: WorkOrder.h:311
Project.h
Isis::RenameProjectWorkOrder
Change the project's GUI name.
Definition: RenameProjectWorkOrder.h:41
Isis::RenameProjectWorkOrder::isNameValid
static bool isNameValid(QString nameToCheck)
Check the validity of the given (proposed) project name.
Definition: RenameProjectWorkOrder.cpp:170
Isis::WorkOrder::setInternalData
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
Definition: WorkOrder.cpp:1318
Isis::RenameProjectWorkOrder::clone
virtual RenameProjectWorkOrder * clone() const
This method clones the current RenameProjectWorkOrder and returns it.
Definition: RenameProjectWorkOrder.cpp:103
Isis::RenameProjectWorkOrder::~RenameProjectWorkOrder
~RenameProjectWorkOrder()
Destructor.
Definition: RenameProjectWorkOrder.cpp:94
Isis::RenameProjectWorkOrder::dependsOn
bool dependsOn(WorkOrder *other) const
This WorkOrder is only dependent on another RenameProjectWorkOrder.
Definition: RenameProjectWorkOrder.cpp:183
QStringList
Isis::RenameProjectWorkOrder::setupExecution
virtual bool setupExecution()
Setup this WorkOrder for execution.
Definition: RenameProjectWorkOrder.cpp:131
Isis::Project
The main project for ipce.
Definition: Project.h:289
Isis::RenameProjectWorkOrder::undoExecution
virtual void undoExecution()
Changes the project name back to the old name.
Definition: RenameProjectWorkOrder.cpp:207
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::RenameProjectWorkOrder::isExecutable
virtual bool isExecutable(Context context)
This method returns true if the user clicked on the project name on the project tree,...
Definition: RenameProjectWorkOrder.cpp:119
Isis::RenameProjectWorkOrder::execute
virtual void execute()
This will rename the project.
Definition: RenameProjectWorkOrder.cpp:193
Isis::WorkOrder::project
Project * project() const
Returns the Project this WorkOrder is attached to.
Definition: WorkOrder.cpp:1300
Isis::Project::name
QString name() const
Get the project's GUI name.
Definition: Project.cpp:1625
Isis::Project::setName
void setName(QString newName)
Change the project's name (GUI only, doesn't affect location on disk).
Definition: Project.cpp:1684
Isis::WorkOrder::internalData
QStringList internalData() const
Gets the internal data for this WorkOrder.
Definition: WorkOrder.cpp:1377
Isis::WorkOrder::Context
Context
This enumeration is for recording the context of the current Workorder (whether it is part of a proje...
Definition: WorkOrder.h:339
Isis::Project::setClean
void setClean(bool value)
Function to change the clean state of the project.
Definition: Project.cpp:1595
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16