11#include "qwt_plot_dict.h" 
   12#include "qwt_plot_layout.h" 
   13#include "qwt_scale_widget.h" 
   14#include "qwt_scale_engine.h" 
   15#include "qwt_scale_map.h" 
   16#include "qwt_text_label.h" 
   17#include "qwt_legend.h" 
   18#include "qwt_legend_data.h" 
   19#include "qwt_plot_canvas.h" 
   24#include <qapplication.h> 
   25#include <qcoreevent.h> 
   27static inline void qwtEnableLegendItems( 
QwtPlot* plot, 
bool on )
 
   34        QObject::connect( plot, sig, plot, slot );
 
   36        QObject::disconnect( plot, sig, plot, slot );
 
   39static void qwtSetTabOrder(
 
   40    QWidget* first, QWidget* second, 
bool withChildren )
 
   50        QWidget* w = second->nextInFocusChain();
 
   51        while ( children.contains( w ) )
 
   53            children.removeAll( w );
 
   56            w = w->nextInFocusChain();
 
   60    for ( 
int i = 0; i < tabChain.size() - 1; i++ )
 
   62        QWidget* from = tabChain[i];
 
   63        QWidget* to = tabChain[i + 1];
 
   65        const Qt::FocusPolicy policy1 = from->focusPolicy();
 
   66        const Qt::FocusPolicy policy2 = to->focusPolicy();
 
   68        QWidget* proxy1 = from->focusProxy();
 
   69        QWidget* proxy2 = to->focusProxy();
 
   71        from->setFocusPolicy( Qt::TabFocus );
 
   72        from->setFocusProxy( NULL);
 
   74        to->setFocusPolicy( Qt::TabFocus );
 
   75        to->setFocusProxy( NULL);
 
   77        QWidget::setTabOrder( from, to );
 
   79        from->setFocusPolicy( policy1 );
 
   80        from->setFocusProxy( proxy1);
 
   82        to->setFocusPolicy( policy2 );
 
   83        to->setFocusProxy( proxy2 );
 
   87class QwtPlot::PrivateData
 
   90    QPointer< QwtTextLabel > titleLabel;
 
   91    QPointer< QwtTextLabel > footerLabel;
 
   92    QPointer< QWidget > canvas;
 
   93    QPointer< QwtAbstractLegend > legend;
 
  126    delete m_data->layout;
 
 
  135void QwtPlot::initPlot( 
const QwtText& title )
 
  137    m_data = 
new PrivateData;
 
  140    m_data->autoReplot = 
false;
 
  144    m_data->titleLabel->setObjectName( 
"QwtPlotTitle" );
 
  145    m_data->titleLabel->setFont( QFont( fontInfo().family(), 14, QFont::Bold ) );
 
  148    text.setRenderFlags( Qt::AlignCenter | Qt::TextWordWrap );
 
  149    m_data->titleLabel->setText( text );
 
  153    m_data->footerLabel->setObjectName( 
"QwtPlotFooter" );
 
  157    m_data->footerLabel->setText( 
footer );
 
  160    m_data->legend = NULL;
 
  167    m_data->canvas->setObjectName( 
"QwtPlotCanvas" );
 
  168    m_data->canvas->installEventFilter( 
this );
 
  170    setSizePolicy( QSizePolicy::MinimumExpanding,
 
  171        QSizePolicy::MinimumExpanding );
 
  178    focusChain << 
