Classes | Public Member Functions | Protected Member Functions

QwtCompass Class Reference

A Compass Widget. More...

#include <qwt_compass.h>

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

List of all members.

Classes

class  PrivateData

Public Member Functions

 QwtCompass (QWidget *parent=NULL)
 Constructor.
 QwtCompass (QWidget *parent, const char *name)
 Constructor.
virtual ~QwtCompass ()
 Destructor.
void setRose (QwtCompassRose *rose)
const QwtCompassRoserose () const
QwtCompassRoserose ()
const QMap< double, QString > & labelMap () const
QMap< double, QString > & labelMap ()
void setLabelMap (const QMap< double, QString > &map)
 Set a map, mapping values to labels.

Protected Member Functions

virtual QwtText scaleLabel (double value) const
virtual void drawRose (QPainter *, const QPoint &center, int radius, double north, QPalette::ColorGroup) const
virtual void drawScaleContents (QPainter *, const QPoint &center, int radius) const
virtual void keyPressEvent (QKeyEvent *)

Detailed Description

A Compass Widget.

QwtCompass is a widget to display and enter directions. It consists of a scale, an optional needle and rose.

dials1.png
Note:
The examples/dials example shows how to use QwtCompass.

Definition at line 48 of file qwt_compass.h.


Constructor & Destructor Documentation

QwtCompass::QwtCompass ( QWidget *  parent = NULL ) [explicit]

Constructor.

Parameters:
parentParent widget

Create a compass widget with a scale, no needle and no rose. The default origin is 270.0 with no valid value. It accepts mouse and keyboard inputs and has no step size. The default mode is QwtDial::RotateNeedle.

Definition at line 50 of file qwt_compass.cpp.

                                     :
    QwtDial(parent)
{
    initCompass();
}
QwtCompass::QwtCompass ( QWidget *  parent,
const char *  name 
) [explicit]

Constructor.

Parameters:
parentParent widget
nameObject name

Create a compass widget with a scale, no needle and no rose. The default origin is 270.0 with no valid value. It accepts mouse and keyboard inputs and has no step size. The default mode is QwtDial::RotateNeedle.

Definition at line 68 of file qwt_compass.cpp.

                                                       :
    QwtDial(parent, name)
{
    initCompass();
}
QwtCompass::~QwtCompass (  ) [virtual]

Destructor.

Definition at line 77 of file qwt_compass.cpp.

{
    delete d_data;
}

Member Function Documentation

void QwtCompass::drawRose ( QPainter *  painter,
const QPoint &  center,
int  radius,
double  north,
QPalette::ColorGroup  cg 
) const [protected, virtual]

Draw the compass rose

Parameters:
painterPainter
centerCenter of the compass
radiusof the circle, where to paint the rose
northDirection pointing north, in degrees counter clockwise
cgColor group

Definition at line 149 of file qwt_compass.cpp.

References QwtCompassRose::draw(), and QwtCompass::PrivateData::rose.

Referenced by drawScaleContents().

{
    if ( d_data->rose )
        d_data->rose->draw(painter, center, radius, north,  cg);
}
void QwtCompass::drawScaleContents ( QPainter *  painter,
const QPoint &  center,
int  radius 
) const [protected, virtual]

Draw the contents of the scale

Parameters:
painterPainter
centerCenter of the content circle
radiusRadius of the content circle

Reimplemented from QwtDial.

Definition at line 120 of file qwt_compass.cpp.

References drawRose(), QwtAbstractSlider::isValid(), QwtDial::mode(), QwtDial::origin(), QwtDial::RotateScale, and QwtDoubleRange::value().

{
    QPalette::ColorGroup cg;
    if ( isEnabled() )
        cg = hasFocus() ? QPalette::Active : QPalette::Inactive;
    else
        cg = QPalette::Disabled;

    double north = origin();
    if ( isValid() )
    {
        if ( mode() == RotateScale )
            north -= value(); 
    }

    const int margin = 4;
    drawRose(painter, center, radius - margin, 360.0 - north,  cg);
}
void QwtCompass::keyPressEvent ( QKeyEvent *  kev ) [protected, virtual]

Handles key events

Beside the keys described in QwtDial::keyPressEvent numbers from 1-9 (without 5) set the direction according to their position on the num pad.

See also:
isReadOnly()

Reimplemented from QwtDial.

Definition at line 202 of file qwt_compass.cpp.

