]> Git trees. - libqmvoc.git/commitdiff
API change:
authorPino Toscano <pino@kde.org>
Fri, 16 Feb 2007 23:42:02 +0000 (23:42 +0000)
committerPino Toscano <pino@kde.org>
Fri, 16 Feb 2007 23:42:02 +0000 (23:42 +0000)
move the variables for the mask stuff and rectCost() into the Private class

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

kdeeduplot/kplotwidget.cpp
kdeeduplot/kplotwidget.h

index fcfcb159abe467c385cfa6971f1ed2a0f3e87215..a8c957c2bd8e09e591dc0f4a2d2865a2f19fcc86 100644 (file)
@@ -68,6 +68,16 @@ class KPlotWidget::Private
 
         KPlotWidget *q;
 
+        /**
+         * @return a value indicating how well the given rectangle is 
+         * avoiding masked regions in the plot.  A higher returned value 
+         * indicates that the rectangle is intersecting a larger portion 
+         * of the masked region, or a portion of the masked region which 
+         * is weighted higher.
+         * @param r The rectangle to be tested
+         */
+        float rectCost( const QRectF &r ) const;
+
         //Colors
         QColor cBackground, cForeground, cGrid;
         //draw options
@@ -80,6 +90,9 @@ class KPlotWidget::Private
         QList<KPlotObject*> objectList;
         // 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];
+        double px[100], py[100];
 };
 
 KPlotWidget::KPlotWidget( QWidget * parent )
@@ -222,7 +235,7 @@ void KPlotWidget::removeAllPlotObjects()
 void KPlotWidget::resetPlotMask() {
        for (int ix=0; ix<100; ++ix ) 
                for ( int iy=0; iy<100; ++iy ) 
-                       PlotMask[ix][iy] = 0.0;
+                       d->plotMask[ix][iy] = 0.0;
 }
                
 void KPlotWidget::resetPlot() {
@@ -362,8 +375,8 @@ void KPlotWidget::setPixRect() {
        // PixRect starts at (0,0) because we will translate by leftPadding(), topPadding()
        PixRect = QRect( 0, 0, newWidth, newHeight );
        for ( int i=0; i<100; ++i ) {
-               px[i] = double(i*PixRect.width())/100.0 + double(PixRect.x());
-               py[i] = double(i*PixRect.height())/100.0 + double(PixRect.y());
+               d->px[i] = double(i*PixRect.width())/100.0 + double(PixRect.x());
+               d->py[i] = double(i*PixRect.height())/100.0 + double(PixRect.y());
        }
 }
 
@@ -386,7 +399,7 @@ void KPlotWidget::maskRect( const QRectF& r, float value ) {
 
        for ( int ix=ix1; ix<ix2; ++ix ) 
                for ( int iy=iy1; iy<iy2; ++iy ) 
-                       PlotMask[ix][iy] += value;
+                       d->plotMask[ix][iy] += value;
 }
 
 void KPlotWidget::maskAlongLine( const QPointF &p1, const QPointF &p2, float value ) {
@@ -408,7 +421,7 @@ void KPlotWidget::maskAlongLine( const QPointF &p1, const QPointF &p2, float val
                int iy = int( 100.0*( y - PixRect.y() )/PixRect.height() );
 
                if ( ix >= 0 && ix < 100 && iy >= 0 && iy < 100 )
-               PlotMask[ix][iy] += value;
+               d->plotMask[ix][iy] += value;
 
        }
 }
@@ -426,12 +439,12 @@ void KPlotWidget::placeLabel( QPainter *painter, KPlotPoint *pp ) {
        for ( int ix=ix0-20; ix<ix0+20; ix++ ) {
                for ( int iy=iy0-20; iy<iy0+20; iy++ ) {
                        if ( ( ix >= 0 && ix < 100 ) && ( iy >= 0 && iy < 100 ) ) {
-                               QRectF labelRect = painter->boundingRect( QRectF( px[ix], py[iy], 1, 1 ), textFlags, pp->label() );
+                               QRectF labelRect = painter->boundingRect( QRectF( d->px[ix], d->py[iy], 1, 1 ), textFlags, pp->label() );
                                //Add some padding to labelRect
                                labelRect.adjust( -2, -2, 2, 2 );
 
                                float r = sqrt( (ix-ix0)*(ix-ix0) + (iy-iy0)*(iy-iy0) );
-                               float cost = rectCost( labelRect ) + 0.1*r;
+                               float cost = d->rectCost( labelRect ) + 0.1*r;
 
                                if ( cost < bestCost ) {
                                        bestRect = labelRect;
@@ -476,17 +489,18 @@ void KPlotWidget::placeLabel( QPainter *painter, KPlotPoint *pp ) {
        }
 }
 
-float KPlotWidget::rectCost ( const QRectF &r ) {
-       int ix1= int( 100.0*( r.x() - PixRect.x() )/PixRect.width() );
-       int ix2= int( 100.0*( r.right() - PixRect.x() )/PixRect.width() );
-       int iy1= int( 100.0*( r.y() - PixRect.y() )/PixRect.height() );
-       int iy2= int( 100.0*( r.bottom() - PixRect.y() )/PixRect.height() );
+float KPlotWidget::Private::rectCost( const QRectF &r ) const
+{
+    int ix1 = int( 100.0 * ( r.x() - q->PixRect.x() ) / q->PixRect.width() );
+    int ix2 = int( 100.0 * ( r.right() - q->PixRect.x() ) / q->PixRect.width() );
+    int iy1 = int( 100.0 * ( r.y() - q->PixRect.y() ) / q->PixRect.height() );
+    int iy2 = int( 100.0 * ( r.bottom() - q->PixRect.y() ) / q->PixRect.height() );
        float cost = 0.0;
 
        for ( int ix=ix1; ix<ix2; ++ix ) {
                for ( int iy=iy1; iy<iy2; ++iy ) {
                        if ( ix >= 0 && ix < 100 && iy >= 0 && iy < 100 ) {
-                               cost += PlotMask[ix][iy];
+                               cost += plotMask[ix][iy];
                        } else {
                                cost += 100.;
                        }
index 452254bc93940886c3702b4bf20908a64dc72ec3..3f1f2faa0515b88b773e454518be3ba561c828d8 100644 (file)
@@ -413,24 +413,10 @@ protected:
         */
        QList<KPlotPoint*> pointsUnderPoint( const QPoint& p ) const;
 
-       /**
-        * @return a value indicating how well the given rectangle is 
-        * avoiding masked regions in the plot.  A higher returned value 
-        * indicates that the rectangle is intersecting a larger portion 
-        * of the masked region, or a portion of the masked region which 
-        * is weighted higher.
-        * @param r The rectangle to be tested
-        */
-       float rectCost( const QRectF &r );
-
        /**
         * Limits of the plot area in pixel units
         */
        QRect PixRect;
-
-       //Grid of bools to mask "used" regions of the plot
-       float PlotMask[100][100];
-       double px[100], py[100];
 };
 
 #endif