]> Git trees. - libqmvoc.git/commitdiff
API changes:
authorPino Toscano <pino@kde.org>
Fri, 16 Feb 2007 23:04:51 +0000 (23:04 +0000)
committerPino Toscano <pino@kde.org>
Fri, 16 Feb 2007 23:04:51 +0000 (23:04 +0000)
- kill the x()/y()/x2()/y2()/dataWidth()/dataHeight() functions in flavour of a simplier dataRect() that just return the rect. (Note that x() and y() were quite ambiguous.)
- move the data rect and the secondary data rect in the Private class

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=634346

kdeeduplot/kplotwidget.cpp
kdeeduplot/kplotwidget.h

index 32b9eb1607ca33f76ce76a58a95ce3370b098889..17577ed2efca02a68df240a28924c02ac264eb83 100644 (file)
@@ -78,6 +78,8 @@ class KPlotWidget::Private
         QHash<Axis, KPlotAxis*> axes;
         // List of KPlotObjects
         QList<KPlotObject*> objectList;
+        // Limits of the plot area in data units
+        QRectF dataRect, secondDataRect;
 };
 
 KPlotWidget::KPlotWidget( QWidget * parent )
@@ -87,7 +89,7 @@ KPlotWidget::KPlotWidget( QWidget * parent )
 
     // sets the default limits
     setLimits( 0.0, 1.0, 0.0, 1.0 );
-    SecondDataRect = QRect(); //default: no secondary data rect
+    d->secondDataRect = QRect(); //default: no secondary data rect
 
     setDefaultPaddings();
 
@@ -122,14 +124,14 @@ void KPlotWidget::setLimits( double x1, double x2, double y1, double y2 ) {
                        i18n("y1 and y2 cannot be equal.  Setting y2 = y1 + 1.0") << endl;
                YA2 = YA1 + 1.0;
        }
-       DataRect = QRectF( XA1, YA1, XA2-XA1, YA2-YA1 );
+       d->dataRect = QRectF( XA1, YA1, XA2-XA1, YA2-YA1 );
 
-       axis(LeftAxis)->setTickMarks( y(), dataHeight() );
-       axis(BottomAxis)->setTickMarks( x(), dataWidth() );
+       axis(LeftAxis)->setTickMarks( d->dataRect.y(), d->dataRect.height() );
+       axis(BottomAxis)->setTickMarks( d->dataRect.x(), d->dataRect.width() );
 
        if ( secondaryDataRect().isNull() ) {
-               axis(RightAxis)->setTickMarks( y(), dataHeight() );
-               axis(TopAxis)->setTickMarks( x(), dataWidth() );
+               axis(RightAxis)->setTickMarks( d->dataRect.y(), d->dataRect.height() );
+               axis(TopAxis)->setTickMarks( d->dataRect.x(), d->dataRect.width() );
        }
 
        update();
@@ -152,22 +154,32 @@ void KPlotWidget::setSecondaryLimits( double x1, double x2, double y1, double y2
                        i18n("y1 and y2 cannot be equal.  Setting y2 = y1 + 1.0") << endl;
                YA2 = YA1 + 1.0;
        }
-       SecondDataRect = QRectF( XA1, YA1, XA2-XA1, YA2-YA1 );
+       d->secondDataRect = QRectF( XA1, YA1, XA2-XA1, YA2-YA1 );
 
-       axis(RightAxis)->setTickMarks( SecondDataRect.y(), SecondDataRect.height() );
-       axis(TopAxis)->setTickMarks( SecondDataRect.x(), SecondDataRect.width() );
+       axis(RightAxis)->setTickMarks( d->secondDataRect.y(), d->secondDataRect.height() );
+       axis(TopAxis)->setTickMarks( d->secondDataRect.x(), d->secondDataRect.width() );
 
        update();
 }
 
 void KPlotWidget::clearSecondaryLimits() {
-       SecondDataRect = QRectF();
-       axis(RightAxis)->setTickMarks( DataRect.y(), DataRect.height() );
-       axis(TopAxis)->setTickMarks( DataRect.x(), DataRect.width() );
+       d->secondDataRect = QRectF();
+       axis(RightAxis)->setTickMarks( d->dataRect.y(), d->dataRect.height() );
+       axis(TopAxis)->setTickMarks( d->dataRect.x(), d->dataRect.width() );
 
        update();
 }
 
