-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting width/height spin boxes to link to QgsRatioLockButton
When set, these spin boxes will automatically be updated when their accompanying spin box changes value so that the ratio is maintained.
- Loading branch information
1 parent
eb5ac44
commit 38c8268
Showing
5 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for QgsRatioLockButton | ||
.. note:: This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
""" | ||
__author__ = 'Nyall Dawson' | ||
__date__ = '18/07/2017' | ||
__copyright__ = 'Copyright 2017, The QGIS Project' | ||
# This will get replaced with a git SHA1 when you do a git archive | ||
__revision__ = '$Format:%H$' | ||
|
||
import qgis # NOQA | ||
|
||
from qgis.gui import QgsRatioLockButton | ||
|
||
from qgis.PyQt.QtWidgets import QDoubleSpinBox | ||
|
||
from qgis.testing import start_app, unittest | ||
|
||
start_app() | ||
|
||
|
||
class TestQgsRatioLockButton(unittest.TestCase): | ||
|
||
def testLinkedWidgets(self): | ||
""" test linking spin boxes to combobox""" | ||
w = qgis.gui.QgsRatioLockButton() | ||
|
||
spin_width = QDoubleSpinBox() | ||
spin_width.setMaximum(100000) | ||
spin_height = QDoubleSpinBox() | ||
spin_height.setMaximum(100000) | ||
|
||
w.setWidthSpinBox(spin_width) | ||
spin_width.setValue(1000) | ||
self.assertEqual(spin_width.value(), 1000) | ||
|
||
w.setLocked(True) | ||
spin_width.setValue(2000) | ||
self.assertEqual(spin_width.value(), 2000) | ||
w.setLocked(False) | ||
|
||
w.setHeightSpinBox(spin_height) | ||
spin_width.setValue(1000) | ||
self.assertEqual(spin_width.value(), 1000) | ||
self.assertEqual(spin_height.value(), 0) | ||
|
||
w.setLocked(True) | ||
spin_width.setValue(2000) | ||
self.assertEqual(spin_width.value(), 2000) | ||
self.assertEqual(spin_height.value(), 0) | ||
|
||
spin_height.setValue(1000) | ||
self.assertEqual(spin_width.value(), 2000) | ||
self.assertEqual(spin_height.value(), 1000) | ||
|
||
# ok, that was all setup tests... let's check the real thing now | ||
spin_width.setValue(1000) | ||
self.assertEqual(spin_width.value(), 1000) | ||
self.assertEqual(spin_height.value(), 500) | ||
spin_height.setValue(1000) | ||
self.assertEqual(spin_width.value(), 2000) | ||
self.assertEqual(spin_height.value(), 1000) | ||
|
||
w.setLocked(False) | ||
spin_width.setValue(1000) | ||
self.assertEqual(spin_width.value(), 1000) | ||
self.assertEqual(spin_height.value(), 1000) | ||
spin_height.setValue(2000) | ||
self.assertEqual(spin_width.value(), 1000) | ||
self.assertEqual(spin_height.value(), 2000) | ||
|
||
w.setLocked(True) | ||
spin_height.setValue(1000) | ||
self.assertEqual(spin_width.value(), 500) | ||
self.assertEqual(spin_height.value(), 1000) | ||
|
||
# setting to 0 should "break" lock | ||
spin_height.setValue(0) | ||
self.assertEqual(spin_width.value(), 500) | ||
self.assertEqual(spin_height.value(), 0) | ||
spin_width.setValue(1000) | ||
self.assertEqual(spin_width.value(), 1000) | ||
self.assertEqual(spin_height.value(), 0) | ||
spin_height.setValue(100) | ||
self.assertEqual(spin_width.value(), 1000) | ||
self.assertEqual(spin_height.value(), 100) | ||
|
||
spin_width.setValue(0) | ||
self.assertEqual(spin_width.value(), 0) | ||
self.assertEqual(spin_height.value(), 100) | ||
spin_height.setValue(1000) | ||
self.assertEqual(spin_width.value(), 0) | ||
self.assertEqual(spin_height.value(), 1000) | ||
spin_width.setValue(200) | ||
self.assertEqual(spin_width.value(), 200) | ||
self.assertEqual(spin_height.value(), 1000) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |