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

QwtAbstractScaleDraw Class Reference

A abstract base class for drawing scales. More...

#include <qwt_abstract_scale_draw.h>

Inheritance diagram for QwtAbstractScaleDraw:
Inheritance graph
[legend]
Collaboration diagram for QwtAbstractScaleDraw:
Collaboration graph
[legend]

List of all members.

Classes

class  PrivateData

Public Types

enum  ScaleComponent { Backbone = 1, Ticks = 2, Labels = 4 }

Public Member Functions

 QwtAbstractScaleDraw ()
 Constructor.
 QwtAbstractScaleDraw (const QwtAbstractScaleDraw &)
 Copy constructor.
virtual ~QwtAbstractScaleDraw ()
 Destructor.
QwtAbstractScaleDrawoperator= (const QwtAbstractScaleDraw &)
 Assignment operator.
void setScaleDiv (const QwtScaleDiv &s)
const QwtScaleDivscaleDiv () const
void setTransformation (QwtScaleTransformation *)
const QwtScaleMapmap () const
void enableComponent (ScaleComponent, bool enable=true)
bool hasComponent (ScaleComponent) const
void setTickLength (QwtScaleDiv::TickType, int length)
int tickLength (QwtScaleDiv::TickType) const
int majTickLength () const
void setSpacing (int margin)
 Set the spacing between tick and labels.
int spacing () const
 Get the spacing.
virtual void draw (QPainter *, const QColorGroup &) const
 Draw the scale.
virtual QwtText label (double) const
 Convert a value into its representing label.
virtual int extent (const QPen &, const QFont &) const =0
void setMinimumExtent (int)
 Set a minimum for the extent.
int minimumExtent () const
QwtScaleMapscaleMap ()

Protected Member Functions

virtual void drawTick (QPainter *painter, double value, int len) const =0
virtual void drawBackbone (QPainter *painter) const =0
virtual void drawLabel (QPainter *painter, double value) const =0
void invalidateCache ()
const QwtTexttickLabel (const QFont &, double value) const
 Convert a value into its representing label and cache it.

Detailed Description

A abstract base class for drawing scales.

QwtAbstractScaleDraw can be used to draw linear or logarithmic scales.

After a scale division has been specified as a QwtScaleDiv object using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s), the scale can be drawn with the QwtAbstractScaleDraw::draw() member.

Definition at line 37 of file qwt_abstract_scale_draw.h.


Member Enumeration Documentation

Components of a scale

  • Backbone
  • Ticks
  • Labels
See also:
enableComponent(), hasComponent
Enumerator:
Backbone 
Ticks 
Labels 

Definition at line 51 of file qwt_abstract_scale_draw.h.

    { 
        Backbone = 1,
        Ticks = 2,
        Labels = 4
    };

Constructor & Destructor Documentation

QwtAbstractScaleDraw::QwtAbstractScaleDraw (  )

Constructor.

The range of the scale is initialized to [0, 100], The spacing (distance between ticks and labels) is set to 4, the tick lengths are set to 4,6 and 8 pixels

Definition at line 55 of file qwt_abstract_scale_draw.cpp.

QwtAbstractScaleDraw::QwtAbstractScaleDraw ( const QwtAbstractScaleDraw other )

Copy constructor.

Definition at line 61 of file qwt_abstract_scale_draw.cpp.

{
    d_data = new QwtAbstractScaleDraw::PrivateData(*other.d_data);
}
QwtAbstractScaleDraw::~QwtAbstractScaleDraw (  ) [virtual]

Destructor.

Definition at line 67 of file qwt_abstract_scale_draw.cpp.

{
    delete d_data;
}

Member Function Documentation

void QwtAbstractScaleDraw::draw ( QPainter *  painter,
const QColorGroup &  colorGroup 
) const [virtual]

Draw the scale.

Parameters:
painterThe painter
colorGroupColor group, text color is used for the labels, foreground color for ticks and backbone

Definition at line 152 of file qwt_abstract_scale_draw.cpp.

