QXRD  0.11.16
Public Slots | Public Member Functions | Protected Attributes | List of all members
QcepPlot Class Reference

#include <qcepplot.h>

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

Public Slots

virtual void autoScale ()
 
void printGraph ()
 
void zoomIn ()
 
void zoomOut ()
 
void enableZooming ()
 
void enableMeasuring ()
 
virtual void onLegendClicked (const QVariant &itemInfo, int index)
 
virtual void onLegendChecked (const QVariant &itemInfo, bool on, int index)
 
void setXAxisLog (bool isLog)
 
void setYAxisLog (bool isLog)
 
void setX2AxisLog (bool isLog)
 
void setY2AxisLog (bool isLog)
 
void setLogAxis (int axis, int isLog)
 
int logAxis (int axis)
 

Public Member Functions

 QcepPlot (QWidget *parent=0)
 
virtual ~QcepPlot ()
 
void init (QcepPlotSettingsWPtr settings)
 
void setPlotCurveStyle (int index, QwtPlotCurve *curve)
 
virtual QwtText trackerTextF (const QPointF &pos)
 
void contextMenuEvent (QContextMenuEvent *event)
 
void updateZoomer ()
 

Protected Attributes

QcepPlotSettingsWPtr m_PlotSettings
 
QwtLegend * m_Legend
 
QwtPlotZoomer * m_Zoomer
 
QwtPlotPanner * m_Panner
 
QwtPlotMagnifier * m_Magnifier
 
QcepPlotMeasurerPtr m_Measurer
 
int m_IsLog [QwtPlot::axisCnt]
 

Detailed Description

Definition at line 15 of file qcepplot.h.

Constructor & Destructor Documentation

QcepPlot::QcepPlot ( QWidget *  parent = 0)

Definition at line 18 of file qcepplot.cpp.

References m_IsLog.

19  : QwtPlot(parent),
21  m_Legend(NULL),
22  m_Zoomer(NULL),
23  m_Panner(NULL),
24  m_Magnifier(NULL),
25  m_Measurer(NULL)
26 {
27  for (int i=0; i<QwtPlot::axisCnt; i++) {
28  m_IsLog[i] = 0;
29  }
30 }
QwtPlotMagnifier * m_Magnifier
Definition: qcepplot.h:61
QcepPlotSettingsWPtr m_PlotSettings
Definition: qcepplot.h:57
QwtLegend * m_Legend
Definition: qcepplot.h:58
QwtPlotPanner * m_Panner
Definition: qcepplot.h:60
int m_IsLog[QwtPlot::axisCnt]
Definition: qcepplot.h:64
QwtPlotZoomer * m_Zoomer
Definition: qcepplot.h:59
QcepPlotMeasurerPtr m_Measurer
Definition: qcepplot.h:62
QcepPlot::~QcepPlot ( )
virtual

Definition at line 32 of file qcepplot.cpp.

33 {
34 }

Member Function Documentation

void QcepPlot::autoScale ( )
virtualslot

Definition at line 188 of file qcepplot.cpp.

References m_Zoomer.

Referenced by QxrdImagePlot::autoScale(), contextMenuEvent(), init(), QxrdWindow::initialize(), and QxrdCenterFinderPlot::onCenterChanged().

189 {
190  setAxisAutoScale(QwtPlot::yLeft);
191  setAxisAutoScale(QwtPlot::xBottom);
192 
193  m_Zoomer -> setZoomBase();
194 
195 //
196 // replot();
197 }
QwtPlotZoomer * m_Zoomer
Definition: qcepplot.h:59

Here is the caller graph for this function:

void QcepPlot::contextMenuEvent ( QContextMenuEvent *  event)

Definition at line 356 of file qcepplot.cpp.

References autoScale(), m_PlotSettings, and printGraph().

