Permalink
1 comment
on commit
sign in to comment.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #3009 from pblottiere/magnifier
[FEATURE] add a map canvas magnifier
- Loading branch information
Showing
with
545 additions
and 15 deletions.
- +8 −1 python/core/qgsmapsettings.sip
- +10 −0 python/gui/qgsmapcanvas.sip
- +2 −0 src/app/CMakeLists.txt
- +12 −0 src/app/qgisapp.cpp
- +4 −0 src/app/qgisapp.h
- +10 −0 src/app/qgsoptions.cpp
- +105 −0 src/app/qgsstatusbarmagnifierwidget.cpp
- +78 −0 src/app/qgsstatusbarmagnifierwidget.h
- +30 −2 src/core/qgsmapsettings.cpp
- +9 −2 src/core/qgsmapsettings.h
- +4 −1 src/gui/editorwidgets/qgsdoublespinbox.h
- +21 −8 src/gui/qgsmapcanvas.cpp
- +14 −1 src/gui/qgsmapcanvas.h
- +33 −0 src/ui/qgsoptionsbase.ui
- +205 −0 tests/src/gui/testqgsmapcanvas.cpp
- BIN tests/testdata/control_images/mapcanvas/expected_map_magnification/expected_map_magnification.png
- BIN .../testdata/control_images/mapcanvas/expected_map_magnification/expected_map_magnification_mask.png
- BIN ...stdata/control_images/mapcanvas/expected_map_magnification_6_5/expected_map_magnification_6_5.png
- BIN ...a/control_images/mapcanvas/expected_map_magnification_6_5/expected_map_magnification_6_5_mask.png
@@ -0,0 +1,105 @@ | ||
/*************************************************************************** | ||
qgsstatusbarmagnifierwidget.cpp | ||
begin : April 2016 | ||
copyright : (C) 2016 Paul Blottiere, Oslandia | ||
email : paul dot blottiere at oslandia 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 <QFont> | ||
#include <QHBoxLayout> | ||
#include <QLabel> | ||
|
||
#include <qgsapplication.h> | ||
#include "qgsstatusbarmagnifierwidget.h" | ||
#include "qgsmapcanvas.h" | ||
#include "qgsdoublespinbox.h" | ||
|
||
QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget( QWidget* parent, | ||
QgsMapCanvas *canvas ) : | ||
QWidget( parent ), | ||
mCanvas( canvas ), | ||
mMagnifier( 100 ), | ||
mMagnifierMin( 100 ), | ||
mMagnifierMax( 1000 ) | ||
{ | ||
// label | ||
mLabel = new QLabel( this ); | ||
mLabel->setMinimumWidth( 10 ); | ||
mLabel->setMargin( 3 ); | ||
mLabel->setAlignment( Qt::AlignCenter ); | ||
mLabel->setFrameStyle( QFrame::NoFrame ); | ||
mLabel->setText( tr( "Magnifier" ) ); | ||
mLabel->setToolTip( tr( "Magnifier" ) ); | ||
|
||
mSpinBox = new QgsDoubleSpinBox( this ); | ||
mSpinBox->setSuffix( "%" ); | ||
mSpinBox->setClearValue( mMagnifierMin ); | ||
mSpinBox->setKeyboardTracking( false ); | ||
mSpinBox->setMaximumWidth( 120 ); | ||
mSpinBox->setDecimals( 0 ); | ||
mSpinBox->setRange( mMagnifierMin, mMagnifierMax ); | ||
mSpinBox->setWrapping( false ); | ||
mSpinBox->setSingleStep( 50 ); | ||
mSpinBox->setToolTip( tr( "Magnifier level" ) ); | ||
|
||
connect( mSpinBox, SIGNAL( valueChanged( double ) ), this, | ||
SLOT( updateMagnifier() ) ); | ||
|
||
// layout | ||
mLayout = new QHBoxLayout( this ); | ||
mLayout->addWidget( mLabel ); | ||
mLayout->addWidget( mSpinBox ); | ||
mLayout->setContentsMargins( 0, 0, 0, 0 ); | ||
mLayout->setAlignment( Qt::AlignRight ); | ||
mLayout->setSpacing( 0 ); | ||
|
||
setLayout( mLayout ); | ||
|
||
updateMagnifier(); | ||
} | ||
|
||
QgsStatusBarMagnifierWidget::~QgsStatusBarMagnifierWidget() | ||
{ | ||
} | ||
|
||
double QgsStatusBarMagnifierWidget::magnificationLevel() | ||
{ | ||
return mMagnifier; | ||
} | ||
|
||
void QgsStatusBarMagnifierWidget::setFont( const QFont& myFont ) | ||
{ | ||
mLabel->setFont( myFont ); | ||
mSpinBox->setFont( myFont ); | ||
} | ||
|
||
bool QgsStatusBarMagnifierWidget::setMagnificationLevel( int level ) | ||
{ | ||
bool rc = false; | ||
|
||
if ( level >= mMagnifierMin && level <= mMagnifierMax ) | ||
{ | ||
mSpinBox->setValue( level ); | ||
rc = true; | ||
} | ||
|
||
return rc; | ||
} | ||
|
||
void QgsStatusBarMagnifierWidget::updateMagnifier() | ||
{ | ||
// get current data | ||
mMagnifier = mSpinBox->value(); | ||
|
||
// update map canvas | ||
mCanvas->setMagnificationFactor( mMagnifier / double( mMagnifierMin ) ); | ||
} |
@@ -0,0 +1,78 @@ | ||
/*************************************************************************** | ||
qgsstatusbarmagnifierwidget.h | ||
begin : April 2016 | ||
copyright : (C) 2016 Paul Blottiere, Oslandia | ||
email : paul dot blottiere at oslandia 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 QGSSTATUSBARMAGNIFIERWIDGET_H | ||
#define QGSSTATUSBARMAGNIFIERWIDGET_H | ||
|
||
class QLabel; | ||
class QFont; | ||
class QHBoxLayout; | ||
class QgsMapCanvas; | ||
class QgsDoubleSpinBox; | ||
|
||
#include <QWidget> | ||
|
||
/** | ||
* A widget which lets the user select the current level of magnification to | ||
* apply to the canvas. | ||
* @note added in 2.16 | ||
*/ | ||
class APP_EXPORT QgsStatusBarMagnifierWidget : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** Constructor | ||
* @param parent is the parent widget | ||
* @param canvas the map canvas | ||
*/ | ||
QgsStatusBarMagnifierWidget( QWidget* parent, QgsMapCanvas *canvas ); | ||
|
||
/** Destructor */ | ||
virtual ~QgsStatusBarMagnifierWidget(); | ||
|
||
/** Set the font of the text | ||
* @param font the font to use | ||
*/ | ||
void setFont( const QFont& font ); | ||
|
||
/** Returns the current magnification level | ||
* @return magnification level | ||
*/ | ||
double magnificationLevel(); | ||
|
||
/** Set the magnification level | ||
* @param level the magnification level | ||
* @return true if the level is valid, false otherwise | ||
*/ | ||
bool setMagnificationLevel( int level ); | ||
|
||
private slots: | ||
|
||
void updateMagnifier(); | ||
|
||
private: | ||
QgsMapCanvas *mCanvas; | ||
QHBoxLayout *mLayout; | ||
QLabel *mLabel; | ||
QgsDoubleSpinBox *mSpinBox; | ||
int mMagnifier; | ||
int mMagnifierMin; | ||
int mMagnifierMax; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.
This comment has been minimized.
1602c02
Nice. Here's how it looks on my machine ATM:

Any chance we could reduce the width of the magnification spin box? We could also reduce the rotation spin box too.