PDA

View Full Version : Layered Application



csvivek
2nd April 2008, 16:59
Hi,
I am developing an RealTime Application.
This application is suppose to an area where i should be able to layers. where in one particular layer i should be able to draw, one layer where i should be able to show background images and many layers each having its own purpose. i should also have the option to enable and disable layers. on the whole i need to know how Qt supports this to the maximum? and which Qt class is the best for this kind of requirement. I am a newbie to Qt. Can anyone please help in finding this by stating the advantages and disadvantages for each class that supports this kind of layered approach.
---
Thanks...

wysota
2nd April 2008, 17:06
Take a look at QGraphicsView and family.

csvivek
2nd April 2008, 17:45
I have done 50% of the application with QPainter with support for one layer:confused:.
Now can i continue using QPainter only but still add multiple layers to it?

wysota
2nd April 2008, 18:12
Yes, but you have to do everything yourself if you don't want to use the available architecture meant for such a usecase.

spud
2nd April 2008, 18:15
Sure you can do something like



void paintEvent(QPaintEvent*)
{
QPainter painter(this);

//draw background
painter.drawPixmap(...);
painter.drawPath(...)
...

if(layer1enabled)
{
painter.save();
painter.translate(...);
painter.setOpacity(0.5);
drawRects(...)
painter.restore();
}
if(layer2enabled)
{
painter.save();
painter.translate(...);
painter.drawText(...);
painter.restore();
...
}
}

The solution won't be as elegant as using GV. You would have no help from the framework mapping click events and such, but it is definately possible.

On the other hand, QGraphicsItem also uses QPainter to draw, so porting your current code shouldn't be such a big problem.

aamer4yu
2nd April 2008, 18:33
I agree with wysota....
GraphcisView wud be better. You will need to implement a custom graphicsitem as a layer. Once u implement it, other things wud be easy like setting opacity, selecting a layer, or some fancy shape layer....:)

csvivek
3rd April 2008, 06:54
Hi thanks a lot for the replies :)

I am working on a project, wherein i need to do the following,
1.Receive data pumped from the server at the maximum possible rate.
2.Draw this data on the widget.The data drawn has to be retained for a certain period of time, after which its removed.
3.These data are suppose to be show on different layers depending on their type, Also i should be able to select the objects that are shown in each layer and do certain operations on them.

Currently i am drawing all these data on one widget, each time i get a new data using Qpainter.
Also for layers i thought i will use multiple transparent widgets :D, is this ok ?

I even studied Graphics View Framework and i feel i need to map these individual data as GraphicsItem on the Scene and display the View.
But i am not very clear whether to add the new data to already existing scene or create a new scene , also how to delete these data after certain period.

so can any of u suggest how this porting could be done. will it be easier to do the porting to graphic view from QPainter for my requirement?
if any of u have any samples on graphics view please share them other than those in Qt Documentation!
I am also supposed to display MAPS(dgn,tiff and dted files for which OPenGl will be a good option) as one layer.:), provide zoom, pan facillity.
Is there any specific class, which helps me out in this?

Looking forward to your response :)

wysota
3rd April 2008, 08:08
Also for layers i thought i will use multiple transparent widgets :D, is this ok ?
Not really.


But i am not very clear whether to add the new data to already existing scene or create a new scene , also how to delete these data after certain period.
Use a single scene and add or remove items on demand. You remove them by deleting them or using scene API for removing items (guess how the method is called).


so can any of u suggest how this porting could be done. will it be easier to do the porting to graphic view from QPainter for my requirement?
I say port to GV.

csvivek
3rd April 2008, 08:32
How to go about adding the layers in GV?
Also is Map(Dted,tiff and DGN) related activities simplified in GV?

How to change the color of an Item added to the scene based on some condition? say after 2 ms i need to change the color of an object drawn at (0,0) to green.

patrik08
3rd April 2008, 09:10
How to go about adding the layers in GV?
Also is Map(Dted,tiff and DGN) related activities simplified in GV?

How to change the color of an Item added to the scene based on some condition? say after 2 ms i need to change the color of an object drawn at (0,0) to green.

IMO have a look on http://sourceforge.net/projects/sketchbook/ QT based ..
it chance color or delete item quickly. Only port to QGraphicsView

aamer4yu
3rd April 2008, 09:50
How to change the color of an Item added to the scene based on some condition? say after 2 ms i need to change the color of an object drawn at (0,0) to green.

You can have a color attribute in the graphicsItem. Based on this u color the item. Changing color is just a matter of changing the value of the variable. Simple..


Also for ur needs GraphicsView wud be best. It provides zoom facility.
Selecting and removing objects is also easy. When u click in a scene, u get a list of items on that point. From the list u can select and remove the desired item/layer.