357 {
358  QMenu plotMenu(NULL, NULL);
359 
360  QAction *xLog = plotMenu.addAction("Log X Axis");
361  QAction *yLog = plotMenu.addAction("Log Y Axis");
362  QAction *auSc = plotMenu.addAction("Autoscale");
363  QAction *prGr = plotMenu.addAction("Print Graph...");
364 
366 
367  if (set) {
368  xLog->setCheckable(true);
369  yLog->setCheckable(true);
370  xLog->setChecked(set->get_XAxisLog());
371  yLog->setChecked(set->get_YAxisLog());
372 
373  QAction *action = plotMenu.exec(event->globalPos());
374 
375  if (action == xLog) {
376  set->toggle_XAxisLog();
377  } else if (action == yLog) {
378  set->toggle_YAxisLog();
379  } else if (action == auSc) {
380  autoScale();
381  } else if (action == prGr) {
382  printGraph();
383  }
384  }
385 
386  event->accept();
387 }
QcepPlotSettingsWPtr m_PlotSettings
Definition: qcepplot.h:57
virtual void autoScale()
Definition: qcepplot.cpp:188
void printGraph()
Definition: qcepplot.cpp:199
QSharedPointer< QcepPlotSettings > QcepPlotSettingsPtr

Here is the call graph for this function:

void QcepPlot::enableMeasuring ( )
slot

Definition at line 267 of file qcepplot.cpp.

References m_Measurer, and m_Zoomer.

Referenced by QxrdWindow::initialize().

268 {
269  m_Zoomer -> setEnabled(false);
270  m_Measurer -> setEnabled(true);
271 }
QwtPlotZoomer * m_Zoomer
Definition: qcepplot.h:59
QcepPlotMeasurerPtr m_Measurer
Definition: qcepplot.h:62

Here is the caller graph for this function:

void QcepPlot::enableZooming ( )
slot

Definition at line 261 of file qcepplot.cpp.

References m_Measurer, and m_Zoomer.

Referenced by QxrdWindow::initialize().

262 {
263  m_Zoomer -> setEnabled(true);
264  m_Measurer -> setEnabled(false);
265 }
QwtPlotZoomer * m_Zoomer
Definition: qcepplot.h:59
QcepPlotMeasurerPtr m_Measurer
Definition: qcepplot.h:62

Here is the caller graph for this function:

void QcepPlot::init ( QcepPlotSettingsWPtr  settings)

Definition at line 36 of file qcepplot.cpp.

References autoScale(), m_Legend, m_Magnifier, m_Measurer, m_Panner, m_PlotSettings, m_Zoomer, onLegendChecked(), onLegendClicked(), setX2AxisLog(), setXAxisLog(), setY2AxisLog(), and setYAxisLog().

Referenced by QxrdHistogramPlot::init(), QxrdSynchronizedAcquisitionPlot::init(), QxrdSlicePlot::init(), QxrdAcquisitionExtraInputsPlot::init(), QxrdIntegratorPlot::init(), QxrdDistortionCorrectionPlot::init(), QxrdCenterFinderPlot::init(), and QxrdImagePlot::init().

