Qwt User's Guide: qwt_plot_graphicitem.cpp Source File

Qwt User's Guide 6.3.0

Loading...
Searching...
No Matches
qwt_plot_graphicitem.cpp
1/******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10#include "qwt_plot_graphicitem.h"
11#include "qwt_scale_map.h"
12#include "qwt_painter.h"
13#include "qwt_text.h"
14#include "qwt_graphic.h"
15
16class QwtPlotGraphicItem::PrivateData
17{
18 public:
19 QRectF boundingRect;
20 QwtGraphic graphic;
21};
22
32QwtPlotGraphicItem::QwtPlotGraphicItem( const QString& title )
33 : QwtPlotItem( QwtText( title ) )
34{
35 init();
36}
37
47 QwtPlotGraphicItem::QwtPlotGraphicItem( const QwtText& title )
48 : QwtPlotItem( title )
49{
50 init();
51}
52
54QwtPlotGraphicItem::~QwtPlotGraphicItem()
55{
56 delete m_data;
57}
58
59void QwtPlotGraphicItem::init()
60{
61 m_data = new PrivateData();
62 m_data->boundingRect = QwtPlotItem::boundingRect();
63
64 setItemAttribute( QwtPlotItem::AutoScale, true );
65 setItemAttribute( QwtPlotItem::Legend, false );
66
67 setZ( 8.0 );
68}
69
71 int QwtPlotGraphicItem::rtti() const
72{
73 return QwtPlotItem::Rtti_PlotGraphic;
74}
75
82 void QwtPlotGraphicItem::setGraphic(
83 const QRectF& rect, const QwtGraphic& graphic )
84{
85 m_data->boundingRect = rect;
86 m_data->graphic = graphic;
87
88 legendChanged();
89 itemChanged();
90}
91
96 QwtGraphic QwtPlotGraphicItem::graphic() const
97{
98 return m_data->graphic;
99}
100
102QRectF QwtPlotGraphicItem::boundingRect() const
103{
104 return m_data->boundingRect;
105}
106
115 void QwtPlotGraphicItem::draw( QPainter* painter,
116 const QwtScaleMap& xMap, const QwtScaleMap& yMap,
117 const QRectF& canvasRect ) const
118{
119 if ( m_data->graphic.isEmpty() )
120 return;
121
122 QRectF r = QwtScaleMap::transform( xMap, yMap, boundingRect() );
123
124 if ( !r.intersects( canvasRect ) )
125 return;
126
127 if ( QwtPainter::roundingAlignment( painter ) )
128 {
129 r.setLeft ( qRound( r.left() ) );
130 r.setRight ( qRound( r.right() ) );
131 r.setTop ( qRound( r.top() ) );
132 r.setBottom ( qRound( r.bottom() ) );
133 }
134
135 m_data->graphic.render( painter, r );
136}
QwtGraphic
A paint device for scalable graphics.
Definition qwt_graphic.h:76
QwtGraphic::isEmpty
bool isEmpty() const
Definition qwt_graphic.cpp:422
QwtGraphic::render
void render(QPainter *) const
Replay all recorded painter commands.
Definition qwt_graphic.cpp:624
QwtPainter::roundingAlignment
static bool roundingAlignment()
Definition qwt_painter.h:183
QwtPlotGraphicItem::setGraphic
void setGraphic(const QRectF &rect, const QwtGraphic &)
Definition qwt_plot_graphicitem.cpp:82
QwtPlotGraphicItem::~QwtPlotGraphicItem
virtual ~QwtPlotGraphicItem()
Destructor.
Definition qwt_plot_graphicitem.cpp:54
QwtPlotGraphicItem::graphic
QwtGraphic graphic() const
Definition qwt_plot_graphicitem.cpp:96
QwtPlotGraphicItem::boundingRect
virtual QRectF boundingRect() const override
Bounding rectangle of the item.
Definition qwt_plot_graphicitem.cpp:102
QwtPlotGraphicItem::QwtPlotGraphicItem
QwtPlotGraphicItem(const QString &title=QString())
Constructor.
Definition qwt_plot_graphicitem.cpp:32
QwtPlotGraphicItem::draw
virtual void draw(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const override
Definition qwt_plot_graphicitem.cpp:115
QwtPlotGraphicItem::rtti
virtual int rtti() const override
Definition qwt_plot_graphicitem.cpp:71
QwtPlotItem
Base class for items on the plot canvas.
Definition qwt_plot_item.h:67
QwtPlotItem::legendChanged
virtual void legendChanged()
Definition qwt_plot_item.cpp:491
QwtPlotItem::setZ
void setZ(double z)
Set the z value.
Definition qwt_plot_item.cpp:165
QwtPlotItem::setItemAttribute
void setItemAttribute(ItemAttribute, bool on=true)
Definition qwt_plot_item.cpp:228
QwtPlotItem::Rtti_PlotGraphic
@ Rtti_PlotGraphic
For QwtPlotGraphicItem, QwtPlotSvgItem.
Definition qwt_plot_item.h:108
QwtPlotItem::itemChanged
virtual void itemChanged()
Definition qwt_plot_item.cpp:481
QwtPlotItem::Legend
@ Legend
The item is represented on the legend.
Definition qwt_plot_item.h:150
QwtPlotItem::AutoScale
@ AutoScale
Definition qwt_plot_item.h:157
QwtPlotItem::boundingRect
virtual QRectF boundingRect() const
Definition qwt_plot_item.cpp:568
QwtScaleMap
A scale map.
Definition qwt_scale_map.h:27
QwtScaleMap::transform
double transform(double s) const
Definition qwt_scale_map.h:137
QwtText
A class representing a text.
Definition qwt_text.h:52