this << m_data->titleLabel << 
axisWidget( XTop )
 
  181               << m_data->footerLabel;
 
  183    for ( 
int i = 0; i < focusChain.size() - 1; i++ )
 
  184        qwtSetTabOrder( focusChain[i], focusChain[i + 1], 
false );
 
  186    qwtEnableLegendItems( 
this, 
true );
 
  215    if ( 
canvas == m_data->canvas )
 
  218    delete m_data->canvas;
 
  223        canvas->setParent( 
this );
 
  224        canvas->installEventFilter( 
this );
 
 
  239    bool ok = QFrame::event( 
event );
 
  240    switch ( 
event->type() )
 
  242        case QEvent::LayoutRequest:
 
  245        case QEvent::PolishRequest:
 
 
  273    if ( 
object == m_data->canvas )
 
  275        if ( 
event->type() == QEvent::Resize )
 
  279        else if ( 
event->type() == QEvent::ContentsRectChange )
 
  285    return QFrame::eventFilter( 
object, 
event );
 
 
  291    if ( m_data->autoReplot )
 
 
  312    m_data->autoReplot = tf;
 
 
  321    return m_data->autoReplot;
 
 
  330    if ( 
title != m_data->titleLabel->text().text() )
 
  332        m_data->titleLabel->setText( 
title );
 
 
  343    if ( 
title != m_data->titleLabel->text() )
 
  345        m_data->titleLabel->setText( 
title );
 
 
  353    return m_data->titleLabel->text();
 
 
  359    return m_data->titleLabel;
 
 
  365    return m_data->titleLabel;
 
 
  374    if ( text != m_data->footerLabel->text().text() )
 
  376        m_data->footerLabel->setText( text );
 
 
  387    if ( text != m_data->footerLabel->text() )
 
  389        m_data->footerLabel->setText( text );
 
 
  397    return m_data->footerLabel->text();
 
 
  403    return m_data->footerLabel;
 
 
  409    return m_data->footerLabel;
 
 
  420    if ( layout != m_data->layout )
 
  422        delete m_data->layout;
 
  423        m_data->layout = layout;
 
 
  432    return m_data->layout;
 
 
  438    return m_data->layout;
 
 
  447    return m_data->legend;
 
 
  456    return m_data->legend;
 
 
  465    return m_data->canvas;
 
 
  473    return m_data->canvas;
 
 
  485    for ( 
int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
 
  488            const QwtAxisId axisId( axisPos );
 
  492                const int niceDist = 40;
 
  501                    const int hDiff = ( majCnt - 1 ) * niceDist - hint.height();
 
  502                    dh = qMax( dh, hDiff );
 
  506                    const int wDiff = ( majCnt - 1 ) * niceDist - hint.width();
 
  507                    dw = qMax( dw, wDiff );
 
 
  521    hint += QSize( 2 * frameWidth(), 2 * frameWidth() );
 
 
  532    QFrame::resizeEvent( e );
 
 
  557    QApplication::sendPostedEvents( 
this, QEvent::LayoutRequest );
 
  559    if ( m_data->canvas )
 
  561        const bool ok = QMetaObject::invokeMethod(
 
  562            m_data->canvas, 
"replot", Qt::DirectConnection );
 
  566            m_data->canvas->update( m_data->canvas->contentsRect() );
 
 
  580    layout->
activate( 
this, contentsRect() );
 
  582    const QRect titleRect = layout->
titleRect().toRect();
 
  583    const QRect footerRect = layout->
footerRect().toRect();
 
  584    const QRect legendRect = layout->
legendRect().toRect();
 
  585    const QRect canvasRect = layout->
canvasRect().toRect();
 
  589    if ( !m_data->titleLabel->text().isEmpty() )
 
  591        m_data->titleLabel->setGeometry( titleRect );
 
  592        if ( !m_data->titleLabel->isVisibleTo( 
this ) )
 
  593            m_data->titleLabel->show();
 
  596        m_data->titleLabel->hide();
 
  598    if ( !m_data->footerLabel->text().isEmpty() )
 
  600        m_data->footerLabel->setGeometry( footerRect );
 
  601        if ( !m_data->footerLabel->isVisibleTo( 
this ) )
 
  602            m_data->footerLabel->show();
 
  606        m_data->footerLabel->hide();
 
  609    for ( 
int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
 
  612            const QwtAxisId axisId( axisPos );
 
  618                const QRect scaleRect = layout->
scaleRect( axisId ).toRect();
 
  620                if ( scaleRect != scaleWidget->geometry() )
 
  622                    scaleWidget->setGeometry( scaleRect );
 
  624                    int startDist, endDist;
 
  629                if ( !scaleWidget->isVisibleTo( 
this ) )
 
  639    if ( m_data->legend )
 
  641        if ( m_data->legend->isEmpty() )
 
  643            m_data->legend->hide();
 
  647            m_data->legend->setGeometry( legendRect );
 
  648            m_data->legend->show();
 
  652    m_data->canvas->setGeometry( canvasRect );
 
 
  671    const QwtScaleMap maps[], 
const QRectF& canvasRect,
 
  672    double& left, 
double& top, 
double& right, 
double& bottom)
 const 
  674    left = top = right = bottom = -1.0;
 
  677    for ( QwtPlotItemIterator it = itmList.begin();
 
  678        it != itmList.end(); ++it )
 
  685            double m[ AxisPositions ];
 
  688                canvasRect, m[YLeft], m[XTop], m[YRight], m[XBottom] );
 
  690            left = qwtMaxF( left, m[YLeft] );
 
  691            top = qwtMaxF( top, m[XTop] );
 
  692            right = qwtMaxF( right, m[YRight] );
 
  693            bottom = qwtMaxF( bottom, m[XBottom] );
 
 
  711    for ( 
int axisId = 0; axisId < AxisPositions; axisId++ )
 
  714    double margins[AxisPositions];
 
  716        margins[YLeft], margins[XTop], margins[YRight], margins[XBottom] );
 
  718    bool doUpdate = 
false;
 
  719    for ( 
int axisPos = 0; axisPos < AxisPositions; axisPos++ )
 
  721        if ( margins[axisPos] >= 0.0 )
 
  723            const int m = qwtCeil( margins[axisPos] );
 
 
  745    for ( 
int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
 
  748    drawItems( painter, m_data->canvas->contentsRect(), maps );
 
 
  765    const QwtScaleMap maps[ QwtAxis::AxisPositions ] )
 const 
  768    for ( QwtPlotItemIterator it = itmList.begin();
 
  769        it != itmList.end(); ++it )
 
  774            const QwtAxisId xAxis = item->
xAxis();
 
  775            const QwtAxisId yAxis = item->
yAxis();
 
  779            painter->setRenderHint( QPainter::Antialiasing,
 
  782#if QT_VERSION < 0x050100 
  783            painter->setRenderHint( QPainter::HighQualityAntialiasing,
 
  787            item->
draw( painter, maps[xAxis], maps[yAxis], canvasRect );
 
 
  803    if ( !m_data->canvas )
 
  831        const QRect& canvasRect = m_data->canvas->contentsRect();
 
  832        if ( isYAxis( axisId ) )
 
  835            if ( !
plotLayout()->alignCanvasToScale( XTop ) )
 
  839            if ( !
plotLayout()->alignCanvasToScale( XBottom ) )
 
  843                canvasRect.top() + top );
 
  848            if ( !
plotLayout()->alignCanvasToScale( YLeft ) )
 
  852            if ( !
plotLayout()->alignCanvasToScale( YRight ) )
 
  856                canvasRect.right() - right );
 
 
  875    QPalette pal = m_data->canvas->palette();
 
  876    pal.setBrush( QPalette::Window, brush );
 
  878    canvas()->setPalette( pal );
 
 
  890    return canvas()->palette().brush(
 
  891        QPalette::Normal, QPalette::Window );
 
 
  932    if ( 
legend != m_data->legend )
 
  934        if ( m_data->legend && m_data->legend->parent() == 
this )
 
  935            delete m_data->legend;
 
  939        if ( m_data->legend )
 
  946            if ( m_data->legend->parent() != 
this )
 
  947                m_data->legend->setParent( 
this );
 
  949            qwtEnableLegendItems( 
this, 
false );
 
  951            qwtEnableLegendItems( 
this, 
true );
 
  976            QWidget* previousInChain = NULL;
 
  987                    previousInChain = 
this;
 
 1003            if ( previousInChain )
 
 1004                qwtSetTabOrder( previousInChain, 
legend, 
true );
 
 
 1019    for ( QwtPlotItemIterator it = itmList.begin();
 
 1020        it != itmList.end(); ++it )
 
 
 1034    if ( plotItem == NULL )
 
 
 1058void QwtPlot::updateLegendItems( 
const QVariant& itemInfo,
 
 1065        for ( QwtPlotItemIterator it = itmList.begin();
 
 1066            it != itmList.end(); ++it )
 
 1081void QwtPlot::attachItem( 
QwtPlotItem* plotItem, 
bool on )
 
 1088        for ( QwtPlotItemIterator it = itmList.begin();
 
 1089            it != itmList.end(); ++it )
 
 1119            const QVariant itemInfo = 
itemToInfo( plotItem );
 
 1141    return QVariant::fromValue( plotItem );
 
 
 1162        return qvariant_cast< QwtPlotItem* >( itemInfo );
 
 
 1167#include "moc_qwt_plot.cpp" 
Abstract base class for legend widgets.
const QwtScaleDiv & scaleDiv() const
void setMaxColumns(uint numColums)
Set the maximum number of entries in a row.
void insertItem(QwtPlotItem *)
const QwtPlotItemList & itemList() const
A QwtPlotItemList of all attached plot items.
void removeItem(QwtPlotItem *)
void detachItems(int rtti=QwtPlotItem::Rtti_PlotItem, bool autoDelete=true)
void insertLegend(QwtAbstractLegend *, LegendPosition=QwtPlot::RightLegend, double ratio=-1.0)
Insert a legend.
virtual bool eventFilter(QObject *, QEvent *) override
Event filter.
void setPlotLayout(QwtPlotLayout *)
Assign a new plot layout.
void itemAttached(QwtPlotItem *plotItem, bool on)
void updateAxes()
Rebuild the axes scales.
virtual ~QwtPlot()
Destructor.
void setFooter(const QString &)
@ TopLegend
The legend will be above the title.
@ LeftLegend
The legend will be left from the QwtAxis::YLeft axis.
@ RightLegend
The legend will be right from the QwtAxis::YRight axis.
@ BottomLegend
The legend will be below the footer.
virtual void getCanvasMarginsHint(const QwtScaleMap maps[], const QRectF &canvasRect, double &left, double &top, double &right, double &bottom) const
Calculate the canvas margins.
QwtScaleEngine * axisScaleEngine(QwtAxisId)
virtual QVariant itemToInfo(QwtPlotItem *) const
Build an information, that can be used to identify a plot item on the legend.
virtual void drawItems(QPainter *, const QRectF &, const QwtScaleMap maps[QwtAxis::AxisPositions]) const
virtual bool event(QEvent *) override
Adds handling of layout requests.
QwtTextLabel * footerLabel()
bool isAxisVisible(QwtAxisId) const
virtual void replot()
Redraw the plot.
QwtPlotLayout * plotLayout()
void setTitle(const QString &)
virtual QSize minimumSizeHint() const override
Return a minimum size hint.
virtual QwtPlotItem * infoToItem(const QVariant &) const
Identify the plot item according to an item info object, that has bee generated from itemToInfo().
QBrush canvasBackground() const
void setAutoReplot(bool=true)
Set or reset the autoReplot option.
QwtAbstractLegend * legend()
const QwtScaleWidget * axisWidget(QwtAxisId) const
QwtTextLabel * titleLabel()
virtual QwtScaleMap canvasMap(QwtAxisId) const
QwtPlot(QWidget *=NULL)
Constructor.
virtual void resizeEvent(QResizeEvent *) override
void legendDataChanged(const QVariant &itemInfo, const QList< QwtLegendData > &data)
virtual void updateLayout()
Adjust plot content to its current size.
void setCanvasBackground(const QBrush &)
Change the background of the plotting area.
virtual void drawCanvas(QPainter *)
void setCanvas(QWidget *)
Set the drawing canvas of the plot widget.
void autoRefresh()
Replots the plot if autoReplot() is true.
const QwtScaleDiv & axisScaleDiv(QwtAxisId) const
Return the scale division of a specified axis.
void updateCanvasMargins()
Update the canvas margins.
virtual QSize sizeHint() const override
Base class for items on the plot canvas.
QwtAxisId yAxis() const
Return yAxis.
virtual void draw(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const =0
Draw the item.
virtual QList< QwtLegendData > legendData() const
Return all information, that is needed to represent the item on the legend.
QwtAxisId xAxis() const
Return xAxis.
bool testItemInterest(ItemInterest) const
@ Rtti_PlotItem
Unspecific value, that can be used, when it doesn't matter.
@ RenderAntialiased
Enable antialiasing.
bool testItemAttribute(ItemAttribute) const
bool testRenderHint(RenderHint) const
@ Legend
The item is represented on the legend.
virtual void getCanvasMarginHint(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, double &left, double &top, double &right, double &bottom) const
Calculate a hint for the canvas margin.
virtual void updateLegend(const QwtPlotItem *, const QList< QwtLegendData > &)
Update the item to changes of the legend info.
Layout engine for QwtPlot.
void setCanvasMargin(int margin, int axis=-1)
void setLegendPosition(QwtPlot::LegendPosition pos, double ratio)
Specify the position of the legend.
QRectF footerRect() const
int canvasMargin(int axisId) const
QRectF legendRect() const
QwtPlot::LegendPosition legendPosition() const
virtual QSize minimumSizeHint(const QwtPlot *) const
QRectF scaleRect(QwtAxisId) const
QRectF canvasRect() const
virtual void activate(const QwtPlot *, const QRectF &plotRect, Options options=Options())
Recalculate the geometry of all components.
A class representing a scale division.
double lowerBound() const
double upperBound() const
QList< double > ticks(int tickType) const
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
void setScaleInterval(double s1, double s2)
Specify the borders of the scale interval.
void setTransformation(QwtTransform *)
A class representing a text.
void setRenderFlags(int)
Change the render flags.
A Widget which displays a QwtText.
bool isYAxis(int axisPos)
@ YRight
Y axis right of the canvas.
@ XTop
X axis above the canvas.