Commit 1f1903c4 authored by Thibaut Gridel's avatar Thibaut Gridel
Browse files

NavigationWidget: hold a document for search results

This has 3 parts:
* runner manager doesn't return a model but a vector of placemarks
* search results are appended in MarbleModel treeModel
* the placemarks are displayed on the map automatically

BUG: 247676
parent 9b299620
......@@ -200,6 +200,7 @@ void MarbleRunnerManager::addSearchResult( QVector<GeoDataPlacemark*> result )
d->m_model->addPlacemarks( start, result.size() );
d->m_modelMutex.unlock();
emit searchResultChanged( d->m_model );
emit searchResultChanged( d->m_placemarkContainer );
}
void MarbleRunnerManager::setModel( MarbleModel * model )
......
......@@ -75,6 +75,7 @@ signals:
* @todo FIXME: this sounds like a duplication of QAbstractItemModel signals
*/
void searchResultChanged( QAbstractItemModel *model );
void searchResultChanged( QVector<GeoDataPlacemark*> result );
/**
* The search request for the given search term has finished, i.e. all
......
......@@ -20,6 +20,8 @@
#include "MarbleWidget.h"
#include "MarbleRunnerManager.h"
#include "MarblePlacemarkModel.h"
#include "GeoDataDocument.h"
#include "GeoDataTreeModel.h"
#include "GeoSceneDocument.h"
#include "GeoSceneHead.h"
......@@ -44,6 +46,15 @@ class NavigationWidgetPrivate
QString m_searchTerm;
MarbleRunnerManager *m_runnerManager;
QTimer m_deferSearch;
GeoDataTreeModel m_treeModel;
GeoDataDocument *m_document;
NavigationWidgetPrivate()
: m_document( new GeoDataDocument ) {
m_document->setDocumentRole( SearchResultDocument );
m_treeModel.setRootDocument( m_document );
};
};
NavigationWidget::NavigationWidget( QWidget *parent, Qt::WindowFlags f )
......@@ -104,18 +115,20 @@ NavigationWidget::~NavigationWidget()
void NavigationWidget::setMarbleWidget( MarbleWidget *widget )
{
d->m_runnerManager = new MarbleRunnerManager( widget->model()->pluginManager(), this );
connect( d->m_runnerManager, SIGNAL( searchResultChanged( QAbstractItemModel* ) ),
this, SLOT( setLocations( QAbstractItemModel* ) ) );
connect( d->m_runnerManager, SIGNAL( searchResultChanged( QVector<GeoDataPlacemark*> ) ),
this, SLOT( setLocations( QVector<GeoDataPlacemark*> ) ) );
d->m_widget = widget;
d->m_runnerManager->setModel( widget->model() );
d->m_widget->model()->treeModel()->addDocument( d->m_document );
d->m_sortproxy->setSortLocaleAware( true );
d->m_sortproxy->setDynamicSortFilter( true );
// Make us aware of all the Placemarks in the MarbleModel so that
// we can search them.
setLocations( d->m_widget->model()->placemarkModel() );
// FIXME: Why does this fail: "selection model works on a different model than the view..." ?
// d->m_navigationUi.locationListView->setSelectionModel( d->m_widget->placemarkSelectionModel() );
d->m_sortproxy->setSourceModel( d->m_widget->model()->placemarkModel() );
d->m_sortproxy->sort( 0 );
// Connect necessary signals.
connect( this, SIGNAL( goHome() ), d->m_widget, SLOT( goHome() ) );
......@@ -159,8 +172,17 @@ void NavigationWidget::searchLineChanged( const QString &search )
{
d->m_searchTerm = search;
// if search line is empty, restore original geonames
if ( d->m_searchTerm.isEmpty() )
setLocations( d->m_widget->model()->placemarkModel() );
if ( d->m_searchTerm.isEmpty() ) {
// set the proxy list to the placemarkModel
d->m_sortproxy->setSourceModel( d->m_widget->model()->placemarkModel() );
d->m_sortproxy->sort( 0 );
d->m_widget->model()->placemarkSelectionModel()->clear();
// clear the local document
d->m_widget->model()->treeModel()->removeDocument( d->m_document );
d->m_document->clear();
d->m_widget->model()->treeModel()->addDocument( d->m_document );
}
d->m_deferSearch.start( 500 );
}
......@@ -181,15 +203,23 @@ void NavigationWidget::search()
d->m_navigationUi.locationListView->activate();
}
void NavigationWidget::setLocations(QAbstractItemModel* locations)
void NavigationWidget::setLocations( QVector<GeoDataPlacemark*> locations )
{
QTime t;
t.start();
d->m_sortproxy->setSourceModel( locations );
d->m_sortproxy->setSortLocaleAware( true );
d->m_sortproxy->setDynamicSortFilter( true );
d->m_sortproxy->sort( 0 );
// fill the local document with results
d->m_widget->model()->placemarkSelectionModel()->clear();
d->m_widget->model()->treeModel()->removeDocument( d->m_document );
d->m_document->clear();
foreach (GeoDataPlacemark *placemark, locations ) {
d->m_document->append( new GeoDataPlacemark( *placemark ) );
}
d->m_widget->model()->treeModel()->addDocument( d->m_document );
// set the proxy list to the list of results
d->m_sortproxy->setSourceModel( &d->m_treeModel );
d->m_sortproxy->sort( 0 );
mDebug() << "NavigationWidget (sort): Time elapsed:"<< t.elapsed() << " ms";
}
......
......@@ -29,6 +29,7 @@ namespace Marble
class NavigationWidgetPrivate;
class MarbleWidget;
class GeoDataPlacemark;
class MARBLE_EXPORT NavigationWidget : public QWidget
{
......@@ -91,7 +92,7 @@ class MARBLE_EXPORT NavigationWidget : public QWidget
* them.
* @see centerOn
*/
void setLocations( QAbstractItemModel* locations );
void setLocations( QVector<GeoDataPlacemark*> locations );
void selectTheme( const QString & );
......
......@@ -28,7 +28,8 @@ enum DocumentRole {
MapDocument,
UserDocument,
TrackingDocument,
BookmarkDocument
BookmarkDocument,
SearchResultDocument
};
namespace Marble
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment