Commit 5acce11b authored by Tyler Wilson's avatar Tyler Wilson
Browse files

Fixed a bug causing a seg fault when no images selected. Also fixed issue...

Fixed a bug causing a seg fault when no images selected.  Also fixed issue with user selecting things which are not images or image lists.
parent 46b84888
Loading
Loading
Loading
Loading
+10 −40
Original line number Diff line number Diff line
@@ -1327,59 +1327,29 @@ namespace Isis {

  void JigsawSetupDialog::createObservationSolveSettingsTreeView() {

     QList<ProjectItem *> selectedChildItems = m_project->directory()->model()->selectedChildItems();

    QList<ProjectItem *> selectedItems = m_project->directory()->model()->selectedItems();

    QList<ProjectItem *> selectedBOSSItems = m_project->directory()->model()->selectedBOSSImages();

    ProjectItemModel *model = m_project->directory()->model();

    SortFilterProxyModel *osspm = new SortFilterProxyModel;
    osspm->setSourceModel(model);
    //QList<ProjectItem*> selected = model->selectedChildItems();

    //selected.append(selectedItems[0]->parent() );

    qDebug() << "Selected Child items:  ";
    foreach(ProjectItem * item,selectedChildItems) {
      qDebug() << item->index().data(0).toString();

    }

    //qDebug() << "Selected items:  ";
    //foreach(ProjectItem * item,selectedItems) {
    //  qDebug() << item->index().data(0).toString();
    //}


    //osspm->setDynamicSortFilter(true);


    osspm->setSelectedItems(selectedChildItems );
    osspm->setSelectedItems(selectedBOSSItems );
    m_ui->treeView->setModel(osspm);
    //m_ui->treeView->setRootIsDecorated(false);


    //qDebug() << "Parent=" << selectedItems[0]->parent()->index().data(0).toString();


    //Set the root index to display the subtree we are interested in.  This requires
    //computing the proxy index from the source model.
    if (selectedChildItems.count() > 0) {
      //qDebug() << "parent = " << selectedItems[0]->parent()->text();
      //osspm->setRoot(selectedChildItems[0]->parent());



      //if ( selectedItems[0]->parent()->index().data(0).toString().isEmpty()) {
          m_ui->treeView->setRootIndex(osspm->mapFromSource(selectedChildItems[0]->parent()->parent()->index()));

          qDebug() << "Setting parent to:  " << (selectedItems[0]->parent()->parent()->index()).data(0).toString();

         ProjectItem *imgRoot = model->findItemData(QVariant("Images"),0);
         if (imgRoot) {

            m_ui->treeView->setRootIndex(osspm->mapFromSource(imgRoot->index()));
         }
         else {
          m_ui->treeView->setRootIndex(QModelIndex());
         }

  }


  }
}
+4 −0
Original line number Diff line number Diff line
@@ -63,6 +63,10 @@ namespace Isis {
   *                           net name to anything they choose.
   *   @history 2018-06-01 Christopher Combs - Added support for ui changes, exclusive options and 
   *                           input validators.
   *   @history 2018-06-21 Tyler Wilson - Added support in the Bundle Observations Solve Settings
   *                           (BOSS) tab for displaying user-selected images from the main Project
   *                           treeview.  All changes were made in the
   *                           createObservationSolveSettingsTreeView() function.  References #497.
   */

  class JigsawSetupDialog : public QDialog {
+44 −14
Original line number Diff line number Diff line
@@ -178,40 +178,70 @@ namespace Isis {

    return items;
  }
  /**
   * @brief ProjectItemModel::selectedBOSSImages
   * @return This is a refinement of the selectedItems function which
   * was needed to display a subset of Images/ImageLists in the
   * Bundle Observation Solve Settings (BOSS) tab of the JigsawSetupDialog widget.
   * The primary consumer of the selected images is going to be the SortFilterProxyModel
   * class.
   */
  QList<ProjectItem *> ProjectItemModel::selectedBOSSImages() {

  QList<ProjectItem *> ProjectItemModel::selectedChildItems() {
    QItemSelection selection = selectionModel()->selection();
    QList<ProjectItem *> items;


    //Query the selected items to see if they have children
    foreach ( QModelIndex ix, selection.indexes() ) {
      items.append( itemFromIndex(ix) );

      ProjectItem *item = this->itemFromIndex(ix);

      //Anything that is not an image or an image list does
      //not make sense to display in the BOSS treeview tab,
      //so we need to exclude these items.
      if (item->isImageList() || item->isImage() ) {
        items.append( item );
      }
      else {
        return items;
      }

      //If the selected ImageList has children, include all of the children.
      if (this->hasChildren(ix)) {

        //If the node has children, loop through all of them
        //and add them to selected items.
        int numChildren = this->rowCount(ix);
        for (int i = 0; i < numChildren;i++) {
          QModelIndex ixchild = this->index(i,0,ix);
          items.append(this->itemFromIndex(ixchild ));
          }
      }
      if( this->itemFromIndex(ix)->parent() ->hasChildren()) {
        ProjectItem * parent = this->itemFromIndex(ix)->parent();
        qDebug() << "Appending parent:  " << parent->index().data(0).toString();
          }  //end for
      }//end if

      //Append the parent of any selected child.  This is so
      //the children aren't hanging on the tree without
      //a collapsible parent node.
      if( item->parent() ->hasChildren()) {
        ProjectItem * parent = item->parent();
        if (!items.contains(parent)){
          items.append(parent);
        }
      }

        }// end inner if
      }//end outer if
      //Also include the grandparent.  This handles the event
      //that we may have multiple image lists selected to the treeview
      //and we need a grandparent node attached to group them under.
      if (this->itemFromIndex(ix)->parent()->parent() ){
        ProjectItem *grandparent = this->itemFromIndex(ix)->parent()->parent();
        if (!items.contains(grandparent)) {
          items.append(grandparent);
        }
        } //end inner if

      }
      } //end outer if

    }
  }// end foreach

    return items;

  }


