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 }
bool isImageList() const
Returns true if an ImageList is stored in the data of the item.
$Date$ $Revision$
Internalizes a list of images and allows for operations on the entire list.
Definition: ImageList.h:55
The main project for ipce.
Definition: Project.h:289
bool isImage() const
Returns true if an Image is stored in the data of the item.
int removeAll(Image *const &value)
Removes all occurances of an image.
Definition: ImageList.cpp:303
virtual bool setupExecution()
This sets up the state for the work order.
Definition: WorkOrder.cpp:1275
ImageList * imageList() const
Returns the ImageList stored in the data of the item.
static QStringList images(QStringList)
Verify that the input fileNames are image files.
Definition: Project.cpp:894
void execute()
Remove any selected items from the project directory.
Directory * directory() const
Returns the directory associated with this Project.
Definition: Project.cpp:1229
virtual void removeItems(QList< ProjectItem *> items)
Removes a list of items and their children from the model.
ProjectItemModel * model()
Gets the ProjectItemModel for this directory.
Definition: Directory.cpp:1105
Provide Undo/redo abilities, serialization, and history for an operation.
Definition: WorkOrder.h:322
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:142
virtual void removeItem(ProjectItem *item)
Removes an item and its children from the model.
This represents a cube in a project-based GUI interface.
Definition: Image.h:107
Image * image() const
Returns the Image stored in the data of the item.
bool m_isUndoable
Set the workorder to be undoable/redoable This is defaulted to true - his will allow the workorder to...
Definition: WorkOrder.h:534
void append(Image *const &value)
Appends an image to the image list.
Definition: ImageList.cpp:153
bool setupExecution()
Set up the execution.
void setModifiesDiskState(bool changesProjectOnDisk)
Definition: WorkOrder.cpp:1688
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
virtual bool isExecutable(ImageList *images)
Determines if we can remove this ImageList.
QList< ProjectItem * > selectedItems()
Returns a list of the selected items of the internal selection model.
Represents an item of a ProjectItemModel in Qt&#39;s model-view framework.
Definition: ProjectItem.h:146
Isis exception class.
Definition: IException.h:107
Removes selected images from current project.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Project * project() const
Returns the Project this WorkOrder is attached to.
Definition: WorkOrder.cpp:1314
ImageList * imageList()
Returns a pointer to the ImageList for this WorkOrder.
Definition: WorkOrder.cpp:645
void setClean(bool value)
Function to change the clean state of the project.
Definition: Project.cpp:1595