]> Git trees. - libqmvoc.git/commitdiff
API changes:
authorPino Toscano <pino@kde.org>
Sat, 17 Feb 2007 15:44:16 +0000 (15:44 +0000)
committerPino Toscano <pino@kde.org>
Sat, 17 Feb 2007 15:44:16 +0000 (15:44 +0000)
- 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
kdeeduplot/kplotaxis.h
kdeeduplot/kplotobject.cpp
kdeeduplot/kplotobject.h
kdeeduplot/kplotwidget.cpp
kdeeduplot/kplotwidget.h
kdeeduplot/tests/testplot_widget.cpp

index a242f55aceccb6b6d617de991f4dcc07d176972d..65353fa171b6fdc4b05c516afd6a7edda3b1d410 100644 (file)
@@ -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;
 }
index 3a5b17f30685165c67ca223dcb83786186440e7a..51465812c275533b19689283b00ebde2c6d384d3 100644 (file)
@@ -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.
index 2959ed1941afb0afa9f12f0f4a6f3c6226f747c5..f612bc627a50444e5c38f01d5a8181f65f871198 100644 (file)
@@ -55,7 +55,7 @@ class KPlotObject::Private
         KPlotObject *q;
 
         QList<KPlotPoint*> 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 );
                }
index 46b95c5481a736809d10705347de1173a7d977ae..972bf9e94b0611e0cae0ad88600d8528283de17b 100644 (file)
@@ -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
index 512f4ff62ed63eea254bd44ed23c7a7c60d899fe..71efdcf019774b205a9bb49d200e7e479e2efd1f 100644 (file)
@@ -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<KPlotPoint*> KPlotWidget::pointsUnderPoint( const QPoint& p ) const {
        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;
                }
        }
@@ -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;
     }
index f9dea75894d00781c667f390952b1bddf6342101..81bf5711e526310dd1602f9e1d5513577a0304ad 100644 (file)
@@ -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 
index df3d5cdc886d947d08d228bd4e9969c7d3d7fb60..19311d3db8bde2c1d0750ab004a723cbbc25628a 100644 (file)
@@ -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]");