Isis 3 Programmer Reference
OpenProjectWorkOrder.cpp
Go to the documentation of this file.
1 
23 #include "OpenProjectWorkOrder.h"
24 
25 #include <QCoreApplication>
26 #include <QDebug>
27 #include <QFileDialog>
28 #include <QMessageBox>
29 #include <QStringList>
30 #include <QtConcurrentMap>
31 
32 #include "Cube.h"
33 #include "CubeAttribute.h"
34 #include "FileName.h"
35 #include "SaveProjectWorkOrder.h"
36 #include "ProgressBar.h"
37 #include "Project.h"
38 
39 
40 namespace Isis {
41 
48  WorkOrder(project) {
49 
50  // This workorder is not undoable
51  m_isUndoable = false;
52  QAction::setText(tr("&Open Project"));
53 
54  QUndoCommand::setText(tr("Open Project"));
56 
57  QStringList args = QCoreApplication::arguments();
58 
59 // if (args.count() == 2) {
60 // connect(this, SIGNAL(openProjectFromCommandLine(QString)),
61 // project, SLOT(open(QString)), Qt::QueuedConnection);
62 // emit openProjectFromCommandLine(args.last());
63 // project->open(args.last());
64 // }
65  }
66 
67 
68 
75  WorkOrder(other) {
76  }
77 
78 
83 
84  }
85 
86 
93  return new OpenProjectWorkOrder(*this);
94  }
95 
96 
97 
103  bool OpenProjectWorkOrder::isExecutable(QString projectFileName, bool recentProject) {
104 
105  m_recentProject = recentProject;
106  FileName fname = projectFileName;
107  if (!fname.fileExists() )
108  return false;
109 
110  return true;
111  }
112 
121 
122  bool success = WorkOrder::setupExecution();
123 
124  // We dislike the progress bar
125  delete progressBar();
126 
127  if (success && !project()->isClean() && project()->isOpen() ) {
128  QMessageBox *box = new QMessageBox(QMessageBox::NoIcon, QString("Current Project Has Unsaved Changes"),
129  QString("Would you like to save your current project?"),
130  NULL, qobject_cast<QWidget *>(parent()), Qt::Dialog);
131  QPushButton *save = box->addButton("Save", QMessageBox::AcceptRole);
132  QPushButton *dontsave = box->addButton("Don't Save", QMessageBox::RejectRole);
133  QPushButton *cancel = box->addButton("Cancel", QMessageBox::NoRole);
134  box->exec();
135 
136  if (box->clickedButton() == (QAbstractButton*)cancel) {
137  success = false;
138  }
139  else if (box->clickedButton() == (QAbstractButton*)dontsave) {
140  success = true;
141  }
142  else if (box->clickedButton() == (QAbstractButton*)save) {
144  project()->addToProject(workOrder);
145  }
146  }
147 
148  if (success) {
149  if ("Open Project" == toolTip()) {
150  m_projectPath = QFileDialog::getExistingDirectory(qobject_cast<QWidget *>(parent()),
151  tr("Select Project Directory"));
152  if (!m_projectPath.isEmpty()) {
153  QUndoCommand::setText(tr("Open Project [%1]").arg(m_projectPath));
154  }
155  else {
156  success = false;
157  }
158  }
159  else {
160  m_projectPath = toolTip();
161  }
162  }
163  else {
164  success = false;
165  }
166 
167  return success;
168  }
169 
170 
176  QStringList args = QCoreApplication::arguments();
177  if (args.count() == 2) {
178  project()->open(args.last());
179  }
180  else {
181  project()->open(m_projectPath);
182  }
183 
184  project()->setClean(true);
185 
186  }
187 }
SaveProjectWorkOrder.h
Isis::SaveProjectWorkOrder
Saves a project to disk (File->Save Project...)
Definition: SaveProjectWorkOrder.h:47
Isis::WorkOrder::setupExecution
virtual bool setupExecution()
This sets up the state for the work order.
Definition: WorkOrder.cpp:1261
OpenProjectWorkOrder.h
Isis::WorkOrder
Provide Undo/redo abilities, serialization, and history for an operation.
Definition: WorkOrder.h:311
Project.h
Isis::Project::open
void open(QString)
Open the project at the given path.
Definition: Project.cpp:1345
Isis::OpenProjectWorkOrder::setupExecution
bool setupExecution()
Setup this WorkOrder for execution, deleting the progress bar, determine if there is a current projec...
Definition: OpenProjectWorkOrder.cpp:120
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::FileName::fileExists
bool fileExists() const
Returns true if the file exists; false otherwise.
Definition: FileName.cpp:449
Isis::WorkOrder::save
void save(QXmlStreamWriter &stream) const
: Saves a WorkOrder to a data stream.
Definition: WorkOrder.cpp:544
Isis::OpenProjectWorkOrder::isExecutable
bool isExecutable(QString projectFileName, bool recentProject=false)
This function determines if the given project file name can be opened.
Definition: OpenProjectWorkOrder.cpp:103
Isis::OpenProjectWorkOrder::OpenProjectWorkOrder
OpenProjectWorkOrder(Project *project)
Constructs an OpenProjectWorkOrder.
Definition: OpenProjectWorkOrder.cpp:47
QStringList
Isis::Project
The main project for ipce.
Definition: Project.h:289
Isis::Project::addToProject
void addToProject(WorkOrder *)
This executes the WorkOrder and stores it in the project.
Definition: Project.cpp:2598
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::OpenProjectWorkOrder
This opens a project that's saved on disk.
Definition: OpenProjectWorkOrder.h:56
Isis::WorkOrder::project
Project * project() const
Returns the Project this WorkOrder is attached to.
Definition: WorkOrder.cpp:1300
Isis::OpenProjectWorkOrder::~OpenProjectWorkOrder
~OpenProjectWorkOrder()
Destructor.
Definition: OpenProjectWorkOrder.cpp:82
Isis::OpenProjectWorkOrder::execute
void execute()
Open the chosen project folder.
Definition: OpenProjectWorkOrder.cpp:175
Isis::WorkOrder::progressBar
ProgressBar * progressBar()
Returns the ProgressBar.
Definition: WorkOrder.cpp:975
Isis::WorkOrder::setCreatesCleanState
void setCreatesCleanState(bool createsCleanState)
Declare that this work order is saving the project.
Definition: WorkOrder.cpp:1663
Isis::OpenProjectWorkOrder::clone
virtual OpenProjectWorkOrder * clone() const
Clones the current OpenProjectWorkOrder.
Definition: OpenProjectWorkOrder.cpp:92
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