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

Jason Harris kstars at 30doradus.org
Wed Dec 14 07:19:51 CET 2005


SVN commit 488367 by harris:

Adding replacement for ObjectNamesList.

ObjectNamesList was an array of 27 lists of pointers to SkyObjectName 
objects.  It was designed to provide fast searches of a SkyObject by 
name, and was used by the Find Object tool.  The SkyObjectName class 
stored the name of the object as well as a pointer to the instance of 
the object in the program.

Now that we have the SkyComponents paradigm, this collection of pointers 
is no longer appropriate.  I have replaced the old scheme with a simple 
QStringList of object names, stored in SkyMapComposite.  A SkyComponent 
is responsible for adding its name(s) to the QStringList when it 
initializes itself.  Also, the dtor of the SkyComponent is responsible 
for removing the name(s) from the QStringList.

This is a much simpler scheme than before.  It may not be as fast to 
search for objects in the Find Object tool.  If we find that th new 
implementation is too slow, we can always try a similar optimization to 
what was used by ObjectNamesList (i.e., split the names into 27 lists, 
and select an "active" sub-list as soon as the first letter of the name 
is entered).

TODO: Still need to remove ObjectNameList and SkyObjectName classes, and 
remove vestigal uses of them from the code.

CCMAIL: kstars-devel at kde.org



 M  +3 -0      asteroidscomponent.cpp  
 M  +3 -0      cometscomponent.cpp  
 M  +3 -0      constellationnamescomponent.cpp  
 M  +6 -0      customcatalogcomponent.cpp  
 M  +47 -8     deepskycomponent.cpp  
 M  +9 -2      listcomponent.cpp  
 M  +8 -0      singlecomponent.cpp  
 M  +2 -0      skycomponent.h  
 M  +2 -0      skymapcomposite.h  
 M  +4 -0      solarsystemsinglecomponent.cpp  
 M  +3 -1      starcomponent.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/asteroidscomponent.cpp #488366:488367
@@ -107,6 +107,9 @@
 			ast = new KSAsteroid( data, name, "", JD, a, e, dms(dble_i), dms(dble_w), dms(dble_N), dms(dble_M), H );
 			ast->setAngularSize( 0.005 );
 			objectList().append( ast );
+
+			//Add name to the list of object names
+			parent()->objectNames().append( name );
 		}
 	}
 }
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/cometscomponent.cpp #488366:488367
@@ -68,6 +68,9 @@
 			com->setAngularSize( 0.005 );
 
 			objectList().append( com );
+
+			//Add name to the list of object names
+			parent()->objectNames().append( name );
 		}
 	}
 }
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/constellationnamescomponent.cpp #488366:488367
@@ -72,6 +72,9 @@
 
 			SkyObject *o = new SkyObject( SkyObject::CONSTELLATION, r, d, 0.0, name, abbrev );
 			objectList().append( o );
+
+			//Add name to the list of object names
+			parent()->objectNames().append( name );
 		}
 		file.close();
 	}
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/customcatalogcomponent.cpp #488366:488367
@@ -423,7 +423,13 @@
 		DeepSkyObject *o = new DeepSkyObject( iType, RA, Dec, mag, 
 					name, "", lname, m_catPrefix, a, b, PA );
 		objectList().append( o );
+
+		//Add name to the list of object names
+		if ( ! name.isEmpty() ) 
+			parent()->objectNames().append( name );
 	}
+	if ( ! lname.isEmpty() && lname != name ) 
+		parent()->objectNames().append( lname );
 
 	return true;
 }
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/deepskycomponent.cpp #488366:488367
@@ -44,14 +44,45 @@
 
 DeepSkyComponent::~DeepSkyComponent()
 {
-	while ( ! m_MessierList.isEmpty() ) 
-		delete  m_MessierList.takeFirst();
-	while ( ! m_NGCList.isEmpty() ) 
-		delete  m_NGCList.takeFirst();
-	while ( ! m_ICList.isEmpty() ) 
-		delete  m_ICList.takeFirst();
-	while ( ! m_OtherList.isEmpty() ) 
-		delete  m_OtherList.takeFirst();
+	while ( ! m_MessierList.isEmpty() ) {
+		SkyObject *o = m_MessierList.takeFirst();
+		int i = parent()->objectNames().indexOf( o->name() );
+		if ( i >= 0 ) parent()->objectNames().removeAt( i );
+		i = parent()->objectNames().indexOf( o->longname() );
+		if ( i >= 0 ) parent()->objectNames().removeAt( i );
+
+		delete o;
+	}
+
+	while ( ! m_NGCList.isEmpty() ) {
+		SkyObject *o = m_NGCList.takeFirst();
+		int i = parent()->objectNames().indexOf( o->name() );
+		if ( i >= 0 ) parent()->objectNames().removeAt( i );
+		i = parent()->objectNames().indexOf( o->longname() );
+		if ( i >= 0 ) parent()->objectNames().removeAt( i );
+
+		delete o;
+	}
+
+	while ( ! m_ICList.isEmpty() ) {
+		SkyObject *o = m_ICList.takeFirst();
+		int i = parent()->objectNames().indexOf( o->name() );
+		if ( i >= 0 ) parent()->objectNames().removeAt( i );
+		i = parent()->objectNames().indexOf( o->longname() );
+		if ( i >= 0 ) parent()->objectNames().removeAt( i );
+
+		delete o;
+	}
+
+	while ( ! m_OtherList.isEmpty() ) {
+		SkyObject *o = m_OtherList.takeFirst();
+		int i = parent()->objectNames().indexOf( o->name() );
+		if ( i >= 0 ) parent()->objectNames().removeAt( i );
+		i = parent()->objectNames().indexOf( o->longname() );
+		if ( i >= 0 ) parent()->objectNames().removeAt( i );
+
+		delete o;
+	}
 }
 
 void DeepSkyComponent::init(KStarsData *)
