Skip to content

Commit 9a62305

Browse files
authored
Merge pull request #5861 from signedav/bugFixSH01
Widget size handling in status bar
2 parents 2d9ee3d + 5cfe278 commit 9a62305

4 files changed

+24
-14
lines changed

src/app/qgisapp.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -9005,12 +9005,6 @@ void QgisApp::saveLastMousePosition( const QgsPointXY &p )
90059005
void QgisApp::showScale( double scale )
90069006
{
90079007
mScaleWidget->setScale( scale );
9008-
9009-
// Not sure if the lines below do anything meaningful /Homann
9010-
if ( mScaleWidget->width() > mScaleWidget->minimumWidth() )
9011-
{
9012-
mScaleWidget->setMinimumWidth( mScaleWidget->width() );
9013-
}
90149008
}
90159009

90169010

src/app/qgsstatusbarcoordinateswidget.cpp

+17-8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ QgsStatusBarCoordinatesWidget::QgsStatusBarCoordinatesWidget( QWidget *parent )
3333
: QWidget( parent )
3434
, mMousePrecisionDecimalPlaces( 0 )
3535
{
36+
// calculate the size of two chars
37+
mTwoCharSize = fontMetrics().width( QStringLiteral( "OO" ) );
38+
3639
// add a label to show current position
3740
mLabel = new QLabel( QString(), this );
3841
mLabel->setObjectName( QStringLiteral( "mCoordsLabel" ) );
@@ -46,7 +49,6 @@ QgsStatusBarCoordinatesWidget::QgsStatusBarCoordinatesWidget( QWidget *parent )
4649

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

229-
if ( mLineEdit->width() > mLineEdit->minimumWidth() )
230-
{
231-
mLineEdit->setMinimumWidth( mLineEdit->width() );
232-
}
231+
ensureCoordinatesVisible();
233232
}
234233

235234

@@ -244,9 +243,19 @@ void QgsStatusBarCoordinatesWidget::showExtent()
244243
QgsRectangle myExtents = mMapCanvas->extent();
245244
mLabel->setText( tr( "Extents:" ) );
246245
mLineEdit->setText( myExtents.toString( true ) );
247-
//ensure the label is big enough
248-
if ( mLineEdit->width() > mLineEdit->minimumWidth() )
246+
247+
ensureCoordinatesVisible();
248+
}
249+
250+
void QgsStatusBarCoordinatesWidget::ensureCoordinatesVisible()
251+
{
252+
253+
//ensure the label is big (and small) enough
254+
int width = mLineEdit->fontMetrics().width( mLineEdit->text() ) + 10;
255+
if ( mLineEdit->minimumWidth() < width || ( mLineEdit->minimumWidth() - width ) > mTwoCharSize )
249256
{
250-
mLineEdit->setMinimumWidth( mLineEdit->width() );
257+
mLineEdit->setMinimumWidth( width );
258+
mLineEdit->setMaximumWidth( width );
251259
}
252260
}
261+

src/app/qgsstatusbarcoordinateswidget.h

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class APP_EXPORT QgsStatusBarCoordinatesWidget : public QWidget
5959
void validateCoordinates();
6060
void dizzy();
6161
void showExtent();
62+
void ensureCoordinatesVisible();
6263

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

7577
//! The number of decimal places to use if not automatic
7678
unsigned int mMousePrecisionDecimalPlaces;

src/app/qgsstatusbarscalewidget.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ void QgsStatusBarScaleWidget::setScale( double scale )
7878
mScale->blockSignals( true );
7979
mScale->setScale( scale );
8080
mScale->blockSignals( false );
81+
82+
if ( mScale->width() > mScale->minimumWidth() )
83+
{
84+
mScale->setMinimumWidth( mScale->width() );
85+
}
8186
}
8287

8388
bool QgsStatusBarScaleWidget::isLocked() const

0 commit comments

Comments
 (0)