USGS

Isis 3.0 Object Programmers' Reference

Home

ImageListActionWorkOrder.cpp
1 #include "ImageListActionWorkOrder.h"
2 
3 #include <QMessageBox>
4 
5 #include "Color.h"
6 #include "ImageList.h"
7 #include "Project.h"
8 
9 namespace Isis {
10  ImageListActionWorkOrder::ImageListActionWorkOrder(Project *project) :
11  WorkOrder(project) {
12  }
13 
14 
15  ImageListActionWorkOrder::ImageListActionWorkOrder(Action action, Project *project) :
16  WorkOrder(project) {
17  QAction::setText(toString(action));
18  QUndoCommand::setText(toString(action));
19 
20  QStringList internalData;
21  internalData.append(toString(action));
22  setInternalData(internalData);
23  }
24 
25 
26  ImageListActionWorkOrder::ImageListActionWorkOrder(
27  const ImageListActionWorkOrder &other) : WorkOrder(other) {
28  foreach (const Image *image, *other.imageList()) {
29  connect(this, SIGNAL(bringToFront()), image->displayProperties(), SIGNAL(moveToTop()));
30  }
31  }
32 
33 
34  ImageListActionWorkOrder::~ImageListActionWorkOrder() {
35  }
36 
37 
42  return new ImageListActionWorkOrder(*this);
43  }
44 
45 
50  return !images->isEmpty();
51  }
52 
53 
58  WorkOrder::setData(images);
59 
60  if (internalData().count()) {
61  QAction::setText(qualifyString(internalData()[0], imageList()));
62 
63  QString modifiedString = (qualifyString(internalData()[0], imageList()) + " on %1 images")
64  .arg(imageList()->count());
65  QUndoCommand::setText(modifiedString);
66  }
67 
68  foreach (Image *image, *images) {
69  connect(this, SIGNAL(bringToFront()), image->displayProperties(), SIGNAL(moveToTop()));
70  }
71  }
72 
73 
78  bool result = WorkOrder::execute() && !internalData().isEmpty();
79 
80  if (!internalData().isEmpty()) {
81  QStringList state = internalData();
82  QString actionString = internalData()[0];
83 
84  switch(fromActionString(actionString)) {
85  case UnknownAction:
86  result = false;
87  break;
88 
89  case ChangeTransparency: {
90  int alpha = 255;
91  result = imageList()->askAlpha(&alpha);
92  state.append(QString::number(alpha));
93  break;
94  }
95 
96  case ChangeColor: {
97  QColor color;
98  result = imageList()->askNewColor(&color);
99 
100  // QColor::name() doesn't preserve alpha.
101  if (color.isValid()) {
102  state.append(Color::toRGBAString(color));
103  }
104  break;
105  }
106 
107  case RandomizeColor:
108  break;
109 
110  case ToggleShowLabel: {
111  int maxRecommendedLabels = 2000;
112  if (qualifyString(actionString, imageList()).startsWith(tr("Show")) &&
113  imageList()->count() > maxRecommendedLabels) {
114  QMessageBox::StandardButton selectedOpt = QMessageBox::warning(NULL,
115  tr("Potentially Slow Operation"),
116  tr("You are asking to show the labels on %L1 images. When viewing these images in "
117  "a 2D footprint view, these images will take at least 3x longer to render. This "
118  "is a significant performance loss. Showing more than a few labels at a time is "
119  "not recommended. Are you sure you want to show the labels on these %L1 images?")
120  .arg(imageList()->count()),
121  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
122 
123  if (selectedOpt == QMessageBox::No) {
124  result = false;
125  }
126  }
127  break;
128  }
129 
130  case ToggleShowFilled:
131  break;
132 
133  case ToggleShowCubeData:
134  break;
135 
136  case ToggleShowOutline:
137  break;
138  }
139 
140  setInternalData(state);
141  }
142 
143  return result;
144  }
145 
146 
151  QStringList state = internalData();
152  QString actionString = internalData()[0];
153 
154  switch(fromActionString(actionString)) {
155  case UnknownAction:
156  break;
157 
158  case ChangeTransparency:
159  state = state.mid(0, 2);
160  state.append(imageList()->saveAndApplyAlpha(state[1].toInt()));
161  break;
162 
163  case ChangeColor:
164  state = state.mid(0, 2);
165  state.append(imageList()->saveAndApplyColor(Color::fromRGBAString(state[1])));
166  break;
167 
168  case RandomizeColor:
169  if (state.count() > 1) {
170  // Apply previously randomly generated colors if available
171  imageList()->applyColors(state.mid(1), 1);
172  }
173  else {
174  state.append(imageList()->saveAndApplyRandomColor());
175  }
176  break;
177 
178  case ToggleShowLabel:
179  state = state.mid(0, 1);
180  state.append(imageList()->saveAndToggleShowLabel());
181  break;
182 
183  case ToggleShowFilled:
184  state = state.mid(0, 1);
185  state.append(imageList()->saveAndToggleShowFill());
186  break;
187 
188  case ToggleShowCubeData:
189  state = state.mid(0, 1);
190  state.append(imageList()->saveAndToggleShowDNs());
191  break;
192 
193  case ToggleShowOutline:
194  state = state.mid(0, 1);
195  state.append(imageList()->saveAndToggleShowOutline());
196  break;
197  }
198 
199  setInternalData(state);
200  }
201 
202 
204  QStringList state = internalData();
205  QString actionString = internalData()[0];
206 
207  switch(fromActionString(actionString)) {
208  case UnknownAction:
209  break;
210 
211  case ChangeTransparency:
212  imageList()->applyAlphas(state.mid(2));
213  break;
214 
215  case ChangeColor:
216  imageList()->applyColors(state.mid(2));
217  break;
218 
219  case RandomizeColor:
220  // Apply colors before randomization occurred
221  imageList()->applyColors(state.mid(1), 0);
222  break;
223 
224  case ToggleShowLabel:
225  imageList()->applyShowLabel(state.mid(1));
226  break;
227 
228  case ToggleShowFilled:
229  imageList()->applyShowFill(state.mid(1));
230  break;
231 
232  case ToggleShowCubeData:
233  imageList()->applyShowDNs(state.mid(1));
234  break;
235 
236  case ToggleShowOutline:
237  imageList()->applyShowOutline(state.mid(1));
238  break;
239  }
240 
241  setInternalData(state);
242  }
243 
244 
245  QString ImageListActionWorkOrder::qualifyString(QString unqualifiedString,
246  ImageList *imageList) {
247  QString result = unqualifiedString;
248 
249  if (imageList && imageList->count()) {
250  ImageDisplayProperties *firstDisplay = imageList->first()->displayProperties();
251  Action act = fromActionString(unqualifiedString);
252 
253  if (act == ToggleShowLabel) {
254  if (firstDisplay->getValue(ImageDisplayProperties::ShowLabel).toBool()) {
255  result = tr("Hide Label");
256  }
257  else {
258  result = tr("Show Label");
259  }
260  }
261 
262  if (act == ToggleShowFilled) {
263  if (firstDisplay->getValue(ImageDisplayProperties::ShowFill).toBool()) {
264  result = tr("Show Unfilled");
265  }
266  else {
267  result = tr("Show Filled");
268  }
269  }
270 
271  if (act == ToggleShowCubeData) {
272  if (firstDisplay->getValue(ImageDisplayProperties::ShowDNs).toBool()) {
273  result = tr("Hide Cube Data");
274  }
275  else {
276  result = tr("Show Cube Data");
277  }
278  }
279 
280  if (act == ToggleShowOutline) {
281  if (firstDisplay->getValue(ImageDisplayProperties::ShowOutline).toBool()) {
282  result = tr("Hide Outline");
283  }
284  else {
285  result = tr("Show Outline");
286  }
287  }
288  }
289 
290  return result;
291  }
292 
293 
294  QString ImageListActionWorkOrder::toString(Action action) {
295  QString result;
296 
297  switch(action) {
298  case UnknownAction:
299  result = tr("???");
300  break;
301 
302  case ChangeTransparency:
303  result = tr("Change Transparency");
304  break;
305 
306  case ChangeColor:
307  result = tr("Change Color");
308  break;
309 
310  case RandomizeColor:
311  result = tr("Randomize Color");
312  break;
313 
314  case ToggleShowLabel:
315  result = tr("Toggle Label");
316  break;
317 
318  case ToggleShowFilled:
319  result = tr("Toggle Show Filled");
320  break;
321 
322  case ToggleShowCubeData:
323  result = tr("Toggle Show Cube Data");
324  break;
325 
326  case ToggleShowOutline:
327  result = tr("Toggle Show Outline");
328  break;
329  }
330 
331  return result;
332  }
333 
334 
335  ImageListActionWorkOrder::Action ImageListActionWorkOrder::fromActionString(
336  QString actionString) {
337  Action result = UnknownAction;
338 
339  for (Action act = UnknownAction;
340  result == UnknownAction && act <= ToggleShowOutline;
341  act = (Action)(act + 1)) {
342  if (toString(act).toUpper() == actionString.toUpper()) {
343  result = act;
344  }
345  }
346 
347  return result;
348  }
349 }