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

Alexey Khudyakov alexey.skladnoy at gmail.com
Fri Aug 21 14:44:51 CEST 2009


SVN commit 1014098 by khudyakov:

Move list of variable stars data from KStarsData to LCGenerator
List now read at LCGenerator createion not at KStars startup.
This reduce startup time but increase creation time of LCGenerator
However it does seems to be decently fast

CCMAIL: kstars-devel at kde.org

 M  +0 -43     kstarsdata.cpp  
 M  +0 -18     kstarsdata.h  
 M  +3 -5      kstarsinit.cpp  
 M  +40 -18    tools/lcgenerator.cpp  
 M  +20 -9     tools/lcgenerator.h  


--- trunk/KDE/kdeedu/kstars/kstars/kstarsdata.cpp #1014097:1014098
@@ -136,7 +136,6 @@
     delete m_logObject;
 
     qDeleteAll( geoList );
-    qDeleteAll( VariableStarsList );
     qDeleteAll( INDIHostsList );
     qDeleteAll( ADVtreeList );
 }
@@ -179,7 +178,6 @@
     emit progressText( i18n("Loading Variable Stars" ) );
     readINDIHosts();
     readUserLog();
-    readVARData();
     readADVTreeData();
 
     return true;
@@ -336,7 +334,6 @@
             return loc;
         }
     }
-
     return 0;
 }
 
@@ -794,46 +791,6 @@
     return true;
 }
 
