void QDeclarativeRouteMapItem::setRoute(QDeclarativeGeoRoute *route)
{
    if (route_ == route)
        return;

    route_ = route;

    if (route_)
        setPathFromGeoList(route_->routePath());

    emit routeChanged(route_);
}
void QGeoMapRouteObject::setRoute(const QGeoRoute &route)
{
    d_ptr->route = route;
    emit routeChanged(d_ptr->route);
}
Exemplo n.º 3
0
PaintWidget::PaintWidget(QWidget *parent) :
	QWidget( parent ),
	m_ui( new Ui::PaintWidget )
{
	m_ui->setupUi( this );
	if ( MapData::instance()->loaded() ) {
		setAttribute( Qt::WA_OpaquePaintEvent, true );
		setAttribute( Qt::WA_NoSystemBackground, true );
	}
#else
PaintWidget::PaintWidget() {
#endif
	m_lastMouseX = 0;
	m_lastMouseY = 0;
	m_wheelDelta = 0;
	m_fixed = false;
	setKeepPositionVisible( false );
	m_mouseDown = false;
	m_drag = false;
	m_request.zoom = 0;
	m_request.center = RoutingLogic::instance()->source().ToProjectedCoordinate();

	dataLoaded();
	sourceChanged();
	waypointsChanged();
	trackChanged();
	routeChanged();

	connect( MapData::instance(), SIGNAL(dataLoaded()), this, SLOT(dataLoaded()) );
	connect( RoutingLogic::instance(), SIGNAL(sourceChanged()), this, SLOT(sourceChanged()) );
	connect( RoutingLogic::instance(), SIGNAL(routeChanged()), this, SLOT(routeChanged()) );
	connect( RoutingLogic::instance(), SIGNAL(waypointsChanged()), this, SLOT(waypointsChanged()) );
	connect( Logger::instance(), SIGNAL(trackChanged()), this, SLOT(trackChanged()) );
}

PaintWidget::~PaintWidget()
{
#ifndef SAILFISH
	delete m_ui;
#endif
}

void PaintWidget::paint(QPainter *painter) {
	if ( !isVisible() )
		return;

	IRenderer* renderer = MapData::instance()->renderer();
	if ( renderer == NULL )
		return;

	if ( m_fixed ){
		m_request.center = m_request.position.ToProjectedCoordinate();

		if ( GlobalSettings::autoRotation() )
		{
			//gradually change the screen rotation to match the heading
			double diff = m_request.rotation + m_request.heading;
			while ( diff <= -180 )
				diff += 360;
			while ( diff >= 180 )
				diff -=360;
			//to filter out noise stop when close enough
			if ( diff > 0 )
				diff = std::max( 0.0, diff - 15 );
			if ( diff < 0 )
				diff = std::min( 0.0, diff + 15 );
			m_request.rotation -= diff / 2;

			//normalize
			while ( m_request.rotation < 0 )
				m_request.rotation += 360;
			while ( m_request.rotation >= 360 )
				m_request.rotation -= 360;

			int radius = height() * 0.25;
			m_request.center = renderer->PointToCoordinate( 0, -radius, m_request );
		} else {
			m_request.rotation = 0;
		}
	} else {
		m_request.rotation = 0;
	}

	if (m_keepPositionVisible)
		m_request.center = m_request.position.ToProjectedCoordinate();

	Timer time;
	renderer->Paint( painter, m_request );
	qDebug() << "Rendering:" << time.elapsed() << "ms";
}

void PaintWidget::dataLoaded()
{
	IRenderer* renderer = MapData::instance()->renderer();
	if ( renderer == NULL )
		return;

#ifndef SAILFISH
	setAttribute( Qt::WA_OpaquePaintEvent, true );
	setAttribute( Qt::WA_NoSystemBackground, true );
#endif
	renderer->SetUpdateSlot( this, SLOT(update()) );
	update();
}