#include <vhdQManager/vhdExport.h>
#include <vhdFundamental/vhdVoid.h>
#include <vhdQManager/vhdQWidgetFactory.h>
#include <vhdQManager/vhdIQManagerEvent.h>
Defines | |
#define | REGISTER_WIDGET_EVENT 50000 |
#define | QMANAGER_EVENT 50001 |
#define | VHD_QMANAGER_REGISTER_WIDGET_CLASS(widgetClassName) |
#define | VHD_QMANAGER_CREATE_WIDGET(ptrToWidget, widgetClassName, widgetParent, widgetName) |
VHD_QMANAGER_REGISTER_WIDGET_CLASS. | |
Functions | |
vhdCLASS_DECLARATION (vhdQManager) class VHD_QMANAGER_DLL_EXPORT vhdQManager |
#define QMANAGER_EVENT 50001 |
#define REGISTER_WIDGET_EVENT 50000 |
#define VHD_QMANAGER_CREATE_WIDGET | ( | ptrToWidget, | |||
widgetClassName, | |||||
widgetParent, | |||||
widgetName | ) |
Value:
vhdQWidgetFactory::addWidgetFactory( #widgetClassName, new widgetClassName##_vhdQWidgetFactory ); \ ptrToWidget = ( widgetClassName *) vhdQManager::createWidget( #widgetClassName, widgetParent, widgetName);
Creation of a QWidget
Call this macro where ever you want to instanciate your widget. The first argument is a QWidget pointer that will point to the widget. Typically, this macro does this : ptrToWidget = new widgetClassName ( widgetParent,widgetName);
You can call this macro only if you registered a QWidget subclass (VHD_QMANAGER_REGISTER_WIDGET_CLASS). In the case of non registered standard widgets, call QManager::create directly.
Your custom widgetClassName MUST have the default QWidget constructor profile (parent and name). Any other initialisation must be done outside the constructor (by the way, this is much more clean).
#define VHD_QMANAGER_REGISTER_WIDGET_CLASS | ( | widgetClassName | ) |
Value:
class widgetClassName##_vhdQWidgetFactory : public vhdQWidgetFactory { \ public: \ widgetClassName##_vhdQWidgetFactory (){}\ QWidget *createWidget(QString className, QWidget * parent, QString name ) {\ if (className == #widgetClassName )\ return new widgetClassName(parent,name);\ else\ return 0;\ }\ };
In order to be abble to instanciate yout custom QWidget subclass, QManager needs to first register every new QWidget class. This can be easily done by giving the classname to this macro. For example, you may include the widget declaration header file and call the macro immediately.
Your custom widgetClassName MUST have the default QWidget constructor profile ( parent and name). Any other initialisation must be done outside the constructor (by the way, this is much more clean).
vhdCLASS_DECLARATION | ( | vhdQManager | ) |
Static class that is reposnsible for creation of all QWidget on one GUI thread
QManager creates a thread dedicated to GUI, creates the QApplication and then enters into the QApplication->exec().
GUI thread is the thread on which QApplication->exec() is called. In order to be correclty updated all QWidgets must be created (new QMyWidget) on the same thread on which then QApplication->exec() is called (this thread is named in QT application as GUI thread). And this is exactly what vhdQManager does.
QManager allows you to register your widget classes (with VHD_QMANAGER_REGISTER_WIDGET_CLASS) and then creates the instances in the GUI thread (when calling VHD_QMANAGER_CREATE_WIDGET).
QManager also creates the QWidgetManager GUI tool. This widget manager keeps the list of all registered widgets and remembers their configuration for the next time (position, size and visibility). Other non documented features are obvious.
Constructor : should not be used for this static class
Destructor.
Initialisation of QManager.
QManager needs to be initialised before we can create Widgets. The Init() creates a thread dedicated to Qt and runs the QApplication::exec(). This must be done before any widget creation (in the application main, at the very begining)
Start the QManager.
Shows the loaded widgets and handles the clean exit of the application (neew the viewer to close it as it is not Qt). This should be done just before starting the main event loop.
Termination of QManager.
In order to end the application, you must end the QManager. Terminate() exit the QApplication event processing and wait the Qt thread to join. This must be done before the application terminated (in the application main, at the very end).
Create a Qt Widget
In order to create a QWidget in a thread safe way, you must ask QManager to do it for you. To do so, you must repace the normal instanciation code by a call to QManaget::createWidget.
The QManager is by default abble to build every Qt widgets (QWidget and subclasses: QDialog, QTab, QGLWidget...). For any other custom QWidget subclasses, you have to register the widget class in the vhdQWidgetFactory. See the VHD_QMANAGER_REGISTER_WIDGET_CLASS documentation for a simplified usage.
createWidget is thread safe and blocking: this mean you can call it from any thread and it will return only when the instanciation is fully performed. You can immediately use the pointer (i.e. for ptr->init();)
className | The string representing the name of the class to be instanciated. |
parent | The pointer to the parent class of the instanciated QWidget. Just put 0 for top level widgets. | |
name | The string identifying the widget. It is important and requested as the name is used in the widgetManager. |