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

Akarsh Simha akarshsimha at gmail.com
Thu Dec 10 19:59:38 CET 2009


SVN commit 1061134 by asimha:

The Location dialog used to filter the city list every time the text
changed. This was rather irritating.

This patch enqueues the filtering instead of filtering the list every
time the text changes, just like what's done in the find dialog.

CCMAIL: kstars-devel at kde.org



 M  +16 -4     locationdialog.cpp  
 M  +14 -4     locationdialog.h  


--- trunk/KDE/kdeedu/kstars/kstars/dialogs/locationdialog.cpp #1061133:1061134
@@ -31,7 +31,7 @@
 #include "kstarsdata.h"
 
 LocationDialog::LocationDialog( QWidget* parent ) :
-    KDialog( parent )
+    KDialog( parent ), timer( 0 )
 {
     KStarsData* data = KStarsData::Instance();
     ui = new Ui::LocationDialog();
@@ -52,9 +52,9 @@
     }
 
     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() ) );
-    connect( ui->CountryFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( filterCity() ) );
+    connect( ui->CityFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( enqueueFilterCity() ) );
+    connect( ui->ProvinceFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( enqueueFilterCity() ) );
+    connect( ui->CountryFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( enqueueFilterCity() ) );
     connect( ui->NewCityName, SIGNAL( textChanged( const QString & ) ), this, SLOT( nameChanged() ) );
     connect( ui->NewProvinceName, SIGNAL( textChanged( const QString & ) ), this, SLOT( nameChanged() ) );
     connect( ui->NewCountryName, SIGNAL( textChanged( const QString & ) ), this, SLOT( nameChanged() ) );
@@ -122,6 +122,18 @@
     }
 }
 
+void LocationDialog::enqueueFilterCity() {
+    if( timer )
+        timer->stop();
+    else {
+        timer = new QTimer( this );
+        timer->setSingleShot( true );
+        connect( timer, SIGNAL( timeout() ), this, SLOT( filterCity() ) );
+    }
+    timer->start( 500 );
+}
+
+
 void LocationDialog::filterCity() {
     KStarsData* data = KStarsData::Instance();
     ui->GeoBox->clear();
--- trunk/KDE/kdeedu/kstars/kstars/dialogs/locationdialog.h #1061133:1061134
@@ -45,6 +45,7 @@
 #include <QVBoxLayout>
 #include <QHBoxLayout>
 #include <QGridLayout>
+#include <QTimer>
 
 #include <kdialog.h>
 #include "geolocation.h"
@@ -77,7 +78,8 @@
     /**@return pointer to the List of filtered city pointers. */
     QList<GeoLocation*> filteredList() { return filteredCityList; }
 
-    /**@short Show only cities within 3 degrees of point specified by arguments
+    /**
+     * @short Show only cities within 3 degrees of point specified by arguments
      * @param longitude the longitude of the search point (int)
      * @param latitude the latitude of the search point (int)
      */
@@ -96,12 +98,19 @@
     bool addCityEnabled();
 
 public slots:
-    /**When text is entered in the City/Province/Country Filter KLineEdits,
-     * the List of cities is trimmed to show only cities beginning with the entered text.
-     * Also, the QMemArray of ID numbers is kept in sync with the filtered list.
+    /**
+     * When text is entered in the City/Province/Country Filter
+     * KLineEdits, the List of cities is trimmed to show only cities
+     * beginning with the entered text.  Also, the QMemArray of ID
+     * numbers is kept in sync with the filtered list.
      */
     void filterCity();
 
+    /**
+     * @short Filter by city / province / country only after a few milliseconds
+     */
+    void enqueueFilterCity();
+
     /**When the selected city in the QListBox changes, repaint the MapCanvas
      * so that the crosshairs icon appears on the newly selected city.
      */
@@ -128,6 +137,7 @@
     Ui::LocationDialog *ui;
     GeoLocation *SelectedCity;
     QList<GeoLocation*> filteredCityList;
+    QTimer *timer;
 };
 
 #endif


More information about the Kstars-devel mailing list