QXRD  0.11.16
Public Types | Public Slots | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
QxrdROICoordinatesListModel Class Reference

#include <qxrdroicoordinateslistmodel.h>

Inheritance diagram for QxrdROICoordinatesListModel:
Inheritance graph
[legend]
Collaboration diagram for QxrdROICoordinatesListModel:
Collaboration graph
[legend]

Public Types

enum  {
  NumCol, SumCol, AverageCol, MinimumCol,
  MaximumCol, NPixelsCol, BackgroundCol, XGradientCol,
  YGradientCol, TypeCol, CenterXCol, CenterYCol,
  WidthCol, HeightCol, Width2Col, Height2Col,
  ColCount
}
 

Public Slots

void onROIChanged ()
 
void onROIsChanged ()
 

Public Member Functions

 QxrdROICoordinatesListModel (QcepSettingsSaverWPtr saver, QxrdExperimentWPtr exp)
 
virtual ~QxrdROICoordinatesListModel ()
 
void readSettings (QSettings *settings, QString section)
 
void writeSettings (QSettings *settings, QString section)
 
int rowCount (const QModelIndex &parent) const
 
int columnCount (const QModelIndex &parent) const
 
QVariant data (const QModelIndex &index, int role) const
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const
 
Qt::ItemFlags flags (const QModelIndex &index) const
 
bool setData (const QModelIndex &index, const QVariant &value, int role)
 
void append (QxrdROICoordinatesPtr coords)
 
void removeROI (int row)
 
void moveROIDown (int row)
 
void moveROIUp (int row)
 
void editROI (int row)
 
void moveROICenter (int row, double x, double y)
 
QxrdROICoordinatesPtr roi (int row) const
 
void setRoi (int row, QxrdROICoordinatesPtr c)
 
int roiCount () const
 
void recalculate (QcepImageDataBasePtr img, QcepMaskDataPtr mask)
 
void visualizeBackground (int n, QcepImageDataBasePtr img, QcepMaskDataPtr mask)
 
void visualizePeak (int n, QcepImageDataBasePtr img, QcepMaskDataPtr mask)
 

Static Public Member Functions

static QScriptValue toScriptValue (QScriptEngine *engine, const QxrdROICoordinatesListModelPtr &coords)
 
static void fromScriptValue (const QScriptValue &obj, QxrdROICoordinatesListModelPtr &coords)
 

Private Member Functions

QxrdROICoordinatesPtr newROI (int roiType)
 

Private Attributes

QcepSettingsSaverWPtr m_Saver
 
QMutex m_Mutex
 
QxrdExperimentWPtr m_Experiment
 
QVector< QxrdROICoordinatesPtrm_ROICoordinates
 

Detailed Description

Definition at line 15 of file qxrdroicoordinateslistmodel.h.

Member Enumeration Documentation

anonymous enum
Enumerator
NumCol 
SumCol 
AverageCol 
MinimumCol 
MaximumCol 
NPixelsCol 
BackgroundCol 
XGradientCol 
YGradientCol 
TypeCol 
CenterXCol 
CenterYCol 
WidthCol 
HeightCol 
Width2Col 
Height2Col 
ColCount 

Definition at line 58 of file qxrdroicoordinateslistmodel.h.

58  {
59  NumCol,
60  SumCol,
61  AverageCol,
62  MinimumCol,
63  MaximumCol,
64  NPixelsCol,
68  TypeCol,
69  CenterXCol,
70  CenterYCol,
71  WidthCol,
72  HeightCol,
73  Width2Col,
74  Height2Col,
75  ColCount
76  };

Constructor & Destructor Documentation

QxrdROICoordinatesListModel::QxrdROICoordinatesListModel ( QcepSettingsSaverWPtr  saver,
QxrdExperimentWPtr  exp 
)

Definition at line 6 of file qxrdroicoordinateslistmodel.cpp.

7  : QAbstractListModel(),
8  m_Saver(saver),
9  m_Experiment(exp),
11 {
12 }
QVector< QxrdROICoordinatesPtr > m_ROICoordinates
QxrdROICoordinatesListModel::~QxrdROICoordinatesListModel ( )
virtual

Definition at line 14 of file qxrdroicoordinateslistmodel.cpp.

15 {
16 }

Member Function Documentation

void QxrdROICoordinatesListModel::append ( QxrdROICoordinatesPtr  coords)

Definition at line 270 of file qxrdroicoordinateslistmodel.cpp.

References m_ROICoordinates, onROIChanged(), and QxrdROICoordinates::roiChanged().

271 {
272  beginInsertRows(QModelIndex(), m_ROICoordinates.count(), m_ROICoordinates.count());
273 
274  m_ROICoordinates.append(coords);
275 
276  connect(coords.data(), &QxrdROICoordinates::roiChanged,
278 
279  endInsertRows();
280 }
QVector< QxrdROICoordinatesPtr > m_ROICoordinates

Here is the call graph for this function:

int QxrdROICoordinatesListModel::columnCount ( const QModelIndex &  parent) const

Definition at line 96 of file qxrdroicoordinateslistmodel.cpp.

References ColCount.

Referenced by onROIChanged(), and onROIsChanged().

Here is the caller graph for this function:

QVariant QxrdROICoordinatesListModel::data ( const QModelIndex &  index,
int  role 
) const

Definition at line 101 of file qxrdroicoordinateslistmodel.cpp.

References AverageCol, BackgroundCol, CenterXCol, CenterYCol, Height2Col, HeightCol, MaximumCol, MinimumCol, NPixelsCol, NumCol, roi(), SumCol, TypeCol, Width2Col, WidthCol, XGradientCol, and YGradientCol.

102 {
103  int row = index.row();
104  int col = index.column();
105 
106  QxrdROICoordinatesPtr c = roi(row);
107 
108  if (c) {
109  if (role == Qt::DisplayRole || role == Qt::EditRole) {
110  if (col == NumCol) {
111  return row;
112  } else if (col == SumCol) {
113  return c->get_Sum();
114  } else if (col == AverageCol) {
115  return c->get_Average();
116  } else if (col == MinimumCol) {
117  return c->get_Minimum();
118  } else if (col == MaximumCol) {
119  return c->get_Maximum();
120  } else if (col == NPixelsCol) {
121  return c->get_NPixels();
122  } else if (col == BackgroundCol) {
123  return c->get_Background();
124  } else if (col == XGradientCol) {
125  return c->get_XGradient();
126  } else if (col == YGradientCol) {
127  return c->get_YGradient();
128  } else if (col == TypeCol) {
129  return c->get_RoiTypeName();
130  } else if (col == CenterXCol) {
131  return c->get_Coords().center().x();
132  } else if (col == CenterYCol) {
133  return c->get_Coords().center().y();
134  } else if (col == WidthCol) {
135  return c->get_Coords().width();
136  } else if (col == HeightCol) {
137  return c->get_Coords().height();
138  } else if (col == Width2Col) {
139  return c->get_Width2();
140  } else if (col == Height2Col) {
141  return c->get_Height2();
142  }
143  }
144  }
145 
146  return QVariant();
147 }
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr
QxrdROICoordinatesPtr roi(int row) const

Here is the call graph for this function:

void QxrdROICoordinatesListModel::editROI ( int  row)

Definition at line 325 of file qxrdroicoordinateslistmodel.cpp.

326 {
327 }
Qt::ItemFlags QxrdROICoordinatesListModel::flags ( const QModelIndex &  index) const

Definition at line 194 of file qxrdroicoordinateslistmodel.cpp.

References CenterXCol, CenterYCol, Height2Col, HeightCol, TypeCol, Width2Col, and WidthCol.

195 {
196  int row = index.row();
197  int col = index.column();
198 
199  if (col == TypeCol ||
200  col == CenterXCol ||
201  col == CenterYCol ||
202  col == WidthCol ||
203  col == HeightCol ||
204  col == Width2Col ||
205  col == Height2Col) {
206  return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
207  } else {
208  return QAbstractListModel::flags(index);
209  }
210 }
void QxrdROICoordinatesListModel::fromScriptValue ( const QScriptValue &  obj,
QxrdROICoordinatesListModelPtr coords 
)
static

Definition at line 73 of file qxrdroicoordinateslistmodel.cpp.

74 {
75  QObject *qobj = obj.toQObject();
76 
77  if (qobj) {
78  QxrdROICoordinatesListModel *qcoords = qobject_cast<QxrdROICoordinatesListModel*>(qobj);
79 
80  if (qcoords) {
81  coords = QxrdROICoordinatesListModelPtr(qcoords);
82  }
83  }
84 }
QSharedPointer< QxrdROICoordinatesListModel > QxrdROICoordinatesListModelPtr
QVariant QxrdROICoordinatesListModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role 
) const

Definition at line 149 of file qxrdroicoordinateslistmodel.cpp.

References AverageCol, BackgroundCol, CenterXCol, CenterYCol, Height2Col, HeightCol, MaximumCol, MinimumCol, NPixelsCol, NumCol, SumCol, TypeCol, Width2Col, WidthCol, XGradientCol, and YGradientCol.

150 {
151  if (orientation == Qt::Horizontal) {
152  if (role == Qt::DisplayRole) {
153  if (section == NumCol) {
154  return "#";
155  } else if (section == SumCol) {
156  return "Sum";
157  } else if (section == AverageCol) {
158  return "Avg";
159  } else if (section == MinimumCol) {
160  return "Min";
161  } else if (section == MaximumCol) {
162  return "Max";
163  } else if (section == NPixelsCol) {
164  return "NPix";
165  } else if (section == BackgroundCol) {
166  return "Bkgd";
167  } else if (section == XGradientCol) {
168  return "XGrad";
169  } else if (section == YGradientCol) {
170  return "YGrad";
171  } else if (section == TypeCol) {
172  return "Type";
173  } else if (section == CenterXCol) {
174  return "CenterX";
175  } else if (section == CenterYCol) {
176  return "CenterY";
177  } else if (section == WidthCol) {
178  return "Width";
179  } else if (section == HeightCol) {
180  return "Height";
181  } else if (section == Width2Col) {
182  return "Wd 2";
183  } else if (section == Height2Col) {
184  return "Ht 2";
185  }
186  } else if (role == Qt::TextAlignmentRole) {
187  return Qt::AlignHCenter;
188  }
189  }
190 
191  return QVariant();
192 }
void QxrdROICoordinatesListModel::moveROICenter ( int  row,
double  x,
double  y 
)

Definition at line 343 of file qxrdroicoordinateslistmodel.cpp.

References ColCount, and roi().

344 {
345  QxrdROICoordinatesPtr roi = this->roi(i);
346 
347  if (roi) {
348  roi->setCenter(QPointF(x,y));
349 
350  emit dataChanged(index(i,0), index(i,ColCount));
351  }
352 }
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr
QxrdROICoordinatesPtr roi(int row) const

Here is the call graph for this function:

void QxrdROICoordinatesListModel::moveROIDown ( int  row)

Definition at line 291 of file qxrdroicoordinateslistmodel.cpp.

References m_ROICoordinates.

292 {
293  int nRows = m_ROICoordinates.count();
294 
295  if (row >= 0 && row < (nRows-1)) {
296  beginMoveRows(QModelIndex(), row+1, row+1, QModelIndex(), row);
297 
298  QxrdROICoordinatesPtr p1 = m_ROICoordinates.value(row);
299  QxrdROICoordinatesPtr p2 = m_ROICoordinates.value(row+1);
300 
301  m_ROICoordinates[row] = p2;
302  m_ROICoordinates[row+1] = p1;
303 
304  endMoveRows();
305  }
306 }
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr
QVector< QxrdROICoordinatesPtr > m_ROICoordinates
void QxrdROICoordinatesListModel::moveROIUp ( int  row)

