Loading isis/src/qisis/objs/Directory/Directory.cpp +8 −18 Original line number Diff line number Diff line Loading @@ -74,7 +74,8 @@ #include "ImportControlNetWorkOrder.h" #include "ImportImagesWorkOrder.h" #include "ImportShapesWorkOrder.h" #include "ImportTemplateWorkOrder.h" #include "ImportMapTemplateWorkOrder.h" #include "ImportRegistrationTemplateWorkOrder.h" #include "JigsawWorkOrder.h" #include "MatrixSceneWidget.h" #include "MatrixViewWorkOrder.h" Loading Loading @@ -169,7 +170,8 @@ namespace Isis { m_importControlNetWorkOrder = createWorkOrder<ImportControlNetWorkOrder>(); m_importImagesWorkOrder = createWorkOrder<ImportImagesWorkOrder>(); m_importShapesWorkOrder = createWorkOrder<ImportShapesWorkOrder>(); m_importTemplateWorkOrder = createWorkOrder<ImportTemplateWorkOrder>(); m_importMapTemplateWorkOrder = createWorkOrder<ImportMapTemplateWorkOrder>(); m_importRegistrationTemplateWorkOrder = createWorkOrder<ImportRegistrationTemplateWorkOrder>(); m_openProjectWorkOrder = createWorkOrder<OpenProjectWorkOrder>(); m_saveProjectWorkOrder = createWorkOrder<SaveProjectWorkOrder>(); m_saveProjectAsWorkOrder = createWorkOrder<SaveProjectAsWorkOrder>(); Loading Loading @@ -444,7 +446,10 @@ namespace Isis { importMenu->addAction(m_importControlNetWorkOrder->clone() ); importMenu->addAction(m_importImagesWorkOrder->clone() ); importMenu->addAction(m_importShapesWorkOrder->clone() ); importMenu->addAction(m_importTemplateWorkOrder->clone() ); QMenu *importTemplateMenu = importMenu->addMenu("&Import Templates"); importTemplateMenu->addAction(m_importMapTemplateWorkOrder->clone() ); importTemplateMenu->addAction(m_importRegistrationTemplateWorkOrder->clone() ); QMenu *exportMenu = fileMenu->addMenu("&Export"); Loading Loading @@ -903,9 +908,6 @@ namespace Isis { connect( result, SIGNAL( destroyed(QObject *) ), this, SLOT( cleanupMatrixViewWidgets(QObject *) ) ); connect(result, SIGNAL(windowChangeEvent(bool)), m_project, SLOT(setClean(bool))); m_matrixViewWidgets.append(result); result->setWindowTitle( tr("Matrix View %1").arg( m_matrixViewWidgets.count() ) ); Loading @@ -927,9 +929,6 @@ namespace Isis { connect( result, SIGNAL( destroyed(QObject *) ), this, SLOT( cleanupTargetInfoWidgets(QObject *) ) ); connect(result, SIGNAL(windowChangeEvent(bool)), m_project, SLOT(setClean(bool))); m_targetInfoWidgets.append(result); result->setWindowTitle( tr("%1").arg(target->displayProperties()->displayName() ) ); Loading @@ -951,9 +950,6 @@ namespace Isis { connect( result, SIGNAL( destroyed(QObject *) ), this, SLOT( cleanupTemplateEditorWidgets(QObject *) ) ); connect(result, SIGNAL(windowChangeEvent(bool)), m_project, SLOT(setClean(bool))); m_templateEditorWidgets.append(result); result->setWindowTitle( tr("%1").arg( FileName(currentTemplate->fileName()).name() ) ); Loading @@ -975,9 +971,6 @@ namespace Isis { connect( result, SIGNAL( destroyed(QObject *) ), this, SLOT( cleanupSensorInfoWidgets(QObject *) ) ); connect(result, SIGNAL(windowChangeEvent(bool)), m_project, SLOT(setClean(bool))); m_sensorInfoWidgets.append(result); result->setWindowTitle( tr("%1").arg(camera->displayProperties()->displayName() ) ); Loading @@ -1000,9 +993,6 @@ namespace Isis { connect( result, SIGNAL( destroyed(QObject *) ), this, SLOT( cleanupFileListWidgets(QObject *) ) ); connect(result, SIGNAL(windowChangeEvent(bool)), m_project, SLOT(setClean(bool))); m_fileListWidgets.append(result); result->setWindowTitle( tr("File List %1").arg( m_fileListWidgets.count() ) ); Loading isis/src/qisis/objs/Directory/Directory.h +2 −1 Original line number Diff line number Diff line Loading @@ -498,7 +498,8 @@ namespace Isis { QPointer<WorkOrder> m_saveProjectAsWorkOrder; //!< The Save Project As WorkOrder. QPointer<WorkOrder> m_openRecentProjectWorkOrder; //!< The Open Recent Project WorkOrder. QPointer<WorkOrder> m_closeProjectWorkOrder; //!< The Close Project WorkOrder QPointer<WorkOrder> m_importTemplateWorkOrder; //!< The Import Template WorkOrder QPointer<WorkOrder> m_importMapTemplateWorkOrder; //!< The Import Map Template WorkOrder QPointer<WorkOrder> m_importRegistrationTemplateWorkOrder; //!< The Import Registration Template WorkOrder QPointer<WorkOrder> m_runJigsawWorkOrder; //!< The Run Jigsaw WorkOrder QPointer<WorkOrder> m_renameProjectWorkOrder; //!< The Rename Project WorkOrder Loading isis/src/qisis/objs/Directory/ImportMapTemplateWorkOrder.cpp 0 → 100644 +184 −0 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 "ImportMapTemplateWorkOrder.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 map templates. * * @param *project Pointer to the project this work order belongs to */ ImportMapTemplateWorkOrder::ImportMapTemplateWorkOrder(Project *project) : WorkOrder(project) { m_isUndoable = true; m_list = NULL; QAction::setText(tr("Import Map Templates")); QUndoCommand::setText(tr("Import Map Templates")); setModifiesDiskState(true); } /** * Creates a copy of the other ImportMapTemplateWorkOrder * * @param &other ImportMapTemplateWorkOrder to copy the state from */ ImportMapTemplateWorkOrder::ImportMapTemplateWorkOrder(const ImportMapTemplateWorkOrder &other) : WorkOrder(other) { } /** * Destructor */ ImportMapTemplateWorkOrder::~ImportMapTemplateWorkOrder() { m_list = NULL; } /** * This method clones the current ImportMapTemplateWorkOrder and returns it. * * @return ImportMapTemplateWorkOrder Clone */ ImportMapTemplateWorkOrder *ImportMapTemplateWorkOrder::clone() const { return new ImportMapTemplateWorkOrder(*this); } /** * This method returns true if the user clicked on a project tree node with the text * "Maps". * 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 "Maps" */ bool ImportMapTemplateWorkOrder::isExecutable(ProjectItem *item) { QString itemType = item->text(); setInternalData(QStringList(itemType)); return (itemType == "Maps"); } /** * @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 ImportMapTemplateWorkOrder::setupExecution() { WorkOrder::setupExecution(); QStringList templateFileNames; templateFileNames = QFileDialog::getOpenFileNames( qobject_cast<QWidget *>(parent()), "Import Map Templates", QString(), "Maps (*.def *.map *.pvl);; All Files (*)"); if (!templateFileNames.isEmpty()) { QUndoCommand::setText(tr("Import %1 Template(s)").arg(templateFileNames.count())); } else { return false; } setInternalData(templateFileNames); return true; } /** * @brief Imports the templates * * This method copies the template files into the appropriate directory. If the file already * exists in the chosen directory, it will not be copied over. */ void ImportMapTemplateWorkOrder::execute() { QDir templateFolder = project()->addTemplateFolder("maps/import"); QStringList templateFileNames = internalData(); m_list = new TemplateList(templateFolder.dirName(), "maps", "maps/" + templateFolder.dirName() ); foreach (FileName filename, templateFileNames) { QFile::copy(filename.expanded(), templateFolder.path() + "/" + filename.name()); m_list->append(new Template(templateFolder.path() + "/" + filename.name(), "maps", templateFolder.dirName())); } if (!m_list->isEmpty()) { project()->addMapTemplates(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 ImportMapTemplateWorkOrder::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; } } isis/src/qisis/objs/Directory/ImportMapTemplateWorkOrder.h 0 → 100644 +60 −0 Original line number Diff line number Diff line #ifndef ImportMapTemplateWorkOrder_H #define ImportMapTemplateWorkOrder_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 & 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 map templates to a project * * Asks the user for a map template and copies it into the project. * * @author 2018-07-05 Summer Stapleton * */ class ImportMapTemplateWorkOrder : public WorkOrder { Q_OBJECT public: ImportMapTemplateWorkOrder(Project *project); ImportMapTemplateWorkOrder(const ImportMapTemplateWorkOrder &other); ~ImportMapTemplateWorkOrder(); virtual ImportMapTemplateWorkOrder *clone() const; virtual bool isExecutable(ProjectItem *item); bool setupExecution(); void execute(); void undoExecution(); private: ImportMapTemplateWorkOrder &operator=(const ImportMapTemplateWorkOrder &rhs); TemplateList *m_list; }; } #endif isis/src/qisis/objs/Directory/ImportRegistrationTemplateWorkOrder.cpp 0 → 100644 +185 −0 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 "ImportRegistrationTemplateWorkOrder.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 registration templates. * * @param *project Pointer to the project this work order belongs to */ ImportRegistrationTemplateWorkOrder::ImportRegistrationTemplateWorkOrder(Project *project) : WorkOrder(project) { m_isUndoable = true; m_list = NULL; QAction::setText(tr("Import Registration Templates")); QUndoCommand::setText(tr("Import Registration Templates")); setModifiesDiskState(true); } /** * Creates a copy of the other ImportRegistrationTemplateWorkOrder * * @param &other ImportRegistrationTemplateWorkOrder to copy the state from */ ImportRegistrationTemplateWorkOrder::ImportRegistrationTemplateWorkOrder(const ImportRegistrationTemplateWorkOrder &other) : WorkOrder(other) { } /** * Destructor */ ImportRegistrationTemplateWorkOrder::~ImportRegistrationTemplateWorkOrder() { m_list = NULL; } /** * This method clones the current ImportRegistrationTemplateWorkOrder and returns it. * * @return ImportRegistrationTemplateWorkOrder Clone */ ImportRegistrationTemplateWorkOrder *ImportRegistrationTemplateWorkOrder::clone() const { return new ImportRegistrationTemplateWorkOrder(*this); } /** * This method returns true if the user clicked on a project tree node with the text * "Registrations". * 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 "Registrations" */ bool ImportRegistrationTemplateWorkOrder::isExecutable(ProjectItem *item) { QString itemType = item->text(); setInternalData(QStringList(itemType)); return (itemType == "Registrations"); } /** * @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 ImportRegistrationTemplateWorkOrder::setupExecution() { WorkOrder::setupExecution(); QStringList templateFileNames; templateFileNames = QFileDialog::getOpenFileNames( qobject_cast<QWidget *>(parent()), "Import Registration Templates", QString(), "Registrations (*.def *.pvl);; All Files (*)"); if (!templateFileNames.isEmpty()) { QUndoCommand::setText(tr("Import %1 Template(s)").arg(templateFileNames.count())); } else { return false; } setInternalData(templateFileNames); return true; } /** * @brief Imports the templates * * This method copies the template files into the appropriate directory. If the file already * exists in the chosen directory, it will not be copied over. */ void ImportRegistrationTemplateWorkOrder::execute() { QDir templateFolder = project()->addTemplateFolder("registrations/import"); QStringList templateFileNames = internalData(); m_list = new TemplateList(templateFolder.dirName(), "registrations", "registrations/" + templateFolder.dirName() ); foreach (FileName filename, templateFileNames) { QFile::copy(filename.expanded(), templateFolder.path() + "/" + filename.name()); m_list->append(new Template(templateFolder.path() + "/" + filename.name(), "registrations", templateFolder.dirName())); } if (!m_list->isEmpty()) { project()->addRegTemplates(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 ImportRegistrationTemplateWorkOrder::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; } } Loading
isis/src/qisis/objs/Directory/Directory.cpp +8 −18 Original line number Diff line number Diff line Loading @@ -74,7 +74,8 @@ #include "ImportControlNetWorkOrder.h" #include "ImportImagesWorkOrder.h" #include "ImportShapesWorkOrder.h" #include "ImportTemplateWorkOrder.h" #include "ImportMapTemplateWorkOrder.h" #include "ImportRegistrationTemplateWorkOrder.h" #include "JigsawWorkOrder.h" #include "MatrixSceneWidget.h" #include "MatrixViewWorkOrder.h" Loading Loading @@ -169,7 +170,8 @@ namespace Isis { m_importControlNetWorkOrder = createWorkOrder<ImportControlNetWorkOrder>(); m_importImagesWorkOrder = createWorkOrder<ImportImagesWorkOrder>(); m_importShapesWorkOrder = createWorkOrder<ImportShapesWorkOrder>(); m_importTemplateWorkOrder = createWorkOrder<ImportTemplateWorkOrder>(); m_importMapTemplateWorkOrder = createWorkOrder<ImportMapTemplateWorkOrder>(); m_importRegistrationTemplateWorkOrder = createWorkOrder<ImportRegistrationTemplateWorkOrder>(); m_openProjectWorkOrder = createWorkOrder<OpenProjectWorkOrder>(); m_saveProjectWorkOrder = createWorkOrder<SaveProjectWorkOrder>(); m_saveProjectAsWorkOrder = createWorkOrder<SaveProjectAsWorkOrder>(); Loading Loading @@ -444,7 +446,10 @@ namespace Isis { importMenu->addAction(m_importControlNetWorkOrder->clone() ); importMenu->addAction(m_importImagesWorkOrder->clone() ); importMenu->addAction(m_importShapesWorkOrder->clone() ); importMenu->addAction(m_importTemplateWorkOrder->clone() ); QMenu *importTemplateMenu = importMenu->addMenu("&Import Templates"); importTemplateMenu->addAction(m_importMapTemplateWorkOrder->clone() ); importTemplateMenu->addAction(m_importRegistrationTemplateWorkOrder->clone() ); QMenu *exportMenu = fileMenu->addMenu("&Export"); Loading Loading @@ -903,9 +908,6 @@ namespace Isis { connect( result, SIGNAL( destroyed(QObject *) ), this, SLOT( cleanupMatrixViewWidgets(QObject *) ) ); connect(result, SIGNAL(windowChangeEvent(bool)), m_project, SLOT(setClean(bool))); m_matrixViewWidgets.append(result); result->setWindowTitle( tr("Matrix View %1").arg( m_matrixViewWidgets.count() ) ); Loading @@ -927,9 +929,6 @@ namespace Isis { connect( result, SIGNAL( destroyed(QObject *) ), this, SLOT( cleanupTargetInfoWidgets(QObject *) ) ); connect(result, SIGNAL(windowChangeEvent(bool)), m_project, SLOT(setClean(bool))); m_targetInfoWidgets.append(result); result->setWindowTitle( tr("%1").arg(target->displayProperties()->displayName() ) ); Loading @@ -951,9 +950,6 @@ namespace Isis { connect( result, SIGNAL( destroyed(QObject *) ), this, SLOT( cleanupTemplateEditorWidgets(QObject *) ) ); connect(result, SIGNAL(windowChangeEvent(bool)), m_project, SLOT(setClean(bool))); m_templateEditorWidgets.append(result); result->setWindowTitle( tr("%1").arg( FileName(currentTemplate->fileName()).name() ) ); Loading @@ -975,9 +971,6 @@ namespace Isis { connect( result, SIGNAL( destroyed(QObject *) ), this, SLOT( cleanupSensorInfoWidgets(QObject *) ) ); connect(result, SIGNAL(windowChangeEvent(bool)), m_project, SLOT(setClean(bool))); m_sensorInfoWidgets.append(result); result->setWindowTitle( tr("%1").arg(camera->displayProperties()->displayName() ) ); Loading @@ -1000,9 +993,6 @@ namespace Isis { connect( result, SIGNAL( destroyed(QObject *) ), this, SLOT( cleanupFileListWidgets(QObject *) ) ); connect(result, SIGNAL(windowChangeEvent(bool)), m_project, SLOT(setClean(bool))); m_fileListWidgets.append(result); result->setWindowTitle( tr("File List %1").arg( m_fileListWidgets.count() ) ); Loading
isis/src/qisis/objs/Directory/Directory.h +2 −1 Original line number Diff line number Diff line Loading @@ -498,7 +498,8 @@ namespace Isis { QPointer<WorkOrder> m_saveProjectAsWorkOrder; //!< The Save Project As WorkOrder. QPointer<WorkOrder> m_openRecentProjectWorkOrder; //!< The Open Recent Project WorkOrder. QPointer<WorkOrder> m_closeProjectWorkOrder; //!< The Close Project WorkOrder QPointer<WorkOrder> m_importTemplateWorkOrder; //!< The Import Template WorkOrder QPointer<WorkOrder> m_importMapTemplateWorkOrder; //!< The Import Map Template WorkOrder QPointer<WorkOrder> m_importRegistrationTemplateWorkOrder; //!< The Import Registration Template WorkOrder QPointer<WorkOrder> m_runJigsawWorkOrder; //!< The Run Jigsaw WorkOrder QPointer<WorkOrder> m_renameProjectWorkOrder; //!< The Rename Project WorkOrder Loading
isis/src/qisis/objs/Directory/ImportMapTemplateWorkOrder.cpp 0 → 100644 +184 −0 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 "ImportMapTemplateWorkOrder.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 map templates. * * @param *project Pointer to the project this work order belongs to */ ImportMapTemplateWorkOrder::ImportMapTemplateWorkOrder(Project *project) : WorkOrder(project) { m_isUndoable = true; m_list = NULL; QAction::setText(tr("Import Map Templates")); QUndoCommand::setText(tr("Import Map Templates")); setModifiesDiskState(true); } /** * Creates a copy of the other ImportMapTemplateWorkOrder * * @param &other ImportMapTemplateWorkOrder to copy the state from */ ImportMapTemplateWorkOrder::ImportMapTemplateWorkOrder(const ImportMapTemplateWorkOrder &other) : WorkOrder(other) { } /** * Destructor */ ImportMapTemplateWorkOrder::~ImportMapTemplateWorkOrder() { m_list = NULL; } /** * This method clones the current ImportMapTemplateWorkOrder and returns it. * * @return ImportMapTemplateWorkOrder Clone */ ImportMapTemplateWorkOrder *ImportMapTemplateWorkOrder::clone() const { return new ImportMapTemplateWorkOrder(*this); } /** * This method returns true if the user clicked on a project tree node with the text * "Maps". * 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 "Maps" */ bool ImportMapTemplateWorkOrder::isExecutable(ProjectItem *item) { QString itemType = item->text(); setInternalData(QStringList(itemType)); return (itemType == "Maps"); } /** * @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 ImportMapTemplateWorkOrder::setupExecution() { WorkOrder::setupExecution(); QStringList templateFileNames; templateFileNames = QFileDialog::getOpenFileNames( qobject_cast<QWidget *>(parent()), "Import Map Templates", QString(), "Maps (*.def *.map *.pvl);; All Files (*)"); if (!templateFileNames.isEmpty()) { QUndoCommand::setText(tr("Import %1 Template(s)").arg(templateFileNames.count())); } else { return false; } setInternalData(templateFileNames); return true; } /** * @brief Imports the templates * * This method copies the template files into the appropriate directory. If the file already * exists in the chosen directory, it will not be copied over. */ void ImportMapTemplateWorkOrder::execute() { QDir templateFolder = project()->addTemplateFolder("maps/import"); QStringList templateFileNames = internalData(); m_list = new TemplateList(templateFolder.dirName(), "maps", "maps/" + templateFolder.dirName() ); foreach (FileName filename, templateFileNames) { QFile::copy(filename.expanded(), templateFolder.path() + "/" + filename.name()); m_list->append(new Template(templateFolder.path() + "/" + filename.name(), "maps", templateFolder.dirName())); } if (!m_list->isEmpty()) { project()->addMapTemplates(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 ImportMapTemplateWorkOrder::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; } }
isis/src/qisis/objs/Directory/ImportMapTemplateWorkOrder.h 0 → 100644 +60 −0 Original line number Diff line number Diff line #ifndef ImportMapTemplateWorkOrder_H #define ImportMapTemplateWorkOrder_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 & 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 map templates to a project * * Asks the user for a map template and copies it into the project. * * @author 2018-07-05 Summer Stapleton * */ class ImportMapTemplateWorkOrder : public WorkOrder { Q_OBJECT public: ImportMapTemplateWorkOrder(Project *project); ImportMapTemplateWorkOrder(const ImportMapTemplateWorkOrder &other); ~ImportMapTemplateWorkOrder(); virtual ImportMapTemplateWorkOrder *clone() const; virtual bool isExecutable(ProjectItem *item); bool setupExecution(); void execute(); void undoExecution(); private: ImportMapTemplateWorkOrder &operator=(const ImportMapTemplateWorkOrder &rhs); TemplateList *m_list; }; } #endif
isis/src/qisis/objs/Directory/ImportRegistrationTemplateWorkOrder.cpp 0 → 100644 +185 −0 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 "ImportRegistrationTemplateWorkOrder.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 registration templates. * * @param *project Pointer to the project this work order belongs to */ ImportRegistrationTemplateWorkOrder::ImportRegistrationTemplateWorkOrder(Project *project) : WorkOrder(project) { m_isUndoable = true; m_list = NULL; QAction::setText(tr("Import Registration Templates")); QUndoCommand::setText(tr("Import Registration Templates")); setModifiesDiskState(true); } /** * Creates a copy of the other ImportRegistrationTemplateWorkOrder * * @param &other ImportRegistrationTemplateWorkOrder to copy the state from */ ImportRegistrationTemplateWorkOrder::ImportRegistrationTemplateWorkOrder(const ImportRegistrationTemplateWorkOrder &other) : WorkOrder(other) { } /** * Destructor */ ImportRegistrationTemplateWorkOrder::~ImportRegistrationTemplateWorkOrder() { m_list = NULL; } /** * This method clones the current ImportRegistrationTemplateWorkOrder and returns it. * * @return ImportRegistrationTemplateWorkOrder Clone */ ImportRegistrationTemplateWorkOrder *ImportRegistrationTemplateWorkOrder::clone() const { return new ImportRegistrationTemplateWorkOrder(*this); } /** * This method returns true if the user clicked on a project tree node with the text * "Registrations". * 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 "Registrations" */ bool ImportRegistrationTemplateWorkOrder::isExecutable(ProjectItem *item) { QString itemType = item->text(); setInternalData(QStringList(itemType)); return (itemType == "Registrations"); } /** * @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 ImportRegistrationTemplateWorkOrder::setupExecution() { WorkOrder::setupExecution(); QStringList templateFileNames; templateFileNames = QFileDialog::getOpenFileNames( qobject_cast<QWidget *>(parent()), "Import Registration Templates", QString(), "Registrations (*.def *.pvl);; All Files (*)"); if (!templateFileNames.isEmpty()) { QUndoCommand::setText(tr("Import %1 Template(s)").arg(templateFileNames.count())); } else { return false; } setInternalData(templateFileNames); return true; } /** * @brief Imports the templates * * This method copies the template files into the appropriate directory. If the file already * exists in the chosen directory, it will not be copied over. */ void ImportRegistrationTemplateWorkOrder::execute() { QDir templateFolder = project()->addTemplateFolder("registrations/import"); QStringList templateFileNames = internalData(); m_list = new TemplateList(templateFolder.dirName(), "registrations", "registrations/" + templateFolder.dirName() ); foreach (FileName filename, templateFileNames) { QFile::copy(filename.expanded(), templateFolder.path() + "/" + filename.name()); m_list->append(new Template(templateFolder.path() + "/" + filename.name(), "registrations", templateFolder.dirName())); } if (!m_list->isEmpty()) { project()->addRegTemplates(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 ImportRegistrationTemplateWorkOrder::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; } }