d->m_visible = visible;
}
-bool KPlotAxis::showTickLabels() const
+bool KPlotAxis::areTickLabelsShown() const
{
return d->m_showTickLabels;
}
-void KPlotAxis::setShowTickLabels( bool b )
+void KPlotAxis::setTickLabelsShown( bool b )
{
d->m_showTickLabels = b;
}
/**
* @return whether tick labels will be drawn for this axis
*/
- bool showTickLabels() const;
+ bool areTickLabelsShown() const;
/**
* Determine whether tick labels will be drawn for this axis.
*/
- void setShowTickLabels( bool b );
+ void setTickLabelsShown( bool b );
/**
* Sets the axis label.
KPlotObject *q;
QList<KPlotPoint*> pList;
- int type;
+ PlotTypes type;
PointStyle pointStyle;
double size;
QPen pen, linePen, barPen, labelPen;
setBarPen( pen() );
setLabelPen( pen() );
- d->type = t;
+ d->type |= t;
setSize( size );
setPointStyle( ps );
}
d->pList.at(i)->setLabel( n );
}
-bool KPlotObject::showPoints() const
+KPlotObject::PlotTypes KPlotObject::plotTypes() const
{
- return d->type & KPlotObject::Points;
-}
-
-bool KPlotObject::showLines() const
-{
- return d->type & KPlotObject::Lines;
-}
-
-bool KPlotObject::showBars() const
-{
- return d->type & KPlotObject::Bars;
+ return d->type;
}
void KPlotObject::setShowPoints( bool b )
{
if ( b )
{
- d->type = d->type | KPlotObject::Points;
+ d->type |= KPlotObject::Points;
}
else
{
- d->type = d->type & ~KPlotObject::Points;
+ d->type &= ~KPlotObject::Points;
}
}
{
if ( b )
{
- d->type = d->type | KPlotObject::Lines;
+ d->type |= KPlotObject::Lines;
}
else
{
- d->type = d->type & ~KPlotObject::Lines;
+ d->type &= ~KPlotObject::Lines;
}
}
{
if ( b )
{
- d->type = d->type | KPlotObject::Bars;
+ d->type |= KPlotObject::Bars;
}
else
{
- d->type = d->type & ~KPlotObject::Bars;
+ d->type &= ~KPlotObject::Bars;
}
}
//Order of drawing determines z-distance: Bars in the back, then lines,
//then points, then labels.
- if ( showBars() ) {
+ if ( d->type & Bars ) {
painter->setPen( barPen() );
painter->setBrush( barBrush() );
QPointF pp = d->pList[i]->position();
QPointF p1( pp.x() - 0.5*w, 0.0 );
QPointF p2( pp.x() + 0.5*w, pp.y() );
- QPointF sp1 = pw->toScreen( p1 );
- QPointF sp2 = pw->toScreen( p2 );
+ QPointF sp1 = pw->mapToWidget( p1 );
+ QPointF sp2 = pw->mapToWidget( p2 );
QRectF barRect = QRectF( sp1.x(), sp1.y(), sp2.x()-sp1.x(), sp2.y()-sp1.y() ).normalized();
painter->drawRect( barRect );
}
//Draw lines:
- if ( showLines() ) {
+ if ( d->type & Lines ) {
painter->setPen( linePen() );
QPointF Previous = QPointF(); //Initialize to null
foreach ( KPlotPoint *pp, d->pList ) {
//q is the position of the point in screen pixel coordinates
- QPointF q = pw->toScreen( pp->position() );
+ QPointF q = pw->mapToWidget( pp->position() );
if ( ! Previous.isNull() ) {
painter->drawLine( Previous, q );
}
//Draw points:
- if ( showPoints() ) {
+ if ( d->type & Points ) {
foreach( KPlotPoint *pp, d->pList ) {
//q is the position of the point in screen pixel coordinates
- QPointF q = pw->toScreen( pp->position() );
+ QPointF q = pw->mapToWidget( pp->position() );
if ( pw->pixRect().contains( q.toPoint(), false ) ) {
double x1 = q.x() - size();
double y1 = q.y() - size();
painter->setPen( labelPen() );
foreach ( KPlotPoint *pp, d->pList ) {
- QPoint q = pw->toScreen( pp->position() ).toPoint();
+ QPoint q = pw->mapToWidget( pp->position() ).toPoint();
if ( pw->pixRect().contains(q, false) && ! pp->label().isEmpty() ) {
pw->placeLabel( painter, pp );
}
Lines = 2, ///< each KPlotPoint is connected with a line
Bars = 4 ///< each KPlotPoint is shown as a vertical bar
};
+ Q_DECLARE_FLAGS( PlotTypes, PlotType )
/**
* The possible kind of points.
*/
void setLabel( int i, const QString &n );
- /**
- * @return true if points will be drawn for this object
- */
- bool showPoints() const;
- /**
- * @return true if lines will be drawn for this object
- */
- bool showLines() const;
- /**
- * @return true if bars will be drawn for this object
- */
- bool showBars() const;
+ /**
+ * @return the plot flags of the object
+ */
+ PlotTypes plotTypes() const;
/**
* Set whether points will be drawn for this object
Q_DISABLE_COPY( KPlotObject );
};
+Q_DECLARE_OPERATORS_FOR_FLAGS( KPlotObject::PlotTypes );
#endif
{
// create the axes and setting their default properties
KPlotAxis *leftAxis = new KPlotAxis();
- leftAxis->setShowTickLabels( true );
+ leftAxis->setTickLabelsShown( true );
axes.insert( LeftAxis, leftAxis );
KPlotAxis *bottomAxis = new KPlotAxis();
- bottomAxis->setShowTickLabels( true );
+ bottomAxis->setTickLabelsShown( true );
axes.insert( BottomAxis, bottomAxis );
KPlotAxis *rightAxis = new KPlotAxis();
axes.insert( RightAxis, rightAxis );
d->calcDataRectLimits( 0.0, 1.0, 0.0, 1.0 );
KPlotAxis *a = axis( RightAxis );
a->setLabel( QString() );
- a->setShowTickLabels( false );
+ a->setTickLabelsShown( false );
a = axis( TopAxis );
a->setLabel( QString() );
- a->setShowTickLabels( false );
+ a->setTickLabelsShown( false );
axis(KPlotWidget::LeftAxis)->setLabel( QString() );
axis(KPlotWidget::BottomAxis)->setLabel( QString() );
resetPlotMask();
QList<KPlotPoint*> pts;
foreach ( KPlotObject *po, d->objectList ) {
foreach ( KPlotPoint *pp, po->points() ) {
- if ( ( p - toScreen( pp->position() ).toPoint() ).manhattanLength() <= 4 )
+ if ( ( p - mapToWidget( pp->position() ).toPoint() ).manhattanLength() <= 4 )
pts << pp;
}
}
}
}
-QPointF KPlotWidget::toScreen( const QPointF& p ) const
+QPointF KPlotWidget::mapToWidget( const QPointF& p ) const
{
float px = d->pixRect.left() + d->pixRect.width() * ( p.x() - d->dataRect.x() ) / d->dataRect.width();
float py = d->pixRect.top() + d->pixRect.height() * ( d->dataRect.y() + d->dataRect.height() - p.y() ) / d->dataRect.height();
float rbest = 100;
float bestCost = 1.0e7;
- QPointF pos = toScreen( pp->position() );
+ QPointF pos = mapToWidget( pp->position() );
QRectF bestRect;
int ix0 = int( 100.0*( pos.x() - d->pixRect.x() )/d->pixRect.width() );
int iy0 = int( 100.0*( pos.y() - d->pixRect.y() )/d->pixRect.height() );
QPointF( px, double(d->pixRect.height() - BIGTICKSIZE - TICKOFFSET)) );
//Draw ticklabel
- if ( a->showTickLabels() ) {
+ if ( a->areTickLabelsShown() ) {
QRect r( int(px) - BIGTICKSIZE, d->pixRect.height()+BIGTICKSIZE, 2*BIGTICKSIZE, BIGTICKSIZE );
p->drawText( r, Qt::AlignCenter | Qt::TextDontClip, a->tickLabel( xx ) );
}
p->drawLine( QPointF( TICKOFFSET, py ), QPointF( double(TICKOFFSET + BIGTICKSIZE), py ) );
//Draw ticklabel
- if ( a->showTickLabels() ) {
+ if ( a->areTickLabelsShown() ) {
QRect r( -2*BIGTICKSIZE-SMALLTICKSIZE, int(py)-SMALLTICKSIZE, 2*BIGTICKSIZE, 2*SMALLTICKSIZE );
p->drawText( r, Qt::AlignRight | Qt::AlignVCenter | Qt::TextDontClip, a->tickLabel( yy ) );
}
p->drawLine( QPointF( px, TICKOFFSET ), QPointF( px, double(BIGTICKSIZE + TICKOFFSET)) );
//Draw ticklabel
- if ( a->showTickLabels() ) {
+ if ( a->areTickLabelsShown() ) {
QRect r( int(px) - BIGTICKSIZE, (int)-1.5*BIGTICKSIZE, 2*BIGTICKSIZE, BIGTICKSIZE );
p->drawText( r, Qt::AlignCenter | Qt::TextDontClip, a->tickLabel( xx ) );
}
QPointF( double(d->pixRect.width() - TICKOFFSET - BIGTICKSIZE), py ) );
//Draw ticklabel
- if ( a->showTickLabels() ) {
+ if ( a->areTickLabelsShown() ) {
QRect r( d->pixRect.width() + SMALLTICKSIZE, int(py)-SMALLTICKSIZE, 2*BIGTICKSIZE, 2*SMALLTICKSIZE );
p->drawText( r, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextDontClip, a->tickLabel( yy ) );
}
if ( d->leftPadding >= 0 )
return d->leftPadding;
const KPlotAxis *a = axis( LeftAxis );
- if ( a && a->isVisible() && a->showTickLabels() )
+ if ( a && a->isVisible() && a->areTickLabelsShown() )
{
return !a->label().isEmpty() ? 3 * XPADDING : 2 * XPADDING;
}
if ( d->rightPadding >= 0 )
return d->rightPadding;
const KPlotAxis *a = axis( RightAxis );
- if ( a && a->isVisible() && a->showTickLabels() )
+ if ( a && a->isVisible() && a->areTickLabelsShown() )
{
return !a->label().isEmpty() ? 3 * XPADDING : 2 * XPADDING;
}
if ( d->topPadding >= 0 )
return d->topPadding;
const KPlotAxis *a = axis( TopAxis );
- if ( a && a->isVisible() && a->showTickLabels() )
+ if ( a && a->isVisible() && a->areTickLabelsShown() )
{
return !a->label().isEmpty() ? 3 * YPADDING : 2 * YPADDING;
}
if ( d->bottomPadding >= 0 )
return d->bottomPadding;
const KPlotAxis *a = axis( BottomAxis );
- if ( a && a->isVisible() && a->showTickLabels() )
+ if ( a && a->isVisible() && a->areTickLabelsShown() )
{
return !a->label().isEmpty() ? 3 * YPADDING : 2 * YPADDING;
}
* Used mainly when drawing.
* @return the coordinate in the pixel coordinate system
*/
- QPointF toScreen( const QPointF& p ) const;
+ QPointF mapToWidget( const QPointF& p ) const;
/**
* Indicate that object labels should not occupy the given
{
plot->setLimits( -0.1, 6.38, -1.1, 1.1 );
plot->setSecondaryLimits( -5.73, 365.55, -1.1, 1.1 );
- plot->axis(KPlotWidget::TopAxis)->setShowTickLabels( true );
+ plot->axis(KPlotWidget::TopAxis)->setTickLabelsShown( true );
plot->axis(KPlotWidget::BottomAxis)->setLabel("Angle [radians]");
plot->axis(KPlotWidget::TopAxis)->setLabel("Angle [degrees]");