USGS

Isis 3.0 Object Programmers' Reference

Home

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", Qt::NoPen);
74  m_styleCombo->addItem("Solid Line", Qt::SolidLine);
75  m_styleCombo->addItem("Dash Line", Qt::DashLine);
76  m_styleCombo->addItem("Dot Line", Qt::DotLine);
77  m_styleCombo->addItem("Dash Dot Line", Qt::DashDotLine);
78  m_styleCombo->addItem("Dash Dot Dot Line", 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  QwtSymbol newSymbol( m_plotCurve->markerSymbol() );
199  newSymbol.setStyle(symbolStyle);
200  m_plotCurve->setMarkerSymbol(newSymbol);
201 
202  m_plotCurve->show();
203  m_plotCurve->plot()->replot();
204 
205  // When user hits Apply, the current curve will still be selected
206  // can't use m_curvesCombo->currentIndex() - CubePlotCurve instantiates this config dialog
207  // without a combo box
209  }
210 
211 
217  // ensure that the m_selectedCurve index is in bounds
218  if (m_selectedCurve > m_plotCurvesList.size() - 1 || m_selectedCurve < 0) {
219  throw IException(IException::Programmer, "Curves combobox index out of bounds", _FILEINFO_);
220  }
221 
223 
224  setWindowTitle( "Configure " + m_plotCurve->title().text() );
225 
226  // see if the curves combo box exists in the dialog (right-clicking a curve will not create
227  // a combo box in the dialog)
228  if (m_curvesCombo) {
229  m_curvesCombo->blockSignals(true);
230  m_curvesCombo->clear();
231  // add items to combo box
232  foreach(CubePlotCurve *curve, m_plotCurvesList) {
233  m_curvesCombo->addItem( curve->title().text() );
234  }
235  m_curvesCombo->setCurrentIndex(m_selectedCurve);
236 // m_curvesCombo->setItemText( m_curvesCombo->currentIndex(), m_plotCurve->title().text() );
237  m_curvesCombo->blockSignals(false);
238  }
239 
240  m_nameEdit->setText( m_plotCurve->title().text() );
241 
242  QPalette colorPalette;
243  colorPalette.setColor( QPalette::Button, m_plotCurve->pen().color() );
244  m_colorButton->setPalette(colorPalette);
245 
246  if ( m_sizeCombo->count() ) {
247  m_sizeCombo->setCurrentIndex(0);
248  for (int i = 0; i < m_sizeCombo->count(); i++) {
249  if ( m_sizeCombo->itemData(i) == m_plotCurve->pen().width() )
250  m_sizeCombo->setCurrentIndex(i);
251  }
252  }
253 
254  if ( m_styleCombo->count() ) {
255  m_styleCombo->setCurrentIndex(0);
256  for (int i = 0; i < m_styleCombo->count(); i++) {
257  if ( m_styleCombo->itemData(i) == m_plotCurve->pen().style() )
258  m_styleCombo->setCurrentIndex(i);
259  }
260  }
261 
262  if ( m_symbolCombo->count() ) {
263  m_symbolCombo->setCurrentIndex(0);
264  for (int i = 0; i < m_symbolCombo->count(); i++) {
265  if ( m_symbolCombo->itemData(i).toInt() == m_plotCurve->markerSymbol().style() ) {
266  m_symbolCombo->setCurrentIndex(i);
267  }
268  }
269  }
270  }
271 
272 
273  void CubePlotCurveConfigureDialog::updateComboIndex(int selected) {
274  m_selectedCurve = selected;
276  }
277 
278 
279  void CubePlotCurveConfigureDialog::updateCurvesList() {
280  QList<CubePlotCurve*> newPlotCurveList = qobject_cast<PlotWindow*>(m_parent)->plotCurves();
281  // if we deleted a plot curve, the new list will be smaller in size, reset m_selectedCurve
282  if ( newPlotCurveList.size() < m_plotCurvesList.size() ) {
283  m_selectedCurve = 0;
284  }
285  m_plotCurvesList.clear();
286  m_plotCurvesList = newPlotCurveList;
287  // don't read settings if there are 0 curves in the plot window
288  if (m_plotCurvesList.size() != 0) {
290  }
291  // close the configure dialog if the last curve was deleted
292  else {
293  close();
294  }
295  }
296 
301  QPalette colorPalette( m_colorButton->palette() );
302 
303  QColor newColor = QColorDialog::getColor(
304  colorPalette.color(QPalette::Button), this);
305 
306  if( newColor.isValid() ) {
307  colorPalette.setColor(QPalette::Button, newColor);
308  m_colorButton->setPalette(colorPalette);
309  }
310  }
311 }