PickTable.cxx
Go to the documentation of this file.
1 
12 #include "PickTable.h"
13 
15 #include "datareps/DataRep.h"
17 #include "datasrcs/NTuple.h"
18 #include "datasrcs/NTupleSorter.h"
19 #include "graphics/SymbolType.h"
20 #include "plotters/PlotterBase.h"
21 
22 #if QT_VERSION < 0x040000
23 #include <qheader.h>
24 #include <qlistview.h>
25 #else
26 #include <q3header.h>
27 #include <q3listview.h>
28 #endif
29 
30 #include <qlineedit.h>
31 #include <qpushbutton.h>
32 #include <qlabel.h>
33 #include <qcheckbox.h>
34 
35 using std::string;
36 using std::vector;
37 
38 using namespace hippodraw;
39 
41 PickTable ( PlotterBase * plotter )
42 {
43  m_target = plotter;
44 
45  NTuple * ntuple = plotter -> createPickTuple ();
46  m_sorter = new NTupleSorter ( ntuple );
47 
48  const string & name = ntuple -> getName ();
49  m_title->setText ( name.c_str() );
50 
51  const DataRep * rep = plotter->getDataRep ( 0 );
52  const string & type = rep -> name ();
53 
54  string text = "Plot type : ";
55  text += type.c_str();
56  m_type->setText ( text.c_str() );
57 
58  const vector < string > & labels = ntuple -> getLabels ();
59  m_pick_table->setColumnText ( 1, labels[1].c_str() );
60  m_pick_table->setColumnText ( 2, labels[2].c_str() );
61  unsigned int size = ntuple -> columns ();
62  m_column = size;
63  if ( size == 3 ) {
64  m_pick_table -> removeColumn ( 3 );
65  zLineEdit -> setEnabled ( false );
66  wLineEdit -> setEnabled ( false );
67  }
68  else {
69  m_pick_table -> setColumnText ( 3, labels[3].c_str() );
70  if ( size == 5 ) {
71  const QString & str ( labels[4].c_str() );
72  m_pick_table -> addColumn ( str );
73  }
74  else wLineEdit -> setEnabled ( false );
75  }
76 
78 
79 #if QT_VERSION < 0x040000
80  QHeader * header = m_pick_table->header();
81 #else
82  Q3Header * header = m_pick_table->header();
83 #endif
84  connect ( header, SIGNAL ( clicked (int) ),
85  this, SLOT( listSorted ( int ) ) );
86  m_pick_table->setSorting ( -1 );
88  m_delete -> setEnabled ( false );
89 
90  // Picked points are show by default.
91  addDataRep();
92 }
93 
94 void
96 listSorted ( int i )
97 {
98  m_sorter -> setSorting ( i );
99  m_sorter -> sort ( );
100 
101 #if QT_VERSION < 0x040000
103 #else
104  Q3ListViewItem * item = m_pick_table ->selectedItem ();
105 #endif
106  QString text = item -> text ( 0 );
107  unsigned int selected = text.toUInt ();
108 
109  refreshItems ( selected );
110 }
111 
113 {
114  m_pick_table->clear();
115  m_sorter->clear();
116 }
117 
118 void
120 addItem ( std::vector < double > & v )
121 {
122  unsigned int row = m_sorter -> rows ();
123  v[0] = row;
124  m_sorter -> addRow ( v );
125 
126  refreshItems ( row );
127 }
128 
129 void
131 refreshItems ( unsigned int select )
132 {
133  m_pick_table -> clear();
134 
135  unsigned int row = m_sorter->rows ();
136  bool yes = row > 0;
137  m_delete -> setEnabled ( yes );
138 
139  while ( row-- != 0 ) {
140  const vector < double > & vec = m_sorter->getRow ( row );
141  unsigned int current = static_cast < unsigned int > ( vec[0] );
142 #if QT_VERSION < 0x040000
144 #else
145  Q3ListViewItem * item = new Q3ListViewItem ( m_pick_table );
146 #endif
147  unsigned int size = vec.size();
148 
149  for ( unsigned int i = 0; i < size; i++ ) {
150  item -> setText ( i, QString ( "%1" ).arg ( vec[i] ) );
151  }
152 
153  m_pick_table -> insertItem ( item );
154 
155  if ( select == current ) {
156  m_pick_table -> setSelected ( item, true );
157  m_pick_table -> ensureItemVisible ( item );
158  }
159  }
160 }
161 
162 unsigned int
163 PickTable::
164 #if QT_VERSION < 0x040000
165 indexOf ( QListViewItem * target )
166 #else
167 indexOf ( Q3ListViewItem * target )
168 #endif
169 {
170  unsigned int index = 0;
171 #if QT_VERSION < 0x040000
172  QListViewItem * item = m_pick_table -> firstChild ();
173 #else
174  Q3ListViewItem * item = m_pick_table -> firstChild ();
175 #endif
176  while ( item != target ) {
177  index++;
178  item = item->nextSibling();
179  if ( item == 0 ) break;
180  }
181 
182  return index;
183 }
184 
186 {
187 #if QT_VERSION < 0x040000
189 #else
190  Q3ListViewItem * item = m_pick_table->selectedItem ();
191 #endif
192  if ( item != 0 ) {
193  unsigned int index = indexOf ( item );
194 
195  m_sorter->eraseRow ( index );
196 
197  unsigned int row = index == 0 ? 0 : index - 1;
198  refreshItems ( row );
199  }
200 }
201 
202 void
205 {
206  const string plotTypeStr ( "Scatter Plot" );
207  NTuple * ntuple = m_sorter -> getNTuple ();
208  const vector < string > & labels = ntuple -> getLabels ();
209  vector < string > bindings;
210  bindings.push_back ( labels[1] );
211  bindings.push_back ( labels[2] );
212  if ( labels.size() == 4 ) {
213  if ( labels[3] == "Density" ) {
214  bindings[1] = "Density";
215  }
216  }
217 
219  DataRep * rep
220  = controller -> addDataRep ( m_target, plotTypeStr,
221  ntuple, bindings );
222  m_datarep = rep;
223 
224  const Color red ( Color::red );
225  rep -> setRepColor ( red );
226  rep -> setRepStyle ( Symbol::CIRCLE );
227  rep -> setRepSize ( 6.0 );
228 }
229 
230 void
233 {
234 #if QT_VERSION < 0x040000
235  QListViewItem * item = m_pick_table -> selectedItem ();
236 #else
237  Q3ListViewItem * item = m_pick_table -> selectedItem ();
238 #endif
239  bool yes = item != 0;
240 
241  m_delete -> setEnabled ( yes );
242 }
243 
244 NTuple *
246 getPickTable () const
247 {
248  NTuple * ntuple = m_sorter -> getNTuple ();
249  return ntuple;
250 }
251 
252 void
255 {
256  vector <double> new_entry;
257  double x=xLineEdit->text().toDouble();
258  double y=yLineEdit->text().toDouble();
259  new_entry.push_back(3.0);
260  new_entry.push_back(x);
261  new_entry.push_back(y);
262 
263  if ( m_column > 3 ){
264  double z=zLineEdit->text().toDouble();
265  new_entry.push_back(z);
266  }
267  if ( m_column == 5 ){
268  double w=wLineEdit->text().toDouble();
269  new_entry.push_back(w);
270  }
271 
272  addItem(new_entry);
273 }
274 
275 void
278 {
279  bool show = m_pickedCheckBox->isChecked();
280  if (show) addDataRep();
281  else m_target -> removeDataRep ( m_datarep );
282 }
selectedItem() const
unsigned int i
DataRep * m_datarep
The DataRep of picked points.
Definition: PickTable.h:69
A singleton class that is the interface between GUI and the displays.
setColumnText(int column, const QString &label)
QListViewItem * item
Definition: PickTable.cxx:172
QLineEdit * zLineEdit
Definition: PickTableBase.h:45
void addItem(std::vector< double > &v)
Adds a new point to the pick NTuple and the PickTable&#39;s window.
Definition: PickTable.cxx:120
isChecked() const
text() const
QLineEdit * wLineEdit
Definition: PickTableBase.h:46
virtual void addEntry()
Responds to addEntry button.
Definition: PickTable.cxx:254
A helper class to sort and keep sorted an NTuple.
Definition: NTupleSorter.h:32
hippodraw::DataRep class interface.
unsigned int m_column
The number of columns of the pick table.
Definition: PickTable.h:66
QCheckBox * m_pickedCheckBox
Definition: PickTableBase.h:42
virtual void clear()
Responds to the &#39;clear&#39; button click.
Definition: PickTable.cxx:112
setText(const QString &)
QLabel * m_type
Definition: PickTableBase.h:37
NTupleSorter class interface.
return rep
Definition: Inspector.cxx:3843
PlotterBase * m_target
The target PlotterBase object.
Definition: PickTable.h:62
QLineEdit * xLineEdit
Definition: PickTableBase.h:43
NTuple * getPickTable() const
Gets the pick table as a NTuple.
Definition: PickTable.cxx:246
return yes
Definition: CanvasView.cxx:883
setSorting(int column, bool ascending=TRUE)
A Color class for creating the color object following the standard RGB color space.
Definition: Color.h:37
virtual void deleteSelectedItem()
Responds to the &#39;Delete Selected Item&#39; button click.
Definition: PickTable.cxx:185
hippodraw::NTuple class interface.
The base class for the PlotterBase hierarchy.
Definition: PlotterBase.h:55
PyArray_TYPES type(numeric::array arr)
Definition: num_util.cpp:249
The base class for data representations.
Definition: DataRep.h:68
virtual void eraseRow(unsigned int index)
Erases a row from the NTuple.
SymbolType enumeration.
QPushButton * m_delete
Definition: PickTableBase.h:39
ViewBase * v
Definition: PlotTable.cxx:104
intp size(numeric::array arr)
Definition: num_util.cpp:296
void clear()
Clears the NTuple.
virtual void listSorted(int)
Sorts the table.
Definition: PickTable.cxx:96
setShowSortIndicator(bool show)
hippodraw::PickTable class interface
NTupleSorter * m_sorter
The object that maintains the NTuple of picked data points.
Definition: PickTable.h:57
static DisplayController * instance()
Returns the pointer to the singleton instance.
virtual DataRep * getDataRep(int index) const
Returns the specified DataRep or null pointer if it doesn&#39;t exits.
A DataSource class implemented with std::vector&lt;double&gt; to store the column data. ...
Definition: NTuple.h:33
void refreshItems(unsigned int select)
Refreshes the view of all the items.
Definition: PickTable.cxx:131
QListView * m_pick_table
Definition: PickTableBase.h:41
std::string registerNTuple(DataSource *nt)
Register a DataSource.
PickTable(PlotterBase *plotter)
A constructor.
Definition: PickTable.cxx:41
virtual void pickedCheckBoxClicked()
Responds to the &#39;Show picked points&#39; check box click.
Definition: PickTable.cxx:277
return index
Definition: PickTable.cxx:182
header() const
QLineEdit * yLineEdit
Definition: PickTableBase.h:44
A derived class of PickTableBase class which is generated by the Qt designer.
Definition: PickTable.h:46
DataSourceController class interface.
void addDataRep()
Add DataRep object, called by constructor or show picked points check box.
Definition: PickTable.cxx:204
QLabel * m_title
Definition: PickTableBase.h:40
DisplayController class interface declaration.
virtual void m_pick_table_selectionChanged()
Responds to change of selection in the QListView.
Definition: PickTable.cxx:232
unsigned int rows() const
Returns the number of rows of the NTuple.
hippodraw::PlotterBase class interface.
toUInt(bool *ok=0, int base=10) const
unsigned int indexOf(QListViewItem *target)
Finds the index of the target QListViewItem.
static DataSourceController * instance()
Returns the pointer to the singleton instance.
const std::vector< double > & getRow(unsigned int index) const
Returns a reference to the index row of the sorted NTuple.

Generated for HippoDraw Class Library by doxygen