Classes | Public Types | Public Member Functions | Protected Member Functions

QwtPlotCanvas Class Reference

Canvas of a QwtPlot. More...

#include <qwt_plot_canvas.h>

Collaboration diagram for QwtPlotCanvas:
Collaboration graph
[legend]

List of all members.

Classes

class  PrivateData

Public Types

enum  PaintAttribute { PaintCached = 1, PaintPacked = 2 }
 

Paint attributes.

More...
enum  FocusIndicator { NoFocusIndicator, CanvasFocusIndicator, ItemFocusIndicator }
 

Focus indicator.

More...

Public Member Functions

 QwtPlotCanvas (QwtPlot *)
 Sets a cross cursor, enables QwtPlotCanvas::PaintCached.
virtual ~QwtPlotCanvas ()
 Destructor.
QwtPlotplot ()
 Return parent plot widget.
const QwtPlotplot () const
 Return parent plot widget.
void setFocusIndicator (FocusIndicator)
FocusIndicator focusIndicator () const
void setPaintAttribute (PaintAttribute, bool on=true)
 Changing the paint attributes.
bool testPaintAttribute (PaintAttribute) const
QPixmap * paintCache ()
 Return the paint cache, might be null.
const QPixmap * paintCache () const
 Return the paint cache, might be null.
void invalidatePaintCache ()
 Invalidate the internal paint cache.
void replot ()

Protected Member Functions

virtual void hideEvent (QHideEvent *)
virtual void paintEvent (QPaintEvent *)
virtual void drawContents (QPainter *)
virtual void drawFocusIndicator (QPainter *)
void drawCanvas (QPainter *painter=NULL)

Detailed Description

Canvas of a QwtPlot.

See also:
QwtPlot

Definition at line 26 of file qwt_plot_canvas.h.


Member Enumeration Documentation

Focus indicator.

  • NoFocusIndicator
    Don't paint a focus indicator
  • CanvasFocusIndicator
    The focus is related to the complete canvas. Paint the focus indicator using paintFocus()
  • ItemFocusIndicator
    The focus is related to an item (curve, point, ...) on the canvas. It is up to the application to display a focus indication using f.e. highlighting.
See also:
setFocusIndicator(), focusIndicator(), paintFocus()
Enumerator:
NoFocusIndicator 
CanvasFocusIndicator 
ItemFocusIndicator 

Definition at line 77 of file qwt_plot_canvas.h.

Paint attributes.

  • PaintCached
    Paint double buffered and reuse the content of the pixmap buffer for some spontaneous repaints that happen when a plot gets unhidden, deiconified or changes the focus. Disabling the cache will improve the performance for incremental paints (using QwtPlotCurve::draw).
  • PaintPacked
    Suppress system background repaints and paint it together with the canvas contents. Painting packed might avoid flickering for expensive repaints, when there is a notable gap between painting the background and the plot contents.

The default setting enables PaintCached and PaintPacked

See also:
setPaintAttribute(), testPaintAttribute(), paintCache()
Enumerator:
PaintCached 
PaintPacked 

Definition at line 53 of file qwt_plot_canvas.h.

    {
        PaintCached = 1,
        PaintPacked = 2
    };

Constructor & Destructor Documentation

QwtPlotCanvas::QwtPlotCanvas ( QwtPlot plot ) [explicit]

Sets a cross cursor, enables QwtPlotCanvas::PaintCached.

Definition at line 50 of file qwt_plot_canvas.cpp.

References PaintCached, PaintPacked, and setPaintAttribute().

                                         :
    QFrame(plot)
{
    d_data = new PrivateData;

#if QT_VERSION >= 0x040100
    setAutoFillBackground(true);
#endif

#if QT_VERSION < 0x040000
    setWFlags(Qt::WNoAutoErase);
#ifndef QT_NO_CURSOR
    setCursor(Qt::crossCursor);
#endif
#else
#ifndef QT_NO_CURSOR
    setCursor(Qt::CrossCursor);
#endif
#endif // >= 0x040000

    setPaintAttribute(PaintCached, true);
    setPaintAttribute(PaintPacked, true);
}
QwtPlotCanvas::~QwtPlotCanvas (  ) [virtual]

Destructor.

Definition at line 75 of file qwt_plot_canvas.cpp.

{
    delete d_data;
}

Member Function Documentation

void QwtPlotCanvas::drawCanvas ( QPainter *  painter = NULL ) [protected]

Draw the the canvas

Paints all plot items to the contentsRect(), using QwtPlot::drawCanvas and updates the paint cache.

Parameters:
painterPainter
See also:
QwtPlot::drawCanvas(), setPaintAttributes(), testPaintAttributes()

Definition at line 292 of file qwt_plot_canvas.cpp.

References QwtPlotCanvas::PrivateData::cache, QwtPlotCanvas::PrivateData::paintAttributes, PaintCached, and PaintPacked.

Referenced by drawContents().

{
    if ( !contentsRect().isValid() )
        return;

    QBrush bgBrush;
#if QT_VERSION >= 0x040000
        bgBrush = palette().brush(backgroundRole());
#else
    QColorGroup::ColorRole role = 
        QPalette::backgroundRoleFromMode( backgroundMode() );
    bgBrush = colorGroup().brush( role );
#endif

    if ( d_data->paintAttributes & PaintCached && d_data->cache )
    {
        *d_data->cache = QPixmap(contentsRect().size());

#ifdef Q_WS_X11
#if QT_VERSION >= 0x040000
        if ( d_data->cache->x11Info().screen() != x11Info().screen() )
            d_data->cache->x11SetScreen(x11Info().screen());
#else
        if ( d_data->cache->x11Screen() != x11Screen() )
            d_data->cache->x11SetScreen(x11Screen());
#endif
#endif

        if ( d_data->paintAttributes & PaintPacked )
        {
            QPainter bgPainter(d_data->cache);
            bgPainter.setPen(Qt::NoPen);

            bgPainter.setBrush(bgBrush);
            bgPainter.drawRect(d_data->cache->rect());
        }
        else
            d_data->cache->fill(this, d_data->cache->rect().topLeft());

        QPainter cachePainter(d_data->cache);
        cachePainter.translate(-contentsRect().x(),
            -contentsRect().y());

        ((QwtPlot *)parent())->drawCanvas(&cachePainter);

        cachePainter.end();

        painter->drawPixmap(contentsRect(), *d_data->cache);
    }
    else
    {
#if QT_VERSION >= 0x040000
        if ( d_data->paintAttributes & PaintPacked )
#endif
        {
            painter->save();

            painter->setPen(Qt::NoPen);
            painter->setBrush(bgBrush);
            painter->drawRect(contentsRect());

            painter->restore();
        }

        ((QwtPlot *)parent())->drawCanvas(painter);
    }
}
void QwtPlotCanvas::drawContents ( QPainter *  painter ) [protected, virtual]

Redraw the canvas, and focus rect

Parameters:
painterPainter

Definition at line 260 of file qwt_plot_canvas.cpp.

References QwtPlot::autoReplot(), QwtPlotCanvas::PrivateData::cache, CanvasFocusIndicator, drawCanvas(), drawFocusIndicator(), focusIndicator(), QwtPlotCanvas::PrivateData::paintAttributes, PaintCached, plot(), and QwtPlot::setAutoReplot().

Referenced by paintEvent().

{
    if ( d_data->paintAttributes & PaintCached && d_data->cache 
        && d_data->cache->size() == contentsRect().size() )
    {
        painter->drawPixmap(contentsRect().topLeft(), *d_data->cache);
    }
    else
    {
        QwtPlot *plot = ((QwtPlot *)parent());
        const bool doAutoReplot = plot->autoReplot();
        plot->setAutoReplot(false);

        drawCanvas(painter);

        plot->setAutoReplot(doAutoReplot);
    }

    if ( hasFocus() && focusIndicator() == CanvasFocusIndicator )
        drawFocusIndicator(painter);
}
void QwtPlotCanvas::drawFocusIndicator ( QPainter *  painter ) [protected, virtual]

Draw the focus indication

Parameters:
painterPainter

Definition at line 364 of file qwt_plot_canvas.cpp.

References QwtPainter::drawFocusRect().

Referenced by drawContents().

{
    const int margin = 1;

    QRect focusRect = contentsRect();
    focusRect.setRect(focusRect.x() + margin, focusRect.y() + margin,
        focusRect.width() - 2 * margin, focusRect.height() - 2 * margin);

    QwtPainter::drawFocusRect(painter, this, focusRect);
}
QwtPlotCanvas::FocusIndicator QwtPlotCanvas::focusIndicator (  ) const
Returns:
Focus indicator
See also:
FocusIndicator, setFocusIndicator()

Definition at line 206 of file qwt_plot_canvas.cpp.

References QwtPlotCanvas::PrivateData::focusIndicator.

Referenced by drawContents(), and setFocusIndicator().

{
    return d_data->focusIndicator;
}
void QwtPlotCanvas::hideEvent ( QHideEvent *  event ) [protected, virtual]

Hide event

Parameters:
eventHide event

Definition at line 215 of file qwt_plot_canvas.cpp.

References QwtPlotCanvas::PrivateData::paintAttributes, and PaintPacked.

{
    QFrame::hideEvent(event);

    if ( d_data->paintAttributes & PaintPacked )
    {
        // enable system background to avoid the "looking through
        // the canvas" effect, for the next show

        setSystemBackground(true);
    }
}
void QwtPlotCanvas::invalidatePaintCache (  )

Invalidate the internal paint cache.

Definition at line 185 of file qwt_plot_canvas.cpp.

References QwtPlotCanvas::PrivateData::cache.

Referenced by replot().

{
    if ( d_data->cache )
        *d_data->cache = QPixmap();
}
const QPixmap * QwtPlotCanvas::paintCache (  ) const

Return the paint cache, might be null.

Definition at line 179 of file qwt_plot_canvas.cpp.

References QwtPlotCanvas::PrivateData::cache.

{
    return d_data->cache;
}
QPixmap * QwtPlotCanvas::paintCache (  )

Return the paint cache, might be null.

Definition at line 173 of file qwt_plot_canvas.cpp.

