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

Alexey Khudyakov alexey.skladnoy at gmail.com
Thu Aug 27 00:11:12 CEST 2009


SVN commit 1016072 by khudyakov:

Replace invocations of LocationDialog( KStars::INstance() )
with LocationDialog( this ). This is more in line with Qt
practice and eliminate dependency on KStars class where it
is not needed.

Fix blind casts in MapCanvas. They are really dangerous.
It required a kludge though.

CCMAIL: kstars-devel at kde.org

 M  +1 -1      comast/execute.cpp  
 M  +4 -1      dialogs/locationdialog.cpp  
 M  +1 -1      tools/altvstime.cpp  
 M  +3 -4      tools/conjunctions.cpp  
 M  +2 -2      tools/modcalcaltaz.cpp  
 M  +2 -5      tools/modcalcdaylength.cpp  
 M  +1 -2      tools/modcalcplanets.cpp  
 M  +2 -3      tools/modcalcsidtime.cpp  
 M  +1 -2      tools/modcalcvlsr.cpp  
 M  +1 -1      tools/observinglist.cpp  
 M  +1 -1      tools/obslistwizard.cpp  
 M  +1 -1      tools/scriptbuilder.cpp  
 M  +1 -2      tools/skycalendar.cpp  
 M  +1 -1      tools/wutdialog.cpp  
 M  +33 -30    widgets/mapcanvas.cpp  
 M  +31 -32    widgets/mapcanvas.h  


--- trunk/KDE/kdeedu/kstars/kstars/comast/execute.cpp #1016071:1016072
@@ -173,7 +173,7 @@
 }
 
 void Execute::slotLocation() {
-    QPointer<LocationDialog> ld = new LocationDialog( ks );
+    QPointer<LocationDialog> ld = new LocationDialog( this );
     if ( ld->exec() == QDialog::Accepted ) {
         geo = ld->selectedCity();
         ui.Location->setText( geo -> fullName() );
--- trunk/KDE/kdeedu/kstars/kstars/dialogs/locationdialog.cpp #1016071:1016072
@@ -36,6 +36,9 @@
     KStarsData* data = KStarsData::Instance();
     ui = new Ui::LocationDialog();
     ui->setupUi( mainWidget() );
+    // FIXME: temporary plug! (See MapCanvas for details)
+    ui->MapView->setLocationDialog( this );
+
     setCaption( i18n( "Set Geographic Location" ) );
     setButtons( KDialog::Ok|KDialog::Cancel );
 
@@ -48,7 +51,7 @@
     for ( ; it != itEnd; ++it )
         if ( it.key().length() )
             ui->DSTRuleBox->addItem( it.key() );
-
+    
     connect( this, SIGNAL( cancelClicked() ), this, SLOT( reject() ) );
     connect( ui->CityFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( filterCity() ) );
     connect( ui->ProvinceFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( filterCity() ) );
--- trunk/KDE/kdeedu/kstars/kstars/tools/altvstime.cpp #1016071:1016072
@@ -412,7 +412,7 @@
 }
 
 void AltVsTime::slotChooseCity() {
-    QPointer<LocationDialog> ld = new LocationDialog(ks);
+    QPointer<LocationDialog> ld = new LocationDialog(this);
     if ( ld->exec() == QDialog::Accepted ) {
         GeoLocation *newGeo = ld->selectedCity();
         if ( newGeo ) {
--- trunk/KDE/kdeedu/kstars/kstars/tools/conjunctions.cpp #1016071:1016072
@@ -112,7 +112,7 @@
     int index = OutputView->currentRow();
     long double jd = outputJDList.value( index );
     KStarsDateTime dt;
-    KStars *ks= (KStars *) topLevelWidget()->parent();
+    KStars *ks = KStars::Instance();
     KStarsData *data = KStarsData::Instance();
     SkyMap *map = ks->map();
 
@@ -126,7 +126,7 @@
 }
 
 void ConjunctionsTool::slotFindObject() {
-    QPointer<FindDialog> fd = new FindDialog( (KStars*) topLevelWidget()->parent() );
+    QPointer<FindDialog> fd = new FindDialog( KStars::Instance() );
     if ( fd->exec() == QDialog::Accepted ) {
         if( Object1 )
             delete Object1;
@@ -141,8 +141,7 @@
 
 void ConjunctionsTool::slotLocation()
 {
-    LocationDialog ld( (KStars*) topLevelWidget()->parent() );
-
+    LocationDialog ld( this );
     if ( ld.exec() == QDialog::Accepted ) {
         geoPlace = ld.selectedCity();
         LocationButton -> setText( geoPlace -> fullName() );
--- trunk/KDE/kdeedu/kstars/kstars/tools/modcalcaltaz.cpp #1016071:1016072
@@ -84,7 +84,7 @@
 
 void modCalcAltAz::slotLocation()
 {
-    QPointer<LocationDialog> ld = new LocationDialog( KStars::Instance() );
+    QPointer<LocationDialog> ld = new LocationDialog( this );
     if ( ld->exec() == QDialog::Accepted ) {
         GeoLocation *newGeo = ld->selectedCity();
         if ( newGeo ) {
@@ -98,7 +98,7 @@
 
 void modCalcAltAz::slotObject()
 {
-    QPointer<FindDialog> fd = new FindDialog( (KStars*)topLevelWidget()->parent() );
+    QPointer<FindDialog> fd = new FindDialog( KStars::Instance() );
     if ( fd->exec() == QDialog::Accepted ) {
         SkyObject *o = fd->selectedObject();
         RA->showInHours( o->ra() );
--- trunk/KDE/kdeedu/kstars/kstars/tools/modcalcdaylength.cpp #1016071:1016072
@@ -24,7 +24,6 @@
 
 #include "skyobjects/skyobject.h"
 #include "geolocation.h"
-#include "kstars.h"
 #include "kstarsdata.h"
 #include "skyobjects/kssun.h"
 #include "skyobjects/ksmoon.h"
@@ -83,8 +82,7 @@
 }
 
 void modCalcDayLength::slotLocation() {
-    QPointer<LocationDialog> ld = new LocationDialog( KStars::Instance() );
-
+    QPointer<LocationDialog> ld = new LocationDialog( this );
     if ( ld->exec() == QDialog::Accepted ) {
         GeoLocation *newGeo = ld->selectedCity();
         if ( newGeo ) {
@@ -98,8 +96,7 @@
 }
 
 void modCalcDayLength::slotLocationBatch() {
-    QPointer<LocationDialog> ld = new LocationDialog( KStars::Instance() );
-
+    QPointer<LocationDialog> ld = new LocationDialog( this );
     if ( ld->exec() == QDialog::Accepted ) {
         GeoLocation *newGeo = ld->selectedCity();
         if ( newGeo ) {
--- trunk/KDE/kdeedu/kstars/kstars/tools/modcalcplanets.cpp #1016071:1016072
@@ -25,7 +25,6 @@
 #include "geolocation.h"
 #include "dialogs/locationdialog.h"
 #include "dms.h"
-#include "kstars.h"
 #include "kstarsdata.h"
 #include "ksnumbers.h"
 #include "skyobjects/kssun.h"
@@ -70,7 +69,7 @@
 
 void modCalcPlanets::slotLocation()
 {
-    QPointer<LocationDialog> ld = new LocationDialog( (KStars*) topLevelWidget()->parent() );
+    QPointer<LocationDialog> ld = new LocationDialog( this );
 
     if ( ld->exec() == QDialog::Accepted ) {
         geoPlace = ld->selectedCity();
--- trunk/KDE/kdeedu/kstars/kstars/tools/modcalcsidtime.cpp #1016071:1016072
@@ -22,7 +22,6 @@
 #include <kfiledialog.h>
 #include <kmessagebox.h>
 
-#include "kstars.h"
 #include "kstarsdata.h"
 #include "kstarsdatetime.h"
 #include "simclock.h"
@@ -79,7 +78,7 @@
 }
 
 void modCalcSidTime::slotChangeLocation() {
-    QPointer<LocationDialog> ld = new LocationDialog( KStars::Instance() );
+    QPointer<LocationDialog> ld = new LocationDialog( this );
 
     if ( ld->exec() == QDialog::Accepted ) {
         GeoLocation *newGeo = ld->selectedCity();
@@ -178,7 +177,7 @@
 }
 
 void modCalcSidTime::slotLocationBatch() {
-    QPointer<LocationDialog> ld = new LocationDialog( KStars::Instance() );
+    QPointer<LocationDialog> ld = new LocationDialog( this );
 
     if ( ld->exec() == QDialog::Accepted ) {
         GeoLocation *newGeo = ld->selectedCity();
--- trunk/KDE/kdeedu/kstars/kstars/tools/modcalcvlsr.cpp #1016071:1016072
@@ -26,7 +26,6 @@
 #include "dms.h"
 #include "skyobjects/skypoint.h"
 #include "geolocation.h"
-#include "kstars.h"
 #include "kstarsdata.h"
 #include "kstarsdatetime.h"
 #include "widgets/dmsbox.h"
@@ -91,7 +90,7 @@
 }
 
 void modCalcVlsr::slotLocation() {
-    LocationDialog ld( KStars::Instance() );
+    LocationDialog ld( this );
 
     if ( ld.exec() == QDialog::Accepted ) {
         GeoLocation *newGeo = ld.selectedCity();
--- trunk/KDE/kdeedu/kstars/kstars/tools/observinglist.cpp #1016071:1016072
@@ -1096,7 +1096,7 @@
 }
 
 void ObservingList::slotLocation() {
-    QPointer<LocationDialog> ld = new LocationDialog( (KStars*) topLevelWidget()->parent() );
+    QPointer<LocationDialog> ld = new LocationDialog( this );
     if ( ld->exec() == QDialog::Accepted ) {
         geo = ld->selectedCity();
         ui->SetLocation -> setText( geo -> fullName() );
--- trunk/KDE/kdeedu/kstars/kstars/tools/obslistwizard.cpp #1016071:1016072
@@ -230,7 +230,7 @@
 
 void ObsListWizard::slotChangeLocation()
 {
-    QPointer<LocationDialog> ld = new LocationDialog( ksw );
+    QPointer<LocationDialog> ld = new LocationDialog( this );
 
     if ( ld->exec() == QDialog::Accepted ) {
         //set geographic location
--- trunk/KDE/kdeedu/kstars/kstars/tools/scriptbuilder.cpp #1016071:1016072
@@ -1942,7 +1942,7 @@
 
 //Slots for Arg Widgets
 void ScriptBuilder::slotFindCity() {
-    QPointer<LocationDialog> ld = new LocationDialog( ks );
+    QPointer<LocationDialog> ld = new LocationDialog( this );
 
     if ( ld->exec() == QDialog::Accepted ) {
         if ( ld->selectedCity() ) {
--- trunk/KDE/kdeedu/kstars/kstars/tools/skycalendar.cpp #1016071:1016072
@@ -25,7 +25,6 @@
 #include "calendarwidget.h"
 #include "geolocation.h"
 #include "dialogs/locationdialog.h"
-#include "kstars.h"
 #include "kstarsdatetime.h"
 #include "kstarsdata.h"
 #include "skyobjects/ksplanet.h"
@@ -216,7 +215,7 @@
 }
 
 void SkyCalendar::slotLocation() {
-    QPointer<LocationDialog> ld = new LocationDialog( KStars::Instance() );
+    QPointer<LocationDialog> ld = new LocationDialog( this );
     if ( ld->exec() == QDialog::Accepted ) {
         GeoLocation *newGeo = ld->selectedCity();
         if ( newGeo ) {
--- trunk/KDE/kdeedu/kstars/kstars/tools/wutdialog.cpp #1016071:1016072
@@ -490,7 +490,7 @@
 }
 
 void WUTDialog::slotChangeLocation() {
-    QPointer<LocationDialog> ld = new LocationDialog( KStars::Instance() );
+    QPointer<LocationDialog> ld = new LocationDialog( this );
     if ( ld->exec() == QDialog::Accepted ) {
         GeoLocation *newGeo = ld->selectedCity();
         if ( newGeo ) {
--- trunk/KDE/kdeedu/kstars/kstars/widgets/mapcanvas.cpp #1016071:1016072
@@ -29,10 +29,10 @@
 #include "kstars.h"
 #include "kstarsdata.h"
 
-MapCanvas::MapCanvas( QWidget *parent ) : QFrame( parent ) {
-    ld = (LocationDialog *)topLevelWidget();
-    ks = (KStars *)ld->parent();
-
+MapCanvas::MapCanvas( QWidget *parent ) :
+    QFrame( parent ),
+    ld(0)
+{
     setAutoFillBackground( false );
 
     QString bgFile = KStandardDirs::locate( "data", "kstars/geomap.png" );
@@ -63,7 +63,8 @@
     int lng = ( e->x() - origin.x() );
     int lat  = ( origin.y() - e->y() );
 
-    ld->findCitiesNear( lng, lat );
+    if( ld )
+        ld->findCitiesNear( lng, lat );
 }
 
 void MapCanvas::paintEvent( QPaintEvent * ) {
@@ -76,7 +77,7 @@
 
     //Draw cities
     QPoint o;
-    foreach ( GeoLocation *g, ks->data()->geoList ) {
+    foreach ( GeoLocation *g, KStarsData::Instance()->geoList ) {
         o.setX( int( g->lng()->Degrees() + origin.x() ) );
         o.setY( height() - int( g->lat()->Degrees() + origin.y() ) );
 
@@ -85,36 +86,38 @@
         }
     }
 
-    //redraw the cities that appear in the filtered list, with a white pen
-    //If the list has not been filtered, skip the redraw.
-    if ( ld->filteredList().size() ) {
-        p.setPen( Qt::white );
-        foreach ( GeoLocation *g, ld->filteredList() ) {
-            o.setX( int( g->lng()->Degrees() + origin.x() ) );
-            o.setY( height() - int( g->lat()->Degrees() + origin.y() ) );
+    // FIXME: there must be better way to this. Without bothering LocationDialog
+    if( ld ) {
+        //redraw the cities that appear in the filtered list, with a white pen
+        //If the list has not been filtered, skip the redraw.
+        if ( ld->filteredList().size() ) {
+            p.setPen( Qt::white );
+            foreach ( GeoLocation *g, ld->filteredList() ) {
+                o.setX( int( g->lng()->Degrees() + origin.x() ) );
+                o.setY( height() - int( g->lat()->Degrees() + origin.y() ) );
 
-            if ( o.x() >= 0 && o.x() <= width() && o.y() >=0 && o.y() <=height() ) {
-                p.drawPoint( o.x(), o.y() );
+                if ( o.x() >= 0 && o.x() <= width() && o.y() >=0 && o.y() <=height() ) {
+                    p.drawPoint( o.x(), o.y() );
+                }
             }
         }
-    }
 
-    GeoLocation *g = ld->selectedCity();
-    if ( g ) {
-        o.setX( int( g->lng()->Degrees() + origin.x() ) );
-        o.setY( height() - int( g->lat()->Degrees() + origin.y() ) );
+        GeoLocation *g = ld->selectedCity();
+        if ( g ) {
+            o.setX( int( g->lng()->Degrees() + origin.x() ) );
+            o.setY( height() - int( g->lat()->Degrees() + origin.y() ) );
 
-        p.setPen( Qt::red );
-        p.setBrush( Qt::red );
-        p.drawEllipse( o.x()-3, o.y()-3, 6, 6 );
-        p.drawLine( o.x()-16, o.y(), o.x()-8, o.y() );
-        p.drawLine( o.x()+8, o.y(), o.x()+16, o.y() );
-        p.drawLine( o.x(), o.y()-16, o.x(), o.y()-8 );
-        p.drawLine( o.x(), o.y()+8, o.x(), o.y()+16 );
-        p.setPen( Qt::white );
-        p.setBrush( Qt::white );
+            p.setPen( Qt::red );
+            p.setBrush( Qt::red );
+            p.drawEllipse( o.x()-3, o.y()-3, 6, 6 );
+            p.drawLine( o.x()-16, o.y(), o.x()-8, o.y() );
+            p.drawLine( o.x()+8, o.y(), o.x()+16, o.y() );
+            p.drawLine( o.x(), o.y()-16, o.x(), o.y()-8 );
+            p.drawLine( o.x(), o.y()+8, o.x(), o.y()+16 );
+            p.setPen( Qt::white );
+            p.setBrush( Qt::white );
+        }
     }
-
     p.end();
 }
 #include "mapcanvas.moc"
--- trunk/KDE/kdeedu/kstars/kstars/widgets/mapcanvas.h #1016071:1016072
@@ -33,63 +33,62 @@
 	*@version 1.0
 	*/
 
-class QPixmap;
 class LocationDialog;
-class KStars;
+class QPixmap;
 
 class MapCanvas : public QFrame {
     Q_OBJECT
 public:
     /**Default constructor.  Initialize the widget: create pixmaps, load the
-    	*world map image
-    	*@param ks pointer to the KStars object
-    	*@param ld pointer to the parent LocationDialog
-    	*/
+     * world map image
+     * @param parent pointer to the parent LocationDialog
+     */
     MapCanvas( QWidget *parent );
 
-    /**Destructor (empty)
-    	*/
+    /**Destructor (empty) */
     ~MapCanvas();
 
+    /** Set location dialog */
+    // FIXME: This is temporary plug
+    void setLocationDialog(LocationDialog* loc) { ld = loc; }
 public slots:
     /**Set the geometry of the map widget (overloaded from QWidget).
-    	*Resizes the size of the map pixmap to match the widget, and resets
-    	*the Origin QPoint so it remains at the center of the widget.
-    	*@note this is called automatically by resize events.
-    	*@p x the x-position of the widget
-    	*@p y the y-position of the widget
-    	*@p w the width of the widget
-    	*@p h the height of the widget
-    	*/
+     * Resizes the size of the map pixmap to match the widget, and resets
+     * the Origin QPoint so it remains at the center of the widget.
+     * @note this is called automatically by resize events.
+     * @p x the x-position of the widget
+     * @p y the y-position of the widget
+     * @p w the width of the widget
+     * @p h the height of the widget
+     */
     virtual void setGeometry( int x, int y, int w, int h );
 
     /**Set the geometry of the map widget (overloaded from QWidget).
-    	*Resizes the size of the map pixmap to match the widget, and resets
-    	*the Origin QPoint so it remains at the center of the widget.
-    	*This function behaves just like the above function.  It differs
-    	*only in the data type of its argument.
-    	*@note this is called automatically by resize events.
-    	*@p r QRect describing geometry
-    	*/
+     * Resizes the size of the map pixmap to match the widget, and resets
+     * the Origin QPoint so it remains at the center of the widget.
+     * This function behaves just like the above function.  It differs
+     * only in the data type of its argument.
+     * @note this is called automatically by resize events.
+     * @p r QRect describing geometry
+     */
     virtual void setGeometry( const QRect &r );
 
 protected:
     /**Draw the map.  Draw grey dots on the locations of all cities,
-    	*and highlight the cities which match the current filters 
-    	*as white dits.  Also draw a red crosshairs on the 
-    	*currently-selected city.
-    	*@see LocationDialog
-    	*/
+     * and highlight the cities which match the current filters as
+     * white dits.  Also draw a red crosshairs on the
+     * currently-selected city.
+     * @see LocationDialog
+     */
     virtual void paintEvent( QPaintEvent *e );
 
     /**Trim the list of cities so that only those within 2 degrees
-    	*of the mouse click are shown in the list.
-    	*@see LocationDialog
-    	*/
+     * of the mouse click are shown in the list.
+     * @see LocationDialog
+     */
     virtual void mousePressEvent( QMouseEvent *e );
 
 private:
-    KStars *ks;
     LocationDialog *ld;
     QPixmap *bgImage;
     QString BGColor;


More information about the Kstars-devel mailing list