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