[Kstars-devel] KDE/kdeedu/kstars/kstars
Jason Harris
kstars at 30doradus.org
Sat Jun 28 00:25:43 CEST 2008
Speaking of the find object tool...
Akarsh, your patch to allow lowercase searches for M/NGC/IC objects
doesn't seem to be working. Would it be easier to just make the
search case-insensitive in all cases?
Jason
On Jun 27, 2008, at 1:35 PM, Jason Harris wrote:
> SVN commit 825333 by harris:
>
> Improve combined use of the "by name" and "by type" filtering in the
> Find Object tool. Prior to this commit, changing the object-type
> selection would clear the name filter edit box.
>
> CCMAIL: kstars-devel at kde.org
>
>
>
> M +85 -90 finddialog.cpp
> M +43 -39 finddialog.h
>
>
> --- trunk/KDE/kdeedu/kstars/kstars/finddialog.cpp #825332:825333
> @@ -68,7 +68,7 @@
> connect( this, SIGNAL( cancelClicked() ), this,
> SLOT( reject() ) );
> connect( ui->SearchBox, SIGNAL( textChanged( const QString
> & ) ), SLOT( enqueueSearch() ) );
> connect( ui->SearchBox, SIGNAL( returnPressed() ),
> SLOT( slotOk() ) );
> - connect( ui->FilterType, SIGNAL( activated( int ) ), this,
> SLOT( filterByType( int ) ) );
> + connect( ui->FilterType, SIGNAL( activated( int ) ), this,
> SLOT( enqueueSearch() ) );
> connect( ui->SearchList, SIGNAL( doubleClicked( const
> QModelIndex & ) ), SLOT( slotOk() ) );
>
>
> @@ -83,7 +83,61 @@
>
> void FindDialog::init() {
> ui->SearchBox->clear();
> + filterByType();
> + sortModel->sort( 0 );
> + initSelection();
> +}
>
> +void FindDialog::initSelection() {
> + if ( sortModel->rowCount() <= 0 ) {
> + button( Ok )->setEnabled( false );
> + return;
> + }
> +
> + if ( ui->SearchBox->text().isEmpty() ) {
> + //Pre-select the first item
> + QModelIndex selectItem = sortModel->index( 0, sortModel-
> >filterKeyColumn(), QModelIndex() );
> + switch ( ui->FilterType->currentIndex() ) {
> + case 0: //All objects, choose Andromeda galaxy
> + {
> + QModelIndex qmi = fModel->index( fModel-
> >stringList().indexOf( i18n("Andromeda Galaxy") ) );
> + selectItem = sortModel->mapFromSource( qmi );
> + break;
> + }
> + case 1: //Stars, choose Aldebaran
> + {
> + QModelIndex qmi = fModel->index( fModel-
> >stringList().indexOf( i18n("Aldebaran") ) );
> + selectItem = sortModel->mapFromSource( qmi );
> + break;
> + }
> + case 2: //Solar system or Asteroids, choose Aaltje
> + case 9:
> + {
> + QModelIndex qmi = fModel->index( fModel-
> >stringList().indexOf( i18n("Aaltje") ) );
> + selectItem = sortModel->mapFromSource( qmi );
> + break;
> + }
> + case 8: //Comets, choose 'Aarseth-Brewington (1989 W1)'
> + {
> + QModelIndex qmi = fModel->index( fModel-
> >stringList().indexOf( i18n("Aarseth-Brewington (1989 W1)") ) );
> + selectItem = sortModel->mapFromSource( qmi );
> + break;
> + }
> +
> + }
> +
> + if ( selectItem.isValid() ) {
> + ui->SearchList->selectionModel()->select( selectItem,
> QItemSelectionModel::ClearAndSelect );
> + ui->SearchList->scrollTo( selectItem );
> + ui->SearchList->setCurrentIndex( selectItem );
> + button( Ok )->setEnabled( true );
> + }
> + }
> +
> + listFiltered = true;
> +}
> +
> +void FindDialog::filterByType() {
> KStars *p = (KStars *)parent();
>
> switch ( ui->FilterType->currentIndex() ) {
> @@ -140,87 +194,28 @@
> fModel->setStringList( p->data()->skyComposite()-
> >objectNames( SkyObject::CONSTELLATION ) );
> break;
> }
> -
> - sortModel->sort( 0 );
> -
> - initSelection();
> }
>
> -void FindDialog::initSelection() {
> - if ( sortModel->rowCount() <= 0 ) {
> - button( Ok )->setEnabled( false );
> - return;
> - }
> -
> - if ( ui->SearchBox->text().isEmpty() ) {
> - //Pre-select the first item
> - QModelIndex selectItem = sortModel->index( 0, sortModel-
> >filterKeyColumn(), QModelIndex() );
> - switch ( ui->FilterType->currentIndex() ) {
> - case 0: //All objects, choose Andromeda galaxy
> - {
> - QModelIndex qmi = fModel->index( fModel-
> >stringList().indexOf( i18n("Andromeda Galaxy") ) );
> - selectItem = sortModel->mapFromSource( qmi );
> - break;
> - }
> - case 1: //Stars, choose Aldebaran
> - {
> - QModelIndex qmi = fModel->index( fModel-
> >stringList().indexOf( i18n("Aldebaran") ) );
> - selectItem = sortModel->mapFromSource( qmi );
> - break;
> - }
> - case 2: //Solar system or Asteroids, choose Aaltje
> - case 9:
> - {
> - QModelIndex qmi = fModel->index( fModel-
> >stringList().indexOf( i18n("Aaltje") ) );
> - selectItem = sortModel->mapFromSource( qmi );
> - break;
> - }
> - case 8: //Comets, choose 'Aarseth-Brewington (1989 W1)'
> - {
> - QModelIndex qmi = fModel->index( fModel-
> >stringList().indexOf( i18n("Aarseth-Brewington (1989 W1)") ) );
> - selectItem = sortModel->mapFromSource( qmi );
> - break;
> - }
> -
> - }
> -
> - if ( selectItem.isValid() ) {
> - ui->SearchList->selectionModel()->select( selectItem,
> QItemSelectionModel::ClearAndSelect );
> - ui->SearchList->scrollTo( selectItem );
> - ui->SearchList->setCurrentIndex( selectItem );
> - button( Ok )->setEnabled( true );
> - }
> - }
> -
> - listFiltered = true;
> -}
> -
> -void FindDialog::filterByType( int /*f*/ ) {
> - if ( timer ) {
> - timer->stop();
> - }
> -
> - init();
> - ui->SearchList->QWidget::setFocus();
> -}
> -
> -void FindDialog::filterByName() { //Filter the list of names with
> the string in the SearchBox
> +void FindDialog::filterList() {
> sortModel->setFilterFixedString( ui->SearchBox->text() );
> + filterByType();
> initSelection();
>
> //Select the first item in the list that begins with the filter
> string
> - QStringList mItems = fModel-
> >stringList().filter( QRegExp( '^'+ui->SearchBox->text(),
> Qt::CaseInsensitive ) );
> - mItems.sort();
> -
> - if ( mItems.size() ) {
> - QModelIndex qmi = fModel->index( fModel-
> >stringList().indexOf( mItems[0] ) );
> - QModelIndex selectItem = sortModel->mapFromSource( qmi );
> -
> - if ( selectItem.isValid() ) {
> - ui->SearchList->selectionModel()->select( selectItem,
> QItemSelectionModel::ClearAndSelect );
> - ui->SearchList->scrollTo( selectItem );
> - ui->SearchList->setCurrentIndex( selectItem );
> - button( Ok )->setEnabled( true );
> + if ( ! ui->SearchBox->text().isEmpty() ) {
> + QStringList mItems = fModel-
> >stringList().filter( QRegExp( '^'+ui->SearchBox->text(),
> Qt::CaseInsensitive ) );
> + mItems.sort();
> +
> + if ( mItems.size() ) {
> + QModelIndex qmi = fModel->index( fModel-
> >stringList().indexOf( mItems[0] ) );
> + QModelIndex selectItem = sortModel->mapFromSource( qmi );
> +
> + if ( selectItem.isValid() ) {
> + ui->SearchList->selectionModel()-
> >select( selectItem, QItemSelectionModel::ClearAndSelect );
> + ui->SearchList->scrollTo( selectItem );
> + ui->SearchList->setCurrentIndex( selectItem );
> + button( Ok )->setEnabled( true );
> + }
> }
> }
>
> @@ -246,7 +241,7 @@
> } else {
> timer = new QTimer( this );
> timer->setSingleShot( true );
> - connect( timer, SIGNAL( timeout() ), this,
> SLOT( filterByName() ) );
> + connect( timer, SIGNAL( timeout() ), this,
> SLOT( filterList() ) );
> }
> timer->start( 500 );
> }
> @@ -261,15 +256,15 @@
> // If it is an NGC/IC/M catalog number, as in "M 76" or "NGC
> 5139", check for absence of the space
> re.setPattern("^(m|ngc|ic)\\s*\\d*$");
> if(ui->SearchBox->text().contains(re)) {
> - QString searchtext = ui->SearchBox->text();
> - re.setPattern("\\s*(\\d+)");
> - searchtext.replace( re, " \\1" );
> - re.setPattern("\\s*$");
> - searchtext.replace(re, "");
> - re.setPattern("^\\s*");
> - searchtext.replace(re, "");
> - ui->SearchBox->setText(searchtext);
> - return;
> + QString searchtext = ui->SearchBox->text();
> + re.setPattern("\\s*(\\d+)");
> + searchtext.replace( re, " \\1" );
> + re.setPattern("\\s*$");
> + searchtext.replace(re, "");
> + re.setPattern("^\\s*");
> + searchtext.replace(re, "");
> + ui->SearchBox->setText(searchtext);
> + return;
> }
>
> // TODO after KDE 4.1 release:
> @@ -280,12 +275,12 @@
> void FindDialog::slotOk() {
> //If no valid object selected, show a sorry-box. Otherwise,
> emit accept()
> if(!listFiltered) {
> - processSearchText();
> - filterByName();
> + processSearchText();
> + filterList();
> }
> if(!selectedObject()) {
> - processSearchText();
> - filterByName();
> + processSearchText();
> + filterList();
> }
> if ( selectedObject() == 0 ) {
> QString message = i18n( "No object named %1 found.", ui-
> >SearchBox->text() );
> --- trunk/KDE/kdeedu/kstars/kstars/finddialog.h #825332:825333
> @@ -39,71 +39,69 @@
> };
>
> /**@class FindDialog
> - *Dialog window for finding SkyObjects by name. The dialog contains
> - *a QListBox showing the list of named objects, a QLineEdit for
> filtering
> - *the list by name, and a QCombobox for filtering the list by
> object type.
> - *
> - *@short Find Object Dialog
> - *@author Jason Harris
> - *@version 1.0
> - */
> + *Dialog window for finding SkyObjects by name. The dialog contains
> + *a QListBox showing the list of named objects, a QLineEdit for
> filtering
> + *the list by name, and a QCombobox for filtering the list by
> object type.
> + *
> + *@short Find Object Dialog
> + *@author Jason Harris
> + *@version 1.0
> + */
> class FindDialog : public KDialog {
> Q_OBJECT
>
> public:
> - /**Constructor. Creates all widgets and packs them in
> QLayouts. Connects
> - *Signals and Slots. Runs initObjectList().
> - */
> + /**
> + *Constructor. Creates all widgets and packs them in QLayouts.
> Connects
> + *Signals and Slots. Runs initObjectList().
> + */
> FindDialog( QWidget* parent = 0 );
>
> - /**Destructor
> - */
> + /**
> + *Destructor
> + */
> ~FindDialog();
>
> - /**@return the currently-selected item from the listbox of
> named objects
> - */
> + /**
> + *@return the currently-selected item from the listbox of named
> objects
> + */
> SkyObject* selectedObject() const;
>
> public slots:
> - /**When Text is entered in the QLineEdit, filter the List of
> objects
> - *so that only objects which start with the filter text are
> shown.
> - */
> - void filterByName();
> + /**
> + *When Text is entered in the QLineEdit, filter the List of
> objects
> + *so that only objects which start with the filter text are
> shown.
> + */
> + void filterList();
>
> //FIXME: Still valid for KDialog? i.e., does KDialog have a
> slotOk() ?
> - /**Overloading the Standard KDialogBase slotOk() to show a
> "sorry" message
> - *box if no object is selected when the user presses Ok. The
> window is
> - *not closed in this case.
> - */
> + /**
> + *Overloading the Standard KDialogBase slotOk() to show a
> "sorry" message
> + *box if no object is selected when the user presses Ok. The
> window is
> + *not closed in this case.
> + */
> void slotOk();
>
> private slots:
> /**
> - *Init object list after opening dialog.
> - */
> + *Init object list after opening dialog.
> + */
> void init();
>
> /**
> - *Set the selected item to the first item in the list
> - */
> + *Set the selected item to the first item in the list
> + */
> void initSelection();
>
> void enqueueSearch();
>
> - /**
> - *Filter the list of named objects according to the given
> object type
> - *@param f The integer representation of the object type
> - *@see SkyObject
> - */
> - void filterByType( int f );
> -
> protected:
> /**
> - *Process Keystrokes. The Up and Down arrow keys are used to
> select the
> - *Previous/Next item in the listbox of named objects. The Esc
> key closes
> - *the window with no selection, using reject().
> - *@param e The QKeyEvent pointer
> - */
> + *Process Keystrokes. The Up and Down arrow keys are used to
> select the
> + *Previous/Next item in the listbox of named objects. The Esc
> key closes
> + *the window with no selection, using reject().
> + *@param e The QKeyEvent pointer
> + */
> void keyPressEvent( QKeyEvent *e );
>
> private:
> @@ -116,6 +114,12 @@
> */
> void processSearchText();
>
> + /**
> + *@short pre-filter the list of objects according to
> + *the selected object type.
> + */
> + void filterByType();
> +
> FindDialogUI* ui;
> SkyObject* currentitem;
> QStringListModel *fModel;
> _______________________________________________
> Kstars-devel mailing list
> Kstars-devel at kde.org
> https://mail.kde.org/mailman/listinfo/kstars-devel
More information about the Kstars-devel
mailing list