QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsscalewidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsscalewidget.cpp
3  --------------------------------------
4  Date : 08.01.2015
5  Copyright : (C) 2014 Denis Rouzaud
6  Email : denis.rouzaud@gmail.com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15 
16 #include <QHBoxLayout>
17 
18 #include "qgsapplication.h"
19 #include "qgsscalewidget.h"
20 #include "qgsmapcanvas.h"
21 
23  : QWidget( parent )
24  , mCanvas( NULL )
25  , mShowCurrentScaleButton( false )
26 {
27  QHBoxLayout* layout = new QHBoxLayout( this );
28  layout->setContentsMargins( 0, 0, 0, 0 );
29  layout->setSpacing( 2 );
30 
31  mScaleComboBox = new QgsScaleComboBox( this );
32  layout->addWidget( mScaleComboBox );
33 
34  mCurrentScaleButton = new QToolButton( this );
35  mCurrentScaleButton->setToolTip( tr( "Set to current canvas scale" ) );
36  mCurrentScaleButton->setIcon( QgsApplication::getThemeIcon( "/mActionMapIdentification.svg" ) );
37  layout->addWidget( mCurrentScaleButton );
38  mCurrentScaleButton->hide();
39 
40  connect( mScaleComboBox, SIGNAL( scaleChanged() ), this, SIGNAL( scaleChanged() ) );
41  connect( mCurrentScaleButton, SIGNAL( clicked() ), this, SLOT( setScaleFromCanvas() ) );
42 }
43 
44 
46 {
47 }
48 
49 void QgsScaleWidget::setShowCurrentScaleButton( bool showCurrentScaleButton )
50 {
51  mShowCurrentScaleButton = showCurrentScaleButton;
52  mCurrentScaleButton->setVisible( mShowCurrentScaleButton && mCanvas );
53 }
54 
56 {
57  mCanvas = canvas;
58  mCurrentScaleButton->setVisible( mShowCurrentScaleButton && mCanvas );
59 }
60 
62 {
63  if ( !mCanvas )
64  return;
65 
66  setScale( 1 / mCanvas->scale() );
67 }
68 
69 
70 
QLayout * layout() const
void scaleChanged()
Signal is emitted when user has finished editing/selecting a new scale.
void setContentsMargins(int left, int top, int right, int bottom)
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
void setScaleFromCanvas()
assign the current scale from the map canvas
virtual void setVisible(bool visible)
bool showCurrentScaleButton()
void setScale(double scale)
Function to set the selected scale from double.
void setIcon(const QIcon &icon)
QString tr(const char *sourceText, const char *disambiguation, int n)
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:105
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
double scale()
Get the last reported scale of the canvas.
void setShowCurrentScaleButton(bool showCurrentScaleButton)
shows a button to set the scale to the current scale of the map canvas next to the combobox ...
QgsScaleWidget(QWidget *parent=0)
void hide()
void setMapCanvas(QgsMapCanvas *canvas)
set the map canvas associated to the current button
virtual ~QgsScaleWidget()
void setToolTip(const QString &)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setSpacing(int spacing)
A combobox which lets the user select map scale from predefined list and highlights nearest to curren...