References Backbone, int(), Labels, QwtScaleDiv::MajorTick, QwtScaleDiv::MinorTick, QwtScaleDiv::NTickTypes, and Ticks.

Referenced by QwtThermo::draw(), QwtSlider::draw(), QwtScaleWidget::draw(), QwtPlotScaleItem::draw(), QwtKnob::draw(), QwtDial::drawScale(), and QwtPlot::printScale().

{
    if ( hasComponent(QwtAbstractScaleDraw::Labels) )
    {
        painter->save();

#if QT_VERSION < 0x040000
        painter->setPen(colorGroup.text()); // ignore pen style
#else
        painter->setPen(palette.color(QPalette::Text)); // ignore pen style
#endif

        const QwtValueList &majorTicks = 
            d_data->scldiv.ticks(QwtScaleDiv::MajorTick);

        for (int i = 0; i < (int)majorTicks.count(); i++)
        {
            const double v = majorTicks[i];
            if ( d_data->scldiv.contains(v) )
                drawLabel(painter, majorTicks[i]);
        }

        painter->restore();
    }

    if ( hasComponent(QwtAbstractScaleDraw::Ticks) )
    {
        painter->save();

        QPen pen = painter->pen();
#if QT_VERSION < 0x040000
        pen.setColor(colorGroup.foreground());
#else
        pen.setColor(palette.color(QPalette::Foreground));
#endif
        painter->setPen(pen);

        for ( int tickType = QwtScaleDiv::MinorTick; 
            tickType < QwtScaleDiv::NTickTypes; tickType++ )
        {
            const QwtValueList &ticks = d_data->scldiv.ticks(tickType);
            for (int i = 0; i < (int)ticks.count(); i++)
            {
                const double v = ticks[i];
                if ( d_data->scldiv.contains(v) )
                    drawTick(painter, v, d_data->tickLength[tickType]);
            }
        }

        painter->restore();
    }

    if ( hasComponent(QwtAbstractScaleDraw::Backbone) )
    {
        painter->save();

        QPen pen = painter->pen();
#if QT_VERSION < 0x040000
        pen.setColor(colorGroup.foreground());
#else
        pen.setColor(palette.color(QPalette::Foreground));
#endif
        painter->setPen(pen);

        drawBackbone(painter);

        painter->restore();
    }
}
virtual void QwtAbstractScaleDraw::drawBackbone ( QPainter *  painter ) const [protected, pure virtual]

Draws the baseline of the scale

Parameters:
painterPainter
See also:
drawTick(), drawLabel()

Implemented in QwtRoundScaleDraw, and QwtScaleDraw.

virtual void QwtAbstractScaleDraw::drawLabel ( QPainter *  painter,
double  value 
) const [protected, pure virtual]

Draws the label for a major scale tick

Parameters:
painterPainter
valueValue
See also:
drawTick, drawBackbone

Implemented in QwtRoundScaleDraw, and QwtScaleDraw.

virtual void QwtAbstractScaleDraw::drawTick ( QPainter *  painter,
double  value,
int  len 
) const [protected, pure virtual]

Draw a tick

Parameters:
painterPainter
valueValue of the tick
lenLenght of the tick
See also:
drawBackbone(), drawLabel()

Implemented in QwtRoundScaleDraw, and QwtScaleDraw.

void QwtAbstractScaleDraw::enableComponent ( ScaleComponent  component,
bool  enable = true 
)

En/Disable a component of the scale

Parameters:
componentScale component
enableOn/Off
See also:
hasComponent()

Definition at line 86 of file qwt_abstract_scale_draw.cpp.

References QwtAbstractScaleDraw::PrivateData::components.

Referenced by QwtDial::setScaleOptions().

{
    if ( enable )
        d_data->components |= component;
    else
        d_data->components &= ~component;
}
virtual int QwtAbstractScaleDraw::extent ( const QPen &  ,
const QFont &   
) const [pure virtual]

Calculate the extent

The extent is the distcance from the baseline to the outermost pixel of the scale draw in opposite to its orientation. It is at least minimumExtent() pixels.

