QXRD  0.11.16
qcepscatterplotgraphcontroller.cpp
Go to the documentation of this file.
2 #include <stdio.h>
3 //#include "qcepexperiment-ptr.h"
4 //#include "qcepexperiment.h"
9 #include "qcepintegrateddata.h"
10 #include "qcepdatacolumnscan-ptr.h"
11 #include "qcepdatacolumnscan.h"
12 #include "qcepdatacolumn-ptr.h"
13 #include "qcepdatacolumn.h"
15 
17  : QcepDataObjectGraphController(window, mode, object)
18 {
19 
20 }
21 
23 {
24  delete(m_Widget);
25 }
26 
28 {
30 
31  if (ctrl) {
32  m_Widget = ctrl;
33 
34  m_Window->m_Splitter->addWidget(m_Widget);
35 
36  m_Model = ctrl->model();
37 
39 
40  if (m) {
41  connect(m.data(), &QAbstractItemModel::dataChanged,
43  }
44  }
45 
47 }
48 
50  const QModelIndex &topLeft, const QModelIndex &bottomRight)
51 {
52 // QcepExperimentPtr exp(m_Window->experiment());
53 
54 // if (exp) {
55 // exp->printMessage(tr("QcepScatterPlotGraphController::onPlotDataChanged([%1,%2],[%3,%4])")
56 // .arg(topLeft.column()).arg(topLeft.row())
57 // .arg(bottomRight.column()).arg(bottomRight.row()));
58 // }
59 
60  updateDisplay();
61 }
62 
64 {
65  m_Window -> clearPlot();
66  m_Window -> m_ImagePlot -> enableAxis(QwtPlot::yRight, false);
67 
68  int curveNumber = 0;
69 
72  QcepIntegratedDataPtr integ = qSharedPointerDynamicCast<QcepIntegratedData>(m_Object);
73  QcepDataColumnScanPtr scan = qSharedPointerDynamicCast<QcepDataColumnScan>(m_Object);
74 
75  if (model) {
76  int xcol = -1;
77  int nr = model->rowCount(QModelIndex());
78 
79  for (int i=0; i<nr; i++) {
80  if (model->getX(i)) {
81  xcol = i;
82  }
83  }
84 
85  if (integ) {
86  const double *cols[2];
87  QString labels[2];
88 
89  cols[0] = integ->x();
90  cols[1] = integ->y();
91  int nr = integ->size();
92  labels[0] = integ->get_XUnitsLabel();
93  labels[1] = "Y";
94 
95  if (xcol >= 0) {
96  const double *xc = cols[xcol];
97 
98  m_Window->m_ImagePlot -> setAxisTitle(QwtPlot::xBottom, labels[xcol]);
99 
100  for (int i=0; i<2; i++) {
101  if (model->getY(i)) {
102  appendCurve(labels[i], 0, curveNumber++, xc, cols[i], nr);
103  }
104 
105  if (model->getY2(i)) {
106  appendCurve(labels[i], 1, curveNumber++, xc, cols[i], nr);
107  }
108  }
109  }
110  } else if (scan) {
111  if (xcol >= 0) {
112  QcepDataColumnPtr xCol = scan->column(xcol);
113 
114  if (xCol) {
115  m_Window->m_ImagePlot -> setAxisTitle(QwtPlot::xBottom, xCol->get_Name());
116 
117  for (int i=0; i<nr; i++) {
118  if (model->getY(i)) {
119  QcepDataColumnPtr yCol = scan->column(i);
120 
121  if (yCol) {
122  appendCurve(yCol->get_Name(), 0, curveNumber++, xCol, yCol);
123  }
124  }
125 
126  if (model->getY2(i)) {
127  QcepDataColumnPtr y2Col = scan->column(i);
128 
129  if (y2Col) {
130  appendCurve(y2Col->get_Name(), 1, curveNumber++, xCol, y2Col);
131  }
132  }
133  }
134  }
135  }
136  }
137  }
138 
139  m_Window -> m_ImagePlot -> replot();
140 
142 }
143 
145  QString name, int axis, int curveNumber, const double *x, const double *y, int npts)
146 {
147  QwtPlotCurve *curve = new QwtPlotPiecewiseCurve(m_Window->m_ImagePlot, name);
148 
149  curve->setSamples(x, y, npts);
150 
151  m_Window->m_ImagePlot->setPlotCurveStyle(curveNumber, curve);
152 
153  if (axis == 0) {
154  curve->setYAxis(QwtPlot::yLeft);
155  } else if (axis == 1) {
156  curve->setYAxis(QwtPlot::yRight);
157 
158  m_Window->m_ImagePlot->enableAxis(QwtPlot::yRight, true);
159  }
160 
161  m_Window->appendCurve(curve);
162 }
163 
165  QString name, int axis, int curveNumber, QcepDataColumnPtr x, QcepDataColumnPtr y)
166 {
167  if (x && y) {
168  const double *xp = x->data(), *yp = y->data();
169  int np = qMin(x->count(), y->count());
170 
171  appendCurve(name, axis, curveNumber, xp, yp, np);
172  }
173 }
QSharedPointer< QcepScatterPlotGraphModel > QcepScatterPlotGraphModelPtr
QSharedPointer< QcepDataColumnScan > QcepDataColumnScanPtr
QSharedPointer< QcepDataColumn > QcepDataColumnPtr
JSON Parse a string as a JSON object
void appendCurve(QwtPlotCurve *curve)
QSharedPointer< QcepIntegratedData > QcepIntegratedDataPtr
QcepScatterPlotGraphModelPtr model()
QcepScatterPlotGraphController(QcepDataObjectGraphWindow *window, int mode, QcepDataObjectWPtr object)
A class which draws piecewise curves.
QWeakPointer< QcepDataObject > QcepDataObjectWPtr
QSharedPointer< QcepDataObject > QcepDataObjectPtr
void onPlotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void appendCurve(QString name, int axis, int curveNumber, const double *x, const double *y, int npts)