38#include <QPainterPath>
39#include <QResizeEvent>
42#include "moc_qgsmapoverviewcanvas.cpp"
44using namespace Qt::StringLiterals;
51 setAutoFillBackground(
true );
52 setObjectName( u
"theOverviewCanvas"_s );
76 QWidget::resizeEvent( e );
82 QWidget::showEvent( e );
87 QPainter paint(
this );
88 QRect rect = pe->rect();
90 std::ceil( pe->rect().left() *
mPixmap.devicePixelRatio() ),
91 std::ceil( pe->rect().top() *
mPixmap.devicePixelRatio() ),
92 std::ceil( pe->rect().width() *
mPixmap.devicePixelRatio() ),
93 std::ceil( pe->rect().height() *
mPixmap.devicePixelRatio() )
97 paint.drawPixmap( rect.topLeft(),
mPixmap, sourceRect );
101 paint.fillRect( rect, QBrush(
mSettings.backgroundColor() ) );
120 const QPolygonF &vPoly =
mMapCanvas->mapSettings().visiblePolygon();
158 if ( e->button() == Qt::LeftButton )
175 bool zoomIn = reverseZoom ? e->angleDelta().y() < 0 : e->angleDelta().y() > 0;
179 zoomFactor = 1.0 + ( zoomFactor - 1.0 ) / 120.0 * std::fabs( e->angleDelta().y() );
181 if ( e->modifiers() & Qt::ControlModifier )
184 zoomFactor = 1.0 + ( zoomFactor - 1.0 ) / 20.0;
187 const double signedWheelFactor = zoomIn ? 1 / zoomFactor : zoomFactor;
192 mMapCanvas->zoomByFactor( signedWheelFactor, ¢er );
198 if ( ( e->buttons() & Qt::LeftButton ) == Qt::LeftButton )
236 mSettings.setDevicePixelRatio(
static_cast<float>( devicePixelRatioF() ) );
245 mSettings.setExpressionContext( expressionContext );
264 mPixmap = QPixmap::fromImage(
mJob->renderedImage() );
286 palette.setColor( backgroundRole(), color );
287 setPalette( palette );
292 const auto oldLayers =
mSettings.layers();
300 const auto newLayers =
mSettings.layers();
358QgsPanningWidget::QgsPanningWidget( QWidget *parent )
361 setObjectName( u
"panningWidget"_s );
362 setMinimumSize( 5, 5 );
363 setAttribute( Qt::WA_NoSystemBackground );
366void QgsPanningWidget::setPolygon(
const QPolygon &p )
373 if ( mPoly.at( 0 ) != mPoly.at( mPoly.length() - 1 ) )
374 mPoly.append( mPoly.at( 0 ) );
376 const QRect rect = p.boundingRect() + QMargins( 1, 1, 1, 1 );
381void QgsPanningWidget::paintEvent( QPaintEvent *pe )
388 const QPolygonF t = mPoly.translated( -mPoly.boundingRect().left() + 1, -mPoly.boundingRect().top() + 1 );
393 path.addPolygon( t );
396 pen.setJoinStyle( Qt::MiterJoin );
397 pen.setColor( Qt::white );
401 pen.setColor( Qt::red );
@ DrawLabeling
Enable drawing of labels on top of the map.
Custom exception class for Coordinate Reference System related exceptions.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Map canvas is a class for displaying all GIS data types on a canvas.
void extentsChanged()
Emitted when the extents of the map change.
void canvasColorChanged()
Emitted when canvas background color changes.
void destinationCrsChanged()
Emitted when map CRS has changed.
void transformContextChanged()
Emitted when the canvas transform context is changed.
Base class for all map layer types.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
QPoint mPanningCursorOffset
position of cursor inside panning widget
void wheelEvent(QWheelEvent *e) override
Overridden mouse release event.
void resizeEvent(QResizeEvent *e) override
Overridden resize event.
void mapRenderingFinished()
void setLayers(const QList< QgsMapLayer * > &layers)
updates layer set for overview
void drawExtentRect()
used for overview canvas to reflect changed extent in main map canvas
void mouseReleaseEvent(QMouseEvent *e) override
Overridden mouse release event.
void mouseMoveEvent(QMouseEvent *e) override
Overridden mouse move event.
void transformContextChanged()
Called when the canvas transform context is changed.
void refresh()
renders overview and updates panning widget
void mousePressEvent(QMouseEvent *e) override
Overridden mouse press event.
void layerRepaintRequested(bool deferred=false)
Triggered when a layer in the overview requests a repaint.
void paintEvent(QPaintEvent *pe) override
Overridden paint event.
void setBackgroundColor(const QColor &color)
changes background color
QgsMapOverviewCanvas(QWidget *parent=nullptr, QgsMapCanvas *mapCanvas=nullptr)
QgsMapRendererQImageJob * mJob
for rendering overview
void destinationCrsChanged()
Should be called when the canvas destination CRS is changed.
QPixmap mPixmap
pixmap where the map is stored
QgsPanningWidget * mPanningWidget
widget for panning map in overview
void showEvent(QShowEvent *e) override
Overridden show event.
void updatePanningWidget(QPoint pos)
called when panning to reflect mouse movement
QgsMapSettings mSettings
map settings used for rendering of the overview map
QList< QgsMapLayer * > layers() const
Returns list of layers visible in the overview.
QgsMapCanvas * mMapCanvas
main map canvas - used to get/set extent
void finished()
emitted when asynchronous rendering is finished (or canceled).
Job implementation that renders everything sequentially in one thread.
Perform transforms between map coordinates and device coordinates.
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
void presetFullExtentChanged()
Emitted whenever the presetFullExtent() is changed.
QgsReferencedRectangle fullExtent() const
Returns the full extent of the project, which represents the maximal limits of the project.
static QgsProject * instance()
Returns the QgsProject singleton instance.
const QgsProjectViewSettings * viewSettings() const
Returns the project's view settings, which contains settings and properties relating to how a QgsProj...
A rectangle specified with double values.
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsRectangle with associated coordinate reference system.
static const QgsSettingsEntryBool * settingsReverseWheelZoom
Settings entry reverse wheel zoom.
Stores settings for use within QGIS.
#define QgsDebugMsgLevel(str, level)