Isis 3 Programmer Reference
RemoveImagesWorkOrder.cpp
Go to the documentation of this file.
1
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
35namespace Isis {
36
37 RemoveImagesWorkOrder::RemoveImagesWorkOrder(Project *project) : WorkOrder(project) {
38
39 m_isUndoable = false;
40
41 QAction::setText("&Delete images from project...");
42
43 setModifiesDiskState(true);
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}
ProjectItemModel * model()
Gets the ProjectItemModel for this directory.
Isis exception class.
Definition IException.h:91
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
This represents a cube in a project-based GUI interface.
Definition Image.h:107
Internalizes a list of images and allows for operations on the entire list.
Definition ImageList.h:55
void append(Image *const &value)
Appends an image to the image list.
The main project for ipce.
Definition Project.h:289
static QStringList images(QStringList)
Verify that the input fileNames are image files.
Definition Project.cpp:893
Directory * directory() const
Returns the directory associated with this Project.
Definition Project.cpp:1228
void setClean(bool value)
Function to change the clean state of the project.
Definition Project.cpp:1594
Represents an item of a ProjectItemModel in Qt's model-view framework.
bool isImageList() const
Returns true if an ImageList is stored in the data of the item.
ImageList * imageList() const
Returns the ImageList stored in the data of the item.
Image * image() const
Returns the Image stored in the data of the item.
bool isImage() const
Returns true if an Image is stored in the data of the item.
QList< ProjectItem * > selectedItems()
Returns a list of the selected items of the internal selection model.
virtual void removeItems(QList< ProjectItem * > items)
Removes a list of items and their children from the model.
virtual void removeItem(ProjectItem *item)
Removes an item and its children from the model.
Removes selected images from current project.
bool setupExecution()
@description Set up the execution.
virtual bool isExecutable(ImageList *images)
Determines if we can remove this ImageList.
void execute()
@description Remove any selected items from the project directory.
Provide Undo/redo abilities, serialization, and history for an operation.
Definition WorkOrder.h:311
virtual bool setupExecution()
This sets up the state for the work order.
Project * project() const
Returns the Project this WorkOrder is attached to.
ImageList * imageList()
Returns a pointer to the ImageList for this WorkOrder.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16