Skip to content
Permalink
Browse files

Merge pull request #5861 from signedav/bugFixSH01

Widget size handling in status bar
  • Loading branch information
slarosa committed Feb 23, 2018
2 parents 2d9ee3d + 5cfe278 commit 9a62305786186627a4929e093811729267967849
@@ -9005,12 +9005,6 @@ void QgisApp::saveLastMousePosition( const QgsPointXY &p )
void QgisApp::showScale( double scale )
{
mScaleWidget->setScale( scale );

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


@@ -33,6 +33,9 @@ QgsStatusBarCoordinatesWidget::QgsStatusBarCoordinatesWidget( QWidget *parent )
: QWidget( parent )
, mMousePrecisionDecimalPlaces( 0 )
{
// calculate the size of two chars
mTwoCharSize = fontMetrics().width( QStringLiteral( "OO" ) );

// add a label to show current position
mLabel = new QLabel( QString(), this );
mLabel->setObjectName( QStringLiteral( "mCoordsLabel" ) );
@@ -46,7 +49,6 @@ QgsStatusBarCoordinatesWidget::QgsStatusBarCoordinatesWidget( QWidget *parent )

mLineEdit = new QLineEdit( this );
mLineEdit->setMinimumWidth( 10 );
mLineEdit->setMaximumWidth( 300 );
//mLineEdit->setMaximumHeight( 20 );
mLineEdit->setContentsMargins( 0, 0, 0, 0 );
mLineEdit->setAlignment( Qt::AlignCenter );
@@ -226,10 +228,7 @@ void QgsStatusBarCoordinatesWidget::showMouseCoordinates( const QgsPointXY &p )
mLineEdit->setText( QgsCoordinateUtils::formatCoordinateForProject( p, mMapCanvas->mapSettings().destinationCrs(),
mMousePrecisionDecimalPlaces ) );

if ( mLineEdit->width() > mLineEdit->minimumWidth() )
{
mLineEdit->setMinimumWidth( mLineEdit->width() );
}
ensureCoordinatesVisible();
}


@@ -244,9 +243,19 @@ void QgsStatusBarCoordinatesWidget::showExtent()
QgsRectangle myExtents = mMapCanvas->extent();
mLabel->setText( tr( "Extents:" ) );
mLineEdit->setText( myExtents.toString( true ) );
//ensure the label is big enough
if ( mLineEdit->width() > mLineEdit->minimumWidth() )

ensureCoordinatesVisible();
}

void QgsStatusBarCoordinatesWidget::ensureCoordinatesVisible()
{

//ensure the label is big (and small) enough
int width = mLineEdit->fontMetrics().width( mLineEdit->text() ) + 10;
if ( mLineEdit->minimumWidth() < width || ( mLineEdit->minimumWidth() - width ) > mTwoCharSize )
{
mLineEdit->setMinimumWidth( mLineEdit->width() );
mLineEdit->setMinimumWidth( width );
mLineEdit->setMaximumWidth( width );
}
}

@@ -59,6 +59,7 @@ class APP_EXPORT QgsStatusBarCoordinatesWidget : public QWidget
void validateCoordinates();
void dizzy();
void showExtent();
void ensureCoordinatesVisible();

private:
void refreshMapCanvas();
@@ -71,6 +72,7 @@ class APP_EXPORT QgsStatusBarCoordinatesWidget : public QWidget
QValidator *mCoordsEditValidator = nullptr;
QTimer *mDizzyTimer = nullptr;
QgsMapCanvas *mMapCanvas = nullptr;
int mTwoCharSize;

//! The number of decimal places to use if not automatic
unsigned int mMousePrecisionDecimalPlaces;
@@ -78,6 +78,11 @@ void QgsStatusBarScaleWidget::setScale( double scale )
mScale->blockSignals( true );
mScale->setScale( scale );
mScale->blockSignals( false );

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

bool QgsStatusBarScaleWidget::isLocked() const

0 comments on commit 9a62305

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