mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
Merge pull request #5861 from signedav/bugFixSH01
Widget size handling in status bar
This commit is contained in:
commit
9a62305786
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user