21 #include <QApplication>
25 #include <QGraphicsItem>
26 #include <QGraphicsScene>
27 #include <QGraphicsView>
29 #include <QMouseEvent>
31 #include <QPaintEvent>
34 #include <QTextStream>
35 #include <QResizeEvent>
37 #include <QStringList>
38 #include <QWheelEvent>
81 : QGraphicsView( parent )
85 , mAntiAliasing( false )
90 viewport()->setAttribute( Qt::WA_PaintOnScreen,
true );
93 mScene =
new QGraphicsScene();
95 setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
96 setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
112 setMouseTracking(
true );
113 setFocusPolicy( Qt::StrongFocus );
129 this, SLOT(
readProject(
const QDomDocument & ) ) );
148 QList<QGraphicsItem*> list =
mScene->items();
149 QList<QGraphicsItem*>::iterator it = list.begin();
150 while ( it != list.end() )
152 QGraphicsItem* item = *it;
193 if ( index >= 0 && index < (
int ) layers.size() )
243 QStringList layerSet, layerSetOverview;
246 for ( i = 0; i < layers.size(); i++ )
256 layerSet.push_back( lyr.
layer()->
id() );
260 layerSetOverview.push_back( lyr.
layer()->
id() );
266 bool layerSetChanged = layerSetOld != layerSet;
269 if ( layerSetChanged )
276 disconnect( currentLayer, SIGNAL( repaintRequested() ),
this, SLOT(
refresh() ) );
277 disconnect( currentLayer, SIGNAL( screenUpdateRequested() ),
this, SLOT(
updateMap() ) );
292 connect( currentLayer, SIGNAL( repaintRequested() ),
this, SLOT(
refresh() ) );
293 connect( currentLayer, SIGNAL( screenUpdateRequested() ),
this, SLOT(
updateMap() ) );
308 if ( layerSetOvOld != layerSetOverview )
318 if ( layerSetChanged )
335 disconnect(
mMapRenderer, SIGNAL( destinationSrsChanged() ),
348 connect(
mMapRenderer, SIGNAL( destinationSrsChanged() ),
349 overview, SLOT( destinationSrsChanged() ) );
383 QApplication::setOverrideCursor( Qt::WaitCursor );
402 QApplication::restoreOverrideCursor();
422 if ( theQPixmap != NULL )
426 painter.begin( theQPixmap );
431 theQPixmap->save( theFileName, theFormat.toLocal8Bit().data() );
439 pixmap->save( theFileName, theFormat.toLocal8Bit().data() );
448 myHeader +=
"0 \r\n";
450 myHeader +=
"0 \r\n";
458 QFileInfo myInfo = QFileInfo( theFileName );
460 QString myWorldFileName = myInfo.absolutePath() +
"/" + myInfo.completeBaseName() +
"." + theFormat +
"w";
461 QFile myWorldFile( myWorldFileName );
462 if ( !myWorldFile.open( QIODevice::WriteOnly ) )
466 QTextStream myStream( &myWorldFile );
467 myStream << myHeader;
508 QgsDebugMsg(
"Empty extent - keeping old extent with new center!" );
578 extent.
scale( 1.05 );
730 QPen pen( Qt::gray );
738 double dx = qAbs(( currentExtent.
xMaximum() - currentExtent.
xMinimum() ) / 4 );
739 double dy = qAbs(( currentExtent.
yMaximum() - currentExtent.
yMinimum() ) / 4 );
785 if ( ! e->isAutoRepeat() )
797 case Qt::Key_PageDown:
810 QgsDebugMsg(
"Ignoring key: " + QString::number( e->key() ) );
846 QgsDebugMsg(
"Ignoring key release: " + QString::number( e->key() ) );
875 if ( e->button() == Qt::MidButton )
907 if ( e->button() == Qt::MidButton )
920 QgsDebugMsg(
"Right click in map tool zoom or pan, last tool is " +
962 if ( theRenderContext )
980 mScene->setSceneRect( QRectF( 0, 0, lastSize.width(), lastSize.height() ) );
1000 QList<QGraphicsItem*> list =
mScene->items();
1001 QList<QGraphicsItem*>::iterator it = list.begin();
1002 while ( it != list.end() )
1021 QgsDebugMsg(
"Wheel event delta " + QString::number( e->delta() ) );
1032 if ( e->delta() > 0 )
1050 QgsPoint newCenter( mousePos.x() + (( oldCenter.x() - mousePos.x() ) * scaleFactor ),
1051 mousePos.y() + (( oldCenter.y() - mousePos.y() ) * scaleFactor ) );
1055 extent.
scale( scaleFactor, &newCenter );
1100 r.
scale( scaleFactor, ¢er );
1126 QPoint xy = e->pos();
1169 setCursor( Qt::ArrowCursor );
1185 QBrush bgBrush( theColor );
1186 setBackgroundBrush( bgBrush );
1189 palette.setColor( backgroundRole(), theColor );
1190 setPalette( palette );
1194 mScene->setBackgroundBrush( bgBrush );
1199 return mScene->backgroundBrush().color();
1210 QList<QgsMapLayer*> lst;
1215 lst.append( layer );
1250 qWarning(
"QgsMapCanvas::canvasPixmap() deprecated - returning static pixmap instance - use QgsMapCanvas::paintDevice()" );
1252 static QPixmap staticPixmap;
1257 staticPixmap = QPixmap::fromImage( *image );
1264 return staticPixmap;
1280 QgsDebugMsg(
"Setting map units to " + QString::number( static_cast<int>( u ) ) );
1311 QgsDebugMsg(
"QgsMapCanvas connected to " + QString( signal ) );
1335 double dx = qAbs( end.
x() - start.
x() );
1336 double dy = qAbs( end.
y() - start.
y() );
1341 if ( end.
x() < start.
x() )
1344 r.setXMaximum( r.xMaximum() + dx );
1348 r.setXMinimum( r.xMinimum() - dx );
1349 r.setXMaximum( r.xMaximum() - dx );
1352 if ( end.
y() < start.
y() )
1354 r.setYMaximum( r.yMaximum() + dy );
1355 r.setYMinimum( r.yMinimum() + dy );
1360 r.setYMaximum( r.yMaximum() - dy );
1361 r.setYMinimum( r.yMinimum() - dy );
1396 QList<QGraphicsItem*> list =
mScene->items();
1397 QList<QGraphicsItem*>::iterator it = list.begin();
1398 while ( it != list.end() )
1400 QGraphicsItem* item = *it;
1421 QMessageBox::warning(
1424 tr(
"Could not draw %1 because:\n%2",
"COMMENTED OUT" ).arg( mapLayer->
name() ).arg( mapLayer->
lastError() )
1445 QDomNodeList nodes = doc.elementsByTagName(
"mapcanvas" );
1446 if ( nodes.count() )
1448 QDomNode node = nodes.item( 0 );
1454 QgsDebugMsg(
"Couldn't read mapcanvas information from project" );
1463 QDomNodeList nl = doc.elementsByTagName(
"qgis" );
1466 QgsDebugMsg(
"Unable to find qgis element in project file" );
1469 QDomNode qgisNode = nl.item( 0 );
1471 QDomElement mapcanvasNode = doc.createElement(
"mapcanvas" );
1472 qgisNode.appendChild( mapcanvasNode );
1486 r.
scale( scaleFactor );