the job.
CCMAIL: Jason Harris <kstars@30doradus.org>
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=476012
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
#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
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
void clearPoints() { pList.clear(); }
private:
- QList<DPoint*> pList;
+ QList<QPointF*> pList;
PTYPE Type;
unsigned int Size, Parameter;
QString Color, Name;
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();
}
{
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;
{
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;
}
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;
#ifndef _KPLOTWIDGET_H_
#define _KPLOTWIDGET_H_
+#include <qcolor.h>
+#include <qrect.h>
#include <qwidget.h>
#include <qlist.h>
#include "kplotobject.h"
#define XPADDING 20
#define YPADDING 20
-class QColor;
class QPixmap;
/**
/**
* @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
/**
* @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
*/
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.
*/
//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
*/