References QwtAbstractSlider::isReadOnly(), mitk::Key_1, mitk::Key_2, mitk::Key_3, mitk::Key_4, mitk::Key_5, mitk::Key_6, mitk::Key_7, mitk::Key_8, mitk::Key_9, QwtDial::mode(), QwtDial::origin(), QwtDial::RotateNeedle, QwtAbstractSlider::setValue(), and QwtDoubleRange::value().

{
    if (isReadOnly()) 
        return;

#if 0
    if ( kev->key() == Key_5 )
    {
        invalidate(); // signal ???
        return;
    }
#endif

    double newValue = value();

    if ( kev->key() >= Qt::Key_1 && kev->key() <= Qt::Key_9 )
    {
        if ( mode() != RotateNeedle || kev->key() == Qt::Key_5 )
            return;

        switch (kev->key()) 
        {
            case Qt::Key_6: 
                newValue = 180.0 * 0.0;
                break;
            case Qt::Key_3: 
                newValue = 180.0 * 0.25;
                break;
            case Qt::Key_2: 
                newValue = 180.0 * 0.5;
                break;
            case Qt::Key_1: 
                newValue = 180.0 * 0.75;
                break;
            case Qt::Key_4: 
                newValue = 180.0 * 1.0;
                break;
            case Qt::Key_7: 
                newValue = 180.0 * 1.25;
                break;
            case Qt::Key_8: 
                newValue = 180.0 * 1.5;
                break;
            case Qt::Key_9: 
                newValue = 180.0 * 1.75;
                break;
        }
        newValue -= origin();
        setValue(newValue);
    }
    else
    {
        QwtDial::keyPressEvent(kev);
    }
}
QMap< double, QString > & QwtCompass::labelMap (  )
Returns:
map, mapping values to labels
See also:
setLabelMap()

Definition at line 271 of file qwt_compass.cpp.

References QwtCompass::PrivateData::labelMap.

{ 
    return d_data->labelMap; 
}
const QMap< double, QString > & QwtCompass::labelMap (  ) const
Returns:
map, mapping values to labels
See also:
setLabelMap()

Definition at line 262 of file qwt_compass.cpp.

References QwtCompass::PrivateData::labelMap.

{ 
    return d_data->labelMap; 
}
const QwtCompassRose * QwtCompass::rose (  ) const
Returns:
rose
See also:
setRose()

Definition at line 179 of file qwt_compass.cpp.

References QwtCompass::PrivateData::rose.

Referenced by setRose().

{ 
    return d_data->rose; 
}
QwtCompassRose * QwtCompass::rose (  )
Returns:
rose
See also:
setRose()

Definition at line 188 of file qwt_compass.cpp.

References QwtCompass::PrivateData::rose.

{ 
    return d_data->rose; 
}
QwtText QwtCompass::scaleLabel ( double  value ) const [protected, virtual]

Map a value to a corresponding label

Parameters:
valueValue that will be mapped
Returns:
Label, or QString::null

label() looks in a map for a corresponding label for value or return an null text.

See also:
labelMap(), setLabelMap()

Reimplemented from QwtDial.

Definition at line 303 of file qwt_compass.cpp.

References QwtCompass::PrivateData::labelMap.

{
#if 0
    // better solution ???
    if ( value == -0 )
        value = 0.0;
#endif

    if ( value < 0.0 )
        value += 360.0;

    if ( d_data->labelMap.contains(value) )
        return d_data->labelMap[value];

    return QwtText();
}
void QwtCompass::setLabelMap ( const QMap< double, QString > &  map )

Set a map, mapping values to labels.

Parameters:
mapvalue to label map

The values of the major ticks are found by looking into this map. The default map consists of the labels N, NE, E, SE, S, SW, W, NW.

Warning:
The map will have no effect for values that are no major tick values. Major ticks can be changed by QwtScaleDraw::setScale
See also:
labelMap(), scaleDraw(), setScale()

Definition at line 288 of file qwt_compass.cpp.

References QwtCompass::PrivateData::labelMap.

{ 
    d_data->labelMap = map; 
}
void QwtCompass::setRose ( QwtCompassRose rose )

Set a rose for the compass

Parameters:
roseCompass rose
Warning:
The rose will be deleted, when a different rose is set or in ~QwtCompass
See also:
rose()

Definition at line 163 of file qwt_compass.cpp.

References rose(), and QwtCompass::PrivateData::rose.

{
    if ( rose != d_data->rose )
    {
        if ( d_data->rose )
            delete d_data->rose;

        d_data->rose = rose;
        update();
    }
}

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