Commit 3c9903d4 authored by Ian Humphrey's avatar Ian Humphrey
Browse files

add preliminary ObservationSolveSettingsProxyModel

parent 2e0aa107
Loading
Loading
Loading
Loading
+128 −55
Original line number Diff line number Diff line
@@ -3,8 +3,10 @@
#include <vector>

#include <QDebug>
#include <QIdentityProxyModel>
#include <QMessageBox>
#include <QPushButton>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>

#include "BundleSolutionInfo.h"
@@ -13,6 +15,7 @@
#include "Control.h"
#include "IString.h"
#include "MaximumLikelihoodWFunctions.h"
#include "ObservationSolveSettingsProxyModel.h"
#include "Project.h"
#include "ProjectItemProxyModel.h"
#include "SpecialPixel.h"
@@ -88,61 +91,7 @@ namespace Isis {
    // Update setup dialog with settings from any active (current) settings in jigsaw dialog.

    // initializations for observation solve settings tab
    // Proof-of-concept
//    m_ui->treeView->setModel((QAbstractItemModel*)(m_project->directory()->model()));
    ProjectItemModel *model = m_project->directory()->model();
    qDebug() << "Source model row count: " << model->rowCount();
    ProjectItemProxyModel *proxyModel = new ProjectItemProxyModel(this);
    //proxyModel->setSourceModel(model);

    // Why do we have to do it this way?
    // -- For some reason, the isX() methods in ProjectItem aren't working below.
    for (int i = 0; i < model->rowCount(); i++) {
      ProjectItem *projectItem = model->item(i);
      for (int j = 0; j < projectItem->rowCount(); j++) {
        ProjectItem *imageList = projectItem->child(j);
        if (imageList->text() == "Images") {
          for (int k = 0; k < imageList->rowCount(); k++) {
            ProjectItem *importItem = imageList->child(k);
            proxyModel->addItem(importItem);
          }
        }
      }
    }

//    ProjectItem *root = model->item(0);
//    qDebug() << "root row count : " << root->rowCount();
//    qDebug() << root->isProject();
//    qDebug() << root->child(0)->isProject();
//    ProjectItem *child = static_cast<ProjectItem *>(root->child(0));
//    qDebug() << child->isControlList();
//    qDebug() << child->data().value< ControlList * >();
//    proxyModel->addItem(root->child(0));
//    QVariant value = child->data();
//    qDebug() << value;
//    for (int childIndex = 0; childIndex < root->rowCount(); childIndex++) {
//      ProjectItem *child = root->child(childIndex);

//      if (child->isBundleResults()) qDebug() << "bundleResults @ " << childIndex;
//      if (child->isBundleSettings()) qDebug() << "bundleSettings @ " << childIndex;
//      if (child->isBundleSolutionInfo()) qDebug() << "bundleSolutionInfo @ " << childIndex;
//      if (child->isControl()) qDebug() << "control @ " << childIndex;
//      if (child->isControlList()) qDebug() << "controlList @ " << childIndex;
//      if (child->isCorrelationMatrix()) qDebug() << "correlationMatrix @ " << childIndex;
//      if (child->isImage()) qDebug() << "image @ " << childIndex;
//      if (child->isShape()) qDebug() << "shape @ " << childIndex;
//      if (child->isShapeList()) qDebug() << "shapeList @ " << childIndex;
//      if (child->isProject()) qDebug() << "project @ " << childIndex;
//      if (child->isGuiCamera()) qDebug() << "guiCamera @ " << childIndex;
//      if (child->isTargetBody()) qDebug() << "targetBody @ " << childIndex;
//      if (child->isFileItem()) qDebug() << "fileItem @ " << childIndex;
//      if (child->isTemplate()) qDebug() << "template @ " << childIndex;
//      if (child->isImageList()) qDebug() << "imageList @ " << childIndex;


//    }
    m_ui->treeView->setModel(proxyModel);

    createObservationSolveSettingsTreeView();
    m_ui->spkSolveDegreeSpinBox_2->setValue(-1);

    QStringList tableHeaders;
@@ -1177,4 +1126,128 @@ namespace Isis {
    FileName fname = arg1;
    m_ui->outputControlNet->setText(fname.baseName() + "-out.net");
  }


  void JigsawSetupDialog::createObservationSolveSettingsTreeView() {
    // Proof-of-concept
//    m_ui->treeView->setModel((QAbstractItemModel*)(m_project->directory()->model()));
    ProjectItemModel *model = m_project->directory()->model();
    ProjectItemProxyModel *proxyModel = new ProjectItemProxyModel(this);
    QStandardItemModel *tModel = new QStandardItemModel;
    //proxyModel->setSourceModel(model);

    ObservationSolveSettingsProxyModel *osspm = new ObservationSolveSettingsProxyModel;
    osspm->setSourceModel(model);

    // find the root "Images" and set it in the proxy
    QStandardItem *item = model->invisibleRootItem()->child(0)->child(1);
    qDebug() << "ITEM: " << item << ", " << item->text();
    qDebug() << "PARENT: " << item->parent() << ", " << item->parent()->text();
    // i think source model tries to add top root item, which is invalid???
    //osspm->setRoot(item);    



    // Why do we have to do it this way?
    // -- For some reason, the isX() methods in ProjectItem aren't working below.
    // QStandardItem *root = tModel->invisibleRootItem();
    // for (int i = 0; i < model->rowCount(); i++) {
    //   ProjectItem *projectItem = model->item(i);
    //   for (int j = 0; j < projectItem->rowCount(); j++) {
    //     ProjectItem *imageList = projectItem->child(j);
    //     if (imageList->text() == "Images") {
    //       for (int k = 0; k < imageList->rowCount(); k++) {
    //         QStandardItem *groupItem = new QStandardItem("Group1");
    //         ProjectItem *importItem = imageList->child(k);
    //         groupItem->appendRow(static_cast<QStandardItem *>(importItem));
    //         tModel->appendRow(groupItem);
    //       }
    //     }
    //   }
    // }

    // ProjectItemModel *sourceModel = model;
    //loop through the levels of the original source model tree
    /* (root item)
     * Project
     * - Images
     *   - import1
     *     - img1
     *     - imgN
     *   - importN
     */
    // QIdentityProxyModel *m = new QIdentityProxyModel;
    // m->setSourceModel(sourceModel);
    // Setting the source model will allow changing it (e.g. changing the name of the project int
    // the tree in the proxy model will be reflected in the main project tree view as well)
    //m->setSourceModel(sourceModel);
//    qDebug() << "proxy model row count: " << model->rowCount();
//    qDebug() << "proxy model col count: " << model->columnCount();
//    qDebug() << "can we get first item? " << model->index(0,0);
//    qDebug() << "does parent node have children? " << model->children().count();
//    m->setData(model->index(0,0), QVariant("test"));
//    ProjectItem *p = NULL;
//    QVariant qvp = model->data(model->index(0,0), Qt::DisplayRole);
//    qDebug() << "can convert to ProjectItem? " << qvp.value<ProjectItem*>();
    // for (int rootIndex = 0; rootIndex < m->rowCount(); rootIndex++) {
    //   ProjectItem *projectItem = sourceModel->item(rootIndex);
    //   qDebug() << m->insertRows(0, 1);
    //   QModelIndex projectQMI = m->index(0, 1);
    //   qDebug() << m->setData(projectQMI, QVariant::fromValue(projectItem));
    //   for (int projectChild = 0; projectChild < projectItem->rowCount(); projectChild++) {
    //     ProjectItem *imageList = projectItem->child(projectChild);
    //     if (imageList->text() == "Images") {
    //       for (int imageListChild = 0; imageListChild < imageList->rowCount(); imageListChild++) {
    //         ProjectItem *importItem = imageList->child(imageListChild);
    //         //QStandardItem *group = new QStandardItem("Group1");
    //         //group->appendRow(static_cast<QStandardItem *>(importItem));
            //m->insertRow(group);
            //m->appendRow(static_cast<QStandardItem *>(importItem));
            //m->insertRows(0, 1);
          // }
    //     }
    //   }
    // }

//    ProjectItem *root = model->item(0);
//    qDebug() << "root row count : " << root->rowCount();
//    qDebug() << root->isProject();
//    qDebug() << root->child(0)->isProject();
//    ProjectItem *child = static_cast<ProjectItem *>(root->child(0));
//    qDebug() << child->isControlList();
//    qDebug() << child->data().value< ControlList * >();
//    proxyModel->addItem(root->child(0));
//    QVariant value = child->data();
//    qDebug() << value;
//    for (int childIndex = 0; childIndex < root->rowCount(); childIndex++) {
//      ProjectItem *child = root->child(childIndex);

//      if (child->isBundleResults()) qDebug() << "bundleResults @ " << childIndex;
//      if (child->isBundleSettings()) qDebug() << "bundleSettings @ " << childIndex;
//      if (child->isBundleSolutionInfo()) qDebug() << "bundleSolutionInfo @ " << childIndex;
//      if (child->isControl()) qDebug() << "control @ " << childIndex;
//      if (child->isControlList()) qDebug() << "controlList @ " << childIndex;
//      if (child->isCorrelationMatrix()) qDebug() << "correlationMatrix @ " << childIndex;
//      if (child->isImage()) qDebug() << "image @ " << childIndex;
//      if (child->isShape()) qDebug() << "shape @ " << childIndex;
//      if (child->isShapeList()) qDebug() << "shapeList @ " << childIndex;
//      if (child->isProject()) qDebug() << "project @ " << childIndex;
//      if (child->isGuiCamera()) qDebug() << "guiCamera @ " << childIndex;
//      if (child->isTargetBody()) qDebug() << "targetBody @ " << childIndex;
//      if (child->isFileItem()) qDebug() << "fileItem @ " << childIndex;
//      if (child->isTemplate()) qDebug() << "template @ " << childIndex;
//      if (child->isImageList()) qDebug() << "imageList @ " << childIndex;


//    }
    m_ui->treeView->setModel(model);



    // Try to loop through the view here to add the "groups" so they aren't part of the model

    // Add apply button to the tab view
    // set the text to bold?

  }
}
+2 −0
Original line number Diff line number Diff line
@@ -122,6 +122,8 @@ namespace Isis {
    void showTargetParametersGroupBox();
    void hideTargetParametersGroupBox();

    void createObservationSolveSettingsTreeView();

  private:
    Ui::JigsawSetupDialog *m_ui;
    Project *m_project;
+7 −0
Original line number Diff line number Diff line
ifeq ($(ISISROOT), $(BLANK))
.SILENT:
error:
	echo "Please set ISISROOT";
else
	include $(ISISROOT)/make/isismake.objs
endif
 No newline at end of file
+149 −0
Original line number Diff line number Diff line
#include "ObservationSolveSettingsProxyModel.h"

#include <QAbstractItemModel>
#include <QIdentityProxyModel>
#include <QModelIndex>
#include <QObject>
#include <QPersistentModelIndex>
#include <QSortFilterProxyModel>
#include <QStandardItem>
#include <QVariant>

#include "ProjectItem.h"

namespace Isis {

  ObservationSolveSettingsProxyModel::ObservationSolveSettingsProxyModel(QObject *parent) : QIdentityProxyModel(parent) {
  }


  QModelIndex ObservationSolveSettingsProxyModel::mapFromSource(const QModelIndex &sourceIndex) const {
    // return QIdentityProxyModel::mapFromSource(sourceIndex);
    qDebug() << "BEGIN mapFromSource(" << sourceIndex << ")";
    // QModelIndex parent = sourceIndex.parent();
    // int row = sourceIndex.row();
    // if (!sourceIndex.isValid()) {
    //   return m_root;
    // }

    // First check to see if the source index is the proxy root
    if (sourceIndex == m_root) {
      qDebug() << "source exactly matches root already.";
      return createIndex(sourceIndex.row(), 0, sourceIndex.internalId());
    }

    // If the source index is a child of the proxy root, one if its ancestors IS proxy root
    QModelIndex ancestorIndex = sourceIndex.parent();
    QString n = "";
    qDebug() << ancestorIndex;
    while (ancestorIndex.isValid() && ancestorIndex != m_root) {
      ancestorIndex = ancestorIndex.parent();
      n += "\t";
      qDebug() << n << ancestorIndex;
    }
    if (ancestorIndex.isValid()) {
      return createIndex(sourceIndex.row(), 0, sourceIndex.internalId());
      // return QModelIndex(parent.child(row));
    }
    else {
      return QModelIndex();
    }

    // int sourceRow = sourceIndex.row();
    // int rootRow = m_root.row();

    // Siblings of the proxy root are NOT part of the subtree
    /* Item 0        (the source tree root; the proxy root's parent)
     * - Item 0      (a sibling of the proxy root)
     * - Item 1      (the proxy root, m_root)
     *   - Item 0    (a child of the proxy root)
     * - Item 2      (a sibling of the proxy root)
    //  */
    // if (sourceIndex.parent() == m_root.parent()) {
    //   return QModelIndex();
    // }

    // // Ancestors of the proxy root are NOT part of the subtree
    // QModelIndex parentIndex = sourceIndex.parent();
    // while (parentIndex.isValid()) {
    //   parentIndex = parentIndex.parent();
    // }


    // if (sourceRow != rootRow) {
    //   return QModelIndex();
    // }
    // QModelIndex sourceParent = sourceIndex.parent();

    // See if there 
    // Check to see if we are at the root
    // if (!sourceParent.isValid()) {
      
    // }
    // else {

    // }
    // int targetRow = sourceRow;
    // return QIdentityProxyModel::mapFromSource(sourceIndex);
  }


  QModelIndex ObservationSolveSettingsProxyModel::mapToSource(const QModelIndex &proxyIndex) const {
    // return proxyIndex;
    return QIdentityProxyModel::mapToSource(proxyIndex);
  }


  void ObservationSolveSettingsProxyModel::setSourceModel(QAbstractItemModel *newSourceModel) {
    // QVariant data = newSourceModel->data(newSourceModel->index(0,0,QModelIndex()));
    // qDebug() << data;
    // qDebug() << "can convert to project item: " << data.canConvert<ProjectItem *>();
    qDebug() << typeid(*newSourceModel).name();
    
    // QStandardItem *item = static_cast<QStandardItemModel *>(newSourceModel)->invisibleRootItem();
    QPersistentModelIndex persistentIndex(newSourceModel->index(0,0,QModelIndex()));
    // QPersistentModelIndex persistentIndex(item->index());
    // qDebug() << "root item: " << item;
    // qDebug() << "root item index: " << item->index();

    
    if (persistentIndex.isValid()) {
      qDebug() << "persistent index is valid: " << persistentIndex;
      qDebug() << "parent index: " << persistentIndex.parent();
      m_root = persistentIndex;
    }
    else {
      qDebug() << "persistent index NOT valid.";
      m_root = QPersistentModelIndex(QModelIndex());
    }

    // // qDebug() << "can convert to qstandarditem: " << data.canConvert<QStandardItem *>();
    // if (data.canConvert<ProjectItem *>()) {
    //  m_root = data.value<ProjectItem *>();
    // }
    QIdentityProxyModel::setSourceModel(newSourceModel);
  }


  bool ObservationSolveSettingsProxyModel::setRoot(const QStandardItem *item) {
    qDebug() << "setRoot() item->index() " << item->index();
    qDebug() << "\titem->parent()->index() " << item->parent()->index();
    m_root = QPersistentModelIndex(item->index());
    qDebug() << "Perisentent Model Index ROOT: " << m_root << " is valid ? " << (m_root.isValid() ? "yes" : "no");
    qDebug() << "Persistent's PARENT: " << m_root.parent();
    if (m_root.isValid()) {
      return true;
    }
    else {
      return false;
    }
  }
  
  // bool ObservationSolveSettingsProxyModel::filterAcceptsRow(int sourceRow, 
  //                                                           const QModelIndex &sourceParent) const {
  //   QModelIndex mIndex = sourceModel()->index(sourceRow, 0, sourceParent);

  // }


}
 No newline at end of file
+48 −0
Original line number Diff line number Diff line
#ifndef ObservationSolveSettingsProxyModel_h
#define ObservationSolveSettingsProxyModel_h

#include <QIdentityProxyModel>
#include <QPersistentModelIndex>
#include <QSortFilterProxyModel>

class QAbstractProxyModel;
class QObject;
class QStandardItem;
class QVariant;

namespace Isis {
  
  class ObservationSolveSettingsProxyModel : public QIdentityProxyModel {
    Q_OBJECT

    public:
      explicit ObservationSolveSettingsProxyModel(QObject *parent = 0);

      QModelIndex mapFromSource(const QModelIndex &sourceIndex) const Q_DECL_OVERRIDE;
      QModelIndex mapToSource(const QModelIndex &proxyIndex) const Q_DECL_OVERRIDE;

      void setSourceModel(QAbstractItemModel *newSourceModel) Q_DECL_OVERRIDE;

      bool setRoot(const QStandardItem *item);


      // Allow reading of the model
      //QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
      //Qt::ItemFlags flags(const QModelIndex &index) const override;

      // Allow re-sizing the model
      //bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;

    // Use the method below to change how filtering chooses to accept the row
    // protected:
      // bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;

    private:
      QPersistentModelIndex m_root;

  };

};


#endif
 No newline at end of file