@@ -177,6 +208,14 @@
 					m_OtherList.append( o );
 				}
 
+				//Add name to the list of object names
+				if ( ! name.isEmpty() ) 
+					parent()->objectNames().append( name );
+
+				//Add long name to the list of object names
+				if ( ! longname.isEmpty() && longname != name ) 
+					parent()->objectNames().append( longname );
+
 			} //end while-filereader
 		}
 	} //end for-loop through ngcic files
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/listcomponent.cpp #488366:488367
@@ -30,8 +30,15 @@
 
 ListComponent::~ListComponent()
 {
-	while ( ! objectList().isEmpty() )
-		delete objectList().takeFirst();
+	while ( ! objectList().isEmpty() ) {
+		SkyObject *o = objectList().takeFirst();
+		int i = parent()->objectNames().indexOf( o->name() );
+		if ( i >= 0 ) parent()->objectNames().removeAt( i );
+		i = parent()->objectNames().indexOf( o->longname() );
+		if ( i >= 0 ) parent()->objectNames().removeAt( i );
+
+		delete o;
+	}
 }
 
 void ListComponent::update( KStarsData *data, KSNumbers *num )
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/singlecomponent.cpp #488366:488367
@@ -31,6 +31,14 @@
 
 SingleComponent::~SingleComponent()
 {
+	int i = parent()->objectNames().indexOf( m_StoredObject->name() );
+	if ( i >= 0 )
+		parent()->objectNames().removeAt( i );
+
+	i = parent()->objectNames().indexOf( m_StoredObject->longname() );
+	if ( i >= 0 )
+		parent()->objectNames().removeAt( i );
+
 	delete m_StoredObject;
 }
 
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skycomponent.h #488366:488367
@@ -181,6 +181,8 @@
 
 		void emitProgressText( const QString &message );
 
+		QStringList& objectNames() { return parent()->objectNames(); }
+
 	protected:
 
 		/**
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skymapcomposite.h #488366:488367
@@ -110,6 +110,7 @@
 			return m_CustomCatalogComposite->components(); 
 		}
 
+		QStringList& objectNames() { return m_ObjectNames; }
 
 	signals:
 		void progressText( const QString &message );
@@ -120,6 +121,7 @@
 		StarComponent *m_StarComponent;
 		ConstellationBoundaryComponent *m_CBoundsComponent;
 		ConstellationNamesComponent *m_CNamesComponent;
+		QStringList m_ObjectNames;
 };
 
 #endif
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/solarsystemsinglecomponent.cpp #488366:488367
@@ -45,6 +45,10 @@
 
 void SolarSystemSingleComponent::init(KStarsData *data) {
 	ksp()->loadData();
+
+	if ( ! ksp()->name().isEmpty() ) parent()->objectNames().append( ksp()->name() );
+	if ( ! ksp()->longname().isEmpty() && ksp()->longname() != ksp()->name() )
+		parent()->objectNames().append( ksp()->longname() );
 }
 
 void SolarSystemSingleComponent::updatePlanets(KStarsData *data, KSNumbers *num) {
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.cpp #488366:488367
@@ -270,6 +270,8 @@
 
 	StarObject *o = new StarObject( r, d, mag, name, gname, SpType, pmra, pmdec, plx, mult, var );
 	objectList().append(o);
-	
 	o->EquatorialToHorizontal( data()->lst(), data()->geo()->lat() );
+
+	if ( ! name.isEmpty() ) parent()->objectNames().append( name );
+	if ( ! gname.isEmpty() && gname != name ) parent()->objectNames().append( gname );
 }


More information about the Kstars-devel mailing list