37 {
38  m_PlotSettings = settings;
39 
40  setCanvasBackground(QColor(Qt::white));
41 
42  m_Zoomer = new QcepPlotZoomer(canvas(), this);
43  m_Zoomer -> setStateMachine(new QwtPickerDragRectMachine());
44  m_Zoomer -> setTrackerMode(QwtPicker::AlwaysOn);
45  m_Zoomer -> setRubberBand(QwtPicker::RectRubberBand);
46 
47  m_Zoomer -> setMousePattern(QwtEventPattern::MouseSelect2,
48  Qt::LeftButton, Qt::ControlModifier | Qt::ShiftModifier);
49  m_Zoomer -> setMousePattern(QwtEventPattern::MouseSelect3,
50  Qt::LeftButton, Qt::ControlModifier);
51 
52  m_Zoomer -> setEnabled(true);
53 
54  m_Legend = new QwtLegend(this);
55  m_Legend -> setDefaultItemMode(QwtLegendData::Checkable);
56 
57  m_Panner = new QwtPlotPanner(canvas());
58  m_Panner -> setEnabled(true);
59  m_Panner -> setMouseButton(Qt::MidButton);
60  m_Panner -> setAxisEnabled(QwtPlot::yRight, false);
61 
62  m_Magnifier = new QwtPlotMagnifier(canvas());
63  m_Magnifier -> setEnabled(true);
64  m_Magnifier -> setMouseButton(Qt::NoButton);
65  m_Magnifier -> setAxisEnabled(QwtPlot::yRight, false);
66 
67  m_Measurer = new QcepPlotMeasurer(canvas(), this);
68  m_Measurer -> setEnabled(false);
69 
70  setAxisLabelRotation(QwtPlot::yLeft, -90);
71  setAxisLabelAlignment(QwtPlot::yLeft, Qt::AlignVCenter);
72 
73  autoScale();
74 
76 
77  if (set) {
78  connect(set->prop_XAxisLog(), SIGNAL(valueChanged(bool,int)), this, SLOT(setXAxisLog(bool)));
79  connect(set->prop_YAxisLog(), SIGNAL(valueChanged(bool,int)), this, SLOT(setYAxisLog(bool)));
80  connect(set->prop_X2AxisLog(), SIGNAL(valueChanged(bool,int)), this, SLOT(setX2AxisLog(bool)));
81  connect(set->prop_Y2AxisLog(), SIGNAL(valueChanged(bool,int)), this, SLOT(setY2AxisLog(bool)));
82 
83  setXAxisLog(set->get_XAxisLog());
84  setYAxisLog(set->get_YAxisLog());
85  setX2AxisLog(set->get_X2AxisLog());
86  setY2AxisLog(set->get_Y2AxisLog());
87 
88  if (m_Legend) {
89  int legendPos = set->get_LegendPosition();
90 
91  if (legendPos >= 0) {
92  insertLegend(m_Legend, (QwtPlot::LegendPosition) legendPos);
93  }
94  }
95  }
96 
97  if (m_Legend) {
98  connect(m_Legend, SIGNAL(clicked(const QVariant &,int)), this, SLOT(onLegendClicked(const QVariant&, int)));
99  connect(m_Legend, SIGNAL(checked(const QVariant &,bool,int)), this, SLOT(onLegendChecked(const QVariant&, bool, int)));
100  }
101 }
QwtPlotMagnifier * m_Magnifier
Definition: qcepplot.h:61
QcepPlotSettingsWPtr m_PlotSettings
Definition: qcepplot.h:57
void setY2AxisLog(bool isLog)
Definition: qcepplot.cpp:336
QwtLegend * m_Legend
Definition: qcepplot.h:58
QwtPlotPanner * m_Panner
Definition: qcepplot.h:60
virtual void autoScale()
Definition: qcepplot.cpp:188
QwtPlotZoomer * m_Zoomer
Definition: qcepplot.h:59
virtual void onLegendClicked(const QVariant &itemInfo, int index)
Definition: qcepplot.cpp:273
QSharedPointer< QcepPlotSettings > QcepPlotSettingsPtr
virtual void onLegendChecked(const QVariant &itemInfo, bool on, int index)
Definition: qcepplot.cpp:280
void setX2AxisLog(bool isLog)
Definition: qcepplot.cpp:331
void setYAxisLog(bool isLog)
Definition: qcepplot.cpp:326
QcepPlotMeasurerPtr m_Measurer
Definition: qcepplot.h:62
void setXAxisLog(bool isLog)
Definition: qcepplot.cpp:321

Here is the call graph for this function:

Here is the caller graph for this function:

int QcepPlot::logAxis ( int  axis)
slot

Definition at line 389 of file qcepplot.cpp.

References m_IsLog.