References QwtPlotCanvas::PrivateData::cache.

Referenced by QwtPlotCurve::draw().

{
    return d_data->cache;
}
void QwtPlotCanvas::paintEvent ( QPaintEvent *  event ) [protected, virtual]

Paint event

Parameters:
eventPaint event

Definition at line 232 of file qwt_plot_canvas.cpp.

References drawContents(), QwtPlotCanvas::PrivateData::paintAttributes, and PaintPacked.

{
#if QT_VERSION >= 0x040000
    QPainter painter(this);
    
    if ( !contentsRect().contains( event->rect() ) ) 
    {
        painter.save();
        painter.setClipRegion( event->region() & frameRect() );
        drawFrame( &painter );
        painter.restore(); 
    }

    painter.setClipRegion(event->region() & contentsRect());

    drawContents( &painter );
#else // QT_VERSION < 0x040000
    QFrame::paintEvent(event);
#endif

    if ( d_data->paintAttributes & PaintPacked )
        setSystemBackground(false);
}
const QwtPlot * QwtPlotCanvas::plot (  ) const

Return parent plot widget.

Definition at line 91 of file qwt_plot_canvas.cpp.

{
    const QWidget *w = parentWidget();
    if ( w && w->inherits("QwtPlot") )
        return (QwtPlot *)w;

    return NULL;
}
QwtPlot * QwtPlotCanvas::plot (  )

Return parent plot widget.

Definition at line 81 of file qwt_plot_canvas.cpp.

Referenced by drawContents().

{
    QWidget *w = parentWidget();
    if ( w && w->inherits("QwtPlot") )
        return (QwtPlot *)w;

    return NULL;
}
void QwtPlotCanvas::replot (  )

Invalidate the paint cache and repaint the canvas

See also:
invalidatePaintCache()

Definition at line 398 of file qwt_plot_canvas.cpp.

References invalidatePaintCache(), PaintCached, PaintPacked, and testPaintAttribute().

{
    invalidatePaintCache();

    /*
      In case of cached or packed painting the canvas
      is repainted completely and doesn't need to be erased.
     */
    const bool erase =
        !testPaintAttribute(QwtPlotCanvas::PaintPacked)
        && !testPaintAttribute(QwtPlotCanvas::PaintCached);

#if QT_VERSION >= 0x040000
    const bool noBackgroundMode = testAttribute(Qt::WA_NoBackground);
    if ( !erase && !noBackgroundMode )
        setAttribute(Qt::WA_NoBackground, true);

    repaint(contentsRect());

    if ( !erase && !noBackgroundMode )
        setAttribute(Qt::WA_NoBackground, false);
#else
    repaint(contentsRect(), erase);
#endif
}
void QwtPlotCanvas::setFocusIndicator ( FocusIndicator  focusIndicator )

Set the focus indicator

See also:
FocusIndicator, focusIndicator()

Definition at line 196 of file qwt_plot_canvas.cpp.

References focusIndicator(), and QwtPlotCanvas::PrivateData::focusIndicator.

void QwtPlotCanvas::setPaintAttribute ( PaintAttribute  attribute,
bool  on = true 
)

Changing the paint attributes.

Parameters:
attributePaint attribute
onOn/Off

The default setting enables PaintCached and PaintPacked

See also:
testPaintAttribute(), drawCanvas(), drawContents(), paintCache()

Definition at line 110 of file qwt_plot_canvas.cpp.

References QwtPlotCanvas::PrivateData::cache, QwtPlotCanvas::PrivateData::paintAttributes, PaintCached, and PaintPacked.

Referenced by QwtPlotCanvas().

{
    if ( bool(d_data->paintAttributes & attribute) == on )
        return;

    if ( on )
        d_data->paintAttributes |= attribute;
    else
        d_data->paintAttributes &= ~attribute;

    switch(attribute)
    {
        case PaintCached:
        {
            if ( on )
            {
                if ( d_data->cache == NULL )
                    d_data->cache = new QPixmap();

                if ( isVisible() )
                {
                    const QRect cr = contentsRect();
                    *d_data->cache = QPixmap::grabWidget(this,
                        cr.x(), cr.y(), cr.width(), cr.height() );
                }
            }
            else
            {
                delete d_data->cache;
                d_data->cache = NULL;
            }
            break;
        }
        case PaintPacked:
        {
            /*
              If not visible, changing of the background mode
              is delayed until it becomes visible. This tries to avoid 
              looking through the canvas when the canvas is shown the first 
              time.
             */

            if ( on == false || isVisible() )
                QwtPlotCanvas::setSystemBackground(!on);

            break;
        }
    }
}
bool QwtPlotCanvas::testPaintAttribute ( PaintAttribute  attribute ) const

Test wether a paint attribute is enabled

Parameters:
attributePaint attribute
Returns:
true if the attribute is enabled
See also:
setPaintAttribute()

Definition at line 167 of file qwt_plot_canvas.cpp.

References QwtPlotCanvas::PrivateData::paintAttributes.

Referenced by QwtPlotCurve::draw(), and replot().

{
    return (d_data->paintAttributes & attribute) != 0;
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines