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