4 #include <QPrintDialog>
6 #include <QContextMenuEvent>
8 #include <qwt_symbol.h>
9 #include <qwt_picker_machine.h>
10 #include <qwt_plot_renderer.h>
11 #include <qwt_scale_engine.h>
27 for (
int i=0; i<QwtPlot::axisCnt; i++) {
40 setCanvasBackground(QColor(Qt::white));
43 m_Zoomer -> setStateMachine(
new QwtPickerDragRectMachine());
44 m_Zoomer -> setTrackerMode(QwtPicker::AlwaysOn);
45 m_Zoomer -> setRubberBand(QwtPicker::RectRubberBand);
47 m_Zoomer -> setMousePattern(QwtEventPattern::MouseSelect2,
48 Qt::LeftButton, Qt::ControlModifier | Qt::ShiftModifier);
49 m_Zoomer -> setMousePattern(QwtEventPattern::MouseSelect3,
50 Qt::LeftButton, Qt::ControlModifier);
55 m_Legend -> setDefaultItemMode(QwtLegendData::Checkable);
57 m_Panner =
new QwtPlotPanner(canvas());
59 m_Panner -> setMouseButton(Qt::MidButton);
60 m_Panner -> setAxisEnabled(QwtPlot::yRight,
false);
65 m_Magnifier -> setAxisEnabled(QwtPlot::yRight,
false);
70 setAxisLabelRotation(QwtPlot::yLeft, -90);
71 setAxisLabelAlignment(QwtPlot::yLeft, Qt::AlignVCenter);
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)));
89 int legendPos = set->get_LegendPosition();
92 insertLegend(
m_Legend, (QwtPlot::LegendPosition) legendPos);
99 connect(
m_Legend, SIGNAL(checked(
const QVariant &,
bool,
int)),
this, SLOT(
onLegendChecked(
const QVariant&,
bool,
int)));
105 const int nColors = 10;
106 const int nSymbols = 4;
107 const int nStyles = 3;
109 int colorIndex = index % nColors;
110 int symbolIndex = (index / nColors) % nSymbols;
111 int styleIndex = (index / (nColors * nSymbols)) % nStyles;
114 QwtSymbol *symb =
new QwtSymbol();
117 switch (colorIndex) {
119 pen = QPen(QColor(255,0,0));
122 pen = QPen(QColor(255,170,0));
125 pen = QPen(QColor(255,232,137));
128 pen = QPen(QColor(0,255,0));
131 pen = QPen(QColor(0,170,0));
134 pen = QPen(QColor(0,255,255));
137 pen = QPen(QColor(0,170,255));
140 pen = QPen(QColor(0,0,255));
143 pen = QPen(QColor(145,0,255));
146 pen = QPen(QColor(255,0,255));
150 switch (styleIndex) {
152 pen.setStyle(Qt::SolidLine);
155 pen.setStyle(Qt::DashLine);
158 pen.setStyle(Qt::DotLine);
161 pen.setStyle(Qt::DashDotLine);
166 symb->setBrush(QBrush(pen.color()));
169 switch (symbolIndex) {
171 symb->setStyle(QwtSymbol::Ellipse);
174 symb->setStyle(QwtSymbol::Rect);
177 symb->setStyle(QwtSymbol::Triangle);
180 symb->setStyle(QwtSymbol::DTriangle);
184 curve -> setPen(pen);
185 curve -> setSymbol(symb);
190 setAxisAutoScale(QwtPlot::yLeft);
191 setAxisAutoScale(QwtPlot::xBottom);
201 QPrinter printer( QPrinter::HighResolution );
203 QString docName = this->title().text();
204 if ( !docName.isEmpty() )
206 docName.replace ( QRegExp ( QString::fromLatin1 (
"\n" ) ), tr (
" -- " ) );
207 printer.setDocName ( docName );
211 printer.setOrientation( QPrinter::Landscape );
213 QPrintDialog dialog( &printer );
215 if ( dialog.exec() ) {
216 QwtPlotRenderer renderer;
218 if ( printer.colorMode() == QPrinter::GrayScale ) {
219 renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground );
220 renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground );
221 renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasFrame );
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);
234 QRectF rect(0,0, pw,ph);
236 QPainter p(&printer);
238 renderer.render(
this, &p, rect);
286 QwtPlotItem *item = infoToItem(itemInfo);
289 QwtPlotCurve *pc =
dynamic_cast<QwtPlotCurve*
>(item);
292 QPen pen = pc->pen();
293 const QwtSymbol *oldsym = pc->symbol();
294 QwtSymbol *sym = NULL;
297 sym =
new QwtSymbol(oldsym->style(), oldsym->brush(), oldsym->pen(), oldsym->size());
343 if (axis >= 0 && axis < QwtPlot::axisCnt) {
347 setAxisScaleEngine(axis,
new QwtLogScaleEngine);
349 setAxisScaleEngine(axis,
new QwtLinearScaleEngine);
358 QMenu plotMenu(NULL, NULL);
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...");
368 xLog->setCheckable(
true);
369 yLog->setCheckable(
true);
370 xLog->setChecked(set->get_XAxisLog());
371 yLog->setChecked(set->get_YAxisLog());
373 QAction *action = plotMenu.exec(event->globalPos());
375 if (action == xLog) {
376 set->toggle_XAxisLog();
377 }
else if (action == yLog) {
378 set->toggle_YAxisLog();
379 }
else if (action == auSc) {
381 }
else if (action == prGr) {
399 set->set_XMouse(pos.x());
400 set->set_YMouse(pos.y());
403 return tr(
"%1, %2").arg(pos.x()).arg(pos.y());
QwtPlotMagnifier * m_Magnifier
void contextMenuEvent(QContextMenuEvent *event)
QWeakPointer< QcepPlotSettings > QcepPlotSettingsWPtr
QcepPlot(QWidget *parent=0)
void setPlotCurveStyle(int index, QwtPlotCurve *curve)
QcepPlotSettingsWPtr m_PlotSettings
void setY2AxisLog(bool isLog)
int m_IsLog[QwtPlot::axisCnt]
void setLogAxis(int axis, int isLog)
virtual void onLegendClicked(const QVariant &itemInfo, int index)
void init(QcepPlotSettingsWPtr settings)
virtual QwtText trackerTextF(const QPointF &pos)
QSharedPointer< QcepPlotSettings > QcepPlotSettingsPtr
virtual void onLegendChecked(const QVariant &itemInfo, bool on, int index)
void setX2AxisLog(bool isLog)
void setYAxisLog(bool isLog)
QcepPlotMeasurerPtr m_Measurer
void setXAxisLog(bool isLog)