Commit a4576d9d authored by Christopher Combs's avatar Christopher Combs
Browse files

Added serialization of CnetEditorWidgets to the ipce project. Fixes #4989

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce@7978 41f8697f-d340-4b68-9986-7bafba869bb8
parent b0809d78
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -601,7 +601,7 @@ namespace Isis {
      QString currentFile = *curFile;
      closeNetwork(false);
      *curFile = currentFile;
      networkLoaded(filteredCnet);
      networkLoaded(filteredCnet, currentFile);

      if (newCubeListFileName != "")
        loadCubeList(newCubeListFileName);
@@ -701,10 +701,10 @@ namespace Isis {
  }


  void CnetEditorWindow::networkLoaded(ControlNet *net) {
  void CnetEditorWindow::networkLoaded(ControlNet *net, QString currentFile) {

    cnet = net;
    editorWidget = new CnetEditorWidget(cnet, FileName(
    Control *control = new Control(net, currentFile);
    editorWidget = new CnetEditorWidget(control, FileName(
        "$HOME/.Isis/cneteditor/cneteditor.config").expanded());
    populateMenus();
    populateToolBars();
@@ -728,7 +728,7 @@ namespace Isis {

  void CnetEditorWindow::networkLoaded(QList<Control *> nets) {
    ASSERT(nets.count() == 1);
    networkLoaded(nets.first()->controlNet());
    networkLoaded(nets.first()->controlNet(), nets.first()->fileName());
  }


+5 −3
Original line number Diff line number Diff line
@@ -29,6 +29,9 @@ namespace Isis {
   * @author 2011-??-?? Eric Hyer
   *
   * @internal
   *   @history 2017-08-11 Christopher Combs - Changed networkLoaded() to take in a QString of
   *                           the current ControlNet file to create a Control object for
   *                           CnetEditorWidget's new constructor.
   */
  class CnetEditorWindow : public QMainWindow {
      Q_OBJECT
@@ -87,7 +90,7 @@ namespace Isis {
      void save();
      void saveAs();
      void closeNetwork(bool promptToSave = true);
      void networkLoaded(ControlNet *);
      void networkLoaded(ControlNet *, QString currentFile);
      void networkLoaded(QList<Control *>);
      void cubeListLoaded();

@@ -150,4 +153,3 @@ namespace Isis {
}

#endif
+132 −58
Original line number Diff line number Diff line
@@ -26,13 +26,14 @@
#include <QToolBar>
#include <QVBoxLayout>
#include <QWhatsThis>

#include <QtXml>

#include "AbstractMeasureItem.h"
#include "AbstractPointItem.h"
#include "AbstractTreeItem.h"
#include "CnetDisplayProperties.h"
#include "CnetEditorSortConfigDialog.h"
#include "Control.h"
#include "ControlMeasure.h"
#include "ControlNet.h"
#include "ControlPoint.h"
@@ -44,9 +45,12 @@
#include "MeasureTableModel.h"
#include "PointMeasureTreeModel.h"
#include "PointTableModel.h"
#include "Project.h"
#include "TableView.h"
#include "TableViewHeader.h"
#include "TreeView.h"
#include "XmlStackedHandler.h"
#include "XmlStackedHandlerReader.h"


namespace Isis {
@@ -62,14 +66,7 @@ namespace Isis {
//**************************************************************


  /**
   * Constructor
   * 
   * @param cNet Control network to work on 
   * @param pathForSettings Where to write the settings
   */
  CnetEditorWidget::CnetEditorWidget(ControlNet *cNet,
      QString pathForSettings) {
  CnetEditorWidget::CnetEditorWidget(Control *control, QString pathForSettings) {
    nullify();

    m_workingVersion = new QString;
@@ -78,7 +75,7 @@ namespace Isis {

    m_updatingSelection = false;

    m_controlNet = cNet;
    m_control = control;
    connect(CnetDisplayProperties::getInstance(), SIGNAL(compositionFinished()),
        this, SLOT(rebuildModels()));

@@ -188,7 +185,7 @@ namespace Isis {
    m_serialFilterWidget = NULL;
    m_connectionFilterWidget = NULL;

    m_controlNet = NULL;
    m_control = NULL;
    m_settingsPath = NULL;
    m_workingVersion = NULL;
  }
@@ -340,7 +337,7 @@ namespace Isis {
  void CnetEditorWidget::createPointTreeView() {
    m_pointTreeView = new TreeView();
    m_pointTreeView->setTitle("Point View");
    m_pointModel = new PointMeasureTreeModel(m_controlNet, m_pointTreeView, qApp);
    m_pointModel = new PointMeasureTreeModel(m_control->controlNet(), m_pointTreeView, qApp);
    m_pointTreeView->setModel(m_pointModel);
  }

@@ -351,7 +348,7 @@ namespace Isis {
  void CnetEditorWidget::createSerialTreeView() {
    m_imageTreeView = new TreeView();
    m_imageTreeView->setTitle("Cube View");
    m_imageModel = new ImagePointTreeModel(m_controlNet, m_imageTreeView, qApp);
    m_imageModel = new ImagePointTreeModel(m_control->controlNet(), m_imageTreeView, qApp);
    m_imageTreeView->setModel(m_imageModel);
  }

@@ -362,7 +359,7 @@ namespace Isis {
  void CnetEditorWidget::createConnectionTreeView() {
    m_connectionTreeView = new TreeView();
    m_connectionTreeView->setTitle("Cube Connection View");
    m_connectionModel = new ImageImageTreeModel(m_controlNet, m_connectionTreeView, qApp);
    m_connectionModel = new ImageImageTreeModel(m_control->controlNet(), m_connectionTreeView, qApp);
    m_connectionTreeView->setModel(m_connectionModel);
  }

@@ -810,7 +807,7 @@ namespace Isis {
   * @return ControlNet The control network
   */
  ControlNet *CnetEditorWidget::control() {
    return m_controlNet;
    return m_control->controlNet();
  }


@@ -842,7 +839,7 @@ namespace Isis {
   * @return ControlNet Filtered control network
   */
  ControlNet *CnetEditorWidget::filteredNetwork() const {
    ControlNet *filteredCnet = new ControlNet(*m_controlNet);
    ControlNet *filteredCnet = new ControlNet(*(m_control->controlNet()));

    QList<AbstractTreeItem *> networkItems = m_pointModel->getItems(0, -1,
        AbstractTreeModel::MeasureItems | AbstractTreeModel::PointItems, true);
@@ -1043,5 +1040,82 @@ namespace Isis {
      m_connectionModel->setFrozen(false);
    }
  }


  /**
   * This method pushes a new XmlHandler into the parser stack.
   *
   * @param xmlReader This is the parser stack.
   */
  void CnetEditorWidget::load(XmlStackedHandlerReader *xmlReader) {
    xmlReader->pushContentHandler(new XmlHandler(this));
  }


  /**
   * This method saves the Controls object ids to the stream.
   *
   * @param stream The stream that will output to directory.xml
   * @param project The project to save the users settings to
   * @param newProjectRoot New project's root directory
   */
  void CnetEditorWidget::save(QXmlStreamWriter &stream, Project *project, FileName newProjectRoot) {
    stream.writeStartElement("control");
    stream.writeAttribute("id", m_control->id());
    stream.writeEndElement();
  }


  /**
   * Creates an XmlHandler for cnetEditor
   *
   * @param cnetEditor The widget to be serialized
   */
  CnetEditorWidget::XmlHandler::XmlHandler(CnetEditorWidget *cnetEditor) {
    m_cnetEditor = cnetEditor;
  }


  /**
   * Destructor
   */
  CnetEditorWidget::XmlHandler::~XmlHandler() {
    delete m_cnetEditor;
    m_cnetEditor = NULL;
  }


  /**
   * Placeholder for later serialization of CnetEditorWidgets
   *
   * @param cnetEditor The widget to be serialized
   * @param namespaceURI ???
   * @param localName Determines what attributes to retrieve from atts.
   * @param qName ???
   * @param atts Stores the attributes.
   *
   * @return @b bool The result of XmlStackedHandler's startElement() method.
   */
  bool CnetEditorWidget::XmlHandler::startElement(const QString &namespaceURI,
      const QString &localName, const QString &qName, const QXmlAttributes &atts) {
    bool result = XmlStackedHandler::startElement(namespaceURI, localName, qName, atts);
    return result;
  }


  /**
   * This method calls XmlStackedHandler's endElement() and dereferences pointers according to
   * the value of localName.
   *
   * @param namespaceURI ???
   * @param localName Determines which pointers to dereference.
   * @param qName ???
   *
   * @return @b bool The result of XmlStackedHandler's endElement() method.
   */
  bool CnetEditorWidget::XmlHandler::endElement(const QString &namespaceURI,
      const QString &localName, const QString &qName) {
    bool result = XmlStackedHandler::endElement(namespaceURI, localName, qName);
    return result;
  }
}
+55 −7
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@

#include <QWidget>

#include "XmlStackedHandler.h"

class QAction;
class QBoxLayout;
class QGroupBox;
@@ -13,12 +15,27 @@ class QScrollArea;
class QSplitter;
class QString;
class QToolBar;
class QXmlStreamWriter;
class QXmlAttributes;

namespace Isis {
  class AbstractTableModel;
  class AbstractTreeItem;
  class Control;
  class ControlNet;
  class ControlPoint;
  class Directory;
  class FileName;
  class Image;
  class MosaicGraphicsView;
  class MosaicSceneItem;
  class MosaicTool;
  class ProgressBar;
  class Projection;
  class Project;
  class PvlGroup;
  class PvlObject;
  class ToolPad;
  class FilterWidget;
  class ImageImageTreeModel;
  class ImagePointTreeModel;
@@ -49,7 +66,11 @@ namespace Isis {
   *   @history 2017-07-24 Makayla Shepherd - Fixed a seg fault in ipce that occurs when attempting
   *                           to edit a control point when there is not an active control network.
   *                           Fixes #5048.
   *   @history 2017-08-09 Christopher Combs - Added Apriori lat, lon, and radius labels. Fixes#5066
   *   @history 2017-08-10 Christopher Combs - Added Apriori lat, lon, and radius labels. Fixes#5066
   *   @history 2017-08-11 Christopher Combs - Changed constructor to take in a Control instead of
   *                           a ControlNet. Added load and save methods as well as an XmlHandler
   *                           to allow for serialization of the widget into the project.
   *                           Fixes #4989.
   */
  class CnetEditorWidget : public QWidget {
      Q_OBJECT
@@ -61,7 +82,7 @@ namespace Isis {
        ConnectionView
      };

      CnetEditorWidget(ControlNet *, QString);
      CnetEditorWidget(Control *control, QString pathForSettings);
      virtual ~CnetEditorWidget();
      void readSettings();
      void writeSettings();
@@ -95,6 +116,9 @@ namespace Isis {
      void setPointTableSortingEnabled(bool enabled);
      void setPointTableSortLimit(int limit);

      void load(XmlStackedHandlerReader *xmlReader);
      void save(QXmlStreamWriter &stream, Project *project, FileName newProjectRoot);


    public slots:
      void configSorting();
@@ -133,7 +157,7 @@ namespace Isis {

      // data
      bool m_updatingSelection;                                 //!< Updates selection
      ControlNet *m_controlNet;                                 //!< Control network for this widget
      Control *m_control;                                       //!< Control for this widget
      QString *m_workingVersion;                                //!< Working version
      static const QString VERSION;                             //!< Version

@@ -167,6 +191,30 @@ namespace Isis {
      QMap< QString, QList< QAction * > > * m_toolBarActions;   //!< QMap of tool bar actions

      QString *m_settingsPath; //!< Path to read/write settings


    private:
      /**
       * @author 2017-07-25 Christopher Combs
       *
       * This class is a placeholder for future plans to serialize more of
       * CnetEditorWidget's configurations when saving a project.
       */
      class XmlHandler : public XmlStackedHandler {
        public:
          XmlHandler(CnetEditorWidget *cnetEditor);
          ~XmlHandler();

          virtual bool startElement(const QString &namespaceURI, const QString &localName,
                                    const QString &qName, const QXmlAttributes &atts);
          virtual bool endElement(const QString &namespaceURI, const QString &localName,
                                  const QString &qName);

        private:
          Q_DISABLE_COPY(XmlHandler);

          CnetEditorWidget *m_cnetEditor;
      };
  };
}

+17 −2
Original line number Diff line number Diff line
@@ -535,8 +535,7 @@ namespace Isis {
    QMenuBar *menuBar = new QMenuBar;
    resultLayout->addWidget(menuBar, row, 0, 1, 2);
    row++;
    CnetEditorWidget *mainWidget =
        new CnetEditorWidget( network->controlNet(), configFile.expanded() );
    CnetEditorWidget *mainWidget = new CnetEditorWidget(network, configFile.expanded());
    resultLayout->addWidget(mainWidget, row, 0, 1, 2);
    row++;

@@ -1307,6 +1306,18 @@ namespace Isis {
      stream.writeEndElement();
    }

        // Save cnetEditorViews
    if ( !m_cnetEditorViewWidgets.isEmpty() ) {
      stream.writeStartElement("cnetEditorViews");

      foreach (CnetEditorWidget *cnetEditorWidget, m_cnetEditorViewWidgets) {
        cnetEditorWidget->save(stream, project(), newProjectRoot);
      }

      stream.writeEndElement();
    }


    stream.writeEndElement();
  }

@@ -1356,6 +1367,10 @@ namespace Isis {
      else if (localName == "cubeDnView") {
        m_directory->addCubeDnView()->load(reader(), m_directory->project());
      }
      else if (localName == "control") {
        QString id = atts.value("id");
        m_directory->addCnetEditorView(m_directory->project()->control(id));
      }
    }

    return result;
Loading