Commit 6cfd27af authored by Marjorie Hahn's avatar Marjorie Hahn
Browse files

Deleting an image import from the project tree no longer results in a seg fault. Fixes #5074.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce@7961 41f8697f-d340-4b68-9986-7bafba869bb8
parent c9ee91eb
Loading
Loading
Loading
Loading
+28 −10
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ namespace Isis {
   * @description Set up the execution.
   *
   * @return bool True if parent WordOrder can set up the execution.
   * 
   */
  bool RemoveImagesWorkOrder::setupExecution() {

@@ -86,21 +87,38 @@ namespace Isis {

  /**
   * @description Remove any selected items from the project directory.
   * 
   * @internal
   *   @history 2017-08-08 Marjorie Hahn - Created a conditional to check if the currently 
   *                           selected item to be deleted is actually an image list, so that
   *                           each image can be removed one by one. Fixes #5074.
   */
  void RemoveImagesWorkOrder::execute() {

    QList<ProjectItem *> selectedItems = project()->directory()->model()->selectedItems();
    QList<ImageList *>   images = project()->images();
    QList<ImageList *> projectImageLists = project()->images();

    foreach(ProjectItem *currentItem, selectedItems) {
    foreach (ProjectItem *selectedItem, selectedItems) {
      
      if (currentItem->isImageList()) {
        project()->removeImages(*(currentItem->imageList()));
      if (selectedItem->isImage()) {
        Image *selectedImage = selectedItem->image();
        foreach (ImageList* projectImageList, projectImageLists) {
          projectImageList->removeAll(selectedImage);
        }
      else {
        Image *image = currentItem->image();
        foreach (ImageList* list, project()->images()) {
          list->removeAll(image);
      }
      else if (selectedItem->isImageList()) {
        ImageList *selectedImageList = selectedItem->imageList();
        foreach (Image *selectedImage, *selectedImageList) {
          foreach (ImageList* projectImageList, projectImageLists) {
            projectImageList->removeAll(selectedImage);
          }
        }
        project()->removeImages(*selectedImageList);
      }
      else {
        throw IException(IException::User, 
                         "Item cannot be removed from the project.", 
                         _FILEINFO_);
      }
    }
    
+3 −0
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ namespace Isis {
   *   @history 2017-04-16 J Bonn - Updated to new workorder design #4764.
   *   @history 2017-07-25 Cole Neubauer - Added project()->setClean call #4969
   *   @history 2017-07-31 Cole Neubauer - Fixed images not removing correctly Fixes #4998
   *   @history 2017-08-08 Marjorie Hahn - Modified execute() to check if the currently 
   *                           selected item to be deleted is actually an image list, so that
   *                           each image can be removed one by one. Fixes #5074.
   */
  class RemoveImagesWorkOrder : public WorkOrder {
      Q_OBJECT
+16 −6
Original line number Diff line number Diff line
@@ -197,18 +197,28 @@ namespace Isis {
   * Removes an item and its children from the model.
   *
   * @param item (ProjectItem *) The item to be removed.
   * 
   * @internal
   *   @history 2017-08-08 Marjorie Hahn - Added a check so that if the item to be removed 
   *                           has any children then they can be removed first. Fixes #5074.
   */
  void ProjectItemModel::removeItem(ProjectItem *item) {
    if (!item) {
      return;
    }
//  qDebug()<<"ProjectItemModel::removeItem item= "<<item;
    
    // remove any children the item has first
    if (item->hasChildren()) {
      for (int row = (item->rowCount() - 1); row >= 0; row--) {
        removeRow(item->child(row)->row(), item->index());
      }
    }
    
    if (ProjectItem *parentItem = item->parent()) {
//    qDebug()<<"ProjectItemModel::removeItem  ParentItem ";
      // remove the item from its parent
      removeRow(item->row(), parentItem->index());
    }
    else {
//    qDebug()<<"ProjectItemModel::removeItem item row =  "<<item->row();
      removeRow(item->row());
    }
  }
+7 −5
Original line number Diff line number Diff line
@@ -104,6 +104,8 @@ namespace Isis {
   *                           a user can name things like ImageLists/ShapeLists/ControlLists.
   *                           (ie. this class maintains a QStringList of reserved words which
   *                           cannot be used for naming objects).  Fixes #5047.
   *   @history 2017-08-08 Marjorie Hahn - Modified removeItem() so that if the item to be removed 
   *                           has any children then they can be removed first. Fixes #5074.
   */
  class ProjectItemModel : public QStandardItemModel {