13 #include "ui_GoToDialog.h"
27 #include <QAbstractListModel>
29 #include <QPushButton>
38 TargetModel( MarbleModel* marbleModel,
QObject * parent = 0 );
44 void setShowRoutingItems(
bool show );
47 QVariant currentLocationData (
int role )
const;
51 QVariant homeData (
int role )
const;
53 QVariant bookmarkData (
int index,
int role )
const;
57 MarbleModel *
const m_marbleModel;
61 bool m_hasCurrentLocation;
63 bool m_showRoutingItems;
66 class GoToDialogPrivate :
public Ui::GoTo
71 GeoDataCoordinates m_coordinates;
73 MarbleModel *
const m_marbleModel;
75 TargetModel m_targetModel;
77 SearchRunnerManager m_runnerManager;
79 GeoDataDocument *m_searchResult;
81 GeoDataTreeModel m_searchResultModel;
89 GoToDialogPrivate( GoToDialog* parent, MarbleModel* marbleModel );
93 void createProgressAnimation();
99 void updateSearchMode();
101 void updateProgress();
103 void stopProgressAnimation();
105 void updateResultMessage(
int results );
108 TargetModel::TargetModel( MarbleModel *marbleModel,
QObject * parent ) :
110 m_marbleModel( marbleModel ),
111 m_hasCurrentLocation( false ),
112 m_showRoutingItems( true )
114 BookmarkManager* manager = m_marbleModel->bookmarkManager();
115 foreach( GeoDataFolder * folder, manager->folders() ) {
120 for ( ; iter != end; ++iter ) {
121 m_bookmarks.push_back( *iter );
125 PositionTracking*
tracking = m_marbleModel->positionTracking();
131 if ( !m_showRoutingItems ) {
135 RouteRequest* request = m_marbleModel->routingManager()->routeRequest();
137 for (
int i = 0; i < request->size(); ++i ) {
138 if ( request->at( i ).longitude() != 0.0 || request->at( i ).latitude() != 0.0 ) {
139 GeoDataPlacemark placemark;
140 placemark.setCoordinate( request->at( i ) );
141 placemark.setName( request->name( i ) );
148 int TargetModel::rowCount (
const QModelIndex & parent )
const
152 result += m_hasCurrentLocation ? 1 : 0;
153 result += viaPoints().
size();
155 result += m_bookmarks.size();
162 QVariant TargetModel::currentLocationData (
int role )
const
164 PositionTracking* tracking = m_marbleModel->positionTracking();
166 GeoDataCoordinates currentLocation = tracking->currentLocation();
168 case Qt::DisplayRole:
return tr(
"Current Location: %1" ).arg( currentLocation.toString() ) ;
169 case Qt::DecorationRole:
return QIcon(
":/icons/gps.png" );
171 return qVariantFromValue( currentLocation );
181 RouteRequest* request = m_marbleModel->routingManager()->routeRequest();
183 case Qt::DisplayRole:
return via.
at( index ).name();
184 case Qt::DecorationRole:
return QIcon( request->pixmap( index ) );
186 const GeoDataCoordinates coordinates = via.
at( index ).coordinate();
187 return qVariantFromValue( coordinates );
194 QVariant TargetModel::homeData (
int role )
const
197 case Qt::DisplayRole:
return tr(
"Home" );
198 case Qt::DecorationRole:
return QIcon(
":/icons/go-home.png" );
200 qreal lon( 0.0 ), lat( 0.0 );
202 m_marbleModel->home( lon, lat, zoom );
204 return qVariantFromValue( coordinates );
211 QVariant TargetModel::bookmarkData (
int index,
int role )
const
214 case Qt::DisplayRole: {
215 GeoDataFolder* folder =
dynamic_cast<GeoDataFolder*
>( m_bookmarks[index]->parent() );
216 Q_ASSERT( folder &&
"Internal bookmark representation has changed. Please report this as a bug at http://bugs.kde.org." );
221 case Qt::DecorationRole:
return QIcon(
":/icons/bookmarks.png" );
231 if ( index.
isValid() && index.
row() >= 0 && index.
row() < rowCount() ) {
232 int row = index.
row();
233 bool const isCurrentLocation = row == 0 && m_hasCurrentLocation;
234 int homeOffset = m_hasCurrentLocation ? 1 : 0;
236 bool const isRoute = row >= homeOffset && row < homeOffset + via.
size();
238 if ( isCurrentLocation ) {
239 return currentLocationData( role );
240 }
else if ( isRoute ) {
241 int routeIndex = row - homeOffset;
242 Q_ASSERT( routeIndex >= 0 && routeIndex < via.
size() );
243 return routeData( via, routeIndex, role );
245 int bookmarkIndex = row - homeOffset - via.
size();
246 if ( bookmarkIndex == 0 ) {
247 return homeData( role );
250 Q_ASSERT( bookmarkIndex >= 0 && bookmarkIndex < m_bookmarks.size() );
251 return bookmarkData( bookmarkIndex, role );
259 void TargetModel::setShowRoutingItems(
bool show )
261 m_showRoutingItems = show;
266 void GoToDialogPrivate::createProgressAnimation()
269 int const iconSize = smallScreen ? 32 : 16;
272 qreal
const h = iconSize / 2.0;
273 qreal
const q = h / 2.0;
275 qreal
const r = d / 2.0;
278 QImage canvas( iconSize, iconSize, QImage::Format_ARGB32 );
280 painter.setRenderHint( QPainter::Antialiasing,
true );
281 painter.setPen(
QColor ( Qt::gray ) );
282 painter.setBrush(
QColor( Qt::white ) );
285 for(
double t = 0.0; t < 2 *
M_PI; t += M_PI / 8.0 ) {
286 canvas.fill( Qt::transparent );
287 QRectF firstCircle( h - r + q * cos( t ), h - r + q * sin( t ), d, d );
288 QRectF secondCircle( h - r + q * cos( t + M_PI ), h - r + q * sin( t + M_PI ), d, d );
289 painter.drawEllipse( firstCircle );
290 painter.drawEllipse( secondCircle );
295 GoToDialogPrivate::GoToDialogPrivate( GoToDialog* parent, MarbleModel* marbleModel ) :
297 m_marbleModel( marbleModel ),
298 m_targetModel( marbleModel ),
299 m_runnerManager( marbleModel ),
300 m_searchResult( new GeoDataDocument ),
305 m_progressTimer.setInterval( 100 );
308 void GoToDialogPrivate::saveSelection(
const QModelIndex &index )
310 if ( searchButton->isChecked() && m_searchResult->size() ) {
312 m_coordinates = coordinates.
value<GeoDataCoordinates>();
315 m_coordinates = coordinates.
value<GeoDataCoordinates>();
320 void GoToDialogPrivate::startSearch()
327 m_runnerManager.findPlacemarks( searchTerm );
328 if ( m_progressAnimation.isEmpty() ) {
329 createProgressAnimation();
331 m_progressTimer.start();
332 progressButton->setVisible(
true );
333 searchLineEdit->setEnabled(
false );
334 updateResultMessage( 0 );
339 m_searchResultModel.setRootDocument( 0 );
340 m_searchResult->clear();
341 foreach (GeoDataPlacemark *placemark, placemarks) {
342 m_searchResult->append(
new GeoDataPlacemark( *placemark ) );
344 m_searchResultModel.setRootDocument( m_searchResult );
345 bookmarkListView->setModel( &m_searchResultModel );
346 updateResultMessage( m_searchResultModel.rowCount() );
351 d( new GoToDialogPrivate( this, marbleModel ) )
356 #endif // Q_WS_MAEMO_5
358 d->searchLineEdit->setPlaceholderText(
tr(
"Address or search term" ) );
360 d->m_searchResultModel.setRootDocument( d->m_searchResult );
361 d->bookmarkListView->setModel( &d->m_targetModel );
364 connect( d->searchLineEdit, SIGNAL(returnPressed()),
365 this, SLOT(startSearch()) );
366 d->buttonBox->button( QDialogButtonBox::Close )->setAutoDefault(
false );
367 connect( d->searchButton, SIGNAL(clicked(
bool)),
368 this, SLOT(updateSearchMode()) );
369 connect( d->browseButton, SIGNAL(clicked(
bool)),
370 this, SLOT(updateSearchMode()) );
371 connect( &d->m_progressTimer, SIGNAL(timeout()),
372 this, SLOT(updateProgress()) );
373 connect( d->progressButton, SIGNAL(clicked(
bool)),
374 this, SLOT(stopProgressAnimation()) );
375 d->updateSearchMode();
376 d->progressButton->setVisible(
false );
381 this, SLOT(stopProgressAnimation()) );
391 return d->m_coordinates;
396 d->m_targetModel.setShowRoutingItems( show );
401 d->browseButton->setVisible( enabled );
402 d->searchButton->setVisible( enabled );
404 d->searchButton->setChecked(
false );
405 d->updateSearchMode();
409 void GoToDialogPrivate::updateSearchMode()
411 bool const searchEnabled = searchButton->isChecked();
412 searchLineEdit->setVisible( searchEnabled );
413 descriptionLabel->setVisible( searchEnabled );
414 progressButton->setVisible( searchEnabled && m_progressTimer.isActive() );
415 if ( searchEnabled ) {
416 bookmarkListView->setModel( &m_searchResultModel );
417 searchLineEdit->setFocus();
419 bookmarkListView->setModel( &m_targetModel );
423 void GoToDialogPrivate::updateProgress()
425 if ( !m_progressAnimation.isEmpty() ) {
426 m_currentFrame = ( m_currentFrame + 1 ) % m_progressAnimation.size();
427 QIcon frame = m_progressAnimation[m_currentFrame];
428 progressButton->setIcon( frame );
432 void GoToDialogPrivate::stopProgressAnimation()
434 searchLineEdit->setEnabled(
true );
435 m_progressTimer.stop();
436 updateResultMessage( bookmarkListView->model()->rowCount() );
437 progressButton->setVisible(
false );
440 void GoToDialogPrivate::updateResultMessage(
int results )
442 descriptionLabel->setText(
QObject::tr(
"%n results found.",
"Number of search results", results ) );
447 #include "GoToDialog.moc"
A 3d point representation.
This file contains the headers for MarbleModel.
void setSearchEnabled(bool enabled)
Toggle whether the dialog can be used to search for placemarks.
const_iterator constEnd() const
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
QString tr(const char *sourceText, const char *disambiguation, int n)
void setShowRoutingItems(bool show)
Toggle whether routing items (source, destination and via points) are visible.
GoToDialog(MarbleModel *marbleModel, QWidget *parent=0, Qt::WindowFlags f=0)
GeoDataCoordinates coordinates() const
Returns the position of the item selected by the user, or a default constructed GeoDataLookAt if the ...
const QSize iconSize(16, 16)
static MarbleGlobal * getInstance()
The GeoDataCoordinates coordinate.
const T & at(int i) const
The data model (not based on QAbstractModel) for a MarbleWidget.
const_iterator constBegin() const
QVariant data(int role) const
Profiles profiles() const
void push_back(const T &value)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)