Referenced by QwtPlotPiecewiseCurve::ignorePoint().

390 {
391  return m_IsLog[axis];
392 }
int m_IsLog[QwtPlot::axisCnt]
Definition: qcepplot.h:64

Here is the caller graph for this function:

void QcepPlot::onLegendChecked ( const QVariant &  itemInfo,
bool  on,
int  index 
)
virtualslot

Definition at line 280 of file qcepplot.cpp.

Referenced by init(), and QxrdImagePlot::onLegendChecked().

281 {
282 // if (g_Application) {
283 // g_Application->printMessage(tr("QxrdPlot::onLegendChecked(%1,%2,%3)").arg(itemInfo.toString()).arg(on).arg(index));
284 // }
285 
286  QwtPlotItem *item = infoToItem(itemInfo);
287 
288  if (item) {
289  QwtPlotCurve *pc = dynamic_cast<QwtPlotCurve*>(item);
290 
291  if (pc) {
292  QPen pen = pc->pen();
293  const QwtSymbol *oldsym = pc->symbol();
294  QwtSymbol *sym = NULL;
295 
296  if (oldsym) {
297  sym = new QwtSymbol(oldsym->style(), oldsym->brush(), oldsym->pen(), oldsym->size());
298  }
299 
300  if (on) {
301  pen.setWidth(3);
302  if (sym) {
303  sym->setSize(9,9);
304  }
305  } else {
306  pen.setWidth(1);
307  if (sym) {
308  sym->setSize(5,5);
309  }
310  }
311  pc->setPen(pen);
312  if (sym) {
313  pc->setSymbol(sym);
314  }
315  }
316 
317  replot();
318  }
319 }

Here is the caller graph for this function:

void QcepPlot::onLegendClicked ( const QVariant &  itemInfo,
int  index 
)
virtualslot

Definition at line 273 of file qcepplot.cpp.

Referenced by init().

274 {
275 // if (g_Application) {
276 // g_Application->printMessage(tr("QxrdPlot::onLegendClicked(%1,%2)").arg(itemInfo.toString()).arg(index));
277 // }
278 }

Here is the caller graph for this function:

void QcepPlot::printGraph ( )
slot

Definition at line 199 of file qcepplot.cpp.

Referenced by QxrdDetectorImagePlot::contextMenuEvent(), contextMenuEvent(), QxrdImagePlot::contextMenuEvent(), and QxrdWindow::initialize().

200 {
201  QPrinter printer( QPrinter::HighResolution );
202 
203  QString docName = this->title().text();
204  if ( !docName.isEmpty() )
205  {
206  docName.replace ( QRegExp ( QString::fromLatin1 ( "\n" ) ), tr ( " -- " ) );
207  printer.setDocName ( docName );
208  }
209 
210 // printer.setCreator( "Bode example" );
211  printer.setOrientation( QPrinter::Landscape );
212 
213  QPrintDialog dialog( &printer );
214 
215  if ( dialog.exec() ) {
216  QwtPlotRenderer renderer;
217 
218  if ( printer.colorMode() == QPrinter::GrayScale ) {
219  renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground );
220  renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground );
221  renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasFrame );
222 // renderer.setLayoutFlag( QwtPlotRenderer::FrameWithScales );
223  }
224 
225  double gw = this->width();
226  double gh = this->height();
227  double pw = printer.width();
228  double ph = printer.height();
229  double scal = qMin( pw/gw, ph/gh);
230 
231  pw = gw*scal;
232  ph = gh*scal;
233 
234  QRectF rect(0,0, pw,ph);
235 
236  QPainter p(&printer);
237 
238  renderer.render( this, &p, rect);
239  }
240 }

Here is the caller graph for this function:

void QcepPlot::setLogAxis ( int  axis,
int  isLog 
)
slot

Definition at line 341 of file qcepplot.cpp.

References m_IsLog.

Referenced by setX2AxisLog(), setXAxisLog(), setY2AxisLog(), and setYAxisLog().

