@@ -58,6 +58,7 @@ WTableView::WTableView()
5858 dropEvent_ (impl_ , "dropEvent" ),
5959 scrolled_ (impl_ , "scrolled" ),
6060 itemTouchSelectEvent_ (impl_ , "itemTouchSelectEvent" ),
61+ preloadMarginRows_ (-1 ),
6162 firstColumn_ (-1 ),
6263 lastColumn_ (-1 ),
6364 viewportLeft_ (0 ),
@@ -685,10 +686,14 @@ void WTableView::renderTable(const int fr, const int lr,
685686 assert (lastRow () == lr && firstRow () == fr );
686687 assert (lastColumn () == lc && firstColumn () == fc );
687688
689+ const int marginHeight = preloadMarginRows_ == -1 ?
690+ viewportHeight_ / 2 :
691+ static_cast < int > (preloadMarginRows_ * rowHeight ().toPixels ()) / 2 ;
692+
688693 int scrollX1 = std ::max (0 , viewportLeft_ - viewportWidth_ / 2 );
689694 int scrollX2 = viewportLeft_ + viewportWidth_ / 2 ;
690- int scrollY1 = std ::max (0 , viewportTop_ - viewportHeight_ / 2 );
691- int scrollY2 = viewportTop_ + viewportHeight_ / 2 ;
695+ int scrollY1 = std ::max (0 , viewportTop_ - marginHeight );
696+ int scrollY2 = viewportTop_ + marginHeight ;
692697
693698 WStringStream s ;
694699
@@ -1640,22 +1645,25 @@ void WTableView::computeRenderedArea()
16401645
16411646 if (viewportHeight_ != -1 ) {
16421647 /* row range */
1643- int top = std ::min (viewportTop_ ,
1648+ const int top = std ::min (viewportTop_ ,
16441649 static_cast < int > (canvas_ -> height ().toPixels ()));
16451650
1646- int height = std ::min (viewportHeight_ ,
1651+ const int height = std ::min (viewportHeight_ ,
16471652 static_cast < int > (canvas_ -> height ().toPixels ()));
16481653
1649- int renderedRows = static_cast < int > (height / rowHeight ().toPixels ()
1654+ const int renderedRows = static_cast < int > (height / rowHeight ().toPixels ()
16501655 + 0.5 );
16511656
16521657 renderedFirstRow_ = static_cast < int > (top / rowHeight ().toPixels ());
16531658
1659+ const int marginRows = preloadMarginRows_ == -1 ? renderedRows + borderRows : preloadMarginRows_ ;
1660+
16541661 renderedLastRow_
1655- = std ::min (renderedFirstRow_ + renderedRows * 2 + borderRows ,
1656- modelHeight - 1 );
1662+ = static_cast < int > ( std ::min (static_cast < long long > ( renderedFirstRow_ ) + renderedRows + marginRows ,
1663+ static_cast < long long > ( modelHeight - 1 )) );
16571664 renderedFirstRow_
1658- = std ::max (renderedFirstRow_ - renderedRows - borderRows , 0 );
1665+ = static_cast < int > (std ::max (static_cast < long long > (renderedFirstRow_ ) - marginRows ,
1666+ 0LL ));
16591667 } else {
16601668 renderedFirstRow_ = 0 ;
16611669 renderedLastRow_ = modelHeight - 1 ;
@@ -2110,6 +2118,15 @@ void WTableView::setOverflow(Overflow overflow,
21102118 contentsContainer_ -> setOverflow (overflow , orientation );
21112119}
21122120
2121+ void WTableView ::setPreloadMarginRows (int rows )
2122+ {
2123+ preloadMarginRows_ = rows ;
2124+
2125+ computeRenderedArea ();
2126+
2127+ scheduleRerender (RenderState ::NeedAdjustViewPort );
2128+ }
2129+
21132130void WTableView ::setRowHeaderCount (int count )
21142131{
21152132 WAbstractItemView ::setRowHeaderCount (count );
0 commit comments