Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add method to set line edit alignment in Qgs(Double)SpinBox
  • Loading branch information
elpaso committed Feb 2, 2018
1 parent 287f822 commit bbf6214
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 2 deletions.
7 changes: 7 additions & 0 deletions python/gui/editorwidgets/qgsdoublespinbox.sip.in
Expand Up @@ -117,6 +117,13 @@ Defines if the clear value should be the minimum or maximum values of the widget
Returns the value used when clear() is called.

.. seealso:: :py:func:`setClearValue`
%End

void setLineEditAlignment( Qt::Alignment alignment );
%Docstring
Set alignment in the embedded line edit widget

:param alignment:
%End

virtual double valueFromText( const QString &text ) const;
Expand Down
7 changes: 7 additions & 0 deletions python/gui/editorwidgets/qgsspinbox.sip.in
Expand Up @@ -117,6 +117,13 @@ Defines if the clear value should be the minimum or maximum values of the widget
Returns the value used when clear() is called.

.. seealso:: :py:func:`setClearValue`
%End

void setLineEditAlignment( Qt::Alignment alignment );
%Docstring
Set alignment in the embedded line edit widget

:param alignment:
%End

virtual int valueFromText( const QString &text ) const;
Expand Down
6 changes: 5 additions & 1 deletion src/gui/editorwidgets/qgsdoublespinbox.cpp
Expand Up @@ -34,7 +34,6 @@ QgsDoubleSpinBox::QgsDoubleSpinBox( QWidget *parent )
// By default, group separator is off
setLocale( QLocale( QgsApplication::locale( ) ) );
setLineEdit( mLineEdit );
mLineEdit->setAlignment( Qt::AlignRight );

QSize msz = minimumSizeHint();
setMinimumSize( msz.width() + CLEAR_ICON_SIZE + 9 + frameWidth() * 2 + 2,
Expand Down Expand Up @@ -137,6 +136,11 @@ double QgsDoubleSpinBox::clearValue() const
return mCustomClearValue;
}

void QgsDoubleSpinBox::setLineEditAlignment( Qt::Alignment alignment )
{
mLineEdit->setAlignment( alignment );
}

QString QgsDoubleSpinBox::stripped( const QString &originalText ) const
{
//adapted from QAbstractSpinBoxPrivate::stripped
Expand Down
6 changes: 6 additions & 0 deletions src/gui/editorwidgets/qgsdoublespinbox.h
Expand Up @@ -126,6 +126,12 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
*/
double clearValue() const;

/**
* Set alignment in the embedded line edit widget
* \param alignment
*/
void setLineEditAlignment( Qt::Alignment alignment );

double valueFromText( const QString &text ) const override;
QValidator::State validate( QString &input, int &pos ) const override;
void paintEvent( QPaintEvent *e ) override;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/editorwidgets/qgsrangewidgetwrapper.cpp
Expand Up @@ -47,12 +47,14 @@ QWidget *QgsRangeWidgetWrapper::createWidget( QWidget *parent )
case QVariant::Double:
{
editor = new QgsDoubleSpinBox( parent );
static_cast<QgsDoubleSpinBox *>( editor )->setLineEditAlignment( Qt::AlignRight );
break;
}
case QVariant::Int:
case QVariant::LongLong:
default:
editor = new QgsSpinBox( parent );
static_cast<QgsSpinBox *>( editor )->setLineEditAlignment( Qt::AlignRight );
break;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/gui/editorwidgets/qgsspinbox.cpp
Expand Up @@ -30,7 +30,6 @@ QgsSpinBox::QgsSpinBox( QWidget *parent )
: QSpinBox( parent )
{
mLineEdit = new QgsSpinBoxLineEdit();
mLineEdit->setAlignment( Qt::AlignRight );
setLineEdit( mLineEdit );

QSize msz = minimumSizeHint();
Expand Down Expand Up @@ -133,6 +132,11 @@ int QgsSpinBox::clearValue() const
return mCustomClearValue;
}

void QgsSpinBox::setLineEditAlignment( Qt::Alignment alignment )
{
mLineEdit->setAlignment( alignment );
}

int QgsSpinBox::valueFromText( const QString &text ) const
{
if ( !mExpressionsEnabled )
Expand Down
6 changes: 6 additions & 0 deletions src/gui/editorwidgets/qgsspinbox.h
Expand Up @@ -126,6 +126,12 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
*/
int clearValue() const;

/**
* Set alignment in the embedded line edit widget
* \param alignment
*/
void setLineEditAlignment( Qt::Alignment alignment );

int valueFromText( const QString &text ) const override;
QValidator::State validate( QString &input, int &pos ) const override;

Expand Down

0 comments on commit bbf6214

Please sign in to comment.