Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add step properties to widget
  • Loading branch information
nyalldawson committed Nov 26, 2020
1 parent 7177226 commit b41a9a8
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
44 changes: 44 additions & 0 deletions python/gui/auto_generated/qgsrangeslider.sip.in
Expand Up @@ -146,6 +146,28 @@ position for the widget. If the value is ``True``, the minimum and maximum appea
virtual QSize minimumSizeHint() const;


int singleStep() const;
%Docstring
Returns the single step value for the widget.

This corresponds to the smaller increment or decrement applied when the user presses an arrow key.

.. seealso:: :py:func:`setSingleStep`

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

int pageStep() const;
%Docstring
Returns the page step value for the widget.

This corresponds to the larger increment or decrement applied when the user presses the page increment key (usually PageUp or PageDown).

.. seealso:: :py:func:`setPageStep`

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

public slots:

void setMaximum( int maximum );
Expand Down Expand Up @@ -204,6 +226,28 @@ Sets the current range selected in the widget.
.. seealso:: :py:func:`setLowerValue`

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

void setSingleStep( int step );
%Docstring
Sets the single ``step`` value for the widget.

This corresponds to the smaller increment or decrement applied when the user presses an arrow key.

.. seealso:: :py:func:`singleStep`

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

void setPageStep( int step );
%Docstring
Sets the page ``step`` value for the widget.

This corresponds to the larger increment or decrement applied when the user presses the page increment key (usually PageUp or PageDown).

.. seealso:: :py:func:`pageStep`

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

virtual bool event( QEvent *event );
Expand Down
20 changes: 20 additions & 0 deletions src/gui/qgsrangeslider.cpp
Expand Up @@ -317,6 +317,26 @@ QRect QgsRangeSlider::selectedRangeRect()
return selectionRect.adjusted( -1, 1, 1, -1 );
}

int QgsRangeSlider::pageStep() const
{
return mPageStep;
}

void QgsRangeSlider::setPageStep( int step )
{
mPageStep = step;
}

int QgsRangeSlider::singleStep() const
{
return mSingleStep;
}

void QgsRangeSlider::setSingleStep( int step )
{
mSingleStep = step;
}

void QgsRangeSlider::setTickPosition( QSlider::TickPosition position )
{
mStyleOption.tickPosition = position;
Expand Down
43 changes: 43 additions & 0 deletions src/gui/qgsrangeslider.h
Expand Up @@ -148,6 +148,26 @@ class GUI_EXPORT QgsRangeSlider : public QWidget
QSize sizeHint() const override;
QSize minimumSizeHint() const override;

/**
* Returns the single step value for the widget.
*
* This corresponds to the smaller increment or decrement applied when the user presses an arrow key.
*
* \see setSingleStep()
* \see pageStep()
*/
int singleStep() const;

/**
* Returns the page step value for the widget.
*
* This corresponds to the larger increment or decrement applied when the user presses the page increment key (usually PageUp or PageDown).
*
* \see setPageStep()
* \see singleStep()
*/
int pageStep() const;

public slots:

/**
Expand Down Expand Up @@ -200,6 +220,26 @@ class GUI_EXPORT QgsRangeSlider : public QWidget
*/
void setRange( int lower, int upper );

/**
* Sets the single \a step value for the widget.
*
* This corresponds to the smaller increment or decrement applied when the user presses an arrow key.
*
* \see singleStep()
* \see pageStep()
*/
void setSingleStep( int step );

/**
* Sets the page \a step value for the widget.
*
* This corresponds to the larger increment or decrement applied when the user presses the page increment key (usually PageUp or PageDown).
*
* \see pageStep()
* \see setSingleStep()
*/
void setPageStep( int step );

bool event( QEvent *event ) override;

signals:
Expand All @@ -226,6 +266,9 @@ class GUI_EXPORT QgsRangeSlider : public QWidget
int mLowerValue = 0;
int mUpperValue = 0;

int mSingleStep = 1;
int mPageStep = 10;

QStyleOptionSlider mStyleOption;
enum Control
{
Expand Down
6 changes: 6 additions & 0 deletions tests/src/python/test_qgsrangeslider.py
Expand Up @@ -39,6 +39,12 @@ def testSettersGetters(self):
w.setFlippedDirection(True)
self.assertTrue(w.flippedDirection())

w.setSingleStep(2)
self.assertEqual(w.singleStep(), 2)

w.setPageStep(5)
self.assertEqual(w.pageStep(), 5)

def testLimits(self):
w = QgsRangeSlider()
spy = QSignalSpy(w.rangeLimitsChanged)
Expand Down

0 comments on commit b41a9a8

Please sign in to comment.