See also:
setMinimumExtent(), minimumExtent()

Implemented in QwtRoundScaleDraw, and QwtScaleDraw.

bool QwtAbstractScaleDraw::hasComponent ( ScaleComponent  component ) const
void QwtAbstractScaleDraw::invalidateCache (  ) [protected]

Invalidate the cache used by QwtAbstractScaleDraw::tickLabel

The cache is invalidated, when a new QwtScaleDiv is set. If the labels need to be changed. while the same QwtScaleDiv is set, QwtAbstractScaleDraw::invalidateCache needs to be called manually.

Definition at line 403 of file qwt_abstract_scale_draw.cpp.

References QwtAbstractScaleDraw::PrivateData::labelCache.

{
    d_data->labelCache.clear();
}
QwtText QwtAbstractScaleDraw::label ( double  value ) const [virtual]

Convert a value into its representing label.

The value is converted to a plain text using QLocale::system().toString(value). This method is often overloaded by applications to have individual labels.

Parameters:
valueValue
Returns:
Label string.

Reimplemented in QwtDialScaleDraw.

Definition at line 360 of file qwt_abstract_scale_draw.cpp.

Referenced by QwtRoundScaleDraw::drawLabel(), QwtRoundScaleDraw::extent(), and tickLabel().

{
    return QLocale::system().toString(value);
}
int QwtAbstractScaleDraw::majTickLength (  ) const
const QwtScaleMap & QwtAbstractScaleDraw::map (  ) const
int QwtAbstractScaleDraw::minimumExtent (  ) const

Get the minimum extent

See also:
extent(), setMinimumExtent()

Definition at line 293 of file qwt_abstract_scale_draw.cpp.

References QwtAbstractScaleDraw::PrivateData::minExtent.

Referenced by QwtScaleDraw::extent(), and QwtRoundScaleDraw::extent().

{
    return d_data->minExtent;
}
QwtAbstractScaleDraw & QwtAbstractScaleDraw::operator= ( const QwtAbstractScaleDraw other )

Assignment operator.

Definition at line 72 of file qwt_abstract_scale_draw.cpp.

{
    *d_data = *other.d_data;
    return *this;
}
const QwtScaleDiv & QwtAbstractScaleDraw::scaleDiv (  ) const
QwtScaleMap & QwtAbstractScaleDraw::scaleMap (  )
Returns:
Map how to translate between scale and pixel values

Definition at line 132 of file qwt_abstract_scale_draw.cpp.

References QwtAbstractScaleDraw::PrivateData::map.

Referenced by QwtScaleDraw::drawTick(), QwtRoundScaleDraw::QwtRoundScaleDraw(), QwtAbstractScale::scaleMap(), and QwtRoundScaleDraw::setAngleRange().

{
    return d_data->map;
}
void QwtAbstractScaleDraw::setMinimumExtent ( int  minExtent )

Set a minimum for the extent.

The extent is calculated from the coomponents of the scale draw. In situations, where the labels are changing and the layout depends on the extent (f.e scrolling a scale), setting an upper limit as minimum extent will avoid jumps of the layout.

Parameters:
minExtentMinimum extent
See also:
extent(), minimumExtent()

Definition at line 281 of file qwt_abstract_scale_draw.cpp.

References QwtAbstractScaleDraw::PrivateData::minExtent.

{
    if ( minExtent < 0 )
        minExtent = 0;

    d_data->minExtent = minExtent;
}
void QwtAbstractScaleDraw::setScaleDiv ( const QwtScaleDiv sd )
void QwtAbstractScaleDraw::setSpacing ( int  spacing )

Set the spacing between tick and labels.

The spacing is the distance between ticks and labels. The default spacing is 4 pixels.

Parameters:
spacingSpacing
See also:
spacing()

Definition at line 247 of file qwt_abstract_scale_draw.cpp.

References spacing(), and QwtAbstractScaleDraw::PrivateData::spacing.

