[Marble-commits] KDE/kdeedu/marble/src

Jens-Michael Hoffmann jensmh at gmx.de
Tue May 11 23:55:38 CEST 2010


SVN commit 1125663 by jmhoffmann:

Download Region: Disconnect the expensive slots when the dialog is hidden.

 M  +14 -0     lib/DownloadRegionDialog.cpp  
 M  +11 -0     lib/DownloadRegionDialog.h  
 M  +14 -5     marble_part.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/DownloadRegionDialog.cpp #1125662:1125663
@@ -18,9 +18,11 @@
 #include <QtGui/QDialogButtonBox>
 #include <QtGui/QGroupBox>
 #include <QtGui/QHBoxLayout>
+#include <QtGui/QHideEvent>
 #include <QtGui/QLabel>
 #include <QtGui/QPushButton>
 #include <QtGui/QRadioButton>
+#include <QtGui/QShowEvent>
 #include <QtGui/QVBoxLayout>
 
 #include "AbstractScanlineTextureMapper.h"
@@ -309,6 +311,18 @@
     updateTilesCount();
 }
 
+void DownloadRegionDialog::hideEvent( QHideEvent * event )
+{
+    emit hidden();
+    event->accept();
+}
+
+void DownloadRegionDialog::showEvent( QShowEvent * event )
+{
+    emit shown();
+    event->accept();
+}
+
 void DownloadRegionDialog::toggleSelectionMethod()
 {
     d->m_latLonBoxWidget->setEnabled( !d->m_latLonBoxWidget->isEnabled() );
--- trunk/KDE/kdeedu/marble/src/lib/DownloadRegionDialog.h #1125662:1125663
@@ -19,6 +19,9 @@
 #include "TileCoordsPyramid.h"
 #include "marble_export.h"
 
+class QHideEvent;
+class QShowEvent;
+
 namespace Marble
 {
 class GeoDataLatLonAltBox;
@@ -47,7 +50,15 @@
  Q_SIGNALS:
     /// This signal is emitted when the "Apply" button is pressed.
     void applied();
+    /// This signal is emitted when the dialog receives a QHideEvent.
+    void hidden();
+    /// This signal is emitted when the dialog receives a QShowEvent
+    void shown();
 
+ protected:
+    virtual void hideEvent( QHideEvent * event );
+    virtual void showEvent( QShowEvent * event );
+
  private Q_SLOTS:
     void toggleSelectionMethod();
     void updateTilesCount();
--- trunk/KDE/kdeedu/marble/src/marble_part.cpp #1125662:1125663
@@ -971,20 +971,22 @@
     //m_controlView->marbleControl()->updateMapThemes();
 }
 
+// connect to expensive slots, only needed when the non modal dialog is show
 void MarblePart::connectDownloadRegionDialog()
 {
-    connect( m_downloadRegionDialog, SIGNAL( accepted() ), SLOT( downloadRegion() ));
-    connect( m_downloadRegionDialog, SIGNAL( applied() ), SLOT( downloadRegion() ));
     connect( m_controlView->marbleWidget(), SIGNAL( visibleLatLonAltBoxChanged( GeoDataLatLonAltBox )),
              m_downloadRegionDialog, SLOT( setVisibleLatLonAltBox( GeoDataLatLonAltBox )));
     connect( m_controlView->marbleWidget(), SIGNAL( themeChanged( QString )),
              m_downloadRegionDialog, SLOT( updateTextureLayer() ));
 }
 
+// disconnect from expensive slots, not needed when dialog is hidden
 void MarblePart::disconnectDownloadRegionDialog()
 {
-    disconnect( m_downloadRegionDialog, 0, this, 0 );
-    disconnect( m_controlView->marbleWidget(), 0, m_downloadRegionDialog, 0 );
+    disconnect( m_controlView->marbleWidget(), SIGNAL( visibleLatLonAltBoxChanged( GeoDataLatLonAltBox )),
+                m_downloadRegionDialog, SLOT( setVisibleLatLonAltBox( GeoDataLatLonAltBox )));
+    disconnect( m_controlView->marbleWidget(), SIGNAL( themeChanged( QString )),
+                m_downloadRegionDialog, SLOT( updateTextureLayer() ));
 }
 
 void MarblePart::showDownloadRegionDialog()
@@ -993,7 +995,14 @@
     MarbleModel * const model = m_controlView->marbleWidget()->map()->model();
     if ( !m_downloadRegionDialog ) {
         m_downloadRegionDialog = new DownloadRegionDialog( viewport, model, widget() );
-        connectDownloadRegionDialog();
+        // it might be tempting to move the connects to DownloadRegionDialog's "accepted" and
+        // "applied" signals, be aware that the "hidden" signal might be come before the "accepted"
+        // signal, leading to a too early disconnect.
+        connect( m_downloadRegionDialog, SIGNAL( accepted() ), SLOT( downloadRegion() ));
+        connect( m_downloadRegionDialog, SIGNAL( applied() ), SLOT( downloadRegion() ));
+        connect( m_downloadRegionDialog, SIGNAL( shown() ), SLOT( connectDownloadRegionDialog() ));
+        connect( m_downloadRegionDialog, SIGNAL( hidden() ),
+                 SLOT( disconnectDownloadRegionDialog() ));
     }
     // FIXME: get allowed range from current map theme
     m_downloadRegionDialog->setAllowedTileLevelRange( 0, 18 );


More information about the Marble-commits mailing list