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

Jason Harris kstars at 30doradus.org
Sat Aug 23 15:48:14 CEST 2008


SVN commit 851288 by harris:

It is now finally possible to properly handle custom catalogs in the Download 
Extra Data tool.  If any downloaded file has a filename matching *.cat, it will 
attempt to import it as a custom catalog.

You can try it out immediately, because I recently (finally) added Carl Knight's 
contribution of the Abell Planetary Nebula catalog to the download tool.  When you 
install the catalog using Ctrl+D, it will start displaying the PN immediately, you 
can search for them in the Find tool, and the catalog will appear in the Catalogs 
tab of the config tool.  Hooray!

Will backport to 4.1.

If you're using < KDE 4.1.x (where x>0), you'll have to add the catalog manually 
after installing the file, using the "Load Catalog" button in the Config tool, and 
pointing it to $KDEHOME/share/apps/kstars/catalogname.cat.

CCMAIL: kstars-devel at kde.org



 M  +4 -4      addcatdialog.cpp  
 M  +23 -1     kstarsactions.cpp  
 M  +12 -5     opscatalog.cpp  
 M  +1 -1      skycomponents/customcatalogcomponent.cpp  
 M  +12 -1     skycomponents/customcatalogcomponent.h  
 M  +13 -7     skycomponents/skymapcomposite.cpp  
 M  +1 -1      skycomponents/skymapcomposite.h  


--- trunk/KDE/kdeedu/kstars/kstars/addcatdialog.cpp #851287:851288
@@ -50,6 +50,9 @@
              this, SLOT( slotShowDataFile() ) );
     connect( acd->PreviewButton, SIGNAL( clicked() ), this, SLOT( slotPreviewCatalog() ) );
     connect( this, SIGNAL( okClicked() ), this, SLOT( slotCreateCatalog() ) );
+//    connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
+    connect(this,SIGNAL(cancelClicked()),this,SLOT(slotCancel()));
+    connect(this,SIGNAL(helpClicked()),this,SLOT(slotHelp()));
 
     acd->FieldList->addItem( i18n( "ID Number" ) );
     acd->FieldList->addItem( i18n( "Right Ascension" ) );
@@ -62,9 +65,6 @@
     acd->FieldPool->addItem( i18n( "Minor Axis" ) );
     acd->FieldPool->addItem( i18n( "Position Angle" ) );
     acd->FieldPool->addItem( i18n( "Ignore" ) );
