Skip to content

Commit

Permalink
Add options menu and allow setting map view scale
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent 9560bba commit 02a0e53
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 0 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
177 changes: 177 additions & 0 deletions images/themes/default/mActionMapSettings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions src/app/qgsmapcanvasdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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()
Expand Down Expand Up @@ -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 );
}
27 changes: 27 additions & 0 deletions src/app/qgsmapcanvasdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};


Expand Down

0 comments on commit 02a0e53

Please sign in to comment.