- add plotObjects() to get the list of the plot objects (thus removing objectCount() )
- add addPlotObjects() to add more objects with a single update
- add 'Plot' in the name of the other functions that work with the plot objects
- finally hide the real object list in the Private class
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=634293
Private()
{
+ qDeleteAll( objectList );
qDeleteAll( axes );
}
int leftPadding, rightPadding, topPadding, bottomPadding;
// hashmap with the axes we have
QHash<Axis, KPlotAxis*> axes;
+ // List of KPlotObjects
+ QList<KPlotObject*> objectList;
};
KPlotWidget::KPlotWidget( QWidget *parent, double x1, double x2, double y1, double y2 )
KPlotWidget::~KPlotWidget()
{
- qDeleteAll( ObjectList );
- ObjectList.clear();
-
delete d;
}
update();
}
-void KPlotWidget::addObject( KPlotObject *o ) {
+void KPlotWidget::addPlotObject( KPlotObject *o ) {
// skip null pointers
if ( !o ) return;
- ObjectList.append( o );
+ d->objectList.append( o );
update();
}
-void KPlotWidget::clearObjectList() {
- qDeleteAll( ObjectList );
- ObjectList.clear();
- update();
+void KPlotWidget::addPlotObjects( const QList< KPlotObject* >& objects )
+{
+ bool addedsome = false;
+ foreach ( KPlotObject *o, objects )
+ {
+ if ( !o )
+ continue;
+
+ d->objectList.append( o );
+ addedsome = true;
+ }
+ if ( addedsome )
+ update();
+}
+
+QList< KPlotObject* > KPlotWidget::plotObjects() const
+{
+ return d->objectList;
+}
+
+void KPlotWidget::removeAllPlotObjects()
+{
+ if ( d->objectList.isEmpty() )
+ return;
+
+ qDeleteAll( d->objectList );
+ d->objectList.clear();
+ update();
}
void KPlotWidget::resetPlotMask() {
}
void KPlotWidget::resetPlot() {
- clearObjectList();
+ qDeleteAll( d->objectList );
+ d->objectList.clear();
clearSecondaryLimits();
setLimits(0.0, 1.0, 0.0, 1.0);
axis(KPlotWidget::RightAxis)->setShowTickLabels( false );
resetPlotMask();
}
-void KPlotWidget::replaceObject( int i, KPlotObject *o ) {
+void KPlotWidget::replacePlotObject( int i, KPlotObject *o ) {
// skip null pointers
if ( !o ) return;
- ObjectList.replace( i, o );
+ d->objectList.replace( i, o );
update();
}
-
-KPlotObject *KPlotWidget::object( int i ) {
- if ( i < 0 || i >= ObjectList.count() ) {
- kWarning() << "KPlotWidget::object(): index " << i << " out of range!" << endl;
- return 0;
- }
- return ObjectList.at(i);
-}
-
QColor KPlotWidget::backgroundColor() const
{
return d->cBackground;
QList<KPlotPoint*> KPlotWidget::pointsUnderPoint( const QPoint& p ) const {
QList<KPlotPoint*> pts;
- foreach ( KPlotObject *po, ObjectList ) {
+ foreach ( KPlotObject *po, d->objectList ) {
foreach ( KPlotPoint *pp, po->points() ) {
if ( ( p - toScreen( pp->position() ).toPoint() ).manhattanLength() <= 4 )
pts << pp;
resetPlotMask();
- foreach( KPlotObject *po, ObjectList )
+ foreach( KPlotObject *po, d->objectList )
po->draw( &p, this );
//DEBUG_MASK
* Add an item to the list of KPlotObjects to be plotted.
* @param o pointer to the KPlotObject to be added
*/
- void addObject( KPlotObject *o );
+ void addPlotObject( KPlotObject *o );
+
+ /**
+ * Add more than one KPlotObject at one time.
+ * @param objects the KPlotObject's to be added
+ */
+ void addPlotObjects( const QList< KPlotObject* >& objects );
+
+ /**
+ * @return the list of the current objects
+ */
+ QList< KPlotObject* > plotObjects() const;
/**
* Remove and delete all items from the list of KPlotObjects
*/
- void clearObjectList();
+ void removeAllPlotObjects();
/**
* Reset the PlotMask so that all regions are empty
* @param i the index of th item to be replaced
* @param o pointer to the replacement KPlotObject
*/
- void replaceObject( int i, KPlotObject *o );
-
- /**
- * @return the number of KPlotObjects in the list
- */
- int objectCount() const { return ObjectList.size(); }
-
- /**
- * @return a pointer to a specific KPlotObject in the list
- * @param i the index of the desired KPlotObject
- */
- KPlotObject *object( int i );
+ void replacePlotObject( int i, KPlotObject *o );
/**
* @return the background color of the plot
* Limits of the plot area in data units
*/
QRectF DataRect, SecondDataRect;
- /**
- * List of KPlotObjects
- */
- QList<KPlotObject*> ObjectList;
//Grid of bools to mask "used" regions of the plot
float PlotMask[100][100];
po2->addPoint( x, 50.0 - 5.0*x );
}
- plot->addObject( po1 );
- plot->addObject( po2 );
+ plot->addPlotObject( po1 );
+ plot->addPlotObject( po2 );
plot->update();
break;
po2->addPoint( t, cos(t) );
}
- plot->addObject( po1 );
- plot->addObject( po2 );
+ plot->addPlotObject( po1 );
+ plot->addPlotObject( po2 );
plot->update();
break;
po1->addPoint( x, 100*exp( -0.5*x*x ), "", 0.5 );
}
- plot->addObject( po1 );
+ plot->addPlotObject( po1 );
plot->update();
break;
po1->addPoint( -0.8, 0.0, i18n("West") );
po1->addPoint( -0.57, 0.57, i18n("Northwest") );
- plot->addObject( po1 );
+ plot->addPlotObject( po1 );
plot->update();
break;
po1->addPoint( 1.25, 1.5 );
po1->addPoint( 1.75, 1.75 );
- plot->addObject( po1 );
+ plot->addPlotObject( po1 );
update();
break;
po1->addPoint( 1.25, 1.5, "G" );
po1->addPoint( 1.75, 1.75, "H" );
- plot->addObject( po1 );
+ plot->addPlotObject( po1 );
update();
break;