]> Git trees. - libqmvoc.git/commitdiff
Get rid of DPoint and DRect, as Qt4 provides QPointF and QRectF that already do
authorPino Toscano <pino@kde.org>
Mon, 31 Oct 2005 09:42:29 +0000 (09:42 +0000)
committerPino Toscano <pino@kde.org>
Mon, 31 Oct 2005 09:42:29 +0000 (09:42 +0000)
the job.

CCMAIL: Jason Harris <kstars@30doradus.org>

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

kdeeduplot/README
kdeeduplot/kplotobject.h
kdeeduplot/kplotwidget.cpp
kdeeduplot/kplotwidget.h

index ab695f9a7db4c30fbe4dc40e34f7879cfe992f95..6210c3b914b9ce82c43a2340ac70789aa54e5cd7 100644 (file)
@@ -14,9 +14,8 @@ then calling updateTickmarks() to recompute the positions of tickmarks
 and ticklabels.
 
 Data to be plotted are stored using the KPlotObject class.  KPlotObject
-consists of a QPtrList of DPoints, each specifying the X,Y coordinates
-of a data point (DPoint is like QPoint, but the X and Y values are doubles 
-instead of ints).  KPlotObject also specifies the "type" of data to be 
+consists of a QList of QPointF's, each specifying the X,Y coordinates
+of a data point.  KPlotObject also specifies the "type" of data to be 
 plotted (POINTS or CURVE or POLYGON or LABEL).
 
 Jason Harris
index 0f78d6eb6c5cccdf04b31ea68ea6670c663427cd..ae76bf96474f1548508f509377f6939bf1666c79 100644 (file)
 #ifndef KPLOTOBJECT_H
 #define KPLOTOBJECT_H
 
-class QString;
 class QPainter;
 
-#include <kdemacros.h>
-
-/**
- * @class DRect
- * @short Equivalent of QRect with double x,y coordinates
- * @author Jason Harris
- * @version 1.0
- */
-class KDE_EXPORT DRect {
-public:
-       DRect() { DRect( 0.0, 0.0, 1.0, 1.0 ); }
-       DRect( double x, double y, double w, double h ) { X = x; Y = y; W = w; H = h; }
-       ~DRect() {}
-
-       double x() const { return X; }
-       double y() const { return Y; }
-       double x2() const { return X + W; }
-       double y2() const { return Y + H; }
-       double width() const { return W; }
-       double height() const { return H; }
-
-       void setX( double x ) { X = x; }
-       void setY( double y ) { Y = y; }
-       void setWidth( double w ) { W = w; }
-       void setHeight( double h ) { H = h; }
-
-private:
-       double X,Y,W,H;
-};
-
-/**
- * @class DPoint
- * @short equivalent of QPoint with double x,y coordinates
- * @author Jason Harris
- * @version 1.0
- */
-class KDE_EXPORT DPoint {
-public:
-       DPoint() { DPoint( 0.0, 0.0 ); }
-       DPoint( double x, double y ) { setX( x ); setY( y ); }
-       ~DPoint() {}
-
-       double x() const { return X; }
-       double y() const { return Y; }
+#include <QPointF>
+#include <QRectF>
+#include <QString>
 
-       QPoint qpoint( const QRect& pb, const DRect& db ) {
-               int px = pb.left() + int( pb.width()*( x() -  db.x() )/db.width() );
-               int py = pb.top() + int( pb.height()*( db.y2() - y() )/db.height() );
-               return QPoint( px, py );
-       }
-
-       void setX( double x ) { X = x; }
-       void setY( double y ) { Y = y; }
-
-private:
-       double X, Y;
-};
+#include <kdemacros.h>
 
 /**
  * @class KPlotObject
@@ -183,25 +130,25 @@ public:
        void setParam( unsigned int p ) { Parameter = p; }
 
        /**
-        * @return a pointer to the DPoint at position i
+        * @return a pointer to the QPointF at position i
         * @param i the index of the desired point.
         */
-       DPoint* point( unsigned int i ) { return pList.at(i); }
+       QPointF* point( unsigned int i ) { return pList.at(i); }
 
-       QList<DPoint*> *points() { return &pList; }
+       QList<QPointF*> *points() { return &pList; }
 
        /**
         * Add a point to the object's list.
-        * @param p the DPoint to add.
+        * @param p the QPointF to add.
         */
-       void addPoint( const DPoint &p ) { pList.append( new DPoint( p.x(), p.y() ) ); }
+       void addPoint( const QPointF &p ) { pList.append( new QPointF( p.x(), p.y() ) ); }
 
        /**
         * Add a point to the object's list.
         * @overload
-        * @param p pointer to the DPoint to add.
+        * @param p pointer to the QPointF to add.
         */
