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

Added setModified and isModified mthods to keep track of the modification...

Added setModified and isModified mthods to keep track of the modification state of the control net. Added write method so that the state of the control net is known before writing to disk.
parent 9f8e2ab0
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ namespace Isis {
    m_controlNet = NULL;
    m_displayProperties = NULL;
    m_project = NULL;
    m_modified = false;

    try {
      openControlNet();
@@ -59,6 +60,7 @@ namespace Isis {
    m_controlNet = NULL;
    m_displayProperties = NULL;
    m_project = project;
    m_modified = false;

    m_displayProperties
        = new ControlDisplayProperties(FileName(m_fileName).name(), this);
@@ -82,6 +84,7 @@ namespace Isis {
    m_controlNet = controlNet;
    m_displayProperties = NULL;
    m_project = NULL;
    m_modified = false;

    m_displayProperties
        = new ControlDisplayProperties(FileName(m_fileName).name(), this);
@@ -103,6 +106,7 @@ namespace Isis {
    m_displayProperties = NULL;
    m_id = NULL;
    m_project = NULL;
    m_modified = false;

    xmlReader->pushContentHandler(new XmlHandler(this, cnetFolder));
  }
@@ -122,6 +126,9 @@ namespace Isis {
    //    destructor will take care of deleting the display props. See call to
    //    DisplayProperties' constructor.
    m_displayProperties = NULL;

    // TODO: If control net is modified, prompt for save before destroying??

  }


@@ -154,6 +161,7 @@ namespace Isis {
        if (m_project) {
          m_controlNet->SetMutex(m_project->mutex());
        }
        m_modified = false;

      }
      catch (IException &e) {
@@ -163,6 +171,32 @@ namespace Isis {
  }


  /**
   * @description Write control net to disk.  This method is used instead of calling 
   * ControlNet::Write directly so that Control knows the modification state of the control net. 
   *  
   * @return @b bool Returns false if there is not a control net open to write 
   *  
   * @throws IException::Programmer "Cannot write control net to disk" 
   */
  bool Control::write() {

    if (!m_controlNet) {
      return false;
    }

    try {
      m_controlNet->Write(fileName());
    }
    catch (IException &e) {
      throw IException(e, IException::Programmer, "Cannot write control net.", _FILEINFO_);
    }

    m_modified = false;
    return true;
  }


  /**
   * Cleans up the ControlNet pointer. This method should be called
   * once there is no more need for this network because the OS will limit
@@ -173,6 +207,31 @@ namespace Isis {
      delete m_controlNet;
      m_controlNet = NULL;
    }
    m_modified = false;
  }


  /**
   * @description Has this control been modified? 
   *  
   * @return @b bool Has this control been modified? 
   *  
   */
  bool Control::isModified() {
    return m_modified;
  }


  /**
   * @description Sets the modification state of this control. This is needed for now since many 
   * classes make changes to the control net contained in this object, but the control does not 
   * know the state of the control net. 
   * TODO:  Change this class to always know the state of the control Net.
   *  
   */
  void Control::setModified(bool modified) {
    
    m_modified = modified;
  }


@@ -256,6 +315,7 @@ namespace Isis {
    // If we're the last thing in the folder, remove the folder too.
    QDir dir;
    dir.rmdir(FileName(m_fileName).path());
    m_modified = false;
  }


+12 −1
Original line number Diff line number Diff line
@@ -67,6 +67,11 @@ namespace Isis {
   *                           to compare project roots. References #4804, #4849.
   *   @history 2018-01-19 Tracie Sucharski - Do not copy control unless the project root has
   *                           changed. References #5212.
   *   @history 2018-03-30 Tracie Sucharski - Added setModified and is Modified methods to keep
   *                           track of the modification state of the control net. Add write method
   *                           to write the control net to disk.  This write method should be called
   *                           by ipce classes instead of calling the ControlNet::Write directly so
   *                           that control knows the state of the control net.
   */
  class Control : public QObject {
    Q_OBJECT
@@ -87,6 +92,10 @@ namespace Isis {

      QString id() const;

      bool isModified();
      void setModified(bool modified = true);
      bool write();  

      void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const;
      void copyToNewProjectRoot(const Project *project, FileName newProjectRoot);
      void deleteFromDisk();
@@ -123,6 +132,8 @@ namespace Isis {
      Control(const Control &other);
      Control &operator=(const Control &rhs);

      bool m_modified;

      ControlDisplayProperties *m_displayProperties; /**< Contains the display properties for this
                                                          Control object.*/
      Project *m_project; //! Project associated with this control