Isis 3 Programmer Reference
CubePlotCurveConfigureDialog.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "CubePlotCurveConfigureDialog.h"
10
11#include <iostream>
12
13#include <QCheckBox>
14#include <QColorDialog>
15#include <QComboBox>
16#include <QGridLayout>
17#include <QLabel>
18#include <QLineEdit>
19#include <QPushButton>
20
21#include <qwt_text.h>
22
23#include "CubePlotCurve.h"
24#include "IException.h"
25#include "PlotWindow.h"
26
27namespace Isis {
36 CubePlotCurve *curve, QWidget *parent) : QDialog(parent) {
37 m_plotCurve = curve;
38 m_parent = parent;
39 // initially set selected curve index to 0 (first curve)
41
42 // we can grab the CubePlotCurve QList from the parent widget (PlotWindow)
43 if (parent) {
44 connect( parent, SIGNAL( plotChanged() ),
45 this, SLOT( updateCurvesList() ) );
46 m_plotCurvesList = qobject_cast<PlotWindow *>(parent)->plotCurves();
47 }
48 else {
49 m_plotCurvesList.append(curve);
50 }
51
52 QGridLayout *optionsLayout = new QGridLayout;
53 int row = 0;
54
55 // only create a combo box if instantiating this dialog with the configure tool button
56 if (parent) {
57 QLabel *curvesLabel = new QLabel("Curves: ");
59 connect( m_curvesCombo, SIGNAL( currentIndexChanged(int) ),
60 this, SLOT( updateComboIndex(int) ) );
61 optionsLayout->addWidget(curvesLabel, row, 0);
62 optionsLayout->addWidget(m_curvesCombo, row, 1);
63 row++;
64 }
65
66 QLabel *nameLabel = new QLabel("Curve Name: ");
67 m_nameEdit = new QLineEdit( m_plotCurve->title().text() );
68 optionsLayout->addWidget(nameLabel, row, 0);
69 optionsLayout->addWidget(m_nameEdit, row, 1);
70 row++;
71
72 QLabel *colorLabel = new QLabel("Color: ");
73 m_colorButton = new QPushButton;
74 m_colorButton->setFixedWidth(25);
75 connect( m_colorButton, SIGNAL( clicked() ),
76 this, SLOT( askUserForColor() ) );
77 optionsLayout->addWidget(colorLabel, row, 0);
78 optionsLayout->addWidget(m_colorButton, row, 1);
79 row++;
80
81 QLabel *styleLabel = new QLabel("Style:");
83 m_styleCombo->addItem("No Line", static_cast<int>(Qt::NoPen));
84 m_styleCombo->addItem("Solid Line", static_cast<int>(Qt::SolidLine));
85 m_styleCombo->addItem("Dash Line", static_cast<int>(Qt::DashLine));
86 m_styleCombo->addItem("Dot Line", static_cast<int>(Qt::DotLine));
87 m_styleCombo->addItem("Dash Dot Line", static_cast<int>(Qt::DashDotLine));
88 m_styleCombo->addItem("Dash Dot Dot Line", static_cast<int>(Qt::DashDotDotLine));
89 optionsLayout->addWidget(styleLabel, row, 0);
90 optionsLayout->addWidget(m_styleCombo, row, 1);
91 row++;
92
93 QLabel *sizeLabel = new QLabel("Size:");
95 m_sizeCombo->addItem("1", 1);
96 m_sizeCombo->addItem("2", 2);
97 m_sizeCombo->addItem("3", 3);
98 m_sizeCombo->addItem("4", 4);
99 optionsLayout->addWidget(sizeLabel, row, 0);
100 optionsLayout->addWidget(m_sizeCombo, row, 1);
101 row++;
102
103 QLabel *symbolLabel = new QLabel("Symbol:");
105 m_symbolCombo->addItem("None", QwtSymbol::NoSymbol);
106
107 m_symbolCombo->addItem("Diamond", QwtSymbol::Diamond);
108 m_symbolCombo->addItem("Rectangle", QwtSymbol::Rect);
109 m_symbolCombo->addItem("Triangle", QwtSymbol::Triangle);
110 m_symbolCombo->insertSeparator( m_symbolCombo->count() );
111
112 m_symbolCombo->addItem("Down Facing Triangle", QwtSymbol::UTriangle);
113 m_symbolCombo->addItem("Up Facing Triangle", QwtSymbol::DTriangle);
114 m_symbolCombo->addItem("Left Facing Triangle", QwtSymbol::RTriangle);
115 m_symbolCombo->addItem("Right Facing Triangle", QwtSymbol::LTriangle);
116 m_symbolCombo->insertSeparator( m_symbolCombo->count() );
117
118 m_symbolCombo->addItem("Diagonal Cross (X)", QwtSymbol::XCross);
119 m_symbolCombo->addItem("Eight-Pointed Star", QwtSymbol::Star1);
120 m_symbolCombo->addItem("Ellipse", QwtSymbol::Ellipse);
121 m_symbolCombo->addItem("Hexagon", QwtSymbol::Hexagon);
122 m_symbolCombo->addItem("Horizontal Line", QwtSymbol::HLine);
123 m_symbolCombo->addItem("Plus Sign (+)", QwtSymbol::Cross);
124 m_symbolCombo->addItem("Six-Pointed Star", QwtSymbol::Star2);
125 m_symbolCombo->addItem("Vertical Line", QwtSymbol::VLine);
126 optionsLayout->addWidget(symbolLabel, row, 0);
127 optionsLayout->addWidget(m_symbolCombo, row, 1);
128 row++;
129
130 QHBoxLayout *applyButtonsLayout = new QHBoxLayout;
131 applyButtonsLayout->addStretch();
132
133 QPushButton *okay = new QPushButton("&Ok");
134 okay->setIcon( QIcon::fromTheme("dialog-ok") );
135 connect( okay, SIGNAL( clicked() ),
136 this, SLOT( applySettingsToCurve() ) );
137 connect( okay, SIGNAL( clicked() ),
138 this, SLOT( close() ) );
139 applyButtonsLayout->addWidget(okay);
140
141 QPushButton *apply = new QPushButton("&Apply");
142 apply->setIcon( QIcon::fromTheme("dialog-ok-apply") );
143 connect( apply, SIGNAL( clicked() ),
144 this, SLOT( applySettingsToCurve() ) );
145 applyButtonsLayout->addWidget(apply);
146
147 QPushButton *cancel = new QPushButton("&Cancel");
148 cancel->setIcon( QIcon::fromTheme("dialog-cancel") );
149 connect( cancel, SIGNAL( clicked() ),
150 this, SLOT( close() ) );
151 applyButtonsLayout->addWidget(cancel);
152
153 QWidget *optionsHolder = new QWidget;
154 optionsHolder->setLayout(optionsLayout);
155
156 QWidget *applyButtonsHolder = new QWidget;
157 applyButtonsHolder->setLayout(applyButtonsLayout);
158
159 QVBoxLayout *mainLayout = new QVBoxLayout;
160 mainLayout->addWidget(optionsHolder);
161 mainLayout->addWidget(applyButtonsHolder);
162
163 setLayout(mainLayout);
164
166 }
167
168
177
178
185 if ( m_plotCurve->title() != m_nameEdit->text() ) {
186 m_plotCurve->enableAutoRenaming(false);
187 m_plotCurve->setTitle( m_nameEdit->text() );
188 }
189
190 QPalette colorPalette( m_colorButton->palette() );
191
192 QPen curvePen;
193 curvePen.setColor( colorPalette.color(QPalette::Button) );
194
195 int penWidth = m_sizeCombo->itemData( m_sizeCombo->currentIndex() ).toInt();
196 curvePen.setWidth(penWidth);
197
198 Qt::PenStyle penStyle = (Qt::PenStyle)m_styleCombo->itemData(
199 m_styleCombo->currentIndex() ).toInt();
200 curvePen.setStyle(penStyle);
201
202 m_plotCurve->setPen(curvePen);
203 m_plotCurve->setColor( colorPalette.color(QPalette::Button) );
204
205
206 QwtSymbol::Style symbolStyle = (QwtSymbol::Style)m_symbolCombo->itemData(
207 m_symbolCombo->currentIndex() ).toInt();
208 m_plotCurve->setMarkerSymbol(symbolStyle);
209
210 m_plotCurve->show();
211 m_plotCurve->plot()->replot();
212
213 // When user hits Apply, the current curve will still be selected
214 // can't use m_curvesCombo->currentIndex() - CubePlotCurve instantiates this config dialog
215 // without a combo box
217 }
218
219
225 // ensure that the m_selectedCurve index is in bounds
226 if (m_selectedCurve > m_plotCurvesList.size() - 1 || m_selectedCurve < 0) {
227 throw IException(IException::Programmer, "Curves combobox index out of bounds", _FILEINFO_);
228 }
229
231
232 setWindowTitle( "Configure " + m_plotCurve->title().text() );
233
234 // see if the curves combo box exists in the dialog (right-clicking a curve will not create
235 // a combo box in the dialog)
236 if (m_curvesCombo) {
237 m_curvesCombo->blockSignals(true);
238 m_curvesCombo->clear();
239 // add items to combo box
240 foreach(CubePlotCurve *curve, m_plotCurvesList) {
241 m_curvesCombo->addItem( curve->title().text() );
242 }
243 m_curvesCombo->setCurrentIndex(m_selectedCurve);
244// m_curvesCombo->setItemText( m_curvesCombo->currentIndex(), m_plotCurve->title().text() );
245 m_curvesCombo->blockSignals(false);
246 }
247
248 m_nameEdit->setText( m_plotCurve->title().text() );
249
250 QPalette colorPalette;
251 colorPalette.setColor( QPalette::Button, m_plotCurve->pen().color() );
252 m_colorButton->setPalette(colorPalette);
253
254 if ( m_sizeCombo->count() ) {
255 m_sizeCombo->setCurrentIndex(0);
256 for (int i = 0; i < m_sizeCombo->count(); i++) {
257 if ( m_sizeCombo->itemData(i) == m_plotCurve->pen().width() )
258 m_sizeCombo->setCurrentIndex(i);
259 }
260 }
261
262 if ( m_styleCombo->count() ) {
263 m_styleCombo->setCurrentIndex(0);
264 for (int i = 0; i < m_styleCombo->count(); i++) {
265 if ( m_styleCombo->itemData(i) == static_cast<int>(m_plotCurve->pen().style()) )
266 m_styleCombo->setCurrentIndex(i);
267 }
268 }
269
270 if ( m_symbolCombo->count() ) {
271 m_symbolCombo->setCurrentIndex(0);
272 for (int i = 0; i < m_symbolCombo->count(); i++) {
273 if ( m_symbolCombo->itemData(i).toInt() == m_plotCurve->markerSymbol()->style() ) {
274 m_symbolCombo->setCurrentIndex(i);
275 }
276 }
277 }
278 }
279
280
281 void CubePlotCurveConfigureDialog::updateComboIndex(int selected) {
282 m_selectedCurve = selected;
284 }
285
286
287 void CubePlotCurveConfigureDialog::updateCurvesList() {
288 QList<CubePlotCurve*> newPlotCurveList = qobject_cast<PlotWindow*>(m_parent)->plotCurves();
289 // if we deleted a plot curve, the new list will be smaller in size, reset m_selectedCurve
290 if ( newPlotCurveList.size() < m_plotCurvesList.size() ) {
291 m_selectedCurve = 0;
292 }
293 m_plotCurvesList.clear();
294 m_plotCurvesList = newPlotCurveList;
295 // don't read settings if there are 0 curves in the plot window
296 if (m_plotCurvesList.size() != 0) {
298 }
299 // close the configure dialog if the last curve was deleted
300 else {
301 close();
302 }
303 }
304
309 QPalette colorPalette( m_colorButton->palette() );
310
311 QColor newColor = QColorDialog::getColor(
312 colorPalette.color(QPalette::Button), this);
313
314 if( newColor.isValid() ) {
315 colorPalette.setColor(QPalette::Button, newColor);
316 m_colorButton->setPalette(colorPalette);
317 }
318 }
319}
void applySettingsToCurve()
This takes the configuration settings and applies them to the plot curve.
void askUserForColor()
This prompts the user to select a new color for the curve/curve markers.
CubePlotCurveConfigureDialog(CubePlotCurve *curve, QWidget *parent=NULL)
This instantiates a configuration dialog associated with the given cube plot curve.
QPointer< QComboBox > m_curvesCombo
The selection/combo box for the cube plot curve.
QList< CubePlotCurve * > m_plotCurvesList
The list of plot curves to configure.
QPointer< CubePlotCurve > m_plotCurve
The current plot curve to configure.
QPointer< QComboBox > m_sizeCombo
The selection/combo box for the cube plot curve's size/thickness.
QPointer< QWidget > m_parent
The parent widget of the configuration dialog.
virtual ~CubePlotCurveConfigureDialog()
This destroys the configuration dialog, which happens when the user closes it or clicks ok or cancel.
QPointer< QComboBox > m_symbolCombo
The selection/combo box for the cube plot curve's marker style.
QPointer< QPushButton > m_colorButton
The button for changing the cube plot curve's color.
QPointer< QLineEdit > m_nameEdit
The line edit containing the cube plot curve's name.
int m_selectedCurve
The index of the selected curve in m_curvesCombo.
void readSettingsFromCurve()
This takes the current data inside of the plot curve and populates this configuration dialog's widget...
QPointer< QComboBox > m_styleCombo
The selection/combo box for the cube plot curve's line style.
This is a plot curve with information relating it to a particular cube or region of a cube.
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
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