8#include "ui_GoToDialog.h"
10#include "BookmarkManager.h"
13#include "MarblePlacemarkModel.h"
14#include "GeoDataLookAt.h"
15#include "GeoDataTreeModel.h"
16#include "GeoDataDocument.h"
17#include "GeoDataFolder.h"
18#include "GeoDataPlacemark.h"
19#include "PositionTracking.h"
20#include "SearchRunnerManager.h"
21#include "routing/RoutingManager.h"
22#include "routing/RouteRequest.h"
24#include <QAbstractListModel>
35 TargetModel( MarbleModel* marbleModel,
QObject *
parent =
nullptr );
41 void setShowRoutingItems(
bool show );
44 QVariant currentLocationData (
int role )
const;
48 QVariant homeData (
int role )
const;
54 MarbleModel *
const m_marbleModel;
58 bool m_hasCurrentLocation;
60 bool m_showRoutingItems;
63class GoToDialogPrivate :
public Ui::GoTo
68 GeoDataCoordinates m_coordinates;
70 MarbleModel *
const m_marbleModel;
72 TargetModel m_targetModel;
74 SearchRunnerManager m_runnerManager;
76 GeoDataDocument *m_searchResult;
78 GeoDataTreeModel m_searchResultModel;
86 GoToDialogPrivate( GoToDialog* parent, MarbleModel* marbleModel );
90 void createProgressAnimation();
96 void updateSearchMode();
98 void updateProgress();
100 void stopProgressAnimation();
102 void updateResultMessage(
int results );
105TargetModel::TargetModel( MarbleModel *marbleModel,
QObject * parent ) :
107 m_marbleModel( marbleModel ),
108 m_hasCurrentLocation( false ),
109 m_showRoutingItems( true )
111 BookmarkManager* manager = m_marbleModel->bookmarkManager();
112 for( GeoDataFolder * folder: manager->folders() ) {
117 for ( ; iter !=
end; ++iter ) {
118 m_bookmarks.push_back( *iter );
122 PositionTracking* tracking = m_marbleModel->positionTracking();
123 m_hasCurrentLocation = tracking && tracking->status() == PositionProviderStatusAvailable;
128 if ( !m_showRoutingItems ) {
132 RouteRequest* request = m_marbleModel->routingManager()->routeRequest();
134 for (
int i = 0; i < request->size(); ++i ) {
135 if ( request->at( i ).isValid() ) {
136 GeoDataPlacemark placemark;
137 placemark.setCoordinate( request->at( i ) );
138 placemark.setName( request->name( i ) );
145int TargetModel::rowCount (
const QModelIndex & parent )
const
149 result += m_hasCurrentLocation ? 1 : 0;
150 result += viaPoints().size();
152 result += m_bookmarks.size();
159QVariant TargetModel::currentLocationData (
int role )
const
161 const PositionTracking* tracking = m_marbleModel->positionTracking();
162 if ( tracking->status() == PositionProviderStatusAvailable ) {
163 GeoDataCoordinates currentLocation = tracking->currentLocation();
165 case Qt::DisplayRole:
return tr(
"Current Location: %1" ).arg( currentLocation.toString() ) ;
167 case MarblePlacemarkModel::CoordinateRole: {
178 RouteRequest* request = m_marbleModel->routingManager()->routeRequest();
182 case MarblePlacemarkModel::CoordinateRole: {
183 const GeoDataCoordinates coordinates = via.
at( index ).coordinate();
191QVariant TargetModel::homeData (
int role )
const
196 case MarblePlacemarkModel::CoordinateRole: {
197 qreal lon( 0.0 ), lat( 0.0 );
199 m_marbleModel->home( lon, lat, zoom );
200 const GeoDataCoordinates coordinates = GeoDataCoordinates( lon, lat, 0, GeoDataCoordinates::Degree );
208QVariant TargetModel::bookmarkData (
int index,
int role )
const
212 const GeoDataFolder *folder = geodata_cast<GeoDataFolder>(m_bookmarks[index]->parent());
213 Q_ASSERT( folder &&
"Internal bookmark representation has changed. Please report this as a bug at https://bugs.kde.org." );
220 case MarblePlacemarkModel::CoordinateRole:
return QVariant::fromValue( m_bookmarks[index]->lookAt()->coordinates() );
229 if ( index.
isValid() && index.
row() >= 0 && index.
row() < rowCount() ) {
230 int row = index.
row();
231 bool const isCurrentLocation = row == 0 && m_hasCurrentLocation;
232 int homeOffset = m_hasCurrentLocation ? 1 : 0;
234 bool const isRoute = row >= homeOffset && row < homeOffset + via.
size();
236 if ( isCurrentLocation ) {
237 return currentLocationData( role );
238 }
else if ( isRoute ) {
239 int routeIndex = row - homeOffset;
240 Q_ASSERT( routeIndex >= 0 && routeIndex < via.
size() );
241 return routeData( via, routeIndex, role );
243 int bookmarkIndex = row - homeOffset - via.
size();
244 if ( bookmarkIndex == 0 ) {
245 return homeData( role );
248 Q_ASSERT( bookmarkIndex >= 0 && bookmarkIndex < m_bookmarks.size() );
249 return bookmarkData( bookmarkIndex, role );
257void TargetModel::setShowRoutingItems(
bool show )
259 m_showRoutingItems = show;
264void GoToDialogPrivate::createProgressAnimation()
266 bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
267 int const iconSize = smallScreen ? 32 : 16;
270 qreal
const h = iconSize / 2.0;
271 qreal
const q = h / 2.0;
273 qreal
const r = d / 2.0;
283 for(
double t = 0.0; t < 2 * M_PI; t += M_PI / 8.0 ) {
285 QRectF firstCircle( h - r + q * cos( t ), h - r + q * sin( t ), d, d );
286 QRectF secondCircle( h - r + q * cos( t + M_PI ), h - r + q * sin( t + M_PI ), d, d );
287 painter.drawEllipse( firstCircle );
288 painter.drawEllipse( secondCircle );
293GoToDialogPrivate::GoToDialogPrivate( GoToDialog* parent, MarbleModel* marbleModel ) :
295 m_marbleModel( marbleModel ),
296 m_targetModel( marbleModel ),
297 m_runnerManager( marbleModel ),
298 m_searchResult( new GeoDataDocument ),
303 m_progressTimer.setInterval( 100 );
306void GoToDialogPrivate::saveSelection(
const QModelIndex &index )
308 if ( searchButton->isChecked() && m_searchResult->size() ) {
309 QVariant coordinates = m_searchResultModel.
data( index, MarblePlacemarkModel::CoordinateRole );
310 m_coordinates = coordinates.
value<GeoDataCoordinates>();
312 QVariant coordinates = index.
data( MarblePlacemarkModel::CoordinateRole );
313 m_coordinates = coordinates.
value<GeoDataCoordinates>();
318void GoToDialogPrivate::startSearch()
325 m_runnerManager.findPlacemarks( searchTerm );
326 if ( m_progressAnimation.isEmpty() ) {
327 createProgressAnimation();
329 m_progressTimer.start();
330 progressButton->setVisible(
true );
331 searchLineEdit->setEnabled(
false );
332 updateResultMessage( 0 );
337 m_searchResultModel.setRootDocument(
nullptr );
338 m_searchResult->clear();
339 for (GeoDataPlacemark *placemark: placemarks) {
340 m_searchResult->append(
new GeoDataPlacemark( *placemark ) );
342 m_searchResultModel.setRootDocument( m_searchResult );
343 bookmarkListView->setModel( &m_searchResultModel );
344 updateResultMessage( m_searchResultModel.rowCount() );
349 d( new GoToDialogPrivate( this, marbleModel ) )
351 d->searchLineEdit->setPlaceholderText( tr(
"Address or search term" ) );
353 d->m_searchResultModel.setRootDocument( d->m_searchResult );
354 d->bookmarkListView->setModel( &d->m_targetModel );
357 connect( d->searchLineEdit, SIGNAL(returnPressed()),
358 this, SLOT(startSearch()) );
360 connect( d->searchButton, SIGNAL(clicked(
bool)),
361 this, SLOT(updateSearchMode()) );
362 connect( d->browseButton, SIGNAL(clicked(
bool)),
363 this, SLOT(updateSearchMode()) );
364 connect( &d->m_progressTimer, SIGNAL(timeout()),
365 this, SLOT(updateProgress()) );
366 connect( d->progressButton, SIGNAL(clicked(
bool)),
367 this, SLOT(stopProgressAnimation()) );
368 d->updateSearchMode();
369 d->progressButton->setVisible(
false );
374 this, SLOT(stopProgressAnimation()) );
377GoToDialog::~GoToDialog()
384 return d->m_coordinates;
387void GoToDialog::setShowRoutingItems(
bool show )
389 d->m_targetModel.setShowRoutingItems( show );
392void GoToDialog::setSearchEnabled(
bool enabled )
394 d->browseButton->setVisible( enabled );
395 d->searchButton->setVisible( enabled );
397 d->searchButton->setChecked(
false );
398 d->updateSearchMode();
402void GoToDialogPrivate::updateSearchMode()
404 bool const searchEnabled = searchButton->isChecked();
405 searchLineEdit->setVisible( searchEnabled );
406 descriptionLabel->setVisible( searchEnabled );
407 progressButton->setVisible( searchEnabled && m_progressTimer.isActive() );
408 if ( searchEnabled ) {
409 bookmarkListView->setModel( &m_searchResultModel );
410 searchLineEdit->setFocus();
412 bookmarkListView->setModel( &m_targetModel );
416void GoToDialogPrivate::updateProgress()
418 if ( !m_progressAnimation.isEmpty() ) {
419 m_currentFrame = ( m_currentFrame + 1 ) % m_progressAnimation.size();
420 QIcon frame = m_progressAnimation[m_currentFrame];
421 progressButton->setIcon( frame );
425void GoToDialogPrivate::stopProgressAnimation()
427 searchLineEdit->setEnabled(
true );
428 m_progressTimer.stop();
429 updateResultMessage( bookmarkListView->model()->rowCount() );
430 progressButton->setVisible(
false );
433void GoToDialogPrivate::updateResultMessage(
int results )
437 descriptionLabel->setText(
QObject::tr(
"%n result(s) found.",
"Number of search results", results ) );
442#include "moc_GoToDialog.cpp"
443#include "GoToDialog.moc"
This file contains the headers for MarbleModel.
A 3d point representation.
QAction * zoom(const QObject *recvr, const char *slot, QObject *parent)
const QList< QKeySequence > & end()
QString name(StandardShortcut id)
Binds a QML item to a specific geodetic location in screen coordinates.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
const_reference at(qsizetype i) const const
const_iterator constBegin() const const
const_iterator constEnd() const const
void push_back(parameter_type value)
qsizetype size() const const
QVariant data(int role) const const
bool isValid() const const
QObject * parent() const const
T qobject_cast(QObject *object)
QString tr(const char *sourceText, const char *disambiguation, int n)
QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags)
bool isEmpty() const const
QString trimmed() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QVariant fromValue(T &&value)