Skip to content
Permalink
Browse files

Allow reseting ratio manually for linked ratio lock buttons

  • Loading branch information
nyalldawson committed Oct 10, 2017
1 parent ea453be commit aebe5a42e6b6f4acb6edde667ed346beb95a207f
@@ -67,6 +67,12 @@ class QgsRatioLockButton : QToolButton
.. seealso:: setWidthSpinBox()
%End

void resetRatio();
%Docstring
Resets the current width/height ratio, taking the width and height
from the current values of the width and height spin boxes.
%End

signals:

void lockChanged( const bool locked );
@@ -156,3 +156,9 @@ void QgsRatioLockButton::setHeightSpinBox( QDoubleSpinBox *widget )
mPrevHeight = widget->value();
connect( mHeightSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsRatioLockButton::heightSpinBoxChanged );
}

void QgsRatioLockButton::resetRatio()
{
mPrevWidth = mWidthSpinBox ? mWidthSpinBox->value() : 0.0;
mPrevHeight = mHeightSpinBox ? mHeightSpinBox->value() : 0.0;
}
@@ -82,6 +82,12 @@ class GUI_EXPORT QgsRatioLockButton : public QToolButton
*/
void setHeightSpinBox( QDoubleSpinBox *widget );

/**
* Resets the current width/height ratio, taking the width and height
* from the current values of the width and height spin boxes.
*/
void resetRatio();

signals:

/**
@@ -99,6 +99,37 @@ def testLinkedWidgets(self):
self.assertEqual(spin_width.value(), 200)
self.assertEqual(spin_height.value(), 1000)

def testResetRatio(self):
w = qgis.gui.QgsRatioLockButton()

spin_width = QDoubleSpinBox()
spin_width.setMaximum(100000)
spin_height = QDoubleSpinBox()
spin_height.setMaximum(100000)

spin_width.setValue(1000)
w.setWidthSpinBox(spin_width)
spin_height.setValue(500)
w.setHeightSpinBox(spin_height)

w.setLocked(True)
spin_width.setValue(2000)
self.assertEqual(spin_height.value(), 1000)

spin_width.blockSignals(True)
spin_width.setValue(1000)
spin_width.blockSignals(False)

spin_height.setValue(2000)
self.assertEqual(spin_width.value(), 4000) # signals were blocked, so ratio wasn't updated

spin_width.blockSignals(True)
spin_width.setValue(2000)
spin_width.blockSignals(False)
w.resetRatio() # since signals were blocked, we need to manually reset ratio
spin_height.setValue(1000)
self.assertEqual(spin_width.value(), 1000)


if __name__ == '__main__':
unittest.main()

0 comments on commit aebe5a4

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