Fix bug#125 - "QAbstractTextDocumentLayout.registerHandler apparently not working"
Added class QPyTextObject which inherits from QObject and QTextObjectInterface to
solve the issue with registerHandler, the same approach used by PyQt.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
Renato Araújo <renato.filho@openbossa.org>
This commit is contained in:
parent
94ce2814e9
commit
8f4246a522
7 changed files with 74 additions and 4 deletions
|
|
@ -27,8 +27,8 @@ macro(create_pyside_module module_name module_include_dir module_libraries modul
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
COMMENT "Running generator for ${module_name}...")
|
COMMENT "Running generator for ${module_name}...")
|
||||||
|
|
||||||
include_directories(${module_name} ${${module_include_dir}})
|
include_directories(${module_name} ${${module_include_dir}} ${pyside_SOURCE_DIR})
|
||||||
add_library(${module_name} MODULE ${${module_sources}})
|
add_library(${module_name} MODULE ${${module_sources}} ${${ARGN}})
|
||||||
set_target_properties(${module_name} PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY ${pyside_BINARY_DIR})
|
set_target_properties(${module_name} PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY ${pyside_BINARY_DIR})
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set_target_properties(${module_name} PROPERTIES SUFFIX ".pyd")
|
set_target_properties(${module_name} PROPERTIES SUFFIX ".pyd")
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,8 @@ else()
|
||||||
)
|
)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
qt4_wrap_cpp(QPYTEXTOBJECT_MOC "${pyside_SOURCE_DIR}/qpytextobject.h")
|
||||||
|
|
||||||
set(QtGui_SRC
|
set(QtGui_SRC
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qabstractbutton_wrapper.cpp
|
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qabstractbutton_wrapper.cpp
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qabstractgraphicsshapeitem_wrapper.cpp
|
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qabstractgraphicsshapeitem_wrapper.cpp
|
||||||
|
|
@ -227,6 +229,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpolygon_wrapper.cpp
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qprogressbar_wrapper.cpp
|
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qprogressbar_wrapper.cpp
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qprogressdialog_wrapper.cpp
|
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qprogressdialog_wrapper.cpp
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qproxymodel_wrapper.cpp
|
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qproxymodel_wrapper.cpp
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpytextobject_wrapper.cpp
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpushbutton_wrapper.cpp
|
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpushbutton_wrapper.cpp
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qradialgradient_wrapper.cpp
|
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qradialgradient_wrapper.cpp
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qradiobutton_wrapper.cpp
|
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qradiobutton_wrapper.cpp
|
||||||
|
|
@ -395,6 +398,7 @@ check_qt_class(QtGui QPrintEngine QtGui_SRC)
|
||||||
set(QtGui_typesystem_path "${QtCore_SOURCE_DIR}${PATH_SEP}${QtGui_SOURCE_DIR}")
|
set(QtGui_typesystem_path "${QtCore_SOURCE_DIR}${PATH_SEP}${QtGui_SOURCE_DIR}")
|
||||||
set(QtGui_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}
|
set(QtGui_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/
|
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/
|
||||||
|
${pyside_SOURCE_DIR}
|
||||||
${QT_INCLUDE_DIR}
|
${QT_INCLUDE_DIR}
|
||||||
${SHIBOKEN_INCLUDE_DIR}
|
${SHIBOKEN_INCLUDE_DIR}
|
||||||
${libpyside_SOURCE_DIR}
|
${libpyside_SOURCE_DIR}
|
||||||
|
|
@ -412,5 +416,6 @@ create_pyside_module(QtGui
|
||||||
QtGui_deps
|
QtGui_deps
|
||||||
QtGui_typesystem_path
|
QtGui_typesystem_path
|
||||||
QtGui_SRC
|
QtGui_SRC
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/typesystem_gui.xml")
|
"${CMAKE_CURRENT_BINARY_DIR}/typesystem_gui.xml"
|
||||||
|
QPYTEXTOBJECT_MOC)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1388,6 +1388,7 @@
|
||||||
<modify-argument index="1" invalidate-after-use="yes"/>
|
<modify-argument index="1" invalidate-after-use="yes"/>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
</object-type>
|
</object-type>
|
||||||
|
<object-type name="QPyTextObject" />
|
||||||
<object-type name="QActionGroup">
|
<object-type name="QActionGroup">
|
||||||
<modify-function signature="addAction(QAction*)">
|
<modify-function signature="addAction(QAction*)">
|
||||||
<modify-argument index="1">
|
<modify-argument index="1">
|
||||||
|
|
@ -2527,7 +2528,7 @@
|
||||||
<extra-includes>
|
<extra-includes>
|
||||||
<include file-name="autoarraypointer.h" location="global"/>
|
<include file-name="autoarraypointer.h" location="global"/>
|
||||||
</extra-includes>
|
</extra-includes>
|
||||||
|
|
||||||
<modify-argument index="2">
|
<modify-argument index="2">
|
||||||
<remove-argument/>
|
<remove-argument/>
|
||||||
<conversion-rule class="native">
|
<conversion-rule class="native">
|
||||||
|
|
|
||||||
|
|
@ -353,6 +353,7 @@ QT_END_HEADER
|
||||||
#undef qdoc
|
#undef qdoc
|
||||||
#endif
|
#endif
|
||||||
#include <QtGui/QtGui>
|
#include <QtGui/QtGui>
|
||||||
|
#include "qpytextobject.h"
|
||||||
#if @ENABLE_X11@
|
#if @ENABLE_X11@
|
||||||
#include <QtGui/QX11Info>
|
#include <QtGui/QX11Info>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
16
PySide/qpytextobject.h
Normal file
16
PySide/qpytextobject.h
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef QPYTEXTOBJECT
|
||||||
|
#define QPYTEXTOBJECT
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTextObjectInterface>
|
||||||
|
|
||||||
|
class QPyTextObject : public QObject, public QTextObjectInterface
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_INTERFACES(QTextObjectInterface)
|
||||||
|
public:
|
||||||
|
QPyTextObject(QObject* parent = 0) : QObject(parent) {}
|
||||||
|
void drawObject(QPainter* painter, const QRectF& rect, QTextDocument* doc, int posInDocument, const QTextFormat& format ) = 0;
|
||||||
|
QSizeF intrinsicSize(QTextDocument* doc, int posInDocument, const QTextFormat& format ) = 0;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
@ -14,6 +14,7 @@ PYSIDE_TEST(missing_symbols_test.py)
|
||||||
PYSIDE_TEST(paint_event_test.py)
|
PYSIDE_TEST(paint_event_test.py)
|
||||||
PYSIDE_TEST(parent_method_test.py)
|
PYSIDE_TEST(parent_method_test.py)
|
||||||
PYSIDE_TEST(python_properties_test.py)
|
PYSIDE_TEST(python_properties_test.py)
|
||||||
|
PYSIDE_TEST(qabstracttextdocumentlayout_test.py)
|
||||||
PYSIDE_TEST(qapplication_exit_segfault_test.py)
|
PYSIDE_TEST(qapplication_exit_segfault_test.py)
|
||||||
PYSIDE_TEST(qapplication_singleton_test.py)
|
PYSIDE_TEST(qapplication_singleton_test.py)
|
||||||
PYSIDE_TEST(qapp_test.py)
|
PYSIDE_TEST(qapp_test.py)
|
||||||
|
|
|
||||||
46
tests/QtGui/qabstracttextdocumentlayout_test.py
Normal file
46
tests/QtGui/qabstracttextdocumentlayout_test.py
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
import unittest
|
||||||
|
import colorsys
|
||||||
|
|
||||||
|
from PySide.QtCore import *
|
||||||
|
from PySide.QtGui import *
|
||||||
|
from helper import UsesQApplication
|
||||||
|
|
||||||
|
class Foo(QPyTextObject):
|
||||||
|
called = False
|
||||||
|
|
||||||
|
def intrinsicSize(self, doc, posInDocument, format):
|
||||||
|
Foo.called = True
|
||||||
|
return QSizeF(10, 10)
|
||||||
|
|
||||||
|
def drawObject(self, painter, rect, doc, posInDocument, format):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class QAbstractTextDocumentLayoutTest(UsesQApplication):
|
||||||
|
|
||||||
|
objectType = QTextFormat.UserObject + 1
|
||||||
|
|
||||||
|
def foo(self):
|
||||||
|
fmt = QTextCharFormat()
|
||||||
|
fmt.setObjectType(QAbstractTextDocumentLayoutTest.objectType)
|
||||||
|
|
||||||
|
cursor = self.textEdit.textCursor()
|
||||||
|
cursor.insertText(unichr(0xfffc), fmt)
|
||||||
|
self.textEdit.setTextCursor(cursor)
|
||||||
|
self.textEdit.close()
|
||||||
|
|
||||||
|
def testIt(self):
|
||||||
|
|
||||||
|
self.textEdit = QTextEdit()
|
||||||
|
self.textEdit.show()
|
||||||
|
|
||||||
|
interface = Foo()
|
||||||
|
self.textEdit.document().documentLayout().registerHandler(QAbstractTextDocumentLayoutTest.objectType, interface)
|
||||||
|
|
||||||
|
QTimer.singleShot(0, self.foo)
|
||||||
|
self.app.exec_()
|
||||||
|
|
||||||
|
self.assertTrue(Foo.called)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue