Commit dd3cf25c authored by Summer Stapleton's avatar Summer Stapleton
Browse files

Adding history comments and removing outdated workorder files

parent 0d3fe044
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -159,6 +159,9 @@ namespace Isis {
   *                           state can be reset after the IpceMainWindow::show() causes resize and
   *                           move events which in turn cause the project clean flag to be false
   *                           even though the project has just opened.
   *   @history 2018-07-07 Summer Stapleton - Added check in the closeEvent() for changes to any 
   *                           TemplateEditorWidget currently open to create a pop-up warning/
   *                           option to save.
   */
  class IpceMainWindow : public QMainWindow {
      Q_OBJECT
+2 −1
Original line number Diff line number Diff line
@@ -93,9 +93,10 @@ namespace Isis {
   *                           control point and loading a different control point. 
   *   @history 2018-06-11 Summer Stapleton - Stripped path from displayed filename of Control 
   *                           Network and set the tooltip to the full path for easier access.
   *                           control point and loading a different control point.
   *   @history 2018-06-19 Adam Goins - Fixed updating references in selectLeftMeasure and
   *                           selectRightMeasure to fix a segfault that was occuring. #Fixes #5435
   *   @history 2018-07-07 Summer Stapleton - Added a QComboBox to the widget to allow for changing
   *                           the active registration template from the widget itself.
   */
  class ControlPointEditWidget : public QWidget {
    Q_OBJECT
+2 −0
Original line number Diff line number Diff line
@@ -251,6 +251,8 @@ namespace Isis {
   *                           Fixes #5435.
   *   @history 2018-06-19 Adam Goins - Gave the ControlHealthMonitorView() a reference to the
   *                           directory instance rather than the activeControl. Fixes #5435.
   *   @history 2018-07-07 Summer Stapleton - Implemented changes to handle implementation of 
   *                           separate import work orders for both map and registration templates.
   *
   */
  class Directory : public QObject {
+0 −208
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
 *   for intellectual property information, user agreements, and related
 *   information.
 *
 *   Although Isis has been used by the USGS, no warranty, expressed or
 *   implied, is made by the USGS as to the accuracy and functioning of such
 *   software and related material nor shall the fact of distribution
 *   constitute any such warranty, and no responsibility is assumed by the
 *   USGS in connection therewith.
 *
 *   For additional information, launch
 *   $ISISROOT/doc//documents/Disclaimers/Disclaimers.html
 *   in a browser or see the Privacy & Disclaimers page on the Isis website,
 *   http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
 *   http://www.usgs.gov/privacy.html.
 */
#include "ImportTemplateWorkOrder.h"

#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QRegularExpression>
#include <QDebug>

#include "Project.h"
#include "ProjectItemModel.h"
#include "Template.h"
#include "TemplateList.h"

namespace Isis {
  /**
   * Creates a work order to import a template.
   *
   * @param *project Pointer to the project this work order belongs to
   */
  ImportTemplateWorkOrder::ImportTemplateWorkOrder(Project *project) :
      WorkOrder(project) {

    m_isUndoable = true;
    m_list = NULL;

    QAction::setText(tr("Import Template"));
    QUndoCommand::setText(tr("Import Template"));
    setModifiesDiskState(true);

  }


  /**
   * Creates a copy of the other ImportTemplateWorkOrder
   *
   * @param &other ImportTemplateWorkOrder to copy the state from
   */
  ImportTemplateWorkOrder::ImportTemplateWorkOrder(const ImportTemplateWorkOrder &other) :
      WorkOrder(other) {
  }


  /**
   * Destructor
   */
  ImportTemplateWorkOrder::~ImportTemplateWorkOrder() {
    m_list = NULL;
  }


  /**
   * This method clones the current ImportTemplateWorkOrder and returns it.
   *
   * @return ImportTemplateWorkOrder Clone
   */
  ImportTemplateWorkOrder *ImportTemplateWorkOrder::clone() const {
    return new ImportTemplateWorkOrder(*this);
  }


  /**
   * This method returns true if the user clicked on a project tree node with the text
   * "Templates".
   * This is used by Directory::supportedActions(DataType data) to determine what actions are
   * appended to context menus.
   *
   * @param item The ProjectItem that was clicked
   *
   * @return bool True if the user clicked on a project tree node named "Templates"
   */
  bool ImportTemplateWorkOrder::isExecutable(ProjectItem *item) {
    QString itemType = item->text();
    setInternalData(QStringList(itemType));

    return (itemType == "Maps" || itemType == "Registrations" || itemType == "Templates");
  }


  /**
   * @brief Sets up the work order for execution.
   *
   * This method prompts the user for a template to open.
   *
   * @see WorkOrder::setupExecution()
   *
   * @return bool Returns true if we have at least one template file name.
   */
  bool ImportTemplateWorkOrder::setupExecution() {
    WorkOrder::setupExecution();

    QString itemType;
    QString filterText =
        "Please select a file type;; Maps (*.def *.map *.pvl);; Registrations (*.def *.pvl)";

    // If clicked "File"->"Import"->"Import Templates"
    if (internalData().isEmpty()) {
      itemType = "Templates";
    }
    // If clicked "Import Templates" from under "Maps" or "Registrations" ProjectItems rightclicks
    else {
      itemType = internalData().at(0);

      if (itemType == "Maps") { filterText = "Maps (*.def *.map *.pvl)"; }
      else if (itemType == "Registrations") { filterText = "Registrations (*.def *.pvl)"; }

      internalData().clear();
    }

    QString selectedFilter;
    QStringList templateFileNames;

    templateFileNames = QFileDialog::getOpenFileNames(
        qobject_cast<QWidget *>(parent()),
        "Import " + itemType,
        QString(),
        filterText,
        &selectedFilter);

    if (!templateFileNames.isEmpty() && !selectedFilter.isEmpty()) {
      QUndoCommand::setText(tr("Import %1 Template(s)").arg(templateFileNames.count()));
    }
    else {
      return false;
    }

    // The user must choose a filter to import any file. The type is saved in m_fileType
    // Currently, the only options for this will be "maps" and "registrations"
    m_fileType = selectedFilter.remove(QRegularExpression(" \\(.*\\)")).toLower();
    setInternalData(templateFileNames);

    return true;
  }


  /**
   * @brief Imports the templates
   *
   * This method copies the template files into the appropriate directory according to the
   * chosen filter from setupExecution's QFileDialog. If the file already exists in the chosen
   * directory, it will not be copied over.
   */
  void ImportTemplateWorkOrder::execute() {
    QDir templateFolder = project()->addTemplateFolder(m_fileType + "/import");
    QStringList templateFileNames = internalData();

    m_list = new TemplateList(templateFolder.dirName(), 
                              m_fileType, 
                              m_fileType + "/" + templateFolder.dirName() );

    foreach (FileName filename, templateFileNames) {
      QFile::copy(filename.expanded(), templateFolder.path() + "/" + filename.name());
      m_list->append(new Template(templateFolder.path() + "/" + filename.name(), 
                                  m_fileType, 
                                  templateFolder.dirName()));
    }

    if (!m_list->isEmpty()) {
     project()->addTemplates(m_list);
     project()->setClean(false);
    }


  }


  /**
   * @brief Deletes the previously imported templates
   *
   * This method deletes the templates from both the directory they were copied to
   * and the ProjectItemModel
   */
  void ImportTemplateWorkOrder::undoExecution() {
    if (m_list && project()->templates().size() > 0) {
      m_list->deleteFromDisk( project() );
      ProjectItem *currentItem =
          project()->directory()->model()->findItemData(QVariant::fromValue(m_list));
      project()->directory()->model()->removeItem(currentItem);
    }
    foreach ( Template *currentTemplate, *m_list) {
      delete currentTemplate;
    }
    delete m_list;
    m_list = NULL;
  }

}
+0 −66
Original line number Diff line number Diff line
#ifndef ImportTemplateWorkOrder_H
#define ImportTemplateWorkOrder_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
 *   for intellectual property information, user agreements, and related
 *   information.
 *
 *   Although Isis has been used by the USGS, no warranty, expressed or
 *   implied, is made by the USGS as to the accuracy and functioning of such
 *   software and related material nor shall the fact of distribution
 *   constitute any such warranty, and no responsibility is assumed by the
 *   USGS in connection therewith.
 *
 *   For additional information, launch
 *   $ISISROOT/doc//documents/Disclaimers/Disclaimers.html
 *   in a browser or see the Privacy &amp; Disclaimers page on the Isis website,
 *   http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
 *   http://www.usgs.gov/privacy.html.
 */
 #include "WorkOrder.h"
 #include "ProjectItem.h"
 #include "Template.h"
 #include "TemplateList.h"

 namespace Isis {
   /**
    * @brief Add templates to a project
    *
    * Asks the user for a template and its type and copies it into the project.
    *
    * @author 2017-07-31 Christopher Combs
    *
    * @internal
    *   @history 2017-08-23 Tracie Sucharski - Fixed assignment to itemType in setupExecution to use
    *                          assignment operator rather than comparison operator.
    *   @history 2017-11-03 Christopher Combs - Added support for new Template and TemplateList
    *                          classes. Fixes #5117.
    */
    class ImportTemplateWorkOrder : public WorkOrder {
        Q_OBJECT
      public:
        ImportTemplateWorkOrder(Project *project);
        ImportTemplateWorkOrder(const ImportTemplateWorkOrder &other);
        ~ImportTemplateWorkOrder();

        virtual ImportTemplateWorkOrder *clone() const;

        virtual bool isExecutable(ProjectItem *item);
        bool setupExecution();
        void execute();
        void undoExecution();

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

        TemplateList *m_list;
        QString m_fileType; //!< The file type filter chosen in the QFileDialog
    };
 }

 #endif
Loading