Commit 46b84888 authored by Tyler Wilson's avatar Tyler Wilson
Browse files

Modified ProjectItemModel::selectedChildItems() to also include grandparents...

Modified ProjectItemModel::selectedChildItems() to also include grandparents of selected children.  Need when setting the root index correctly for SortFilterProxyModel.
parent b6dbf9d3
Loading
Loading
Loading
Loading
+12 −13
Original line number Diff line number Diff line
@@ -1336,7 +1336,7 @@ namespace Isis {

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

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

@@ -1346,36 +1346,35 @@ namespace Isis {

    }

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

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


    //osspm->setDynamicSortFilter(true);

    m_ui->treeView->setRootIsDecorated(true);

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


    qDebug() << "Parent=" << selectedItems[0]->parent()->index().data(0).toString();
    //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 (selectedItems.count() > 0) {
    if (selectedChildItems.count() > 0) {
      //qDebug() << "parent = " << selectedItems[0]->parent()->text();
      osspm->setRoot(selectedItems[0]->parent());
      //osspm->setRoot(selectedChildItems[0]->parent());



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

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


    }
+16 −1
Original line number Diff line number Diff line
@@ -191,9 +191,24 @@ namespace Isis {
        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();
        if (!items.contains(parent)){
          items.append(parent);
        }
      }

      if (this->itemFromIndex(ix)->parent()->parent() ){
        ProjectItem *grandparent = this->itemFromIndex(ix)->parent()->parent();
        if (!items.contains(grandparent)) {
          items.append(grandparent);
        }

      }

    }

    return items;
+20 −9
Original line number Diff line number Diff line
@@ -85,21 +85,22 @@ namespace Isis {
  bool SortFilterProxyModel::filterAcceptsRow(int sourceRow,
                                                        const QModelIndex &sourceParent) const {

    //static QList<QModelIndex> accepted = selectedIndices;

    qDebug() << "filterAcceptsRow";

    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();
           accept = true;
         }


         if (selectedIndices.contains(ix)  && (this->sourceModel()->hasChildren(ix))) {
           qDebug() << "Accepted (has children):" << ix.data(0).toString();
           //int numChildren = this->sourceModel()->rowCount(ix);
@@ -111,23 +112,33 @@ namespace Isis {
             //}
           }

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

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

         if (selectedIndices.contains(ix)  ) {
           qDebug() << "Accepted:  " << ix.data(0).toString();
           qDebug() << "Accepted:  " << ix << ":" << ix.data(0).toString();
           accept = true;
         }

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

       }//end if (ix.isValid() )
         else {
         qDebug() << "Rejected:  " << ix << ":" << ix.data(0).toString();

         }

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

    }
 return accept;

    }




}//end namespace