-    connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
-    connect(this,SIGNAL(cancelClicked()),this,SLOT(slotCancel()));
-    connect(this,SIGNAL(helpClicked()),this,SLOT(slotHelp()));
 }
 
 AddCatDialog::~AddCatDialog(){
@@ -132,7 +132,7 @@
         QTextStream ostream( &tmpFile );
         ostream << CatalogContents;
         ostream.flush();
-        CustomCatalogComponent newCat( 0, tmpFile.fileName(), true, Options::showOther );
+        CustomCatalogComponent newCat( 0, tmpFile.fileName(), true, 0 );
         newCat.init( ks->data() );
 
         int nObjects = newCat.objectList().size();
--- trunk/KDE/kdeedu/kstars/kstars/kstarsactions.cpp #851287:851288
@@ -86,6 +86,7 @@
 #include "indifitsconf.h"
 #include "telescopewizardprocess.h"
 #include "telescopeprop.h"
+#include "skycomponents/customcatalogcomponent.h"
 
 #include <config-kstars.h>
 
@@ -207,8 +208,26 @@
 
 void KStars::slotDownload() {
     KNS::Entry::List entries = KNS::Engine::download();
+
+    foreach ( KNS::Entry *e, entries ) {
+        foreach ( QString fname, e->installedFiles() ) {
+            if ( fname.endsWith( ".cat" ) ) {
+                //DEBUG
+                kDebug() << "Initializing catalog: " << fname << endl;
+
+                //To start displaying the custom catalog, add it to SkyMapComposite
+                Options::setCatalogFile( Options::catalogFile() << fname );
+                Options::setShowCatalog( Options::showCatalog() << 1 );
+                //DEBUG
+                kDebug() << Options::catalogFile() << endl;
+
+                data()->skyComposite()->addCustomCatalog( fname, data(),  Options::catalogFile().size()-1 );
+            }
+        }
+    }
+
     // we need to delete the entry* items in the returned list
-	qDeleteAll(entries);
+    qDeleteAll(entries);
 }
 
 void KStars::slotLCGenerator() {
@@ -1134,6 +1153,9 @@
     cg = KGlobal::config()->group( "ViewToolBar" );
     toolBar( "viewToolBar" )->saveSettings( cg );
 
+    //DEBUG
+    kDebug() << "Custom catalogs: " << Options::catalogFile() << endl;
+    
     //synch the config file with the Config object
     writeConfig();
 
--- trunk/KDE/kdeedu/kstars/kstars/opscatalog.cpp #851287:851288
@@ -82,6 +82,10 @@
     //Add custom catalogs, if necessary
     for ( int i = 0; i < ksw->data()->skyComposite()->customCatalogs().size(); ++i ) {
         CustomCatalogComponent *cc = ((CustomCatalogComponent*)ksw->data()->skyComposite()->customCatalogs()[i]);
+
+        //DEBUG
+        kDebug() << "Custom catalog: " << cc->name() << endl;
+        
         QListWidgetItem *newItem = new QListWidgetItem( cc->name(), CatalogList );
         newItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
         newItem->setCheckState( Options::showCatalog()[i] ?  Qt::Checked : Qt::Unchecked );
@@ -130,6 +134,9 @@
 void OpsCatalog::selectCatalog() {
     //If selected item is a custom catalog, enable the remove button (otherwise, disable it)
     RemoveCatalog->setEnabled( false );
+
+    if ( ! CatalogList->currentItem() ) return;
+    
     foreach ( SkyComponent *sc, ksw->data()->skyComposite()->customCatalogs() ) {
         CustomCatalogComponent *cc = (CustomCatalogComponent*)sc;
         if ( CatalogList->currentItem()->text() == cc->name() ) {
@@ -150,7 +157,7 @@
     QString filename = KFileDialog::getOpenFileName( QDir::homePath(), "*");
     if ( ! filename.isEmpty() ) {
         //test integrity of file before trying to add it
-      CustomCatalogComponent newCat( ksw->data()->skyComposite(), filename, true, Options::showOther );
+        CustomCatalogComponent newCat( ksw->data()->skyComposite(), filename, true, 0 );
         newCat.init( ksw->data() );
         if ( newCat.objectList().size() )
             insertCatalog( filename );
@@ -178,8 +185,8 @@
         QString name = cc->name();
 
         if ( CatalogList->currentItem()->text() == name ) {
-            m_CustomCatalogFile.removeAll( m_CustomCatalogFile[i] );
-            m_ShowCustomCatalog.removeAll( m_ShowCustomCatalog[i] );
+            m_CustomCatalogFile.removeAt( i );
+            m_ShowCustomCatalog.removeAt( i );
             break;
         }
     }
@@ -232,17 +239,17 @@
     }
 
     //Add custom catalogs as needed
+    Options::setShowCatalog( m_ShowCustomCatalog );
     for ( int i=0; i < m_CustomCatalogFile.size(); ++i ) {
         QString filename = m_CustomCatalogFile[i];
 
         if ( ! Options::catalogFile().contains( filename ) ) {
             //Add this catalog
-            ksw->data()->skyComposite()->addCustomCatalog( filename, ksw->data(),  Options::showOther );
+            ksw->data()->skyComposite()->addCustomCatalog( filename, ksw->data(),  i );
         }
     }
 
     Options::setCatalogFile( m_CustomCatalogFile );
-    Options::setShowCatalog( m_ShowCustomCatalog );
 
     // update time for all objects because they might be not initialized
     // it's needed when using horizontal coordinates
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/customcatalogcomponent.cpp #851287:851288
@@ -34,7 +34,7 @@
 
 QStringList CustomCatalogComponent::m_Columns = QString( "ID RA Dc Tp Nm Mg Mj Mn PA Ig" ).split( ' ', QString::SkipEmptyParts );
 
-CustomCatalogComponent::CustomCatalogComponent(SkyComponent *parent, const QString &fname, bool showerrs, bool (*visibleMethod)()) : ListComponent(parent, visibleMethod), m_Filename( fname ), m_Showerrs( showerrs )
+CustomCatalogComponent::CustomCatalogComponent(SkyComponent *parent, const QString &fname, bool showerrs, int index) : ListComponent(parent), m_Filename( fname ), m_Showerrs( showerrs ), m_ccIndex(index)
 {
 }
 
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/customcatalogcomponent.h #851287:851288
@@ -20,6 +20,7 @@
 
 
 #include "listcomponent.h"
+#include "Options.h"
 
 class KStarsData;
 class CustomCatalog;
@@ -41,7 +42,7 @@
     	*@short Constructor
     	*@p parent Pointer to the parent SkyComponent object
     	*/
-    CustomCatalogComponent( SkyComponent*, const QString &fname, bool showerrs, bool (*visibleMethod)() );
+    CustomCatalogComponent( SkyComponent*, const QString &fname, bool showerrs, int index );
     /**
     	*@short Destructor.  Delete list members
     	*/
@@ -66,6 +67,15 @@
     	*/
     QString name() const { return m_catName; }
 
+    /**
+     *@return true if visibility Option is set for this catalog
+     *@note this is complicated for custom catalogs, because 
+     *Option::showCatalog() returns a QList<int>, not a bool.
+     *This function extracts the correct visibility value and 
+     *returns the appropriate bool value
+     */
+    inline bool getVisibility() { return (Options::showCatalog()[m_ccIndex] > 0) ? true : false; }
+    
 private:
 
     /**
@@ -120,6 +130,7 @@
     QString m_catName, m_catPrefix, m_catColor;
     float m_catEpoch;
     bool m_Showerrs;
+    int m_ccIndex;
 
     static QStringList m_Columns;
 };
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skymapcomposite.cpp #851287:851288
@@ -100,11 +100,9 @@
     m_DeepSky = new DeepSkyComponent( this );
     addComponent( m_DeepSky );
 
-    //FIXME: can't use Options::showCatalog as visibility fcn,
-    //because it returns QList, not bool
     m_CustomCatalogs = new SkyComposite( this );
-    foreach ( const QString &fname, Options::catalogFile() ) {
-        CustomCatalogComponent *cc = new CustomCatalogComponent( this, fname, false,  &Options::showOther );
+    for ( int i=0; i<Options::catalogFile().size(); ++ i ) {
+        CustomCatalogComponent *cc = new CustomCatalogComponent( this, Options::catalogFile()[i], false, i );
         cc->init( data );
         m_CustomCatalogs->addComponent( cc );
     }
@@ -436,10 +434,18 @@
 	return 0;
 }
 
-void SkyMapComposite::addCustomCatalog( const QString &filename, KStarsData *data, bool (*visibleMethod)() ) {
-    CustomCatalogComponent *cc = new CustomCatalogComponent( this, filename, false, visibleMethod );
+void SkyMapComposite::addCustomCatalog( const QString &filename, KStarsData *data, int index ) {
+    CustomCatalogComponent *cc = new CustomCatalogComponent( this, filename, false, index );
     cc->init( data );
-    m_CustomCatalogs->addComponent( cc );
+    
+    //DEBUG
+    kDebug() << cc->objectList().size() << endl;
+    
+    if ( cc->objectList().size() ) {
+        m_CustomCatalogs->addComponent( cc );
+    } else {
+        delete cc;
+    }
 }
 
 void SkyMapComposite::removeCustomCatalog( const QString &name ) {
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skymapcomposite.h #851287:851288
@@ -158,7 +158,7 @@
     virtual bool removeTrail( SkyObject *o );
     virtual void clearTrailsExcept( SkyObject *o );
 
-    void addCustomCatalog( const QString &filename, KStarsData *data, bool (*visibleMethod)() );
+    void addCustomCatalog( const QString &filename, KStarsData *data, int index );
     void removeCustomCatalog( const QString &name );
 
     bool addNameLabel( SkyObject *o );


More information about the Kstars-devel mailing list