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