-       void addPoint( DPoint *p ) { pList.append( p ); }
+       void addPoint( QPointF *p ) { pList.append( p ); }
 
        /**
         * Remove the QPoint at position index from the list of points
@@ -220,7 +167,7 @@ public:
        void clearPoints() { pList.clear(); }
 
 private:
-       QList<DPoint*> pList;
+       QList<QPointF*> pList;
        PTYPE Type;
        unsigned int Size, Parameter;
        QString Color, Name;
index 6a88767d98722962af67bbe277dbcb88765d7a81..bafc0028e42f8cec00e562183781420f58c47548 100644 (file)
@@ -62,7 +62,7 @@ void KPlotWidget::setLimits( double x1, double x2, double y1, double y2 ) {
        if ( y2<y1) { YA1=y2; YA2=y1; }
        else { YA1=y1; YA2=y2; }
 
-       DataRect = DRect( XA1, YA1, XA2-XA1, YA2-YA1 );
+       DataRect = QRectF( XA1, YA1, XA2-XA1, YA2-YA1 );
        updateTickmarks();
 }
 
@@ -166,9 +166,9 @@ void KPlotWidget::drawObjects( QPainter *p ) {
                                {
                                        p->setBrush( QColor( po->color() ) );
 
-                                       for ( QList<DPoint*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit )
+                                       for ( QList<QPointF*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit )
                                        {
-                                               QPoint q = ( *dpit )->qpoint( PixRect, DataRect );
+                                               QPoint q = mapToPoint( **dpit );
                                                int x1 = q.x() - po->size()/2;
                                                int y1 = q.y() - po->size()/2;
 
@@ -188,15 +188,15 @@ void KPlotWidget::drawObjects( QPainter *p ) {
                                {
                                        p->setPen( QPen( QColor( po->color() ), po->size(), (Qt::PenStyle)po->param() ) );
                                        QPolygon poly;
-                                       for ( QList<DPoint*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit )
-                                               poly << ( *dpit )->qpoint( PixRect, DataRect );
+                                       for ( QList<QPointF*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit )
+                                               poly << mapToPoint( **dpit );
                                        p->drawPolyline( poly );
                                        break;
                                }
 
                                case KPlotObject::LABEL : //draw label centered at point in x, and slightly below point in y.
                                {
-                                       QPoint q = po->points()->first()->qpoint( PixRect, DataRect );
+                                       QPoint q = mapToPoint( *(po->points()->first()) );
                                        p->drawText( q.x()-20, q.y()+6, 40, 10, Qt::AlignCenter | Qt::TextDontClip, po->name() );
                                        break;
                                }
@@ -210,8 +210,8 @@ void KPlotWidget::drawObjects( QPainter *p ) {
                                        QPolygon a( po->count() );
 
                                        unsigned int i=0;
-                                       for ( QList<DPoint*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit )
-                                               a.setPoint( i++, ( *dpit )->qpoint( PixRect, DataRect ) );
+                                       for ( QList<QPointF*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit )
+                                               a.setPoint( i++, mapToPoint( **dpit ) );
 
                                        p->drawPolygon( a );
                                        break;
index 4217bd49a94e3ee1305f8b8c8c43782820478611..e1dc32c761fa195774f9f8b2890a2785603300ab 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef _KPLOTWIDGET_H_
 #define _KPLOTWIDGET_H_
 
+#include <qcolor.h>
+#include <qrect.h>
 #include <qwidget.h>
 #include <qlist.h>
 #include "kplotobject.h"
@@ -28,7 +30,6 @@
 #define XPADDING 20
 #define YPADDING 20
 
-class QColor;
 class QPixmap;
 
 /**
@@ -86,7 +87,7 @@ public:
        /**
         * @return the maximum X value in data units
         */
-       virtual double x2() const { return DataRect.x2(); }
+       virtual double x2() const { return DataRect.x() + DataRect.width(); }
 
        /**
         * @return the minimum Y value in data units
@@ -96,7 +97,7 @@ public:
        /**
         * @return the maximum Y value in data units
         */
-       virtual double y2() const { return DataRect.y2(); }
+       virtual double y2() const { return DataRect.y() + DataRect.height(); }
 
        /**
         * @return the width in data units
@@ -260,6 +261,12 @@ public:
         */
        virtual void setDefaultPadding() { LeftPadding = -1; RightPadding = -1; TopPadding = -1; BottomPadding = -1; }
 
+       QPoint mapToPoint( const QPointF& p ) {
+               int px = PixRect.left() + int( PixRect.width()*( p.x() -  DataRect.x() )/DataRect.width() );
+               int py = PixRect.top() + int( PixRect.height()*( DataRect.y() + DataRect.height() - p.y() )/DataRect.height() );
+               return QPoint( px, py );
+       }
+
        /**
         * The bottom X axis.
         */
@@ -314,7 +321,7 @@ protected:
        //Limits of the plot area in pixel units
        QRect PixRect;
        //Limits of the plot area in data units
-       DRect DataRect;
+       QRectF DataRect;
        /**
         * List of KPlotObjects
         */