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

Refactored RenameProjectWorkOrder to match new WorkOrder design. Fixes #4745....

Refactored RenameProjectWorkOrder to match new WorkOrder design.  Fixes #4745.  Added documenation to Footprint2DViewWorkOrder.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce_FY17-Sprint1@7566 41f8697f-d340-4b68-9986-7bafba869bb8
parent e3fe4cbc
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -51,7 +51,11 @@ namespace Isis {


  /**
   * @brief This method has not been implemented.
   * @brief Copy constructor.
   *
   * Creates a copy of the other Footprint2DViewWorkOrder.
   *
   * @param Footprint2DViewWorkOrder &other The other work order to copy state from.
   */
  Footprint2DViewWorkOrder::Footprint2DViewWorkOrder(const Footprint2DViewWorkOrder &other) :
      WorkOrder(other) {
@@ -60,7 +64,9 @@ namespace Isis {


  /**
   * @brief Destructor
   * @brief Destructor.
   *
   * Destructor to clean up any memory that this work order allocates.
   */
   Footprint2DViewWorkOrder::~Footprint2DViewWorkOrder() {
  }
+86 −5
Original line number Diff line number Diff line
/**
 * @file
 * $Revision: 1.19 $
 * $Date: 2010/03/22 19:44:53 $
 *
 *   Unless noted otherwise, the portions of Isis written by the USGS are
 *   public domain. See individual third-party library and package descriptions
@@ -34,11 +32,24 @@
#include "Project.h"

namespace Isis {

  /** 
   * Creates a work order to rename the project using the given new project name. This constructor 
   * is only called if user double-clicks the project name on the project tree.  This WorkOrder is 
   * undoable and runs synchronously. 
   * 
   * @param QString newName New project name 
   * @param Project *project Pointer to the project this work order belongs to.
   */
  RenameProjectWorkOrder::RenameProjectWorkOrder(QString newName, Project *project) :
      WorkOrder(project) {

    m_isUndoable = true;

    QAction::setText(tr("&Rename Project..."));
    QUndoCommand::setText(tr("Rename Project"));

    
    QStringList internalData;
    internalData.append(project->name());
    internalData.append(newName);
@@ -46,35 +57,84 @@ namespace Isis {
  }


  /** 
   * Creates a work order to rename the project. This WorkOrder is undoable and runs synchronously.
   * 
   * @param Project *project Pointer to the project this work order belongs to.
   */
  RenameProjectWorkOrder::RenameProjectWorkOrder(Project *project) :
      WorkOrder(project) {

    m_isUndoable = true;

    QAction::setText(tr("&Rename Project..."));
    QUndoCommand::setText(tr("Rename Project"));
  }


  /**
   * @brief Copy constructor.
   *
   * Creates a copy of the other RenameProjectWorkOrder.
   *
   * @param RenameProjectWorkOrder &other The other work order to copy state from.
   */
  RenameProjectWorkOrder::RenameProjectWorkOrder(const RenameProjectWorkOrder &other) :
      WorkOrder(other) {

    m_isUndoable = other.m_isUndoable;
  }


  /**
   * @brief Destructor.
   *
   * Destructor to clean up any memory that this work order allocates.
   */
  RenameProjectWorkOrder::~RenameProjectWorkOrder() {
  }


  /**
   * @brief This method clones the current RenameProjectWorkOrder and returns it.
   * 
   * @return @b Footprint2DViewWorkOrder that was cloned
   */
  RenameProjectWorkOrder *RenameProjectWorkOrder::clone() const {
    return new RenameProjectWorkOrder(*this);
  }


  /**
   * @brief 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. This is used by
   *              Directory::supportedActions(DataType data) to determine what actions are appended
   *              to context menus.
   * 
   * @param Context context This indicates whether this WorkOrder is  part of a Project.  Context is 
   *                an enum defined in WorkOrder with two possible values: NoContext,ProjectContext.
   * 
   * @return @b bool True if user selected 
   */
  bool RenameProjectWorkOrder::isExecutable(Context context) {
    return (context == ProjectContext);
  }


  /**
   * @brief Setup this WorkOrder for execution.  Prompt for new project name and make sure it is a 
   *              valid directory location.  This calls WorkOrder::setupExecution().
   * 
   * @return @b bool True if WorkOrder::execute() returns true and footprints can be created, 
   *         otherwise returns False.
   */
  bool RenameProjectWorkOrder::setupExecution() {
    bool success = WorkOrder::setupExecution();

    //  Prompt for new project name.  This will only happen if user initiated by right-clicking on
    //  project name from the project tree or selecting "Rename Project" from the Project menu.
    //  Otherwise, they double-clicked on the project name on the tree and entered a name through
    //  Qt's line edit.
    if (success && internalData().count() == 0) {
      QString newName;

@@ -96,7 +156,8 @@ namespace Isis {
      setInternalData(internalData);
    }

    QUndoCommand::setText(tr("Rename Project To [%1]").arg(internalData()[1]));
    QUndoCommand::setText(tr("Rename Project from [%1] to [%2]").
                          arg(internalData()[0]).arg(internalData()[1]));

    return success && (internalData()[1] != project()->name());
  }
@@ -111,18 +172,38 @@ namespace Isis {
  }


 /**
   * This WorkOrder is only dependent on another RenameProjectWorkOrder.  It cannot be run if 
   * another RenameProjectWorkOrder is currently being executed. 
   *        
   * @param other  The WorkOrder being checked for dependency.
   * @return @b bool  True if there is the other WorkOrder is another RenameProjectWorkOrder, False
   *         otherwise.
   */
  bool RenameProjectWorkOrder::dependsOn(WorkOrder *other) const {
    // depend on types of ourselves only.
    return dynamic_cast<RenameProjectWorkOrder *>(other);
  }


  void RenameProjectWorkOrder::syncRedo() {
  /**
   * @brief This will rename the project.
   *  
   */
  void RenameProjectWorkOrder::execute() {
    project()->setName(internalData()[1]);
  }


  void RenameProjectWorkOrder::syncUndo() {
  /**
   * @brief Changes the project name back to the old name.
   *
   * This will undo this WorkOrder's execute by renaming the project back to the old name.  The old
   * name was saved in the first internal data value.
   *
   * @see WorkOrder::undoExecution()
   */
  void RenameProjectWorkOrder::undoExecution() {
    project()->setName(internalData()[0]);
  }
}
+7 −7
Original line number Diff line number Diff line
@@ -2,8 +2,6 @@
#define RenameProjectWorkOrder_H
/**
 * @file
 * $Revision: 1.19 $
 * $Date: 2010/03/22 19:44:53 $
 *
 *   Unless noted otherwise, the portions of Isis written by the USGS are
 *   public domain. See individual third-party library and package descriptions
@@ -35,6 +33,9 @@ namespace Isis {
   *   @history 2012-12-19 Steven Lambright and Stuart Sides - Added isNameValid() and changed
   *                           execute() to return false if the project name isn't changing, so that
   *                           the work order is thrown away.
   *   @history 2017-04-12 Tracie Sucharski - Refactored to match new WorkOrder design, renaming
   *                           execute to setupExecution, syncUndo to execute, and syncUndo to
   *                           undoExecution. Fixes #4745.
   */
  class RenameProjectWorkOrder : public WorkOrder {
      Q_OBJECT
@@ -46,16 +47,15 @@ namespace Isis {

      virtual RenameProjectWorkOrder *clone() const;

      bool isExecutable(Context context);

      bool setupExecution();
      virtual bool isExecutable(Context context);
      virtual bool setupExecution();
      virtual void execute();

      static bool isNameValid(QString nameToCheck);

    protected:
      virtual void undoExecution();
      bool dependsOn(WorkOrder *other) const;
      void syncRedo();
      void syncUndo();

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