From cba06f5dc8286156088ed6ec6e487080b2580631 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 17 Feb 2007 15:44:16 +0000 Subject: [PATCH] API changes: - KPlotAxis: showTickLabels() -> areTickLabelsShown() - KPlotAxis: setShowTickLabels() -> setTickLabelsShown() - KPlotObject: added the flags for PlotType - KPlotObject: remove the show*() in flavour of getting directly the flags with the types - KPlotWidget: toScreen() -> mapToWidget() svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=634555 --- kdeeduplot/kplotaxis.cpp | 4 +-- kdeeduplot/kplotaxis.h | 4 +-- kdeeduplot/kplotobject.cpp | 46 +++++++++++----------------- kdeeduplot/kplotobject.h | 18 ++++------- kdeeduplot/kplotwidget.cpp | 30 +++++++++--------- kdeeduplot/kplotwidget.h | 2 +- kdeeduplot/tests/testplot_widget.cpp | 2 +- 7 files changed, 45 insertions(+), 61 deletions(-) diff --git a/kdeeduplot/kplotaxis.cpp b/kdeeduplot/kplotaxis.cpp index a242f55..65353fa 100644 --- a/kdeeduplot/kplotaxis.cpp +++ b/kdeeduplot/kplotaxis.cpp @@ -61,12 +61,12 @@ void KPlotAxis::setVisible( bool visible ) 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; } diff --git a/kdeeduplot/kplotaxis.h b/kdeeduplot/kplotaxis.h index 3a5b17f..5146581 100644 --- a/kdeeduplot/kplotaxis.h +++ b/kdeeduplot/kplotaxis.h @@ -57,12 +57,12 @@ public: /** * @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. diff --git a/kdeeduplot/kplotobject.cpp b/kdeeduplot/kplotobject.cpp index 2959ed1..f612bc6 100644 --- a/kdeeduplot/kplotobject.cpp +++ b/kdeeduplot/kplotobject.cpp @@ -55,7 +55,7 @@ class KPlotObject::Private KPlotObject *q; QList pList; - int type; + PlotTypes type; PointStyle pointStyle; double size; QPen pen, linePen, barPen, labelPen; @@ -145,7 +145,7 @@ KPlotObject::KPlotObject( const QColor &c, PlotType t, double size, PointStyle p setBarPen( pen() ); setLabelPen( pen() ); - d->type = t; + d->type |= t; setSize( size ); setPointStyle( ps ); } @@ -171,30 +171,20 @@ void KPlotObject::setLabel( int i, const QString &n ) 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; } } @@ -202,11 +192,11 @@ void KPlotObject::setShowLines( bool b ) { if ( b ) { - d->type = d->type | KPlotObject::Lines; + d->type |= KPlotObject::Lines; } else { - d->type = d->type & ~KPlotObject::Lines; + d->type &= ~KPlotObject::Lines; } } @@ -214,11 +204,11 @@ void KPlotObject::setShowBars( bool b ) { if ( b ) { - d->type = d->type | KPlotObject::Bars; + d->type |= KPlotObject::Bars; } else { - d->type = d->type & ~KPlotObject::Bars; + d->type &= ~KPlotObject::Bars; } } @@ -345,7 +335,7 @@ void KPlotObject::draw( QPainter *painter, KPlotWidget *pw ) { //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() ); @@ -363,8 +353,8 @@ void KPlotObject::draw( QPainter *painter, KPlotWidget *pw ) { 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 ); @@ -373,14 +363,14 @@ void KPlotObject::draw( QPainter *painter, KPlotWidget *pw ) { } //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 ); @@ -392,11 +382,11 @@ void KPlotObject::draw( QPainter *painter, KPlotWidget *pw ) { } //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(); @@ -493,7 +483,7 @@ void KPlotObject::draw( QPainter *painter, KPlotWidget *pw ) { 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 ); } diff --git a/kdeeduplot/kplotobject.h b/kdeeduplot/kplotobject.h index 46b95c5..972bf9e 100644 --- a/kdeeduplot/kplotobject.h +++ b/kdeeduplot/kplotobject.h @@ -155,6 +155,7 @@ public: 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. @@ -202,18 +203,10 @@ public: */ 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 @@ -372,5 +365,6 @@ private: Q_DISABLE_COPY( KPlotObject ); }; +Q_DECLARE_OPERATORS_FOR_FLAGS( KPlotObject::PlotTypes ); #endif diff --git a/kdeeduplot/kplotwidget.cpp b/kdeeduplot/kplotwidget.cpp index 512f4ff..71efdcf 100644 --- a/kdeeduplot/kplotwidget.cpp +++ b/kdeeduplot/kplotwidget.cpp @@ -47,10 +47,10 @@ class KPlotWidget::Private { // 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 ); @@ -248,10 +248,10 @@ void KPlotWidget::resetPlot() { 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(); @@ -349,7 +349,7 @@ QList KPlotWidget::pointsUnderPoint( const QPoint& p ) const { QList 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; } } @@ -390,7 +390,7 @@ void KPlotWidget::setPixRect() { } } -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(); @@ -442,7 +442,7 @@ void KPlotWidget::placeLabel( QPainter *painter, KPlotPoint *pp ) { 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() ); @@ -602,7 +602,7 @@ void KPlotWidget::drawAxes( QPainter *p ) { 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 ) ); } @@ -638,7 +638,7 @@ void KPlotWidget::drawAxes( QPainter *p ) { 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 ) ); } @@ -694,7 +694,7 @@ void KPlotWidget::drawAxes( QPainter *p ) { 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 ) ); } @@ -730,7 +730,7 @@ void KPlotWidget::drawAxes( QPainter *p ) { 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 ) ); } @@ -768,7 +768,7 @@ int KPlotWidget::leftPadding() const 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; } @@ -780,7 +780,7 @@ int KPlotWidget::rightPadding() const 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; } @@ -792,7 +792,7 @@ int KPlotWidget::topPadding() const 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; } @@ -804,7 +804,7 @@ int KPlotWidget::bottomPadding() const 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; } diff --git a/kdeeduplot/kplotwidget.h b/kdeeduplot/kplotwidget.h index f9dea75..81bf571 100644 --- a/kdeeduplot/kplotwidget.h +++ b/kdeeduplot/kplotwidget.h @@ -303,7 +303,7 @@ public: * 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 diff --git a/kdeeduplot/tests/testplot_widget.cpp b/kdeeduplot/tests/testplot_widget.cpp index df3d5cd..19311d3 100644 --- a/kdeeduplot/tests/testplot_widget.cpp +++ b/kdeeduplot/tests/testplot_widget.cpp @@ -77,7 +77,7 @@ void TestPlot::slotSelectPlot( int n ) { { 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]"); -- 2.47.3