1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

[OP-835] Qt 5.1.0 - migrated GCS libs/qwt

This commit is contained in:
Philippe Renon 2013-09-15 23:05:27 +02:00
parent 0e347a90f9
commit 706c371ccc
60 changed files with 872 additions and 599 deletions

View File

@ -184,7 +184,7 @@ void QwtAbstractScaleDraw::draw( QPainter *painter,
{ {
const double v = majorTicks[i]; const double v = majorTicks[i];
if ( d_data->scldiv.contains( v ) ) if ( d_data->scldiv.contains( v ) )
drawLabel( painter, majorTicks[i] ); drawLabel( painter, v );
} }
painter->restore(); painter->restore();

View File

@ -9,6 +9,7 @@
#include "qwt_analog_clock.h" #include "qwt_analog_clock.h"
#include <qmath.h> #include <qmath.h>
#include <qlocale.h>
/*! /*!
Constructor Constructor
@ -87,7 +88,7 @@ void QwtAnalogClock::setNeedle( QwtDialNeedle * )
*/ */
void QwtAnalogClock::setHand( Hand hand, QwtDialNeedle *needle ) void QwtAnalogClock::setHand( Hand hand, QwtDialNeedle *needle )
{ {
if ( hand >= 0 || hand < NHands ) if ( hand >= 0 && hand < NHands )
{ {
delete d_hand[hand]; delete d_hand[hand];
d_hand[hand] = needle; d_hand[hand] = needle;
@ -151,10 +152,10 @@ void QwtAnalogClock::setTime( const QTime &time )
*/ */
QwtText QwtAnalogClock::scaleLabel( double value ) const QwtText QwtAnalogClock::scaleLabel( double value ) const
{ {
if ( value == 0.0 ) if ( qFuzzyCompare( value + 1.0, 1.0 ) )
value = 60.0 * 60.0 * 12.0; value = 60.0 * 60.0 * 12.0;
return QString::number( int( value / ( 60.0 * 60.0 ) ) ); return QLocale().toString( qRound( value / ( 60.0 * 60.0 ) ) );
} }
/*! /*!

View File

@ -137,7 +137,7 @@ public:
~PointBuffer() ~PointBuffer()
{ {
if ( m_buffer ) if ( m_buffer )
qFree( m_buffer ); free( m_buffer );
} }
inline void setPoints( int numPoints, const Point *points ) inline void setPoints( int numPoints, const Point *points )
@ -145,7 +145,7 @@ public:
reserve( numPoints ); reserve( numPoints );
m_size = numPoints; m_size = numPoints;
qMemCopy( m_buffer, points, m_size * sizeof( Point ) ); memcpy( m_buffer, points, m_size * sizeof( Point ) );
} }
inline void reset() inline void reset()
@ -190,7 +190,7 @@ private:
while ( m_capacity < size ) while ( m_capacity < size )
m_capacity *= 2; m_capacity *= 2;
m_buffer = ( Point * ) qRealloc( m_buffer = ( Point * ) realloc(
m_buffer, m_capacity * sizeof( Point ) ); m_buffer, m_capacity * sizeof( Point ) );
} }
@ -229,7 +229,7 @@ public:
Polygon p; Polygon p;
p.resize( points1.size() ); p.resize( points1.size() );
qMemCopy( p.data(), points1.data(), points1.size() * sizeof( Point ) ); memcpy( p.data(), points1.data(), points1.size() * sizeof( Point ) );
return p; return p;
} }

View File

@ -9,7 +9,6 @@
#include "qwt_column_symbol.h" #include "qwt_column_symbol.h"
#include "qwt_math.h" #include "qwt_math.h"
#include "qwt_text.h"
#include "qwt_painter.h" #include "qwt_painter.h"
#include <qpainter.h> #include <qpainter.h>
#include <qpalette.h> #include <qpalette.h>
@ -124,8 +123,6 @@ public:
QwtColumnSymbol::FrameStyle frameStyle; QwtColumnSymbol::FrameStyle frameStyle;
QPalette palette; QPalette palette;
QwtText label;
int lineWidth; int lineWidth;
}; };

View File

@ -279,7 +279,7 @@ void QwtCompass::setLabelMap( const QMap<double, QString> &map )
QwtText QwtCompass::scaleLabel( double value ) const QwtText QwtCompass::scaleLabel( double value ) const
{ {
if ( qFuzzyCompare( value, 0.0 ) ) if ( qFuzzyCompare( value + 1.0, 1.0 ) )
value = 0.0; value = 0.0;
if ( value < 0.0 ) if ( value < 0.0 )

View File

@ -59,13 +59,8 @@ QwtSimpleCompassRose::QwtSimpleCompassRose(
const QColor light( 192, 255, 255 ); const QColor light( 192, 255, 255 );
QPalette palette; QPalette palette;
for ( int i = 0; i < QPalette::NColorGroups; i++ ) palette.setColor( QPalette::Dark, dark );
{ palette.setColor( QPalette::Light, light );
palette.setColor( ( QPalette::ColorGroup )i,
QPalette::Dark, dark );
palette.setColor( ( QPalette::ColorGroup )i,
QPalette::Light, light );
}
setPalette( palette ); setPalette( palette );
} }

View File

@ -11,6 +11,8 @@
#define _QWT_COMPAT_H_ #define _QWT_COMPAT_H_
#include "qwt_global.h" #include "qwt_global.h"
#include "qwt_interval.h"
#include "qwt_point_3d.h"
#include <qlist.h> #include <qlist.h>
#include <qvector.h> #include <qvector.h>
#include <qpoint.h> #include <qpoint.h>

View File

@ -17,41 +17,29 @@
/*! /*!
\brief The Counter Widget \brief The Counter Widget
A Counter consists of a label displaying a number and A Counter consists of a lineEdit displaying a number and
one ore more (up to three) push buttons on each side one ore more (up to three) push buttons on each side
of the label which can be used to increment or decrement of the lineEdit which can be used to increment or decrement
the counter's value. the counter's value.
A Counter has a range from a minimum value to a maximum value A Counter has a range from a minimum value to a maximum value
and a step size. The range can be specified using and a step size. The range can be specified using setRange().
QwtDblRange::setRange().
The counter's value is an integer multiple of the step size.
The number of steps by which a button increments or decrements The number of steps by which a button increments or decrements
the value can be specified using QwtCounter::setIncSteps(). the value can be specified using setIncSteps().
The number of buttons can be changed with The number of buttons can be changed with setNumButtons().
QwtCounter::setNumButtons().
Holding the space bar down with focus on a button is the
fastest method to step through the counter values.
When the counter underflows/overflows, the focus is set
to the smallest up/down button and counting is disabled.
Counting is re-enabled on a button release event (mouse or
space bar).
Example: Example:
\code \code
#include "../include/qwt_counter.h> #include <qwt_counter.h>
QwtCounter *cnt; QwtCounter *counter = new QwtCounter(parent);
cnt = new QwtCounter(parent, name); counter->setRange(0.0, 100.0, 1.0); // From 0.0 to 100, step 1.0
counter->setNumButtons(2); // Two buttons each side
counter->setIncSteps(QwtCounter::Button1, 1); // Button 1 increments 1 step
counter->setIncSteps(QwtCounter::Button2, 20); // Button 2 increments 20 steps
cnt->setRange(0.0, 100.0, 1.0); // From 0.0 to 100, step 1.0 connect(counter, SIGNAL(valueChanged(double)), my_class, SLOT(newValue(double)));
cnt->setNumButtons(2); // Two buttons each side
cnt->setIncSteps(QwtCounter::Button1, 1); // Button 1 increments 1 step
cnt->setIncSteps(QwtCounter::Button2, 20); // Button 2 increments 20 steps
connect(cnt, SIGNAL(valueChanged(double)), my_class, SLOT(newValue(double)));
\endcode \endcode
*/ */

View File

@ -317,6 +317,8 @@ double QwtWeedingCurveFitter::tolerance() const
*/ */
QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const
{ {
const double toleranceSqr = d_data->tolerance * d_data->tolerance;
QStack<Line> stack; QStack<Line> stack;
stack.reserve( 500 ); stack.reserve( 500 );
@ -325,8 +327,6 @@ QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const
QVector<bool> usePoint( nPoints, false ); QVector<bool> usePoint( nPoints, false );
double distToSegment;
stack.push( Line( 0, nPoints - 1 ) ); stack.push( Line( 0, nPoints - 1 ) );
while ( !stack.isEmpty() ) while ( !stack.isEmpty() )
@ -342,45 +342,43 @@ QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const
const double unitVecX = ( vecLength != 0.0 ) ? vecX / vecLength : 0.0; const double unitVecX = ( vecLength != 0.0 ) ? vecX / vecLength : 0.0;
const double unitVecY = ( vecLength != 0.0 ) ? vecY / vecLength : 0.0; const double unitVecY = ( vecLength != 0.0 ) ? vecY / vecLength : 0.0;
double maxDist = 0.0; double maxDistSqr = 0.0;
int nVertexIndexMaxDistance = r.from + 1; int nVertexIndexMaxDistance = r.from + 1;
for ( int i = r.from + 1; i < r.to; i++ ) for ( int i = r.from + 1; i < r.to; i++ )
{ {
//compare to anchor //compare to anchor
const double fromVecX = p[i].x() - p[r.from].x(); const double fromVecX = p[i].x() - p[r.from].x();
const double fromVecY = p[i].y() - p[r.from].y(); const double fromVecY = p[i].y() - p[r.from].y();
const double fromVecLength =
qSqrt( fromVecX * fromVecX + fromVecY * fromVecY );
double distToSegmentSqr;
if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 ) if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 )
{ {
distToSegment = fromVecLength; distToSegmentSqr = fromVecX * fromVecX + fromVecY * fromVecY;
}
if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 )
{
distToSegment = fromVecLength;
} }
else else
{ {
const double toVecX = p[i].x() - p[r.to].x(); const double toVecX = p[i].x() - p[r.to].x();
const double toVecY = p[i].y() - p[r.to].y(); const double toVecY = p[i].y() - p[r.to].y();
const double toVecLength = qSqrt( toVecX * toVecX + toVecY * toVecY ); const double toVecLength = toVecX * toVecX + toVecY * toVecY;
const double s = toVecX * ( -unitVecX ) + toVecY * ( -unitVecY ); const double s = toVecX * ( -unitVecX ) + toVecY * ( -unitVecY );
if ( s < 0.0 ) if ( s < 0.0 )
distToSegment = toVecLength; {
distToSegmentSqr = toVecLength;
}
else else
{ {
distToSegment = qSqrt( qFabs( toVecLength * toVecLength - s * s ) ); distToSegmentSqr = qFabs( toVecLength - s * s );
} }
} }
if ( maxDist < distToSegment ) if ( maxDistSqr < distToSegmentSqr )
{ {
maxDist = distToSegment; maxDistSqr = distToSegmentSqr;
nVertexIndexMaxDistance = i; nVertexIndexMaxDistance = i;
} }
} }
if ( maxDist <= d_data->tolerance ) if ( maxDistSqr <= toleranceSqr )
{ {
usePoint[r.from] = true; usePoint[r.from] = true;
usePoint[r.to] = true; usePoint[r.to] = true;
@ -392,14 +390,12 @@ QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const
} }
} }
int cnt = 0; QPolygonF stripped;
QPolygonF stripped( nPoints );
for ( int i = 0; i < nPoints; i++ ) for ( int i = 0; i < nPoints; i++ )
{ {
if ( usePoint[i] ) if ( usePoint[i] )
stripped[cnt++] = p[i]; stripped += p[i];
} }
stripped.resize( cnt );
return stripped; return stripped;
} }

View File

