From 9758fe0e0c09e5017c0c48ce2b5745c285eaf893 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Mon, 31 Oct 2005 09:42:29 +0000 Subject: [PATCH] Get rid of DPoint and DRect, as Qt4 provides QPointF and QRectF that already do the job. CCMAIL: Jason Harris svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=476012 --- kdeeduplot/README | 5 +-- kdeeduplot/kplotobject.h | 77 ++++++-------------------------------- kdeeduplot/kplotwidget.cpp | 16 ++++---- kdeeduplot/kplotwidget.h | 15 ++++++-- 4 files changed, 33 insertions(+), 80 deletions(-) diff --git a/kdeeduplot/README b/kdeeduplot/README index ab695f9..6210c3b 100644 --- a/kdeeduplot/README +++ b/kdeeduplot/README @@ -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 diff --git a/kdeeduplot/kplotobject.h b/kdeeduplot/kplotobject.h index 0f78d6e..ae76bf9 100644 --- a/kdeeduplot/kplotobject.h +++ b/kdeeduplot/kplotobject.h @@ -18,66 +18,13 @@ #ifndef KPLOTOBJECT_H #define KPLOTOBJECT_H -class QString; class QPainter; -#include - -/** - * @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 +#include +#include - 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 /** * @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 *points() { return &pList; } + QList *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 pList; + QList pList; PTYPE Type; unsigned int Size, Parameter; QString Color, Name; diff --git a/kdeeduplot/kplotwidget.cpp b/kdeeduplot/kplotwidget.cpp index 6a88767..bafc002 100644 --- a/kdeeduplot/kplotwidget.cpp +++ b/kdeeduplot/kplotwidget.cpp @@ -62,7 +62,7 @@ void KPlotWidget::setLimits( double x1, double x2, double y1, double y2 ) { if ( y2setBrush( QColor( po->color() ) ); - for ( QList::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit ) + for ( QList::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::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit ) - poly << ( *dpit )->qpoint( PixRect, DataRect ); + for ( QList::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::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit ) - a.setPoint( i++, ( *dpit )->qpoint( PixRect, DataRect ) ); + for ( QList::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit ) + a.setPoint( i++, mapToPoint( **dpit ) ); p->drawPolygon( a ); break; diff --git a/kdeeduplot/kplotwidget.h b/kdeeduplot/kplotwidget.h index 4217bd4..e1dc32c 100644 --- a/kdeeduplot/kplotwidget.h +++ b/kdeeduplot/kplotwidget.h @@ -18,6 +18,8 @@ #ifndef _KPLOTWIDGET_H_ #define _KPLOTWIDGET_H_ +#include +#include #include #include #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 */ -- 2.47.3