[Marble-commits] KDE/kdeedu/marble/src/lib
Dennis Nienhüser
earthwings at gentoo.org
Tue Nov 30 22:28:38 CET 2010
SVN commit 1202433 by nienhueser:
Move more of the management and initialization methods out of RoutingWidget to allow its lazy creation. Fixes "directions from/to here" context menu buttons and route restoration not working correctly until the routing dialog was opened once on Maemo.
M +5 -0 MarbleWidget.cpp
M +10 -2 MarbleWidgetPopupMenu.cpp
M +5 -2 routing/AlternativeRoutesModel.cpp
M +14 -6 routing/RoutingLayer.cpp
M +7 -1 routing/RoutingLayer.h
M +1 -6 routing/RoutingWidget.cpp
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidget.cpp #1202432:1202433
@@ -50,6 +50,7 @@
#include "BookmarkManager.h"
#include "routing/RoutingLayer.h"
#include "routing/RoutingManager.h"
+#include "routing/AlternativeRoutesModel.h"
namespace Marble
{
@@ -249,10 +250,14 @@
m_routingLayer = new RoutingLayer( m_widget, m_widget );
m_routingLayer->setRouteRequest( m_model->routingManager()->routeRequest() );
+ m_routingLayer->setModel( m_model->routingManager()->routingModel() );
m_map->addLayer( m_routingLayer );
m_widget->connect( m_routingLayer, SIGNAL( routeDirty() ),
m_model->routingManager(), SLOT( updateRoute() ) );
+ m_widget->connect( m_model->routingManager()->alternativeRoutesModel(),
+ SIGNAL( currentRouteChanged( GeoDataDocument* ) ),
+ m_widget, SLOT( repaint() ) );
}
void MarbleWidgetPrivate::moveByStep( int stepsRight, int stepsDown, FlyToMode mode )
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidgetPopupMenu.cpp #1202432:1202433
@@ -264,11 +264,15 @@
void MarbleWidgetPopupMenu::directionsFromHere()
{
RouteRequest* request = m_widget->model()->routingManager()->routeRequest();
- if ( request && request->size() > 0 )
+ if ( request )
{
GeoDataCoordinates coordinates;
if ( mouseCoordinates( &coordinates, m_setHomePointAction ) ) {
+ if ( request->size() > 0 ) {
request->setPosition( 0, coordinates );
+ } else {
+ request->append( coordinates );
+ }
m_widget->model()->routingManager()->updateRoute();
}
}
@@ -277,11 +281,15 @@
void MarbleWidgetPopupMenu::directionsToHere()
{
RouteRequest* request = m_widget->model()->routingManager()->routeRequest();
- if ( request && request->size() > 1 )
+ if ( request )
{
GeoDataCoordinates coordinates;
if ( mouseCoordinates( &coordinates, m_setHomePointAction ) ) {
+ if ( request->size() > 1 ) {
request->setPosition( request->size()-1, coordinates );
+ } else {
+ request->append( coordinates );
+ }
m_widget->model()->routingManager()->updateRoute();
}
}
--- trunk/KDE/kdeedu/marble/src/lib/routing/AlternativeRoutesModel.cpp #1202432:1202433
@@ -91,7 +91,7 @@
AlternativeRoutesModelPrivate::AlternativeRoutesModelPrivate( MarbleModel* marbleModel ) :
- m_marbleModel( marbleModel ), m_currentIndex( 0 )
+ m_marbleModel( marbleModel ), m_currentIndex( -1 )
{
// nothing to do
}
@@ -332,6 +332,7 @@
void AlternativeRoutesModel::newRequest( RouteRequest * )
{
d->m_responseTime.start();
+ d->m_currentIndex = -1;
clear();
}
@@ -355,6 +356,8 @@
}
d->m_restrainedRoutes.clear();
+ Q_ASSERT( !d->m_routes.isEmpty() );
+ setCurrentRoute( 0 );
}
void AlternativeRoutesModel::addRoute( GeoDataDocument* document, WritePolicy policy )
@@ -435,7 +438,7 @@
void AlternativeRoutesModel::setCurrentRoute( int index )
{
- if ( index >= 0 && index < rowCount() ) {
+ if ( index >= 0 && index < rowCount() && d->m_currentIndex != index ) {
d->m_currentIndex = index;
emit currentRouteChanged( currentRoute() );
}
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingLayer.cpp #1202432:1202433
@@ -171,7 +171,8 @@
m_targetPixmap( ":/data/bitmaps/routing_pick.png" ), m_dragStopOverRightIndex( -1 ),
m_pointSelection( false ), m_routingModel( 0 ), m_placemarkModel( 0 ), m_selectionModel( 0 ),
m_routeDirty( false ), m_pixmapSize( 22, 22 ), m_routeRequest( 0 ), m_activeMenuIndex( -1 ),
- m_alternativeRoutesView( 0 ), m_alternativeRoutesModel( 0 )
+ m_alternativeRoutesView( 0 ),
+ m_alternativeRoutesModel( widget->model()->routingManager()->alternativeRoutesModel() )
{
m_contextMenu = new MarbleWidgetPopupMenu( m_marbleWidget, m_marbleWidget->model() );
m_removeViaPointAction = new QAction( QObject::tr( "&Remove this destination" ), q );
@@ -311,7 +312,7 @@
GeoDataCoordinates pos = qVariantValue<GeoDataCoordinates>( index.data( RoutingModel::CoordinateRole ) );
RoutingModel::RoutingItemType type = qVariantValue<RoutingModel::RoutingItemType>( index.data( RoutingModel::TypeRole ) );
- if ( type == RoutingModel::Instruction ) {
+ if ( type == RoutingModel::Instruction && m_proxyModel && m_selectionModel ) {
painter->setBrush( QBrush( alphaAdjusted( oxygenAluminumGray4, 200 ) ) );
QModelIndex proxyIndex = m_proxyModel->mapFromSource( index );
@@ -420,8 +421,8 @@
}
foreach( const ModelRegion ®ion, m_instructionRegions ) {
- if ( region.region.contains( e->pos() ) ) {
- if ( e->button() == Qt::LeftButton ) {
+ if ( region.region.contains( e->pos() ) && m_selectionModel ) {
+ if ( e->button() == Qt::LeftButton && m_proxyModel ) {
QModelIndex index = m_proxyModel->mapFromSource( region.index );
QItemSelectionModel::SelectionFlag command = QItemSelectionModel::ClearAndSelect;
if ( m_selectionModel->isSelected( index ) ) {
@@ -640,6 +641,8 @@
QObject( parent ), d( new RoutingLayerPrivate( this, widget ) )
{
widget->installEventFilter( this );
+ connect( widget->model()->routingManager(), SIGNAL( stateChanged( RoutingManager::State, RouteRequest* ) ),
+ this, SLOT( updateRouteState( RoutingManager::State, RouteRequest* ) ) );
}
RoutingLayer::~RoutingLayer()
@@ -731,9 +734,8 @@
d->m_proxyModel = model;
}
-void RoutingLayer::synchronizeAlternativeRoutesWith( AlternativeRoutesModel* model, QComboBox *view )
+void RoutingLayer::synchronizeAlternativeRoutesWith( QComboBox *view )
{
- d->m_alternativeRoutesModel = model;
d->m_alternativeRoutesView = view;
connect( d->m_alternativeRoutesModel, SIGNAL( rowsInserted( QModelIndex, int, int) ),
@@ -797,6 +799,12 @@
}
}
+void RoutingLayer::updateRouteState( RoutingManager::State state, RouteRequest *route )
+{
+ d->m_routeRequest = route;
+ setRouteDirty( state == RoutingManager::Downloading );
+}
+
} // namespace Marble
#include "RoutingLayer.moc"
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingLayer.h #1202432:1202433
@@ -13,6 +13,7 @@
#include "GeoDataCoordinates.h"
#include "LayerInterface.h"
+#include "RoutingManager.h"
#include <QtCore/QModelIndex>
#include <QtGui/QItemSelection>
@@ -69,7 +70,7 @@
* @todo: Should use a QAbstractItemView instead, but working on this instead of the
* QComboBox does not work (changing the selection is not reflected by the combo box)
*/
- void synchronizeAlternativeRoutesWith( AlternativeRoutesModel* model, QComboBox *view );
+ void synchronizeAlternativeRoutesWith( QComboBox *view );
/**
* Set the routing model to use. Implicitly removes the placemark model.
@@ -134,6 +135,11 @@
/** Export route to a file */
void exportRoute();
+ /**
+ * Paint a dashed route when downloading a new route, a solid one otherwise.
+ */
+ void updateRouteState( RoutingManager::State state, RouteRequest *route );
+
private:
RoutingLayerPrivate *const d;
friend class RoutingLayerPrivate;
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingWidget.cpp #1202432:1202433
@@ -188,7 +188,7 @@
d->m_ui.routeComboBox->setModel( d->m_routingManager->alternativeRoutesModel() );
d->m_routingLayer = d->m_widget->routingLayer();
- d->m_routingLayer->synchronizeAlternativeRoutesWith( d->m_routingManager->alternativeRoutesModel(), d->m_ui.routeComboBox );
+ d->m_routingLayer->synchronizeAlternativeRoutesWith( d->m_ui.routeComboBox );
d->m_ui.routingProfileComboBox->setModel( d->m_routingManager->profilesModel() );
@@ -196,8 +196,6 @@
this, SLOT( selectFirstProfile() ) );
connect( d->m_routingManager->profilesModel(), SIGNAL( modelReset() ),
this, SLOT( selectFirstProfile() ) );
- connect( d->m_routingManager->alternativeRoutesModel(), SIGNAL( currentRouteChanged( GeoDataDocument* ) ),
- d->m_widget, SLOT( repaint() ) );
connect( d->m_routingLayer, SIGNAL( placemarkSelected( QModelIndex ) ),
this, SLOT( activatePlacemark( QModelIndex ) ) );
connect( d->m_routingLayer, SIGNAL( pointSelected( GeoDataCoordinates ) ),
@@ -223,7 +221,6 @@
d->m_routingProxyModel->setSourceModel( d->m_routingManager->routingModel() );
d->m_ui.directionsListView->setModel( d->m_routingProxyModel );
- d->m_routingLayer->setModel( d->m_routingManager->routingModel() );
QItemSelectionModel *selectionModel = d->m_ui.directionsListView->selectionModel();
d->m_routingLayer->synchronizeWith( d->m_routingProxyModel, selectionModel );
connect( d->m_ui.directionsListView, SIGNAL( activated ( QModelIndex ) ),
@@ -422,8 +419,6 @@
d->m_ui.routeComboBox->clear();
}
- d->m_routingLayer->setRouteDirty( state == RoutingManager::Downloading );
-
if ( state == RoutingManager::Downloading ) {
d->m_progressTimer.start();
}
More information about the Marble-commits
mailing list