[kde-edu]: KDE/kdeedu/libkdeedu/kdeeduplot

Jason Harris kstars at 30doradus.org
Wed Oct 25 03:17:27 CEST 2006


SVN commit 598923 by harris:

Convert plotting data to floating-point variants (QPoint-->QPointF, 
QPolygon-->QPolygonF, etc).  Moved mapToPoint() definition from 
kplotwidget.h to kplotwidget.cpp.

CCMAIL: kde-edu at kde.org



 M  +14 -7     kplotwidget.cpp  
 M  +1 -5      kplotwidget.h  


--- trunk/KDE/kdeedu/libkdeedu/kdeeduplot/kplotwidget.cpp #598922:598923
@@ -190,7 +190,7 @@
 			continue;
 
 		for ( QList<QPointF*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit ) {
-			if ( ( p - mapToPoint( **dpit ) ).manhattanLength() <= 4 )
+			if ( ( p - mapToPoint( **dpit ).toPoint() ).manhattanLength() <= 4 )
 				pts << po;
 		}
 	}
@@ -226,6 +226,12 @@
 	PixRect = QRect( 0, 0, newWidth, newHeight );
 }
 
+QPointF KPlotWidget::mapToPoint( 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();
+	return QPointF( px, py );
+}
+
 void KPlotWidget::paintEvent( QPaintEvent *e ) {
 	// let QFrame draw its default stuff (like the frame)
 	QFrame::paintEvent( e );
@@ -260,9 +266,9 @@
 
 					for ( QList<QPointF*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit )
 					{
-						QPoint q = mapToPoint( **dpit );
-						int x1 = q.x() - po->size()/2;
-						int y1 = q.y() - po->size()/2;
+						QPointF q = mapToPoint( **dpit );
+						float x1 = q.x() - 0.5*po->size();
+						float y1 = q.y() - 0.5*po->size();
 
 						switch( po->param() ) {
 							case KPlotObject::CIRCLE : p->drawEllipse( x1, y1, po->size(), po->size() ); break;
@@ -279,16 +285,17 @@
 				case KPlotObject::CURVE :
 				{
 					p->setPen( QPen( po->color(), po->size(), (Qt::PenStyle)po->param() ) );
-					QPolygon poly;
+					QPolygonF poly;
 					for ( QList<QPointF*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit )
 						poly << mapToPoint( **dpit );
 					p->drawPolyline( poly );
 					break;
 				}
 
+				//FIXME: implement non-overlapping labels
 				case KPlotObject::LABEL : //draw label centered at point in x, and slightly below point in y.
 				{
-					QPoint q = mapToPoint( *(po->points()->first()) );
+					QPointF q = mapToPoint( *(po->points()->first()) );
 					p->drawText( q.x()-20, q.y()+6, 40, 10, Qt::AlignCenter | Qt::TextDontClip, po->name() );
 					break;
 				}
@@ -298,7 +305,7 @@
 					p->setPen( QPen( po->color(), po->size(), (Qt::PenStyle)po->param() ) );
 					p->setBrush( po->color() );
 
-					QPolygon a( po->count() );
+					QPolygonF a( po->count() );
 
 					for ( QList<QPointF*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit )
 						a << mapToPoint( **dpit );
--- trunk/KDE/kdeedu/libkdeedu/kdeeduplot/kplotwidget.h #598922:598923
@@ -292,11 +292,7 @@
 	 * Used mainly when drawing.
 	 * @return the coordinate in the pixel coordinate system
 	 */
-	QPoint mapToPoint( const QPointF& p ) const {
-		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 );
-	}
+	QPointF mapToPoint( const QPointF& p ) const;
 
 	/**
 	 * Retrieve the pointer to the axis of type @p a.


More information about the kde-edu mailing list