342 {
343  if (axis >= 0 && axis < QwtPlot::axisCnt) {
344  m_IsLog[axis] = isLog;
345 
346  if (isLog) {
347  setAxisScaleEngine(axis, new QwtLogScaleEngine);
348  } else {
349  setAxisScaleEngine(axis, new QwtLinearScaleEngine);
350  }
351 
352  replot();
353  }
354 }
int m_IsLog[QwtPlot::axisCnt]
Definition: qcepplot.h:64

Here is the caller graph for this function:

void QcepPlot::setPlotCurveStyle ( int  index,
QwtPlotCurve *  curve 
)

Definition at line 103 of file qcepplot.cpp.

Referenced by QxrdImagePlot::displayPowderMarkers(), QxrdIntegratorPlot::onNewIntegrationAvailable(), and QxrdImagePlot::updateROIDisplay().

104 {
105  const int nColors = 10;
106  const int nSymbols = 4;
107  const int nStyles = 3;
108 
109  int colorIndex = index % nColors;
110  int symbolIndex = (index / nColors) % nSymbols;
111  int styleIndex = (index / (nColors * nSymbols)) % nStyles;
112 
113  QPen pen;
114  QwtSymbol *symb = new QwtSymbol();
115  QBrush brush;
116 
117  switch (colorIndex) {
118  case 0:
119  pen = QPen(QColor(255,0,0)); // red
120  break;
121  case 1:
122  pen = QPen(QColor(255,170,0)); // Orange
123  break;
124  case 2:
125  pen = QPen(QColor(255,232,137)); // Yellow
126  break;
127  case 3:
128  pen = QPen(QColor(0,255,0)); // Green
129  break;
130  case 4:
131  pen = QPen(QColor(0,170,0)); // Dk green
132  break;
133  case 5:
134  pen = QPen(QColor(0,255,255)); // Cyan
135  break;
136  case 6:
137  pen = QPen(QColor(0,170,255)); // Sea blue
138  break;
139  case 7:
140  pen = QPen(QColor(0,0,255)); // Blue
141  break;
142  case 8:
143  pen = QPen(QColor(145,0,255)); // Violet
144  break;
145  case 9:
146  pen = QPen(QColor(255,0,255)); // Magenta
147  break;
148  }
149 
150  switch (styleIndex) {
151  case 0:
152  pen.setStyle(Qt::SolidLine);
153  break;
154  case 1:
155  pen.setStyle(Qt::DashLine);
156  break;
157  case 2:
158  pen.setStyle(Qt::DotLine);
159  break;
160  case 3:
161  pen.setStyle(Qt::DashDotLine);
162  break;
163  }
164 
165  symb->setPen(pen);
166  symb->setBrush(QBrush(pen.color()));
167  symb->setSize(5,5);
168 
169  switch (symbolIndex) {
170  case 0:
171  symb->setStyle(QwtSymbol::Ellipse);
172  break;
173  case 1:
174  symb->setStyle(QwtSymbol::Rect);
175  break;
176  case 2:
177  symb->setStyle(QwtSymbol::Triangle);
178  break;
179  case 3:
180  symb->setStyle(QwtSymbol::DTriangle);
181  break;
182  }
183 
184  curve -> setPen(pen);
185  curve -> setSymbol(symb);
186 }

Here is the caller graph for this function:

void QcepPlot::setX2AxisLog ( bool  isLog)
slot

Definition at line 331 of file qcepplot.cpp.

References setLogAxis().

Referenced by init().

332 {
333  setLogAxis(QwtPlot::xTop, isLog);
334 }
void setLogAxis(int axis, int isLog)
Definition: qcepplot.cpp:341

Here is the call graph for this function:

Here is the caller graph for this function:

void QcepPlot::setXAxisLog ( bool  isLog)
slot

Definition at line 321 of file qcepplot.cpp.