Definition at line 308 of file qxrdroicoordinateslistmodel.cpp.

References m_ROICoordinates.

309 {
310  int nRows = m_ROICoordinates.count();
311 
312  if (row >= 1 && row < nRows) {
313  beginMoveRows(QModelIndex(), row, row, QModelIndex(), row-1);
314 
315  QxrdROICoordinatesPtr p1 = m_ROICoordinates.value(row-1);
316  QxrdROICoordinatesPtr p2 = m_ROICoordinates.value(row);
317 
318  m_ROICoordinates[row-1] = p2;
319  m_ROICoordinates[row] = p1;
320 
321  endMoveRows();
322  }
323 }
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr
QVector< QxrdROICoordinatesPtr > m_ROICoordinates
QxrdROICoordinatesPtr QxrdROICoordinatesListModel::newROI ( int  roiType)
private

Definition at line 265 of file qxrdroicoordinateslistmodel.cpp.

References m_Experiment, and m_Saver.

Referenced by readSettings().

266 {
268 }
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr

Here is the caller graph for this function:

void QxrdROICoordinatesListModel::onROIChanged ( )
slot

Definition at line 354 of file qxrdroicoordinateslistmodel.cpp.

References columnCount(), and m_ROICoordinates.

Referenced by append(), and readSettings().

355 {
356 // printf("QxrdROICoordinatesListModel::onROIChanged()\n");
357 
358  QObject *s = sender();
359 
360  QxrdROICoordinates *c = qobject_cast<QxrdROICoordinates*>(s);
361 
362  if (c) {
363  for (int i=0; i<m_ROICoordinates.count(); i++) {
365 
366  if (r && r.data() == c) {
367 // printf("ROI %d changed\n", i);
368 
369  emit dataChanged(index(i,0), index(i,columnCount(QModelIndex())));
370  }
371  }
372  }
373 }
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr
int columnCount(const QModelIndex &parent) const
QVector< QxrdROICoordinatesPtr > m_ROICoordinates

Here is the call graph for this function:

Here is the caller graph for this function:

void QxrdROICoordinatesListModel::onROIsChanged ( )
slot

Definition at line 375 of file qxrdroicoordinateslistmodel.cpp.

References columnCount(), and rowCount().

376 {
377  emit dataChanged(index(0,0), index(rowCount(QModelIndex()), columnCount(QModelIndex())));
378 }
int rowCount(const QModelIndex &parent) const
int columnCount(const QModelIndex &parent) const

Here is the call graph for this function:

void QxrdROICoordinatesListModel::readSettings ( QSettings *  settings,
QString  section 
)

Definition at line 18 of file qxrdroicoordinateslistmodel.cpp.

References m_Mutex, m_ROICoordinates, newROI(), onROIChanged(), roi(), and QxrdROICoordinates::roiChanged().

