itom
Loading...
Searching...
No Matches
ito::WidgetWrapper Class Reference

One instance of this class acts as wrapper for several import public methods of classes, derived from QObject, which should be made available by the call-method in python. More...

Public Member Functions

 WidgetWrapper (UiOrganizer *uiOrganizer)
 constructor
 
 ~WidgetWrapper ()
 destructor
 
MethodDescriptionList getMethodList (QObject *object)
 returns a list of MethodDescription, which contains all wrapped methods of the given object and all its base classes.
 
ito::RetVal call (QObject *object, int methodIndex, void **_a)
 call method which calls a wrapped method of any class derived from QObject at runtime. This call is for exampled executed by UiOrganizer::callMethod.
 
QMetaProperty fakeProperty (const QObject *baseObject, const QString &fakePropertyName, QObject **destinationObject)
 Method is able to handle unexisting properties and map them to existing ones (compatibility to QtDesigner)
 

Private Member Functions

void initMethodHash ()
 initializes the hash table containing information about all methods which should be wrapped.
 
MethodDescription buildMethodDescription (QByteArray signature, QString retType, int methodIndex, bool &ok)
 creates an instance of MethodDescription which contains all necessary information in order to call the corresponding method at runtime using the method
 
ito::RetVal callObject (QObject *object, int methodIndex, void **_a)
 
ito::RetVal callListWidget (QListWidget *listWidget, int methodIndex, void **_a)
 
ito::RetVal callComboBox (QComboBox *comboBox, int methodIndex, void **_a)
 
ito::RetVal callTabWidget (QTabWidget *tabWidget, int methodIndex, void **_a)
 
ito::RetVal callTableView (QTableView *tableView, int methodIndex, void **_a)
 
ito::RetVal callSplitter (QSplitter *splitter, int methodIndex, void **_a)
 
ito::RetVal callStatusBar (QStatusBar *statusBar, int methodIndex, void **_a)
 
ito::RetVal callMainWindow (QMainWindow *mainWindow, int methodIndex, void **_a)
 
ito::RetVal callWidget (QWidget *widget, int methodIndex, void **_a)
 
ito::RetVal callTableWidget (QTableWidget *tableWidget, int methodIndex, void **_a)
 
ito::RetVal callToolBar (QToolBar *toolbar, int methodIndex, void **_a)
 
ito::RetVal callAction (QAction *action, int methodIndex, void **_a)
 
ito::RetVal callLayout (QLayout *layout, int methodIndex, void **_a)
 
ito::RetVal callFormLayout (QFormLayout *layout, int methodIndex, void **_a)
 
ito::RetVal callGridLayout (QGridLayout *layout, int methodIndex, void **_a)
 
ito::RetVal callBoxLayout (QBoxLayout *layout, int methodIndex, void **_a)
 

Private Attributes

QHash< QString, MethodDescriptionList > m_methodHash
 
bool m_initialized
 
int m_methodIndexNotFound
 
UiOrganizerm_pUiOrganizer
 

Detailed Description

One instance of this class acts as wrapper for several import public methods of classes, derived from QObject, which should be made available by the call-method in python.

Usually, the huge meta system, provided by QMetaObject, of Qt gives the possibility to call slots and changes properties of all classes, derived from QObject, at runtime. Other public methods of these classes however can not be accessed by this runtime-system. Since the python-bindings which are integrated in the python-class UiDialog and UiDialogMetaObject use the Qt-meta system in order to access properties and connect to signals or call slots, it is also desirable to access other public methods of Qt-based classes. Frameworks, like PythonQt or PyQt have an internal parsing system which automatically creates wrappers for all public methods; here the class WidgetWrapper is a manually created wrapper for the most important methods.

Constructor & Destructor Documentation

◆ WidgetWrapper()

ito::WidgetWrapper::WidgetWrapper ( UiOrganizer * uiOrganizer)

constructor

initializes a hash table containing information about all public-methods which should be wrapped and therefore accessed for instance from the python-method "call".

See also
UiOrganizer

Member Function Documentation

◆ buildMethodDescription()

MethodDescription ito::WidgetWrapper::buildMethodDescription ( QByteArray signature,
QString retType,
int methodIndex,
bool & ok )
private

creates an instance of MethodDescription which contains all necessary information in order to call the corresponding method at runtime using the method

See also
call.

This method creates the necessary input for the constructor of MethodDescription, which has pretty much the same functionality than the call of slots in Qt at runtime using the signal/slot and Qt-meta system.

Parameters
[in]signatureis the Qt-like signature string for the method to wrap (e.g. "methodName(argType1,argType2,argType3,...)" without argument names)
[in]typenameof the return value or "void" if no return value. This return type must be known by QMetaType, which is the case for all standard types, else use
See also
qRegisterMetaType.
Parameters
[in]aself defined, unique ID for the method; this ID must only be unique within the corresponding Qt-class.
[out]okreturns whether the MethodDescription instance could successfully be built (true).
Returns
instance of MethodDescription, empty MethodDescription in case of error
See also
MethodDescription, call

◆ call()

ito::RetVal ito::WidgetWrapper::call ( QObject * object,
int methodIndex,
void ** _a )

call method which calls a wrapped method of any class derived from QObject at runtime. This call is for exampled executed by UiOrganizer::callMethod.

This method uses the class-name of object and checks if there is an call-implementation for the given methodIndex. If so, the call is executed (see switch-case inside of the method). If the method index does not fit, the class name of the base class of object is iteratively checked until either an appropriate method call could be executed or no other base class is available.

Please adapt the switch case in order to check for wrapped methods of other classes. Use the void-array _a and a reinterpret_cast- operation for accessing the necessary parameters and write back the return value of the "real" call to the wrapped public method.

Parameters
[in]objectis the instance casted to its base class QObject, whose wrapped public method should be called
[in]methodIndexis the ID of the wrapped method to call
[in/out]_a is a void-array containing the value for the return value as first element and the content of all argument as following elements. (similar to qt_metacall)
Returns
true if call could successfully be executed (only if call itself was successful), false if method could not be found
See also
UiOrganizer::callMethod

◆ fakeProperty()

QMetaProperty ito::WidgetWrapper::fakeProperty ( const QObject * baseObject,
const QString & fakePropertyName,
QObject ** destinationObject )

Method is able to handle unexisting properties and map them to existing ones (compatibility to QtDesigner)

In QtDesigner, sometimes it is possible to change properties that are not directly extracted from the QMetaObject-system. However, QtDesigner adds some artificial sets of properties, especially for widgets derived from QTreeView and QTableView. Therefore, if methods UiOrganizer::writeProperties and UiOrganizer::readProperties fail to address the given property, they call this method. In the given property can be transformed into a new property of a new object, then this is returned, else an empty QMetaProperty is returned.

Parameters
[in]baseObjectis the original input object
[in]fakePropertyNameis the artificial property name
[out]destinationObjectwill be filled with a pointer to the new object, the new property is valid for (or NULL)
Returns
instance of QMetaProperty (valid, if fakePropertyName could be converted to another property and object)
See also
UiOrganizer::writeProperties, UiOrganizer::readProperties

◆ getMethodList()

MethodDescriptionList ito::WidgetWrapper::getMethodList ( QObject * object)

returns a list of MethodDescription, which contains all wrapped methods of the given object and all its base classes.

Methods, contained in this list, can be accessed for example by python finally using the method call.

Parameters
[in]objectis the pointer to an instance derived from QObject whose wrapped public methods should be returned
Returns
list of wrapped public methods
See also
m_methodHash

◆ initMethodHash()

void ito::WidgetWrapper::initMethodHash ( )
private

initializes the hash table containing information about all methods which should be wrapped.

Every public method of a class derived from QObject can be made available for access by Python if some information about this method are contained in a corresponding instance of the class MethodDescription. A list of such instances is linked to its appropriate class and therefore stored in the hash table m_methodHash whose key is the Qt-internal name of the corresponding class. Classes which are derived from that class also have access to the recently wrapped methods.

If you want to register new wrapper methods for an Qt-based class with name "newClass", you should at first create a temporary variable of type MethodDescriptionList, which is nothing else but a QList<MethodDescription>. Then you can add elements to this list for example using the helper-method

See also
buildMethodDescription. This method returns a new value of class MethodDescription. Finally you add this list of MethodDescription to m_methodHash with the key "newClass".

All wrapped methods can finally be called by the method

See also
call, which needs the method's index and a pointer to the base class QObject*. You must also adapt the method call, in order to successfully finish the wrapping process.
buildMethodDescription, MethodDescription, MethodDescriptionList

Member Data Documentation

◆ m_initialized

bool ito::WidgetWrapper::m_initialized
private

member indicating whether the initMethodHash method already has been executed, which is done in the constructor of WidgetWrapper.

◆ m_methodHash

QHash<QString, MethodDescriptionList> ito::WidgetWrapper::m_methodHash
private

Hash-table containing a list of method description for all public methods of a class derived from QObject which should be accessed by the call method of WidgetWrapper at runtime.

◆ m_methodIndexNotFound

int ito::WidgetWrapper::m_methodIndexNotFound
private

RetVal error code if the methodIndex could not be handled by the currently tested widget.


The documentation for this class was generated from the following files: