[Kstars-devel] KDE/kdeedu/kstars/kstars/skycomponents

Jason Harris kstars at 30doradus.org
Sat Sep 17 04:01:49 CEST 2005


SVN commit 461265 by harris:

More fixes in skycomponents.  Added CoordinateGridComposite code.  
Fixed syntax of foreach() in skycomposite.cpp (it uses "," not 
";" to separate arguments).  I hadn't known about this nice function.
Instead of what I had been doing to loop through QLists:

  for ( int i=0; i< spList.size(); ++i ) {
    SkyPoint *p = spList[i];

We can just do:

  foreach ( SkyPoint *p, spList ) {

Very cool.  I will update all of my for-loops to use foreach.

CCMAIL: kstars-devel at kde.org



 M  +14 -0     coordinategridcomposite.cpp  
 M  +0 -3      coordinategridcomposite.h  
 M  +8 -6      milkywaycomponent.cpp  
 M  +6 -6      skycomposite.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/coordinategridcomposite.cpp #461264:461265
@@ -16,3 +16,17 @@
  ***************************************************************************/
 
 #include "coordinategridcomposite.h"
+#include "coordinategridcomponent.h"
+
+CoordinateGridComposite::CoordinateGridComposite( SkyComposite *parent ) 
+  : SkyComposite(parent) 
+{
+  //Parallels
+  for ( double dec=-80.0; dec <= 80.0; dec += 10.0 ) 
+    addComponent( new CoordinatGridComponent( this, true, dec ) );
+  
+  //Meridians
+  for ( double ra=0.0; ra < 12.0; ra += 2.0 ) 
+    addComponent( new CoordinatGridComponent( this, false, ra ) );
+}
+
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/coordinategridcomposite.h #461264:461265
@@ -31,9 +31,6 @@
 {
  public:
   CoordinateGridComposite( SkyComposite* );
-  virtual ~CoordinateGridComposite();
-
-
 };
 
 
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/milkywaycomponent.cpp #461264:461265
@@ -38,7 +38,10 @@
 
 MilkyWayComponent::~MilkyWayComponent()
 {
-	delete pts;
+  for ( int i=0; i<NMWFILES; ++i ) 
+    while ( ! MilkyWay[i].isEmpty() ) delete MilkyWay[i].takeFirst();
+  
+  delete pts;
 }
 
 // was bool KStarsData::readMWData( void )
@@ -92,7 +95,7 @@
 //		for ( unsigned int j=0; j<11; ++j )
 		for ( unsigned int j=0; j<NMWFILES; ++j )
 		{
-			for (SkyPoint *p = MilkyWay[j].first(); p; p=MilkyWay[j].next())
+		  foreach  ( SkyPoint *p, MilkyWay[j] ) {
 			{
 				if (needNewCoords) p->updateCoords( num );
 				p->EquatorialToHorizontal( LST, map->data()->geo()->lat() );
@@ -127,8 +130,7 @@
 			if ( o.x() != -10000000 && o.y() != -10000000 ) pts->setPoint( ptsCount++, o.x(), o.y() );
 			if ( o.x() >= 0 && o.x() <= Width && o.y() >= 0 && o.y() <= Height ) partVisible = true;
 
-			for ( SkyPoint *p = MilkyWay[j].first(); p; p = MilkyWay[j].next())
-			{
+			for ( SkyPoint *p, MilkyWay[j] ) {
 				o = map->getXY( p, Options::useAltAz(), Options::useRefraction(), scale );
 				if ( o.x() != -10000000 && o.y() != -10000000 ) pts->setPoint( ptsCount++, o.x(), o.y() );
 				if ( o.x() >= 0 && o.x() <= Width && o.y() >= 0 && o.y() <= Height ) partVisible = true;
@@ -144,8 +146,8 @@
 
 			psky.moveTo( o.x(), o.y() );
 
-			for ( unsigned int i=1; i<MilkyWay[j].count(); ++i ) {
-				o = map->getXY( MilkyWay[j].at(i), Options::useAltAz(), Options::useRefraction(), scale );
+			for ( SkyPoint *p, MilkyWay[j] ) {
+				o = map->getXY( p, Options::useAltAz(), Options::useRefraction(), scale );
 				if (o.x()==-10000000 && o.y()==-10000000) offscreen = true;
 				else offscreen = false;
 
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skycomposite.cpp #461264:461265
@@ -53,36 +53,36 @@
 
 void SkyComposite::draw(SkyMap *map, QPainter& psky, double scale)
 {
-	foreach (SkyComponent *component; Components)
+  foreach (SkyComponent *component, Components)
 		component->draw(map, psky, scale);
 }
 
 void SkyComposite::drawExportable(SkyMap *map, QPainter& psky, double scale)
 {
-	foreach (SkyComponent *component; Components)
+  foreach (SkyComponent *component, Components)
 		component->drawExportable(map, psky, scale);
 }
 
 void SkyComposite::init(KStarsData *data)
 {
-	foreach (SkyComponent *component; Components)
+  foreach (SkyComponent *component, Components)
 		component->init(data);
 }
 
 void SkyComposite::update(KStarsData *data, KSNumbers *num, bool needNewCoords)
 {
-	foreach (SkyComponent *component; Components)
+  foreach (SkyComponent *component, Components)
 		component->update(data, num, needNewCoords);
 }
 
 void SkyComposite::updatePlanets(KStarsData*, KSNumbers*, bool needNewCoords)
 {
-	foreach (SkyComponent *component; Components)
+  foreach (SkyComponent *component, Components)
 		component->updatePlanets(data, num, needNewCoords);
 }}
 
 void SkyComposite::updateMoons(KStarsData*, KSNumbers*, bool needNewCoords)
 {
-	foreach (SkyComponent *component; Components)
+  foreach (SkyComponent *component, Components)
 		component->updateMoons(data, num, needNewCoords);
 }


More information about the Kstars-devel mailing list