+QRectF KPlotWidget::dataRect() const
+{
+    return d->dataRect;
+}
+
+QRectF KPlotWidget::secondaryDataRect() const
+{
+    return d->secondDataRect;
+}
+
 void KPlotWidget::addPlotObject( KPlotObject *object )
 {
     // skip null pointers
@@ -356,8 +368,8 @@ void KPlotWidget::setPixRect() {
 }
 
 QPointF KPlotWidget::toScreen( const QPointF& p ) const {
-       float px = PixRect.left() + PixRect.width()*( p.x() -  DataRect.x() )/DataRect.width();
-       float py = PixRect.top() + PixRect.height()*( DataRect.y() + DataRect.height() - p.y() )/DataRect.height();
+       float px = PixRect.left() + PixRect.width()*( p.x() -  d->dataRect.x() )/d->dataRect.width();
+       float py = PixRect.top() + PixRect.height()*( d->dataRect.y() + d->dataRect.height() - p.y() )/d->dataRect.height();
        return QPointF( px, py );
 }
 
@@ -532,12 +544,12 @@ void KPlotWidget::drawAxes( QPainter *p ) {
                //Grid lines are placed at locations of primary axes' major tickmarks
                //vertical grid lines
                foreach ( double xx, axis(BottomAxis)->majorTickMarks() ) {
-                       double px = PixRect.width() * (xx - x()) / dataWidth();
+                       double px = PixRect.width() * (xx - d->dataRect.x()) / d->dataRect.width();
                        p->drawLine( QPointF( px, 0.0 ), QPointF( px, double(PixRect.height()) ) );
                }
                //horizontal grid lines
                foreach( double yy, axis(LeftAxis)->majorTickMarks() ) {
-                       double py = PixRect.height() * (yy - y()) / dataHeight();
+                       double py = PixRect.height() * (yy - d->dataRect.y()) / d->dataRect.height();
                        p->drawLine( QPointF( 0.0, py ), QPointF( double(PixRect.width()), py ) );
                }
        }
@@ -559,7 +571,7 @@ void KPlotWidget::drawAxes( QPainter *p ) {
 
                // Draw major tickmarks
                foreach( double xx, a->majorTickMarks() ) {
-                       double px = PixRect.width() * (xx - x()) / dataWidth();
+                       double px = PixRect.width() * (xx - d->dataRect.x()) / d->dataRect.width();
                        if ( px > 0 && px < PixRect.width() ) {
                                p->drawLine( QPointF( px, double(PixRect.height() - TICKOFFSET)), 
                                                QPointF( px, double(PixRect.height() - BIGTICKSIZE - TICKOFFSET)) );
@@ -574,7 +586,7 @@ void KPlotWidget::drawAxes( QPainter *p ) {
 
                // Draw minor tickmarks
                foreach ( double xx, a->minorTickMarks() ) {
-                       double px = PixRect.width() * (xx - x()) / dataWidth();
+                       double px = PixRect.width() * (xx - d->dataRect.x()) / d->dataRect.width();
                        if ( px > 0 && px < PixRect.width() ) {
                                p->drawLine( QPointF( px, double(PixRect.height() - TICKOFFSET)), 
                                                QPointF( px, double(PixRect.height() - SMALLTICKSIZE -TICKOFFSET)) );
@@ -596,7 +608,7 @@ void KPlotWidget::drawAxes( QPainter *p ) {
 
                // Draw major tickmarks
                foreach( double yy, a->majorTickMarks() ) {
-                       double py = PixRect.height() * ( 1.0 - (yy - y()) / dataHeight() );
+                       double py = PixRect.height() * ( 1.0 - (yy - d->dataRect.y()) / d->dataRect.height() );
                        if ( py > 0 && py < PixRect.height() ) {
                                p->drawLine( QPointF( TICKOFFSET, py ), QPointF( double(TICKOFFSET + BIGTICKSIZE), py ) );
 
@@ -610,7 +622,7 @@ void KPlotWidget::drawAxes( QPainter *p ) {
 
                // Draw minor tickmarks
                foreach ( double yy, a->minorTickMarks() ) {
-                       double py = PixRect.height() * ( 1.0 - (yy - y()) / dataHeight() );
+                       double py = PixRect.height() * ( 1.0 - (yy - d->dataRect.y()) / d->dataRect.height() );
                        if ( py > 0 && py < PixRect.height() ) {
                                p->drawLine( QPointF( TICKOFFSET, py ), QPointF( double(TICKOFFSET + SMALLTICKSIZE), py ) );
                        }
@@ -633,10 +645,10 @@ void KPlotWidget::drawAxes( QPainter *p ) {
        }  //End of LeftAxis
 
        //Prepare for top and right axes; we may need the secondary data rect
-       double x0 = x();
-       double y0 = y();
-       double dw = dataWidth();
-       double dh = dataHeight();
+       double x0 = d->dataRect.x();
+       double y0 = d->dataRect.y();
+       double dw = d->dataRect.width();
+       double dh = d->dataRect.height();
        if ( secondaryDataRect().isValid() ) {
                x0 = secondaryDataRect().x();
                y0 = secondaryDataRect().y();
index 3af774edb95ed8ff8c8ce91a5895d6077a9030e0..452254bc93940886c3702b4bf20908a64dc72ec3 100644 (file)
@@ -141,37 +141,14 @@ public:
         */
        virtual void clearSecondaryLimits();
 
-       /**
-        * @return the minimum X value in data units
-        */
-       virtual double x() const { return DataRect.x(); }
-
-       /**
-        * @return the maximum X value in data units
-        */
-       virtual double x2() const { return DataRect.x() + DataRect.width(); }
-
-       /**
-        * @return the minimum Y value in data units
-        */
-       virtual double y() const { return DataRect.y(); }
-
-       /**
-        * @return the maximum Y value in data units
-        */
-       virtual double y2() const { return DataRect.y() + DataRect.height(); }
-
-       /**
-        * @return the width in data units
-        */
-       virtual double dataWidth() const { return DataRect.width(); }
-
-       /**
-        * @return the height in data units
-        */
-       virtual double dataHeight() const { return DataRect.height(); }
+        /**
+         * Return the rect in natural limits representing the shown data.
+         * @warning the coordinate system of QRectF and the human one are not the same!
+         * Though, the height of the rect is really the height of the data rect.
+         */
+        QRectF dataRect() const;
 
-       const QRectF& secondaryDataRect() const { return SecondDataRect; }
+        QRectF secondaryDataRect() const;
 
         /**
          * Add an item to the list of KPlotObjects to be plotted.
@@ -450,10 +427,6 @@ protected:
         * Limits of the plot area in pixel units
         */
        QRect PixRect;
-       /**
-        * Limits of the plot area in data units
-        */
-       QRectF DataRect, SecondDataRect;
 
        //Grid of bools to mask "used" regions of the plot
        float PlotMask[100][100];