[Kstars-devel] branches/kstars/summer/kdeedu/kstars/kstars
Akarsh Simha
akarshsimha at gmail.com
Wed Jun 4 00:27:05 CEST 2008
SVN commit 816459 by asimha:
+ Storing a pointer to the spectral type string in SkyObject::SpType,
instead of the string itself.
+ Implementing a SkyObject::init() method that does initialization of
star data independent of the constructor.
CCMAIL: kstars-devel at kde.org
M +41 -8 starobject.cpp
M +28 -4 starobject.h
--- branches/kstars/summer/kdeedu/kstars/kstars/starobject.cpp #816458:816459
@@ -49,7 +49,7 @@
StarObject::StarObject( StarObject &o )
: SkyObject (o)
{
- SpType = o.SpType;
+ SpType = new QString(*o.SpType);
//SONAME: deprecated (?) JH
// soName = o.soName;
PM_RA = o.pmRA();
@@ -65,10 +65,12 @@
const QString &sptype, double pmra, double pmdec,
double par, bool mult, bool var )
: SkyObject (SkyObject::STAR, r, d, m, n, n2, QString()),
- SpType(sptype), PM_RA(pmra), PM_Dec(pmdec),
- Parallax(par), Multiplicity(mult), Variability(var)
+ PM_RA(pmra), PM_Dec(pmdec),
+ Parallax(par), Multiplicity(mult), Variability(var)
// SONAME deprecated //, soName( 0 )
{
+
+ SpType = new QString(sptype);
QString lname;
if ( hasName() ) {
lname = n;
@@ -90,10 +92,12 @@
const QString &sptype, double pmra, double pmdec,
double par, bool mult, bool var )
: SkyObject (SkyObject::STAR, r, d, m, n, n2, QString()),
- SpType(sptype), PM_RA(pmra), PM_Dec(pmdec),
+ PM_RA(pmra), PM_Dec(pmdec),
Parallax(par), Multiplicity(mult), Variability(var)
// SONAME deprecated //, soName( 0 )
{
+
+ SpType = new QString(sptype);
QString lname;
if ( hasName() ) {
lname = n;
@@ -105,9 +109,39 @@
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)
+{
+
+ /* TODO: Fix bug and uncomment this code */
+ setType( SkyObject::STAR );
+ setMag( m );
+ setRA0( r );
+ setDec0( d );
+ setRA( r );
+ setDec( d );
+ SpType = new QString(sptype);
+ PM_RA = pmra;
+ PM_Dec = pmdec;
+ Parallax = par;
+ Multiplicity = mult;
+ Variability = var ;
+
+ // setLongName(i18n("star"));
+ updateID = updateNumID = 0;
+}
+
void StarObject::initImages() {
SkyMap *map = SkyMap::Instance();
double scale = 1.0;
+
if ( map && map->scale() > 1.0 ) scale = map->scale();
if ( Options::starColorMode() == 0 ) { //Real colors
@@ -226,7 +260,7 @@
}
QString StarObject::sptype( void ) const {
- return SpType;
+ return (*SpType);
}
QString StarObject::gname( bool useGreekChars ) const {
@@ -366,7 +400,7 @@
}
QColor StarObject::color() const {
- return ColorMap[SpType.at(0)];
+ return (SpType ? ColorMap[SpType -> at(0)] : "-");
}
void StarObject::updateColors( bool desaturateColors, int saturation ) {
@@ -402,8 +436,7 @@
if ( isize >= 14 ) {
isize = 14;
}
-
- QString imKey = ((SpType != "") ? SpType.at(0) : (QChar)' ') + QString("%1").arg(isize);
+ QString imKey = ((SpType && !(SpType -> isEmpty())) ? SpType -> at(0) : (QChar)'-') + 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 #816458:816459
@@ -90,11 +90,35 @@
double par=0.0, bool mult=false, bool var=false );
/**
- *Empty destructor.
- */
- ~StarObject() {}
+ * Destructor. Deletes SpType.
+ */
+ ~StarObject();
/**
+ *@short Initializes a StarObject to given data
+ *
+ * This is almost like the StarObject constructor itself, but it avoids
+ * setting up name, gname etc for unnamed stars. If called instead of the
+ * constructor, this method will be much faster for unnamed stars
+ *
+ *@param r Right Ascension [Hours]
+ *@param d Declination [Degrees]
+ *@param m Magnitude
+ *@param sptype Spectral Type
+ *@param pmra Proper motion in RA direction [mas/yr]
+ *@param pmdec Proper motion in Dec direction [mas/yr]
+ *@param par Parallax angle [mas]
+ *@param mult Multiplicity flag (false=dingle star; true=multiple star)
+ *@param var Variability flag (true if star is a known periodic variable)
+ *@return Nothing
+ *
+ * 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 init(double r, double d, float m=0.0, const QString &sptype="--", double pmra=0.0, double pmdec=0.0,
+ double par=0.0, bool mult=false, bool var=false);
+
+ /**
*@return true if the star has a name ("star" doesn't count)
*/
inline bool hasName() const { return ( !Name.isEmpty() && Name!=starString ); }
@@ -293,7 +317,7 @@
static QHash<QString, QPixmap> StarImage;
private:
- QString SpType;
+ QString *SpType;
double PM_RA, PM_Dec, Parallax; //, VRange, VPeriod;
bool Multiplicity, Variability;
More information about the Kstars-devel
mailing list