19 {
20  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
21 
22  beginResetModel();
23 
24  int n = settings->beginReadArray(section+"/roi");
25 
26  m_ROICoordinates.resize(0);
27 
28  for (int i=0; i<n; i++) {
29  settings->setArrayIndex(i);
30 
31  int roiType = settings->value("roiType", 0).toInt();
32 
33  QxrdROICoordinatesPtr roi = newROI(roiType);
34 
35  if (roi) {
36  roi->readSettings(settings, "");
37  m_ROICoordinates.append(roi);
38 
39  connect(roi.data(), &QxrdROICoordinates::roiChanged,
41  }
42  }
43 
44  settings->endArray();
45 
46  endResetModel();
47 }
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr
QxrdROICoordinatesPtr newROI(int roiType)
QVector< QxrdROICoordinatesPtr > m_ROICoordinates
QxrdROICoordinatesPtr roi(int row) const

Here is the call graph for this function:

void QxrdROICoordinatesListModel::recalculate ( QcepImageDataBasePtr  img,
QcepMaskDataPtr  mask 
)

Definition at line 380 of file qxrdroicoordinateslistmodel.cpp.

References m_ROICoordinates, NPixelsCol, and SumCol.

381 {
382  for (int i=0; i<m_ROICoordinates.count(); i++) {
384 
385  if (r) {
386  r->recalculate(img, mask);
387  }
388  }
389 
390  emit dataChanged(index(0,SumCol), index(m_ROICoordinates.count(),NPixelsCol));
391 }
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr
QVector< QxrdROICoordinatesPtr > m_ROICoordinates
void QxrdROICoordinatesListModel::removeROI ( int  row)

Definition at line 282 of file qxrdroicoordinateslistmodel.cpp.

References m_ROICoordinates.

283 {
284  beginRemoveRows(QModelIndex(), row, row);
285 
286  m_ROICoordinates.remove(row);
287 
288  endRemoveRows();
289 }
QVector< QxrdROICoordinatesPtr > m_ROICoordinates
QxrdROICoordinatesPtr QxrdROICoordinatesListModel::roi ( int  row) const

Definition at line 329 of file qxrdroicoordinateslistmodel.cpp.

References m_ROICoordinates.

Referenced by data(), moveROICenter(), readSettings(), setData(), and writeSettings().

330 {
331  return m_ROICoordinates.value(row);
332 }
QVector< QxrdROICoordinatesPtr > m_ROICoordinates

Here is the caller graph for this function:

int QxrdROICoordinatesListModel::roiCount ( ) const

Definition at line 86 of file qxrdroicoordinateslistmodel.cpp.

References m_ROICoordinates.

87 {
88  return m_ROICoordinates.count();
89 }
QVector< QxrdROICoordinatesPtr > m_ROICoordinates
int QxrdROICoordinatesListModel::rowCount ( const QModelIndex &  parent) const

Definition at line 91 of file qxrdroicoordinateslistmodel.cpp.

References m_ROICoordinates.

Referenced by onROIsChanged().

92 {
93  return m_ROICoordinates.count();
94 }
QVector< QxrdROICoordinatesPtr > m_ROICoordinates

Here is the caller graph for this function:

bool QxrdROICoordinatesListModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role 
)

Definition at line 212 of file qxrdroicoordinateslistmodel.cpp.

References AverageCol, BackgroundCol, CenterXCol, CenterYCol, Height2Col, HeightCol, MaximumCol, MinimumCol, NPixelsCol, roi(), setRoi(), SumCol, TypeCol, Width2Col, WidthCol, XGradientCol, and YGradientCol.

213 {
214  int row = index.row();
215  int col = index.column();
216 
217  QxrdROICoordinatesPtr c = roi(row);
218 
219  if (c) {
220  if (role == Qt::EditRole || role == Qt::DisplayRole) {
221  if (col == SumCol) {
222  c->set_Sum(value.toDouble());
223  } else if (col == AverageCol) {
224  c->set_Average(value.toDouble());
225  } else if (col == MinimumCol) {
226  c->set_Minimum(value.toDouble());
227  } else if (col == MaximumCol) {
228  c->set_Maximum(value.toDouble());
229  } else if (col == NPixelsCol) {
230  c->set_NPixels(value.toDouble());
231  } else if (col == BackgroundCol) {
232  c->set_Background(value.toDouble());
233  } else if (col == XGradientCol) {
234  c->set_XGradient(value.toDouble());
235  } else if (col == YGradientCol) {
236  c->set_YGradient(value.toDouble());
237  } else if (col == TypeCol) {
238  c->selectNamedROIType(value.toString());
239  } else if (col == CenterXCol) {
240  c->setCenterX(value.toDouble());
241  } else if (col == CenterYCol) {
242  c->setCenterY(value.toDouble());
243  } else if (col == WidthCol) {
244  c->setWidth(value.toDouble());
245  } else if (col == HeightCol) {
246  c->setHeight(value.toDouble());
247  } else if (col == Width2Col) {
248  c->setWidth2(value.toDouble());
249  } else if (col == Height2Col) {
250  c->setHeight2(value.toDouble());
251  } else {
252  return false;
253  }
254 
255  setRoi(row, c);
256 
257  emit dataChanged(index, index);
258 
259  return true;
260  }
261  }
262  return false;
263 }
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr
QxrdROICoordinatesPtr roi(int row) const
void setRoi(int row, QxrdROICoordinatesPtr c)

