From 8cc311d4a8b3efa4530823047674b2dd935f1f69 Mon Sep 17 00:00:00 2001 From: dodes Date: Wed, 11 Nov 2015 13:16:14 +0100 Subject: [PATCH] WTableView: Support for model data caching --- src/Wt/WAbstractItemModel | 8 ++++++++ src/Wt/WAbstractItemModel.C | 3 +++ src/Wt/WTableView.C | 15 +++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/Wt/WAbstractItemModel b/src/Wt/WAbstractItemModel index 4816a6f..db1e0e3 100644 --- a/src/Wt/WAbstractItemModel +++ b/src/Wt/WAbstractItemModel @@ -327,6 +327,14 @@ public: | MatchWrap)) const; + /*! \brief Prepare the data beforehand. + * + * This is call before the retrieving the data. In some situtations it + * it would be better to load the bulk of the data, insted of one by one. + * This is mainly used by virtual table views. + */ + virtual void prepareData(int rowFrom, int rowTo); + /*! \brief Returns the data item at the given column and row. * * This is a convenience method, and is equivalent to: diff --git a/src/Wt/WAbstractItemModel.C b/src/Wt/WAbstractItemModel.C index ee3ec07..0b2afa6 100644 --- a/src/Wt/WAbstractItemModel.C +++ b/src/Wt/WAbstractItemModel.C @@ -91,6 +91,9 @@ WAbstractItemModel::itemData(const WModelIndex& index) const return result; } +void WAbstractItemModel::prepareData(int rowFrom, int rowTo) +{ } + boost::any WAbstractItemModel::data(int row, int column, int role, const WModelIndex& parent) const { diff --git a/src/Wt/WTableView.C b/src/Wt/WTableView.C index 78ecb37..776aeb9 100644 --- a/src/Wt/WTableView.C +++ b/src/Wt/WTableView.C @@ -581,6 +581,17 @@ void WTableView::renderTable(const int fr, const int lr, for (int i = 0; i < -bottomRowsToAdd; ++i) removeSection(Bottom); + //If there are some columns defined + if(rowHeaderCount() > 0 || (firstColumn() < lastColumn())) + { + // Only if got top rows + if(topRowsToAdd > 0) + model()->prepareData(firstRow() - topRowsToAdd, firstRow()); + // Only if got bottom rows + else if(bottomRowsToAdd > 0) + model()->prepareData(lastRow() + 1, lastRow() + bottomRowsToAdd); + } + // Add rows for (int i = 0; i < topRowsToAdd; i++) { int row = firstRow() - 1; @@ -606,6 +617,10 @@ void WTableView::renderTable(const int fr, const int lr, addSection(Bottom, items); } + // Only if there are some columns to add and we've got some rows + if((leftColsToAdd > 0 || rightColsToAdd > 0) && firstRow() < lastRow()) + model()->prepareData(firstRow(), lastRow()); + // Add columns for (int i = 0; i < leftColsToAdd; ++i) { int col = firstColumn() - 1; -- 1.9.5.msysgit.0