Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move coordinate bounds map to its own reusable widget
- Loading branch information
1 parent
e6ac0e2
commit 337f1d9
Showing
9 changed files
with
241 additions
and
76 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
python/gui/auto_generated/qgscoordinateboundspreviewmapwidget.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgscoordinateboundspreviewmapwidget.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
class QgsCoordinateBoundsPreviewMapWidget : QgsMapCanvas | ||
{ | ||
%Docstring | ||
A widget for showing the bounds of a rectangular region on an interactive map. | ||
|
||
.. versionadded:: 3.8.1 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgscoordinateboundspreviewmapwidget.h" | ||
%End | ||
public: | ||
|
||
QgsCoordinateBoundsPreviewMapWidget( QWidget *parent /TransferThis/ = 0 ); | ||
%Docstring | ||
Constructor for QgsCoordinateBoundsPreviewMapWidget. | ||
%End | ||
|
||
~QgsCoordinateBoundsPreviewMapWidget(); | ||
|
||
void setCanvasRect( const QgsRectangle &rect ); | ||
%Docstring | ||
Sets the canvas bounds rectangle for the bounds overview map. | ||
|
||
Must be in EPSG:4326 coordinate reference system. | ||
|
||
.. seealso:: :py:func:`canvasRect` | ||
%End | ||
|
||
QgsRectangle canvasRect() const; | ||
%Docstring | ||
Returns the current canvas bounds rectangle shown in the map. | ||
|
||
.. seealso:: :py:func:`setCanvasRect` | ||
%End | ||
|
||
void setPreviewRect( const QgsRectangle &rect ); | ||
%Docstring | ||
Sets the "preview" rectangle for the bounds overview map. | ||
Must be in EPSG:4326 coordinate reference system. | ||
|
||
.. seealso:: :py:func:`previewRect` | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgscoordinateboundspreviewmapwidget.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
|
||
|
||
|
||
|
||
class QgsProjectionSelectionTreeWidget : QWidget | ||
{ | ||
%Docstring | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/*************************************************************************** | ||
* qgscoordinateboundspreviewmapwidget.h * | ||
* Copyright (C) 2019 by Nyall Dawson * | ||
* nyall dot dawson at gmail dot com * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
***************************************************************************/ | ||
#include "qgscoordinateboundspreviewmapwidget.h" | ||
#include "qgsrubberband.h" | ||
#include "qgsvertexmarker.h" | ||
#include "qgsapplication.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgsmaptoolpan.h" | ||
|
||
QgsCoordinateBoundsPreviewMapWidget::QgsCoordinateBoundsPreviewMapWidget( QWidget *parent ) | ||
: QgsMapCanvas( parent ) | ||
{ | ||
mPreviewBand = new QgsRubberBand( this, QgsWkbTypes::PolygonGeometry ); | ||
mPreviewBand->setWidth( 4 ); | ||
|
||
mCanvasPreviewBand = new QgsRubberBand( this, QgsWkbTypes::PolygonGeometry ); | ||
mCanvasPreviewBand->setWidth( 4 ); | ||
QColor rectColor = QColor( 185, 84, 210, 60 ); | ||
mCanvasPreviewBand->setColor( rectColor ); | ||
|
||
mCanvasCenterMarker = new QgsVertexMarker( this ); | ||
mCanvasCenterMarker->setIconType( QgsVertexMarker::ICON_CROSS ); | ||
mCanvasCenterMarker->setColor( QColor( 185, 84, 210 ) ); | ||
mCanvasCenterMarker->setPenWidth( 3 ); | ||
|
||
QgsCoordinateReferenceSystem srs( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ); | ||
setDestinationCrs( srs ); | ||
|
||
QString layerPath = QgsApplication::pkgDataPath() + QStringLiteral( "/resources/data/world_map.shp" ); | ||
mLayers << new QgsVectorLayer( layerPath ); | ||
setLayers( mLayers ); | ||
setMapTool( new QgsMapToolPan( this ) ); | ||
setPreviewJobsEnabled( true ); | ||
} | ||
|
||
QgsCoordinateBoundsPreviewMapWidget::~QgsCoordinateBoundsPreviewMapWidget() | ||
{ | ||
qDeleteAll( mLayers ); | ||
delete mPreviewBand; | ||
delete mCanvasPreviewBand; | ||
delete mCanvasCenterMarker; | ||
} | ||
|
||
void QgsCoordinateBoundsPreviewMapWidget::setPreviewRect( const QgsRectangle &rect ) | ||
{ | ||
if ( !qgsDoubleNear( rect.area(), 0.0 ) ) | ||
{ | ||
QgsGeometry geom; | ||
if ( rect.xMinimum() > rect.xMaximum() ) | ||
{ | ||
QgsRectangle rect1 = QgsRectangle( -180, rect.yMinimum(), rect.xMaximum(), rect.yMaximum() ); | ||
QgsRectangle rect2 = QgsRectangle( rect.xMinimum(), rect.yMinimum(), 180, rect.yMaximum() ); | ||
geom = QgsGeometry::fromRect( rect1 ); | ||
geom.addPart( QgsGeometry::fromRect( rect2 ) ); | ||
} | ||
else | ||
{ | ||
geom = QgsGeometry::fromRect( rect ); | ||
} | ||
mPreviewBand->setToGeometry( geom, nullptr ); | ||
mPreviewBand->setColor( QColor( 255, 0, 0, 65 ) ); | ||
QgsRectangle extent = geom.boundingBox(); | ||
extent.scale( 1.1 ); | ||
setExtent( extent ); | ||
refresh(); | ||
mPreviewBand->show(); | ||
} | ||
else | ||
{ | ||
mPreviewBand->hide(); | ||
zoomToFullExtent(); | ||
} | ||
} | ||
|
||
QgsRectangle QgsCoordinateBoundsPreviewMapWidget::canvasRect() const | ||
{ | ||
return mCanvasRect; | ||
} | ||
|
||
void QgsCoordinateBoundsPreviewMapWidget::setCanvasRect( const QgsRectangle &rect ) | ||
{ | ||
mCanvasRect = rect; | ||
mCanvasPreviewBand->setToGeometry( QgsGeometry::fromRect( mCanvasRect ), nullptr ); | ||
mCanvasPreviewBand->show(); | ||
mCanvasCenterMarker->setCenter( rect.center() ); | ||
mCanvasCenterMarker->show(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*************************************************************************** | ||
* qgscoordinateboundspreviewmapwidget.h * | ||
* Copyright (C) 2019 by Nyall Dawson * | ||
* nyall dot dawson at gmail dot com * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
***************************************************************************/ | ||
#ifndef QGSCOORDINATEBOUNDSPREVIEWWIDGET_H | ||
#define QGSCOORDINATEBOUNDSPREVIEWWIDGET_H | ||
|
||
#include "qgsmapcanvas.h" | ||
#include "qgis_sip.h" | ||
#include "qgis_gui.h" | ||
|
||
class QgsVertexMarker; | ||
|
||
/** | ||
* \class QgsCoordinateBoundsPreviewMapWidget | ||
* \ingroup gui | ||
* A widget for showing the bounds of a rectangular region on an interactive map. | ||
* \since QGIS 3.8.1 | ||
*/ | ||
|
||
class GUI_EXPORT QgsCoordinateBoundsPreviewMapWidget : public QgsMapCanvas | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** | ||
* Constructor for QgsCoordinateBoundsPreviewMapWidget. | ||
*/ | ||
QgsCoordinateBoundsPreviewMapWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr ); | ||
|
||
~QgsCoordinateBoundsPreviewMapWidget() override; | ||
|
||
/** | ||
* Sets the canvas bounds rectangle for the bounds overview map. | ||
* | ||
* Must be in EPSG:4326 coordinate reference system. | ||
* \see canvasRect() | ||
*/ | ||
void setCanvasRect( const QgsRectangle &rect ); | ||
|
||
/** | ||
* Returns the current canvas bounds rectangle shown in the map. | ||
* \see setCanvasRect() | ||
*/ | ||
QgsRectangle canvasRect() const; | ||
|
||
/** | ||
* Sets the "preview" rectangle for the bounds overview map. | ||
* Must be in EPSG:4326 coordinate reference system. | ||
* \see previewRect() | ||
*/ | ||
void setPreviewRect( const QgsRectangle &rect ); | ||
|
||
private: | ||
|
||
QgsRubberBand *mPreviewBand = nullptr; | ||
QgsRubberBand *mCanvasPreviewBand = nullptr; | ||
QgsVertexMarker *mCanvasCenterMarker = nullptr; | ||
|
||
QList<QgsMapLayer *> mLayers; | ||
|
||
QgsRectangle mCanvasRect; | ||
|
||
}; | ||
|
||
#endif // QGSCOORDINATEBOUNDSPREVIEWWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.