Fix graph blocks rendering optimization (#1164)

This commit is contained in:
Adam Zambrzycki 2019-02-05 16:21:02 +01:00 committed by xarkes
parent 8c82449423
commit 3493eae194

View File

@ -416,8 +416,8 @@ void GraphView::paintEvent(QPaintEvent *event)
int render_offset_x = -horizontalScrollBar()->value() * current_scale; int render_offset_x = -horizontalScrollBar()->value() * current_scale;
int render_offset_y = -verticalScrollBar()->value() * current_scale; int render_offset_y = -verticalScrollBar()->value() * current_scale;
int render_width = viewport()->size().width() / current_scale; int render_width = viewport()->size().width();
int render_height = viewport()->size().height() / current_scale; int render_height = viewport()->size().height();
// Do we have scrollbars? // Do we have scrollbars?
bool hscrollbar = horizontalScrollBar()->pageStep() < width * current_scale; bool hscrollbar = horizontalScrollBar()->pageStep() < width * current_scale;
@ -450,12 +450,17 @@ void GraphView::paintEvent(QPaintEvent *event)
for (auto &blockIt : blocks) { for (auto &blockIt : blocks) {
GraphBlock &block = blockIt.second; GraphBlock &block = blockIt.second;
// Check if block is visible qreal blockXRender = block.x * current_scale;
if ((block.x + block.width > -render_offset_x) || qreal blockYRender = block.y * current_scale;
(block.y + block.height > -render_offset_y) || qreal blockWidthRender = block.width * current_scale;
(-render_offset_x + render_width > block.x) || qreal blockHeightRender = block.height * current_scale;
(-render_offset_y + render_height > block.y)) {
// Only draw block if it is visible // Check if block is visible by checking if block intersects with view area
if (-render_offset_x < blockXRender + blockWidthRender
&& -render_offset_x + render_width > blockXRender
&& -render_offset_y < blockYRender + blockHeightRender
&& -render_offset_y + render_height > blockYRender) {
// If it intersects then draw it
drawBlock(p, block); drawBlock(p, block);
} }