QXRD  0.11.16
qxrdacquisitionscalermodel.cpp
Go to the documentation of this file.
2 #include "qxrdacquisition.h"
3 #include "qxrddetector.h"
6 #include "qxrdroicalculator.h"
7 #include "qxrdroicoordinates.h"
8 
10  : m_Acquisition(acq)
11 {
13 
14  if (acqr) {
15  connect(acqr.data(), &QxrdAcquisition::detectorStateChanged,
17 
18  connect(acqr.data(), &QxrdAcquisition::extraInputsChanged,
20 
21  connect(acqr->prop_ScalerValues(), &QcepDoubleVectorProperty::valueChanged,
23  }
24 }
25 
26 int QxrdAcquisitionScalerModel::rowCount(const QModelIndex &parent) const
27 {
28  int nRows = 2;
29 
31 
32  if (acq) {
33  QxrdAcquisitionExtraInputsPtr xtra = acq->acquisitionExtraInputs();
34  QVector<QxrdAcquisitionExtraInputsChannelPtr> xchans;
35 
36  if (xtra) {
37  xchans = xtra->channels();
38  }
39 
40  int nXtra = xchans.count();
41 
42  if (nXtra) {
43  nRows += nXtra+1;
44  }
45 
46  int nDet = acq->get_DetectorCount();
47 
48  for (int det=0; det<nDet; det++) {
49  QxrdDetectorPtr d = acq->detector(det);
50 
51  if (d && d->isEnabled()) {
52  nRows += 1;
53 // nRows += QxrdDetector::ExtraScalers;
54  nRows += d->roiCount()*QxrdROICoordinates::OutputCount;
55  }
56  }
57  }
58 
59  return nRows;
60 }
61 
62 int QxrdAcquisitionScalerModel::columnCount(const QModelIndex &parent) const
63 {
64  return ColCount;
65 }
66 
67 QVariant QxrdAcquisitionScalerModel::data(const QModelIndex &index, int role) const
68 {
70 
71  if (acq) {
72  int scalerchan = 0;
73 
74  QxrdAcquisitionExtraInputsPtr xtra = acq->acquisitionExtraInputs();
75  QVector<QxrdAcquisitionExtraInputsChannelPtr> xchans;
76 
77  if (xtra) {
78  xchans = xtra->channels();
79  }
80 
81  int row = index.row();
82  int col = index.column();
83  int nXtra = xchans.count();
84  int nDet = acq->get_DetectorCount();
85 
86  if (role == Qt::DisplayRole) {
87  if (row == 0) {
88  if (col == DescriptionCol) {
89  return "====== Acquisition ======";
90  }
91  } else if (row == 1) {
92  if (col == NumCol) {
93  return 0;
94  } else if (col == ValueCol) {
95  return acq->get_FileIndex()-1;
96  } else if (col == DescriptionCol) {
97  return "File Index";
98  }
99  } else {
100  row -= 2;
101  scalerchan += 1;
102 
103  if (nXtra && row == 0) {
104  if (col == DescriptionCol) {
105  return "====== NIDAQ Inputs ======";
106  }
107  } else {
108  if (nXtra) {
109  row -= 1;
110  }
111 
112  if (row < nXtra) {
113  if (col == NumCol) {
114  return scalerchan+row;
115  } else if (col == ValueCol) {
116  QxrdAcquisitionExtraInputsChannelPtr chan = xchans.value(row);
117 
118  if (chan) {
119  return chan->evaluateChannel();
120  }
121  } else if (col == DescriptionCol) {
122  return tr("NIDAQ Channel %1").arg(row);
123  }
124  } else {
125  row -= nXtra;
126  scalerchan += nXtra;
127 
128  for (int det=0; det<nDet; det++) {
129  QxrdDetectorPtr d = acq->detector(det);
130 
131  if (d && d->isEnabled()) {
132  if (row == 0) {
133  if (col == DescriptionCol) {
134  return tr("====== Detector %1 : %2 ======").arg(det).arg(d->get_DetectorName());
135  }
136  } else {
137  row -= 1;
138 
139  int nROI = d->roiCount()*QxrdROICoordinates::OutputCount;
140 
141  if (row < nROI) {
142  if (col == NumCol) {
143  return scalerchan+row;
144  } else if (col == ValueCol) {
145  double val = d->scalerCounts(row);
146 
147  return val;
148  } else if (col == DescriptionCol) {
149  int roiNum = row / QxrdROICoordinates::OutputCount;
150  int optNum = row % QxrdROICoordinates::OutputCount;
151 
152  return tr("Detector %1 : ROI %2 : %3")
153  .arg(det).arg(roiNum).arg(QxrdROICoordinates::outputName(optNum));
154  }
155  } else {
156  row -= nROI;
157  scalerchan += nROI;
158  }
159  }
160  }
161  }
162  }
163  }
164  }
165  }
166  }
167 
168  return QVariant();
169 }
170 
171 QVariant QxrdAcquisitionScalerModel::headerData(int section, Qt::Orientation orientation, int role) const
172 {
173  if (orientation == Qt::Horizontal) {
174  if (role == Qt::DisplayRole) {
175  if (section == NumCol) {
176  return "Scaler#";
177  } else if (section == ValueCol) {
178  return "Value";
179  } else if (section == DescriptionCol) {
180  return "Description";
181  }
182  }
183  }
184 
185  return QVariant();
186 }
187 
189 {
190  beginResetModel();
191 
192  endResetModel();
193 }
int columnCount(const QModelIndex &parent) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const
static QString outputName(int opt)
QSharedPointer< QxrdAcquisition > QxrdAcquisitionPtr
void detectorStateChanged()
QxrdAcquisitionScalerModel(QxrdAcquisitionWPtr acq)
QSharedPointer< QxrdAcquisitionExtraInputs > QxrdAcquisitionExtraInputsPtr
QSharedPointer< QxrdAcquisitionExtraInputsChannel > QxrdAcquisitionExtraInputsChannelPtr
void extraInputsChanged()
QVariant data(const QModelIndex &index, int role) const
int rowCount(const QModelIndex &parent) const
void valueChanged(QcepDoubleVector val, int index)
QWeakPointer< QxrdAcquisition > QxrdAcquisitionWPtr
QSharedPointer< QxrdDetector > QxrdDetectorPtr