Isis 3 Programmer Reference
AbstractPlotTool.cpp
1 #include "IsisDebug.h"
2 
3 #include "AbstractPlotTool.h"
4 
5 #include <QComboBox>
6 #include <QHBoxLayout>
7 #include <QLabel>
8 #include <QPen>
9 #include <QStackedWidget>
10 
11 #include "Cube.h"
12 #include "CubePlotCurve.h"
13 #include "MdiCubeViewport.h"
14 #include "PlotWindow.h"
15 
16 
17 namespace Isis {
18 
28  m_selectWindowCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
29  m_selectWindowCombo->setToolTip("Select which plot window to place plot "
30  "curves.");
31  QString selectWindowWhatsThis =
32  "<b>Function:</b> This will allow the selection of a window to place new "
33  "plot curves into. Current curves in this window will be replaced by "
34  "new plot curves. You cannot paste plot curves into this window.";
35  m_selectWindowCombo->setWhatsThis(selectWindowWhatsThis);
36  m_selectWindowCombo->addItem("New Window...");
37  m_selectWindowCombo->setCurrentIndex(-1);
38  connect(m_selectWindowCombo, SIGNAL(currentIndexChanged(int)),
39  this, SLOT(selectedWindowChanged()));
40  }
41 
42 
47  if (m_selectWindowCombo) {
48  // currentIndexChanged wants to call a pure virtual method, which crashes.
49  disconnect(m_selectWindowCombo, SIGNAL(currentIndexChanged(int)),
50  this, SLOT(selectedWindowChanged()));
51 
52  for (int i = m_selectWindowCombo->count(); i >= 0; i--) {
53  QVariant windowVariant = m_selectWindowCombo->itemData(i);
54 
55  if (!windowVariant.isNull() && windowVariant.canConvert<PlotWindow *>()) {
56  PlotWindow *window = windowVariant.value<PlotWindow *>();
57  delete window;
58  window = NULL;
59  }
60  }
61  }
62  }
63 
64 
73  void AbstractPlotTool::paintViewport(MdiCubeViewport *vp, QPainter *painter) {
74  for (int i = 0; i < m_selectWindowCombo->count(); i++) {
75  QVariant windowVariant = m_selectWindowCombo->itemData(i);
76 
77  if (!windowVariant.isNull() && windowVariant.canConvert<PlotWindow *>()) {
78  PlotWindow *window = windowVariant.value<PlotWindow *>();
79  window->paint(vp, painter);
80  }
81  }
82  }
83 
84 
96  QWidget *toolBarWidget = new QWidget(parent);
97  QHBoxLayout *layout = new QHBoxLayout;
98  layout->addWidget(new QLabel("Plot Into:"));
99  layout->addWidget(m_selectWindowCombo);
100  layout->addStretch(1);
101  toolBarWidget->setLayout(layout);
102 
103  return toolBarWidget;
104  }
105 
106 
111  foreach (PlotWindow *window, plotWindows()) {
112  window->update(cubeViewport());
113  }
114  }
115 
116 
126  QList<MdiCubeViewport *> viewports;
127  MdiCubeViewport *activeViewport = cubeViewport();
128 
129  for (int i = 0; i < cubeViewportList()->size(); i++) {
130  MdiCubeViewport *viewport = (*(cubeViewportList()))[i];
131 
132  if (viewport == activeViewport ||
133  (activeViewport->isLinked() && viewport->isLinked())) {
134  viewports.append(viewport);
135  }
136  }
137 
138  return viewports;
139  }
140 
141 
148  QList<PlotWindow *> windows;
149 
150  for (int i = 0; i < m_selectWindowCombo->count(); i++) {
151  QVariant windowVariant = m_selectWindowCombo->itemData(i);
152 
153  if (!windowVariant.isNull() && windowVariant.canConvert<PlotWindow *>()) {
154  PlotWindow *window = windowVariant.value<PlotWindow *>();
155  windows.append(window);
156  }
157  }
158 
159  return windows;
160  }
161 
162 
171  int currentIndex = m_selectWindowCombo->currentIndex();
172  if (currentIndex != -1) {
173  // Selected an item in the list that isn't a window
174  if (m_selectWindowCombo->itemData(currentIndex).isNull()) {
175  addWindow();
176  ASSERT(m_selectWindowCombo->itemData(
177  m_selectWindowCombo->currentIndex()).canConvert<PlotWindow *>());
178  }
179  else if (selectedWindow(false)) {
180  selectedWindow(false)->showWindow();
181  }
182  }
183 
184  detachCurves();
185  }
186 
187 
196  // See if we need to unselect it before removing it
197  int currentWindowIndex = m_selectWindowCombo->currentIndex();
198  QVariant windowVariant = QVariant::fromValue((PlotWindow *) window);
199 
200  if (currentWindowIndex != -1) {
201  if (m_selectWindowCombo->itemData(currentWindowIndex) == windowVariant) {
202  m_selectWindowCombo->setCurrentIndex(-1);
203  }
204  }
205 
206  m_selectWindowCombo->removeItem(
207  m_selectWindowCombo->findData(windowVariant));
208 
210  }
211 
212 
226  PlotCurve::Units xUnits, PlotCurve::Units yUnits) {
227  CubePlotCurve * newCurve = new CubePlotCurve(xUnits, yUnits);
228 
229  newCurve->setTitle(name);
230  newCurve->setPen(pen);
231  newCurve->setColor(pen.color());
232 
233  return newCurve;
234  }
235 
236 
249  PlotWindow *window = NULL;
250  int curIndex = m_selectWindowCombo->currentIndex();
251 
252  if (curIndex != -1) {
253  QVariant windowVariant = m_selectWindowCombo->itemData(
254  m_selectWindowCombo->currentIndex());
255 
256  if (!windowVariant.isNull() && windowVariant.canConvert<PlotWindow *>()) {
257  window = windowVariant.value<PlotWindow *>();
258  }
259  }
260 
261  if (!window && createIfNeeded) {
262  window = addWindow();
263  }
264 
265  return window;
266  }
267 
268 
278 
279  foreach (MdiCubeViewport * viewport, allViewports) {
280  if (pc->sourceCube().contains(viewport->cube()->fileName())) {
281  viewport->repaint();
282  }
283  }
284  }
285 
286 
296  PlotWindow *newPlotWindow = createWindow();
297 
298  connect(newPlotWindow, SIGNAL(closed()),
299  newPlotWindow, SLOT(deleteLater()));
300 
301  QString originalTitle = newPlotWindow->windowTitle();
302  QString titleToTry = originalTitle;
303  bool titleUsed = false;
304  int titleNumber = 0;
305 
306  do {
307  titleNumber++;
308  if (titleNumber > 1) {
309  titleToTry = originalTitle + " " + QString::number(titleNumber);
310  }
311 
312  titleUsed = false;
313 
314  for (int i = 0; i < m_selectWindowCombo->count() && !titleUsed; i++) {
315  titleUsed = titleUsed ||
316  (m_selectWindowCombo->itemText(i) == titleToTry);
317  }
318  } while (titleUsed);
319 
320  newPlotWindow->setWindowTitle(titleToTry);
321 
322  int newItemIndex = m_selectWindowCombo->count() - 1;
323 
324  m_selectWindowCombo->setCurrentIndex(-1);
325  m_selectWindowCombo->insertItem(newItemIndex,
326  newPlotWindow->windowTitle(), QVariant::fromValue(newPlotWindow));
327  m_selectWindowCombo->setCurrentIndex(newItemIndex);
328 
329  connect(newPlotWindow, SIGNAL(destroyed(QObject *)),
330  this, SLOT(removeWindow(QObject *)));
331  connect(newPlotWindow, SIGNAL(plotChanged()),
332  this, SLOT(repaintViewports()));
333 
334  return newPlotWindow;
335  }
336 
337 
343  if (selectedWindow()) {
345  }
346  }
347 
348 
356 
357  foreach (MdiCubeViewport * viewport, allViewports) {
358  viewport->viewport()->repaint();
359  }
360  }
361 }
362 
Cube display widget for certain Isis MDI applications.
QStringList sourceCube() const
This method returns the cube view port associated with the curve.
Cube * cube() const
Definition: CubeViewport.h:348
virtual void detachCurves()=0
This will be called when the selected plot window changes.
CubeViewportList * cubeViewportList() const
Return the list of cubeviewports.
Definition: Tool.cpp:390
virtual void paint(MdiCubeViewport *vp, QPainter *painter)
Paint plot curve information onto the viewport.
QWidget * createToolBarWidget(QStackedWidget *parent)
This provides the standard plot tool options, such as selecting an active plot window.
void repaintViewports()
This method causes all of the viewports to be repainted.
virtual PlotWindow * createWindow()=0
This needs to be implemented by children to instantiate a plot window of the appropriate child class ...
virtual void updateTool()
This forwards all update calls to the plot windows.
QPointer< QComboBox > m_selectWindowCombo
This allows the user to select the active plot window.
This is a plot curve with information relating it to a particular cube or region of a cube...
Definition: CubePlotCurve.h:68
PlotWindow * addWindow()
This creates and initializes everything about a plot window.
virtual ~AbstractPlotTool()
Clean up the abstract plot tool.
bool isLinked() const
Is the viewport linked with other viewports.
void setColor(const QColor &color)
Set the color of this curve and it&#39;s markers.
Definition: PlotCurve.cpp:97
static CubePlotCurve * createCurve(QString name, QPen pen, PlotCurve::Units xUnits, PlotCurve::Units yUnits)
This is a helper method for children.
void removeWindow(QObject *)
When a user closes a window, we want to remove that window from our combo box for selecting the activ...
virtual void paintViewport(MdiCubeViewport *vp, QPainter *painter)
This method allows each plot window to paint any information it wants onto the cube viewports...
virtual void update(MdiCubeViewport *activeViewport)
This is provided to allow children to react to tool updates.
Definition: PlotWindow.cpp:197
virtual QString fileName() const
Returns the opened cube&#39;s filename.
Definition: Cube.cpp:1208
PlotWindow * selectedWindow(bool createIfNeeded=true)
Get the &#39;active&#39; plot window (the window selected by the user to contain new curves).
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void showPlotWindow()
displays the plot window
Base class for the Qisis tools.
Definition: Tool.h:81
MdiCubeViewport * cubeViewport() const
Return the current cubeviewport.
Definition: Tool.h:211
void showWindow()
Shows the plot window, and raises it to the front of any overlapping sibling widgets.
Definition: PlotWindow.cpp:185
QList< MdiCubeViewport * > viewportsToPlot()
Get a list of linked viewports that should be plotting when a new plot is requested.
AbstractPlotTool(QWidget *parent)
When you construct a plot tool, this initializes the common functionality between plot tools...
void setPen(const QPen &pen)
Sets the plot pen to the passed-in pen.
Definition: PlotCurve.cpp:340
QList< PlotWindow * > plotWindows()
Get a list of all of the instantiated plot windows.
void selectedWindowChanged()
This method is called when the window where new curves are placed is changed by the user...
Units
These are all the possible units for the x or y data in a plot curve.
Definition: PlotCurve.h:54