Skip to content
Permalink
Browse files

move scale widget in its own class (away from qgisapp)

  • Loading branch information
3nids committed May 28, 2016
1 parent 2c1f2ce commit 69a1718b5f49b038a785fa63bece69d0cd033311
@@ -52,6 +52,7 @@ SET(QGIS_APP_SRCS
qgssavestyletodbdialog.cpp
qgsstatusbarcoordinateswidget.cpp
qgsstatusbarmagnifierwidget.cpp
qgsstatusbarscalewidget.cpp
qgsversioninfo.cpp
qgswelcomepageitemsmodel.cpp
qgswelcomepage.cpp
@@ -231,6 +232,7 @@ SET (QGIS_APP_MOC_HDRS
qgsshortcutsmanager.h
qgsstatusbarcoordinateswidget.h
qgsstatusbarmagnifierwidget.h
qgsstatusbarscalewidget.h
qgsversioninfo.h
qgswelcomepageitemsmodel.h
qgswelcomepage.h
@@ -122,8 +122,6 @@
#include "qgscomposer.h"
#include "qgscomposermanager.h"
#include "qgscomposerview.h"
#include "qgsstatusbarcoordinateswidget.h"
#include "qgsstatusbarmagnifierwidget.h"
#include "qgsconfigureshortcutsdialog.h"
#include "qgscoordinatetransform.h"
#include "qgscoordinateutils.h"
@@ -207,17 +205,19 @@
#include "qgsrasterrenderer.h"
#include "qgsrasterlayersaveasdialog.h"
#include "qgsrectangle.h"
#include "qgsscalecombobox.h"
#include "qgsscalevisibilitydialog.h"
#include "qgsgroupwmsdatadialog.h"
#include "qgsshortcutsmanager.h"
#include "qgssinglebandgrayrenderer.h"
#include "qgssnappingdialog.h"
#include "qgssponsors.h"
#include "qgsstatisticalsummarydockwidget.h"
#include "qgssymbolv2selectordialog.h"
#include "qgsstatusbarcoordinateswidget.h"
#include "qgsstatusbarmagnifierwidget.h"
#include "qgsstatusbarscalewidget.h"
#include "qgsstylev2.h"
#include "qgssvgannotationitem.h"
#include "qgssymbolv2selectordialog.h"
#include "qgstextannotationitem.h"
#include "qgstipgui.h"
#include "qgsundowidget.h"
@@ -543,9 +543,7 @@ QgisApp *QgisApp::smInstance = nullptr;
QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCheck, QWidget * parent, Qt::WindowFlags fl )
: QMainWindow( parent, fl )
, mNonEditMapTool( nullptr )
, mScaleLabel( nullptr )
, mScaleEdit( nullptr )
, mScaleEditValidator( nullptr )
, mScaleWidget( nullptr )
, mMagnifierWidget( nullptr )
, mCoordsEdit( nullptr )
, mRotationLabel( nullptr )
@@ -1001,9 +999,7 @@ QgisApp::QgisApp()
, mpGpsDock( nullptr )
, mLogDock( nullptr )
, mNonEditMapTool( nullptr )
, mScaleLabel( nullptr )
, mScaleEdit( nullptr )
, mScaleEditValidator( nullptr )
, mScaleWidget( nullptr )
, mMagnifierWidget( nullptr )
, mCoordsEdit( nullptr )
, mRotationLabel( nullptr )
@@ -2138,36 +2134,13 @@ void QgisApp::createStatusBar()
mCoordsEdit->setFont( myFont );
statusBar()->addPermanentWidget( mCoordsEdit, 0 );

// add a label to show current scale
mScaleLabel = new QLabel( QString(), statusBar() );
mScaleLabel->setObjectName( "mScaleLable" );
mScaleLabel->setFont( myFont );
mScaleLabel->setMinimumWidth( 10 );
//mScaleLabel->setMaximumHeight( 20 );
mScaleLabel->setMargin( 3 );
mScaleLabel->setAlignment( Qt::AlignCenter );
mScaleLabel->setFrameStyle( QFrame::NoFrame );
mScaleLabel->setText( tr( "Scale" ) );
mScaleLabel->setToolTip( tr( "Current map scale" ) );
statusBar()->addPermanentWidget( mScaleLabel, 0 );

mScaleEdit = new QgsScaleComboBox( statusBar() );
mScaleEdit->setObjectName( "mScaleEdit" );
mScaleEdit->setFont( myFont );
// seems setFont() change font only for popup not for line edit,
// so we need to set font for it separately
mScaleEdit->lineEdit()->setFont( myFont );
mScaleEdit->setMinimumWidth( 10 );
mScaleEdit->setContentsMargins( 0, 0, 0, 0 );
mScaleEdit->setWhatsThis( tr( "Displays the current map scale" ) );
mScaleEdit->setToolTip( tr( "Current map scale (formatted as x:y)" ) );

statusBar()->addPermanentWidget( mScaleEdit, 0 );
connect( mScaleEdit, SIGNAL( scaleChanged( double ) ), this, SLOT( userScale() ) );
mScaleWidget = new QgsStatusBarScaleWidget( mMapCanvas, statusBar() );
mScaleWidget->setFont( myFont );
statusBar()->addPermanentWidget( mScaleWidget, 0 );

// zoom widget
QSettings mySettings;
mMagnifierWidget = new QgsStatusBarMagnifierWidget( statusBar(), mMapCanvas );
mMagnifierWidget = new QgsStatusBarMagnifierWidget( mMapCanvas, statusBar() );
mMagnifierWidget->setFont( myFont );
mMagnifierWidget->setMagnificationLevel( mySettings.value( "/qgis/magnifier_level", 100 ).toInt() );
statusBar()->addPermanentWidget( mMagnifierWidget, 0 );
@@ -2227,7 +2200,7 @@ void QgisApp::createStatusBar()
mOnTheFlyProjectionStatusButton->setObjectName( "mOntheFlyProjectionStatusButton" );
// Maintain uniform widget height in status bar by setting button height same as labels
// For Qt/Mac 3.3, the default toolbutton height is 30 and labels were expanding to match
mOnTheFlyProjectionStatusButton->setMaximumHeight( mScaleLabel->height() );
mOnTheFlyProjectionStatusButton->setMaximumHeight( mScaleWidget->height() );
mOnTheFlyProjectionStatusButton->setIcon( QgsApplication::getThemeIcon( "mIconProjectionEnabled.png" ) );
mOnTheFlyProjectionStatusButton->setWhatsThis( tr( "This icon shows whether "
"on the fly coordinate reference system transformation is enabled or not. "
@@ -2247,7 +2220,7 @@ void QgisApp::createStatusBar()
mMessageButton->setWhatsThis( tr( "Messages" ) );
mMessageButton->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
mMessageButton->setObjectName( "mMessageLogViewerButton" );
mMessageButton->setMaximumHeight( mScaleLabel->height() );
mMessageButton->setMaximumHeight( mScaleWidget->height() );
mMessageButton->setCheckable( true );
statusBar()->addPermanentWidget( mMessageButton, 0 );
}
@@ -4198,7 +4171,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
mMapCanvas->refresh();
mMapCanvas->clearExtentHistory();
mMapCanvas->setRotation( 0.0 );
mScaleEdit->updateScales();
mScaleWidget->updateScales();

// set project CRS
QString defCrs = settings.value( "/Projections/projectDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
@@ -4648,7 +4621,7 @@ bool QgisApp::addProject( const QString& projectFile )
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
if ( projectScales )
{
mScaleEdit->updateScales( QgsProject::instance()->readListEntry( "Scales", "/ScalesList" ) );
mScaleWidget->updateScales( QgsProject::instance()->readListEntry( "Scales", "/ScalesList" ) );
}

mMapCanvas->updateScale();
@@ -7906,21 +7879,15 @@ void QgisApp::saveLastMousePosition( const QgsPoint & p )
void QgisApp::showScale( double theScale )
{
// Why has MapCanvas the scale inverted?
mScaleEdit->setScale( 1.0 / theScale );
mScaleWidget->setScale( 1.0 / theScale );

// Not sure if the lines below do anything meaningful /Homann
if ( mScaleEdit->width() > mScaleEdit->minimumWidth() )
if ( mScaleWidget->width() > mScaleWidget->minimumWidth() )
{
mScaleEdit->setMinimumWidth( mScaleEdit->width() );
mScaleWidget->setMinimumWidth( mScaleWidget->width() );
}
}

void QgisApp::userScale()
{
// Why has MapCanvas the scale inverted?
mMapCanvas->zoomScale( 1.0 / mScaleEdit->scale() );
}


void QgisApp::userRotation()
{
@@ -8633,7 +8600,7 @@ void QgisApp::showOptionsDialog( QWidget *parent, const QString& currentPage )

if ( oldScales != mySettings.value( "Map/scales", PROJECT_SCALES ).toString() )
{
mScaleEdit->updateScales();
mScaleWidget->updateScales();
}

qobject_cast<QgsMeasureTool*>( mMapTools.mMeasureDist )->updateSettings();
@@ -9964,7 +9931,7 @@ void QgisApp::projectProperties()
connect( pp, SIGNAL( displayPrecisionChanged() ), this,
SLOT( updateMouseCoordinatePrecision() ) );

connect( pp, SIGNAL( scalesChanged( const QStringList & ) ), mScaleEdit,
connect( pp, SIGNAL( scalesChanged( const QStringList & ) ), mScaleWidget,
SLOT( updateScales( const QStringList & ) ) );
QApplication::restoreOverrideCursor();

@@ -46,6 +46,7 @@ class QgsComposerManager;
class QgsComposerView;
class QgsStatusBarCoordinatesWidget;
class QgsStatusBarMagnifierWidget;
class QgsStatusBarScaleWidget;
class QgsContrastEnhancement;
class QgsCustomLayerOrderWidget;
class QgsDoubleSpinBox;
@@ -90,8 +91,6 @@ class QgsDecorationItem;
class QgsMessageLogViewer;
class QgsMessageBar;

class QgsScaleComboBox;

class QgsDataItem;
class QgsTileScaleWidget;

@@ -736,8 +735,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void saveLastMousePosition( const QgsPoint & );
//! Slot to show current map scale;
void showScale( double theScale );
//! Slot to handle user scale input;
void userScale();
//! Slot to handle user rotation input;
//! @note added in 2.8
void userRotation();
@@ -1589,12 +1586,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QgsMapTool *mNonEditMapTool;

//! Widget that will live on the statusbar to display "scale 1:"
QLabel *mScaleLabel;
//! Widget that will live on the statusbar to display scale value
QgsScaleComboBox *mScaleEdit;
//! The validator for the mScaleEdit
QValidator * mScaleEditValidator;
QgsStatusBarScaleWidget* mScaleWidget;

//! zoom widget
QgsStatusBarMagnifierWidget *mMagnifierWidget;
@@ -23,8 +23,7 @@
#include "qgsmapcanvas.h"
#include "qgsdoublespinbox.h"

QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget( QWidget* parent,
QgsMapCanvas *canvas ) :
QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget(QgsMapCanvas *canvas, QWidget* parent) :
QWidget( parent ),
mCanvas( canvas ),
mMagnifier( 100 ),
@@ -40,7 +40,7 @@ class APP_EXPORT QgsStatusBarMagnifierWidget : public QWidget
* @param parent is the parent widget
* @param canvas the map canvas
*/
QgsStatusBarMagnifierWidget( QWidget* parent, QgsMapCanvas *canvas );
QgsStatusBarMagnifierWidget( QgsMapCanvas *canvas, QWidget* parent = 0 );

/** Destructor */
virtual ~QgsStatusBarMagnifierWidget();
@@ -0,0 +1,88 @@
/***************************************************************************
qgsstatusbarscalewidget.cpp
begin : May 2016
copyright : (C) 2016 Denis Rouzaud
email : denis.rouzaud@gmail.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 <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QValidator>

#include "qgsstatusbarscalewidget.h"

#include "qgsmapcanvas.h"
#include "qgsscalecombobox.h"

QgsStatusBarScaleWidget::QgsStatusBarScaleWidget(QgsMapCanvas *canvas, QWidget *parent)
: QWidget(parent)
, mMapCanvas( canvas )
{
// add a label to show current scale
mLabel = new QLabel( QString(), this );
mLabel->setObjectName( "mScaleLable" );
mLabel->setMinimumWidth( 10 );
//mScaleLabel->setMaximumHeight( 20 );
mLabel->setMargin( 3 );
mLabel->setAlignment( Qt::AlignCenter );
mLabel->setFrameStyle( QFrame::NoFrame );
mLabel->setText( tr( "Scale" ) );
mLabel->setToolTip( tr( "Current map scale" ) );

mScale = new QgsScaleComboBox( this );
mScale->setObjectName( "mScaleEdit" );
// seems setFont() change font only for popup not for line edit,
// so we need to set font for it separately
mScale->setMinimumWidth( 10 );
mScale->setContentsMargins( 0, 0, 0, 0 );
mScale->setWhatsThis( tr( "Displays the current map scale" ) );
mScale->setToolTip( tr( "Current map scale (formatted as x:y)" ) );

// layout
mLayout = new QHBoxLayout( this );
mLayout->addWidget( mLabel );
mLayout->addWidget( mScale );
mLayout->setContentsMargins( 0, 0, 0, 0 );
mLayout->setAlignment( Qt::AlignRight );
mLayout->setSpacing( 0 );

setLayout( mLayout );

connect( mScale, SIGNAL( scaleChanged( double ) ), this, SLOT( userScale() ) );
}

QgsStatusBarScaleWidget::~QgsStatusBarScaleWidget()
{
}

void QgsStatusBarScaleWidget::setScale(double scale)
{
mScale->setScale(scale);
}

void QgsStatusBarScaleWidget::setFont(const QFont &font)
{
mLabel->setFont( font );
mScale->lineEdit()->setFont( font );
}

void QgsStatusBarScaleWidget::updateScales(const QStringList &scales)
{
mScale->updateScales(scales);
}

void QgsStatusBarScaleWidget::userScale()
{
// Why has MapCanvas the scale inverted?
mMapCanvas->zoomScale( 1.0 / mScale->scale() );
}

0 comments on commit 69a1718

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