Isis 3 Programmer Reference
AbstractPlotTool.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include "IsisDebug.h"
10 
11 #include "AbstractPlotTool.h"
12 
13 #include <QComboBox>
14 #include <QHBoxLayout>
15 #include <QLabel>
16 #include <QPen>
17 #include <QStackedWidget>
18 
19 #include "Cube.h"
20 #include "CubePlotCurve.h"
21 #include "MdiCubeViewport.h"
22 #include "PlotWindow.h"
23 
24 
25 namespace Isis {
26 
36  m_selectWindowCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
37  m_selectWindowCombo->setToolTip("Select which plot window to place plot "
38  "curves.");
39  QString selectWindowWhatsThis =
40  "<b>Function:</b> This will allow the selection of a window to place new "
41  "plot curves into. Current curves in this window will be replaced by "
42  "new plot curves. You cannot paste plot curves into this window.";
43  m_selectWindowCombo->setWhatsThis(selectWindowWhatsThis);
44  m_selectWindowCombo->addItem("New Window...");
45  m_selectWindowCombo->setCurrentIndex(-1);
46  connect(m_selectWindowCombo, SIGNAL(currentIndexChanged(int)),
47  this, SLOT(selectedWindowChanged()));
48  }
49 
50 
55  if (m_selectWindowCombo) {
56  // currentIndexChanged wants to call a pure virtual method, which crashes.
57  disconnect(m_selectWindowCombo, SIGNAL(currentIndexChanged(int)),
58  this, SLOT(selectedWindowChanged()));
59 
60  for (int i = m_selectWindowCombo->count(); i >= 0; i--) {
61  QVariant windowVariant = m_selectWindowCombo->itemData(i);
62 
63  if (!windowVariant.isNull() && windowVariant.canConvert<PlotWindow *>()) {
64  PlotWindow *window = windowVariant.value<PlotWindow *>();
65  delete window;
66  window = NULL;
67  }
68  }
69  }
70  }
71 
72 
81  void AbstractPlotTool::paintViewport(MdiCubeViewport *vp, QPainter *painter) {
82  for (int i = 0; i < m_selectWindowCombo->count(); i++) {
83  QVariant windowVariant = m_selectWindowCombo->itemData(i);
84 
85  if (!windowVariant.isNull() && windowVariant.canConvert<PlotWindow *>()) {
86  PlotWindow *window = windowVariant.value<PlotWindow *>();
87  window->paint(vp, painter);
88  }
89  }
90  }
91 
92 
104  QWidget *toolBarWidget = new QWidget(parent);
105  QHBoxLayout *layout = new QHBoxLayout;
106  layout->addWidget(new QLabel("Plot Into:"));
107  layout->addWidget(m_selectWindowCombo);
108  layout->addStretch(1);
109  toolBarWidget->setLayout(layout);
110 
111  return toolBarWidget;
112  }
113 
114 
119  foreach (PlotWindow *window, plotWindows()) {
120  window->update(cubeViewport());
121  }
122  }
123 
124 
134  QList<MdiCubeViewport *> viewports;
135  MdiCubeViewport *activeViewport = cubeViewport();
136 
137  for (int i = 0; i < cubeViewportList()->size(); i++) {
138  MdiCubeViewport *viewport = (*(cubeViewportList()))[i];
139 
140  if (viewport == activeViewport ||
141  (activeViewport->isLinked() && viewport->isLinked())) {
142  viewports.append(viewport);
143  }
144  }
145 
146  return viewports;
147  }
148 
149 
156  QList<PlotWindow *> windows;
157 
158  for (int i = 0; i < m_selectWindowCombo->count(); i++) {
159  QVariant windowVariant = m_selectWindowCombo->itemData(i);
160 
161  if (!windowVariant.isNull() && windowVariant.canConvert<PlotWindow *>()) {
162  PlotWindow *window = windowVariant.value<PlotWindow *>();
163  windows.append(window);
164  }
165  }
166 
167  return windows;
168  }
169 
170 
179  int currentIndex = m_selectWindowCombo->currentIndex();
180  if (currentIndex != -1) {
181  // Selected an item in the list that isn't a window
182  if (m_selectWindowCombo->itemData(currentIndex).isNull()) {
183  addWindow();
184  ASSERT(m_selectWindowCombo->itemData(
185  m_selectWindowCombo->currentIndex()).canConvert<PlotWindow *>());
186  }
187  else if (selectedWindow(false)) {
188  selectedWindow(false)->showWindow();
189  }
190  }
191 
192  detachCurves();
193  }
194 
195 
204  // See if we need to unselect it before removing it
205  int currentWindowIndex = m_selectWindowCombo->currentIndex();
206  QVariant windowVariant = QVariant::fromValue((PlotWindow *) window);
207 
208  if (currentWindowIndex != -1) {
209  if (m_selectWindowCombo->itemData(currentWindowIndex) == windowVariant) {
210  m_selectWindowCombo->setCurrentIndex(-1);
211  }
212  }
213 
214  m_selectWindowCombo->removeItem(
215  m_selectWindowCombo->findData(windowVariant));
216 
218  }
219 
220 
234  PlotCurve::Units xUnits, PlotCurve::Units yUnits) {
235  CubePlotCurve * newCurve = new CubePlotCurve(xUnits, yUnits);
236 
237  newCurve->setTitle(name);
238  newCurve->setPen(pen);
239  newCurve->setColor(pen.color());
240 
241  return newCurve;
242  }
243 
244 
257  PlotWindow *window = NULL;
258  int curIndex = m_selectWindowCombo->currentIndex();
259 
260  if (curIndex != -1) {
261  QVariant windowVariant = m_selectWindowCombo->itemData(
262  m_selectWindowCombo->currentIndex());
263 
264  if (!windowVariant.isNull() && windowVariant.canConvert<PlotWindow *>()) {
265  window = windowVariant.value<PlotWindow *>();
266  }
267  }
268 
269  if (!window && createIfNeeded) {
270  window = addWindow();
271  }
272 
273  return window;
274  }
275 
276 
286 
287  foreach (MdiCubeViewport * viewport, allViewports) {
288  if (pc->sourceCube().contains(viewport->cube()->fileName())) {
289  viewport->repaint();
290  }
291  }
292  }
293 
294 
304  PlotWindow *newPlotWindow = createWindow();
305 
306  connect(newPlotWindow, SIGNAL(closed()),
307  newPlotWindow, SLOT(deleteLater()));
308 
309  QString originalTitle = newPlotWindow->windowTitle();
310  QString titleToTry = originalTitle;
311  bool titleUsed = false;
312  int titleNumber = 0;
313 
314  do {
315  titleNumber++;
316  if (titleNumber > 1) {
317  titleToTry = originalTitle + " " + QString::number(titleNumber);
318  }
319 
320  titleUsed = false;
321 
322  for (int i = 0; i < m_selectWindowCombo->count() && !titleUsed; i++) {
323  titleUsed = titleUsed ||
324  (m_selectWindowCombo->itemText(i) == titleToTry);
325  }
326  } while (titleUsed);
327 
328  newPlotWindow->setWindowTitle(titleToTry);
329 
330  int newItemIndex = m_selectWindowCombo->count() - 1;
331 
332  m_selectWindowCombo->setCurrentIndex(-1);
333  m_selectWindowCombo->insertItem(newItemIndex,
334  newPlotWindow->windowTitle(), QVariant::fromValue(newPlotWindow));
335  m_selectWindowCombo->setCurrentIndex(newItemIndex);
336 
337  connect(newPlotWindow, SIGNAL(destroyed(QObject *)),
338  this, SLOT(removeWindow(QObject *)));
339  connect(newPlotWindow, SIGNAL(plotChanged()),
340  this, SLOT(repaintViewports()));
341 
342  return newPlotWindow;
343  }
344 
345 
351  if (selectedWindow()) {
353  }
354  }
355 
356 
364 
365  foreach (MdiCubeViewport * viewport, allViewports) {
366  viewport->viewport()->repaint();
367  }
368  }
369 }
Isis::AbstractPlotTool::addWindow
PlotWindow * addWindow()
This creates and initializes everything about a plot window.
Definition: AbstractPlotTool.cpp:303
Isis::AbstractPlotTool::updateTool
virtual void updateTool()
This forwards all update calls to the plot windows.
Definition: AbstractPlotTool.cpp:118
Isis::PlotWindow::showWindow
void showWindow()
Shows the plot window, and raises it to the front of any overlapping sibling widgets.
Definition: PlotWindow.cpp:185
Isis::MdiCubeViewport
Cube display widget for certain Isis MDI applications.
Definition: MdiCubeViewport.h:39
Isis::AbstractPlotTool::m_selectWindowCombo
QPointer< QComboBox > m_selectWindowCombo
This allows the user to select the active plot window.
Definition: AbstractPlotTool.h:98
QWidget
Isis::Cube::fileName
virtual QString fileName() const
Returns the opened cube's filename.
Definition: Cube.cpp:1563
Isis::AbstractPlotTool::createCurve
static CubePlotCurve * createCurve(QString name, QPen pen, PlotCurve::Units xUnits, PlotCurve::Units yUnits)
This is a helper method for children.
Definition: AbstractPlotTool.cpp:233
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis::AbstractPlotTool::~AbstractPlotTool
virtual ~AbstractPlotTool()
Clean up the abstract plot tool.
Definition: AbstractPlotTool.cpp:54
Isis::AbstractPlotTool::removeWindow
void removeWindow(QObject *)
When a user closes a window, we want to remove that window from our combo box for selecting the activ...
Definition: AbstractPlotTool.cpp:203
Isis::CubePlotCurve
This is a plot curve with information relating it to a particular cube or region of a cube.
Definition: CubePlotCurve.h:53
Isis::Tool::cubeViewportList
CubeViewportList * cubeViewportList() const
Return the list of cubeviewports.
Definition: Tool.cpp:390
Isis::Tool
Base class for the Qisis tools.
Definition: Tool.h:67
Isis::PlotCurve::setPen
void setPen(const QPen &pen)
Sets the plot pen to the passed-in pen.
Definition: PlotCurve.cpp:340
Isis::AbstractPlotTool::paintViewport
virtual void paintViewport(MdiCubeViewport *vp, QPainter *painter)
This method allows each plot window to paint any information it wants onto the cube viewports.
Definition: AbstractPlotTool.cpp:81
Isis::AbstractPlotTool::viewportsToPlot
QList< MdiCubeViewport * > viewportsToPlot()
Get a list of linked viewports that should be plotting when a new plot is requested.
Definition: AbstractPlotTool.cpp:133
Isis::AbstractPlotTool::selectedWindow
PlotWindow * selectedWindow(bool createIfNeeded=true)
Get the 'active' plot window (the window selected by the user to contain new curves).
Definition: AbstractPlotTool.cpp:256
PlotWindow.h
Isis::PlotCurve::Units
Units
These are all the possible units for the x or y data in a plot curve.
Definition: PlotCurve.h:54
Isis::PlotWindow::update
virtual void update(MdiCubeViewport *activeViewport)
This is provided to allow children to react to tool updates.
Definition: PlotWindow.cpp:197
Isis::AbstractPlotTool::showPlotWindow
void showPlotWindow()
displays the plot window
Definition: AbstractPlotTool.cpp:350
Isis::AbstractPlotTool::plotWindows
QList< PlotWindow * > plotWindows()
Get a list of all of the instantiated plot windows.
Definition: AbstractPlotTool.cpp:155
Isis::AbstractPlotTool::selectedWindowChanged
void selectedWindowChanged()
This method is called when the window where new curves are placed is changed by the user.
Definition: AbstractPlotTool.cpp:178
QComboBox
Isis::AbstractPlotTool::AbstractPlotTool
AbstractPlotTool(QWidget *parent)
When you construct a plot tool, this initializes the common functionality between plot tools.
Definition: AbstractPlotTool.cpp:34
Isis::AbstractPlotTool::detachCurves
virtual void detachCurves()=0
This will be called when the selected plot window changes.
Isis::MdiCubeViewport::isLinked
bool isLinked() const
Is the viewport linked with other viewports.
Definition: MdiCubeViewport.h:50
Isis::CubePlotCurve::sourceCube
QStringList sourceCube() const
This method returns the cube view port associated with the curve.
Definition: CubePlotCurve.cpp:235
Isis::PlotCurve::setColor
void setColor(const QColor &color)
Set the color of this curve and it's markers.
Definition: PlotCurve.cpp:97
Isis::AbstractPlotTool::createWindow
virtual PlotWindow * createWindow()=0
This needs to be implemented by children to instantiate a plot window of the appropriate child class ...
QObject
QVector
This is free and unencumbered software released into the public domain.
Definition: Calculator.h:18
Isis::PlotWindow
Definition: PlotWindow.h:88
Isis::CubeViewport::cube
Cube * cube() const
Definition: CubeViewport.h:338
Isis::AbstractPlotTool::createToolBarWidget
QWidget * createToolBarWidget(QStackedWidget *parent)
This provides the standard plot tool options, such as selecting an active plot window.
Definition: AbstractPlotTool.cpp:103
Isis::AbstractPlotTool::repaintViewports
void repaintViewports()
This method causes all of the viewports to be repainted.
Definition: AbstractPlotTool.cpp:362
Isis::Tool::cubeViewport
MdiCubeViewport * cubeViewport() const
Return the current cubeviewport.
Definition: Tool.h:197
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::PlotWindow::paint
virtual void paint(MdiCubeViewport *vp, QPainter *painter)
Paint plot curve information onto the viewport.
Definition: PlotWindow.cpp:1787