Loading...
Searching...
No Matches
qwt_plot_graphicitem.cpp
/******************************************************************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_plot_graphicitem.h"
#include "qwt_scale_map.h"
#include "qwt_painter.h"
#include "qwt_text.h"
#include "qwt_graphic.h"
class QwtPlotGraphicItem::PrivateData
{
public:
QRectF boundingRect;
QwtGraphic graphic;
};
QwtPlotGraphicItem::QwtPlotGraphicItem( const QString& title )
: QwtPlotItem( QwtText( title ) )
{
init();
}
QwtPlotGraphicItem::QwtPlotGraphicItem( const QwtText& title )
: QwtPlotItem( title )
{
init();
}
QwtPlotGraphicItem::~QwtPlotGraphicItem()
{
delete m_data;
}
void QwtPlotGraphicItem::init()
{
m_data = new PrivateData();
m_data->boundingRect = QwtPlotItem::boundingRect();
setItemAttribute( QwtPlotItem::AutoScale, true );
setItemAttribute( QwtPlotItem::Legend, false );
setZ( 8.0 );
}
int QwtPlotGraphicItem::rtti() const
{
return QwtPlotItem::Rtti_PlotGraphic;
}
void QwtPlotGraphicItem::setGraphic(
const QRectF& rect, const QwtGraphic& graphic )
{
m_data->boundingRect = rect;
m_data->graphic = graphic;
legendChanged();
itemChanged();
}
QwtGraphic QwtPlotGraphicItem::graphic() const
{
return m_data->graphic;
}
QRectF QwtPlotGraphicItem::boundingRect() const
{
return m_data->boundingRect;
}
void QwtPlotGraphicItem::draw( QPainter* painter,
const QwtScaleMap& xMap, const QwtScaleMap& yMap,
const QRectF& canvasRect ) const
{
if ( m_data->graphic.isEmpty() )
return;
QRectF r = QwtScaleMap::transform( xMap, yMap, boundingRect() );
if ( !r.intersects( canvasRect ) )
return;
if ( QwtPainter::roundingAlignment( painter ) )
{
r.setLeft ( qRound( r.left() ) );
r.setRight ( qRound( r.right() ) );
r.setTop ( qRound( r.top() ) );
r.setBottom ( qRound( r.bottom() ) );
}
m_data->graphic.render( painter, r );
}
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