[Kstars-devel] KDE/kdeedu/kstars/kstars/skycomponents
Jason Harris
kstars at 30doradus.org
Sat Dec 31 04:25:39 CET 2005
SVN commit 492772 by harris:
Add first() and next() functions to Composite and Component base
classes, so we can now loop over all SkyObjects like this:
for ( SkyObject *o = data()->skyComposite()->first(); o; o =
data()->skyComposite()->next() ) {
//do stuff
}
So, next() will return 0 when it has finished looping over all objects.
CCMAIL: kstars-devel at kde.org
M +14 -1 listcomponent.cpp
M +4 -1 listcomponent.h
M +8 -0 singlecomponent.cpp
M +3 -0 singlecomponent.h
M +3 -0 skycomponent.h
M +18 -1 skycomposite.cpp
M +4 -0 skycomposite.h
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/listcomponent.cpp #492771:492772
@@ -24,7 +24,7 @@
#include "skyobject.h"
ListComponent::ListComponent( SkyComponent *parent, bool (*visibleMethod)() )
-: SkyComponent( parent, visibleMethod )
+: SkyComponent( parent, visibleMethod ), m_CurrentIndex(0)
{
}
@@ -77,3 +77,16 @@
return oBest;
}
+
+SkyObject* ListComponent::first() {
+ m_CurrentIndex = 0;
+ return ObjectList[m_CurrentIndex];
+}
+
+SkyObject* ListComponent::next() {
+ m_CurrentIndex++;
+ if ( m_CurrentIndex >= ObjectList.size() )
+ return 0;
+ else
+ return ObjectList[m_CurrentIndex];
+}
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/listcomponent.h #492771:492772
@@ -70,9 +70,11 @@
virtual void update( KStarsData *data, KSNumbers *num=0 );
virtual SkyObject* findByName( const QString &name );
-
virtual SkyObject* objectNearest( SkyPoint *p, double &maxrad );
+ virtual SkyObject* first();
+ virtual SkyObject* next();
+
QList<SkyObject*>& objectList() { return ObjectList; }
void clear();
@@ -80,6 +82,7 @@
private:
SkyComposite *Parent;
QList<SkyObject*> ObjectList;
+ int m_CurrentIndex;
};
#endif
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/singlecomponent.cpp #492771:492772
@@ -67,3 +67,11 @@
return 0;
}
+
+SkyObject* SingleComponent::first() {
+ return skyObject();
+}
+
+SkyObject* SingleComponent::next() {
+ return 0;
+}
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/singlecomponent.h #492771:492772
@@ -75,6 +75,9 @@
virtual SkyObject* objectNearest( SkyPoint *p, double &maxrad );
+ virtual SkyObject* first();
+ virtual SkyObject* next();
+
SkyObject* skyObject() { return m_StoredObject; }
void setStoredObject( SkyObject *o ) { m_StoredObject = o; }
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skycomponent.h #492771:492772
@@ -148,6 +148,9 @@
virtual void clearTrailsExcept( SkyObject *o );
virtual void drawTrails( KStars *, QPainter &, double );
+ virtual SkyObject* first() { return 0; }
+ virtual SkyObject* next() { return 0; }
+
/**
*@short Search the children of this SkyComponent for
*a SkyObject whose name matches the argument
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skycomposite.cpp #492771:492772
@@ -22,7 +22,7 @@
#include "skyobject.h"
SkyComposite::SkyComposite(SkyComponent *parent )
-: SkyComponent( parent )
+: SkyComponent( parent ), m_CurrentIndex(0)
{
}
@@ -92,3 +92,20 @@
return oBest; //will be 0 if no object nearer than maxrad was found
}
+
+SkyObject* SkyComposite::first() {
+ m_CurrentIndex = 0;
+ return m_Components[m_CurrentIndex]->first();
+}
+
+SkyObject* SkyComposite::next() {
+ SkyObject *result = m_Components[m_CurrentIndex]->next();
+
+ if ( !result ) {
+ m_CurrentIndex++;
+ if ( m_CurrentIndex >= m_Components.size() ) return 0;
+ return m_Components[m_CurrentIndex]->first();
+ }
+
+ return result;
+}
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skycomposite.h #492771:492772
@@ -154,6 +154,9 @@
virtual bool hasTrail( SkyObject *o, bool &found );
virtual bool removeTrail( SkyObject *o );
+ virtual SkyObject* first();
+ virtual SkyObject* next();
+
/**
*@short Search the children of this SkyComposite for
*a SkyObject whose name matches the argument.
@@ -179,6 +182,7 @@
private:
QList<SkyComponent*> m_Components;
+ int m_CurrentIndex;
};
#endif
More information about the Kstars-devel
mailing list