[Kstars-devel] branches/kstars/summer/kdeedu/kstars/kstars

Akarsh Simha akarshsimha at gmail.com
Sun Jun 8 02:06:12 CEST 2008


SVN commit 818170 by asimha:

Changing the Spectral Type field in StarObject into a character array
of size 2. It was a QString earlier.

CCMAIL: kstars-devel at kde.org



 M  +14 -14    starobject.cpp  
 M  +4 -4      starobject.h  


--- branches/kstars/summer/kdeedu/kstars/kstars/starobject.cpp #818169:818170
@@ -49,7 +49,8 @@
 StarObject::StarObject( StarObject &o )
         : SkyObject (o)
 {
-    SpType = new QString(*o.SpType);
+    SpType[0] = o.SpType[0];
+    SpType[1] = o.SpType[1];
     //SONAME: deprecated (?) JH
     //	soName = o.soName;
     PM_RA = o.pmRA();
@@ -70,7 +71,9 @@
         // SONAME deprecated //, soName( 0 )
 {
 
-    SpType = new QString(sptype);
+    const char *spt = (const char *)sptype.toAscii();
+    SpType[0] = spt[0];
+    SpType[1] = spt[1];
     QString lname;
     if ( hasName() ) {
         lname = n;
@@ -96,8 +99,10 @@
         Parallax(par), Multiplicity(mult), Variability(var)
         // SONAME deprecated //, soName( 0 )
 {
+    const char *spt = (const char *)sptype.toAscii();
+    SpType[0] = spt[0];
+    SpType[1] = spt[1];
 
-    SpType = new QString(sptype);
     QString lname;
     if ( hasName() ) {
         lname = n;
@@ -109,13 +114,6 @@
     updateID = updateNumID = 0;
 }
 
-StarObject::~StarObject() {
-    if( SpType )
-	delete SpType;
-}
-
-// WARNING: This method is dangerous. Use only if you didn't call the default constructor.
-//          Calling this method otherwise may lead to memory leakage!
 void StarObject::init(double r, double d, float m, const QString &sptype, double pmra, 
 		 double pmdec, double par, bool mult, bool var) 
 {
@@ -127,7 +125,9 @@
     setDec0( d );
     setRA( r );
     setDec( d );
-    SpType = new QString(sptype);
+    const char *spt = (const char *)sptype.toAscii();
+    SpType[0] = spt[0];
+    SpType[1] = spt[1];
     PM_RA = pmra;
     PM_Dec = pmdec;
     Parallax = par;
@@ -260,7 +260,7 @@
 }
 
 QString StarObject::sptype( void ) const {
-    return (*SpType);
+    return (QString)QByteArray(SpType, 2);
 }
 
 QString StarObject::gname( bool useGreekChars ) const {
@@ -400,7 +400,7 @@
 }
 
 QColor StarObject::color() const {
-    return (SpType ? ColorMap[SpType -> at(0)] : "-");
+    return ColorMap[QString(QChar(SpType[0]))];
 }
 
 void StarObject::updateColors( bool desaturateColors, int saturation ) {
@@ -436,7 +436,7 @@
     if ( isize >= 14 ) {
         isize = 14;
     }
-    QString imKey = ((SpType && !(SpType -> isEmpty())) ? SpType -> at(0) : (QChar)'-') + QString("%1").arg(isize);
+    QString imKey = SpType[0] + QString("%1").arg(isize);
     float offset = 0.5*StarImage[imKey].width();
     psky.drawPixmap( QPointF(x-offset, y-offset), StarImage[imKey] );
 
--- branches/kstars/summer/kdeedu/kstars/kstars/starobject.h #818169:818170
@@ -90,9 +90,9 @@
                 double par=0.0, bool mult=false, bool var=false );
 
     /**
-     * Destructor. Deletes SpType.
+     * Destructor. (Empty)
      */
-    ~StarObject();
+    ~StarObject() { }
 
     /**
      *@short  Initializes a StarObject to given data
@@ -178,7 +178,7 @@
      */
     void getIndexCoords( KSNumbers *num, double *ra, double *dec );
 
-    /* @short added for JIT updates from both StarComponent and ConstellatoinLines
+    /* @short added for JIT updates from both StarComponent and ConstellationLines
      */
     void JITupdate( KStarsData* data );
 
@@ -317,7 +317,7 @@
     static QHash<QString, QPixmap> StarImage;
 
 private:
-    QString *SpType;
+    char SpType[2];
 
     double PM_RA, PM_Dec, Parallax;  //, VRange, VPeriod;
     bool Multiplicity, Variability;


More information about the Kstars-devel mailing list