@ -145,13 +145,13 @@ void QwtDial::initDial()
QPalette p = palette(); QPalette p = palette();
for ( int i = 0; i < QPalette::NColorGroups; i++ ) for ( int i = 0; i < QPalette::NColorGroups; i++ )
{ {
const QPalette::ColorGroup cg = ( QPalette::ColorGroup )i; const QPalette::ColorGroup colorGroup = ( QPalette::ColorGroup )i;
// Base: background color of the circle inside the frame. // Base: background color of the circle inside the frame.
// WindowText: background color of the circle inside the scale // WindowText: background color of the circle inside the scale
p.setColor( cg, QPalette::WindowText, p.setColor( colorGroup, QPalette::WindowText,
p.color( cg, QPalette::Base ) ); p.color( colorGroup, QPalette::Base ) );
} }
setPalette( p ); setPalette( p );
@ -159,7 +159,7 @@ void QwtDial::initDial()
d_data->scaleDraw->setRadius( 0 ); d_data->scaleDraw->setRadius( 0 );
setScaleArc( 0.0, 360.0 ); // scale as a full circle setScaleArc( 0.0, 360.0 ); // scale as a full circle
setRange( 0.0, 360.0, 1.0, 10 ); // degrees as deafult setRange( 0.0, 360.0, 1.0, 10 ); // degrees as default
} }
//! Destructor //! Destructor
@ -634,7 +634,7 @@ void QwtDial::drawScale( QPainter *painter, const QPointF &center,
painter->setFont( font() ); painter->setFont( font() );
d_data->scaleDraw->setAngleRange( minArc, maxArc ); d_data->scaleDraw->setAngleRange( minArc, maxArc );
d_data->scaleDraw->setRadius( radius ); d_data->scaleDraw->setRadius( qFloor( radius ) );
d_data->scaleDraw->moveCenter( center ); d_data->scaleDraw->moveCenter( center );
QPalette pal = palette(); QPalette pal = palette();
@ -837,10 +837,8 @@ void QwtDial::setScaleTicks( int minLen, int medLen,
*/ */
QwtText QwtDial::scaleLabel( double value ) const QwtText QwtDial::scaleLabel( double value ) const
{ {
#if 1 if ( value == -0.0 )
if ( value == -0 ) value = 0.0;
value = 0;
#endif
return QString::number( value ); return QString::number( value );
} }
@ -944,13 +942,15 @@ QSize QwtDial::minimumSizeHint() const
return QSize( d, d ); return QSize( d, d );
} }
static double line2Radians( const QPointF &p1, const QPointF &p2 ) static double line2Degrees( const QPointF &p1, const QPointF &p2 )
{ {
const QPointF p = p2 - p1; const QPointF p = p2 - p1;
double angle; double angle;
if ( p.x() == 0 ) if ( p.x() == 0.0 )
{
angle = ( p.y() <= 0.0 ) ? M_PI_2 : 3 * M_PI_2; angle = ( p.y() <= 0.0 ) ? M_PI_2 : 3 * M_PI_2;
}
else else
{ {
angle = qAtan( double( -p.y() ) / double( p.x() ) ); angle = qAtan( double( -p.y() ) / double( p.x() ) );
@ -973,7 +973,7 @@ double QwtDial::getValue( const QPoint &pos )
if ( d_data->maxScaleArc == d_data->minScaleArc || maxValue() == minValue() ) if ( d_data->maxScaleArc == d_data->minScaleArc || maxValue() == minValue() )
return minValue(); return minValue();
double dir = line2Radians( innerRect().center(), pos ) - d_data->origin; double dir = line2Degrees( innerRect().center(), pos ) - d_data->origin;
if ( dir < 0.0 ) if ( dir < 0.0 )
dir += 360.0; dir += 360.0;
@ -1122,7 +1122,8 @@ void QwtDial::keyPressEvent( QKeyEvent *event )
if ( !isValid() ) if ( !isValid() )
return; return;
double previous = prevValue(); const double previousValue = value();
switch ( event->key() ) switch ( event->key() )
{ {
case Qt::Key_Down: case Qt::Key_Down:
@ -1150,6 +1151,6 @@ void QwtDial::keyPressEvent( QKeyEvent *event )
event->ignore(); event->ignore();
} }
if ( value() != previous ) if ( value() != previousValue )
Q_EMIT sliderMoved( value() ); Q_EMIT sliderMoved( value() );
} }

View File

@ -14,6 +14,11 @@
#include <qapplication.h> #include <qapplication.h>
#include <qpainter.h> #include <qpainter.h>
#if QT_VERSION < 0x040601
#define qFastSin(x) qSin(x)
#define qFastCos(x) qCos(x)
#endif
static void qwtDrawStyle1Needle( QPainter *painter, static void qwtDrawStyle1Needle( QPainter *painter,
const QPalette &palette, QPalette::ColorGroup colorGroup, const QPalette &palette, QPalette::ColorGroup colorGroup,
double length ) double length )
@ -27,8 +32,8 @@ static void qwtDrawStyle1Needle( QPainter *painter,
const double angle = a[i] / 180.0 * M_PI; const double angle = a[i] / 180.0 * M_PI;
const double radius = r[i] * length; const double radius = r[i] * length;
const double x = radius * qCos( angle ); const double x = radius * qFastCos( angle );
const double y = radius * qSin( angle ); const double y = radius * qFastSin( angle );
path.lineTo( x, -y ); path.lineTo( x, -y );
} }
@ -278,13 +283,8 @@ QwtDialSimpleNeedle::QwtDialSimpleNeedle( Style style, bool hasKnob,
d_width( -1 ) d_width( -1 )
{ {
QPalette palette; QPalette palette;
for ( int i = 0; i < QPalette::NColorGroups; i++ ) palette.setColor( QPalette::Mid, mid );
{ palette.setColor( QPalette::Base, base );
palette.setColor( ( QPalette::ColorGroup )i,
QPalette::Mid, mid );
palette.setColor( ( QPalette::ColorGroup )i,
QPalette::Base, base );
}
setPalette( palette ); setPalette( palette );
} }
@ -340,7 +340,7 @@ void QwtDialSimpleNeedle::drawNeedle( QPainter *painter,
pen.setCapStyle( Qt::FlatCap ); pen.setCapStyle( Qt::FlatCap );
painter->setPen( pen ); painter->setPen( pen );
painter->drawLine( 0, 0, length, 0 ); painter->drawLine( QPointF( 0.0, 0.0 ), QPointF( length, 0.0 ) );
knobWidth = qMax( width * 3.0, 5.0 ); knobWidth = qMax( width * 3.0, 5.0 );
} }
@ -359,15 +359,9 @@ QwtCompassMagnetNeedle::QwtCompassMagnetNeedle( Style style,
d_style( style ) d_style( style )
{ {
QPalette palette; QPalette palette;
for ( int i = 0; i < QPalette::NColorGroups; i++ ) palette.setColor( QPalette::Light, light );
{ palette.setColor( QPalette::Dark, dark );
palette.setColor( ( QPalette::ColorGroup )i, palette.setColor( QPalette::Base, Qt::gray );
QPalette::Light, light );
palette.setColor( ( QPalette::ColorGroup )i,
QPalette::Dark, dark );
palette.setColor( ( QPalette::ColorGroup )i,
QPalette::Base, Qt::gray );
}
setPalette( palette ); setPalette( palette );
} }
@ -424,13 +418,8 @@ QwtCompassWindArrow::QwtCompassWindArrow( Style style,
d_style( style ) d_style( style )
{ {
QPalette palette; QPalette palette;
for ( int i = 0; i < QPalette::NColorGroups; i++ ) palette.setColor( QPalette::Light, light );
{ palette.setColor( QPalette::Dark, dark );
palette.setColor( ( QPalette::ColorGroup )i,
QPalette::Light, light );
palette.setColor( ( QPalette::ColorGroup )i,
QPalette::Dark, dark );
}
setPalette( palette ); setPalette( palette );
} }

View File

@ -88,7 +88,7 @@ void QwtDoubleRange::setNewValue( double value, bool align )
if ( d_data->periodic && vmin != vmax ) if ( d_data->periodic && vmin != vmax )
{ {
d_data->value = value + d_data->value = value +
qwtCeilF( ( vmin - value ) / ( vmax - vmin ) ) * ( vmax - vmin ); ::ceil( ( vmin - value ) / ( vmax - vmin ) ) * ( vmax - vmin );
} }
else else
d_data->value = vmin; d_data->value = vmin;
@ -98,7 +98,7 @@ void QwtDoubleRange::setNewValue( double value, bool align )
if ( ( d_data->periodic ) && ( vmin != vmax ) ) if ( ( d_data->periodic ) && ( vmin != vmax ) )
{ {
d_data->value = value - d_data->value = value -
qwtCeilF( ( value - vmax ) / ( vmax - vmin ) ) * ( vmax - vmin ); ::ceil( ( value - vmax ) / ( vmax - vmin ) ) * ( vmax - vmin );
} }
else else
d_data->value = vmax; d_data->value = vmax;

View File

@ -9,7 +9,7 @@
#include "qwt_dyngrid_layout.h" #include "qwt_dyngrid_layout.h"
#include "qwt_math.h" #include "qwt_math.h"
#include <qwidget.h> #include <qvector.h>
#include <qlist.h> #include <qlist.h>
class QwtDynGridLayout::PrivateData class QwtDynGridLayout::PrivateData
@ -211,7 +211,7 @@ Qt::Orientations QwtDynGridLayout::expandingDirections() const
} }
/*! /*!
Reorganizes columns and rows and resizes managed widgets within Reorganizes columns and rows and resizes managed items within
the rectangle rect. the rectangle rect.
\param rect Layout geometry \param rect Layout geometry
@ -234,12 +234,8 @@ void QwtDynGridLayout::setGeometry( const QRect &rect )
for ( QList<QLayoutItem*>::iterator it = d_data->itemList.begin(); for ( QList<QLayoutItem*>::iterator it = d_data->itemList.begin();
it != d_data->itemList.end(); ++it ) it != d_data->itemList.end(); ++it )
{ {
QWidget *w = ( *it )->widget(); ( *it )->setGeometry( itemGeometries[index] );
if ( w ) index++;
{
w->setGeometry( itemGeometries[index] );
index++;
}
} }
} }
@ -256,11 +252,14 @@ uint QwtDynGridLayout::columnsForWidth( int width ) const
if ( isEmpty() ) if ( isEmpty() )
return 0; return 0;
const int maxCols = ( d_data->maxCols > 0 ) ? d_data->maxCols : itemCount(); uint maxCols = itemCount();
if ( d_data->maxCols > 0 )
maxCols = qMin( d_data->maxCols, maxCols );
if ( maxRowWidth( maxCols ) <= width ) if ( maxRowWidth( maxCols ) <= width )
return maxCols; return maxCols;
for ( int numCols = 2; numCols <= maxCols; numCols++ ) for ( uint numCols = 2; numCols <= maxCols; numCols++ )
{ {
const int rowWidth = maxRowWidth( numCols ); const int rowWidth = maxRowWidth( numCols );
if ( rowWidth > width ) if ( rowWidth > width )
@ -342,9 +341,12 @@ QList<QRect> QwtDynGridLayout::layoutItems( const QRect &rect,
return itemGeometries; return itemGeometries;
uint numRows = itemCount() / numCols; uint numRows = itemCount() / numCols;
if ( numRows % itemCount() ) if ( numCols % itemCount() )
numRows++; numRows++;
if ( numRows == 0 )
return itemGeometries;
QVector<int> rowHeight( numRows ); QVector<int> rowHeight( numRows );
QVector<int> colWidth( numCols ); QVector<int> colWidth( numCols );
@ -371,11 +373,11 @@ QList<QRect> QwtDynGridLayout::layoutItems( const QRect &rect,
const int xySpace = spacing(); const int xySpace = spacing();
rowY[0] = yOffset + margin(); rowY[0] = yOffset + margin();
for ( int r = 1; r < ( int )numRows; r++ ) for ( uint r = 1; r < numRows; r++ )
rowY[r] = rowY[r-1] + rowHeight[r-1] + xySpace; rowY[r] = rowY[r-1] + rowHeight[r-1] + xySpace;
colX[0] = xOffset + margin(); colX[0] = xOffset + margin();
for ( int c = 1; c < ( int )numCols; c++ ) for ( uint c = 1; c < numCols; c++ )
colX[c] = colX[c-1] + colWidth[c-1] + xySpace; colX[c] = colX[c-1] + colWidth[c-1] + xySpace;
const int itemCount = d_data->itemList.size(); const int itemCount = d_data->itemList.size();
@ -411,8 +413,7 @@ void QwtDynGridLayout::layoutGrid( uint numCols,
if ( d_data->isDirty ) if ( d_data->isDirty )
d_data->updateLayoutCache(); d_data->updateLayoutCache();
for ( uint index = 0; for ( int index = 0; index < d_data->itemSizeHints.count(); index++ )
index < ( uint )d_data->itemSizeHints.count(); index++ )
{ {
const int row = index / numCols; const int row = index / numCols;
const int col = index % numCols; const int col = index % numCols;
@ -455,7 +456,7 @@ int QwtDynGridLayout::heightForWidth( int width ) const
layoutGrid( numCols, rowHeight, colWidth ); layoutGrid( numCols, rowHeight, colWidth );
int h = 2 * margin() + ( numRows - 1 ) * spacing(); int h = 2 * margin() + ( numRows - 1 ) * spacing();
for ( int row = 0; row < ( int )numRows; row++ ) for ( uint row = 0; row < numRows; row++ )
h += rowHeight[row]; h += rowHeight[row];
return h; return h;
@ -481,12 +482,12 @@ void QwtDynGridLayout::stretchGrid( const QRect &rect,
if ( expandH ) if ( expandH )
{ {
int xDelta = rect.width() - 2 * margin() - ( numCols - 1 ) * spacing(); int xDelta = rect.width() - 2 * margin() - ( numCols - 1 ) * spacing();
for ( int col = 0; col < ( int )numCols; col++ ) for ( uint col = 0; col < numCols; col++ )
xDelta -= colWidth[col]; xDelta -= colWidth[col];
if ( xDelta > 0 ) if ( xDelta > 0 )
{ {
for ( int col = 0; col < ( int )numCols; col++ ) for ( uint col = 0; col < numCols; col++ )
{ {
const int space = xDelta / ( numCols - col ); const int space = xDelta / ( numCols - col );
colWidth[col] += space; colWidth[col] += space;
@ -502,12 +503,12 @@ void QwtDynGridLayout::stretchGrid( const QRect &rect,
numRows++; numRows++;
int yDelta = rect.height() - 2 * margin() - ( numRows - 1 ) * spacing(); int yDelta = rect.height() - 2 * margin() - ( numRows - 1 ) * spacing();
for ( int row = 0; row < ( int )numRows; row++ ) for ( uint row = 0; row < numRows; row++ )
yDelta -= rowHeight[row]; yDelta -= rowHeight[row];
if ( yDelta > 0 ) if ( yDelta > 0 )
{ {
for ( int row = 0; row < ( int )numRows; row++ ) for ( uint row = 0; row < numRows; row++ )
{ {
const int space = yDelta / ( numRows - row ); const int space = yDelta / ( numRows - row );
rowHeight[row] += space; rowHeight[row] += space;
@ -529,7 +530,10 @@ QSize QwtDynGridLayout::sizeHint() const
if ( isEmpty() ) if ( isEmpty() )
return QSize(); return QSize();
const uint numCols = ( d_data->maxCols > 0 ) ? d_data->maxCols : itemCount(); uint numCols = itemCount();
if ( d_data->maxCols > 0 )
numCols = qMin( d_data->maxCols, numCols );
uint numRows = itemCount() / numCols; uint numRows = itemCount() / numCols;
if ( itemCount() % numCols ) if ( itemCount() % numCols )
numRows++; numRows++;
@ -540,11 +544,11 @@ QSize QwtDynGridLayout::sizeHint() const
layoutGrid( numCols, rowHeight, colWidth ); layoutGrid( numCols, rowHeight, colWidth );
int h = 2 * margin() + ( numRows - 1 ) * spacing(); int h = 2 * margin() + ( numRows - 1 ) * spacing();
for ( int row = 0; row < ( int )numRows; row++ ) for ( uint row = 0; row < numRows; row++ )
h += rowHeight[row]; h += rowHeight[row];
int w = 2 * margin() + ( numCols - 1 ) * spacing(); int w = 2 * margin() + ( numCols - 1 ) * spacing();
for ( int col = 0; col < ( int )numCols; col++ ) for ( uint col = 0; col < numCols; col++ )
w += colWidth[col]; w += colWidth[col];
return QSize( w, h ); return QSize( w, h );

View File

@ -14,26 +14,23 @@
// QWT_VERSION is (major << 16) + (minor << 8) + patch. // QWT_VERSION is (major << 16) + (minor << 8) + patch.
#define QWT_VERSION 0x060001 #define QWT_VERSION 0x060002
#define QWT_VERSION_STR "6.0.1" #define QWT_VERSION_STR "6.0.2"
#if defined(Q_WS_WIN) || defined(Q_WS_S60)
#if defined(_MSC_VER) /* MSVC Compiler */ #if defined(_MSC_VER) /* MSVC Compiler */
/* template-class specialization 'identifier' is already instantiated */ /* template-class specialization 'identifier' is already instantiated */
#pragma warning(disable: 4660) #pragma warning(disable: 4660)
#endif // _MSC_VER #endif // _MSC_VER
#ifdef QWT_DLL
#if defined(QWT_MAKEDLL) // create a Qwt DLL library #if defined(QWT_MAKEDLL) // create a Qwt DLL library
#define QWT_EXPORT Q_DECL_EXPORT #define QWT_EXPORT Q_DECL_EXPORT
#define QWT_TEMPLATEDLL
#else // use a Qwt DLL library #else // use a Qwt DLL library
#define QWT_EXPORT Q_DECL_IMPORT #define QWT_EXPORT Q_DECL_IMPORT
#endif #endif
#endif // QWT_DLL
#endif // Q_WS_WIN || Q_WS_S60
#ifndef QWT_EXPORT #ifndef QWT_EXPORT
#define QWT_EXPORT #define QWT_EXPORT

View File

@ -198,6 +198,19 @@ inline double QwtInterval::maxValue() const
return d_maxValue; return d_maxValue;
} }
/*!
A interval is valid when minValue() <= maxValue().
In case of QwtInterval::ExcludeBorders it is true
when minValue() < maxValue()
*/
inline bool QwtInterval::isValid() const
{
if ( ( d_borderFlags & ExcludeBorders ) == 0 )
return d_minValue <= d_maxValue;
else
return d_minValue < d_maxValue;
}
/*! /*!
Return the width of an interval Return the width of an interval
The width of invalid intervals is 0.0, otherwise the result is The width of invalid intervals is 0.0, otherwise the result is
@ -262,19 +275,6 @@ inline bool QwtInterval::isNull() const
return isValid() && d_minValue >= d_maxValue; return isValid() && d_minValue >= d_maxValue;
} }
/*!
A interval is valid when minValue() <= maxValue().
In case of QwtInterval::ExcludeBorders it is true
when minValue() < maxValue()
*/
inline bool QwtInterval::isValid() const
{
if ( ( d_borderFlags & ExcludeBorders ) == 0 )
return d_minValue <= d_maxValue;
else
return d_minValue < d_maxValue;
}
/*! /*!
Invalidate the interval Invalidate the interval

View File

@ -14,6 +14,8 @@
#if QT_VERSION < 0x040601 #if QT_VERSION < 0x040601
#define qAtan2(y, x) ::atan2(y, x) #define qAtan2(y, x) ::atan2(y, x)
#define qFastSin(x) qSin(x)
#define qFastCos(x) qCos(x)
#endif #endif
class QwtIntervalSymbol::PrivateData class QwtIntervalSymbol::PrivateData
@ -231,8 +233,8 @@ void QwtIntervalSymbol::draw( QPainter *painter, Qt::Orientation orientation,
const double angle = qAtan2( dy, dx ) + M_PI_2; const double angle = qAtan2( dy, dx ) + M_PI_2;
double dw2 = sw / 2.0; double dw2 = sw / 2.0;
const double cx = qCos( angle ) * dw2; const double cx = qFastCos( angle ) * dw2;
const double sy = qSin( angle ) * dw2; const double sy = qFastSin( angle ) * dw2;
QwtPainter::drawLine( painter, QwtPainter::drawLine( painter,
p1.x() - cx, p1.y() - sy, p1.x() - cx, p1.y() - sy,
@ -279,8 +281,8 @@ void QwtIntervalSymbol::draw( QPainter *painter, Qt::Orientation orientation,
const double angle = qAtan2( dy, dx ) + M_PI_2; const double angle = qAtan2( dy, dx ) + M_PI_2;
double dw2 = sw / 2.0; double dw2 = sw / 2.0;
const int cx = qCos( angle ) * dw2; const double cx = qFastCos( angle ) * dw2;
const int sy = qSin( angle ) * dw2; const double sy = qFastSin( angle ) * dw2;
QPolygonF polygon; QPolygonF polygon;
polygon += QPointF( p1.x() - cx, p1.y() - sy ); polygon += QPointF( p1.x() - cx, p1.y() - sy );

View File

@ -22,8 +22,8 @@
#if QT_VERSION < 0x040601 #if QT_VERSION < 0x040601
#define qAtan2(y, x) ::atan2(y, x) #define qAtan2(y, x) ::atan2(y, x)
#define qFabs(x) ::fabs(x) #define qFabs(x) ::fabs(x)
#define qFastCos(x) ::cos(x) #define qFastCos(x) qCos(x)
#define qFastSin(x) ::sin(x) #define qFastSin(x) qSin(x)
#endif #endif
class QwtKnob::PrivateData class QwtKnob::PrivateData
@ -254,19 +254,21 @@ double QwtKnob::getValue( const QPoint &pos )
void QwtKnob::getScrollMode( const QPoint &pos, void QwtKnob::getScrollMode( const QPoint &pos,
QwtAbstractSlider::ScrollMode &scrollMode, int &direction ) const QwtAbstractSlider::ScrollMode &scrollMode, int &direction ) const
{ {
const int r = d_data->knobRect.width() / 2; const double r = 0.5 * d_data->knobRect.width();
const double dx = d_data->knobRect.x() + r - pos.x();
const double dy = d_data->knobRect.y() + r - pos.y();
const int dx = d_data->knobRect.x() + r - pos.x(); if ( qwtSqr( dx ) + qwtSqr( dy ) <= qwtSqr( r ) )
const int dy = d_data->knobRect.y() + r - pos.y();
if ( ( dx * dx ) + ( dy * dy ) <= ( r * r ) ) // point is inside the knob
{ {
// point is inside the knob
scrollMode = QwtAbstractSlider::ScrMouse; scrollMode = QwtAbstractSlider::ScrMouse;
direction = 0; direction = 0;
} }
else // point lies outside else // point lies outside
{ {
scrollMode = QwtAbstractSlider::ScrTimer; scrollMode = QwtAbstractSlider::ScrTimer;
double arc = qAtan2( double( -dx ), double( dy ) ) * 180.0 / M_PI; double arc = qAtan2( double( -dx ), double( dy ) ) * 180.0 / M_PI;
if ( arc < d_data->angle ) if ( arc < d_data->angle )
direction = -1; direction = -1;
@ -375,8 +377,7 @@ void QwtKnob::paintEvent( QPaintEvent *event )
\param painter painter \param painter painter
\param knobRect Bounding rectangle of the knob (without scale) \param knobRect Bounding rectangle of the knob (without scale)
*/ */
void QwtKnob::drawKnob( QPainter *painter, void QwtKnob::drawKnob( QPainter *painter, const QRectF &knobRect ) const
const QRectF &knobRect ) const
{ {
double dim = qMin( knobRect.width(), knobRect.height() ); double dim = qMin( knobRect.width(), knobRect.height() );
dim -= d_data->borderWidth * 0.5; dim -= d_data->borderWidth * 0.5;
@ -406,7 +407,7 @@ void QwtKnob::drawKnob( QPainter *painter,
{ {
double off = 0.3 * knobRect.width(); double off = 0.3 * knobRect.width();
QRadialGradient gradient( knobRect.center(), QRadialGradient gradient( knobRect.center(),
knobRect.width(), knobRect.topLeft() + QPoint( off, off ) ); knobRect.width(), knobRect.topLeft() + QPointF( off, off ) );
gradient.setColorAt( 0.0, palette().color( QPalette::Midlight ) ); gradient.setColorAt( 0.0, palette().color( QPalette::Midlight ) );
gradient.setColorAt( 1.0, palette().color( QPalette::Button ) ); gradient.setColorAt( 1.0, palette().color( QPalette::Button ) );
@ -521,7 +522,7 @@ void QwtKnob::drawMarker( QPainter *painter,
const double rb = qMax( radius - d_data->markerSize, 1.0 ); const double rb = qMax( radius - d_data->markerSize, 1.0 );
const double re = radius; const double re = radius;
const QLine line( xm - sinA * rb, ym - cosA * rb, const QLineF line( xm - sinA * rb, ym - cosA * rb,
xm - sinA * re, ym - cosA * re ); xm - sinA * re, ym - cosA * re );
QPen pen( palette().color( QPalette::ButtonText ), 0 ); QPen pen( palette().color( QPalette::ButtonText ), 0 );
@ -615,9 +616,7 @@ int QwtKnob::markerSize() const
*/ */
void QwtKnob::recalcAngle() void QwtKnob::recalcAngle()
{ {
//
// calculate the angle corresponding to the value // calculate the angle corresponding to the value
//
if ( maxValue() == minValue() ) if ( maxValue() == minValue() )
{ {
d_data->angle = 0; d_data->angle = 0;

View File

@ -410,7 +410,7 @@ void QwtMagnifier::widgetWheelEvent( QWheelEvent *wheelEvent )
of 120 (== 15 * 8). of 120 (== 15 * 8).
*/ */
double f = qPow( d_data->wheelFactor, double f = qPow( d_data->wheelFactor,
qAbs( wheelEvent->delta() / 120 ) ); qAbs( wheelEvent->delta() / 120.0 ) );
if ( wheelEvent->delta() > 0 ) if ( wheelEvent->delta() > 0 )
f = 1 / f; f = 1 / f;
@ -456,18 +456,12 @@ void QwtMagnifier::widgetKeyReleaseEvent( QKeyEvent *keyEvent )
//! \return Parent widget, where the rescaling happens //! \return Parent widget, where the rescaling happens
QWidget *QwtMagnifier::parentWidget() QWidget *QwtMagnifier::parentWidget()
{ {
if ( parent()->inherits( "QWidget" ) ) return qobject_cast<QWidget *>( parent() );
return ( QWidget * )parent();
return NULL;
} }
//! \return Parent widget, where the rescaling happens //! \return Parent widget, where the rescaling happens
const QWidget *QwtMagnifier::parentWidget() const const QWidget *QwtMagnifier::parentWidget() const
{ {
if ( parent()->inherits( "QWidget" ) ) return qobject_cast<const QWidget *>( parent() );
return ( const QWidget * )parent();
return NULL;
} }

View File

@ -231,7 +231,7 @@ void QwtPainter::fillRect( QPainter *painter,
QRectF r = rect; QRectF r = rect;
if ( deviceClipping ) if ( deviceClipping )
r = r.intersect( clipRect ); r = r.intersected( clipRect );
if ( r.isValid() ) if ( r.isValid() )
painter->fillRect( r, brush ); painter->fillRect( r, brush );
@ -405,7 +405,7 @@ void QwtPainter::drawPolyline( QPainter *painter,
if ( deviceClipping ) if ( deviceClipping )
{ {
QPolygonF polygon( pointCount ); QPolygonF polygon( pointCount );
qMemCopy( polygon.data(), points, pointCount * sizeof( QPointF ) ); memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) );
polygon = QwtClipper::clipPolygonF( clipRect, polygon ); polygon = QwtClipper::clipPolygonF( clipRect, polygon );
::drawPolyline( painter, ::drawPolyline( painter,

View File

@ -22,13 +22,9 @@ static QVector<QwtPicker *> qwtActivePickers( QWidget *w )
QObjectList children = w->children(); QObjectList children = w->children();
for ( int i = 0; i < children.size(); i++ ) for ( int i = 0; i < children.size(); i++ )
{ {
QObject *obj = children[i]; QwtPicker *picker = qobject_cast<QwtPicker *>( children[i] );
if ( obj->inherits( "QwtPicker" ) ) if ( picker && picker->isEnabled() )
{ pickers += picker;
QwtPicker *picker = ( QwtPicker * )obj;
if ( picker->isEnabled() )
pickers += picker;
}
} }
return pickers; return pickers;
@ -390,13 +386,13 @@ void QwtPanner::widgetMousePressEvent( QMouseEvent *mouseEvent )
// We don't want to grab the picker ! // We don't want to grab the picker !
QVector<QwtPicker *> pickers = qwtActivePickers( parentWidget() ); QVector<QwtPicker *> pickers = qwtActivePickers( parentWidget() );
for ( int i = 0; i < ( int )pickers.size(); i++ ) for ( int i = 0; i < pickers.size(); i++ )
pickers[i]->setEnabled( false ); pickers[i]->setEnabled( false );
d_data->pixmap = grab(); d_data->pixmap = grab();
d_data->contentsMask = contentsMask(); d_data->contentsMask = contentsMask();
for ( int i = 0; i < ( int )pickers.size(); i++ ) for ( int i = 0; i < pickers.size(); i++ )
pickers[i]->setEnabled( true ); pickers[i]->setEnabled( true );
show(); show();

View File

@ -42,6 +42,7 @@ public:
protected: protected:
virtual void paintEvent( QPaintEvent * ); virtual void paintEvent( QPaintEvent * );
virtual void resizeEvent( QResizeEvent * );
QwtPicker *d_picker; QwtPicker *d_picker;
Type d_type; Type d_type;
@ -196,6 +197,13 @@ void QwtPicker::PickerWidget::paintEvent( QPaintEvent *e )
} }
} }
void QwtPicker::PickerWidget::resizeEvent( QResizeEvent *event )
{
QWidget::resizeEvent( event );
if ( isVisible() )
updateMask();
}
/*! /*!
Constructor Constructor
@ -820,32 +828,50 @@ bool QwtPicker::eventFilter( QObject *object, QEvent *event )
break; break;
} }
case QEvent::Enter: case QEvent::Enter:
{
widgetEnterEvent( event ); widgetEnterEvent( event );
break; break;
}
case QEvent::Leave: case QEvent::Leave:
{
widgetLeaveEvent( event ); widgetLeaveEvent( event );
break; break;
}
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
{
widgetMousePressEvent( ( QMouseEvent * )event ); widgetMousePressEvent( ( QMouseEvent * )event );
break; break;
}
case QEvent::MouseButtonRelease: case QEvent::MouseButtonRelease:
{
widgetMouseReleaseEvent( ( QMouseEvent * )event ); widgetMouseReleaseEvent( ( QMouseEvent * )event );
break; break;
}
case QEvent::MouseButtonDblClick: case QEvent::MouseButtonDblClick:
{
widgetMouseDoubleClickEvent( ( QMouseEvent * )event ); widgetMouseDoubleClickEvent( ( QMouseEvent * )event );
break; break;
}
case QEvent::MouseMove: case QEvent::MouseMove:
{
widgetMouseMoveEvent( ( QMouseEvent * )event ); widgetMouseMoveEvent( ( QMouseEvent * )event );
break; break;
}
case QEvent::KeyPress: case QEvent::KeyPress:
{
widgetKeyPressEvent( ( QKeyEvent * )event ); widgetKeyPressEvent( ( QKeyEvent * )event );
break; break;
}
case QEvent::KeyRelease: case QEvent::KeyRelease:
{
widgetKeyReleaseEvent( ( QKeyEvent * )event ); widgetKeyReleaseEvent( ( QKeyEvent * )event );
break; break;
}
case QEvent::Wheel: case QEvent::Wheel:
{
widgetWheelEvent( ( QWheelEvent * )event ); widgetWheelEvent( ( QWheelEvent * )event );
break; break;
}
default: default:
break; break;
} }
@ -1396,6 +1422,7 @@ void QwtPicker::updateDisplay()
if ( rw.isNull() ) if ( rw.isNull() )
{ {
rw = new PickerWidget( this, w, PickerWidget::RubberBand ); rw = new PickerWidget( this, w, PickerWidget::RubberBand );
rw->setObjectName( "PickerRubberBand" );
rw->resize( w->size() ); rw->resize( w->size() );
} }
rw->updateMask(); rw->updateMask();
@ -1410,6 +1437,7 @@ void QwtPicker::updateDisplay()
if ( tw.isNull() ) if ( tw.isNull() )
{ {
tw = new PickerWidget( this, w, PickerWidget::Text ); tw = new PickerWidget( this, w, PickerWidget::Text );
tw->setObjectName( "PickerTracker" );
tw->resize( w->size() ); tw->resize( w->size() );
} }
tw->setFont( d_data->trackerFont ); tw->setFont( d_data->trackerFont );

View File

@ -97,16 +97,16 @@ QwtPickerClickPointMachine::QwtPickerClickPointMachine():
//! Transition //! Transition
QList<QwtPickerMachine::Command> QwtPickerClickPointMachine::transition( QList<QwtPickerMachine::Command> QwtPickerClickPointMachine::transition(
const QwtEventPattern &eventPattern, const QEvent *e ) const QwtEventPattern &eventPattern, const QEvent *event )
{ {
QList<QwtPickerMachine::Command> cmdList; QList<QwtPickerMachine::Command> cmdList;
switch ( e->type() ) switch ( event->type() )
{ {
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
{ {
if ( eventPattern.mouseMatch( if ( eventPattern.mouseMatch(
QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) ) QwtEventPattern::MouseSelect1, ( const QMouseEvent * )event ) )
{ {
cmdList += Begin; cmdList += Begin;
cmdList += Append; cmdList += Append;
@ -117,7 +117,7 @@ QList<QwtPickerMachine::Command> QwtPickerClickPointMachine::transition(
case QEvent::KeyPress: case QEvent::KeyPress:
{ {
if ( eventPattern.keyMatch( if ( eventPattern.keyMatch(
QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) QwtEventPattern::KeySelect1, ( const QKeyEvent * )event ) )
{ {
cmdList += Begin; cmdList += Begin;
cmdList += Append; cmdList += Append;
@ -140,16 +140,16 @@ QwtPickerDragPointMachine::QwtPickerDragPointMachine():
//! Transition //! Transition
QList<QwtPickerMachine::Command> QwtPickerDragPointMachine::transition( QList<QwtPickerMachine::Command> QwtPickerDragPointMachine::transition(
const QwtEventPattern &eventPattern, const QEvent *e ) const QwtEventPattern &eventPattern, const QEvent *event )
{ {
QList<QwtPickerMachine::Command> cmdList; QList<QwtPickerMachine::Command> cmdList;
switch ( e->type() ) switch ( event->type() )
{ {
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
{ {
if ( eventPattern.mouseMatch( if ( eventPattern.mouseMatch(
QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) ) QwtEventPattern::MouseSelect1, ( const QMouseEvent * )event ) )
{ {
if ( state() == 0 ) if ( state() == 0 )
{ {
@ -179,7 +179,7 @@ QList<QwtPickerMachine::Command> QwtPickerDragPointMachine::transition(
case QEvent::KeyPress: case QEvent::KeyPress:
{ {
if ( eventPattern.keyMatch( if ( eventPattern.keyMatch(
QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) QwtEventPattern::KeySelect1, ( const QKeyEvent * )event ) )
{ {
if ( state() == 0 ) if ( state() == 0 )
{ {
@ -210,16 +210,16 @@ QwtPickerClickRectMachine::QwtPickerClickRectMachine():
//! Transition //! Transition
QList<QwtPickerMachine::Command> QwtPickerClickRectMachine::transition( QList<QwtPickerMachine::Command> QwtPickerClickRectMachine::transition(
const QwtEventPattern &eventPattern, const QEvent *e ) const QwtEventPattern &eventPattern, const QEvent *event )
{ {
QList<QwtPickerMachine::Command> cmdList; QList<QwtPickerMachine::Command> cmdList;
switch ( e->type() ) switch ( event->type() )
{ {
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
{ {
if ( eventPattern.mouseMatch( if ( eventPattern.mouseMatch(
QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) ) QwtEventPattern::MouseSelect1, ( const QMouseEvent * )event ) )
{ {
switch ( state() ) switch ( state() )
{ {
@ -253,7 +253,7 @@ QList<QwtPickerMachine::Command> QwtPickerClickRectMachine::transition(
case QEvent::MouseButtonRelease: case QEvent::MouseButtonRelease:
{ {
if ( eventPattern.mouseMatch( if ( eventPattern.mouseMatch(
QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) ) QwtEventPattern::MouseSelect1, ( const QMouseEvent * )event ) )
{ {
if ( state() == 1 ) if ( state() == 1 )
{ {
@ -266,7 +266,7 @@ QList<QwtPickerMachine::Command> QwtPickerClickRectMachine::transition(
case QEvent::KeyPress: case QEvent::KeyPress:
{ {
if ( eventPattern.keyMatch( if ( eventPattern.keyMatch(
QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) QwtEventPattern::KeySelect1, ( const QKeyEvent * )event ) )
{ {
if ( state() == 0 ) if ( state() == 0 )
{ {
@ -305,16 +305,16 @@ QwtPickerDragRectMachine::QwtPickerDragRectMachine():
//! Transition //! Transition
QList<QwtPickerMachine::Command> QwtPickerDragRectMachine::transition( QList<QwtPickerMachine::Command> QwtPickerDragRectMachine::transition(
const QwtEventPattern &eventPattern, const QEvent *e ) const QwtEventPattern &eventPattern, const QEvent *event )
{ {
QList<QwtPickerMachine::Command> cmdList; QList<QwtPickerMachine::Command> cmdList;
switch ( e->type() ) switch ( event->type() )
{ {
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
{ {
if ( eventPattern.mouseMatch( if ( eventPattern.mouseMatch(
QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) ) QwtEventPattern::MouseSelect1, ( const QMouseEvent * )event ) )
{ {
if ( state() == 0 ) if ( state() == 0 )
{ {
@ -345,7 +345,7 @@ QList<QwtPickerMachine::Command> QwtPickerDragRectMachine::transition(
case QEvent::KeyPress: case QEvent::KeyPress:
{ {
if ( eventPattern.keyMatch( if ( eventPattern.keyMatch(
QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) QwtEventPattern::KeySelect1, ( const QKeyEvent * )event ) )
{ {
if ( state() == 0 ) if ( state() == 0 )
{ {
@ -377,16 +377,16 @@ QwtPickerPolygonMachine::QwtPickerPolygonMachine():
//! Transition //! Transition
QList<QwtPickerMachine::Command> QwtPickerPolygonMachine::transition( QList<QwtPickerMachine::Command> QwtPickerPolygonMachine::transition(
const QwtEventPattern &eventPattern, const QEvent *e ) const QwtEventPattern &eventPattern, const QEvent *event )
{ {
QList<QwtPickerMachine::Command> cmdList; QList<QwtPickerMachine::Command> cmdList;
switch ( e->type() ) switch ( event->type() )
{ {
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
{ {
if ( eventPattern.mouseMatch( if ( eventPattern.mouseMatch(
QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) ) QwtEventPattern::MouseSelect1, ( const QMouseEvent * )event ) )
{ {
if ( state() == 0 ) if ( state() == 0 )
{ {
@ -397,15 +397,17 @@ QList<QwtPickerMachine::Command> QwtPickerPolygonMachine::transition(
} }
else else
{ {
cmdList += End; cmdList += Append;
setState( 0 );
} }
} }
if ( eventPattern.mouseMatch( if ( eventPattern.mouseMatch(
QwtEventPattern::MouseSelect2, ( const QMouseEvent * )e ) ) QwtEventPattern::MouseSelect2, ( const QMouseEvent * )event ) )
{ {
if ( state() == 1 ) if ( state() == 1 )
cmdList += Append; {
cmdList += End;
setState( 0 );
}
} }
break; break;
} }
@ -419,7 +421,7 @@ QList<QwtPickerMachine::Command> QwtPickerPolygonMachine::transition(
case QEvent::KeyPress: case QEvent::KeyPress:
{ {
if ( eventPattern.keyMatch( if ( eventPattern.keyMatch(
QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) QwtEventPattern::KeySelect1, ( const QKeyEvent * )event ) )
{ {
if ( state() == 0 ) if ( state() == 0 )
{ {
@ -430,15 +432,17 @@ QList<QwtPickerMachine::Command> QwtPickerPolygonMachine::transition(
} }
else else
{ {
cmdList += End; cmdList += Append;
setState( 0 );
} }
} }
else if ( eventPattern.keyMatch( else if ( eventPattern.keyMatch(
QwtEventPattern::KeySelect2, ( const QKeyEvent * )e ) ) QwtEventPattern::KeySelect2, ( const QKeyEvent * )event ) )
{ {
if ( state() == 1 ) if ( state() == 1 )
cmdList += Append; {
cmdList += End;
setState( 0 );
}
} }
break; break;
} }

View File

@ -25,7 +25,7 @@
class QwtPlot::PrivateData class QwtPlot::PrivateData
{ {
public: public:
QPointer<QwtTextLabel> lblTitle; QPointer<QwtTextLabel> titleLabel;
QPointer<QwtPlotCanvas> canvas; QPointer<QwtPlotCanvas> canvas;
QPointer<QwtLegend> legend; QPointer<QwtLegend> legend;
QwtPlotLayout *layout; QwtPlotLayout *layout;
@ -75,19 +75,22 @@ void QwtPlot::initPlot( const QwtText &title )
d_data->layout = new QwtPlotLayout; d_data->layout = new QwtPlotLayout;
d_data->autoReplot = false; d_data->autoReplot = false;
d_data->lblTitle = new QwtTextLabel( title, this ); // title
d_data->lblTitle->setObjectName( "QwtPlotTitle" ); d_data->titleLabel = new QwtTextLabel( this );
d_data->titleLabel->setObjectName( "QwtPlotTitle" );
d_data->lblTitle->setFont( QFont( fontInfo().family(), 14, QFont::Bold ) ); d_data->titleLabel->setFont( QFont( fontInfo().family(), 14, QFont::Bold ) );
QwtText text( title ); QwtText text( title );
text.setRenderFlags( Qt::AlignCenter | Qt::TextWordWrap ); text.setRenderFlags( Qt::AlignCenter | Qt::TextWordWrap );
d_data->lblTitle->setText( text ); d_data->titleLabel->setText( text );
// legend
d_data->legend = NULL; d_data->legend = NULL;
// axis
initAxesData(); initAxesData();
// canvas
d_data->canvas = new QwtPlotCanvas( this ); d_data->canvas = new QwtPlotCanvas( this );
d_data->canvas->setObjectName( "QwtPlotCanvas" ); d_data->canvas->setObjectName( "QwtPlotCanvas" );
d_data->canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken ); d_data->canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken );
@ -163,9 +166,9 @@ bool QwtPlot::autoReplot() const
*/ */
void QwtPlot::setTitle( const QString &title ) void QwtPlot::setTitle( const QString &title )
{ {
if ( title != d_data->lblTitle->text().text() ) if ( title != d_data->titleLabel->text().text() )
{ {
d_data->lblTitle->setText( title ); d_data->titleLabel->setText( title );
updateLayout(); updateLayout();
} }
} }
@ -176,17 +179,17 @@ void QwtPlot::setTitle( const QString &title )
*/ */
void QwtPlot::setTitle( const QwtText &title ) void QwtPlot::setTitle( const QwtText &title )
{ {
if ( title != d_data->lblTitle->text() ) if ( title != d_data->titleLabel->text() )
{ {
d_data->lblTitle->setText( title ); d_data->titleLabel->setText( title );
updateLayout(); updateLayout();
} }
} }
//! \return the plot's title //! \return Title of the plot
QwtText QwtPlot::title() const QwtText QwtPlot::title() const
{ {
return d_data->lblTitle->text(); return d_data->titleLabel->text();
} }
//! \return the plot's title //! \return the plot's title
@ -195,7 +198,7 @@ QwtPlotLayout *QwtPlot::plotLayout()
return d_data->layout; return d_data->layout;
} }
//! \return the plot's titel label. //! \return the plot's layout
const QwtPlotLayout *QwtPlot::plotLayout() const const QwtPlotLayout *QwtPlot::plotLayout() const
{ {
return d_data->layout; return d_data->layout;
@ -204,7 +207,7 @@ const QwtPlotLayout *QwtPlot::plotLayout() const
//! \return the plot's titel label. //! \return the plot's titel label.
QwtTextLabel *QwtPlot::titleLabel() QwtTextLabel *QwtPlot::titleLabel()
{ {
return d_data->lblTitle; return d_data->titleLabel;
} }
/*! /*!
@ -212,7 +215,7 @@ QwtTextLabel *QwtPlot::titleLabel()
*/ */
const QwtTextLabel *QwtPlot::titleLabel() const const QwtTextLabel *QwtPlot::titleLabel() const
{ {
return d_data->lblTitle; return d_data->titleLabel;
} }
/*! /*!
@ -352,17 +355,15 @@ void QwtPlot::updateLayout()
QRect legendRect = d_data->layout->legendRect().toRect(); QRect legendRect = d_data->layout->legendRect().toRect();
QRect canvasRect = d_data->layout->canvasRect().toRect(); QRect canvasRect = d_data->layout->canvasRect().toRect();
//
// resize and show the visible widgets // resize and show the visible widgets
// if ( !d_data->titleLabel->text().isEmpty() )
if ( !d_data->lblTitle->text().isEmpty() )
{ {
d_data->lblTitle->setGeometry( titleRect ); d_data->titleLabel->setGeometry( titleRect );
if ( !d_data->lblTitle->isVisibleTo( this ) ) if ( !d_data->titleLabel->isVisibleTo( this ) )
d_data->lblTitle->show(); d_data->titleLabel->show();
} }
else else
d_data->lblTitle->hide(); d_data->titleLabel->hide();
for ( int axisId = 0; axisId < axisCnt; axisId++ ) for ( int axisId = 0; axisId < axisCnt; axisId++ )
{ {
@ -370,18 +371,22 @@ void QwtPlot::updateLayout()
{ {
axisWidget( axisId )->setGeometry( scaleRect[axisId] ); axisWidget( axisId )->setGeometry( scaleRect[axisId] );
#if 1
if ( axisId == xBottom || axisId == xTop ) if ( axisId == xBottom || axisId == xTop )
{ {
// do we need this code any longer ???
QRegion r( scaleRect[axisId] ); QRegion r( scaleRect[axisId] );
if ( axisEnabled( yLeft ) ) if ( axisEnabled( yLeft ) )
r = r.subtract( QRegion( scaleRect[yLeft] ) ); r = r.subtracted( QRegion( scaleRect[yLeft] ) );
if ( axisEnabled( yRight ) ) if ( axisEnabled( yRight ) )
r = r.subtract( QRegion( scaleRect[yRight] ) ); r = r.subtracted( QRegion( scaleRect[yRight] ) );
r.translate( -d_data->layout->scaleRect( axisId ).x(), r.translate( -scaleRect[ axisId ].x(),
-scaleRect[axisId].y() ); -scaleRect[axisId].y() );
axisWidget( axisId )->setMask( r ); axisWidget( axisId )->setMask( r );
} }
#endif
if ( !axisWidget( axisId )->isVisibleTo( this ) ) if ( !axisWidget( axisId )->isVisibleTo( this ) )
axisWidget( axisId )->show(); axisWidget( axisId )->show();
} }
@ -584,9 +589,7 @@ QwtScaleMap QwtPlot::canvasMap( int axisId ) const
void QwtPlot::setCanvasBackground( const QBrush &brush ) void QwtPlot::setCanvasBackground( const QBrush &brush )
{ {
QPalette pal = d_data->canvas->palette(); QPalette pal = d_data->canvas->palette();
pal.setBrush( QPalette::Window, brush );
for ( int i = 0; i < QPalette::NColorGroups; i++ )
pal.setBrush( ( QPalette::ColorGroup )i, QPalette::Window, brush );
canvas()->setPalette( pal ); canvas()->setPalette( pal );
} }

View File

@ -55,7 +55,7 @@ QwtPlot *myPlot = new QwtPlot("Two Curves", parent);
QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1"); QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2"); QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");
// copy the data into the curves // connect or copy the data to the curves
curve1->setData(...); curve1->setData(...);
curve2->setData(...); curve2->setData(...);

View File

@ -619,8 +619,12 @@ void QwtPlot::updateAxes()
if ( axisAutoScale( item->xAxis() ) || axisAutoScale( item->yAxis() ) ) if ( axisAutoScale( item->xAxis() ) || axisAutoScale( item->yAxis() ) )
{ {
const QRectF rect = item->boundingRect(); const QRectF rect = item->boundingRect();
intv[item->xAxis()] |= QwtInterval( rect.left(), rect.right() );
intv[item->yAxis()] |= QwtInterval( rect.top(), rect.bottom() ); if ( rect.width() >= 0.0 )
intv[item->xAxis()] |= QwtInterval( rect.left(), rect.right() );
if ( rect.height() >= 0.0 )
intv[item->yAxis()] |= QwtInterval( rect.top(), rect.bottom() );
} }
} }

View File

@ -158,15 +158,80 @@ private:
QPointF d_origin; QPointF d_origin;
}; };
static void qwtDrawBackground( QPainter *painter, QWidget *widget ) static inline void qwtFillRect( const QWidget *widget, QPainter *painter,
const QRect &rect, const QBrush &brush)
{ {
const QBrush &brush = if ( brush.style() == Qt::TexturePattern )
{
painter->save();
painter->setClipRect( rect );
painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
painter->restore();
}
else if ( brush.gradient() )
{
painter->save();
painter->setClipRect( rect );
painter->fillRect(0, 0, widget->width(),
widget->height(), brush);
painter->restore();
}
else
{
painter->fillRect(rect, brush);
}
}
static void qwtFillPixmap( const QWidget *widget,
QPixmap &pixmap, const QPoint &offset = QPoint() )
{
const QRect rect( offset, pixmap.size() );
QPainter painter( &pixmap );
painter.translate( -offset );
const QBrush autoFillBrush =
widget->palette().brush( widget->backgroundRole() ); widget->palette().brush( widget->backgroundRole() );
if ( !( widget->autoFillBackground() && autoFillBrush.isOpaque() ) )
{
const QBrush bg = widget->palette().brush( QPalette::Window );
qwtFillRect( widget, &painter, rect, bg);
}
if ( widget->autoFillBackground() )
qwtFillRect( widget, &painter, rect, autoFillBrush);
if ( widget->testAttribute(Qt::WA_StyledBackground) )
{
painter.setClipRegion( rect );
QStyleOption opt;
opt.initFrom( widget );
widget->style()->drawPrimitive( QStyle::PE_Widget,
&opt, &painter, widget );
}
}
static void qwtDrawBackground( QPainter *painter, QwtPlotCanvas *canvas )
{
painter->save();
const QPainterPath borderClip = canvas->borderPath( canvas->rect() );
if ( !borderClip.isEmpty() )
painter->setClipPath( borderClip, Qt::IntersectClip );
const QBrush &brush =
canvas->palette().brush( canvas->backgroundRole() );
if ( brush.style() == Qt::TexturePattern ) if ( brush.style() == Qt::TexturePattern )
{ {
QPixmap pm( widget->size() ); QPixmap pm( canvas->size() );
pm.fill( widget, 0, 0 ); qwtFillPixmap( canvas, pm );
painter->drawPixmap( 0, 0, pm ); painter->drawPixmap( 0, 0, pm );
} }
else if ( brush.gradient() ) else if ( brush.gradient() )
@ -175,7 +240,7 @@ static void qwtDrawBackground( QPainter *painter, QWidget *widget )
if ( brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode ) if ( brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode )
{ {
rects += widget->rect(); rects += canvas->rect();
} }
else else
{ {
@ -214,7 +279,7 @@ static void qwtDrawBackground( QPainter *painter, QWidget *widget )
} }
} }
QImage image( widget->size(), format ); QImage image( canvas->size(), format );
QPainter p( &image ); QPainter p( &image );
p.setPen( Qt::NoPen ); p.setPen( Qt::NoPen );
@ -228,40 +293,33 @@ static void qwtDrawBackground( QPainter *painter, QWidget *widget )
} }
else else
{ {
painter->save();
painter->setPen( Qt::NoPen ); painter->setPen( Qt::NoPen );
painter->setBrush( brush ); painter->setBrush( brush );
painter->drawRects( rects ); painter->drawRects( rects );
painter->restore();
} }
} }
else else
{ {
painter->save();
painter->setPen( Qt::NoPen ); painter->setPen( Qt::NoPen );
painter->setBrush( brush ); painter->setBrush( brush );
painter->drawRects( painter->clipRegion().rects() ); painter->drawRects( painter->clipRegion().rects() );
painter->restore();
} }
painter->restore();
} }
static inline void qwtRevertPath( QPainterPath &path ) static inline void qwtRevertPath( QPainterPath &path )
{ {
if ( path.elementCount() == 4 ) if ( path.elementCount() == 4 )
{ {
QPainterPath::Element &el0 = QPainterPath::Element el0 = path.elementAt(0);
const_cast<QPainterPath::Element &>( path.elementAt(0) ); QPainterPath::Element el3 = path.elementAt(3);
QPainterPath::Element &el2 =
const_cast<QPainterPath::Element &>( path.elementAt(3) );
qSwap( el0.x, el2.x ); path.setElementPositionAt( 0, el3.x, el3.y );
qSwap( el0.y, el2.y ); path.setElementPositionAt( 3, el0.x, el0.y );
} }
} }
@ -438,7 +496,8 @@ static void qwtFillBackground( QPainter *painter,
if ( clipRegion.intersects( rect ) ) if ( clipRegion.intersects( rect ) )
{ {
QPixmap pm( rect.size() ); QPixmap pm( rect.size() );
pm.fill( bgWidget, widget->mapTo( bgWidget, rect.topLeft() ) ); qwtFillPixmap( bgWidget, pm,
widget->mapTo( bgWidget, rect.topLeft() ) );
painter->drawPixmap( rect, pm ); painter->drawPixmap( rect, pm );
} }
} }
@ -467,7 +526,7 @@ static void qwtFillBackground( QPainter *painter, QwtPlotCanvas *canvas )
const double radius = canvas->borderRadius(); const double radius = canvas->borderRadius();
if ( radius > 0.0 ) if ( radius > 0.0 )
{ {
QSize sz( radius, radius ); QSizeF sz( radius, radius );
rects += QRectF( r.topLeft(), sz ); rects += QRectF( r.topLeft(), sz );
rects += QRectF( r.topRight() - QPointF( radius, 0 ), sz ); rects += QRectF( r.topRight() - QPointF( radius, 0 ), sz );
@ -518,8 +577,10 @@ public:
}; };
//! Sets a cross cursor, enables QwtPlotCanvas::BackingStore /*!
\brief Constructor
\param plot Parent plot widget
*/
QwtPlotCanvas::QwtPlotCanvas( QwtPlot *plot ): QwtPlotCanvas::QwtPlotCanvas( QwtPlot *plot ):
QFrame( plot ) QFrame( plot )
{ {
@ -544,13 +605,13 @@ QwtPlotCanvas::~QwtPlotCanvas()
//! Return parent plot widget //! Return parent plot widget
QwtPlot *QwtPlotCanvas::plot() QwtPlot *QwtPlotCanvas::plot()
{ {
return qobject_cast<QwtPlot *>( parentWidget() ); return qobject_cast<QwtPlot *>( parent() );
} }
//! Return parent plot widget //! Return parent plot widget
const QwtPlot *QwtPlotCanvas::plot() const const QwtPlot *QwtPlotCanvas::plot() const
{ {
return qobject_cast<const QwtPlot *>( parentWidget() ); return qobject_cast<const QwtPlot *>( parent() );
} }
/*! /*!
@ -733,7 +794,7 @@ void QwtPlotCanvas::paintEvent( QPaintEvent *event )
QPainter p; QPainter p;
if ( d_data->borderRadius <= 0.0 ) if ( d_data->borderRadius <= 0.0 )
{ {
bs.fill( this, 0, 0 ); qwtFillPixmap( this, bs );
p.begin( &bs ); p.begin( &bs );
drawCanvas( &p, false ); drawCanvas( &p, false );
} }
@ -770,7 +831,27 @@ void QwtPlotCanvas::paintEvent( QPaintEvent *event )
if ( testAttribute( Qt::WA_OpaquePaintEvent ) ) if ( testAttribute( Qt::WA_OpaquePaintEvent ) )
{ {
if ( autoFillBackground() ) if ( autoFillBackground() )
{
qwtFillBackground( &painter, this );
qwtDrawBackground( &painter, this ); qwtDrawBackground( &painter, this );
}
}
else
{
if ( borderRadius() > 0.0 )
{
QPainterPath clipPath;
clipPath.addRect( rect() );
clipPath = clipPath.subtracted( borderPath( rect() ) );
painter.save();
painter.setClipPath( clipPath, Qt::IntersectClip );
qwtFillBackground( &painter, this );
qwtDrawBackground( &painter, this );
painter.restore();
}
} }
drawCanvas( &painter, false ); drawCanvas( &painter, false );
@ -837,7 +918,7 @@ void QwtPlotCanvas::drawCanvas( QPainter *painter, bool withBackground )
painter->setPen( Qt::NoPen ); painter->setPen( Qt::NoPen );
painter->setBrush( palette().brush( backgroundRole() ) ); painter->setBrush( palette().brush( backgroundRole() ) );
if ( d_data->borderRadius > 0.0 ) if ( d_data->borderRadius > 0.0 && ( rect() == frameRect() ) )
{ {
if ( frameWidth() > 0 ) if ( frameWidth() > 0 )
{ {
@ -852,7 +933,7 @@ void QwtPlotCanvas::drawCanvas( QPainter *painter, bool withBackground )
} }
else else
{ {
painter->drawRect( contentsRect() ); painter->drawRect( rect() );
} }
} }
@ -869,7 +950,7 @@ void QwtPlotCanvas::drawCanvas( QPainter *painter, bool withBackground )
else else
{ {
if ( d_data->borderRadius > 0.0 ) if ( d_data->borderRadius > 0.0 )
painter->setClipPath( borderPath( rect() ), Qt::IntersectClip ); painter->setClipPath( borderPath( frameRect() ), Qt::IntersectClip );
else else
painter->setClipRect( contentsRect(), Qt::IntersectClip ); painter->setClipRect( contentsRect(), Qt::IntersectClip );
} }

View File

@ -21,6 +21,9 @@ class QPixmap;
/*! /*!
\brief Canvas of a QwtPlot. \brief Canvas of a QwtPlot.
Canvas is the widget where all plot items are displayed
\sa QwtPlot \sa QwtPlot
*/ */
class QWT_EXPORT QwtPlotCanvas : public QFrame class QWT_EXPORT QwtPlotCanvas : public QFrame
@ -99,26 +102,26 @@ public:
/*! /*!
\brief Focus indicator \brief Focus indicator
The default setting is NoFocusIndicator
- NoFocusIndicator\n
Don't paint a focus indicator
- CanvasFocusIndicator\n
The focus is related to the complete canvas.
Paint the focus indicator using paintFocus()
- ItemFocusIndicator\n
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.
\sa setFocusIndicator(), focusIndicator(), paintFocus() \sa setFocusIndicator(), focusIndicator(), paintFocus()
*/ */
enum FocusIndicator enum FocusIndicator
{ {
//! Don't paint a focus indicator
NoFocusIndicator, NoFocusIndicator,
/*!
The focus is related to the complete canvas.
Paint the focus indicator using paintFocus()
*/
CanvasFocusIndicator, CanvasFocusIndicator,
/*!
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.
*/
ItemFocusIndicator ItemFocusIndicator
}; };

View File

@ -192,6 +192,10 @@ QwtPlotCurve::CurveStyle QwtPlotCurve::style() const
/*! /*!
Assign a symbol Assign a symbol
The curve will take the ownership of the symbol, hence the previously
set symbol will be delete by setting a new one. If \p symbol is
\c NULL no symbol will be drawn.
\param symbol Symbol \param symbol Symbol
\sa symbol() \sa symbol()
*/ */
@ -792,33 +796,29 @@ void QwtPlotCurve::drawSymbols( QPainter *painter, const QwtSymbol &symbol,
if ( usePixmap ) if ( usePixmap )
{ {
QPixmap pm( symbol.boundingSize() ); const QSize sz = ( 2 * symbol.boundingSize() + QSize( 1, 1 ) ) / 2;
pm.fill( Qt::transparent ); const int w2 = sz.width() / 2;
const int h2 = sz.height() / 2;
const double pw2 = 0.5 * pm.width(); QPixmap pm( sz );
const double ph2 = 0.5 * pm.height(); pm.fill( Qt::transparent );
QPainter p( &pm ); QPainter p( &pm );
p.setRenderHints( painter->renderHints() ); p.setRenderHints( painter->renderHints() );
symbol.drawSymbol( &p, QPointF( pw2, ph2 ) ); symbol.drawSymbol( &p, QPointF( w2, h2 ) );
p.end(); p.end();
for ( int i = from; i <= to; i++ ) for ( int i = from; i <= to; i++ )
{ {
const QPointF sample = d_series->sample( i ); const QPointF sample = d_series->sample( i );
double xi = xMap.transform( sample.x() ); const double xi = xMap.transform( sample.x() );
double yi = yMap.transform( sample.y() ); const double yi = yMap.transform( sample.y() );
if ( doAlign )
{
xi = qRound( xi );
yi = qRound( yi );
}
if ( canvasRect.contains( xi, yi ) ) if ( canvasRect.contains( xi, yi ) )
{ {
const int left = qCeil( xi ) - pw2; const int left = qRound( xi ) - w2;
const int top = qCeil( yi ) - ph2; const int top = qRound( yi ) - h2;
painter->drawPixmap( left, top, pm ); painter->drawPixmap( left, top, pm );
} }
@ -855,15 +855,16 @@ void QwtPlotCurve::drawSymbols( QPainter *painter, const QwtSymbol &symbol,
The baseline is needed for filling the curve with a brush or The baseline is needed for filling the curve with a brush or
the Sticks drawing style. the Sticks drawing style.
The interpretation of the baseline depends on the CurveType.
With QwtPlotCurve::Yfx, the baseline is interpreted as a horizontal line The interpretation of the baseline depends on the orientation().
at y = baseline(), with QwtPlotCurve::Yfy, it is interpreted as a vertical With Qt::Horizontal, the baseline is interpreted as a horizontal line
at y = baseline(), with Qt::Vertical, it is interpreted as a vertical
line at x = baseline(). line at x = baseline().
The default value is 0.0. The default value is 0.0.
\param value Value of the baseline \param value Value of the baseline
\sa baseline(), setBrush(), setStyle(), setStyle() \sa baseline(), setBrush(), setStyle(), QwtPlotAbstractSeriesItem::orientation()
*/ */
void QwtPlotCurve::setBaseline( double value ) void QwtPlotCurve::setBaseline( double value )
{ {
@ -984,9 +985,9 @@ void QwtPlotCurve::drawLegendIdentifier(
if ( rect.isEmpty() ) if ( rect.isEmpty() )
return; return;
const int dim = qMin( rect.width(), rect.height() ); const double dim = qMin( rect.width(), rect.height() );
QSize size( dim, dim ); QSizeF size( dim, dim );
QRectF r( 0, 0, size.width(), size.height() ); QRectF r( 0, 0, size.width(), size.height() );
r.moveCenter( rect.center() ); r.moveCenter( rect.center() );

View File

@ -252,27 +252,27 @@ protected:
void init(); void init();
virtual void drawCurve( QPainter *p, int style, virtual void drawCurve( QPainter *, int style,
const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect, int from, int to ) const; const QRectF &canvasRect, int from, int to ) const;
virtual void drawSymbols( QPainter *p, const QwtSymbol &, virtual void drawSymbols( QPainter *, const QwtSymbol &,
const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect, int from, int to ) const; const QRectF &canvasRect, int from, int to ) const;
void drawLines( QPainter *p, void drawLines( QPainter *,
const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect, int from, int to ) const; const QRectF &canvasRect, int from, int to ) const;
void drawSticks( QPainter *p, void drawSticks( QPainter *,
const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect, int from, int to ) const; const QRectF &canvasRect, int from, int to ) const;
void drawDots( QPainter *p, void drawDots( QPainter *,
const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect, int from, int to ) const; const QRectF &canvasRect, int from, int to ) const;
void drawSteps( QPainter *p, void drawSteps( QPainter *,
const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect, int from, int to ) const; const QRectF &canvasRect, int from, int to ) const;

View File

@ -26,6 +26,8 @@ typedef QList<QwtPlotItem *>::ConstIterator QwtPlotItemIterator;
QwtPlotDict organizes plot items in increasing z-order. QwtPlotDict organizes plot items in increasing z-order.
If autoDelete() is enabled, all attached items will be deleted If autoDelete() is enabled, all attached items will be deleted
in the destructor of the dictionary. in the destructor of the dictionary.
QwtPlotDict can be used to get access to all QwtPlotItem items - or all
items of a specific type - that are currently on the plot.
\sa QwtPlotItem::attach(), QwtPlotItem::detach(), QwtPlotItem::z() \sa QwtPlotItem::attach(), QwtPlotItem::detach(), QwtPlotItem::z()
*/ */

View File

@ -179,7 +179,6 @@ void QwtPlotDirectPainter::drawSeries(
if ( hasBackingStore ) if ( hasBackingStore )
{ {
QPainter painter( const_cast<QPixmap *>( canvas->backingStore() ) ); QPainter painter( const_cast<QPixmap *>( canvas->backingStore() ) );
painter.translate( -canvasRect.x(), -canvasRect.y() );
if ( d_data->hasClipping ) if ( d_data->hasClipping )
painter.setClipRegion( d_data->clipRegion ); painter.setClipRegion( d_data->clipRegion );
@ -194,15 +193,13 @@ void QwtPlotDirectPainter::drawSeries(
} }
bool immediatePaint = true; bool immediatePaint = true;
if ( !canvas->testAttribute( Qt::WA_WState_InPaintEvent ) && if ( !canvas->testAttribute( Qt::WA_WState_InPaintEvent ) )
!canvas->testAttribute( Qt::WA_PaintOutsidePaintEvent ) )
{ {
immediatePaint = false; immediatePaint = false;
} }
if ( immediatePaint ) if ( immediatePaint )
{ {
QwtPlotCanvas *canvas = seriesItem->plot()->canvas();
if ( !d_data->painter.isActive() ) if ( !d_data->painter.isActive() )
{ {
reset(); reset();

View File

@ -23,7 +23,7 @@ static inline bool qwtIsHSampleInside( const QwtIntervalSample &sample,
const double x2 = sample.interval.maxValue(); const double x2 = sample.interval.maxValue();
const bool isOffScreen = ( y < yMin ) || ( y > yMax ) const bool isOffScreen = ( y < yMin ) || ( y > yMax )
|| ( x1 < xMin && x2 < xMin ) || ( x1 > yMax && x2 > xMax ); || ( x1 < xMin && x2 < xMin ) || ( x1 > xMax && x2 > xMax );
return !isOffScreen; return !isOffScreen;
} }
@ -45,14 +45,14 @@ class QwtPlotIntervalCurve::PrivateData
{ {
public: public:
PrivateData(): PrivateData():
style( Tube ), style( QwtPlotIntervalCurve::Tube ),
symbol( NULL ), symbol( NULL ),
pen( Qt::black ), pen( Qt::black ),
brush( Qt::white ) brush( Qt::white )
{ {
paintAttributes = QwtPlotIntervalCurve::ClipPolygons; paintAttributes = QwtPlotIntervalCurve::ClipPolygons;
paintAttributes |= QwtPlotIntervalCurve::ClipSymbol; paintAttributes |= QwtPlotIntervalCurve::ClipSymbol;
pen.setCapStyle( Qt::FlatCap ); pen.setCapStyle( Qt::FlatCap );
} }
@ -61,7 +61,7 @@ public:
delete symbol; delete symbol;
} }
CurveStyle style; QwtPlotIntervalCurve::CurveStyle style;
const QwtIntervalSymbol *symbol; const QwtIntervalSymbol *symbol;
QPen pen; QPen pen;
@ -121,7 +121,7 @@ int QwtPlotIntervalCurve::rtti() const
\param on On/Off \param on On/Off
\sa testPaintAttribute() \sa testPaintAttribute()
*/ */
void QwtPlotIntervalCurve::setPaintAttribute( void QwtPlotIntervalCurve::setPaintAttribute(
PaintAttribute attribute, bool on ) PaintAttribute attribute, bool on )
{ {
if ( on ) if ( on )
@ -134,7 +134,7 @@ void QwtPlotIntervalCurve::setPaintAttribute(
\brief Return the current paint attributes \brief Return the current paint attributes
\sa PaintAttribute, setPaintAttribute() \sa PaintAttribute, setPaintAttribute()
*/ */
bool QwtPlotIntervalCurve::testPaintAttribute( bool QwtPlotIntervalCurve::testPaintAttribute(
PaintAttribute attribute ) const PaintAttribute attribute ) const
{ {
return ( d_data->paintAttributes & attribute ); return ( d_data->paintAttributes & attribute );
@ -303,7 +303,7 @@ void QwtPlotIntervalCurve::drawSeries( QPainter *painter,
if ( d_data->symbol && if ( d_data->symbol &&
( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) ) ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) )
{ {
drawSymbols( painter, *d_data->symbol, drawSymbols( painter, *d_data->symbol,
xMap, yMap, canvasRect, from, to ); xMap, yMap, canvasRect, from, to );
} }
} }
@ -387,8 +387,8 @@ void QwtPlotIntervalCurve::drawTube( QPainter *painter,
if ( d_data->paintAttributes & ClipPolygons ) if ( d_data->paintAttributes & ClipPolygons )
{ {
const qreal m = 1.0; const qreal m = 1.0;
const QPolygonF p = QwtClipper::clipPolygonF( const QPolygonF p = QwtClipper::clipPolygonF(
canvasRect.adjusted(-m, -m, m, m), polygon, true ); canvasRect.adjusted( -m, -m, m, m ), polygon, true );
QwtPainter::drawPolygon( painter, p ); QwtPainter::drawPolygon( painter, p );
} }
@ -405,19 +405,19 @@ void QwtPlotIntervalCurve::drawTube( QPainter *painter,
if ( d_data->paintAttributes & ClipPolygons ) if ( d_data->paintAttributes & ClipPolygons )
{ {
qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF()); qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF() );
const QRectF clipRect = canvasRect.adjusted(-pw, -pw, pw, pw); const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );
QPolygonF p; QPolygonF p;
p.resize( size ); p.resize( size );
qMemCopy( p.data(), points, size * sizeof( QPointF ) ); memcpy( p.data(), points, size * sizeof( QPointF ) );
p = QwtClipper::clipPolygonF( canvasRect, p ); p = QwtClipper::clipPolygonF( clipRect, p );
QwtPainter::drawPolyline( painter, p ); QwtPainter::drawPolyline( painter, p );
p.resize( size ); p.resize( size );
qMemCopy( p.data(), points + size, size * sizeof( QPointF ) ); memcpy( p.data(), points + size, size * sizeof( QPointF ) );
p = QwtClipper::clipPolygonF( canvasRect, p ); p = QwtClipper::clipPolygonF( clipRect, p );
QwtPainter::drawPolyline( painter, p ); QwtPainter::drawPolyline( painter, p );
} }
else else
@ -456,14 +456,14 @@ void QwtPlotIntervalCurve::drawSymbols(
painter->setPen( pen ); painter->setPen( pen );
painter->setBrush( symbol.brush() ); painter->setBrush( symbol.brush() );
const QRectF &tr = QwtScaleMap::invTransform( xMap, yMap, canvasRect); const QRectF tr = QwtScaleMap::invTransform( xMap, yMap, canvasRect );
const double xMin = tr.left(); const double xMin = tr.left();
const double xMax = tr.right(); const double xMax = tr.right();
const double yMin = tr.top(); const double yMin = tr.top();
const double yMax = tr.bottom(); const double yMax = tr.bottom();
const bool doClip = d_data->paintAttributes & ClipPolygons; const bool doClip = d_data->paintAttributes & ClipSymbol;
for ( int i = from; i <= to; i++ ) for ( int i = from; i <= to; i++ )
{ {
@ -499,13 +499,14 @@ void QwtPlotIntervalCurve::drawSymbols(
} }
/*! /*!
In case of Tibe stale() a plain rectangle is painted without a pen filled \brief Draw the identifier for the legend
the brush(). If a symbol is assigned it is painted cebtered into rect.
In case of Tube style() a plain rectangle filled with the brush() is painted.
If a symbol is assigned it is painted centered into rect.
\param painter Painter \param painter Painter
\param rect Bounding rectangle for the identifier \param rect Bounding rectangle for the identifier
*/ */
void QwtPlotIntervalCurve::drawLegendIdentifier( void QwtPlotIntervalCurve::drawLegendIdentifier(
QPainter *painter, const QRectF &rect ) const QPainter *painter, const QRectF &rect ) const
{ {

View File

@ -327,10 +327,10 @@ void QwtPlotItem::itemChanged()
The item will painted according to the coordinates its Axes. The item will painted according to the coordinates its Axes.
\param xAxis X Axis \param xAxis X Axis ( QwtPlot::xBottom or QwtPlot::xTop )
\param yAxis Y Axis \param yAxis Y Axis ( QwtPlot::yLeft or QwtPlot::yRight )
\sa setXAxis(), setYAxis(), xAxis(), yAxis() \sa setXAxis(), setYAxis(), xAxis(), yAxis(), QwtPlot::Axis
*/ */
void QwtPlotItem::setAxes( int xAxis, int yAxis ) void QwtPlotItem::setAxes( int xAxis, int yAxis )
{ {
@ -348,8 +348,8 @@ void QwtPlotItem::setAxes( int xAxis, int yAxis )
The item will painted according to the coordinates its Axes. The item will painted according to the coordinates its Axes.
\param axis X Axis \param axis X Axis ( QwtPlot::xBottom or QwtPlot::xTop )
\sa setAxes(), setYAxis(), xAxis() \sa setAxes(), setYAxis(), xAxis(), QwtPlot::Axis
*/ */
void QwtPlotItem::setXAxis( int axis ) void QwtPlotItem::setXAxis( int axis )
{ {
@ -365,8 +365,8 @@ void QwtPlotItem::setXAxis( int axis )
The item will painted according to the coordinates its Axes. The item will painted according to the coordinates its Axes.
\param axis Y Axis \param axis Y Axis ( QwtPlot::yLeft or QwtPlot::yRight )
\sa setAxes(), setXAxis(), yAxis() \sa setAxes(), setXAxis(), yAxis(), QwtPlot::Axis
*/ */
void QwtPlotItem::setYAxis( int axis ) void QwtPlotItem::setYAxis( int axis )
{ {
@ -391,6 +391,7 @@ int QwtPlotItem::yAxis() const
/*! /*!
\return An invalid bounding rect: QRectF(1.0, 1.0, -2.0, -2.0) \return An invalid bounding rect: QRectF(1.0, 1.0, -2.0, -2.0)
\note A width or height < 0.0 is ignored by the autoscaler
*/ */
QRectF QwtPlotItem::boundingRect() const QRectF QwtPlotItem::boundingRect() const
{ {
@ -513,9 +514,9 @@ void QwtPlotItem::updateScaleDiv( const QwtScaleDiv &xScaleDiv,
\brief Calculate the bounding scale rect of 2 maps \brief Calculate the bounding scale rect of 2 maps
\param xMap X map \param xMap X map
\param yMap X map \param yMap Y map
\return Bounding scale rect of the scale maps, normalized \return Bounding scale rect of the scale maps, not normalized
*/ */
QRectF QwtPlotItem::scaleRect( const QwtScaleMap &xMap, QRectF QwtPlotItem::scaleRect( const QwtScaleMap &xMap,
const QwtScaleMap &yMap ) const const QwtScaleMap &yMap ) const
@ -528,9 +529,9 @@ QRectF QwtPlotItem::scaleRect( const QwtScaleMap &xMap,
\brief Calculate the bounding paint rect of 2 maps \brief Calculate the bounding paint rect of 2 maps
\param xMap X map \param xMap X map
\param yMap X map \param yMap Y map
\return Bounding paint rect of the scale maps, normalized \return Bounding paint rect of the scale maps, not normalized
*/ */
QRectF QwtPlotItem::paintRect( const QwtScaleMap &xMap, QRectF QwtPlotItem::paintRect( const QwtScaleMap &xMap,
const QwtScaleMap &yMap ) const const QwtScaleMap &yMap ) const

View File

@ -72,18 +72,40 @@ public:
*/ */
enum RttiValues enum RttiValues
{ {
//! Unspecific value, that can be used, when it doesn't matter
Rtti_PlotItem = 0, Rtti_PlotItem = 0,
//! For QwtPlotGrid
Rtti_PlotGrid, Rtti_PlotGrid,
//! For QwtPlotScaleItem
Rtti_PlotScale, Rtti_PlotScale,
//! For QwtPlotMarker
Rtti_PlotMarker, Rtti_PlotMarker,
//! For QwtPlotCurve
Rtti_PlotCurve, Rtti_PlotCurve,
//! For QwtPlotSpectroCurve
Rtti_PlotSpectroCurve, Rtti_PlotSpectroCurve,
//! For QwtPlotIntervalCurve
Rtti_PlotIntervalCurve, Rtti_PlotIntervalCurve,
//! For QwtPlotHistogram
Rtti_PlotHistogram, Rtti_PlotHistogram,
//! For QwtPlotSpectrogram
Rtti_PlotSpectrogram, Rtti_PlotSpectrogram,
//! For QwtPlotSvgItem
Rtti_PlotSVG, Rtti_PlotSVG,
/*!
Values >= Rtti_PlotUserItem are reserved for plot items
not implemented in the Qwt library.
*/
Rtti_PlotUserItem = 1000 Rtti_PlotUserItem = 1000
}; };

View File

@ -43,7 +43,7 @@ public:
int start; int start;
int end; int end;
int baseLineOffset; int baseLineOffset;
int tickOffset; double tickOffset;
int dimWithoutTitle; int dimWithoutTitle;
} scale[QwtPlot::axisCnt]; } scale[QwtPlot::axisCnt];
@ -139,7 +139,7 @@ void QwtPlotLayout::LayoutData::init( const QwtPlot *plot, const QRectF &rect )
scale[axis].start = 0; scale[axis].start = 0;
scale[axis].end = 0; scale[axis].end = 0;
scale[axis].baseLineOffset = 0; scale[axis].baseLineOffset = 0;
scale[axis].tickOffset = 0; scale[axis].tickOffset = 0.0;
scale[axis].dimWithoutTitle = 0; scale[axis].dimWithoutTitle = 0;
} }
} }
@ -375,7 +375,6 @@ double QwtPlotLayout::legendRatio() const
\return Geometry for the title \return Geometry for the title
\sa activate(), invalidate() \sa activate(), invalidate()
*/ */
const QRectF &QwtPlotLayout::titleRect() const const QRectF &QwtPlotLayout::titleRect() const
{ {
return d_data->titleRect; return d_data->titleRect;
@ -385,7 +384,6 @@ const QRectF &QwtPlotLayout::titleRect() const
\return Geometry for the legend \return Geometry for the legend
\sa activate(), invalidate() \sa activate(), invalidate()
*/ */
const QRectF &QwtPlotLayout::legendRect() const const QRectF &QwtPlotLayout::legendRect() const
{ {
return d_data->legendRect; return d_data->legendRect;
@ -396,7 +394,6 @@ const QRectF &QwtPlotLayout::legendRect() const
\return Geometry for the scale \return Geometry for the scale
\sa activate(), invalidate() \sa activate(), invalidate()
*/ */
const QRectF &QwtPlotLayout::scaleRect( int axis ) const const QRectF &QwtPlotLayout::scaleRect( int axis ) const
{ {
if ( axis < 0 || axis >= QwtPlot::axisCnt ) if ( axis < 0 || axis >= QwtPlot::axisCnt )
@ -411,7 +408,6 @@ const QRectF &QwtPlotLayout::scaleRect( int axis ) const
\return Geometry for the canvas \return Geometry for the canvas
\sa activate(), invalidate() \sa activate(), invalidate()
*/ */
const QRectF &QwtPlotLayout::canvasRect() const const QRectF &QwtPlotLayout::canvasRect() const
{ {
return d_data->canvasRect; return d_data->canvasRect;
@ -466,7 +462,7 @@ QSize QwtPlotLayout::minimumSizeHint( const QwtPlot *plot ) const
scl->getBorderDistHint( sd.minLeft, sd.minRight ); scl->getBorderDistHint( sd.minLeft, sd.minRight );
sd.tickOffset = scl->margin(); sd.tickOffset = scl->margin();
if ( scl->scaleDraw()->hasComponent( QwtAbstractScaleDraw::Ticks ) ) if ( scl->scaleDraw()->hasComponent( QwtAbstractScaleDraw::Ticks ) )
sd.tickOffset += scl->scaleDraw()->maxTickLength(); sd.tickOffset += qCeil( scl->scaleDraw()->maxTickLength() );
} }
canvasBorder[axis] = plot->canvas()->frameWidth() + canvasBorder[axis] = plot->canvas()->frameWidth() +
@ -582,7 +578,7 @@ QSize QwtPlotLayout::minimumSizeHint( const QwtPlot *plot ) const
w += d_data->spacing; w += d_data->spacing;
if ( legendH > h ) if ( legendH > h )
legendW += legend->verticalScrollBar()->sizeHint().height(); legendW += legend->verticalScrollBar()->sizeHint().width();
if ( d_data->legendRatio < 1.0 ) if ( d_data->legendRatio < 1.0 )
legendW = qMin( legendW, int( w / ( 1.0 - d_data->legendRatio ) ) ); legendW = qMin( legendW, int( w / ( 1.0 - d_data->legendRatio ) ) );
@ -745,7 +741,7 @@ void QwtPlotLayout::expandLineBreaks( int options, const QRectF &rect,
if ( !d_data->layoutData.title.text.isEmpty() ) if ( !d_data->layoutData.title.text.isEmpty() )
{ {
int w = rect.width(); double w = rect.width();
if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled
!= d_data->layoutData.scale[QwtPlot::yRight].isEnabled ) != d_data->layoutData.scale[QwtPlot::yRight].isEnabled )
@ -772,7 +768,7 @@ void QwtPlotLayout::expandLineBreaks( int options, const QRectF &rect,
if ( scaleData.isEnabled ) if ( scaleData.isEnabled )
{ {
int length; double length;
if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom ) if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom )
{ {
length = rect.width() - dimAxis[QwtPlot::yLeft] length = rect.width() - dimAxis[QwtPlot::yLeft]
@ -803,13 +799,13 @@ void QwtPlotLayout::expandLineBreaks( int options, const QRectF &rect,
{ {
length += qMin( length += qMin(
d_data->layoutData.scale[QwtPlot::xBottom].tickOffset, d_data->layoutData.scale[QwtPlot::xBottom].tickOffset,
scaleData.start - backboneOffset[QwtPlot::xBottom] ); double( scaleData.start - backboneOffset[QwtPlot::xBottom] ) );
} }
if ( dimAxis[QwtPlot::xTop] > 0 ) if ( dimAxis[QwtPlot::xTop] > 0 )
{ {
length += qMin( length += qMin(
d_data->layoutData.scale[QwtPlot::xTop].tickOffset, d_data->layoutData.scale[QwtPlot::xTop].tickOffset,
scaleData.end - backboneOffset[QwtPlot::xTop] ); double( scaleData.end - backboneOffset[QwtPlot::xTop] ) );
} }
if ( dimTitle > 0 ) if ( dimTitle > 0 )
@ -819,7 +815,7 @@ void QwtPlotLayout::expandLineBreaks( int options, const QRectF &rect,
int d = scaleData.dimWithoutTitle; int d = scaleData.dimWithoutTitle;
if ( !scaleData.scaleWidget->title().isEmpty() ) if ( !scaleData.scaleWidget->title().isEmpty() )
{ {
d += scaleData.scaleWidget->titleHeightForWidth( length ); d += scaleData.scaleWidget->titleHeightForWidth( qFloor( length ) );
} }
@ -871,15 +867,15 @@ void QwtPlotLayout::alignScales( int options,
if ( leftScaleRect.isValid() ) if ( leftScaleRect.isValid() )
{ {
const int dx = leftOffset + leftScaleRect.width(); const double dx = leftOffset + leftScaleRect.width();
if ( d_data->alignCanvasToScales && dx < 0 ) if ( d_data->alignCanvasToScales && dx < 0.0 )
{ {
/* /*
The axis needs more space than the width The axis needs more space than the width
of the left scale. of the left scale.
*/ */
canvasRect.setLeft( qMax( canvasRect.left(), const double cLeft = canvasRect.left(); // qreal -> double
axisRect.left() - dx ) ); canvasRect.setLeft( qMax( cLeft, axisRect.left() - dx ) );
} }
else else
{ {
@ -908,15 +904,15 @@ void QwtPlotLayout::alignScales( int options,
if ( rightScaleRect.isValid() ) if ( rightScaleRect.isValid() )
{ {
const int dx = rightOffset + rightScaleRect.width(); const double dx = rightOffset + rightScaleRect.width();
if ( d_data->alignCanvasToScales && dx < 0 ) if ( d_data->alignCanvasToScales && dx < 0 )
{ {
/* /*
The axis needs more space than the width The axis needs more space than the width
of the right scale. of the right scale.
*/ */
canvasRect.setRight( qMin( canvasRect.right(), const double cRight = canvasRect.right(); // qreal -> double
axisRect.right() + dx ) ); canvasRect.setRight( qMin( cRight, axisRect.right() + dx ) );
} }
const double maxRight = rightScaleRect.right(); const double maxRight = rightScaleRect.right();
@ -945,15 +941,15 @@ void QwtPlotLayout::alignScales( int options,
if ( bottomScaleRect.isValid() ) if ( bottomScaleRect.isValid() )
{ {
const int dy = bottomOffset + bottomScaleRect.height(); const double dy = bottomOffset + bottomScaleRect.height();
if ( d_data->alignCanvasToScales && dy < 0 ) if ( d_data->alignCanvasToScales && dy < 0 )
{ {
/* /*
The axis needs more space than the height The axis needs more space than the height
of the bottom scale. of the bottom scale.
*/ */
canvasRect.setBottom( qMin( canvasRect.bottom(), const double cBottom = canvasRect.bottom(); // qreal -> double
axisRect.bottom() + dy ) ); canvasRect.setBottom( qMin( cBottom, axisRect.bottom() + dy ) );
} }
else else
{ {
@ -982,15 +978,15 @@ void QwtPlotLayout::alignScales( int options,
if ( topScaleRect.isValid() ) if ( topScaleRect.isValid() )
{ {
const int dy = topOffset + topScaleRect.height(); const double dy = topOffset + topScaleRect.height();
if ( d_data->alignCanvasToScales && dy < 0 ) if ( d_data->alignCanvasToScales && dy < 0 )
{ {
/* /*
The axis needs more space than the height The axis needs more space than the height
of the top scale. of the top scale.
*/ */
canvasRect.setTop( qMax( canvasRect.top(), const double cTop = canvasRect.top(); // qreal -> double
axisRect.top() - dy ) ); canvasRect.setTop( qMax( cTop, axisRect.top() - dy ) );
} }
else else
{ {
@ -1090,7 +1086,7 @@ void QwtPlotLayout::activate( const QwtPlot *plot,
// subtract d_data->legendRect from rect // subtract d_data->legendRect from rect
const QRegion region( rect.toRect() ); const QRegion region( rect.toRect() );
rect = region.subtract( d_data->legendRect.toRect() ).boundingRect(); rect = region.subtracted( d_data->legendRect.toRect() ).boundingRect();
switch ( d_data->legendPos ) switch ( d_data->legendPos )
{ {
@ -1138,8 +1134,8 @@ void QwtPlotLayout::activate( const QwtPlot *plot,
if ( dimTitle > 0 ) if ( dimTitle > 0 )
{ {
d_data->titleRect = QRect( rect.x(), rect.y(), d_data->titleRect.setRect(
rect.width(), dimTitle ); rect.left(), rect.top(), rect.width(), dimTitle );
if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled != if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled !=
d_data->layoutData.scale[QwtPlot::yRight].isEnabled ) d_data->layoutData.scale[QwtPlot::yRight].isEnabled )
@ -1147,7 +1143,7 @@ void QwtPlotLayout::activate( const QwtPlot *plot,
// if only one of the y axes is missing we align // if only one of the y axes is missing we align
// the title centered to the canvas // the title centered to the canvas
d_data->titleRect.setX( rect.x() + dimAxes[QwtPlot::yLeft] ); d_data->titleRect.setX( rect.left() + dimAxes[QwtPlot::yLeft] );
d_data->titleRect.setWidth( rect.width() d_data->titleRect.setWidth( rect.width()
- dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight] ); - dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight] );
} }

View File

@ -139,7 +139,13 @@ void QwtPlotMarker::draw( QPainter *painter,
if ( d_data->symbol && if ( d_data->symbol &&
( d_data->symbol->style() != QwtSymbol::NoSymbol ) ) ( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
{ {
d_data->symbol->drawSymbol( painter, pos ); const QSizeF sz = d_data->symbol->size();
const QRectF clipRect = canvasRect.adjusted(
-sz.width(), -sz.height(), sz.width(), sz.height() );
if ( clipRect.contains( pos ) )
d_data->symbol->drawSymbol( painter, pos );
} }
drawLabel( painter, canvasRect, pos ); drawLabel( painter, canvasRect, pos );

View File

@ -9,6 +9,7 @@
#include "qwt_plot_picker.h" #include "qwt_plot_picker.h"
#include "qwt_plot.h" #include "qwt_plot.h"
#include "qwt_plot_canvas.h"
#include "qwt_scale_div.h" #include "qwt_scale_div.h"
#include "qwt_painter.h" #include "qwt_painter.h"
#include "qwt_scale_map.h" #include "qwt_scale_map.h"
@ -277,8 +278,8 @@ bool QwtPlotPicker::end( bool ok )
if ( !plot ) if ( !plot )
return false; return false;
const QPolygon pa = selection(); const QPolygon points = selection();
if ( pa.count() == 0 ) if ( points.count() == 0 )
return false; return false;
QwtPickerMachine::SelectionType selectionType = QwtPickerMachine::SelectionType selectionType =
@ -291,16 +292,16 @@ bool QwtPlotPicker::end( bool ok )
{ {
case QwtPickerMachine::PointSelection: case QwtPickerMachine::PointSelection:
{ {
const QPointF pos = invTransform( pa[0] ); const QPointF pos = invTransform( points.first() );
Q_EMIT selected( pos ); Q_EMIT selected( pos );
break; break;
} }
case QwtPickerMachine::RectSelection: case QwtPickerMachine::RectSelection:
{ {
if ( pa.count() >= 2 ) if ( points.count() >= 2 )
{ {
const QPoint p1 = pa[0]; const QPoint p1 = points.first();
const QPoint p2 = pa[int( pa.count() - 1 )]; const QPoint p2 = points.last();
const QRect rect = QRect( p1, p2 ).normalized(); const QRect rect = QRect( p1, p2 ).normalized();
Q_EMIT selected( invTransform( rect ) ); Q_EMIT selected( invTransform( rect ) );
@ -309,9 +310,9 @@ bool QwtPlotPicker::end( bool ok )
} }
case QwtPickerMachine::PolygonSelection: case QwtPickerMachine::PolygonSelection:
{ {
QVector<QPointF> dpa( pa.count() ); QVector<QPointF> dpa( points.count() );
for ( int i = 0; i < int( pa.count() ); i++ ) for ( int i = 0; i < points.count(); i++ )
dpa[i] = invTransform( pa[i] ); dpa[i] = invTransform( points[i] );
Q_EMIT selected( dpa ); Q_EMIT selected( dpa );
} }

View File

@ -643,11 +643,11 @@ void QwtPlotRasterItem::draw( QPainter *painter,
QRectF pixelRect = pixelHint(area); QRectF pixelRect = pixelHint(area);
if ( !pixelRect.isEmpty() ) if ( !pixelRect.isEmpty() )
{ {
const QRectF r = QwtScaleMap::invTransform( // pixel in target device resolution
xxMap, yyMap, QRectF(0, 0, 1, 1) ).normalized(); const double dx = qAbs( xxMap.invTransform( 1 ) - xxMap.invTransform( 0 ) );
const double dy = qAbs( yyMap.invTransform( 1 ) - yyMap.invTransform( 0 ) );
if ( r.width() > pixelRect.width() && if ( dx > pixelRect.width() && dy > pixelRect.height() )
r.height() > pixelRect.height() )
{ {
/* /*
When the resolution of the data pixels is higher than When the resolution of the data pixels is higher than

View File

@ -23,7 +23,7 @@
#include <qpainter.h> #include <qpainter.h>
#include <qpaintengine.h> #include <qpaintengine.h>
#include <qtransform.h> #include <qtransform.h>
#include <qprinter.h> #include <QtPrintSupport/QPrinter>
#include <qstyle.h> #include <qstyle.h>
#include <qstyleoption.h> #include <qstyleoption.h>
#include <qimagewriter.h> #include <qimagewriter.h>
@ -238,7 +238,7 @@ void QwtPlotRenderer::renderDocument( QwtPlot *plot,
const QRectF documentRect( 0.0, 0.0, size.width(), size.height() ); const QRectF documentRect( 0.0, 0.0, size.width(), size.height() );
const QString fmt = format.toLower(); const QString fmt = format.toLower();
if ( fmt == "pdf" || fmt == "ps" ) if ( fmt == "pdf" )
{ {
#ifndef QT_NO_PRINTER #ifndef QT_NO_PRINTER
QPrinter printer; QPrinter printer;
@ -246,8 +246,22 @@ void QwtPlotRenderer::renderDocument( QwtPlot *plot,
printer.setPaperSize( sizeMM, QPrinter::Millimeter ); printer.setPaperSize( sizeMM, QPrinter::Millimeter );
printer.setDocName( title ); printer.setDocName( title );
printer.setOutputFileName( fileName ); printer.setOutputFileName( fileName );
printer.setOutputFormat( ( format == "pdf" ) printer.setOutputFormat( QPrinter::PdfFormat );
? QPrinter::PdfFormat : QPrinter::PostScriptFormat ); printer.setResolution( resolution );
QPainter painter( &printer );
render( plot, &painter, documentRect );
#endif
}
else if ( fmt == "ps" )
{
#ifndef QT_NO_PRINTER
QPrinter printer;
printer.setFullPage( true );
printer.setPaperSize( sizeMM, QPrinter::Millimeter );
printer.setDocName( title );
printer.setOutputFileName( fileName );
printer.setOutputFormat( QPrinter::NativeFormat );
printer.setResolution( resolution ); printer.setResolution( resolution );
QPainter painter( &printer ); QPainter painter( &printer );
@ -411,7 +425,17 @@ void QwtPlotRenderer::render( QwtPlot *plot,
double( painter->device()->logicalDpiX() ) / plot->logicalDpiX(), double( painter->device()->logicalDpiX() ) / plot->logicalDpiX(),
double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() ); double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() );
painter->save();
QRectF layoutRect = transform.inverted().mapRect( plotRect );
if ( !( d_data->discardFlags & DiscardBackground ) )
{
// subtract the contents margins
int left, top, right, bottom;
plot->getContentsMargins( &left, &top, &right, &bottom );
layoutRect.adjust( left, top, -right, -bottom );
}
int baseLineDists[QwtPlot::axisCnt]; int baseLineDists[QwtPlot::axisCnt];
if ( d_data->layoutFlags & FrameWithScales ) if ( d_data->layoutFlags & FrameWithScales )
@ -424,18 +448,53 @@ void QwtPlotRenderer::render( QwtPlot *plot,
baseLineDists[axisId] = scaleWidget->margin(); baseLineDists[axisId] = scaleWidget->margin();
scaleWidget->setMargin( 0 ); scaleWidget->setMargin( 0 );
} }
if ( !plot->axisEnabled( axisId ) )
{
int left = 0;
int right = 0;
int top = 0;
int bottom = 0;
// When we have a scale the frame is painted on
// the position of the backbone - otherwise we
// need to introduce a margin around the canvas
switch( axisId )
{
case QwtPlot::yLeft:
layoutRect.adjust( 1, 0, 0, 0 );
break;
case QwtPlot::yRight:
layoutRect.adjust( 0, 0, -1, 0 );
break;
case QwtPlot::xTop:
layoutRect.adjust( 0, 1, 0, 0 );
break;
case QwtPlot::xBottom:
layoutRect.adjust( 0, 0, 0, -1 );
break;
default:
break;
}
layoutRect.adjust( left, top, right, bottom );
}
} }
} }
// Calculate the layout for the print.
// Calculate the layout for the document.
QwtPlotLayout::Options layoutOptions = QwtPlotLayout::Options layoutOptions =
QwtPlotLayout::IgnoreScrollbars | QwtPlotLayout::IgnoreFrames; QwtPlotLayout::IgnoreScrollbars | QwtPlotLayout::IgnoreFrames;
if ( d_data->discardFlags & DiscardLegend ) if ( d_data->discardFlags & DiscardLegend )
layoutOptions |= QwtPlotLayout::IgnoreLegend; layoutOptions |= QwtPlotLayout::IgnoreLegend;
const QRectF layoutRect = transform.inverted().mapRect( plotRect );
plot->plotLayout()->activate( plot, layoutRect, layoutOptions ); plot->plotLayout()->activate( plot, layoutRect, layoutOptions );
// now start painting
painter->save();
painter->setWorldTransform( transform, true ); painter->setWorldTransform( transform, true );
// canvas // canvas
@ -536,9 +595,18 @@ void QwtPlotRenderer::renderLegend( const QwtPlot *plot,
if ( legendLayout == NULL ) if ( legendLayout == NULL )
return; return;
uint numCols = legendLayout->columnsForWidth( rect.width() ); int left, right, top, bottom;
plot->legend()->getContentsMargins( &left, &top, &right, &bottom );
QRect layoutRect;
layoutRect.setLeft( qCeil( rect.left() ) + left );
layoutRect.setTop( qCeil( rect.top() ) + top );
layoutRect.setRight( qFloor( rect.right() ) - right );
layoutRect.setBottom( qFloor( rect.bottom() ) - bottom );
uint numCols = legendLayout->columnsForWidth( layoutRect.width() );
QList<QRect> itemRects = QList<QRect> itemRects =
legendLayout->layoutItems( rect.toRect(), numCols ); legendLayout->layoutItems( layoutRect, numCols );
int index = 0; int index = 0;
@ -634,12 +702,7 @@ void QwtPlotRenderer::renderScale( const QwtPlot *plot,
&& scaleWidget->colorBarWidth() > 0 ) && scaleWidget->colorBarWidth() > 0 )
{ {
scaleWidget->drawColorBar( painter, scaleWidget->colorBarRect( rect ) ); scaleWidget->drawColorBar( painter, scaleWidget->colorBarRect( rect ) );
baseDist += scaleWidget->colorBarWidth() + scaleWidget->spacing();
const int off = scaleWidget->colorBarWidth() + scaleWidget->spacing();
if ( scaleWidget->scaleDraw()->orientation() == Qt::Horizontal )
baseDist += off;
else
baseDist += off;
} }
painter->save(); painter->save();
@ -816,7 +879,10 @@ void QwtPlotRenderer::buildCanvasMaps( const QwtPlot *plot,
} }
else else
{ {
int margin = plot->plotLayout()->canvasMargin( axisId ); int margin = 0;
if ( !plot->plotLayout()->alignCanvasToScales() )
margin = plot->plotLayout()->canvasMargin( axisId );
if ( axisId == QwtPlot::yLeft || axisId == QwtPlot::yRight ) if ( axisId == QwtPlot::yLeft || axisId == QwtPlot::yRight )
{ {
from = canvasRect.bottom() - margin; from = canvasRect.bottom() - margin;

View File

@ -70,7 +70,10 @@ public:
//! Use the default layout without margins and frames //! Use the default layout without margins and frames
DefaultLayout = 0x00, DefaultLayout = 0x00,
//! Render all frames of the plot /*!
Render all frames of the plot
\note Not supported yet
*/
KeepFrames = 0x01, KeepFrames = 0x01,
/*! /*!
@ -98,11 +101,11 @@ public:
void setLayoutFlags( LayoutFlags flags ); void setLayoutFlags( LayoutFlags flags );
LayoutFlags layoutFlags() const; LayoutFlags layoutFlags() const;
void renderDocument( QwtPlot *, const QString &format, void renderDocument( QwtPlot *, const QString &fileName,
const QSizeF &sizeMM, int resolution = 85 ); const QSizeF &sizeMM, int resolution = 85 );
void renderDocument( QwtPlot *, void renderDocument( QwtPlot *,
const QString &title, const QString &format, const QString &fileName, const QString &format,
const QSizeF &sizeMM, int resolution = 85 ); const QSizeF &sizeMM, int resolution = 85 );
#ifndef QWT_NO_SVG #ifndef QWT_NO_SVG

View File

@ -299,18 +299,22 @@ const QwtPlot *QwtPlotRescaler::plot() const
} }
//! Event filter for the plot canvas //! Event filter for the plot canvas
bool QwtPlotRescaler::eventFilter( QObject *o, QEvent *e ) bool QwtPlotRescaler::eventFilter( QObject *object, QEvent *event )
{ {
if ( o && o == canvas() ) if ( object && object == canvas() )
{ {
switch ( e->type() ) switch ( event->type() )
{ {
case QEvent::Resize: case QEvent::Resize:
canvasResizeEvent( ( QResizeEvent * )e ); {
canvasResizeEvent( ( QResizeEvent * )event );
break; break;
}
case QEvent::PolishRequest: case QEvent::PolishRequest:
{
rescale(); rescale();
break; break;
}
default:; default:;
} }
} }

View File

@ -46,8 +46,6 @@ public:
void QwtPlotScaleItem::PrivateData::updateBorders( const QRectF &canvasRect, void QwtPlotScaleItem::PrivateData::updateBorders( const QRectF &canvasRect,
const QwtScaleMap &xMap, const QwtScaleMap &yMap ) const QwtScaleMap &xMap, const QwtScaleMap &yMap )
{ {
canvasRectCache = canvasRect;
QwtInterval interval; QwtInterval interval;
if ( scaleDraw->orientation() == Qt::Horizontal ) if ( scaleDraw->orientation() == Qt::Horizontal )
{ {
@ -64,6 +62,7 @@ void QwtPlotScaleItem::PrivateData::updateBorders( const QRectF &canvasRect,
scaleDiv.setInterval( interval ); scaleDiv.setInterval( interval );
scaleDraw->setScaleDiv( scaleDiv ); scaleDraw->setScaleDiv( scaleDiv );
} }
/*! /*!
\brief Constructor for scale item at the position pos. \brief Constructor for scale item at the position pos.
@ -350,7 +349,10 @@ void QwtPlotScaleItem::draw( QPainter *painter,
if ( d_data->scaleDivFromAxis ) if ( d_data->scaleDivFromAxis )
{ {
if ( canvasRect != d_data->canvasRectCache ) if ( canvasRect != d_data->canvasRectCache )
{
d_data->updateBorders( canvasRect, xMap, yMap ); d_data->updateBorders( canvasRect, xMap, yMap );
d_data->canvasRectCache = canvasRect;
}
} }
QPen pen = painter->pen(); QPen pen = painter->pen();
@ -438,6 +440,7 @@ void QwtPlotScaleItem::updateScaleDiv( const QwtScaleDiv& xScaleDiv,
{ {
d_data->updateBorders( plt->canvas()->contentsRect(), d_data->updateBorders( plt->canvas()->contentsRect(),
plt->canvasMap( xAxis() ), plt->canvasMap( yAxis() ) ); plt->canvasMap( xAxis() ), plt->canvasMap( yAxis() ) );
d_data->canvasRectCache = QRect();
} }
} }
} }

View File

@ -60,20 +60,64 @@ template <typename T>
class QwtPlotSeriesItem: public QwtPlotAbstractSeriesItem class QwtPlotSeriesItem: public QwtPlotAbstractSeriesItem
{ {
public: public:
/*!
Constructor
\param title Title of the series item
*/
explicit QwtPlotSeriesItem<T>( const QString &title = QString::null ); explicit QwtPlotSeriesItem<T>( const QString &title = QString::null );
/*!
Constructor
\param title Title of the series item
*/
explicit QwtPlotSeriesItem<T>( const QwtText &title ); explicit QwtPlotSeriesItem<T>( const QwtText &title );
//! Destructor
virtual ~QwtPlotSeriesItem<T>(); virtual ~QwtPlotSeriesItem<T>();
/*!
Assign a series of samples
\param data Data
\warning The item takes ownership of the data object, deleting
it when its not used anymore.
*/
void setData( QwtSeriesData<T> * ); void setData( QwtSeriesData<T> * );
//! \return the the curve data
QwtSeriesData<T> *data(); QwtSeriesData<T> *data();
//! \return the the curve data
const QwtSeriesData<T> *data() const; const QwtSeriesData<T> *data() const;
/*!
Return the size of the data arrays
\sa setData()
*/
size_t dataSize() const; size_t dataSize() const;
/*!
\param index Index
\return Sample at position index
*/
T sample( int index ) const; T sample( int index ) const;
/*!
\return Bounding rectangle of the data.
If there is no bounding rect, like for empty data the rectangle is invalid.
\sa QwtSeriesData<T>::boundingRect(), QRectF::isValid()
*/
virtual QRectF boundingRect() const; virtual QRectF boundingRect() const;
/*!
Update the rect of interest according to the current scale ranges
\param xScaleDiv Scale division of the x-axis
\param yScaleDiv Scale division of the y-axis
\sa QwtSeriesData<T>::setRectOfInterest()
*/
virtual void updateScaleDiv( const QwtScaleDiv &, virtual void updateScaleDiv( const QwtScaleDiv &,
const QwtScaleDiv & ); const QwtScaleDiv & );
@ -82,10 +126,6 @@ protected:
QwtSeriesData<T> *d_series; QwtSeriesData<T> *d_series;
}; };
/*!
Constructor
\param title Title of the series item
*/
template <typename T> template <typename T>
QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QString &title ): QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QString &title ):
QwtPlotAbstractSeriesItem( QwtText( title ) ), QwtPlotAbstractSeriesItem( QwtText( title ) ),
@ -93,10 +133,6 @@ QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QString &title ):
{ {
} }
/*!
Constructor
\param title Title of the series item
*/
template <typename T> template <typename T>
QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QwtText &title ): QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QwtText &title ):
QwtPlotAbstractSeriesItem( title ), QwtPlotAbstractSeriesItem( title ),
@ -104,44 +140,30 @@ QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QwtText &title ):
{ {
} }
//! Destructor
template <typename T> template <typename T>
QwtPlotSeriesItem<T>::~QwtPlotSeriesItem() QwtPlotSeriesItem<T>::~QwtPlotSeriesItem()
{ {
delete d_series; delete d_series;
} }
//! \return the the curve data
template <typename T> template <typename T>
inline QwtSeriesData<T> *QwtPlotSeriesItem<T>::data() inline QwtSeriesData<T> *QwtPlotSeriesItem<T>::data()
{ {
return d_series; return d_series;
} }
//! \return the the curve data
template <typename T> template <typename T>
inline const QwtSeriesData<T> *QwtPlotSeriesItem<T>::data() const inline const QwtSeriesData<T> *QwtPlotSeriesItem<T>::data() const
{ {
return d_series; return d_series;
} }
/*!
\param index Index
\return Sample at position index
*/
template <typename T> template <typename T>
inline T QwtPlotSeriesItem<T>::sample( int index ) const inline T QwtPlotSeriesItem<T>::sample( int index ) const
{ {
return d_series ? d_series->sample( index ) : T(); return d_series ? d_series->sample( index ) : T();
} }
/*!
Assign a series of samples
\param data Data
\warning The item takes ownership of the data object, deleting
it when its not used anymore.
*/
template <typename T> template <typename T>
void QwtPlotSeriesItem<T>::setData( QwtSeriesData<T> *data ) void QwtPlotSeriesItem<T>::setData( QwtSeriesData<T> *data )
{ {
@ -153,10 +175,6 @@ void QwtPlotSeriesItem<T>::setData( QwtSeriesData<T> *data )
} }
} }
/*!
Return the size of the data arrays
\sa setData()
*/
template <typename T> template <typename T>
size_t QwtPlotSeriesItem<T>::dataSize() const size_t QwtPlotSeriesItem<T>::dataSize() const
{ {
@ -166,12 +184,6 @@ size_t QwtPlotSeriesItem<T>::dataSize() const
return d_series->size(); return d_series->size();
} }
/*!
\return Bounding rectangle of the data.
If there is no bounding rect, like for empty data the rectangle is invalid.
\sa QwtSeriesData<T>::boundingRect(), QRectF::isValid()
*/
template <typename T> template <typename T>
QRectF QwtPlotSeriesItem<T>::boundingRect() const QRectF QwtPlotSeriesItem<T>::boundingRect() const
{ {
@ -181,23 +193,18 @@ QRectF QwtPlotSeriesItem<T>::boundingRect() const
return d_series->boundingRect(); return d_series->boundingRect();
} }
/*!
Update the rect of interest according to the current scale ranges
\param xScaleDiv Scale division of the x-axis
\param yScaleDiv Scale division of the y-axis
\sa QwtSeriesData<T>::setRectOfInterest()
*/
template <typename T> template <typename T>
void QwtPlotSeriesItem<T>::updateScaleDiv( void QwtPlotSeriesItem<T>::updateScaleDiv(
const QwtScaleDiv &xScaleDiv, const QwtScaleDiv &yScaleDiv ) const QwtScaleDiv &xScaleDiv, const QwtScaleDiv &yScaleDiv )
{ {
const QRectF rect = QRectF( if ( d_series )
xScaleDiv.lowerBound(), yScaleDiv.lowerBound(), {
xScaleDiv.range(), yScaleDiv.range() ); const QRectF rect = QRectF(
xScaleDiv.lowerBound(), yScaleDiv.lowerBound(),
xScaleDiv.range(), yScaleDiv.range() );
d_series->setRectOfInterest( rect ); d_series->setRectOfInterest( rect );
}
} }
#endif #endif

View File

@ -227,7 +227,7 @@ void QwtPlotSpectroCurve::drawSeries( QPainter *painter,
if ( from < 0 ) if ( from < 0 )
from = 0; from = 0;
if ( from >= to ) if ( from > to )
return; return;
drawDots( painter, xMap, yMap, canvasRect, from, to ); drawDots( painter, xMap, yMap, canvasRect, from, to );

View File

@ -20,7 +20,7 @@
#if QT_VERSION >= 0x040400 #if QT_VERSION >= 0x040400
#include <qthread.h> #include <qthread.h>
#include <qfuture.h> #include <qfuture.h>
#include <qtconcurrentrun.h> #include <QtConcurrent/QtConcurrentRun>
#endif #endif
class QwtPlotSpectrogram::PrivateData class QwtPlotSpectrogram::PrivateData
@ -586,8 +586,6 @@ void QwtPlotSpectrogram::drawContourLines( QPainter *painter,
if ( d_data->data == NULL ) if ( d_data->data == NULL )
return; return;
const QwtInterval intensityRange = d_data->data->interval( Qt::ZAxis );
const int numLevels = d_data->contourLevels.size(); const int numLevels = d_data->contourLevels.size();
for ( int l = 0; l < numLevels; l++ ) for ( int l = 0; l < numLevels; l++ )
{ {

View File

@ -109,7 +109,7 @@ inline QwtPoint3D::QwtPoint3D( const QPointF &other ):
*/ */
inline bool QwtPoint3D::isNull() const inline bool QwtPoint3D::isNull() const
{ {
return d_x == 0.0 && d_y == 0.0 && d_z == 0; return d_x == 0.0 && d_y == 0.0 && d_z == 0.0;
} }
//! Returns the x-coordinate of the point. //! Returns the x-coordinate of the point.

View File

@ -93,7 +93,7 @@ inline bool QwtRasterData::ContourPlane::intersect(
break; break;
case 6: case 6:
// e(-1,1,0), e(1,0,-1) // e(-1,1,0), e(1,0,-1)
line[0] = vertex[1].toPoint(); line[0] = vertex[2].toPoint();
line[1] = intersection( vertex[0], vertex[1] ); line[1] = intersection( vertex[0], vertex[1] );
break; break;
case 7: case 7:

View File

@ -20,8 +20,8 @@ class QwtRoundScaleDraw::PrivateData
{ {
public: public:
PrivateData(): PrivateData():
center( 50, 50 ), center( 50.0, 50.0 ),
radius( 50 ), radius( 50.0 ),
startAngle( -135 * 16 ), startAngle( -135 * 16 ),
endAngle( 135 * 16 ) endAngle( 135 * 16 )
{ {
@ -77,7 +77,7 @@ void QwtRoundScaleDraw::setRadius( int radius )
*/ */
int QwtRoundScaleDraw::radius() const int QwtRoundScaleDraw::radius() const
{ {
return d_data->radius; return qCeil( d_data->radius );
} }
/*! /*!
@ -220,14 +220,17 @@ void QwtRoundScaleDraw::drawTick( QPainter *painter, double value, double len )
*/ */
void QwtRoundScaleDraw::drawBackbone( QPainter *painter ) const void QwtRoundScaleDraw::drawBackbone( QPainter *painter ) const
{ {
const double a1 = qMin( scaleMap().p1(), scaleMap().p2() ) - 90 * 16; const double deg1 = scaleMap().p1();
const double a2 = qMax( scaleMap().p1(), scaleMap().p2() ) - 90 * 16; const double deg2 = scaleMap().p2();
const int a1 = qRound( qMin( deg1, deg2 ) - 90 * 16 );
const int a2 = qRound( qMax( deg1, deg2 ) - 90 * 16 );
const double radius = d_data->radius; const double radius = d_data->radius;
const double x = d_data->center.x() - radius; const double x = d_data->center.x() - radius;
const double y = d_data->center.y() - radius; const double y = d_data->center.y() - radius;
painter->drawArc( x, y, 2 * radius, 2 * radius, painter->drawArc( QRectF( x, y, 2 * radius, 2 * radius ),
-a2, a2 - a1 + 1 ); // counterclockwise -a2, a2 - a1 + 1 ); // counterclockwise
} }

View File

@ -154,7 +154,7 @@ void QwtScaleDiv::invert()
*/ */
void QwtScaleDiv::setTicks( int type, const QList<double> &ticks ) void QwtScaleDiv::setTicks( int type, const QList<double> &ticks )
{ {
if ( type >= 0 || type < NTickTypes ) if ( type >= 0 && type < NTickTypes )
d_ticks[type] = ticks; d_ticks[type] = ticks;
} }
@ -165,7 +165,7 @@ void QwtScaleDiv::setTicks( int type, const QList<double> &ticks )
*/ */
const QList<double> &QwtScaleDiv::ticks( int type ) const const QList<double> &QwtScaleDiv::ticks( int type ) const
{ {
if ( type >= 0 || type < NTickTypes ) if ( type >= 0 && type < NTickTypes )
return d_ticks[type]; return d_ticks[type];
static QList<double> noTicks; static QList<double> noTicks;

View File

@ -16,6 +16,11 @@
#include <qpainter.h> #include <qpainter.h>
#include <qmath.h> #include <qmath.h>
#if QT_VERSION < 0x040601
#define qFastSin(x) qSin(x)
#define qFastCos(x) qCos(x)
#endif
class QwtScaleDraw::PrivateData class QwtScaleDraw::PrivateData
{ {
public: public:
@ -188,7 +193,7 @@ int QwtScaleDraw::minLabelDist( const QFont &font ) const
return 0; return 0;
const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
if ( ticks.count() == 0 ) if ( ticks.isEmpty() )
return 0; return 0;
const QFontMetrics fm( font ); const QFontMetrics fm( font );
@ -199,9 +204,10 @@ int QwtScaleDraw::minLabelDist( const QFont &font ) const
QRectF bRect2 = labelRect( font, ticks[0] ); QRectF bRect2 = labelRect( font, ticks[0] );
if ( vertical ) if ( vertical )
{ {
bRect2.setRect( -bRect2.bottom(), 0, bRect2.height(), bRect2.width() ); bRect2.setRect( -bRect2.bottom(), 0.0, bRect2.height(), bRect2.width() );
} }
int maxDist = 0;
double maxDist = 0.0;
for ( int i = 1; i < ticks.count(); i++ ) for ( int i = 1; i < ticks.count(); i++ )
{ {
@ -209,11 +215,11 @@ int QwtScaleDraw::minLabelDist( const QFont &font ) const
bRect2 = labelRect( font, ticks[i] ); bRect2 = labelRect( font, ticks[i] );
if ( vertical ) if ( vertical )
{ {
bRect2.setRect( -bRect2.bottom(), 0, bRect2.setRect( -bRect2.bottom(), 0.0,
bRect2.height(), bRect2.width() ); bRect2.height(), bRect2.width() );
} }
int dist = fm.leading(); // space between the labels double dist = fm.leading(); // space between the labels
if ( bRect1.right() > 0 ) if ( bRect1.right() > 0 )
dist += bRect1.right(); dist += bRect1.right();
if ( bRect2.left() < 0 ) if ( bRect2.left() < 0 )
@ -227,8 +233,9 @@ int QwtScaleDraw::minLabelDist( const QFont &font ) const
if ( vertical ) if ( vertical )
angle += M_PI / 2; angle += M_PI / 2;
if ( qSin( angle ) == 0.0 ) const double sinA = qFastSin( angle ); // qreal -> double
return maxDist; if ( qFuzzyCompare( sinA + 1.0, 1.0 ) )
return qCeil( maxDist );
const int fmHeight = fm.ascent() - 2; const int fmHeight = fm.ascent() - 2;
@ -236,13 +243,10 @@ int QwtScaleDraw::minLabelDist( const QFont &font ) const
// the height of the label font. This height is needed // the height of the label font. This height is needed
// for the neighbour labal. // for the neighbour labal.
int labelDist = qFloor( fmHeight / qSin( angle ) * qCos( angle ) ); double labelDist = fmHeight / qFastSin( angle ) * qFastCos( angle );
if ( labelDist < 0 ) if ( labelDist < 0 )
labelDist = -labelDist; labelDist = -labelDist;
// The cast above floored labelDist. We want to ceil.
labelDist++;
// For text orientations close to the scale orientation // For text orientations close to the scale orientation
if ( labelDist > maxDist ) if ( labelDist > maxDist )
@ -254,7 +258,7 @@ int QwtScaleDraw::minLabelDist( const QFont &font ) const
if ( labelDist < fmHeight ) if ( labelDist < fmHeight )
labelDist = fmHeight; labelDist = fmHeight;
return labelDist; return qCeil( labelDist );
} }
/*! /*!
@ -846,7 +850,7 @@ Qt::Alignment QwtScaleDraw::labelAlignment() const
*/ */
int QwtScaleDraw::maxLabelWidth( const QFont &font ) const int QwtScaleDraw::maxLabelWidth( const QFont &font ) const
{ {
int maxWidth = 0; double maxWidth = 0.0;
const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
for ( int i = 0; i < ticks.count(); i++ ) for ( int i = 0; i < ticks.count(); i++ )
@ -854,13 +858,13 @@ int QwtScaleDraw::maxLabelWidth( const QFont &font ) const
const double v = ticks[i]; const double v = ticks[i];
if ( scaleDiv().contains( v ) ) if ( scaleDiv().contains( v ) )
{ {
const int w = labelSize( font, ticks[i] ).width(); const double w = labelSize( font, ticks[i] ).width();
if ( w > maxWidth ) if ( w > maxWidth )
maxWidth = w; maxWidth = w;
} }
} }
return maxWidth; return qCeil( maxWidth );
} }
/*! /*!
@ -869,7 +873,7 @@ int QwtScaleDraw::maxLabelWidth( const QFont &font ) const
*/ */
int QwtScaleDraw::maxLabelHeight( const QFont &font ) const int QwtScaleDraw::maxLabelHeight( const QFont &font ) const
{ {
int maxHeight = 0; double maxHeight = 0.0;
const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
for ( int i = 0; i < ticks.count(); i++ ) for ( int i = 0; i < ticks.count(); i++ )
@ -877,13 +881,13 @@ int QwtScaleDraw::maxLabelHeight( const QFont &font ) const
const double v = ticks[i]; const double v = ticks[i];
if ( scaleDiv().contains( v ) ) if ( scaleDiv().contains( v ) )
{ {
const int h = labelSize( font, ticks[i] ).height(); const double h = labelSize( font, ticks[i] ).height();
if ( h > maxHeight ) if ( h > maxHeight )
maxHeight = h; maxHeight = h;
} }
} }
return maxHeight; return qCeil( maxHeight );
} }
void QwtScaleDraw::updateMap() void QwtScaleDraw::updateMap()

View File

@ -12,6 +12,7 @@
#include "qwt_scale_map.h" #include "qwt_scale_map.h"
#include <qalgorithms.h> #include <qalgorithms.h>
#include <qmath.h> #include <qmath.h>
#include <float.h>
#if QT_VERSION < 0x040601 #if QT_VERSION < 0x040601
#define qFabs(x) ::fabs(x) #define qFabs(x) ::fabs(x)
@ -34,7 +35,7 @@ double QwtScaleArithmetic::ceilEps( double value,
const double eps = _eps * intervalSize; const double eps = _eps * intervalSize;
value = ( value - eps ) / intervalSize; value = ( value - eps ) / intervalSize;
return qwtCeilF( value ) * intervalSize; return ::ceil( value ) * intervalSize;
} }
/*! /*!
@ -50,7 +51,7 @@ double QwtScaleArithmetic::floorEps( double value, double intervalSize )
const double eps = _eps * intervalSize; const double eps = _eps * intervalSize;
value = ( value + eps ) / intervalSize; value = ( value + eps ) / intervalSize;
return qwtFloorF( value ) * intervalSize; return ::floor( value ) * intervalSize;
} }
/*! /*!
@ -83,7 +84,7 @@ double QwtScaleArithmetic::ceil125( double x )
const double sign = ( x > 0 ) ? 1.0 : -1.0; const double sign = ( x > 0 ) ? 1.0 : -1.0;
const double lx = ::log10( qFabs( x ) ); const double lx = ::log10( qFabs( x ) );
const double p10 = qwtFloorF( lx ); const double p10 = ::floor( lx );
double fr = qPow( 10.0, lx - p10 ); double fr = qPow( 10.0, lx - p10 );
if ( fr <= 1.0 ) if ( fr <= 1.0 )
@ -111,7 +112,7 @@ double QwtScaleArithmetic::floor125( double x )
double sign = ( x > 0 ) ? 1.0 : -1.0; double sign = ( x > 0 ) ? 1.0 : -1.0;
const double lx = ::log10( qFabs( x ) ); const double lx = ::log10( qFabs( x ) );
const double p10 = qwtFloorF( lx ); const double p10 = ::floor( lx );
double fr = qPow( 10.0, lx - p10 ); double fr = qPow( 10.0, lx - p10 );
if ( fr >= 10.0 ) if ( fr >= 10.0 )
@ -283,6 +284,13 @@ QList<double> QwtScaleEngine::strip( const QList<double>& ticks,
QwtInterval QwtScaleEngine::buildInterval( double v ) const QwtInterval QwtScaleEngine::buildInterval( double v ) const
{ {
const double delta = ( v == 0.0 ) ? 0.5 : qAbs( 0.5 * v ); const double delta = ( v == 0.0 ) ? 0.5 : qAbs( 0.5 * v );
if ( DBL_MAX - delta < v )
return QwtInterval( DBL_MAX - delta, DBL_MAX );
if ( -DBL_MAX + delta > v )
return QwtInterval( -DBL_MAX, -DBL_MAX + delta );
return QwtInterval( v - delta, v + delta ); return QwtInterval( v - delta, v + delta );
} }
@ -465,8 +473,7 @@ void QwtLinearScaleEngine::buildTicks(
const QwtInterval& interval, double stepSize, int maxMinSteps, const QwtInterval& interval, double stepSize, int maxMinSteps,
QList<double> ticks[QwtScaleDiv::NTickTypes] ) const QList<double> ticks[QwtScaleDiv::NTickTypes] ) const
{ {
const QwtInterval boundingInterval = const QwtInterval boundingInterval = align( interval, stepSize );
align( interval, stepSize );
ticks[QwtScaleDiv::MajorTick] = ticks[QwtScaleDiv::MajorTick] =
buildMajorTicks( boundingInterval, stepSize ); buildMajorTicks( boundingInterval, stepSize );
@ -587,13 +594,22 @@ void QwtLinearScaleEngine::buildMinorTicks(
QwtInterval QwtLinearScaleEngine::align( QwtInterval QwtLinearScaleEngine::align(
const QwtInterval &interval, double stepSize ) const const QwtInterval &interval, double stepSize ) const
{ {
double x1 = QwtScaleArithmetic::floorEps( interval.minValue(), stepSize ); double x1 = interval.minValue();
if ( qwtFuzzyCompare( interval.minValue(), x1, stepSize ) == 0 ) double x2 = interval.maxValue();
x1 = interval.minValue();
double x2 = QwtScaleArithmetic::ceilEps( interval.maxValue(), stepSize ); if ( -DBL_MAX + stepSize <= x1 )
if ( qwtFuzzyCompare( interval.maxValue(), x2, stepSize ) == 0 ) {
x2 = interval.maxValue(); const double x = QwtScaleArithmetic::floorEps( x1, stepSize );
if ( qwtFuzzyCompare( x1, x, stepSize ) != 0 )
x1 = x;
}
if ( DBL_MAX - stepSize >= x2 )
{
const double x = QwtScaleArithmetic::ceilEps( x2, stepSize );
if ( qwtFuzzyCompare( x2, x, stepSize ) != 0 )
x2 = x;
}
return QwtInterval( x1, x2 ); return QwtInterval( x1, x2 );
} }
@ -617,7 +633,7 @@ QwtScaleTransformation *QwtLog10ScaleEngine::transformation() const
\sa QwtScaleEngine::setAttribute() \sa QwtScaleEngine::setAttribute()
*/ */
void QwtLog10ScaleEngine::autoScale( int maxNumSteps, void QwtLog10ScaleEngine::autoScale( int maxNumSteps,
double &x1, double &x2, double &stepSize ) const double &x1, double &x2, double &stepSize ) const
{ {
if ( x1 > x2 ) if ( x1 > x2 )
qSwap( x1, x2 ); qSwap( x1, x2 );
@ -627,7 +643,7 @@ void QwtLog10ScaleEngine::autoScale( int maxNumSteps,
if ( interval.maxValue() / interval.minValue() < 10.0 ) if ( interval.maxValue() / interval.minValue() < 10.0 )
{ {
// scale width is less than one decade -> build linear scale // scale width is less than one decade -> try to build a linear scale
QwtLinearScaleEngine linearScaler; QwtLinearScaleEngine linearScaler;
linearScaler.setAttributes( attributes() ); linearScaler.setAttributes( attributes() );
@ -635,9 +651,21 @@ void QwtLog10ScaleEngine::autoScale( int maxNumSteps,
linearScaler.setMargins( lowerMargin(), upperMargin() ); linearScaler.setMargins( lowerMargin(), upperMargin() );
linearScaler.autoScale( maxNumSteps, x1, x2, stepSize ); linearScaler.autoScale( maxNumSteps, x1, x2, stepSize );
stepSize = ::log10( stepSize );
return; QwtInterval linearInterval = QwtInterval( x1, x2 ).normalized();
linearInterval = linearInterval.limited( LOG_MIN, LOG_MAX );
if ( linearInterval.maxValue() / linearInterval.minValue() < 10.0 )
{
// the aligned scale is still less than a decade
if ( stepSize < 0.0 )
stepSize = -::log10( qAbs( stepSize ) );
else
stepSize = ::log10( stepSize );
return;
}
} }
double logRef = 1.0; double logRef = 1.0;
@ -707,7 +735,12 @@ QwtScaleDiv QwtLog10ScaleEngine::divideScale( double x1, double x2,
linearScaler.setMargins( lowerMargin(), upperMargin() ); linearScaler.setMargins( lowerMargin(), upperMargin() );
if ( stepSize != 0.0 ) if ( stepSize != 0.0 )
stepSize = qPow( 10.0, stepSize ); {
if ( stepSize < 0.0 )
stepSize = -qPow( 10.0, -stepSize );
else
stepSize = qPow( 10.0, stepSize );
}
return linearScaler.divideScale( x1, x2, return linearScaler.divideScale( x1, x2,
maxMajSteps, maxMinSteps, stepSize ); maxMajSteps, maxMinSteps, stepSize );

View File

@ -44,9 +44,9 @@ public:
QwtScaleTransformation( Type type ); QwtScaleTransformation( Type type );
virtual ~QwtScaleTransformation(); virtual ~QwtScaleTransformation();
virtual double xForm( double x, double s1, double s2, virtual double xForm( double s, double s1, double s2,
double p1, double p2 ) const; double p1, double p2 ) const;
virtual double invXForm( double x, double p1, double p2, virtual double invXForm( double p, double p1, double p2,
double s1, double s2 ) const; double s1, double s2 ) const;
Type type() const; Type type() const;

View File

@ -201,19 +201,20 @@ void QwtScaleWidget::setTitle( const QwtText &title )
*/ */
void QwtScaleWidget::setAlignment( QwtScaleDraw::Alignment alignment ) void QwtScaleWidget::setAlignment( QwtScaleDraw::Alignment alignment )
{ {
if ( d_data->scaleDraw )
d_data->scaleDraw->setAlignment( alignment );
if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) ) if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) )
{ {
QSizePolicy policy( QSizePolicy::MinimumExpanding, QSizePolicy policy( QSizePolicy::MinimumExpanding,
QSizePolicy::Fixed ); QSizePolicy::Fixed );
if ( d_data->scaleDraw->orientation() == Qt::Vertical ) if ( d_data->scaleDraw->orientation() == Qt::Vertical )
policy.transpose(); policy.transpose();
setSizePolicy( policy );
setSizePolicy( policy );
setAttribute( Qt::WA_WState_OwnSizePolicy, false ); setAttribute( Qt::WA_WState_OwnSizePolicy, false );
} }
if ( d_data->scaleDraw )
d_data->scaleDraw->setAlignment( alignment );
layoutScale(); layoutScale();
} }
@ -645,7 +646,7 @@ void QwtScaleWidget::drawTitle( QPainter *painter,
QwtText title = d_data->title; QwtText title = d_data->title;
title.setRenderFlags( flags ); title.setRenderFlags( flags );
title.draw( painter, QRect( 0, 0, r.width(), r.height() ) ); title.draw( painter, QRectF( 0.0, 0.0, r.width(), r.height() ) );
painter->restore(); painter->restore();
} }
@ -712,7 +713,7 @@ QSize QwtScaleWidget::minimumSizeHint() const
int QwtScaleWidget::titleHeightForWidth( int width ) const int QwtScaleWidget::titleHeightForWidth( int width ) const
{ {
return d_data->title.heightForWidth( width, font() ); return qCeil( d_data->title.heightForWidth( width, font() ) );
} }
/*! /*!

View File

@ -36,7 +36,7 @@ static inline QRectF qwtBoundingRect( const QwtSetSample &sample )
double minX = sample.set[0]; double minX = sample.set[0];
double maxX = sample.set[0]; double maxX = sample.set[0];
for ( int i = 1; i < ( int )sample.set.size(); i++ ) for ( int i = 1; i < sample.set.size(); i++ )
{ {
if ( sample.set[i] < minX ) if ( sample.set[i] < minX )
minX = sample.set[i]; minX = sample.set[i];
@ -63,7 +63,7 @@ static inline QRectF qwtBoundingRect( const QwtSetSample &sample )
*/ */
template <class T> template <class T>
QRectF qwtBoundingRectT( QRectF qwtBoundingRectT(
const QwtSeriesData<T>& series, int from, int to ) const QwtSeriesData<T>& series, int from, int to )
{ {
QRectF boundingRect( 1.0, 1.0, -2.0, -2.0 ); // invalid; QRectF boundingRect( 1.0, 1.0, -2.0, -2.0 ); // invalid;
@ -115,7 +115,7 @@ QRectF qwtBoundingRectT(
\return Bounding rectangle \return Bounding rectangle
*/ */
QRectF qwtBoundingRect( QRectF qwtBoundingRect(
const QwtSeriesData<QPointF> &series, int from, int to ) const QwtSeriesData<QPointF> &series, int from, int to )
{ {
return qwtBoundingRectT<QPointF>( series, from, to ); return qwtBoundingRectT<QPointF>( series, from, to );
@ -132,7 +132,7 @@ QRectF qwtBoundingRect(
\return Bounding rectangle \return Bounding rectangle
*/ */
QRectF qwtBoundingRect( QRectF qwtBoundingRect(
const QwtSeriesData<QwtPoint3D> &series, int from, int to ) const QwtSeriesData<QwtPoint3D> &series, int from, int to )
{ {
return qwtBoundingRectT<QwtPoint3D>( series, from, to ); return qwtBoundingRectT<QwtPoint3D>( series, from, to );
@ -152,7 +152,7 @@ QRectF qwtBoundingRect(
\return Bounding rectangle \return Bounding rectangle
*/ */
QRectF qwtBoundingRect( QRectF qwtBoundingRect(
const QwtSeriesData<QwtPointPolar> &series, int from, int to ) const QwtSeriesData<QwtPointPolar> &series, int from, int to )
{ {
return qwtBoundingRectT<QwtPointPolar>( series, from, to ); return qwtBoundingRectT<QwtPointPolar>( series, from, to );
@ -169,7 +169,7 @@ QRectF qwtBoundingRect(
\return Bounding rectangle \return Bounding rectangle
*/ */
QRectF qwtBoundingRect( QRectF qwtBoundingRect(
const QwtSeriesData<QwtIntervalSample>& series, int from, int to ) const QwtSeriesData<QwtIntervalSample>& series, int from, int to )
{ {
return qwtBoundingRectT<QwtIntervalSample>( series, from, to ); return qwtBoundingRectT<QwtIntervalSample>( series, from, to );
@ -186,7 +186,7 @@ QRectF qwtBoundingRect(
\return Bounding rectangle \return Bounding rectangle
*/ */
QRectF qwtBoundingRect( QRectF qwtBoundingRect(
const QwtSeriesData<QwtSetSample>& series, int from, int to ) const QwtSeriesData<QwtSetSample>& series, int from, int to )
{ {
return qwtBoundingRectT<QwtSetSample>( series, from, to ); return qwtBoundingRectT<QwtSetSample>( series, from, to );
@ -323,10 +323,10 @@ QwtPointArrayData::QwtPointArrayData( const double *x,
const double *y, size_t size ) const double *y, size_t size )
{ {
d_x.resize( size ); d_x.resize( size );
qMemCopy( d_x.data(), x, size * sizeof( double ) ); memcpy( d_x.data(), x, size * sizeof( double ) );
d_y.resize( size ); d_y.resize( size );
qMemCopy( d_y.data(), y, size * sizeof( double ) ); memcpy( d_y.data(), y, size * sizeof( double ) );
} }
/*! /*!
@ -535,10 +535,10 @@ QRectF QwtSyntheticPointData::rectOfInterest() const
*/ */
QRectF QwtSyntheticPointData::boundingRect() const QRectF QwtSyntheticPointData::boundingRect() const
{ {
if ( d_size == 0 || if ( d_size == 0 ||
!( d_interval.isValid() || d_intervalOfInterest.isValid() ) ) !( d_interval.isValid() || d_intervalOfInterest.isValid() ) )
{ {
return QRectF(1.0, 1.0, -2.0, -2.0); // something invalid return QRectF( 1.0, 1.0, -2.0, -2.0 ); // something invalid
} }
return qwtBoundingRect( *this ); return qwtBoundingRect( *this );

View File

@ -61,14 +61,14 @@ inline QwtIntervalSample::QwtIntervalSample(
} }
//! Compare operator //! Compare operator
inline bool QwtIntervalSample::operator==( inline bool QwtIntervalSample::operator==(
const QwtIntervalSample &other ) const const QwtIntervalSample &other ) const
{ {
return value == other.value && interval == other.interval; return value == other.value && interval == other.interval;
} }
//! Compare operator //! Compare operator
inline bool QwtIntervalSample::operator!=( inline bool QwtIntervalSample::operator!=(
const QwtIntervalSample &other ) const const QwtIntervalSample &other ) const
{ {
return !( *this == other ); return !( *this == other );
@ -117,12 +117,33 @@ inline bool QwtSetSample::operator!=( const QwtSetSample &other ) const
but in situations, where data of an application specific format but in situations, where data of an application specific format
needs to be displayed, without having to copy it, it is recommended needs to be displayed, without having to copy it, it is recommended
to implement an individual data access. to implement an individual data access.
A subclass of QwtSeriesData<QPointF> must implement:
- size()\n
Should return number of data points.
- sample()\n
Should return values x and y values of the sample at specific position
as QPointF object.
- boundingRect()\n
Should return the bounding rectangle of the data series.
It is used for autoscaling and might help certain algorithms for displaying
the data. You can use qwtBoundingRect() for an implementation
but often it is possible to implement a more efficient alogrithm
depending on the characteristics of the series.
The member d_boundingRect is intended for caching the calculated rectangle.
*/ */
template <typename T> template <typename T>
class QwtSeriesData class QwtSeriesData
{ {
public: public:
//! Constructor
QwtSeriesData(); QwtSeriesData();
//! Destructor
virtual ~QwtSeriesData(); virtual ~QwtSeriesData();
//! \return Number of samples //! \return Number of samples
@ -147,7 +168,18 @@ public:
*/ */
virtual QRectF boundingRect() const = 0; virtual QRectF boundingRect() const = 0;
virtual void setRectOfInterest( const QRectF & ); /*!
Set a the "rect of interest"
QwtPlotSeriesItem defines the current area of the plot canvas
as "rect of interest" ( QwtPlotSeriesItem::updateScaleDiv() ).
It can be used to implement different levels of details.
The default implementation does nothing.
\param rect Rectangle of interest
*/
virtual void setRectOfInterest( const QRectF &rect );
protected: protected:
//! Can be used to cache a calculated bounding rectangle //! Can be used to cache a calculated bounding rectangle
@ -157,28 +189,17 @@ private:
QwtSeriesData<T> &operator=( const QwtSeriesData<T> & ); QwtSeriesData<T> &operator=( const QwtSeriesData<T> & );
}; };
//! Constructor
template <typename T> template <typename T>
QwtSeriesData<T>::QwtSeriesData(): QwtSeriesData<T>::QwtSeriesData():
d_boundingRect( 0.0, 0.0, -1.0, -1.0 ) d_boundingRect( 0.0, 0.0, -1.0, -1.0 )
{ {
} }
//! Destructor
template <typename T> template <typename T>
QwtSeriesData<T>::~QwtSeriesData() QwtSeriesData<T>::~QwtSeriesData()
{ {
} }
/*!
Set a the "rect of interest"
QwtPlotSeriesItem defines the current area of the plot canvas
as "rect of interest" ( QwtPlotSeriesItem::updateScaleDiv() ).
It can be used to implement different levels of details.
The default implementation does nothing.
*/
template <typename T> template <typename T>
void QwtSeriesData<T>::setRectOfInterest( const QRectF & ) void QwtSeriesData<T>::setRectOfInterest( const QRectF & )
{ {
@ -194,40 +215,51 @@ template <typename T>
class QwtArraySeriesData: public QwtSeriesData<T> class QwtArraySeriesData: public QwtSeriesData<T>
{ {
public: public:
//! Constructor
QwtArraySeriesData(); QwtArraySeriesData();
QwtArraySeriesData( const QVector<T> & );
void setSamples( const QVector<T> & ); /*!
Constructor
\param samples Array of samples
*/
QwtArraySeriesData( const QVector<T> &samples );
/*!
Assign an array of samples
\param samples Array of samples
*/
void setSamples( const QVector<T> &samples );
//! \return Array of samples
const QVector<T> samples() const; const QVector<T> samples() const;
//! \return Number of samples
virtual size_t size() const; virtual size_t size() const;
virtual T sample( size_t ) const;
/*!
\return Sample at a specific position
\param index Index
\return Sample at position i
*/
virtual T sample( size_t index ) const;
protected: protected:
//! Vector of samples //! Vector of samples
QVector<T> d_samples; QVector<T> d_samples;
}; };
//! Constructor
template <typename T> template <typename T>
QwtArraySeriesData<T>::QwtArraySeriesData() QwtArraySeriesData<T>::QwtArraySeriesData()
{ {
} }
/*!
Constructor
\param samples Array of samples
*/
template <typename T> template <typename T>
QwtArraySeriesData<T>::QwtArraySeriesData( const QVector<T> &samples ): QwtArraySeriesData<T>::QwtArraySeriesData( const QVector<T> &samples ):
d_samples( samples ) d_samples( samples )
{ {
} }
/*!
Assign an array of samples
\param samples Array of samples
*/
template <typename T> template <typename T>
void QwtArraySeriesData<T>::setSamples( const QVector<T> &samples ) void QwtArraySeriesData<T>::setSamples( const QVector<T> &samples )
{ {
@ -235,29 +267,22 @@ void QwtArraySeriesData<T>::setSamples( const QVector<T> &samples )
d_samples = samples; d_samples = samples;
} }
//! \return Array of samples
template <typename T> template <typename T>
const QVector<T> QwtArraySeriesData<T>::samples() const const QVector<T> QwtArraySeriesData<T>::samples() const
{ {
return d_samples; return d_samples;
} }
//! \return Number of samples
template <typename T> template <typename T>
size_t QwtArraySeriesData<T>::size() const size_t QwtArraySeriesData<T>::size() const
{ {
return d_samples.size(); return d_samples.size();
} }
/*!
Return a sample
\param i Index
\return Sample at position i
*/
template <typename T> template <typename T>
T QwtArraySeriesData<T>::sample( size_t i ) const T QwtArraySeriesData<T>::sample( size_t i ) const
{ {
return d_samples[i]; return d_samples[ static_cast<int>( i ) ];
} }
//! Interface for iterating over an array of points //! Interface for iterating over an array of points
@ -439,4 +464,4 @@ QWT_EXPORT QRectF qwtBoundingRect(
QWT_EXPORT QRectF qwtBoundingRect( QWT_EXPORT QRectF qwtBoundingRect(
const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 ); const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 );
#endif #endif

View File

@ -941,7 +941,7 @@ void QwtSymbol::drawSymbols( QPainter *painter,
//! \return Size of the bounding rectangle of a symbol //! \return Size of the bounding rectangle of a symbol
QSize QwtSymbol::boundingSize() const QSize QwtSymbol::boundingSize() const
{ {
QSize size; QSizeF size;
switch ( d_data->style ) switch ( d_data->style )
{ {
@ -953,7 +953,7 @@ QSize QwtSymbol::boundingSize() const
if ( d_data->pen.style() != Qt::NoPen ) if ( d_data->pen.style() != Qt::NoPen )
pw = qMax( d_data->pen.widthF(), qreal( 1.0 ) ); pw = qMax( d_data->pen.widthF(), qreal( 1.0 ) );
size = d_data->size + QSize( pw, pw ); size = d_data->size + QSizeF( pw, pw );
break; break;
} }
@ -971,7 +971,7 @@ QSize QwtSymbol::boundingSize() const
if ( d_data->pen.style() != Qt::NoPen ) if ( d_data->pen.style() != Qt::NoPen )
pw = qMax( d_data->pen.widthF(), qreal( 1.0 ) ); pw = qMax( d_data->pen.widthF(), qreal( 1.0 ) );
size = d_data->size + QSize( 2 * pw, 2 * pw ); size = d_data->size + QSizeF( 2 * pw, 2 * pw );
break; break;
} }
default: default:
@ -980,7 +980,9 @@ QSize QwtSymbol::boundingSize() const
} }
} }
return size + QSize( 1, 1 ); // for antialiasing size += QSizeF( 1.0, 1.0 ); // for antialiasing
return QSize( qCeil( size.width() ), qCeil( size.height() ) );
} }
/*! /*!

View File

@ -176,8 +176,8 @@ QSize QwtTextLabel::minimumSizeHint() const
} }
/*! /*!
Returns the preferred height for this widget, given the width.
\param width Width \param width Width
\return Preferred height for this widget, given the width.
*/ */
int QwtTextLabel::heightForWidth( int width ) const int QwtTextLabel::heightForWidth( int width ) const
{ {
@ -191,8 +191,8 @@ int QwtTextLabel::heightForWidth( int width ) const
if ( renderFlags & Qt::AlignLeft || renderFlags & Qt::AlignRight ) if ( renderFlags & Qt::AlignLeft || renderFlags & Qt::AlignRight )
width -= indent; width -= indent;
int height = d_data->text.heightForWidth( width, font() ); int height = qCeil( d_data->text.heightForWidth( width, font() ) );
if ( renderFlags & Qt::AlignTop || renderFlags & Qt::AlignBottom ) if ( ( renderFlags & Qt::AlignTop ) || ( renderFlags & Qt::AlignBottom ) )
height += indent; height += indent;
height += 2 * frameWidth(); height += 2 * frameWidth();

View File

@ -20,8 +20,12 @@
static inline bool qwtIsLogarithmic( const QwtThermo *thermo ) static inline bool qwtIsLogarithmic( const QwtThermo *thermo )
{ {
const QwtScaleTransformation::Type scaleType = const QwtScaleTransformation* transform =
thermo->scaleEngine()->transformation()->type(); thermo->scaleEngine()->transformation();
const QwtScaleTransformation::Type scaleType = transform->type();
delete transform;
return ( scaleType == QwtScaleTransformation::Log10 ); return ( scaleType == QwtScaleTransformation::Log10 );
} }
@ -449,7 +453,7 @@ QRect QwtThermo::pipeRect() const
scaleDraw()->getBorderDistHint( font(), d1, d2 ); scaleDraw()->getBorderDistHint( font(), d1, d2 );
mbd = qMax( d1, d2 ); mbd = qMax( d1, d2 );
} }
int bw = d_data->borderWidth; const int bw = d_data->borderWidth;
QRect tRect; QRect tRect;
if ( d_data->orientation == Qt::Horizontal ) if ( d_data->orientation == Qt::Horizontal )
@ -460,7 +464,7 @@ QRect QwtThermo::pipeRect() const
{ {
tRect.setRect( tRect.setRect(
cr.x() + mbd + bw, cr.x() + mbd + bw,
cr.y() + cr.height() - d_data->pipeWidth - 2 * bw, cr.y() + cr.height() - d_data->pipeWidth - bw,
cr.width() - 2 * ( bw + mbd ), cr.width() - 2 * ( bw + mbd ),
d_data->pipeWidth d_data->pipeWidth
); );
@ -473,7 +477,7 @@ QRect QwtThermo::pipeRect() const
{ {
tRect.setRect( tRect.setRect(
cr.x() + mbd + bw, cr.x() + mbd + bw,
cr.y() + d_data->borderWidth, cr.y() + bw,
cr.width() - 2 * ( bw + mbd ), cr.width() - 2 * ( bw + mbd ),
d_data->pipeWidth d_data->pipeWidth
); );
@ -500,7 +504,7 @@ QRect QwtThermo::pipeRect() const
default: default:
{ {
tRect.setRect( tRect.setRect(
cr.x() + cr.width() - 2 * bw - d_data->pipeWidth, cr.x() + cr.width() - bw - d_data->pipeWidth,
cr.y() + mbd + bw, cr.y() + mbd + bw,
d_data->pipeWidth, d_data->pipeWidth,
cr.height() - 2 * ( bw + mbd ) ); cr.height() - 2 * ( bw + mbd ) );
@ -1011,8 +1015,7 @@ QSize QwtThermo::minimumSizeHint() const
const int sdLength = scaleDraw()->minLength( font() ); const int sdLength = scaleDraw()->minLength( font() );
w = sdLength; w = sdLength;
h = d_data->pipeWidth + sdExtent + h = d_data->pipeWidth + sdExtent + d_data->spacing;
d_data->borderWidth + d_data->spacing;
} }
else // no scale else // no scale
@ -1027,6 +1030,7 @@ QSize QwtThermo::minimumSizeHint() const
w += 2 * d_data->borderWidth; w += 2 * d_data->borderWidth;
h += 2 * d_data->borderWidth; h += 2 * d_data->borderWidth;
// finally add the margins
int left, right, top, bottom; int left, right, top, bottom;
getContentsMargins( &left, &top, &right, &bottom ); getContentsMargins( &left, &top, &right, &bottom );
w += left + right; w += left + right;

View File

@ -337,22 +337,22 @@ void QwtWheel::drawWheelBackground(
if ( orientation() == Qt::Horizontal ) if ( orientation() == Qt::Horizontal )
{ {
painter->setPen( lightPen ); painter->setPen( lightPen );
painter->drawLine( rect.left(), rect.top() + bw2, painter->drawLine( QPointF( rect.left(), rect.top() + bw2 ),
rect.right(), rect.top() + bw2 ); QPointF( rect.right(), rect.top() + bw2 ) );
painter->setPen( darkPen ); painter->setPen( darkPen );
painter->drawLine( rect.left(), rect.bottom() - bw2, painter->drawLine( QPointF( rect.left(), rect.bottom() - bw2 ),
rect.right(), rect.bottom() - bw2 ); QPointF( rect.right(), rect.bottom() - bw2 ) );
} }
else // Qt::Vertical else // Qt::Vertical
{ {
painter->setPen( lightPen ); painter->setPen( lightPen );
painter->drawLine( rect.left() + bw2, rect.top(), painter->drawLine( QPointF( rect.left() + bw2, rect.top() ),
rect.left() + bw2, rect.bottom() ); QPointF( rect.left() + bw2, rect.bottom() ) );
painter->setPen( darkPen ); painter->setPen( darkPen );
painter->drawLine( rect.right() - bw2, rect.top(), painter->drawLine( QPointF( rect.right() - bw2, rect.top() ),
rect.right() - bw2, rect.bottom() ); QPointF( rect.right() - bw2, rect.bottom() ) );
} }
painter->restore(); painter->restore();
@ -367,7 +367,9 @@ void QwtWheel::drawWheelBackground(
void QwtWheel::drawTicks( QPainter *painter, const QRectF &rect ) void QwtWheel::drawTicks( QPainter *painter, const QRectF &rect )
{ {
if ( maxValue() == minValue() || d_data->totalAngle == 0.0 ) if ( maxValue() == minValue() || d_data->totalAngle == 0.0 )
{
return; return;
}
const QPen lightPen( palette().color( QPalette::Light ), const QPen lightPen( palette().color( QPalette::Light ),
0, Qt::SolidLine, Qt::FlatCap ); 0, Qt::SolidLine, Qt::FlatCap );
@ -400,7 +402,7 @@ void QwtWheel::drawTicks( QPainter *painter, const QRectF &rect )
const double minpos = rect.left() + 2; const double minpos = rect.left() + 2;
// draw tick marks // draw tick marks
for ( double tickValue = qwtCeilF( loValue / tickWidth ) * tickWidth; for ( double tickValue = ::ceil( loValue / tickWidth ) * tickWidth;
tickValue < hiValue; tickValue += tickWidth ) tickValue < hiValue; tickValue += tickWidth )
{ {
const double angle = ( tickValue - value() ) * M_PI / 180.0; const double angle = ( tickValue - value() ) * M_PI / 180.0;
@ -412,9 +414,11 @@ void QwtWheel::drawTicks( QPainter *painter, const QRectF &rect )
if ( ( tickPos <= maxpos ) && ( tickPos > minpos ) ) if ( ( tickPos <= maxpos ) && ( tickPos > minpos ) )
{ {
painter->setPen( darkPen ); painter->setPen( darkPen );
painter->drawLine( tickPos - 1 , l1, tickPos - 1, l2 ); painter->drawLine( QPointF( tickPos - 1 , l1 ),
QPointF( tickPos - 1, l2 ) );
painter->setPen( lightPen ); painter->setPen( lightPen );
painter->drawLine( tickPos, l1, tickPos, l2 ); painter->drawLine( QPointF( tickPos, l1 ),
QPointF( tickPos, l2 ) );
} }
} }
} }
@ -434,7 +438,7 @@ void QwtWheel::drawTicks( QPainter *painter, const QRectF &rect )
const double maxpos = rect.bottom() - 2; const double maxpos = rect.bottom() - 2;
const double minpos = rect.top() + 2; const double minpos = rect.top() + 2;
for ( double tickValue = qwtCeilF( loValue / tickWidth ) * tickWidth; for ( double tickValue = ::ceil( loValue / tickWidth ) * tickWidth;
tickValue < hiValue; tickValue += tickWidth ) tickValue < hiValue; tickValue += tickWidth )
{ {
const double angle = ( tickValue - value() ) * M_PI / 180.0; const double angle = ( tickValue - value() ) * M_PI / 180.0;
@ -446,9 +450,11 @@ void QwtWheel::drawTicks( QPainter *painter, const QRectF &rect )
if ( ( tickPos <= maxpos ) && ( tickPos > minpos ) ) if ( ( tickPos <= maxpos ) && ( tickPos > minpos ) )
{ {
painter->setPen( darkPen ); painter->setPen( darkPen );
painter->drawLine( l1, tickPos - 1 , l2, tickPos - 1 ); painter->drawLine( QPointF( l1, tickPos - 1 ),
QPointF( l2, tickPos - 1 ) );
painter->setPen( lightPen ); painter->setPen( lightPen );
painter->drawLine( l1, tickPos, l2, tickPos ); painter->drawLine( QPointF( l1, tickPos ),
QPointF( l2, tickPos ) );
} }
} }
} }

View File

@ -12,16 +12,19 @@
TEMPLATE = lib TEMPLATE = lib
TARGET = Qwt TARGET = Qwt
DEFINES += QWT_LIBRARY DEFINES += QWT_LIBRARY
QT += printsupport
include(../../../openpilotgcslibrary.pri) include(../../../openpilotgcslibrary.pri)
include( ../qwtconfig.pri ) include( ../qwtconfig.pri )
#VVERSION = $$[QT_VERSION] #VVERSION = $$[QT_VERSION]
contains(QWT_CONFIG, QwtDll) { contains(QWT_CONFIG, QwtDll) {
CONFIG += dll CONFIG += dll
win32|symbian: DEFINES += QT_DLL QWT_DLL QWT_MAKEDLL win32|symbian: DEFINES += QT_DLL QWT_DLL QWT_MAKEDLL
} }
else { else {
CONFIG += staticlib CONFIG += staticlib
} }
unix:!mac:LIBS += -lrt unix:!mac:LIBS += -lrt
@ -204,4 +207,4 @@ contains(QWT_CONFIG, QwtWidgets) {
qwt_slider.cpp \ qwt_slider.cpp \
qwt_thermo.cpp \ qwt_thermo.cpp \
qwt_wheel.cpp qwt_wheel.cpp
} }