-bool KStarsData::readVARData()
-{
-    QString varFile   = "valaav.txt";
-    QString localName =  KStandardDirs::locateLocal( "appdata", varFile );
-    QFile file;
-
-    file.setFileName( localName );
-    if ( !file.open( QIODevice::ReadOnly ) ) {
-        // Copy file with varstars data to user's data dir
-        QFile::copy(KStandardDirs::locate("appdata", varFile), localName);
-        if( !file.open( QIODevice::ReadOnly ) )
-            return false;
-    }
-
-
-    QTextStream stream(&file);
-    stream.readLine();
-
-    QString Name, Designation, Line;
-    while  (!stream.atEnd())
-    {
-        Line = stream.readLine();
-
-        if (Line.startsWith('*'))
-            break;
-
-        Designation = Line.left(8).trimmed();
-        Name        = Line.mid(10,20).simplified();
-
-        VariableStarInfo *VInfo = new VariableStarInfo;
-
-        VInfo->Designation = Designation;
-        VInfo->Name        = Name;
-        VariableStarsList.append(VInfo);
-    }
-
-    return true;
-}
-
-
 bool KStarsData::readINDIHosts()
 {
 #ifdef HAVE_INDI_H
--- trunk/KDE/kdeedu/kstars/kstars/kstarsdata.h #1014097:1014098
@@ -56,12 +56,6 @@
 class ADVTreeData;
 
 
-struct VariableStarInfo
-{
-    QString Name;
-    QString Designation;
-};
-
 /**@class KStarsData
 	*KStarsData is the backbone of KStars.  It contains all the data used by KStars, 
 	*including the SkyMapComposite that contains all items in the skymap 
@@ -90,9 +84,6 @@
     friend class INDIDriver;
     // FIXME: It uses geoList
     friend class MapCanvas;
-    // FIXME: It uses VariableStarList and is only one user.
-    //        VariableStarsList should be moved there.
-    friend class LCGenerator;
     // FIXME: It uses temporary trail. There must be way to
     //        this better. And resumeKey in DBUS code
     friend class KStars;
@@ -152,14 +143,6 @@
     	*/
     bool processCity( const QString& line );
 
-    /**Read Variable Stars data and stores them in structure of type VariableStarsInfo.
-    	*@li 0-8 AAVSO Star Designation
-    	*@li 10-20 Common star name
-    	*@short read Variable Stars data.
-    	*@return true if data is successfully read.
-    	*/
-    bool readVARData();
-
     //TODO JM: ADV tree should use XML instead
     /**Read Advanced interface structure to be used later to construct the list view in
     	*the advanced tab in the Detail Dialog.
@@ -399,7 +382,6 @@
     // FIXME: this should be moved to CustomCatalogComponent
     QList<SkyObject> objList;
 
-    QList<VariableStarInfo*> VariableStarsList;
     QList<ADVTreeData*> ADVtreeList;
     QList<INDIHostsInfo*> INDIHostsList;
 
--- trunk/KDE/kdeedu/kstars/kstars/kstarsinit.cpp #1014097:1014098
@@ -334,11 +334,9 @@
         << KShortcut( Qt::CTRL+Qt::Key_L );
 
     // enable action only if file was loaded and processed successfully.
-    if (!data()->VariableStarsList.isEmpty()) {
-        actionCollection()->addAction("lightcurvegenerator", this, SLOT( slotLCGenerator() ) )
-            << i18n("AAVSO Light Curves...")
-            << KShortcut( Qt::CTRL+Qt::Key_V );
-    }
+    actionCollection()->addAction("lightcurvegenerator", this, SLOT( slotLCGenerator() ) )
+        << i18n("AAVSO Light Curves...")
+        << KShortcut( Qt::CTRL+Qt::Key_V );
 
     actionCollection()->addAction("altitude_vs_time", this, SLOT( slotAVT() ) )
         << i18n("Altitude vs. Time...")
--- trunk/KDE/kdeedu/kstars/kstars/tools/lcgenerator.cpp #1014097:1014098
@@ -56,15 +56,14 @@
     lcg->StartDateBox->setDate(data->lt().date());
     lcg->EndDateBox->setDate(data->lt().date());
 
-    // Fill stars designations
-    for (int i=0; i< (data->VariableStarsList.count()); i++)
-        lcg->DesignationBox->addItem(data->VariableStarsList.at(i)->Designation);
+    readVarData();
+    // Fill stars designations & names
+    for (int i=0; i< (varInfoList.count()); i++) {
+        lcg->DesignationBox->addItem( varInfoList.at(i).designation );
+        lcg->NameBox->addItem( varInfoList.at(i).name );
+    }
 
-    // Fill star names
-    for (int i=0; i<data->VariableStarsList.count(); i++)
-        lcg->NameBox->addItem(data->VariableStarsList.at(i)->Name);
 
-
     // Signals/Slots
     QObject::connect(lcg->GetCurveButton, SIGNAL(clicked()), this,
                      SLOT(VerifyData()));
@@ -163,13 +162,10 @@
 
 void LCGenerator::downloadReady(KJob * job)
 {
-    KStarsData* data = KStarsData::Instance();
-
     downloadJob = 0;
     if ( job->error() )
     {
         static_cast<KIO::Job*>(job)->showErrorDialog();
-        closeEvent (0);
         return;
     }
 
@@ -177,24 +173,50 @@
 
     if ( file->exists() )
     {
-        data->readVARData();
+        readVarData();
 
         lcg->DesignationBox->clear();
         lcg->NameBox->clear();
 
         // Fill stars designations
-        for (int i=0; i < data->VariableStarsList.count(); i++)
-            lcg->DesignationBox->addItem(data->VariableStarsList.at(i)->Designation);
+        for (int i=0; i < varInfoList.count(); i++) {
+            lcg->DesignationBox->addItem( varInfoList.at(i).designation );
+            lcg->NameBox->addItem( varInfoList.at(i).name );
+        }
 
-        // Fill star names
-        for (int i=0; i < data->VariableStarsList.count(); i++)
-            lcg->NameBox->addItem(data->VariableStarsList.at(i)->Name);
-
         KMessageBox::information(this, i18n("AAVSO Star list downloaded successfully."));
         return;
     }
-    closeEvent (0);
+}
 
+bool LCGenerator::readVarData()
+{
+    QString varFile   = "valaav.txt";
+    QString localName =  KStandardDirs::locateLocal( "appdata", varFile );
+    QFile file;
+
+    file.setFileName( localName );
+    if ( !file.open( QIODevice::ReadOnly ) ) {
+        // Copy file with varstars data to user's data dir
+        QFile::copy(KStandardDirs::locate("appdata", varFile), localName);
+        if( !file.open( QIODevice::ReadOnly ) )
+            return false;
+    }
+
+    QTextStream stream(&file);
+    stream.readLine();
+
+    VariableStarInfo vInfo;
+    while(!stream.atEnd()) {
+        QString line = stream.readLine();
+        if( line.startsWith('*') )
+            break;
+
+        vInfo.designation = line.left(8).trimmed();
+        vInfo.name        = line.mid(10,20).simplified();
+        varInfoList.append(vInfo);
+    }
+    return true;
 }
 
 void LCGenerator::closeEvent (QCloseEvent *ev)
--- trunk/KDE/kdeedu/kstars/kstars/tools/lcgenerator.h #1014097:1014098
@@ -19,6 +19,8 @@
 #define LCGENERATOR_H_
 
 #include <QCloseEvent>
+#include <QList>
+#include <QString>
 #include <kdialog.h>
 #include <kio/job.h>
 
@@ -26,6 +28,12 @@
 
 class QFile;
 
+struct VariableStarInfo
+{
+    QString name;
+    QString designation;
+};
+
 class LCGeneratorUI : public QFrame, public Ui::LCGenerator {
     Q_OBJECT
 public:
@@ -33,14 +41,12 @@
 };
 
 
-/**
-	*@class LCGenerator
-	*@short KStars Light Curve Generator
-	*This class provides a simple interface that enables a user to download
-	*variable stars light curves from an online AAVSO database given few basic parameters.
-	*@author Jasem Mutlaq
-	*@version 1.0
-	*/
+/** @class LCGenerator
+ *  @short KStars Light Curve Generator
+ *  This class provides a simple interface that enables a user to download
+ *  variable stars light curves from an online AAVSO database given few basic parameters.
+ *  @author Jasem Mutlaq
+ */
 class LCGenerator : public KDialog
 {
     Q_OBJECT
@@ -85,10 +91,15 @@
      */
     void DownloadCurve(const QDate &StartDate, const QDate &EndDate, const QString &Designation, const QString &AverageDay);
 
+    /** Read list of variable stars. */
+    bool readVarData();
+
+
     LCGeneratorUI *lcg;
 
-    KIO::Job *downloadJob;  // download job of image -> 0 == no job is running
+    KIO::Job *downloadJob;               /// download job of image -> 0 == no job is running
     QFile *file;
+    QList<VariableStarInfo> varInfoList; /// Information about variable stars.
 
     /** Make sure all events have been processed before closing the dialog
      *  @p ev pointer to the QCloseEvent object


More information about the Kstars-devel mailing list