{
    if ( spacing < 0 )
        spacing = 0;

    d_data->spacing = spacing;
}
void QwtAbstractScaleDraw::setTickLength ( QwtScaleDiv::TickType  tickType,
int  length 
)

Set the length of the ticks

Parameters:
tickTypeTick type
lengthNew length
Warning:
the length is limited to [0..1000]

Definition at line 306 of file qwt_abstract_scale_draw.cpp.

References QwtScaleDiv::MajorTick, QwtScaleDiv::MinorTick, and QwtAbstractScaleDraw::PrivateData::tickLength.

Referenced by QwtDial::setScaleTicks().

{
    if ( tickType < QwtScaleDiv::MinorTick || 
        tickType > QwtScaleDiv::MajorTick )
    {
        return;
    }

    if ( length < 0 )
        length = 0;

    const int maxTickLen = 1000;
    if ( length > maxTickLen )
        length = 1000;

    d_data->tickLength[tickType] = length;
}
void QwtAbstractScaleDraw::setTransformation ( QwtScaleTransformation transformation )

Change the transformation of the scale

Parameters:
transformationNew scale transformation

Definition at line 119 of file qwt_abstract_scale_draw.cpp.

References QwtAbstractScaleDraw::PrivateData::map, and QwtScaleMap::setTransformation().

Referenced by QwtPlotScaleItem::draw(), QwtAbstractScale::rescale(), QwtScaleWidget::setScaleDiv(), and QwtDial::updateScale().

{
    d_data->map.setTransformation(transformation);
}
int QwtAbstractScaleDraw::spacing (  ) const

Get the spacing.

The spacing is the distance between ticks and labels. The default spacing is 4 pixels.

See also:
setSpacing()

Definition at line 263 of file qwt_abstract_scale_draw.cpp.

References QwtAbstractScaleDraw::PrivateData::spacing.

Referenced by QwtRoundScaleDraw::drawLabel(), QwtScaleDraw::extent(), QwtRoundScaleDraw::extent(), QwtScaleDraw::labelPosition(), and setSpacing().

{
    return d_data->spacing;
}
const QwtText & QwtAbstractScaleDraw::tickLabel ( const QFont &  font,
double  value 
) const [protected]

Convert a value into its representing label and cache it.

The conversion between value and label is called very often in the layout and painting code. Unfortunately the calculation of the label sizes might be slow (really slow for rich text in Qt4), so it's necessary to cache the labels.

Parameters:
fontFont
valueValue
Returns:
Tick label

Definition at line 378 of file qwt_abstract_scale_draw.cpp.

References label(), QwtAbstractScaleDraw::PrivateData::labelCache, QwtText::MinimumLayout, QwtText::setLayoutAttribute(), QwtText::setRenderFlags(), QwtText::textSize(), and void().

Referenced by QwtScaleDraw::boundingLabelRect(), QwtScaleDraw::drawLabel(), QwtRoundScaleDraw::drawLabel(), QwtRoundScaleDraw::extent(), and QwtScaleDraw::labelRect().

{
    QMap<double, QwtText>::const_iterator it = d_data->labelCache.find(value);
    if ( it == d_data->labelCache.end() )
    {
        QwtText lbl = label(value);
        lbl.setRenderFlags(0);
        lbl.setLayoutAttribute(QwtText::MinimumLayout);

        (void)lbl.textSize(font); // initialize the internal cache

        it = d_data->labelCache.insert(value, lbl);
    }

    return (*it);
}
int QwtAbstractScaleDraw::tickLength ( QwtScaleDiv::TickType  tickType ) const

Return the length of the ticks

See also:
setTickLength(), majTickLength()

Definition at line 330 of file qwt_abstract_scale_draw.cpp.

References QwtScaleDiv::MajorTick, QwtScaleDiv::MinorTick, and QwtAbstractScaleDraw::PrivateData::tickLength.

{
    if ( tickType < QwtScaleDiv::MinorTick || 
        tickType > QwtScaleDiv::MajorTick )
    {
        return 0;
    }

    return d_data->tickLength[tickType];
}

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