PDA

View Full Version : QTreeModel Items to a Widget



baray98
27th December 2007, 07:25
My app is an interface to a system in which i represented all command and response available in a QTreeModel style. Representation example below


// command tree
Commands
|__Device1
| |__SignatureRq
| | |__Opcode
| |
| |__AnotherRqForThisDevice
| |__data for this Req
| |__data for this Req
|__ Device2
|__SignatureWriteRq
| |__SerialNo
| |__Manufacturing Date
| |__FirmwareVersion
|
|__AnotherRqForThisDevice
|__data for this Req

// response tree
Response
|__Device1
| |__SignatureRsp
| | |__SerialNo
| | |__Manufacturing Date
| | |__FirmwareVersion
| |
| |__AnotherRspForThisDevice
| |__data for this Rsp
|__ Device2
|__SignatureRsp
| |__SerialNo
| |__Manufacturing Date
| |__FirmwareVersion
|
|__AnotherRspForThisDevice
|__data for this Rsp


User can click a command item of a certain device and click a send command button and look at the response at the coresponding response from the device at the response tree...

Now, this style is good for the engineering user for they know what request to use and what response to look for in the response tree but I was ask to make an interface for the normal user then came my problem. I would like to somehow create a widget that represent each device and pick some not all the command and show the response in a user firendly fashion. I would like to use my tree model as the backbone of this interface so that if the designer decides to add or delete some command ill just edit my tree and my interface will adjust.

My million dollar question is

can I somehow link a widget to represent an Item including its children of my model? notice that the devices ( device 1 and so on ) is always the child of COMMAND/RESPONSE Item in my model, and the children of my devices is the available command or response depending on which model you are looking.

What is the easiest way to implement this goal? I was planning to use a delegate to somehow draw my Widget so i will still have a tree like view as viewer.

Is there any other simple way to achieve my goal?

Lastly, Did you guys have a good holiday season ?

baray98

wysota
27th December 2007, 16:42
I suggest you have a hidden role that will tell you the type of each argument of each command and simply have a component that will build widgets according to the information stored in the model. The functionality will be close to what property browsers offer only that the visual representation will be different.

Take a look at this:
http://doc.trolltech.com/qq/qq13-attributes.html

baray98
28th December 2007, 18:11
I did some reading on that document but when i tried the source it won't compile on me the problem is that qvaluevector.h is missing. well well anyways my understanding is still not clear of what is needed to be done . Any more links and example which I can study on or better yet you can explain a little bit of some idea in how my problem be solved.

thanks for your reply wyosota, i love you man .......

still reading some qt docs,
baray98

wysota
28th December 2007, 19:34
The code is for Qt3. You have to port it to Qt4. I wanted to show you the idea, not a final solution.

baray98
28th December 2007, 20:25
thats what i tought its qt3 but.. thank you for the link . I want some more examples or explainations , hoping a way to solve this problem.

baray98

wysota
28th December 2007, 22:49
If you like the approach then simply port the code. It should take no more than 10 minutes to do it.

baray98
29th December 2007, 09:27
What i would like to do is to draw a widget in tree like fashion ie:



Device1
----------
| |
| |----------Device 2
| |
| |-------------Device 3
|
|
Device 4
|_______Device5
|_______Device 5


The user can click on the "device widget" and another widget will pop-up showing its signature and some other info that is neccessary. All this widget and the poping widget should all be dynamically build according to the info in my models , by the way i can adjust the data in my model to hold more info to build my widgets.

Is there any more idea on how to do implement this , I've been reading a lot today and still no idea how will i implement this.

I dont even know how to draw those device widget in a tree like fashion.

I am super tired now I have to sleep, talk you later guys
baray98

wysota
29th December 2007, 12:26
Can't you implement it like in the example I gave you? It's all there - the "attributes" are your tree items. Simply fetch data from the tree and fill in the dialog. Is there a specific implementation problem you are facing or a simple lack of concept?

As for the tree - use a tree view with a model that will map devices to nodes. Everything else will be handled by the architecture.

baray98
29th December 2007, 17:59
I have both problems. yes, I can implement it with the "attributes" style and this will serve as my popping widget everytime my user click on a dvice widget.

Now, my specific problem for now is that how can i insert a widget as a node in treeview? I wanted it to be a widget so that i can implement the right and left click if I want. I tried the treeview->style()->drawControl() but there is no signal out from widget that i have drawn, where i can connect my showing of my "attributes" widget slot.

thank you for your insights wyosota...

baray98

wysota
29th December 2007, 22:22
It doesn't have to be a widget. You can do it though signals or delegates. See docs for QAbstractItemDelegate and friends.

baray98
29th December 2007, 23:50
all i can see in the delegate is


QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const

if i will use this then everytim my user trigger the edit then i will pop-up my "attribute" window correct?

I was thinking of giving my user contextMenu on right click of widget devices and there will be an option like "properties" then show the attribute window. is this doable? is there something i miss on delegates?

baray98

wysota
30th December 2007, 09:32
QAbstractItemDelegate::paint() and QAbstractItemDelegate::editorEvent() are the things to look at.

As for the menu, you can always subclass the widget and reimplement its context menu event, but going through the delegate is fine too.