122122#include " qgscomposer.h"
123123#include " qgscomposermanager.h"
124124#include " qgscomposerview.h"
125+ #include " qgsstatusbarcoordinateswidget.h"
125126#include " qgsconfigureshortcutsdialog.h"
126127#include " qgscoordinatetransform.h"
127128#include " qgscredentialdialog.h"
@@ -502,9 +503,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
502503 , mScaleLabel( 0 )
503504 , mScaleEdit( 0 )
504505 , mScaleEditValidator( 0 )
505- , mCoordsLabel( 0 )
506506 , mCoordsEdit( 0 )
507- , mCoordsEditValidator( 0 )
508507 , mRotationLabel( 0 )
509508 , mRotationEdit( 0 )
510509 , mRotationEditValidator( 0 )
@@ -521,7 +520,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
521520 , mToolPopupDisplay( 0 )
522521 , mLayerTreeCanvasBridge( 0 )
523522 , mSplash( splash )
524- , mMousePrecisionDecimalPlaces( 0 )
525523 , mInternalClipboard( 0 )
526524 , mShowProjectionTab( false )
527525 , mPythonUtils( 0 )
@@ -944,15 +942,12 @@ QgisApp::QgisApp()
944942 , mScaleLabel ( 0 )
945943 , mScaleEdit ( 0 )
946944 , mScaleEditValidator ( 0 )
947- , mCoordsLabel ( 0 )
948945 , mCoordsEdit ( 0 )
949- , mCoordsEditValidator ( 0 )
950946 , mRotationLabel ( 0 )
951947 , mRotationEdit ( 0 )
952948 , mRotationEditValidator ( 0 )
953949 , mProgressBar ( 0 )
954950 , mRenderSuppressionCBox ( 0 )
955- , mToggleExtentsViewButton ( 0 )
956951 , mOnTheFlyProjectionStatusLabel ( 0 )
957952 , mOnTheFlyProjectionStatusButton ( 0 )
958953 , mMessageButton ( 0 )
@@ -971,11 +966,9 @@ QgisApp::QgisApp()
971966 , mMapWindow ( 0 )
972967 , mQgisInterface ( 0 )
973968 , mSplash ( 0 )
974- , mMousePrecisionDecimalPlaces ( 0 )
975969 , mInternalClipboard ( 0 )
976970 , mShowProjectionTab ( false )
977971 , mpMapTipsTimer( 0 )
978- , mDizzyTimer ( 0 )
979972 , mpMaptip( 0 )
980973 , mMapTipsVisible ( false )
981974 , mFullScreenMode ( false )
@@ -1941,52 +1934,13 @@ void QgisApp::createStatusBar()
19411934 // small on some platforms. A point size of 9 still provides
19421935 // plenty of display space on 1024x768 resolutions
19431936 QFont myFont ( " Arial" , 9 );
1944-
19451937 statusBar ()->setFont ( myFont );
1946- // toggle to switch between mouse pos and extents display in status bar widget
1947- mToggleExtentsViewButton = new QToolButton ( statusBar () );
1948- mToggleExtentsViewButton ->setObjectName ( " mToggleExtentsViewButton" );
1949- mToggleExtentsViewButton ->setMaximumWidth ( 20 );
1950- // mToggleExtentsViewButton->setMaximumHeight( 20 );
1951- mToggleExtentsViewButton ->setIcon ( QgsApplication::getThemeIcon ( " tracking.png" ) );
1952- mToggleExtentsViewButton ->setToolTip ( tr ( " Toggle extents and mouse position display" ) );
1953- mToggleExtentsViewButton ->setCheckable ( true );
1954- connect ( mToggleExtentsViewButton , SIGNAL ( toggled ( bool ) ), this , SLOT ( extentsViewToggled ( bool ) ) );
1955- statusBar ()->addPermanentWidget ( mToggleExtentsViewButton , 0 );
1956-
1957- // add a label to show current position
1958- mCoordsLabel = new QLabel ( QString (), statusBar () );
1959- mCoordsLabel ->setObjectName ( " mCoordsLabel" );
1960- mCoordsLabel ->setFont ( myFont );
1961- mCoordsLabel ->setMinimumWidth ( 10 );
1962- // mCoordsLabel->setMaximumHeight( 20 );
1963- mCoordsLabel ->setMargin ( 3 );
1964- mCoordsLabel ->setAlignment ( Qt::AlignCenter );
1965- mCoordsLabel ->setFrameStyle ( QFrame::NoFrame );
1966- mCoordsLabel ->setText ( tr ( " Coordinate:" ) );
1967- mCoordsLabel ->setToolTip ( tr ( " Current map coordinate" ) );
1968- statusBar ()->addPermanentWidget ( mCoordsLabel , 0 );
19691938
19701939 // coords status bar widget
1971- mCoordsEdit = new QLineEdit ( QString (), statusBar () );
1972- mCoordsEdit ->setObjectName ( " mCoordsEdit " );
1940+ mCoordsEdit = new QgsStatusBarCoordinatesWidget ( statusBar () );
1941+ mCoordsEdit ->setMapCanvas ( mMapCanvas );
19731942 mCoordsEdit ->setFont ( myFont );
1974- mCoordsEdit ->setMinimumWidth ( 10 );
1975- mCoordsEdit ->setMaximumWidth ( 300 );
1976- // mCoordsEdit->setMaximumHeight( 20 );
1977- mCoordsEdit ->setContentsMargins ( 0 , 0 , 0 , 0 );
1978- mCoordsEdit ->setAlignment ( Qt::AlignCenter );
1979- QRegExp coordValidator ( " [+-]?\\ d+\\ .?\\ d*\\ s*,\\ s*[+-]?\\ d+\\ .?\\ d*" );
1980- mCoordsEditValidator = new QRegExpValidator ( coordValidator, mCoordsEdit );
1981- mCoordsEdit ->setWhatsThis ( tr ( " Shows the map coordinates at the "
1982- " current cursor position. The display is continuously updated "
1983- " as the mouse is moved. It also allows editing to set the canvas "
1984- " center to a given position. The format is lat,lon or east,north" ) );
1985- mCoordsEdit ->setToolTip ( tr ( " Current map coordinate (lat,lon or east,north)" ) );
19861943 statusBar ()->addPermanentWidget ( mCoordsEdit , 0 );
1987- connect ( mCoordsEdit , SIGNAL ( returnPressed () ), this , SLOT ( userCenter () ) );
1988- mDizzyTimer = new QTimer ( this );
1989- connect ( mDizzyTimer , SIGNAL ( timeout () ), this , SLOT ( dizzy () ) );
19901944
19911945 // add a label to show current scale
19921946 mScaleLabel = new QLabel ( QString (), statusBar () );
@@ -2312,9 +2266,9 @@ void QgisApp::setupConnections()
23122266
23132267 // signal when mouse moved over window (coords display in status bar)
23142268 connect ( mMapCanvas , SIGNAL ( xyCoordinates ( const QgsPoint & ) ),
2315- this , SLOT ( showMouseCoordinate ( const QgsPoint & ) ) );
2269+ this , SLOT ( saveLastMousePosition ( const QgsPoint & ) ) );
23162270 connect ( mMapCanvas , SIGNAL ( extentsChanged () ),
2317- this , SLOT ( showExtents () ) );
2271+ this , SLOT ( extentChanged () ) );
23182272 connect ( mMapCanvas , SIGNAL ( scaleChanged ( double ) ),
23192273 this , SLOT ( showScale ( double ) ) );
23202274 connect ( mMapCanvas , SIGNAL ( rotationChanged ( double ) ),
@@ -7334,7 +7288,7 @@ void QgisApp::layerSubsetString()
73347288 delete qb;
73357289}
73367290
7337- void QgisApp::showMouseCoordinate ( const QgsPoint & p )
7291+ void QgisApp::saveLastMousePosition ( const QgsPoint & p )
73387292{
73397293 if ( mMapTipsVisible )
73407294 {
@@ -7352,43 +7306,6 @@ void QgisApp::showMouseCoordinate( const QgsPoint & p )
73527306 // QgsDebugMsg("Started maptips timer");
73537307 }
73547308 }
7355- if ( mToggleExtentsViewButton ->isChecked () )
7356- {
7357- // we are in show extents mode so no need to do anything
7358- return ;
7359- }
7360- else
7361- {
7362- if ( mMapCanvas ->mapUnits () == QGis::Degrees )
7363- {
7364- if ( !mMapCanvas ->mapSettings ().destinationCrs ().isValid () )
7365- return ;
7366-
7367- QgsPoint geo = p;
7368- if ( !mMapCanvas ->mapSettings ().destinationCrs ().geographicFlag () )
7369- {
7370- QgsCoordinateTransform ct ( mMapCanvas ->mapSettings ().destinationCrs (), QgsCoordinateReferenceSystem ( GEOSRID ) );
7371- geo = ct.transform ( p );
7372- }
7373- QString format = QgsProject::instance ()->readEntry ( " PositionPrecision" , " /DegreeFormat" , " D" );
7374-
7375- if ( format == " DM" )
7376- mCoordsEdit ->setText ( geo.toDegreesMinutes ( mMousePrecisionDecimalPlaces ) );
7377- else if ( format == " DMS" )
7378- mCoordsEdit ->setText ( geo.toDegreesMinutesSeconds ( mMousePrecisionDecimalPlaces ) );
7379- else
7380- mCoordsEdit ->setText ( geo.toString ( mMousePrecisionDecimalPlaces ) );
7381- }
7382- else
7383- {
7384- mCoordsEdit ->setText ( p.toString ( mMousePrecisionDecimalPlaces ) );
7385- }
7386-
7387- if ( mCoordsEdit ->width () > mCoordsEdit ->minimumWidth () )
7388- {
7389- mCoordsEdit ->setMinimumWidth ( mCoordsEdit ->width () );
7390- }
7391- }
73927309}
73937310
73947311
@@ -7410,58 +7327,6 @@ void QgisApp::userScale()
74107327 mMapCanvas ->zoomScale ( 1.0 / mScaleEdit ->scale () );
74117328}
74127329
7413- void QgisApp::dizzy ()
7414- {
7415- // constants should go to options so that people can customize them to their taste
7416- int d = 10 ; // max. translational dizziness offset
7417- int r = 4 ; // max. rotational dizzines angle
7418- QRectF rect = mMapCanvas ->sceneRect ();
7419- if ( rect.x () < -d || rect.x () > d || rect.y () < -d || rect.y () > d )
7420- return ; // do not affect panning
7421- rect.moveTo (( qrand () % ( 2 * d ) ) - d, ( qrand () % ( 2 * d ) ) - d );
7422- mMapCanvas ->setSceneRect ( rect );
7423- QTransform matrix;
7424- matrix.rotate (( qrand () % ( 2 * r ) ) - r );
7425- mMapCanvas ->setTransform ( matrix );
7426- }
7427-
7428- void QgisApp::userCenter ()
7429- {
7430- if ( mCoordsEdit ->text () == " dizzy" )
7431- {
7432- // sometimes you may feel a bit dizzy...
7433- if ( mDizzyTimer ->isActive () )
7434- {
7435- mDizzyTimer ->stop ();
7436- mMapCanvas ->setSceneRect ( mMapCanvas ->viewport ()->rect () );
7437- mMapCanvas ->setTransform ( QTransform () );
7438- }
7439- else
7440- mDizzyTimer ->start ( 100 );
7441- }
7442- else if ( mCoordsEdit ->text () == " retro" )
7443- {
7444- mMapCanvas ->setProperty ( " retro" , !mMapCanvas ->property ( " retro" ).toBool () );
7445- refreshMapCanvas ();
7446- }
7447-
7448- QStringList parts = mCoordsEdit ->text ().split ( ' ,' );
7449- if ( parts.size () != 2 )
7450- return ;
7451-
7452- bool xOk;
7453- double x = parts.at ( 0 ).toDouble ( &xOk );
7454- if ( !xOk )
7455- return ;
7456-
7457- bool yOk;
7458- double y = parts.at ( 1 ).toDouble ( &yOk );
7459- if ( !yOk )
7460- return ;
7461-
7462- mMapCanvas ->setCenter ( QgsPoint ( x, y ) );
7463- mMapCanvas ->refresh ();
7464- }
74657330
74667331void QgisApp::userRotation ()
74677332{
@@ -7470,7 +7335,6 @@ void QgisApp::userRotation()
74707335 mMapCanvas ->refresh ();
74717336}
74727337
7473-
74747338// toggle overview status
74757339void QgisApp::isInOverview ()
74767340{
@@ -9234,32 +9098,18 @@ void QgisApp::showMapCanvas()
92349098 mCentralContainer ->setCurrentIndex ( 0 );
92359099}
92369100
9237- void QgisApp::extentsViewToggled ( bool theFlag )
9238- {
9239- if ( theFlag )
9240- {
9241- // extents view mode!
9242- mToggleExtentsViewButton ->setIcon ( QgsApplication::getThemeIcon ( " extents.png" ) );
9243- mCoordsEdit ->setToolTip ( tr ( " Map coordinates for the current view extents" ) );
9244- mCoordsEdit ->setReadOnly ( true );
9245- showExtents ();
9246- }
9247- else
9248- {
9249- // mouse cursor pos view mode!
9250- mToggleExtentsViewButton ->setIcon ( QgsApplication::getThemeIcon ( " tracking.png" ) );
9251- mCoordsEdit ->setToolTip ( tr ( " Map coordinates at mouse cursor position" ) );
9252- mCoordsEdit ->setReadOnly ( false );
9253- mCoordsLabel ->setText ( tr ( " Coordinate:" ) );
9254- }
9255- }
9256-
92579101void QgisApp::markDirty ()
92589102{
92599103 // notify the project that there was a change
92609104 QgsProject::instance ()->dirty ( true );
92619105}
92629106
9107+ void QgisApp::extentChanged ()
9108+ {
9109+ // allow symbols in the legend update their preview if they use map units
9110+ mLayerTreeView ->layerTreeModel ()->setLegendMapViewData ( mMapCanvas ->mapUnitsPerPixel (), mMapCanvas ->mapSettings ().outputDpi (), mMapCanvas ->scale () );
9111+ }
9112+
92639113void QgisApp::layersWereAdded ( const QList<QgsMapLayer *>& theLayers )
92649114{
92659115 for ( int i = 0 ; i < theLayers.size (); ++i )
@@ -9303,27 +9153,6 @@ void QgisApp::layersWereAdded( const QList<QgsMapLayer *>& theLayers )
93039153 }
93049154}
93059155
9306- void QgisApp::showExtents ()
9307- {
9308- // allow symbols in the legend update their preview if they use map units
9309- mLayerTreeView ->layerTreeModel ()->setLegendMapViewData ( mMapCanvas ->mapUnitsPerPixel (), mMapCanvas ->mapSettings ().outputDpi (), mMapCanvas ->scale () );
9310-
9311- if ( !mToggleExtentsViewButton ->isChecked () )
9312- {
9313- return ;
9314- }
9315-
9316- // update the statusbar with the current extents.
9317- QgsRectangle myExtents = mMapCanvas ->extent ();
9318- mCoordsLabel ->setText ( tr ( " Extents:" ) );
9319- mCoordsEdit ->setText ( myExtents.toString ( true ) );
9320- // ensure the label is big enough
9321- if ( mCoordsEdit ->width () > mCoordsEdit ->minimumWidth () )
9322- {
9323- mCoordsEdit ->setMinimumWidth ( mCoordsEdit ->width () );
9324- }
9325- } // QgisApp::showExtents
9326-
93279156void QgisApp::showRotation ()
93289157{
93299158 // update the statusbar with the current rotation.
@@ -9358,7 +9187,7 @@ void QgisApp::updateMouseCoordinatePrecision()
93589187 if ( dp < 0 )
93599188 dp = 0 ;
93609189
9361- mMousePrecisionDecimalPlaces = dp ;
9190+ mCoordsEdit -> setMouseCoordinatesPrecision ( dp ) ;
93629191}
93639192
93649193void QgisApp::showStatusMessage ( const QString& theMessage )
0 commit comments