Isis 3 Programmer Reference
RemoveImagesWorkOrder.cpp
Go to the documentation of this file.
1 
23 #include "RemoveImagesWorkOrder.h"
24 
25 #include <QDebug>
26 #include <QMessageBox>
27 
28 #include "IException.h"
29 #include "ImageList.h"
30 #include "Progress.h"
31 #include "Project.h"
32 #include "ProjectItem.h"
33 #include "ProjectItemModel.h"
34 
35 namespace Isis {
36 
37  RemoveImagesWorkOrder::RemoveImagesWorkOrder(Project *project) : WorkOrder(project) {
38 
39  m_isUndoable = false;
40 
41  QAction::setText("&Delete images from project...");
42 
44  }
45 
46 
47  RemoveImagesWorkOrder::RemoveImagesWorkOrder(const RemoveImagesWorkOrder &other) :
48  WorkOrder(other) {
49  // This is not undoable
50  m_isUndoable = false;
51  }
52 
53 
54  RemoveImagesWorkOrder::~RemoveImagesWorkOrder() {
55  }
56 
57 
58  RemoveImagesWorkOrder *RemoveImagesWorkOrder::clone() const {
59  return new RemoveImagesWorkOrder(*this);
60  }
61 
62 
70 
71  return true;
72  }
73 
74 
82 
83  bool success = WorkOrder::setupExecution();
84 
85  QList<ProjectItem *> selectedItems = project()->directory()->model()->selectedItems();
86  long itemCount = selectedItems.count();
87  if (itemCount == 1) {
88  if (selectedItems.at(0)->isImage()) {
89  QUndoCommand::setText("&Delete image " + selectedItems.at(0)->image()->fileName() + " from project...");
90  }
91  else if (selectedItems.at(0)->isImageList()) {
92  QUndoCommand::setText("&Delete " + QString::number(selectedItems.at(0)->imageList()->count(), 10) + " images from project...");
93  }
94  }
95  else {
96  long totalCount = 0;
97  QList<ImageList *> imageListAdded;
98  ImageList images;
99  foreach(ProjectItem *item, selectedItems) {
100  if (item->isImage()) {
101  totalCount++;
102  images.append(item->image());
103  }
104  else if (item->isImageList()) {
105  totalCount += item->imageList()->count();
106  imageListAdded.append(item->imageList());
107  }
108  }
109  // this is needed to be able to get a correct count when a user selects an image and
110  // the imagelist containing that image
111  foreach (ImageList *imageList, imageListAdded) {
112  foreach (Image *image, images) {
113  if (imageList->contains(image)) {
114  totalCount--;
115  }
116  }
117  }
118  QUndoCommand::setText("&Delete " + QString::number(totalCount, 10) + " images from project...");
119  }
120 
121  return success;
122  //TODO: 2016-07-29 TLS Should I ask if files should be deleted from disk also?
123  }
124 
125 
138 
139  QList<ProjectItem *> selectedItems = project()->directory()->model()->selectedItems();
140  QList<ProjectItem *> needToRemoveItems;
141 
142 
143  QList<ImageList *> projectImageLists = project()->images();
144  QList<ImageList *> imageListToProcess;
145  foreach (ProjectItem *selectedItem, selectedItems) {
146  if (selectedItem->isImage()) {
147  Image *selectedImage = selectedItem->image();
148  project()->directory()->model()->removeItem(selectedItem);
149 
150  foreach (ImageList* projectImageList, projectImageLists) {
151  projectImageList->removeAll(selectedImage);
152  }
153  }
154  else if (selectedItem->isImageList()) {
155  imageListToProcess.append(selectedItem->imageList());
156  needToRemoveItems.append(selectedItem);
157  }
158  else {
160  "Item cannot be removed from the project.",
161  _FILEINFO_);
162  }
163  }
164  foreach(ImageList *imageList, imageListToProcess) {
165  foreach (Image *selectedImage, *imageList) {
166  foreach (ImageList* projectImageList, projectImageLists) {
167  projectImageList->removeAll(selectedImage);
168  }
169  }
170  project()->removeImages(*imageList);
171  }
172 
173  project()->directory()->model()->removeItems(needToRemoveItems);
174  project()->setClean(false);
175  }
176 }
Isis::WorkOrder::setupExecution
virtual bool setupExecution()
This sets up the state for the work order.
Definition: WorkOrder.cpp:1261
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis::WorkOrder
Provide Undo/redo abilities, serialization, and history for an operation.
Definition: WorkOrder.h:311
Project.h
Isis::Directory::model
ProjectItemModel * model()
Gets the ProjectItemModel for this directory.
Definition: Directory.cpp:1091
Isis::ProjectItem::image
Image * image() const
Returns the Image stored in the data of the item.
Definition: ProjectItem.cpp:476
Isis::RemoveImagesWorkOrder::execute
void execute()
@description Remove any selected items from the project directory.
Definition: RemoveImagesWorkOrder.cpp:137
Isis::WorkOrder::imageList
ImageList * imageList()
Returns a pointer to the ImageList for this WorkOrder.
Definition: WorkOrder.cpp:631
RemoveImagesWorkOrder.h
Isis::ProjectItemModel::removeItems
virtual void removeItems(QList< ProjectItem * > items)
Removes a list of items and their children from the model.
Definition: ProjectItemModel.cpp:342
Isis::ImageList::append
void append(Image *const &value)
Appends an image to the image list.
Definition: ImageList.cpp:153
Isis::RemoveImagesWorkOrder
Removes selected images from current project.
Definition: RemoveImagesWorkOrder.h:56
Isis::RemoveImagesWorkOrder::setupExecution
bool setupExecution()
@description Set up the execution.
Definition: RemoveImagesWorkOrder.cpp:81
Isis::Project
The main project for ipce.
Definition: Project.h:289
Isis::Project::directory
Directory * directory() const
Returns the directory associated with this Project.
Definition: Project.cpp:1229
Isis::ImageList
Internalizes a list of images and allows for operations on the entire list.
Definition: ImageList.h:55
Isis::Project::images
static QStringList images(QStringList)
Verify that the input fileNames are image files.
Definition: Project.cpp:894
Isis::ProjectItem::isImageList
bool isImageList() const
Returns true if an ImageList is stored in the data of the item.
Definition: ProjectItem.cpp:657
Isis::WorkOrder::m_isUndoable
bool m_isUndoable
Set the workorder to be undoable/redoable This is defaulted to true - his will allow the workorder to...
Definition: WorkOrder.h:523
Isis::ProjectItem::isImage
bool isImage() const
Returns true if an Image is stored in the data of the item.
Definition: ProjectItem.cpp:646
Isis::ProjectItemModel::selectedItems
QList< ProjectItem * > selectedItems()
Returns a list of the selected items of the internal selection model.
Definition: ProjectItemModel.cpp:158
Isis::WorkOrder::project
Project * project() const
Returns the Project this WorkOrder is attached to.
Definition: WorkOrder.cpp:1300
Isis::Image
This represents a cube in a project-based GUI interface.
Definition: Image.h:107
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::RemoveImagesWorkOrder::isExecutable
virtual bool isExecutable(ImageList *images)
Determines if we can remove this ImageList.
Definition: RemoveImagesWorkOrder.cpp:69
Isis::ProjectItem::imageList
ImageList * imageList() const
Returns the ImageList stored in the data of the item.
Definition: ProjectItem.cpp:486
Isis::WorkOrder::setModifiesDiskState
void setModifiesDiskState(bool changesProjectOnDisk)
Definition: WorkOrder.cpp:1674
Isis::ImageList::removeAll
int removeAll(Image *const &value)
Removes all occurances of an image.
Definition: ImageList.cpp:303
Isis::Project::setClean
void setClean(bool value)
Function to change the clean state of the project.
Definition: Project.cpp:1595
Isis::ProjectItemModel::removeItem
virtual void removeItem(ProjectItem *item)
Removes an item and its children from the model.
Definition: ProjectItemModel.cpp:315
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::IException::User
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition: IException.h:126
Isis::ProjectItem
Represents an item of a ProjectItemModel in Qt's model-view framework.
Definition: ProjectItem.h:134