• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • lib
  • marble
SearchInputWidget.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2012 Dennis Nienhüser <earthwings@gentoo.org>
9 // Copyright 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
10 //
11 
12 #include "SearchInputWidget.h"
13 
14 #include "MarblePlacemarkModel.h"
15 
16 #include <QCompleter>
17 #include <QMenu>
18 
19 namespace Marble {
20 
21 SearchInputWidget::SearchInputWidget( QWidget *parent ) :
22  MarbleLineEdit( parent ),
23  m_completer( new QCompleter( this ) ),
24  m_areaSearch( false )
25 {
26  updatePlaceholderText();
27  QPixmap const decorator = QPixmap( ":/icons/16x16/edit-find.png" );
28  Q_ASSERT( !decorator.isNull() );
29  setDecorator( decorator );
30 
31  connect( this, SIGNAL(clearButtonClicked()), this, SLOT(search()) );
32  connect( this, SIGNAL(returnPressed()), this, SLOT(search()) );
33  connect( this, SIGNAL(decoratorButtonClicked()), this, SLOT(showDropDownMenu()) );
34 
35  m_sortFilter.setSortRole( MarblePlacemarkModel::PopularityIndexRole );
36  m_sortFilter.sort( 0, Qt::AscendingOrder );
37  m_sortFilter.setDynamicSortFilter( true );
38 
39  m_completer->setCompletionRole( Qt::DisplayRole );
40  m_completer->setCaseSensitivity( Qt::CaseInsensitive );
41  m_completer->setModel( &m_sortFilter );
42  setCompleter( m_completer );
43  connect( m_completer, SIGNAL(activated(QModelIndex)), this, SLOT(centerOnSearchSuggestion(QModelIndex)) );
44 }
45 
46 void SearchInputWidget::setCompletionModel( QAbstractItemModel *completionModel )
47 {
48  m_sortFilter.setSourceModel( completionModel );
49 }
50 
51 void SearchInputWidget::search()
52 {
53  QString const searchTerm = text();
54  if ( !searchTerm.isEmpty() ) {
55  setBusy( true );
56  }
57  emit search( searchTerm, m_areaSearch ? AreaSearch : GlobalSearch );
58 }
59 
60 void SearchInputWidget::disableSearchAnimation()
61 {
62  setBusy( false );
63 }
64 
65 void SearchInputWidget::centerOnSearchSuggestion(const QModelIndex &index )
66 {
67  QAbstractItemModel const * model = completer()->completionModel();
68  QVariant const value = model->data( index, MarblePlacemarkModel::CoordinateRole );
69  GeoDataCoordinates const coordinates = value.value<GeoDataCoordinates>();
70  emit centerOn( coordinates );
71 }
72 
73 void SearchInputWidget::showDropDownMenu()
74 {
75  QMenu menu( this );
76  QAction* globalSearch = menu.addAction( tr( "Global Search" ), this, SLOT(setGlobalSearch()) );
77  globalSearch->setCheckable( true );
78  globalSearch->setChecked( !m_areaSearch );
79  QAction* areaSearch = menu.addAction( tr( "Area Search" ), this, SLOT(setAreaSearch()) );
80  areaSearch->setCheckable( true );
81  areaSearch->setChecked( m_areaSearch );
82  menu.exec( mapToGlobal( QPoint( 0, size().height() ) ) );
83 }
84 
85 void SearchInputWidget::setGlobalSearch()
86 {
87  m_areaSearch = false;
88  updatePlaceholderText();
89 }
90 
91 void SearchInputWidget::setAreaSearch()
92 {
93  m_areaSearch = true;
94  updatePlaceholderText();
95 }
96 
97 void SearchInputWidget::updatePlaceholderText()
98 {
99  setPlaceholderText( m_areaSearch ? tr( "Area Search" ) : tr ( "Global Search" ) );
100 }
101 
102 }
103 
104 #include "SearchInputWidget.moc"
Marble::SearchInputWidget::centerOn
void centerOn(const GeoDataCoordinates &coordinates)
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
search
Definition: google-search.qml:12
QWidget
Marble::AreaSearch
Search a certain region of a planet (e.g. visible region)
Definition: MarbleGlobal.h:181
Marble::GlobalSearch
Search a whole planet.
Definition: MarbleGlobal.h:180
Marble::MarbleLineEdit::setDecorator
void setDecorator(const QPixmap &decorator)
Definition: MarbleLineEdit.cpp:111
Marble::MarbleLineEdit
A QLineEdit with an embedded clear button.
Definition: MarbleLineEdit.h:32
Marble::SearchInputWidget::setCompletionModel
void setCompletionModel(QAbstractItemModel *completionModel)
Definition: SearchInputWidget.cpp:46
MarblePlacemarkModel.h
QAbstractItemModel
Marble::SearchInputWidget::disableSearchAnimation
void disableSearchAnimation()
Definition: SearchInputWidget.cpp:60
Marble::MarblePlacemarkModel::PopularityIndexRole
The popularity index.
Definition: MarblePlacemarkModel.h:60
Marble::MarblePlacemarkModel::CoordinateRole
The GeoDataCoordinates coordinate.
Definition: MarblePlacemarkModel.h:53
Marble::MarbleLineEdit::setBusy
void setBusy(bool busy)
Definition: MarbleLineEdit.cpp:131
SearchInputWidget.h
Marble::MarbleLineEdit::decoratorButtonClicked
void decoratorButtonClicked()
Marble::SearchInputWidget::SearchInputWidget
SearchInputWidget(QWidget *parent=0)
Definition: SearchInputWidget.cpp:21
Marble::MarbleLineEdit::clearButtonClicked
void clearButtonClicked()
The clear button was clicked with the left mouse button.
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal