Skip to content
Permalink
Browse files

Add options menu and allow setting map view scale

  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent 9560bba commit 02a0e53284a950718f0a1c664b3d8d49ce7a52b5
@@ -557,6 +557,7 @@
<file>themes/default/processingResult.svg</file>
<file>themes/default/search.svg</file>
<file>themes/default/mActionNewMap.svg</file>
<file>themes/default/mActionMapSettings.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
@@ -0,0 +1,177 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
height="24"
width="24"
version="1.1"
id="svg23"
sodipodi:docname="mActionMapSettings.svg"
inkscape:version="0.92.1 r">
<metadata
id="metadata29">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs27">
<linearGradient
id="a-3"
gradientTransform="matrix(-0.10786508,0.87849049,0.87408031,0.10732357,-1.811623,758.65836)"
gradientUnits="userSpaceOnUse"
x1="304.76001"
x2="335.29999"
y1="64.294998"
y2="81.926003">
<stop
offset="0"
stop-color="#d3d7cf"
id="stop2-6" />
<stop
offset=".18304"
stop-color="#babdb6"
id="stop4-7" />
<stop
offset=".31893"
stop-color="#fff"
id="stop6" />
<stop
offset=".87644"
stop-color="#babdb6"
id="stop8" />
<stop
offset="1"
stop-color="#eeeeec"
id="stop10" />
</linearGradient>
<linearGradient
id="b"
gradientTransform="matrix(-0.34112292,0.26690344,0.34708506,0.44633485,7.3860378,1027.6433)"
gradientUnits="userSpaceOnUse"
x1="-6.3077998"
x2="-9.7747002"
y1="44.229"
y2="44.139999">
<stop
offset="0"
id="stop13" />
<stop
offset="1"
stop-opacity="0"
id="stop15" />
</linearGradient>
<linearGradient
id="c"
gradientTransform="matrix(-0.67481701,0.52736572,0.29432462,0.37835898,77.717559,981.12162)"
gradientUnits="userSpaceOnUse"
x1="97.442001"
x2="90.221001"
y1="35.152"
y2="35.078999">
<stop
offset="0"
stop-color="#f8e27e"
id="stop18" />
<stop
offset="1"
stop-color="#e3d189"
id="stop20" />
</linearGradient>
</defs>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1016"
id="namedview25"
showgrid="false"
inkscape:zoom="9.8333333"
inkscape:cx="12.40678"
inkscape:cy="11.59322"
inkscape:window-x="0"
inkscape:window-y="27"
inkscape:window-maximized="1"
inkscape:current-layer="svg23" />
<linearGradient
id="a"
gradientUnits="userSpaceOnUse"
x1="3.5"
x2="11.5"
y1="19.5"
y2="19.5">
<stop
offset="0"
stop-color="#b7b7b7"
id="stop2" />
<stop
offset="1"
stop-color="#e6e6e6"
id="stop4" />
</linearGradient>
<g
transform="translate(0 -8)"
id="g21">
<path
d="m21.5 29.5h-17c-1 0-1.977816-1.420625-2-2.5v-16.5h19z"
fill="url(#a)"
fill-rule="evenodd"
stroke="#9a9a9a"
id="path7" />
<path
d="m6.5 9.9999996c-1-.9999995-3-.9999995-4 0v16.0000004c1-1 3-1 4 0z"
fill="#e6e6e6"
fill-rule="evenodd"
stroke="#9a9a9a"
id="path9" />
<g
transform="matrix(.69230769 0 0 .69230769 1.8461539 9.8461539)"
id="g19" />
</g>
<g
id="g73"
transform="matrix(0.77430229,0,0,0.77430229,-0.92444663,-790.99716)">
<path
inkscape:connector-curvature="0"
id="path63"
style="fill:url(#a-3);fill-rule:evenodd;stroke:#3b3b3b;stroke-width:1.0266068;stroke-linecap:round;stroke-linejoin:round;stroke-dashoffset:0.3612"
d="m 10.457382,1032.309 c -0.0557,-0.8562 0.634116,-0.2492 0.875491,0 1.024776,0.7434 2.030407,1.5156 3.067343,2.2407 0.725037,0.2552 1.421475,-0.3125 1.904389,-0.793 0.69153,-0.772 1.365424,-1.7692 1.239142,-2.855 -0.0999,-0.5511 -0.678194,-0.7556 -1.060023,-1.087 -0.948649,-0.7006 -1.905189,-1.3938 -2.848652,-2.099 0.0499,-0.5363 0.921102,-0.4312 1.352206,-0.4538 1.799481,0.032 3.760889,0.6193 4.847708,2.1483 0.893786,1.2432 1.095967,2.9098 0.645088,4.3593 0.248756,1.355 0.749129,2.6839 1.605411,3.7751 -1.055028,0.7755 -2.110005,1.5509 -3.165032,2.3264 -0.74403,-0.9699 -1.666431,-1.8128 -2.743678,-2.3982 -1.597268,0.2334 -3.230567,-0.5195 -4.193648,-1.7921 -0.762442,-0.9748 -1.327479,-2.1438 -1.525916,-3.3671 z" />
<path
inkscape:connector-curvature="0"
style="opacity:0.23106001;fill:url(#b)"
id="path65"
d="m 20.569654,1038.9536 c -0.377958,0.2957 -0.449831,0.8327 -0.161152,1.2039 l 5.276506,7.7275 c 0.288677,0.3713 1.28112,0.076 1.659095,-0.2199 0.377957,-0.2957 0.905829,-1.1891 0.617119,-1.5603 l -6.181727,-7.0148 c -0.288677,-0.3712 -0.825389,-0.432 -1.203364,-0.1363 z" />
<path
style="fill:#f0f3f2;fill-rule:evenodd"
inkscape:connector-curvature="0"
id="path67"
d="m 10.776308,1032.3503 c 0.0041,0.017 0.02652,0.01 0.02736,0 l 3.280939,2.4093 c 0.441955,0.3249 1.026164,0.2014 1.532663,-0.063 0.511499,-0.2667 1.030216,-0.7135 1.465827,-1.3248 0.436534,-0.6127 0.691989,-1.2801 0.782256,-1.8547 0.09008,-0.5733 -0.0071,-1.1337 -0.432392,-1.4464 l -3.308254,-2.4126 c -3.27e-4,-0.012 0.0053,-0.029 0.0034,-0.028 -0.02145,0.016 0.01356,0.01 0.02736,0 1.60773,-0.1726 3.391001,0.2382 4.500933,1.0542 1.518297,1.1161 2.06238,3.1241 1.496172,4.9767 -0.567334,1.8439 -2.398541,3.2549 -4.002325,3.466 -1.037771,0.1302 -2.105965,-0.1107 -2.984774,-0.7566 -1.106711,-0.8138 -2.046256,-2.4203 -2.389076,-4.0275 h -9.3e-5 z" />
<path
inkscape:connector-curvature="0"
id="path69"
style="fill:url(#c);stroke:#3b3b3b;stroke-width:0.86699998;stroke-linecap:round;stroke-linejoin:round;stroke-dashoffset:0.69999999"
d="m 21.969626,1036.9102 9.581585,11.1009 c 0.570734,0.7337 -0.03271,2.1379 -1.34119,3.1605 -1.308483,1.0226 -2.814237,1.2668 -3.384954,0.5331 l -8.399386,-12.0247 3.546142,-2.7701 z m 6.345662,11.8213 c -0.650481,0.5084 -0.785855,1.4312 -0.461469,1.8482 0.324412,0.4169 1.282238,0.4855 1.932707,-0.023 0.650479,-0.5084 0.754739,-1.407 0.430357,-1.8239 -0.324413,-0.417 -1.251126,-0.5098 -1.901595,0 z" />
<path
style="fill:#ffffff;fill-opacity:0.57758622;stroke:#3b3b3b;stroke-width:1.28935945"
inkscape:connector-curvature="0"
id="path71"
transform="matrix(0.82455744,-0.56577825,0.66205623,0.74945417,0,0)"
d="m -679.10767,874.67072 h 3.57105 v 0.57711 h -3.57105 z" />
</g>
</svg>
@@ -15,7 +15,11 @@
#include "qgsmapcanvasdockwidget.h"
#include "qgsmapcanvas.h"
#include "qgsprojectionselectiondialog.h"
#include "qgsscalecombobox.h"
#include <QMessageBox>
#include <QMenu>
#include <QToolBar>
#include <QToolButton>

QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *parent )
: QgsDockWidget( parent )
@@ -38,6 +42,36 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa

connect( mActionSetCrs, &QAction::triggered, this, &QgsMapCanvasDockWidget::setMapCrs );
connect( mActionSyncView, &QAction::toggled, this, &QgsMapCanvasDockWidget::syncView );

QMenu *menu = new QMenu();

QToolButton *toolButton = new QToolButton();
toolButton->setMenu( menu );
toolButton->setPopupMode( QToolButton::InstantPopup );
toolButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapSettings.svg" ) ) );
mToolbar->addWidget( toolButton );

QgsScaleComboAction *scaleAction = new QgsScaleComboAction( menu );
menu->addAction( scaleAction );
mScaleCombo = scaleAction->scaleCombo();
connect( mScaleCombo, &QgsScaleComboBox::scaleChanged, this, [ = ]( double scale )
{
if ( !mBlockScaleUpdate )
{
mBlockScaleUpdate = true;
mMapCanvas->zoomScale( 1.0 / scale );
mBlockScaleUpdate = false;
}
} );
connect( mMapCanvas, &QgsMapCanvas::scaleChanged, this, [ = ]( double scale )
{
if ( !mBlockScaleUpdate )
{
mBlockScaleUpdate = true;
mScaleCombo->setScale( 1.0 / scale );
mBlockScaleUpdate = false;
}
} );
}

