Commit f466f224 authored by Tracie Sucharski's avatar Tracie Sucharski
Browse files

Refactored OpenProjectWorkOrder for new WorkOrder design. This entailed a...

Refactored OpenProjectWorkOrder for new WorkOrder design.  This entailed a change to Project::addToProject, which needed to call child WorkOrder's execute even if clean state.  Fixes #4735.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce_FY17-Sprint1@7545 41f8697f-d340-4b68-9986-7bafba869bb8
parent af7042c5
Loading
Loading
Loading
Loading
+32 −17
Original line number Diff line number Diff line
@@ -36,30 +36,33 @@
namespace Isis {

  /**
   * Constructs an OpenProjectWorkOrder
   * @description Constructs an OpenProjectWorkOrder
   *
   * @param project The project 
   * @param project The project object
   */
  OpenProjectWorkOrder::OpenProjectWorkOrder(Project *project) :
      WorkOrder(project) {
    //qDebug()<<"OpenProjectWorkOrder::OpenProjectWorkOrder";

    // This workorder is not undoable
    m_isUndoable = false;

    QAction::setText(tr("&Open Project"));
    QUndoCommand::setText(tr("Open Project"));
    setCreatesCleanState(true);

    QStringList args = QCoreApplication::arguments();

    if (args.count() == 2) {
//    if (args.count() == 2) {
//    connect(this, SIGNAL(openProjectFromCommandLine(QString)),
//            project, SLOT(open(QString)), Qt::QueuedConnection);
//    emit openProjectFromCommandLine(args.last());
//    project->open(args.last());
    }
//    }
  }


  /**
   * Copy constructor
   * @description Copy constructor
   *
   * @param other The other OpenProjectWorkOrder to initialize from
   */
@@ -69,7 +72,7 @@ namespace Isis {


  /**
   * Destructor
   * @description Destructor
   */
  OpenProjectWorkOrder::~OpenProjectWorkOrder() {

@@ -77,9 +80,9 @@ namespace Isis {


  /**
   * Clones the current OpenProjectWorkOrder
   * @description Clones the current OpenProjectWorkOrder
   *
   * @return @b OpenProjectWorkOrder * The OpenProjectWorkOrder clone
   * @return @b (OpenProjectWorkOrder *) The OpenProjectWorkOrder clone
   */
  OpenProjectWorkOrder *OpenProjectWorkOrder::clone() const {
    return new OpenProjectWorkOrder(*this);
@@ -87,12 +90,14 @@ namespace Isis {


  /**
   * Executes the OpenProjectWorkOrder
   * @description Setup this WorkOrder for execution, deleting the progress bar, determine if there
   *              is a current project and if it has been modified and prompting for project
   *              directory.
   *
   * @return @b bool true if the successfully executed
   * @return @b bool True if the setup was successful, False otherwise.
   */
  bool OpenProjectWorkOrder::setupExecution() {
    //qDebug()<<"OpenProjectWorkOrder::execute()";

    bool success = WorkOrder::setupExecution();

    // We dislike the progress bar
@@ -101,16 +106,16 @@ namespace Isis {
    // If more than this work order is in the history, don't allow this operation
    if (success && project()->workOrderHistory().count()) {
      QMessageBox::critical(NULL, tr("Unable To Open a Project"),
                            tr("If you have modified your current project, you cannot open a new "
                               "project because this is not yet implemented"));
                            tr("Opening a new project is not implemented yet because there is no "
                               "checking for changes to the current open project."));
      success = false;
    }
    else if (success) {
      QString projectName = QFileDialog::getExistingDirectory(qobject_cast<QWidget *>(parent()),
      m_projectName = QFileDialog::getExistingDirectory(qobject_cast<QWidget *>(parent()),
                                                              tr("Select Project Directory"));

      if (!projectName.isEmpty()) {
        project()->open(projectName);
      if (!m_projectName.isEmpty()) {
        QUndoCommand::setText(tr("Open Project [%1]").arg(m_projectName));
      }
      else {
        success = false;
@@ -119,4 +124,14 @@ namespace Isis {

    return success;
  }


  /**
   * @description  Open the chosen project folder.
   * 
   */
  void OpenProjectWorkOrder::execute() {

    project()->open(m_projectName);
  }
}
+6 −0
Original line number Diff line number Diff line
@@ -40,6 +40,9 @@ namespace Isis {
   *                           Fixes #3952.
   *   @history 2017-03-28 Tracie Sucharski - Changed user prompt to indicating a directory is to
   *                           be selected, not a project file.
   *   @history 2017-04-06 Tracie Sucharski - Refactor for the new WorkOrder design, renaming
   *                           execute to setupExecution, and moving the actual work to the execute
   *                           method.
   */
  class OpenProjectWorkOrder : public WorkOrder {
      Q_OBJECT
@@ -51,12 +54,15 @@ namespace Isis {
      virtual OpenProjectWorkOrder *clone() const;

      bool setupExecution();
      void execute();

    signals:
      void openProjectFromCommandLine(QString);

    private:
      OpenProjectWorkOrder &operator=(const OpenProjectWorkOrder &rhs);

      QString m_projectName;
  };
}

+1 −1
Original line number Diff line number Diff line
@@ -38,12 +38,12 @@ namespace Isis {
   */
  SetActiveControlWorkOrder::SetActiveControlWorkOrder(Project *project) :
      WorkOrder(project) {

    // This workorder is not undoable
    m_isUndoable = false;

    QAction::setText(tr("Set Active Control Network") );
    QUndoCommand::setText(tr("Set Active Control Network"));

  }


+1 −0
Original line number Diff line number Diff line
@@ -1629,6 +1629,7 @@ namespace Isis {
        //   Instead, we tell the undo stack that we're now clean.
        if (workOrder->createsCleanState()) {
          m_undoStack.setClean();
          workOrder->execute();
        }
        // All other work orders go onto the undo stack, unless specifically told not to
        else if (workOrder->isUndoable()) {
+2 −0
Original line number Diff line number Diff line
@@ -119,6 +119,8 @@ namespace Isis {
   *   @history 2017-03-30 Tracie Sucharski - Cleaned up some documentation regarding last change. 
   *   @history 2017-04-04 Makayla Shepherd - Updated addToProject to support the new WorkOrder 
   *                           design. Fixes #4729.
   *   @history 2017-04-06 Tracie Sucharski - Added call to child WorkOrder::execute() even if it
   *                           a CleanState.
   */
  class Project : public QObject {
    Q_OBJECT