Isis 3 Programmer Reference
ImageListActionWorkOrder.cpp
1#include "ImageListActionWorkOrder.h"
2
3#include <QMessageBox>
4
5#include "Color.h"
6#include "ImageList.h"
7#include "Project.h"
8
9namespace Isis {
10
21
22
30 WorkOrder(project) {
31
32 m_isSavedToHistory = false;
33
34 QAction::setText(toString(action));
35 QUndoCommand::setText(toString(action));
36
38 internalData.append(toString(action));
40 }
41
42
49 const ImageListActionWorkOrder &other) : WorkOrder(other) {
50
51 m_isSavedToHistory = false;
52
53 foreach (const Image *image, *other.imageList()) {
54 connect(this, SIGNAL(bringToFront()), image->displayProperties(), SIGNAL(moveToTop()));
55 }
56 }
57
58
64
65
74
75
85 return !images->isEmpty();
86 }
87
88
97 WorkOrder::setData(images);
98
99 if (internalData().count()) {
100 QAction::setText(qualifyString(internalData()[0], imageList()));
101
102 QString modifiedString = (qualifyString(internalData()[0], imageList()) + " on %1 images")
103 .arg(imageList()->count());
104 QUndoCommand::setText(modifiedString);
105 }
106
107 foreach (Image *image, *images) {
108 connect(this, SIGNAL(bringToFront()), image->displayProperties(), SIGNAL(moveToTop()));
109 }
110 }
111
112
121 bool result = WorkOrder::setupExecution() && !internalData().isEmpty();
122
123 if (!internalData().isEmpty()) {
124 QStringList state = internalData();
125 QString actionString = internalData()[0];
126
127 switch(fromActionString(actionString)) {
128 case UnknownAction:
129 result = false;
130 break;
131
132 case ChangeTransparency: {
133 int alpha = 255;
134 result = imageList()->askAlpha(&alpha);
135 state.append(QString::number(alpha));
136 break;
137 }
138
139 case ChangeColor: {
140 QColor color;
141 result = imageList()->askNewColor(&color);
142
143 // QColor::name() doesn't preserve alpha.
144 if (color.isValid()) {
145 state.append(Color::toRGBAString(color));
146 }
147 break;
148 }
149
150 case RandomizeColor:
151 break;
152
153 case ToggleShowLabel: {
154 int maxRecommendedLabels = 2000;
155 if (qualifyString(actionString, imageList()).startsWith(tr("Show")) &&
156 imageList()->count() > maxRecommendedLabels) {
157 QMessageBox::StandardButton selectedOpt = QMessageBox::warning(NULL,
158 tr("Potentially Slow Operation"),
159 tr("You are asking to show the labels on %L1 images. When viewing these images in "
160 "a 2D footprint view, these images will take at least 3x longer to render. This "
161 "is a significant performance loss. Showing more than a few labels at a time is "
162 "not recommended. Are you sure you want to show the labels on these %L1 images?")
163 .arg(imageList()->count()),
164 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
165
166 if (selectedOpt == QMessageBox::No) {
167 result = false;
168 }
169 }
170 break;
171 }
172
173 case ToggleShowFilled:
174 break;
175
177 break;
178
180 break;
181
182 case MoveToTop:
183 break;
184
185 case MoveUpOne:
186 break;
187
188 case MoveToBottom:
189 break;
190
191 case MoveDownOne:
192 break;
193
194 case ZoomFit:
195 break;
196 }
197
198 setInternalData(state);
199 }
200
201 return result;
202 }
203
204
218 QStringList state = internalData();
219 QString actionString = internalData()[0];
220
221 switch(fromActionString(actionString)) {
222 case UnknownAction:
223 break;
224
226 state = state.mid(0, 2);
227 state.append(imageList()->saveAndApplyAlpha(state[1].toInt()));
228 break;
229
230 case ChangeColor:
231 state = state.mid(0, 2);
232 state.append(imageList()->saveAndApplyColor(Color::fromRGBAString(state[1])));
233 break;
234
235 case RandomizeColor:
236 if (state.count() > 1) {
237 // Apply previously randomly generated colors if available
238 imageList()->applyColors(state.mid(1), 1);
239 }
240 else {
241 state.append(imageList()->saveAndApplyRandomColor());
242 }
243 break;
244
245 case ToggleShowLabel:
246 state = state.mid(0, 1);
247 state.append(imageList()->saveAndToggleShowLabel());
248 break;
249
250 case ToggleShowFilled:
251 state = state.mid(0, 1);
252 state.append(imageList()->saveAndToggleShowFill());
253 break;
254
256 state = state.mid(0, 1);
257 state.append(imageList()->saveAndToggleShowDNs());
258 break;
259
261 state = state.mid(0, 1);
262 state.append(imageList()->saveAndToggleShowOutline());
263 break;
264
265 case MoveToTop:
266 break;
267
268 case MoveUpOne:
269 break;
270
271 case MoveToBottom:
272 break;
273
274 case MoveDownOne:
275 break;
276
277 case ZoomFit:
278 break;
279 }
280
281 setInternalData(state);
282 }
283
284
297 QStringList state = internalData();
298 QString actionString = internalData()[0];
299
300 switch(fromActionString(actionString)) {
301 case UnknownAction:
302 break;
303
305 imageList()->applyAlphas(state.mid(2));
306 break;
307
308 case ChangeColor:
309 imageList()->applyColors(state.mid(2));
310 break;
311
312 case RandomizeColor:
313 // Apply colors before randomization occurred
314 imageList()->applyColors(state.mid(1), 0);
315 break;
316
317 case ToggleShowLabel:
318 imageList()->applyShowLabel(state.mid(1));
319 break;
320
321 case ToggleShowFilled:
322 imageList()->applyShowFill(state.mid(1));
323 break;
324
326 imageList()->applyShowDNs(state.mid(1));
327 break;
328
330 imageList()->applyShowOutline(state.mid(1));
331 break;
332
333 case MoveToTop:
334 break;
335
336 case MoveUpOne:
337 break;
338
339 case MoveToBottom:
340 break;
341
342 case MoveDownOne:
343 break;
344
345 case ZoomFit:
346 break;
347 }
348
349 setInternalData(state);
350 }
351
352
361 QString ImageListActionWorkOrder::qualifyString(QString unqualifiedString,
362 ImageList *imageList) {
363 QString result = unqualifiedString;
364
365 if (imageList && imageList->count()) {
366 ImageDisplayProperties *firstDisplay = imageList->first()->displayProperties();
367 Action act = fromActionString(unqualifiedString);
368
369 if (act == ToggleShowLabel) {
370 if (firstDisplay->getValue(ImageDisplayProperties::ShowLabel).toBool()) {
371 result = tr("Hide Label");
372 }
373 else {
374 result = tr("Show Label");
375 }
376 }
377
378 if (act == ToggleShowFilled) {
379 if (firstDisplay->getValue(ImageDisplayProperties::ShowFill).toBool()) {
380 result = tr("Show Unfilled");
381 }
382 else {
383 result = tr("Show Filled");
384 }
385 }
386
387 if (act == ToggleShowCubeData) {
388 if (firstDisplay->getValue(ImageDisplayProperties::ShowDNs).toBool()) {
389 result = tr("Hide Cube Data");
390 }
391 else {
392 result = tr("Show Cube Data");
393 }
394 }
395
396 if (act == ToggleShowOutline) {
397 if (firstDisplay->getValue(ImageDisplayProperties::ShowOutline).toBool()) {
398 result = tr("Hide Outline");
399 }
400 else {
401 result = tr("Show Outline");
402 }
403 }
404 }
405
406 return result;
407 }
408
409
418 QString result;
419
420 switch(action) {
421 case UnknownAction:
422 result = tr("???");
423 break;
424
426 result = tr("Change Transparency");
427 break;
428
429 case ChangeColor:
430 result = tr("Change Color");
431 break;
432
433 case RandomizeColor:
434 result = tr("Randomize Color");
435 break;
436
437 case ToggleShowLabel:
438 result = tr("Toggle Label");
439 break;
440
441 case ToggleShowFilled:
442 result = tr("Toggle Show Filled");
443 break;
444
446 result = tr("Toggle Show Cube Data");
447 break;
448
450 result = tr("Toggle Show Outline");
451 break;
452
453 case MoveToTop:
454 result = tr("Bring to Front");
455 break;
456
457 case MoveUpOne:
458 result = tr("Bring Forward");
459 break;
460
461 case MoveToBottom:
462 result = tr("Send to Back");
463 break;
464
465 case MoveDownOne:
466 result = tr("Send Backward");
467 break;
468
469 case ZoomFit:
470 result = tr("Zoom Fit");
471 break;
472 }
473
474 return result;
475 }
476
477
486 QString actionString) {
487 Action result = UnknownAction;
488
489 for (Action act = FirstAction;
490 result == UnknownAction && act <= LastAction;
491 act = (Action)(act + 1)) {
492 if (toString(act).toUpper() == actionString.toUpper()) {
493 result = act;
494 }
495 }
496
497 return result;
498 }
499}
static QString toRGBAString(QColor)
Convert a QColor to its QString.
Definition Color.cpp:38
static QColor fromRGBAString(QString)
Converts a QString to its QColor.
Definition Color.cpp:21
This is the GUI communication mechanism for cubes.
@ ShowLabel
True if the cube should show its display name (bool)
@ ShowFill
True if the cube should show a fill area if possible (bool)
@ ShowDNs
True if the cube should show DN values if possible (bool)
@ ShowOutline
True if the cube should be outlined (bool)
This represents a cube in a project-based GUI interface.
Definition Image.h:107
ImageDisplayProperties * displayProperties()
Get the display (GUI) properties (information) associated with this image.
Definition Image.cpp:320
Work orders that can be performed on an image list that modifies internal state.
static Action fromActionString(QString)
Convert a string to an action.
static QString toString(Action)
Convert an action to a string.
ImageListActionWorkOrder(Project *project)
Construct a work order for the given project.
bool setupExecution()
If needed, prompt the user for input and save it.
bool isExecutable(ImageList *images)
Check if the work order can run on a given image list.
ImageListActionWorkOrder * clone() const
Clone the current work order.
void setData(ImageList *images)
Assign an image list to the work order.
void execute()
Perform the action stored in the work order and update the work order's internal data with the result...
static QString qualifyString(QString unqualifiedString, ImageList *)
Determine whether a toggle action should show or hide.
void undoExecution()
Undo the action stored in the work order and update the work order's internal data with the results o...
Action
Type of action to be performed by the work order.
@ ToggleShowOutline
Show or hide each image's outline.
@ MoveToBottom
Move the image to the back.
@ ChangeTransparency
Change the alpha values of the image list.
@ ToggleShowFilled
Show or hide each image's fill area.
@ ChangeColor
Change the color values of the image list.
@ ToggleShowCubeData
Show or hide each image's DNs.
@ MoveDownOne
Move the image backward.
@ ZoomFit
Zoom in on the image so that it fits the screen.
@ MoveToTop
Move the image to the front.
@ ToggleShowLabel
Show or hide each image's display name.
@ RandomizeColor
Set each image in the list to a random color.
Internalizes a list of images and allows for operations on the entire list.
Definition ImageList.h:55
void applyShowOutline(QStringList showOutlineValues)
Sets the visibility of the outlines of the images in the image list based on a list of values.
void applyShowDNs(QStringList showDNsValues)
Sets the visibility of the DNs of the images in the image list based on a list of values.
void applyAlphas(QStringList alphaValues)
Sets the alpha values of the images based on a list of values.
void applyShowLabel(QStringList showLabelValues)
Sets the visibility of the display names of the images in the image list based on a list of values.
void applyColors(QStringList colorValues, int column=0)
Sets the colors values of the images based on a list of values.
bool askAlpha(int *alphaResult) const
Prompts the user for an alpha value.
bool askNewColor(QColor *colorResult) const
Prompts the user for color values.
void applyShowFill(QStringList showFillValues)
Sets the visibility of the fill areas of the images in the image list based on a list of values.
The main project for ipce.
Definition Project.h:289
Provide Undo/redo abilities, serialization, and history for an operation.
Definition WorkOrder.h:311
bool m_isSavedToHistory
Set the work order to be shown in the HistoryTreeWidget.
Definition WorkOrder.h:537
virtual void setData(Context)
Sets the context data for this WorkOrder.
virtual bool setupExecution()
This sets up the state for the work order.
QStringList internalData() const
Gets the internal data for this WorkOrder.
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
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
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition IString.cpp:93