QGIS API Documentation  2.8.2-Wien
 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 : [email protected]
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->setIcon( QgsApplication::getThemeIcon( "/mActionMapIdentification.svg" ) );
36  layout->addWidget( mCurrentScaleButton );
37  mCurrentScaleButton->hide();
38 
39  connect( mScaleComboBox, SIGNAL( scaleChanged() ), this, SIGNAL( scaleChanged() ) );
40  connect( mCurrentScaleButton, SIGNAL( clicked() ), this, SLOT( setScaleFromCanvas() ) );
41 }
42 
43 
45 {
46 }
47 
48 void QgsScaleWidget::setShowCurrentScaleButton( bool showCurrentScaleButton )
49 {
50  mShowCurrentScaleButton = showCurrentScaleButton;
51  mCurrentScaleButton->setVisible( mShowCurrentScaleButton && mCanvas );
52 }
53 
55 {
56  mCanvas = canvas;
57  mCurrentScaleButton->setVisible( mShowCurrentScaleButton && mCanvas );
58 }
59 
61 {
62  if ( !mCanvas )
63  return;
64 
65  setScale( 1 / mCanvas->scale() );
66 }
67 
68 
69