QXRD  0.11.16
qxrddetectorproxylistmodel.cpp
Go to the documentation of this file.
2 #include "qxrddetectorproxy.h"
3 
5 {
6 }
7 
8 int QxrdDetectorProxyListModel::rowCount(const QModelIndex &parent) const
9 {
10  return m_DetectorProxies.count();
11 }
12 
13 int QxrdDetectorProxyListModel::columnCount(const QModelIndex &parent) const
14 {
15  return 4;
16 }
17 
18 QVariant QxrdDetectorProxyListModel::data(const QModelIndex &index, int role) const
19 {
20  int row = index.row();
21  int col = index.column();
23 
24  if (p) {
25  if (role == Qt::EditRole || role == Qt::DisplayRole) {
26  if (col == 0) {
27 // return row;
28  return p->detectorNumber();
29  } else if (col == 2) {
30  return p->detectorTypeName();
31  } else if (col == 3) {
32  return p->detectorName();
33  }
34  } else if (role == Qt::CheckStateRole) {
35  if (col == 1) {
36  if (p->enabled()) {
37  return Qt::Checked;
38  } else {
39  return Qt::Unchecked;
40  }
41  }
42  } else if (role == Qt::TextAlignmentRole) {
43  if (col == 0 || col == 1) {
44  return Qt::AlignHCenter;
45  } else {
46  return Qt::AlignAbsolute;
47  }
48  }
49  }
50 
51  return QVariant();
52 }
53 
54 QVariant QxrdDetectorProxyListModel::headerData(int section, Qt::Orientation orientation, int role) const
55 {
56  if (orientation == Qt::Horizontal) {
57  if (role == Qt::DisplayRole) {
58  if (section == 0) {
59  return "#";
60  }
61 
62  if (section == 1) {
63  return "Enabled";
64  }
65 
66  if (section == 2) {
67  return "Type";
68  }
69 
70  if (section == 3) {
71  return "Name";
72  }
73  } else if (role == Qt::TextAlignmentRole) {
74  return Qt::AlignHCenter;
75  }
76  }
77 
78  return QVariant();
79 }
80 
81 bool QxrdDetectorProxyListModel::setData(const QModelIndex &index, const QVariant &value, int role)
82 {
83  int row = index.row();
84  int col = index.column();
85 
86  QxrdDetectorProxyPtr proxy = m_DetectorProxies.value(row);
87 
88  if (proxy) {
89  if (col == 1 && role == Qt::CheckStateRole) {
90  proxy->setEnabled(!proxy->enabled());
91 
92  emit dataChanged(index, index);
93 
94  return true;
95  } else if (col == 3) {
96  if (role == Qt::EditRole || role == Qt::DisplayRole) {
97  proxy->setDetectorName(value.toString());
98 
99  emit dataChanged(index, index);
100 
101  return true;
102  }
103  }
104  }
105 
106  return false;
107 }
108 
109 Qt::ItemFlags QxrdDetectorProxyListModel::flags(const QModelIndex &index) const
110 {
111  int row = index.row();
112  int col = index.column();
113 
114  if (col == 1) {
115  return QAbstractListModel::flags(index) | Qt::ItemIsUserCheckable;
116  } else if (col == 3) {
117  return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
118  } else {
119  return QAbstractListModel::flags(index);
120  }
121 }
122 
124 {
125  beginInsertRows(QModelIndex(), m_DetectorProxies.count(), m_DetectorProxies.count());
126 
127  m_DetectorProxies.append(proxy);
128 
129  endInsertRows();
130 
132 }
133 
135 {
136  return m_DetectorProxies.value(i);
137 }
138 
140 {
141  beginRemoveRows(QModelIndex(), row, row);
142 
143  m_DetectorProxies.remove(row);
144 
145  endRemoveRows();
146 
148 }
149 
151 {
152  int nRows = m_DetectorProxies.count();
153 
154  if (row >= 0 && row < (nRows-1)) {
155  beginMoveRows(QModelIndex(), row+1, row+1, QModelIndex(), row);
156 
159 
160  m_DetectorProxies[row] = p2;
161  m_DetectorProxies[row+1] = p1;
162 
163  endMoveRows();
164 
166  }
167 }
168 
170 {
171  int nRows = m_DetectorProxies.count();
172 
173  if (row >= 1 && row < nRows) {
174  beginMoveRows(QModelIndex(), row, row, QModelIndex(), row-1);
175 
178 
179  m_DetectorProxies[row-1] = p2;
180  m_DetectorProxies[row] = p1;
181 
182  endMoveRows();
183 
185  }
186 }
187 
189 {
191 
192  if (p) {
193  p->configureDetector();
194  }
195 }
196 
198 {
199  for (int i=0; i<m_DetectorProxies.count(); i++) {
201 
202  if (p) {
203  p->setProperty("detectorNumber", i);
204  }
205  }
206 }
QSharedPointer< QxrdDetectorProxy > QxrdDetectorProxyPtr
void append(QxrdDetectorProxyPtr proxy)
int rowCount(const QModelIndex &parent) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const
bool setData(const QModelIndex &index, const QVariant &value, int role)
QVariant data(const QModelIndex &index, int role) const
QVector< QxrdDetectorProxyPtr > m_DetectorProxies
Qt::ItemFlags flags(const QModelIndex &index) const
QxrdDetectorProxyPtr detectorProxy(int i)
int columnCount(const QModelIndex &parent) const