Here is the call graph for this function:

void QxrdROICoordinatesListModel::setRoi ( int  row,
QxrdROICoordinatesPtr  c 
)

Definition at line 334 of file qxrdroicoordinateslistmodel.cpp.

References ColCount, and m_ROICoordinates.

Referenced by setData().

335 {
336  if (row >= 0 && row < m_ROICoordinates.count()) {
337  m_ROICoordinates[row] = c;
338 
339  emit dataChanged(index(row,0), index(row,ColCount));
340  }
341 }
QVector< QxrdROICoordinatesPtr > m_ROICoordinates

Here is the caller graph for this function:

QScriptValue QxrdROICoordinatesListModel::toScriptValue ( QScriptEngine *  engine,
const QxrdROICoordinatesListModelPtr coords 
)
static

Definition at line 68 of file qxrdroicoordinateslistmodel.cpp.

69 {
70  return engine->newQObject(coords.data());
71 }
void QxrdROICoordinatesListModel::visualizeBackground ( int  n,
QcepImageDataBasePtr  img,
QcepMaskDataPtr  mask 
)

Definition at line 393 of file qxrdroicoordinateslistmodel.cpp.

References m_ROICoordinates.

394 {
396 
397  if (r) {
398  r->visualizeBackground(img, mask);
399  }
400 }
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr
QVector< QxrdROICoordinatesPtr > m_ROICoordinates
void QxrdROICoordinatesListModel::visualizePeak ( int  n,
QcepImageDataBasePtr  img,
QcepMaskDataPtr  mask 
)

Definition at line 402 of file qxrdroicoordinateslistmodel.cpp.

References m_ROICoordinates.

403 {
405 
406  if (r) {
407  r->visualizePeak(img, mask);
408  }
409 }
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr
QVector< QxrdROICoordinatesPtr > m_ROICoordinates
void QxrdROICoordinatesListModel::writeSettings ( QSettings *  settings,
QString  section 
)

Definition at line 49 of file qxrdroicoordinateslistmodel.cpp.

References m_Mutex, m_ROICoordinates, and roi().

50 {
51  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
52 
53  settings->beginWriteArray(section+"/roi");
54 
55  for (int i=0; i<m_ROICoordinates.count(); i++) {
56  settings->setArrayIndex(i);
57 
59 
60  if (roi) {
61  roi->writeSettings(settings, "");
62  }
63  }
64 
65  settings->endArray();
66 }
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr
QVector< QxrdROICoordinatesPtr > m_ROICoordinates
QxrdROICoordinatesPtr roi(int row) const

Here is the call graph for this function:

Member Data Documentation

QxrdExperimentWPtr QxrdROICoordinatesListModel::m_Experiment
private

Definition at line 90 of file qxrdroicoordinateslistmodel.h.

Referenced by newROI().

QMutex QxrdROICoordinatesListModel::m_Mutex
private

Definition at line 89 of file qxrdroicoordinateslistmodel.h.

Referenced by readSettings(), and writeSettings().

QVector<QxrdROICoordinatesPtr> QxrdROICoordinatesListModel::m_ROICoordinates
private
QcepSettingsSaverWPtr QxrdROICoordinatesListModel::m_Saver
private

Definition at line 88 of file qxrdroicoordinateslistmodel.h.

Referenced by newROI().


The documentation for this class was generated from the following files: