aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@openbossa.org>2011-01-24 18:18:45 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:51:49 -0300
commit9c7755b08018b1e71d7895e20f91f848152ffe9d (patch)
tree6cc6271c1d86c5794eb433d7e4c0b74d93b7568d
parenta51b488ca06d412c7071f4f44e556d45b022ec81 (diff)
Implement support to others color spec on deepcopy function.
Created unit test QColor reduce function. Fixes bug #612. Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Marcelo Lira <marcelo.lira@openbossa.org>
-rw-r--r--PySide/QtGui/typesystem_gui_common.xml42
-rw-r--r--tests/QtGui/deepcopy_test.py25
2 files changed, 63 insertions, 4 deletions
diff --git a/PySide/QtGui/typesystem_gui_common.xml b/PySide/QtGui/typesystem_gui_common.xml
index d606fdb2b..c6f29443d 100644
--- a/PySide/QtGui/typesystem_gui_common.xml
+++ b/PySide/QtGui/typesystem_gui_common.xml
@@ -766,10 +766,44 @@
</extra-includes>
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
- <insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="iiii" />
- <replace from="%REDUCE_ARGS" to="%CPPSELF.red(), %CPPSELF.green(), %CPPSELF.blue(), %CPPSELF.alpha()" />
- </insert-template>
+ PyObject *createFunction = 0;
+
+ switch(%CPPSELF.spec()) {
+ case QColor::Rgb:
+ {
+ qreal r, g, b, a;
+ createFunction = PyObject_GetAttrString(%PYSELF, "fromRgbF");
+ %CPPSELF.getRgbF(&amp;r, &amp;g, &amp;b, &amp;a);
+ %PYARG_0 = Py_BuildValue("(N(ffff))", createFunction, r, g, b, a);
+ break;
+ }
+ case QColor::Hsv:
+ {
+ qreal h, s, v, a;
+ createFunction = PyObject_GetAttrString(%PYSELF, "fromHsvF");
+ %CPPSELF.getHsvF(&amp;h, &amp;s, &amp;v, &amp;a);
+ %PYARG_0 = Py_BuildValue("(N(ffff))", createFunction, h, s, v, a);
+ break;
+ }
+ case QColor::Cmyk:
+ {
+ qreal c, m, y, k, a;
+ createFunction = PyObject_GetAttrString(%PYSELF, "fromCmykF");
+ %CPPSELF.getCmykF(&amp;c, &amp;m, &amp;y, &amp;k, &amp;a);
+ %PYARG_0 = Py_BuildValue("(N(fffff))", createFunction, c, m, y, k, a);
+ break;
+ }
+ case QColor::Hsl:
+ {
+ qreal h, s, l, a;
+ createFunction = PyObject_GetAttrString(%PYSELF, "fromHslF");
+ %CPPSELF.getHsvF(&amp;h, &amp;s, &amp;l, &amp;a);
+ %PYARG_0 = Py_BuildValue("(N(ffff))", createFunction, h, s, l, a);
+ break;
+ }
+ default:
+ %PYARG_0 = 0;
+ }
</inject-code>
</add-function>
<modify-function signature="QColor(QColor::Spec)" remove="all"/>
diff --git a/tests/QtGui/deepcopy_test.py b/tests/QtGui/deepcopy_test.py
index 3e9f0f831..1f53d45f9 100644
--- a/tests/QtGui/deepcopy_test.py
+++ b/tests/QtGui/deepcopy_test.py
@@ -17,10 +17,35 @@ class DeepCopyHelper:
self.assert_(copy is not self.original)
self.assertEqual(copy, self.original)
+class DeepCopyColorHelperF:
+ def testCopy(self):
+ copy = deepcopy([self.original])[0]
+ self.assert_(copy is not self.original)
+ self.assertEqual(copy.spec(), self.original.spec())
+ # impossible to compare float point
+ # self.assertEqual(copy, self.original)
+
+
class QColorDeepCopy(DeepCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QColor("red")
+class QColorRGBDeepCopy(DeepCopyColorHelperF, unittest.TestCase):
+ def setUp(self):
+ self.original = QColor.fromRgbF(0.2, 0.3, 0.4, 0.5)
+
+class QColorHSLDeepCopy(DeepCopyColorHelperF, unittest.TestCase):
+ def setUp(self):
+ self.original = QColor.fromHslF(0.2, 0.3, 0.4, 0.5)
+
+class QColorHSVDeepCopy(DeepCopyColorHelperF, unittest.TestCase):
+ def setUp(self):
+ self.original = QColor.fromHsvF(0.2, 0.3, 0.4, 0.5)
+
+class QColorCMYKDeepCopy(DeepCopyColorHelperF, unittest.TestCase):
+ def setUp(self):
+ self.original = QColor.fromCmykF(0.2, 0.3, 0.4, 0.5, 0.6)
+
class QTransformDeepCopy(DeepCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QTransform(1, 2, 3, 4, 5, 6, 7, 8)