QXRD  0.11.16
qxrdintegratorplot.cpp
Go to the documentation of this file.
1 #include "qxrdintegratorplot.h"
2 
3 #include <stdio.h>
4 
5 #include <QMetaMethod>
6 //#include <QTime>
7 
8 #include <qwt_plot_zoomer.h>
9 #include <qwt_plot_curve.h>
10 #include <qwt_legend.h>
11 #include <qwt_legend_label.h>
12 
13 #include "qcepplotmeasurer.h"
14 #include "qcepintegrateddata.h"
15 
16 #include "qxrddataprocessor.h"
17 #include "qxrdintegrator.h"
19 
21  : QcepPlot(parent),
22  m_DataProcessor(),
23  m_Integrator(),
24  m_PlotIndex(0),
25  m_XUnitsLabel("")
26 {
27  qRegisterMetaType< QVector<double> >("QVector<double>");
28 
29 
30 }
31 
33 {
34  QcepPlot::init(settings);
35 
36  if (m_Legend) {
37  insertLegend(m_Legend, QwtPlot::BottomLegend);
38  }
39 }
40 
42 {
43  m_DataProcessor = proc;
44 
46 
47  if (dp) {
48  m_Integrator = dp -> integrator();
49 
50  connect(m_Measurer, (void (QcepPlotMeasurer::*)( const QVector<QPointF> &)) &QwtPlotPicker::selected,
52  }
53 }
54 
56 {
57 
58 // printf("New integration available, %d, %d points\n", x.size(), y.size());
59 
60  if (m_PlotIndex < 40) {
61  QTime tic;
62  tic.start();
63 
64  QString units = data->get_XUnitsLabel();
65 
66  if (m_PlotIndex == 0) {
67  m_XUnitsLabel = units;
68  } else if (units != m_XUnitsLabel) {
69  m_XUnitsLabel = "";
70  }
71 
72  setAxisTitle(QwtPlot::xBottom, m_XUnitsLabel);
73 
74  QcepDoubleImageDataPtr img(data->get_Image());
75 
76  QString title = (img ? img -> get_Title() : data -> get_Title());
77  QString tooltip;
78 
79  if (data->get_Oversample() > 1) {
80  tooltip = tr("%1\nPlotted vs %2\n%3 x oversampled")
81  .arg(title)
82  .arg(units)
83  .arg(data->get_Oversample());
84  } else {
85  tooltip = tr("%1\nPlotted vs %2\nNo oversampling")
86  .arg(title)
87  .arg(units);
88  }
89 
90  QwtPlotCurve *pc = new QwtPlotPiecewiseCurve(this, title/*tr("Plot %1").arg(m_PlotIndex)*/);
91  pc -> setSamples(data->x(), data->y(), data->size());
93  pc -> attach(this);
94  pc -> setLegendAttribute(QwtPlotCurve::LegendShowSymbol, true);
95  pc -> setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
96 
97  updateZoomer();
98 
100 
101  if (proc) {
102  proc -> updateEstimatedTime(proc -> prop_DisplayIntegratedDataTime(), tic.restart());
103  }
104 
105  QWidget *legend = m_Legend->legendWidget(itemToInfo(pc));
106 
107  if (legend) {
108  legend->setToolTip(tooltip);
109  }
110  }
111 
112  m_PlotIndex++;
113 //
114 // printf("Plotting took %d msec\n", tic.restart());
115 }
116 
118 {
119  m_PlotIndex = 0;
120 
121  detachItems(QwtPlotItem::Rtti_PlotCurve);
122  detachItems(QwtPlotItem::Rtti_PlotMarker);
123 
124  replot();
125 }
126 
128 {
129  QList<QwtPlotCurve*> toDelete;
130 
131  foreach(QwtPlotItem* item, itemList()) {
132  QwtPlotCurve *pc = dynamic_cast<QwtPlotCurve*>(item);
133  if (pc) {
134  QWidget *wid = m_Legend->legendWidget(itemToInfo(pc));
135 
136  if (wid) {
137  QwtLegendLabel *itm = qobject_cast<QwtLegendLabel*>(wid);
138 
139  if (itm) {
140  if (itm->isChecked()) {
141  toDelete.append(pc);
142  }
143  }
144  }
145  }
146  }
147 
148  foreach(QwtPlotCurve *curve, toDelete) {
149  if (curve) {
150  curve->detach();
151 
152  delete curve;
153  }
154  }
155 
156  replot();
157 }
158 
QxrdIntegratorWPtr m_Integrator
QWeakPointer< QxrdDataProcessor > QxrdDataProcessorWPtr
QWeakPointer< QcepPlotSettings > QcepPlotSettingsWPtr
void onNewIntegrationAvailable(QcepIntegratedDataPtr data)
QSharedPointer< QxrdDataProcessor > QxrdDataProcessorPtr
void setPlotCurveStyle(int index, QwtPlotCurve *curve)
Definition: qcepplot.cpp:103
QwtLegend * m_Legend
Definition: qcepplot.h:58
QSharedPointer< QcepIntegratedData > QcepIntegratedDataPtr
void printMeasuredPolygon(QVector< QPointF > poly)
A class which draws piecewise curves.
void init(QcepPlotSettingsWPtr settings)
Definition: qcepplot.cpp:36
void setDataProcessor(QxrdDataProcessorWPtr proc)
QxrdIntegratorPlot(QWidget *parent=0)
void init(QcepPlotSettingsWPtr settings)
QcepPlotMeasurerPtr m_Measurer
Definition: qcepplot.h:62
void updateZoomer()
Definition: qcepplot.cpp:252
QxrdDataProcessorWPtr m_DataProcessor
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr