source: ntrip/trunk/BNC/qwt/qwt_plot_graphicitem.cpp

Last change on this file was 11158, checked in by stuerze, 4 days ago

deprecated functions exchanged libs updated

File size: 2.9 KB
Line 
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
23/*!
24 \brief Constructor
25
26 Sets the following item attributes:
27 - QwtPlotItem::AutoScale: true
28 - QwtPlotItem::Legend: false
29
30 \param title Title
31 */
32QwtPlotGraphicItem::QwtPlotGraphicItem( const QString& title )
33 : QwtPlotItem( QwtText( title ) )
34{
35 init();
36}
37
38/*!
39 \brief Constructor
40
41 Sets the following item attributes:
42 - QwtPlotItem::AutoScale: true
43 - QwtPlotItem::Legend: false
44
45 \param title Title
46 */
47QwtPlotGraphicItem::QwtPlotGraphicItem( const QwtText& title )
48 : QwtPlotItem( title )
49{
50 init();
51}
52
53//! Destructor
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
70//! \return QwtPlotItem::Rtti_PlotGraphic
71int QwtPlotGraphicItem::rtti() const
72{
73 return QwtPlotItem::Rtti_PlotGraphic;
74}
75
76/*!
77 Set the graphic to be displayed
78
79 \param rect Rectangle in plot coordinates
80 \param graphic Recorded sequence of painter commands
81 */
82void 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
92/*!
93 \return Recorded sequence of painter commands
94 \sa setGraphic()
95 */
96QwtGraphic QwtPlotGraphicItem::graphic() const
97{
98 return m_data->graphic;
99}
100
101//! Bounding rectangle of the item
102QRectF QwtPlotGraphicItem::boundingRect() const
103{
104 return m_data->boundingRect;
105}
106
107/*!
108 Draw the item
109
110 \param painter Painter
111 \param xMap X-Scale Map
112 \param yMap Y-Scale Map
113 \param canvasRect Contents rect of the plot canvas
114 */
115void 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}
Note: See TracBrowser for help on using the repository browser.