Results 1 to 5 of 5

Thread: To any Qgraphics framework guru... need a solution...

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default To any Qgraphics framework guru... need a solution...

    Hello and excuse for my todays posts
    Finally I cannot do a correct solution for a common problem. Need your help.

    I want to have a QGrapchics framework view & edit capabilities for manage big vectorial worlds. I'm testing my program against a world with 100000 item entities.
    Ok. The feed of system is fast and also its initial visualization.
    The problem was when I want to take control over the paint event. (in example to know when the draw is done)
    If I use a paintevent, I have to recall QgraphicsView:aint(). No problem.

    The big problem I have is when I want to create a dynamic new element (havin the other 100000 items). In example , a new line. To create this line I do the first click and then, when moving the mouse, as expected, I want to view the line. No problem with this. The problem is that I have a repaint for every item intercepted. In case of drawing a new rectangle the problem grows.

    To avoid this, I have tried this trick.
    I create a temporal item, not added to the scene. On mouse_move_event I throws an invalidate event for the foreground layer, in which I'm going to draw this temporal item. I expected that exist some 'auto' buffer strategy at itemslayer, but not. I see how I have a paintevent. Ok, to avoid this, I create a pixmap at the begin of my edit process, copying the screen , later at the paintevent, where I know if I'm editing, I make a pixmap copy to later draw the temporal line at drawforeground event. (subclased). I have passing a rect for the whole scene ( I pass full scene rect because if no by any reason, foreground painting is strange) (I know that a right rect, restricted only to the area needed, would be better, but...)

    The big problem: I have to 'recall' Graphicsview:aint, because if not the drawforeground is not throwed. But doing this means that the QGraphicscene order a repaint for the items...

    This is the code for the paintevent of my class, that extends QGrapchisView.

    Qt Code:
    1. void A_Gview2D::paintEvent(QPaintEvent *event) {
    2.  
    3. if (w_temp_item!=0 )
    4. {
    5. QPainter painter(this->viewport());
    6. painter.drawPixmap(0,0,*pixMap_cached1);
    7. QGraphicsView::paintEvent(event);
    8. // This is the big problem
    9. // If I dont use it, I have not drawforeground , If I use it I have drawforeground but before repaint
    10. // all items....
    11. }
    12. else
    13. {
    14. w_qtutil->time_start();
    15. QGraphicsView::paintEvent(event);
    16. w_qtutil->time_stop();
    17. qDebug()<< w_qtutil->time_spent()<<"";
    18. }
    19. }
    20.  
    21. Mousemove code for a rectangle example:
    22.  
    23. if (w_click_count==1)
    24. {
    25. w_current_Gitem = new A_GItem(WW::Graph_rectangle, QRect(0,0,0,0), punteroo,0);
    26. w_current_Gitem->w_set_draw_props(1,1,1);
    27. w_current_Gitem->setPos(x,y);
    28. last_point_x=x;last_point_y=y;
    29. w_click_count++;
    30. G_view->w_set_temp_item(w_current_Gitem); // set the temporal item
    31. G_view->w_pixmap_copy(); // copy screen
    32. return;
    33. }
    34. else
    35. {
    36. double center_x=(last_point_x+x) /2;
    37. double center_y=(last_point_y+y) /2;
    38. double ix=W_MATH::my_abs(x-last_point_x)/2;
    39. double iy=W_MATH::my_abs(y-last_point_y)/2;
    40.  
    41. w_current_Gitem->w_set_rect( QRectF(-ix,-iy,ix*2,iy*2));
    42. w_current_Gitem->setPos(center_x,center_y);
    43.  
    44. if (w_mouse_action==5) //click
    45. {
    46. w_click_count=0; // done.
    47. G_scene->addItem(w_current_Gitem);
    48. G_view->w_set_temp_item(0);
    49. }
    50. else
    51. { w_click_count++;
    52. G_scene->invalidate(QRectF(x1,y1,xx,yy), QGraphicsScene::ForegroundLayer);
    53. // x1,y1,xx,yy are the total scene limits.
    54. return;
    55. }
    56.  
    57. }
    To copy to clipboard, switch view to plain text mode 


    I need your help. Thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,376
    Thanks
    246
    Thanked 687 Times in 677 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: To any Qgraphics framework guru... need a solution...

    If I understand your description correctly, your problem is that you have a large number of static objects in your scene, and you want to be able to

    1) dynamically add and position new items
    2) move and resize existing items

    without a redraw each time the item is changed.

    Maybe this would work:

    Create a scene (scene2) and a graphics view (view2) that are only used for editing dynamic objects. The scene2 has the same world coordinates and transformations as your real scene (scene1) and the view2 is the same size and position as the real view (view1). View2 has a transparent background, and sits on top of view1.

    When you add a new item, it gets added to scene2 first. Since it is the only item in the scene, it can be moved around and sized without affecting anything else. When the user has stopped interacting with it (loses focus or after some short timeout), the item is removed from scene2 and added to scene1. Scene1 then paints itself once, and you can hide view2 if you want.

    When you edit an existing item in scene1, make a copy and put it into scene2. Again, the user can make changes, and since it is the only item in scene2, view2 gets updated instantly. After editing, copy the new size, position, and other attributes to the item in scene1. Scene1 then paints once. (Or, instead of making a copy, move the item from scene1 to scene2, then put it back when done - this means 2 paints of view1 are required).

    This is sort of the same idea as rubberband drawing - the rubberband is drawn in a separate widget with transparent background, exactly on top of the view underneath with the complex graphics. There is no need for pixmap or other backing store for the main view, because it is not touched when drawing to the widget that is on top.

  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: To any Qgraphics framework guru... need a solution...

    OK, I already had thought on this strategy. But I had the hope that it can be done applying some of I have explained,
    Thanks any way !

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,376
    Thanks
    246
    Thanked 687 Times in 677 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: To any Qgraphics framework guru... need a solution...

    Have you tried playing with the QGraphicsView::ViewportUpdateMode flags?
    Last edited by d_stranz; 29th November 2011 at 22:24.

  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: To any Qgraphics framework guru... need a solution...

    Nothing of them work as I need .... (When i have 1000 items there is no problem, but with 100000 ... ).

    I have make a suggestions to qt debug traker. Individual callers to drawforegroung, drawbackground and drawitemslayer.

    Now you can only use :
    QGraphicsView:aintEvent(event); and this throws allways 1:drawbackground 2:drawitemslayer. 3: drawforegroung,

    The work can be done, but the actual situacion forces to write more code that it dould be needed..

    Thanks again.

Similar Threads

  1. Qt Guru Required for MetaObject system problem.
    By hickscorp in forum Qt Programming
    Replies: 2
    Last Post: 5th August 2011, 14:32
  2. Animation and QGraphics
    By PrimeCP in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2009, 00:31
  3. guru, novice, Beginner, Greenhorn, ...
    By john_god in forum General Discussion
    Replies: 1
    Last Post: 11th February 2009, 06:53
  4. Qgraphics View
    By amagdy.ibrahim in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2008, 10:10
  5. Help wanted from opencvlibrary Guru WebCam image... to avi..
    By patrik08 in forum General Programming
    Replies: 2
    Last Post: 18th May 2007, 00:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.