QgsMapCanvas *QgsMapCanvasDockWidget::mapCanvas()
@@ -106,3 +140,18 @@ void QgsMapCanvasDockWidget::mapExtentChanged()

syncView( true );
}

QgsScaleComboAction::QgsScaleComboAction( QWidget *parent )
: QWidgetAction( parent )
{
mScaleCombo = new QgsScaleComboBox();

QHBoxLayout *hLayout = new QHBoxLayout();
hLayout->setContentsMargins( 2, 2, 2, 2 );
QLabel *label = new QLabel( tr( "Scale" ) );
hLayout->addWidget( label );
hLayout->addWidget( mScaleCombo );
QWidget *w = new QWidget();
w->setLayout( hLayout );
setDefaultWidget( w );
}
@@ -19,9 +19,16 @@

#include "qgsdockwidget.h"
#include "qgis_app.h"
#include <QWidgetAction>

class QgsMapCanvas;
class QgsScaleComboBox;

/**
* \class QgsMapCanvasDockWidget
* A dock widget with an embedded map canvas, for additional map views.
* \note added in QGIS 3.0
*/
class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsMapCanvasDockWidgetBase
{
Q_OBJECT
@@ -58,8 +65,28 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
QgsMapCanvas *mMapCanvas = nullptr;
QgsMapCanvas *mMainCanvas = nullptr;
bool mShowCloseWarning = true;
QgsScaleComboBox *mScaleCombo = nullptr;
bool mBlockScaleUpdate = false;
};

/**
* \class QgsScaleComboAction
* Allows embedding a scale combo into a menu.
* \note added in QGIS 3.0
*/

class QgsScaleComboAction: public QWidgetAction
{
Q_OBJECT

public:

QgsScaleComboAction( QWidget *parent = nullptr );

QgsScaleComboBox *scaleCombo() { return mScaleCombo; }

private:
QgsScaleComboBox *mScaleCombo = nullptr;
};


0 comments on commit 02a0e53

Please sign in to comment.
You can’t perform that action at this time.