PDA

View Full Version : QDialog with multiple backends



pratham_shah
15th May 2013, 07:52
Hi,
I am building an application where I view large data in a dialog.
Dialog contains a QTableWidget which displays the data along wth 3 buttons for Add, Edit, Delete along with other UI stuff. As the data is in some specific format which I parse and fill it in QTableWidget
Now my problem is that I have 9-10 different sources from where I get the data.
Also for each of the different dialogs handling of Add, Edit, Delete is different. Also some dialogs are kind of read only dialog where Add, Edit, Delete functionality is not available, but some different functionality like Fetch is to be provided. Also some dialogs have a combo box whose index change changes the data in the table widget.
How can I use the same UI and add something for that specific dialog ?
In other words How can I use the same dialog UI but different backends and also customise the UI for different dialog.
Hope you got my point.

Santosh Reddy
15th May 2013, 09:09
How can I use the same UI and add something for that specific dialog ?
In other words How can I use the same dialog UI but different backends and also customise the UI for different dialog.
It is possible to use multiple backend (one at a time per instance of dialog), and dialog be just one (multiple instance). Just make the dialog as composite dialog for all the use cases, i.e. containing all the possible buttons like Add/Remove/Edit/Fetch/Refresh etc. Make each backend as an instance of a class derived from a base class say AbstractBackend. The base class should provide the interface to determine if the specific implementation of the backend supports those kind of operation or not, based on which the dialog can enable/disable/hide/show the corresponding the button. You can go further and even customize dialog UI dynamically basded on information available from the interfaces provided by AbstractBackend.

pratham_shah
15th May 2013, 14:27
Sorry to say but I didn't understand it properly. You mean to say that every Backend would inherit the dialog or should contain a dialog object ? Also how my dialog class would have different implementation for Add, Edit, Delete ? Can you please explain ..

Santosh Reddy
15th May 2013, 14:58
Sorry to say but I didn't understand it properly. You mean to say that every Backend would inherit the dialog or should contain a dialog object ? Also how my dialog class would have different implementation for Add, Edit, Delete ? Can you please explain ..
-> Every backend will inherit a BaseBackend class
-> BaseBackend or any other inherited backend will not have any knowledge about any dialog, all it knows is how to Add/Delete etc
-> Dialog class know about the BaseBacked which will provied virtual methods to perform Add/Delete/Edit etc.
-> There virtual methods will be implemented by the respective backend classes
-> Dialog class knows how to trigger the editing (i.e button click or other UI operation).
-> Editing/Adding operation is managed by the dialog, one the operation is done dialog will use the BaseBackend methods to save the data back to backend

Mostly this will deal the C++ way of implementing interfaces.