Synchronizing two GraphicsScenes
Hi!
I have the following problem;
I have two graphics scenes having same items of different size and on different positions. I just want to synchronize any transformation on them. i.e. If user moves, scale or rotate any item on one scene, it should also be done on second scene in same proportion.
Regards,
Manoj
Re: Synchronizing two GraphicsScenes
Maybe you should have one scene displayed in two different views? If that's not an option, then you should react on ItemChange events and apply the changes to appropriate items on the other scene.
Re: Synchronizing two GraphicsScenes
Thanks, I am doing the same. but following is the problem:
(1) How to find out the "appropriate items" or "relevant items" to copy the transformation matrix to and from/
(2) Is there no way to apply all the scene transformations on another scene directly without running the item loop?
Regards,
Manoj
Re: Synchronizing two GraphicsScenes
Quote:
Originally Posted by
manojmka
(1) How to find out the "appropriate items" or "relevant items" to copy the transformation matrix to and from/
When you create them, you need to store pairs of pointers to the objects somewhere so that you can later access them.
Quote:
(2) Is there no way to apply all the scene transformations on another scene directly without running the item loop?
What do you mean by the scene transformations? You want to transform the scene or items on it?
Re: Synchronizing two GraphicsScenes
I ofcourse want to transform items on the scene. But while copying all the transformations for all the items on a scene to another, is there no way to copy all the transformations performed in one go without running the loop for every item and needing to match them?
I think, data() function can also be a possibility to match items from one scene to another. The only reason that I want to copy all transformations from one scene to another is that I don't like the idea of storing all the pair of pointers or storing some data information in all graphics items.
Re: Synchronizing two GraphicsScenes
Quote:
Originally Posted by
manojmka
I ofcourse want to transform items on the scene. But while copying all the transformations for all the items on a scene to another, is there no way to copy all the transformations performed in one go without running the loop for every item and needing to match them?
If they are different scenes then no.
Quote:
I think, data() function can also be a possibility to match items from one scene to another. The only reason that I want to copy all transformations from one scene to another is that I don't like the idea of storing all the pair of pointers or storing some data information in all graphics items.
What is your goal? Why do you need two scenes with matching items and why do you need to mirror all the changes between scenes? If items have different positions, applying the same transformations to them will give different results...
Re: Synchronizing two GraphicsScenes
Sorry for the delayed reply as I was not working tomorrow. I think, I could not make you understand you the exact software requirement. Ok, Here I go;
We have a lot of small graphicsViews displaying different graphicsScenes having different layouts and images. We allow user to click on any of the graphicsView (It will be presented in a listView, i think) and then display the layout and images on a bigger GraphicsScene in bigger view. The size and position of the images has to be in proportion to the small scene.
Now, the following is needed:
(1) User should be able to make any transformations on graphics items on bigger scene and all those transformations should also be performed on relavent smaller graphics scene synchronusly.
(2) When, user selects another small graphics view, all the transofrmations made on previous one should be save and then another graphics scene should be shown on bigger one.
I am following the below mentioned approach for this:
(1) As soon as user click on a smaller graphcis view, I load the big graphcis scene with similar items having similar proportation size and position.
(2) Then, I connect small view also to that bigger scene and use the function fitInView(). This makes the transformations in both views, synchronous.
(3) When user select another small view, I need to copy all the transformations from large scene (all the items) to small scene.
I hope, above makes it clear to you to help me better!
Re: Synchronizing two GraphicsScenes
Quote:
Originally Posted by
manojmka
Sorry for the delayed reply as I was not working tomorrow. I think, I could n..
Well i don't know whether i misunderstood you , but the solution given by wysota seems to fit perfectly in your case.
What exactly is being told to you is that you maintain a single scene for both the bigger as well as smaller thumbnail. Maintain two graphics view with *same* scene - one *view* being large and other small. Scale the smaller view appropriately as needed.
Whenever an item is selected in listview, you set the same corresponding scene to both these view's and apply proper scaling to thumbnail view. Now whatever transformation is done on large view, is reflected in small view automatically as the views share same scene. You don't need to synchronize anything manually at all. :)
Have a look at chips example in the demo of qt-4.[23]+. All the four views share same scene. Try modifying one of them and notice the corresponding change in other views.
Re: Synchronizing two GraphicsScenes
Quote:
Originally Posted by
Gopala Krishna
What exactly is being told to you is that you maintain a single scene for both the bigger as well as smaller thumbnail. Maintain two graphics view with *same* scene - one *view* being large and other small. Scale the smaller view appropriately as needed.
Yes, that's exactly what I meant.
Re: Synchronizing two GraphicsScenes
Hmmmmm...
I know what you mean. This will affect the performance badly. If I try to load the smaller scene in bigger view then resolution of images will go and if I try to load all the images in smaller scenes in full resolution, memory will be used very highly!!!
Re: Synchronizing two GraphicsScenes
Use the level of detail capabilities of graphics view framework.
Re: Synchronizing two GraphicsScenes
Quote:
Originally Posted by
manojmka
Hmmmmm...
I know what you mean. This will affect the performance badly. If I try to load the smaller scene in bigger view then resolution of images will go and if I try to load all the images in smaller scenes in full resolution, memory will be used very highly!!!
What kind of items are you using ?
Re: Synchronizing two GraphicsScenes
I don't get you wysota by "Use the level of detail capabilities of graphics view framework."?
Gopal, I am using Pixmap, Text and Rectangle items for now.
Regards,
Manoj
Re: Synchronizing two GraphicsScenes
Quote:
Originally Posted by
manojmka
I don't get you wysota by "Use the level of detail capabilities of graphics view framework."?
Quote:
qreal QStyleOptionGraphicsItem::levelOfDetail
This variable holds a simple metric for determining an item's level of detail.
This simple metric provides an easy way to determine the level of detail for an item. Its value represents the maximum value of the height and width of a unity rectangle, mapped using the complete transformation matrix of the painter used to draw the item. By default, if no transformations are applied, its value is 1. If zoomed out 1:2, the level of detail will be 0.5, and if zoomed in 2:1, its value is 2.
For more advanced level-of-detail metrics, use
QStyleOptionGraphicsItem::matrix directly.
See also
QStyleOptionGraphicsItem::matrix.
You can implement an item that will use high resolution drawing when the level of detail is high and in low resolution when the item is scaled down.