Skip to content
Permalink
Browse files

move coordinates line edit to a dedicated class

* originally in QgisApp
* keep funny stuff (dizzy, retro) in there
* paste coordinates with space separator (not only comma)
  • Loading branch information
3nids committed Nov 6, 2015
1 parent 04f3216 commit 71a6a3d6ba9274193c5a0a2224c3761b1f99dd2d
@@ -30,6 +30,7 @@ SET(QGIS_APP_SRCS
qgsdecorationgriddialog.cpp
qgsdxfexportdialog.cpp
qgsformannotationdialog.cpp
qgsguivectorlayertools.cpp
qgshtmlannotationdialog.cpp
qgsdelattrdialog.cpp
qgsdiagramproperties.cpp
@@ -48,10 +49,10 @@ SET(QGIS_APP_SRCS
qgsmaplayerstyleguiutils.cpp
qgsrulebasedlabelingwidget.cpp
qgssavestyletodbdialog.cpp
qgsguivectorlayertools.cpp
qgsstatusbarcoordinateswidget.cpp
qgsversioninfo.cpp
qgswelcomepageitemsmodel.cpp
qgswelcomepage.cpp
qgsversioninfo.cpp

qgsmaptooladdfeature.cpp
qgsmaptooladdpart.cpp
@@ -176,6 +177,7 @@ SET (QGIS_APP_MOC_HDRS
qgsjoindialog.h
qgsaddtaborgroup.h
qgsannotationwidget.h
qgsapplayertreeviewmenuprovider.h
qgsattributeactiondialog.h
qgsattributetypedialog.h
qgsattributetabledialog.h
@@ -202,6 +204,7 @@ SET (QGIS_APP_MOC_HDRS
qgsfieldcalculator.h
qgsfieldsproperties.h
qgsformannotationdialog.h
qgsguivectorlayertools.h
qgshtmlannotationdialog.h
qgsidentifyresultsdialog.h
qgslabeldialog.h
@@ -214,11 +217,10 @@ SET (QGIS_APP_MOC_HDRS
qgsrulebasedlabelingwidget.h
qgssavestyletodbdialog.h
qgsshortcutsmanager.h
qgsapplayertreeviewmenuprovider.h
qgsguivectorlayertools.h
qgsstatusbarcoordinateswidget.h
qgsversioninfo.h
qgswelcomepageitemsmodel.h
qgswelcomepage.h
qgsversioninfo.h

qgsmaptooladdfeature.h
qgsmaptoolcircularstringradius.h
@@ -122,6 +122,7 @@
#include "qgscomposer.h"
#include "qgscomposermanager.h"
#include "qgscomposerview.h"
#include "qgsstatusbarcoordinateswidget.h"
#include "qgsconfigureshortcutsdialog.h"
#include "qgscoordinatetransform.h"
#include "qgscredentialdialog.h"
@@ -502,9 +503,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
, mScaleLabel( 0 )
, mScaleEdit( 0 )
, mScaleEditValidator( 0 )
, mCoordsLabel( 0 )
, mCoordsEdit( 0 )
, mCoordsEditValidator( 0 )
, mRotationLabel( 0 )
, mRotationEdit( 0 )
, mRotationEditValidator( 0 )
@@ -521,7 +520,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
, mToolPopupDisplay( 0 )
, mLayerTreeCanvasBridge( 0 )
, mSplash( splash )
, mMousePrecisionDecimalPlaces( 0 )
, mInternalClipboard( 0 )
, mShowProjectionTab( false )
, mPythonUtils( 0 )
@@ -944,15 +942,12 @@ QgisApp::QgisApp()
, mScaleLabel( 0 )
, mScaleEdit( 0 )
, mScaleEditValidator( 0 )
, mCoordsLabel( 0 )
, mCoordsEdit( 0 )
, mCoordsEditValidator( 0 )
, mRotationLabel( 0 )
, mRotationEdit( 0 )
, mRotationEditValidator( 0 )
, mProgressBar( 0 )
, mRenderSuppressionCBox( 0 )
, mToggleExtentsViewButton( 0 )
, mOnTheFlyProjectionStatusLabel( 0 )
, mOnTheFlyProjectionStatusButton( 0 )
, mMessageButton( 0 )
@@ -971,11 +966,9 @@ QgisApp::QgisApp()
, mMapWindow( 0 )
, mQgisInterface( 0 )
, mSplash( 0 )
, mMousePrecisionDecimalPlaces( 0 )
, mInternalClipboard( 0 )
, mShowProjectionTab( false )
, mpMapTipsTimer( 0 )
, mDizzyTimer( 0 )
, mpMaptip( 0 )
, mMapTipsVisible( false )
, mFullScreenMode( false )
@@ -1941,52 +1934,13 @@ void QgisApp::createStatusBar()
// small on some platforms. A point size of 9 still provides
// plenty of display space on 1024x768 resolutions
QFont myFont( "Arial", 9 );

statusBar()->setFont( myFont );
//toggle to switch between mouse pos and extents display in status bar widget
mToggleExtentsViewButton = new QToolButton( statusBar() );
mToggleExtentsViewButton->setObjectName( "mToggleExtentsViewButton" );
mToggleExtentsViewButton->setMaximumWidth( 20 );
//mToggleExtentsViewButton->setMaximumHeight( 20 );
mToggleExtentsViewButton->setIcon( QgsApplication::getThemeIcon( "tracking.png" ) );
mToggleExtentsViewButton->setToolTip( tr( "Toggle extents and mouse position display" ) );
mToggleExtentsViewButton->setCheckable( true );
connect( mToggleExtentsViewButton, SIGNAL( toggled( bool ) ), this, SLOT( extentsViewToggled( bool ) ) );
statusBar()->addPermanentWidget( mToggleExtentsViewButton, 0 );

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

//coords status bar widget
mCoordsEdit = new QLineEdit( QString(), statusBar() );
mCoordsEdit->setObjectName( "mCoordsEdit" );
mCoordsEdit = new QgsStatusBarCoordinatesWidget( statusBar() );
mCoordsEdit->setMapCanvas( mMapCanvas );
mCoordsEdit->setFont( myFont );
mCoordsEdit->setMinimumWidth( 10 );
mCoordsEdit->setMaximumWidth( 300 );
//mCoordsEdit->setMaximumHeight( 20 );
mCoordsEdit->setContentsMargins( 0, 0, 0, 0 );
mCoordsEdit->setAlignment( Qt::AlignCenter );
QRegExp coordValidator( "[+-]?\\d+\\.?\\d*\\s*,\\s*[+-]?\\d+\\.?\\d*" );
mCoordsEditValidator = new QRegExpValidator( coordValidator, mCoordsEdit );
mCoordsEdit->setWhatsThis( tr( "Shows the map coordinates at the "
"current cursor position. The display is continuously updated "
"as the mouse is moved. It also allows editing to set the canvas "
"center to a given position. The format is lat,lon or east,north" ) );
mCoordsEdit->setToolTip( tr( "Current map coordinate (lat,lon or east,north)" ) );
statusBar()->addPermanentWidget( mCoordsEdit, 0 );
connect( mCoordsEdit, SIGNAL( returnPressed() ), this, SLOT( userCenter() ) );
mDizzyTimer = new QTimer( this );
connect( mDizzyTimer, SIGNAL( timeout() ), this, SLOT( dizzy() ) );

// add a label to show current scale
mScaleLabel = new QLabel( QString(), statusBar() );
@@ -2312,9 +2266,9 @@ void QgisApp::setupConnections()

// signal when mouse moved over window (coords display in status bar)
connect( mMapCanvas, SIGNAL( xyCoordinates( const QgsPoint & ) ),
this, SLOT( showMouseCoordinate( const QgsPoint & ) ) );
this, SLOT( saveLastMousePosition( const QgsPoint & ) ) );
connect( mMapCanvas, SIGNAL( extentsChanged() ),
this, SLOT( showExtents() ) );
this, SLOT( extentChanged() ) );
connect( mMapCanvas, SIGNAL( scaleChanged( double ) ),
this, SLOT( showScale( double ) ) );
connect( mMapCanvas, SIGNAL( rotationChanged( double ) ),
@@ -7334,7 +7288,7 @@ void QgisApp::layerSubsetString()
delete qb;
}

void QgisApp::showMouseCoordinate( const QgsPoint & p )
void QgisApp::saveLastMousePosition( const QgsPoint & p )
{
if ( mMapTipsVisible )
{
@@ -7352,43 +7306,6 @@ void QgisApp::showMouseCoordinate( const QgsPoint & p )
//QgsDebugMsg("Started maptips timer");
}
}
if ( mToggleExtentsViewButton->isChecked() )
{
//we are in show extents mode so no need to do anything
return;
}
else
{
if ( mMapCanvas->mapUnits() == QGis::Degrees )
{
if ( !mMapCanvas->mapSettings().destinationCrs().isValid() )
return;

QgsPoint geo = p;
if ( !mMapCanvas->mapSettings().destinationCrs().geographicFlag() )
{
QgsCoordinateTransform ct( mMapCanvas->mapSettings().destinationCrs(), QgsCoordinateReferenceSystem( GEOSRID ) );
geo = ct.transform( p );
}
QString format = QgsProject::instance()->readEntry( "PositionPrecision", "/DegreeFormat", "D" );

if ( format == "DM" )
mCoordsEdit->setText( geo.toDegreesMinutes( mMousePrecisionDecimalPlaces ) );
else if ( format == "DMS" )
mCoordsEdit->setText( geo.toDegreesMinutesSeconds( mMousePrecisionDecimalPlaces ) );
else
mCoordsEdit->setText( geo.toString( mMousePrecisionDecimalPlaces ) );
}
else
{
mCoordsEdit->setText( p.toString( mMousePrecisionDecimalPlaces ) );
}

if ( mCoordsEdit->width() > mCoordsEdit->minimumWidth() )
{
mCoordsEdit->setMinimumWidth( mCoordsEdit->width() );
}
}
}


@@ -7410,58 +7327,6 @@ void QgisApp::userScale()
mMapCanvas->zoomScale( 1.0 / mScaleEdit->scale() );
}

void QgisApp::dizzy()
{
// constants should go to options so that people can customize them to their taste
int d = 10; // max. translational dizziness offset
int r = 4; // max. rotational dizzines angle
QRectF rect = mMapCanvas->sceneRect();
if ( rect.x() < -d || rect.x() > d || rect.y() < -d || rect.y() > d )
return; // do not affect panning
rect.moveTo(( qrand() % ( 2 * d ) ) - d, ( qrand() % ( 2 * d ) ) - d );
mMapCanvas->setSceneRect( rect );
QTransform matrix;
matrix.rotate(( qrand() % ( 2 * r ) ) - r );
mMapCanvas->setTransform( matrix );
}

void QgisApp::userCenter()
{
if ( mCoordsEdit->text() == "dizzy" )
{
// sometimes you may feel a bit dizzy...
if ( mDizzyTimer->isActive() )
{
mDizzyTimer->stop();
mMapCanvas->setSceneRect( mMapCanvas->viewport()->rect() );
mMapCanvas->setTransform( QTransform() );
}
else
mDizzyTimer->start( 100 );
}
else if ( mCoordsEdit->text() == "retro" )
{
mMapCanvas->setProperty( "retro", !mMapCanvas->property( "retro" ).toBool() );
refreshMapCanvas();
}

QStringList parts = mCoordsEdit->text().split( ',' );
if ( parts.size() != 2 )
return;

bool xOk;
double x = parts.at( 0 ).toDouble( &xOk );
if ( !xOk )
return;

bool yOk;
double y = parts.at( 1 ).toDouble( &yOk );
if ( !yOk )
return;

mMapCanvas->setCenter( QgsPoint( x, y ) );
mMapCanvas->refresh();
}

void QgisApp::userRotation()
{
@@ -7470,7 +7335,6 @@ void QgisApp::userRotation()
mMapCanvas->refresh();
}


// toggle overview status
void QgisApp::isInOverview()
{
@@ -9234,32 +9098,18 @@ void QgisApp::showMapCanvas()
mCentralContainer->setCurrentIndex( 0 );
}

void QgisApp::extentsViewToggled( bool theFlag )
{
if ( theFlag )
{
//extents view mode!
mToggleExtentsViewButton->setIcon( QgsApplication::getThemeIcon( "extents.png" ) );
mCoordsEdit->setToolTip( tr( "Map coordinates for the current view extents" ) );
mCoordsEdit->setReadOnly( true );
showExtents();
}
else
{
//mouse cursor pos view mode!
mToggleExtentsViewButton->setIcon( QgsApplication::getThemeIcon( "tracking.png" ) );
mCoordsEdit->setToolTip( tr( "Map coordinates at mouse cursor position" ) );
mCoordsEdit->setReadOnly( false );
mCoordsLabel->setText( tr( "Coordinate:" ) );
}
}

void QgisApp::markDirty()
{
// notify the project that there was a change
QgsProject::instance()->dirty( true );
}

void QgisApp::extentChanged()
{
// allow symbols in the legend update their preview if they use map units
mLayerTreeView->layerTreeModel()->setLegendMapViewData( mMapCanvas->mapUnitsPerPixel(), mMapCanvas->mapSettings().outputDpi(), mMapCanvas->scale() );
}

void QgisApp::layersWereAdded( const QList<QgsMapLayer *>& theLayers )
{
for ( int i = 0; i < theLayers.size(); ++i )
@@ -9303,27 +9153,6 @@ void QgisApp::layersWereAdded( const QList<QgsMapLayer *>& theLayers )
}
}

void QgisApp::showExtents()
{
// allow symbols in the legend update their preview if they use map units
mLayerTreeView->layerTreeModel()->setLegendMapViewData( mMapCanvas->mapUnitsPerPixel(), mMapCanvas->mapSettings().outputDpi(), mMapCanvas->scale() );

if ( !mToggleExtentsViewButton->isChecked() )
{
return;
}

// update the statusbar with the current extents.
QgsRectangle myExtents = mMapCanvas->extent();
mCoordsLabel->setText( tr( "Extents:" ) );
mCoordsEdit->setText( myExtents.toString( true ) );
//ensure the label is big enough
if ( mCoordsEdit->width() > mCoordsEdit->minimumWidth() )
{
mCoordsEdit->setMinimumWidth( mCoordsEdit->width() );
}
} // QgisApp::showExtents

void QgisApp::showRotation()
{
// update the statusbar with the current rotation.
@@ -9358,7 +9187,7 @@ void QgisApp::updateMouseCoordinatePrecision()
if ( dp < 0 )
dp = 0;

mMousePrecisionDecimalPlaces = dp;
mCoordsEdit->setMouseCoordinatesPrecision( dp );
}

void QgisApp::showStatusMessage( const QString& theMessage )

0 comments on commit 71a6a3d

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