+7 −1
Original line number Diff line number Diff line
@@ -130,6 +130,11 @@ namespace Isis {
   *                           bundleoutput.txt (Summary) file to the BundleSolution Statistics
   *                           node. Also changed the name of the Images node under Statistics to
   *                           Image to prevent Import Images to appear on it's context menu.
   *   @history 2018-06-21 Tyler Wilson - Added the function selectedBOSSImages().  This is a
   *                           refinement of selectedItems and is used by the JigsawSetupDialog
   *                           Bundle Observation Solve Settings (BOSS) tab when displaying a
   *                           subset of user-selected images.  References #497
   *
   */
  class ProjectItemModel : public QStandardItemModel {

@@ -155,7 +160,8 @@ namespace Isis {

      ProjectItem *currentItem();
      QList<ProjectItem *> selectedItems();
      QList<ProjectItem *> selectedChildItems();
      QList<ProjectItem *> selectedBOSSImages();


      void appendRow(ProjectItem *item);
      void clean();
+18 −65
Original line number Diff line number Diff line
@@ -42,93 +42,46 @@ namespace Isis {


     if (persistentIndex.isValid()) {
       qDebug() << "persistent index is valid: " << persistentIndex;
      
       //qDebug() << "persistent index is valid: " << persistentIndex;
       m_root = persistentIndex;
     }
     else {
       qDebug() << "persistent index NOT valid.";
       //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 *>();
     // }
     baseModel = newSourceModel;
     QSortFilterProxyModel::setSourceModel(newSourceModel);
   }




  bool SortFilterProxyModel::setRoot(const QStandardItem *item) {

    m_root = QPersistentModelIndex(item->index());   
    qDebug() << "Setting m_root to:  " << m_root.data(0).toString();
    //root = item->index();
    return true;

    //qDebug() << "m_root = " << m_root;

    //if (m_root.isValid()) {
    //  qDebug() <<"m_root is valid";
    //  return true;
   // }
    //else {
      //qDebug() <<"m_root is not valid";

      //return false;
    //}
  }


  bool SortFilterProxyModel::filterAcceptsRow(int sourceRow,
                                                        const QModelIndex &sourceParent) const {



    bool accept(false);

    if (this->sourceModel()!=nullptr) {


       QModelIndex ix = this->sourceModel()->index( sourceRow, 0, sourceParent );
       if (ix.isValid() ) {

        #if 0
         if (this->sourceModel()->hasChildren(ix) ) {
           qDebug() << "Has children:  " << ix.data(0).toString();
    if (selectedIndices.count() == 0) {
      accept = true;
    }

         if (selectedIndices.contains(ix)  && (this->sourceModel()->hasChildren(ix))) {
           qDebug() << "Accepted (has children):" << ix.data(0).toString();
           //int numChildren = this->sourceModel()->rowCount(ix);
           //for (int i = 0; i < numChildren;i++) {

             //QModelIndex ixchild = this->sourceModel()->index(i,0,ix);
             //accepted.append(ixchild);

             //}
           }

      #endif
         qDebug()<< "***************";
         foreach(QModelIndex ix,selectedIndices)
           qDebug() << ix.data(0).toString();

         qDebug()<< "***************";

    if (this->sourceModel()!=nullptr) {
       QModelIndex ix = this->sourceModel()->index( sourceRow, 0, sourceParent );
       if (ix.isValid() ) {
        ProjectItem * item = baseModel->itemFromIndex(ix);
        if (selectedIndices.contains(ix)  ) {
           qDebug() << "Accepted:  " << ix << ":" << ix.data(0).toString();
           accept = true;
         }         

         else {
         qDebug() << "Rejected:  " << ix << ":" << ix.data(0).toString();

        if (item->text() == "Images" ) {
          accept = true;
        }

     }//end if (ix.isValid() )

  }
Loading