24 #include <QVBoxLayout>
28 class SearchWidgetPrivate
31 SearchRunnerManager* m_runnerManager;
32 SearchInputWidget *m_searchField;
33 QListView *m_searchResultView;
35 BranchFilterProxyModel m_branchfilter;
36 QSortFilterProxyModel m_sortproxy;
37 GeoDataDocument *m_document;
39 SearchWidgetPrivate();
40 void setSearchResult( QVector<GeoDataPlacemark*> );
43 void centerMapOn(
const QModelIndex &index );
46 SearchWidgetPrivate::SearchWidgetPrivate() :
49 m_searchResultView( 0 ),
53 m_document( new GeoDataDocument )
55 m_document->setName( QObject::tr(
"Search Results" ) );
58 void SearchWidgetPrivate::setSearchResult( QVector<GeoDataPlacemark *> locations )
60 if( locations.isEmpty() ) {
68 m_widget->model()->placemarkSelectionModel()->clear();
69 GeoDataTreeModel *treeModel = m_widget->model()->treeModel();
70 treeModel->removeDocument( m_document );
72 m_document->setName( QString( QObject::tr(
"Search for '%1'" ) ).arg( m_searchField->text() ) );
73 foreach (GeoDataPlacemark *placemark, locations ) {
74 m_document->append(
new GeoDataPlacemark( *placemark ) );
76 treeModel->addDocument( m_document );
77 m_branchfilter.setBranchIndex( treeModel, treeModel->index( m_document ) );
78 m_searchResultView->setRootIndex(
79 m_sortproxy.mapFromSource(
80 m_branchfilter.mapFromSource( treeModel->index( m_document ) ) ) );
81 m_widget->centerOn( m_document->latLonAltBox() );
82 mDebug() << Q_FUNC_INFO <<
" Time elapsed:"<< timer.elapsed() <<
" ms";
87 d( new SearchWidgetPrivate )
90 d->m_sortproxy.sort( 0, Qt::AscendingOrder );
91 d->m_sortproxy.setDynamicSortFilter(
true );
92 d->m_sortproxy.setSourceModel( &d->m_branchfilter );
95 setFocusProxy( d->m_searchField );
99 d->m_searchResultView =
new QListView(
this );
100 d->m_searchResultView->setModel( &d->m_sortproxy );
101 d->m_searchResultView->setMinimumSize( 0, 0 );
102 connect( d->m_searchResultView, SIGNAL(activated(QModelIndex)),
103 this, SLOT(centerMapOn(QModelIndex)) );
105 QVBoxLayout* layout =
new QVBoxLayout;
106 layout->addWidget( d->m_searchField );
107 layout->addWidget( d->m_searchResultView );
108 layout->setMargin( 0 );
123 d->m_widget = widget;
130 connect( d->m_runnerManager, SIGNAL(searchResultChanged(QVector<GeoDataPlacemark*>)),
131 this, SLOT(setSearchResult(QVector<GeoDataPlacemark*>)) );
132 connect( d->m_runnerManager, SIGNAL(searchFinished(QString)),
133 d->m_searchField, SLOT(disableSearchAnimation()));
138 d->m_branchfilter.setSourceModel( treeModel );
139 d->m_branchfilter.setBranchIndex( treeModel, treeModel->
index( d->m_document ) );
141 d->m_searchResultView->setRootIndex(
142 d->m_sortproxy.mapFromSource(
143 d->m_branchfilter.mapFromSource( treeModel->
index( d->m_document ) ) ) );
146 void SearchWidgetPrivate::search(
const QString &searchTerm,
SearchMode searchMode )
148 if( searchTerm.isEmpty() ) {
152 m_runnerManager->findPlacemarks( searchTerm, m_widget->viewport()->viewLatLonAltBox() );
154 m_runnerManager->findPlacemarks( searchTerm );
159 void SearchWidgetPrivate::clearSearch()
161 m_widget->model()->placemarkSelectionModel()->clear();
164 GeoDataTreeModel *treeModel = m_widget->model()->treeModel();
165 treeModel->removeDocument( m_document );
167 treeModel->addDocument( m_document );
168 m_branchfilter.setBranchIndex( treeModel, treeModel->index( m_document ) );
169 m_searchResultView->setRootIndex(
170 m_sortproxy.mapFromSource(
171 m_branchfilter.mapFromSource( treeModel->index( m_document ) ) ) );
174 m_runnerManager->findPlacemarks( QString() );
177 void SearchWidgetPrivate::centerMapOn(
const QModelIndex &index )
179 if( !index.isValid() ) {
182 GeoDataObject *
object
184 GeoDataPlacemark *placemark =
dynamic_cast<GeoDataPlacemark*
>( object );
186 m_widget->centerOn( *placemark,
true );
187 m_widget->model()->placemarkSelectionModel()->select( index, QItemSelectionModel::ClearAndSelect );
193 #include "SearchWidget.moc"
SearchMode
Search mode: Global (worldwide) versus area (local, regional) search.
A 3d point representation.
The representation of GeoData in a model This class represents all available data given by kml-data f...
This file contains the headers for MarbleModel.
Search a certain region of a planet (e.g. visible region)
The pointer to a specific object.
int addDocument(GeoDataDocument *document)
This file contains the headers for ViewportParams.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
QDebug mDebug()
a function to replace qDebug() in Marble library code
QAbstractItemModel * placemarkModel()