Fix bug#427 - "QSvgWidget, load from QtCore.QByteArray does not work"
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
Renato Araújo <renato.filho@openbossa.org>
This commit is contained in:
parent
50f915572d
commit
a029d217c2
5 changed files with 758 additions and 40 deletions
|
|
@ -18,14 +18,7 @@ struct Converter<QString>
|
||||||
{
|
{
|
||||||
return PyString_Check(pyObj)
|
return PyString_Check(pyObj)
|
||||||
|| PyUnicode_Check(pyObj)
|
|| PyUnicode_Check(pyObj)
|
||||||
|| Converter<QByteArray>::checkType(pyObj)
|
|| pyObj == Py_None;
|
||||||
|| pyObj == Py_None
|
|
||||||
#if PY_VERSION_HEX < 0x03000000
|
|
||||||
|| (pyObj->ob_type->tp_as_buffer
|
|
||||||
&& PyType_HasFeature(pyObj->ob_type, Py_TPFLAGS_HAVE_GETCHARBUFFER)
|
|
||||||
&& pyObj->ob_type->tp_as_buffer->bf_getcharbuffer)
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString toCpp(PyObject* pyObj)
|
static QString toCpp(PyObject* pyObj)
|
||||||
|
|
@ -40,29 +33,7 @@ struct Converter<QString>
|
||||||
#endif
|
#endif
|
||||||
} else if (PyString_Check(pyObj)) {
|
} else if (PyString_Check(pyObj)) {
|
||||||
return QString(Converter<const char * >::toCpp(pyObj));
|
return QString(Converter<const char * >::toCpp(pyObj));
|
||||||
} else if (pyObj == Py_None) {
|
|
||||||
return QString();
|
|
||||||
} else if (Converter<QByteArray>::checkType(pyObj)) {
|
|
||||||
return QString(Converter< QByteArray >::toCpp(pyObj));
|
|
||||||
}
|
}
|
||||||
#if PY_VERSION_HEX < 0x03000000
|
|
||||||
// Support for buffer objects on QString constructor
|
|
||||||
else if (pyObj->ob_type->tp_as_buffer
|
|
||||||
&& PyType_HasFeature(pyObj->ob_type, Py_TPFLAGS_HAVE_GETCHARBUFFER)
|
|
||||||
&& pyObj->ob_type->tp_as_buffer->bf_getcharbuffer) {
|
|
||||||
QByteArray data;
|
|
||||||
PyBufferProcs* bufferProcs = pyObj->ob_type->tp_as_buffer;
|
|
||||||
int segments = bufferProcs->bf_getsegcount(pyObj, 0);
|
|
||||||
for (int i = 0; i < segments; ++i) {
|
|
||||||
char* segmentData;
|
|
||||||
int length = bufferProcs->bf_getcharbuffer(pyObj, i, &segmentData);
|
|
||||||
if (length == -1)
|
|
||||||
break;
|
|
||||||
data.append(segmentData, length);
|
|
||||||
}
|
|
||||||
return QString(data);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,5 @@ class QStringConstructor(unittest.TestCase):
|
||||||
obj.setObjectName(None)
|
obj.setObjectName(None)
|
||||||
self.assertEqual(obj.objectName(), u'')
|
self.assertEqual(obj.objectName(), u'')
|
||||||
|
|
||||||
class QStringImplicitConvertion(unittest.TestCase):
|
|
||||||
'''Implicit conversions for QString'''
|
|
||||||
|
|
||||||
def testQByteArray(self):
|
|
||||||
'''QString implicitly conversion: QByteArray'''
|
|
||||||
obj = QObject()
|
|
||||||
obj.setObjectName(QByteArray('foobar'))
|
|
||||||
self.assertEqual(obj.objectName(), u'foobar')
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
PYSIDE_TEST(qsvggenerator_test.py)
|
PYSIDE_TEST(qsvggenerator_test.py)
|
||||||
|
PYSIDE_TEST(qsvgwidget_test.py)
|
||||||
|
|
|
||||||
26
tests/QtSvg/qsvgwidget_test.py
Normal file
26
tests/QtSvg/qsvgwidget_test.py
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
import unittest, os
|
||||||
|
from PySide.QtCore import *
|
||||||
|
from PySide.QtGui import *
|
||||||
|
from PySide.QtSvg import *
|
||||||
|
|
||||||
|
class QSvgWidgetTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def testLoad(self):
|
||||||
|
tigerPath = os.path.join(os.path.dirname(__file__), 'tiger.svg')
|
||||||
|
|
||||||
|
app = QApplication([])
|
||||||
|
fromFile = QSvgWidget()
|
||||||
|
fromFile.load(tigerPath)
|
||||||
|
self.assertTrue(fromFile.renderer().isValid())
|
||||||
|
|
||||||
|
tigerFile = QFile(tigerPath)
|
||||||
|
tigerFile.open(QFile.ReadOnly)
|
||||||
|
tigerData = tigerFile.readAll()
|
||||||
|
fromContents = QSvgWidget()
|
||||||
|
fromContents.load(tigerData)
|
||||||
|
self.assertTrue(fromContents.renderer().isValid())
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
730
tests/QtSvg/tiger.svg
Normal file
730
tests/QtSvg/tiger.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 94 KiB |
Loading…
Add table
Add a link
Reference in a new issue