QXRD  0.11.16
qcepscatterplotgraphmodel.cpp
Go to the documentation of this file.
2 #include "qcepdatagroup-ptr.h"
3 #include "qcepdatagroup.h"
5 #include "qcepintegrateddata.h"
6 
8  m_Object(object)
9 {
10  m_X.resize(1000);
11  m_Y.resize(1000);
12  m_Y2.resize(1000);
13 }
14 
16  const QModelIndex &parent) const
17 {
18  int res = 0;
19 
21 
22  if (p) {
23  QcepDataGroupPtr dg = qSharedPointerDynamicCast<QcepDataGroup>(p);
24 
25  if (dg) {
26  res = dg->childCount();
27  } else {
28  QcepIntegratedDataPtr integ = qSharedPointerDynamicCast<QcepIntegratedData>(p);
29 
30  if (integ) {
31  res = 2;
32  }
33  }
34  }
35 
36  return res;
37 }
38 
40  const QModelIndex &parent) const
41 {
42  return 4;
43 }
44 
46  int section, Qt::Orientation orientation, int role) const
47 {
48  QVariant res;
49 
50  if (orientation==Qt::Horizontal && role==Qt::DisplayRole) {
51  switch (section) {
52  case 0:
53  res = "Column";
54  break;
55 
56  case 1:
57  res = "X?";
58  break;
59 
60  case 2:
61  res = "Y?";
62  break;
63 
64  case 3:
65  res = "Y2?";
66  break;
67  }
68  }
69 
70  return res;
71 }
72 
74  const QModelIndex &index, int role) const
75 {
76  int r = index.row();
77  int c = index.column();
78 
79  QVariant res;
80 
82 
83  if (p) {
84  QcepDataGroupPtr dg = qSharedPointerDynamicCast<QcepDataGroup>(p);
85 
86  if (dg) {
87  QcepDataObjectPtr o = dg->item(r);
88 
89  if (o) {
90  if (role == Qt::DisplayRole && c == 0) {
91  res = o->objectName();
92  } else if (role == Qt::CheckStateRole) {
93  if (c == 1) {
94  res = checkState(getX(r));
95  } else if (c == 2) {
96  res = checkState(getY(r));
97  } else if (c == 3) {
98  res = checkState(getY2(r));
99  }
100  }
101  }
102  } else {
103  QcepIntegratedDataPtr integ = qSharedPointerDynamicCast<QcepIntegratedData>(p);
104 
105  if (integ) {
106  if (role == Qt::DisplayRole && c == 0) {
107  switch(r) {
108  case 0:
109  res = integ->get_XUnitsLabel();
110  break;
111 
112  case 1:
113  res = "Intensity";
114  break;
115  }
116  } else if (role == Qt::CheckStateRole) {
117  if (c == 1) {
118  res = checkState(getX(r));
119  } else if (c == 2) {
120  res = checkState(getY(r));
121  } else if (c == 3) {
122  res = checkState(getY2(r));
123  }
124  }
125  }
126  }
127  }
128 
129  return res;
130 }
131 
132 void QcepScatterPlotGraphModel::toggle(const QModelIndex &index)
133 {
134  int r = index.row();
135  int c = index.column();
136  int nr = rowCount(QModelIndex());
137  int nc = columnCount(QModelIndex());
138 
139  if (r >= 0 && r < nr) {
140  if (c == 1) { // 'X' column:
141  toggleX(r);
142  } else if (c == 2) { // 'Y' column
143  toggleY(r);
144  } else if (c == 3) { // 'Y2' column
145  toggleY2(r);
146  }
147  }
148 }
149 
151 {
152  return m_X.value(row);
153 }
154 
156 {
157  return m_Y.value(row);
158 }
159 
161 {
162  return m_Y2.value(row);
163 }
164 
166 {
167  int nr = rowCount(QModelIndex());
168 
169  if (row >= 0 && row < nr) {
170  for (int i=0; i<nr; i++) {
171  m_X[i] = false;
172  }
173 
174  m_X[row] = true;
175 
176  emit dataChanged(index(0,1), index(nr-1,1));
177  }
178 }
179 
181 {
182  int nr = rowCount(QModelIndex());
183 
184  if (row >= 0 && row < nr) {
185  m_Y[row] = !m_Y[row];
186 
187  emit dataChanged(index(row,2), index(row,2));
188  }
189 }
190 
192 {
193  int nr = rowCount(QModelIndex());
194 
195  if (row >= 0 && row < nr) {
196  m_Y2[row] = !m_Y2[row];
197 
198  emit dataChanged(index(row,3), index(row,3));
199  }
200 }
201 
203 {
204  if (val) {
205  return Qt::Checked;
206  } else {
207  return Qt::Unchecked;
208  }
209 }
int columnCount(const QModelIndex &parent) const
QSharedPointer< QcepDataGroup > QcepDataGroupPtr
QVariant data(const QModelIndex &index, int role) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const
QSharedPointer< QcepIntegratedData > QcepIntegratedDataPtr
QWeakPointer< QcepDataObject > QcepDataObjectWPtr
void toggle(const QModelIndex &index)
QcepScatterPlotGraphModel(QcepDataObjectWPtr object)
QSharedPointer< QcepDataObject > QcepDataObjectPtr
int rowCount(const QModelIndex &parent) const