References setLogAxis().

Referenced by init().

322 {
323  setLogAxis(QwtPlot::xBottom, isLog);
324 }
void setLogAxis(int axis, int isLog)
Definition: qcepplot.cpp:341

Here is the call graph for this function:

Here is the caller graph for this function:

void QcepPlot::setY2AxisLog ( bool  isLog)
slot

Definition at line 336 of file qcepplot.cpp.

References setLogAxis().

Referenced by init().

337 {
338  setLogAxis(QwtPlot::yRight, isLog);
339 }
void setLogAxis(int axis, int isLog)
Definition: qcepplot.cpp:341

Here is the call graph for this function:

Here is the caller graph for this function:

void QcepPlot::setYAxisLog ( bool  isLog)
slot

Definition at line 326 of file qcepplot.cpp.

References setLogAxis().

Referenced by init().

327 {
328  setLogAxis(QwtPlot::yLeft, isLog);
329 }
void setLogAxis(int axis, int isLog)
Definition: qcepplot.cpp:341

Here is the call graph for this function:

Here is the caller graph for this function:

QwtText QcepPlot::trackerTextF ( const QPointF &  pos)
virtual

Reimplemented in QxrdImagePlot.

Definition at line 394 of file qcepplot.cpp.

References m_PlotSettings.

Referenced by QcepPlotMeasurer::trackerTextF(), and QcepPlotZoomer::trackerTextF().

395 {
397 
398  if (set) {
399  set->set_XMouse(pos.x());
400  set->set_YMouse(pos.y());
401  }
402 
403  return tr("%1, %2").arg(pos.x()).arg(pos.y());
404 }
QcepPlotSettingsWPtr m_PlotSettings
Definition: qcepplot.h:57
QSharedPointer< QcepPlotSettings > QcepPlotSettingsPtr

Here is the caller graph for this function:

void QcepPlot::updateZoomer ( )

Definition at line 252 of file qcepplot.cpp.

References m_Zoomer.

Referenced by QxrdIntegratorPlot::onNewIntegrationAvailable().

253 {
254  if (m_Zoomer && m_Zoomer -> zoomRectIndex() == 0) {
255  m_Zoomer -> setZoomBase();
256  }
257 
258  replot();
259 }
QwtPlotZoomer * m_Zoomer
Definition: qcepplot.h:59

Here is the caller graph for this function:

void QcepPlot::zoomIn ( )
slot

Definition at line 242 of file qcepplot.cpp.

References m_Zoomer.

243 {
244  m_Zoomer -> zoom(1);
245 }
QwtPlotZoomer * m_Zoomer
Definition: qcepplot.h:59
void QcepPlot::zoomOut ( )
slot

Definition at line 247 of file qcepplot.cpp.

References m_Zoomer.

Referenced by QxrdWindow::initialize().

248 {
249  m_Zoomer -> zoom(-1);
250 }
QwtPlotZoomer * m_Zoomer
Definition: qcepplot.h:59

Here is the caller graph for this function:

Member Data Documentation

int QcepPlot::m_IsLog[QwtPlot::axisCnt]
protected

Definition at line 64 of file qcepplot.h.

Referenced by logAxis(), QcepPlot(), and setLogAxis().

QwtLegend* QcepPlot::m_Legend
protected
QwtPlotMagnifier* QcepPlot::m_Magnifier
protected

Definition at line 61 of file qcepplot.h.

Referenced by init().

QcepPlotMeasurerPtr QcepPlot::m_Measurer
protected
QwtPlotPanner* QcepPlot::m_Panner
protected

Definition at line 60 of file qcepplot.h.

Referenced by init().

QcepPlotSettingsWPtr QcepPlot::m_PlotSettings
protected

Definition at line 57 of file qcepplot.h.

Referenced by contextMenuEvent(), init(), and trackerTextF().

QwtPlotZoomer* QcepPlot::m_Zoomer
protected

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