• 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
NavigationWidget.cpp
Go to the documentation of this file.
1 // 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 2004-2007 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007 Inge Wallin <ingwa@kde.org>
10 // Copyright 2007 Thomas Zander <zander@kde.org>
11 // Copyright 2010 Bastian Holst <bastianholst@gmx.de>
12 //
13 
14 // Self
15 #include "NavigationWidget.h"
16 
17 // Marble
18 #include "MarbleDebug.h"
19 #include "MarbleModel.h"
20 #include "MarbleWidget.h"
21 #include "MarblePlacemarkModel.h"
22 #include "BranchFilterProxyModel.h"
23 #include "GeoDataDocument.h"
24 #include "GeoDataTreeModel.h"
25 #include "GeoSceneDocument.h"
26 #include "GeoSceneHead.h"
27 #include "SearchRunnerManager.h"
28 #include "ViewportParams.h"
29 
30 // Qt
31 #include <QTime>
32 #include <QTimer>
33 #include <QSortFilterProxyModel>
34 
35 using namespace Marble;
36 
37 #include "ui_NavigationWidget.h"
38 
39 namespace Marble
40 {
41 
42 class NavigationWidgetPrivate
43 {
44  public:
45  NavigationWidgetPrivate();
46 
47  void updateButtons( int );
48 
49  void mapCenterOnSignal( const QModelIndex & );
50 
51  void adjustForAnimation();
52  void adjustForStill();
53 
63  void setSearchResult( QVector<GeoDataPlacemark*> locations );
64 
65  Ui::NavigationWidget m_navigationUi;
66  MarbleWidget *m_widget;
67  BranchFilterProxyModel m_branchfilter;
68  QSortFilterProxyModel *m_sortproxy;
69  QString m_searchTerm;
70  SearchRunnerManager *m_runnerManager;
71  GeoDataDocument *m_document;
72 };
73 
74 NavigationWidgetPrivate::NavigationWidgetPrivate()
75  : m_widget( 0 ), m_sortproxy( 0 ), m_runnerManager( 0 ),
76  m_document( new GeoDataDocument ) {
77  m_document->setDocumentRole( SearchResultDocument );
78  m_document->setName( "Search Results" );
79 }
80 
81 
82 NavigationWidget::NavigationWidget( QWidget *parent, Qt::WindowFlags f )
83  : QWidget( parent, f ),
84  d( new NavigationWidgetPrivate() )
85 {
86  d->m_searchTerm.clear();
87  d->m_widget = 0;
88 
89  d->m_navigationUi.setupUi( this );
90  d->m_navigationUi.m_splitter->setStretchFactor( 0, 1 );
91  d->m_navigationUi.m_splitter->setStretchFactor( 1, 2 );
92  d->m_navigationUi.locationListView->setVisible( false );
93 
94  d->m_sortproxy = new QSortFilterProxyModel( this );
95  d->m_navigationUi.locationListView->setModel( d->m_sortproxy );
96  connect( d->m_navigationUi.goHomeButton, SIGNAL(clicked()),
97  this, SIGNAL(goHome()) );
98  connect( d->m_navigationUi.zoomSlider, SIGNAL(valueChanged(int)),
99  this, SIGNAL(zoomChanged(int)) );
100  connect( d->m_navigationUi.zoomInButton, SIGNAL(clicked()),
101  this, SIGNAL(zoomIn()) );
102  connect( d->m_navigationUi.zoomOutButton, SIGNAL(clicked()),
103  this, SIGNAL(zoomOut()) );
104 
105  connect( d->m_navigationUi.zoomSlider, SIGNAL(valueChanged(int)),
106  this, SLOT(updateButtons(int)) );
107 
108  connect( d->m_navigationUi.moveLeftButton, SIGNAL(clicked()),
109  this, SIGNAL(moveLeft()) );
110  connect( d->m_navigationUi.moveRightButton, SIGNAL(clicked()),
111  this, SIGNAL(moveRight()) );
112  connect( d->m_navigationUi.moveUpButton, SIGNAL(clicked()),
113  this, SIGNAL(moveUp()) );
114  connect( d->m_navigationUi.moveDownButton, SIGNAL(clicked()),
115  this, SIGNAL(moveDown()) );
116 
117  connect( d->m_navigationUi.locationListView, SIGNAL(activated(QModelIndex)),
118  this, SLOT(mapCenterOnSignal(QModelIndex)) );
119 
120  connect( d->m_navigationUi.zoomSlider, SIGNAL(sliderPressed()),
121  this, SLOT(adjustForAnimation()) );
122  connect( d->m_navigationUi.zoomSlider, SIGNAL(sliderReleased()),
123  this, SLOT(adjustForStill()) );
124 }
125 
126 NavigationWidget::~NavigationWidget()
127 {
128  delete d;
129 }
130 
131 void NavigationWidget::setMarbleWidget( MarbleWidget *widget )
132 {
133  GeoDataTreeModel *treeModel;
134 
135  d->m_runnerManager = new SearchRunnerManager( widget->model(), this );
136  connect( d->m_runnerManager, SIGNAL(searchResultChanged(QVector<GeoDataPlacemark*>)),
137  this, SLOT(setSearchResult(QVector<GeoDataPlacemark*>)) );
138  connect( d->m_runnerManager, SIGNAL(searchFinished(QString)), this, SIGNAL(searchFinished()) );
139 
140  d->m_widget = widget;
141  treeModel = d->m_widget->model()->treeModel();
142  treeModel->addDocument( d->m_document );
143 
144  d->m_branchfilter.setSourceModel( treeModel );
145  d->m_branchfilter.setBranchIndex( treeModel, treeModel->index( d->m_document ) );
146  d->m_sortproxy->setSortRole( MarblePlacemarkModel::PopularityIndexRole );
147  d->m_sortproxy->sort( 0, Qt::AscendingOrder );
148  d->m_sortproxy->setDynamicSortFilter( true );
149  d->m_sortproxy->setSourceModel( &d->m_branchfilter );
150  d->m_navigationUi.locationListView->setRootIndex(
151  d->m_sortproxy->mapFromSource(
152  d->m_branchfilter.mapFromSource( treeModel->index( d->m_document ) ) ) );
153 
154  // Connect necessary signals.
155  connect( this, SIGNAL(goHome()), d->m_widget, SLOT(goHome()) );
156  connect( this, SIGNAL(zoomChanged(int)), d->m_widget, SLOT(setZoom(int)) );
157  connect( this, SIGNAL(zoomIn()), d->m_widget, SLOT(zoomIn()) );
158  connect( this, SIGNAL(zoomOut()), d->m_widget, SLOT(zoomOut()) );
159 
160  connect( this, SIGNAL(moveLeft()), d->m_widget, SLOT(moveLeft()) );
161  connect( this, SIGNAL(moveRight()), d->m_widget, SLOT(moveRight()) );
162  connect( this, SIGNAL(moveUp()), d->m_widget, SLOT(moveUp()) );
163  connect( this, SIGNAL(moveDown()), d->m_widget, SLOT(moveDown()) );
164 
165  connect( d->m_widget, SIGNAL(zoomChanged(int)),
166  this, SLOT(changeZoom(int)) );
167 
168  connect( d->m_widget, SIGNAL(themeChanged(QString)),
169  this, SLOT(selectTheme(QString)) );
170 }
171 
172 void NavigationWidget::search(const QString &searchTerm, SearchMode searchMode )
173 {
174  d->m_searchTerm = searchTerm;
175 
176  if( searchTerm.isEmpty() ) {
177  clearSearch();
178  } else {
179  d->m_navigationUi.locationListView->setVisible( true );
180  if ( searchMode == AreaSearch ) {
181  d->m_runnerManager->findPlacemarks( d->m_searchTerm, d->m_widget->viewport()->viewLatLonAltBox() );
182  } else {
183  d->m_runnerManager->findPlacemarks( d->m_searchTerm );
184  }
185  }
186 }
187 
188 void NavigationWidget::changeZoom( int zoom )
189 {
190  // There exists a circular signal/slot connection between MarbleWidget and this widget's
191  // zoom slider. MarbleWidget prevents recursion, but it still loops one time unless
192  // blocked here. Note that it would be possible to only connect the sliders
193  // sliderMoved signal instead of its valueChanged signal above to break up the loop.
194  // This however means that the slider cannot be operated with the mouse wheel, as this
195  // does not emit the sliderMoved signal for some reason. Therefore the signal is blocked
196  // below before calling setValue on the slider to avoid that it calls back to MarbleWidget,
197  // and then un-blocked again to make user interaction possible.
198 
199  d->m_navigationUi.zoomSlider->blockSignals( true );
200 
201  d->m_navigationUi.zoomSlider->setValue( zoom );
202  // As we have disabled all zoomSlider Signals, we have to update our buttons separately.
203  d->updateButtons( zoom );
204 
205  d->m_navigationUi.zoomSlider->blockSignals( false );
206 }
207 
208 void NavigationWidget::clearSearch()
209 {
210  d->m_searchTerm.clear();
211 
212  d->m_navigationUi.locationListView->setVisible( false );
213  d->m_widget->model()->placemarkSelectionModel()->clear();
214 
215  // clear the local document
216  GeoDataTreeModel *treeModel = d->m_widget->model()->treeModel();
217  treeModel->removeDocument( d->m_document );
218  d->m_document->clear();
219  treeModel->addDocument( d->m_document );
220  d->m_branchfilter.setBranchIndex( treeModel, treeModel->index( d->m_document ) );
221  d->m_navigationUi.locationListView->setRootIndex(
222  d->m_sortproxy->mapFromSource(
223  d->m_branchfilter.mapFromSource( treeModel->index( d->m_document ) ) ) );
224 
225  // clear cached search results
226  d->m_runnerManager->findPlacemarks( QString() );
227 }
228 
229 void NavigationWidgetPrivate::setSearchResult( QVector<GeoDataPlacemark*> locations )
230 {
231  if( locations.isEmpty() ) {
232  return;
233  }
234 
235  QTime t;
236  t.start();
237 
238  // fill the local document with results
239  m_widget->model()->placemarkSelectionModel()->clear();
240  GeoDataTreeModel *treeModel = m_widget->model()->treeModel();
241  treeModel->removeDocument( m_document );
242  m_document->clear();
243  foreach (GeoDataPlacemark *placemark, locations ) {
244  m_document->append( new GeoDataPlacemark( *placemark ) );
245  }
246  treeModel->addDocument( m_document );
247  m_branchfilter.setBranchIndex( treeModel, treeModel->index( m_document ) );
248  m_navigationUi.locationListView->setRootIndex(
249  m_sortproxy->mapFromSource(
250  m_branchfilter.mapFromSource( treeModel->index( m_document ) ) ) );
251  m_widget->centerOn( m_document->latLonAltBox() );
252  mDebug() << "NavigationWidget (searchResults): Time elapsed:"<< t.elapsed() << " ms";
253 }
254 
255 void NavigationWidget::selectTheme( const QString &theme )
256 {
257  Q_UNUSED( theme )
258 
259  if( d->m_widget ) {
260  d->m_navigationUi.zoomSlider->setMinimum( d->m_widget->minimumZoom() );
261  d->m_navigationUi.zoomSlider->setMaximum( d->m_widget->maximumZoom() );
262  d->updateButtons( d->m_navigationUi.zoomSlider->value() );
263  }
264 }
265 
266 void NavigationWidgetPrivate::updateButtons( int zoom )
267 {
268  if ( zoom <= m_navigationUi.zoomSlider->minimum() ) {
269  m_navigationUi.zoomInButton->setEnabled( true );
270  m_navigationUi.zoomOutButton->setEnabled( false );
271  } else if ( zoom >= m_navigationUi.zoomSlider->maximum() ) {
272  m_navigationUi.zoomInButton->setEnabled( false );
273  m_navigationUi.zoomOutButton->setEnabled( true );
274  } else {
275  m_navigationUi.zoomInButton->setEnabled( true );
276  m_navigationUi.zoomOutButton->setEnabled( true );
277  }
278 }
279 
280 void NavigationWidgetPrivate::mapCenterOnSignal( const QModelIndex &index )
281 {
282  if( !index.isValid() ) {
283  return;
284  }
285  GeoDataObject *object
286  = index.model()->data(index, MarblePlacemarkModel::ObjectPointerRole ).value<GeoDataObject*>();
287  GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( object );
288  if ( placemark ) {
289  m_widget->centerOn( *placemark, true );
290  m_widget->model()->placemarkSelectionModel()->select( index, QItemSelectionModel::ClearAndSelect );
291  }
292 }
293 
294 void NavigationWidgetPrivate::adjustForAnimation()
295 {
296  // TODO: use signals here as well
297  if ( m_widget ) {
298  m_widget->setViewContext( Animation );
299  }
300 }
301 
302 void NavigationWidgetPrivate::adjustForStill()
303 {
304  // TODO: use signals here as well
305  if ( m_widget ) {
306  m_widget->setViewContext( Still );
307  }
308 }
309 
310 void NavigationWidget::resizeEvent ( QResizeEvent * )
311 {
312  bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
313 
314  if ( smallScreen || height() < 390 ) {
315  if ( !d->m_navigationUi.zoomSlider->isHidden() ) {
316  setUpdatesEnabled(false);
317  d->m_navigationUi.zoomSlider->hide();
318  d->m_navigationUi.m_pSpacerFrame->setSizePolicy( QSizePolicy::Preferred,
319  QSizePolicy::Expanding );
320  setUpdatesEnabled(true);
321  }
322  } else {
323  if ( d->m_navigationUi.zoomSlider->isHidden() ) {
324  setUpdatesEnabled(false);
325  d->m_navigationUi.zoomSlider->show();
326  d->m_navigationUi.m_pSpacerFrame->setSizePolicy( QSizePolicy::Preferred,
327  QSizePolicy::Fixed );
328  setUpdatesEnabled(true);
329  }
330  }
331 }
332 
333 }
334 
335 #include "NavigationWidget.moc"
Marble::NavigationWidget::moveUp
void moveUp()
Signal emitted when the Move Up button has been pressed.
GeoSceneHead.h
Marble::NavigationWidget::setMarbleWidget
void setMarbleWidget(MarbleWidget *widget)
Set a MarbleWidget associated to this widget.
Definition: NavigationWidget.cpp:131
GeoDataDocument.h
Marble::NavigationWidget::moveLeft
void moveLeft()
Signal emitted when the Move Left button has been pressed.
Marble::SearchMode
SearchMode
Search mode: Global (worldwide) versus area (local, regional) search.
Definition: MarbleGlobal.h:179
Marble::GeoDataDocument
A container for Features, Styles and in the future Schemas.
Definition: GeoDataDocument.h:64
Marble::GeoDataTreeModel
The representation of GeoData in a model This class represents all available data given by kml-data f...
Definition: GeoDataTreeModel.h:32
MarbleModel.h
This file contains the headers for MarbleModel.
Marble::NavigationWidget::resizeEvent
void resizeEvent(QResizeEvent *)
Reimplementation of the resizeEvent() of the widget.
Definition: NavigationWidget.cpp:310
Marble::GeoDataObject
A base class for all geodata objects.
Definition: GeoDataObject.h:48
QWidget
Marble::NavigationWidget::searchFinished
void searchFinished()
Marble::AreaSearch
Search a certain region of a planet (e.g. visible region)
Definition: MarbleGlobal.h:181
GeoSceneDocument.h
Marble::SearchResultDocument
Definition: GeoDataDocument.h:45
Marble::MarblePlacemarkModel::ObjectPointerRole
The pointer to a specific object.
Definition: MarblePlacemarkModel.h:62
Marble::NavigationWidget::zoomOut
void zoomOut()
Signal emitted when the Zoom Out button has been pressed.
Marble::SearchRunnerManager
Definition: SearchRunnerManager.h:33
MarbleDebug.h
Marble::GeoDataTreeModel::addDocument
int addDocument(GeoDataDocument *document)
Definition: GeoDataTreeModel.cpp:595
Marble::MarbleWidget
A widget class that displays a view of the earth.
Definition: MarbleWidget.h:102
Marble::NavigationWidget::zoomChanged
void zoomChanged(int zoom)
Signal emitted when the zoom slider has been moved.
Marble::Animation
animated view (e.g. while rotating the globe)
Definition: MarbleGlobal.h:74
Marble::NavigationWidget::clearSearch
void clearSearch()
Clear all previous search results.
Definition: NavigationWidget.cpp:208
NavigationWidget.h
Marble::GeoDataTreeModel::removeDocument
void removeDocument(int index)
Definition: GeoDataTreeModel.cpp:646
Marble::Still
still image
Definition: MarbleGlobal.h:73
Marble::MarbleWidget::model
MarbleModel * model() const
Return the model that this view shows.
Definition: MarbleWidget.cpp:283
Marble::NavigationWidget::goHome
void goHome()
Signal emitted when the Home button has been pressed.
Marble::NavigationWidget::~NavigationWidget
~NavigationWidget()
Definition: NavigationWidget.cpp:126
MarblePlacemarkModel.h
BranchFilterProxyModel.h
GeoDataTreeModel.h
Marble::NavigationWidget::selectTheme
void selectTheme(const QString &)
Definition: NavigationWidget.cpp:255
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::MarbleGlobal::SmallScreen
Definition: MarbleGlobal.h:268
Marble::MarbleGlobal::getInstance
static MarbleGlobal * getInstance()
Definition: MarbleGlobal.cpp:37
Marble::MarblePlacemarkModel::PopularityIndexRole
The popularity index.
Definition: MarblePlacemarkModel.h:60
Marble::MarbleGlobal::profiles
Profiles profiles() const
Definition: MarbleGlobal.cpp:48
SearchRunnerManager.h
Marble::GeoDataTreeModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: GeoDataTreeModel.cpp:313
MarbleWidget.h
This file contains the headers for MarbleWidget.
Marble::NavigationWidget::moveRight
void moveRight()
Signal emitted when the Move Right button has been pressed.
Marble::NavigationWidget::search
void search(const QString &searchTerm, SearchMode searchMode)
Definition: NavigationWidget.cpp:172
Marble::BranchFilterProxyModel
Definition: BranchFilterProxyModel.h:21
Marble::NavigationWidget::changeZoom
void changeZoom(int zoom)
Sets the value of the slider.
Definition: NavigationWidget.cpp:188
Marble::NavigationWidget::NavigationWidget
NavigationWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: NavigationWidget.cpp:82
Marble::GeoDataPlacemark
a class representing a point of interest on the map
Definition: GeoDataPlacemark.h:54
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
Marble::NavigationWidget::moveDown
void moveDown()
Signal emitted when the Move Down button has been pressed.
Marble::NavigationWidget::zoomIn
void zoomIn()
Signal emitted when the Zoom In button has been pressed.
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:51 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