1
|
#include <Wt/WApplication.h>
|
2
|
#include <Wt/WEnvironment.h>
|
3
|
#include <Wt/WServer.h>
|
4
|
#include <Wt/WStandardItem.h>
|
5
|
#include <Wt/WStandardItemModel.h>
|
6
|
#include <Wt/WTimer.h>
|
7
|
#include <Wt/WTableView.h>
|
8
|
#include <Wt/WGridLayout.h>
|
9
|
|
10
|
|
11
|
using namespace Wt;
|
12
|
|
13
|
constexpr int GRID_ROWS = 4;
|
14
|
constexpr int GRID_COLS = 4;
|
15
|
constexpr int TIMER_INTERVAL_MS = 200;
|
16
|
|
17
|
class TableView : public WTableView {
|
18
|
public:
|
19
|
TableView(int& instance_counter)
|
20
|
{
|
21
|
instance_ = ++instance_counter;
|
22
|
|
23
|
setLayoutSizeAware(true);
|
24
|
scrolled().connect([=] (WScrollEvent se) {
|
25
|
#if 0
|
26
|
log("info") << "TableView[" << instance_ << "] scrolled: scrollX: " << se.scrollX() << ", scrollY: " << se.scrollY()
|
27
|
<< ", viewportWidth: " << se.viewportWidth() << ", viewportHeight: " << se.viewportHeight();
|
28
|
#endif
|
29
|
});
|
30
|
}
|
31
|
|
32
|
void layoutSizeChanged(int width, int height) override
|
33
|
{
|
34
|
#if 0
|
35
|
log("info") << "TableView[" << instance_ << "] layoutSizeChanged: (w = " << width << ", h = " << height << ")";
|
36
|
#endif
|
37
|
WTableView::layoutSizeChanged(width, height);
|
38
|
}
|
39
|
|
40
|
private:
|
41
|
int instance_ = 0;
|
42
|
};
|
43
|
|
44
|
class TestApp : public WApplication {
|
45
|
public:
|
46
|
TestApp(const WEnvironment& env);
|
47
|
|
48
|
private:
|
49
|
std::vector<TableView *> tableViews_;
|
50
|
int tableViewInstanceCounter_ = 0;
|
51
|
};
|
52
|
|
53
|
TestApp::TestApp(const WEnvironment& env) : WApplication(env)
|
54
|
{
|
55
|
setTitle("WTableView scrollTo displays 'Loading'");
|
56
|
|
57
|
auto topLayout = std::make_unique<WGridLayout>();
|
58
|
|
59
|
auto model = std::make_shared<WStandardItemModel>(1000, 4);
|
60
|
for (int r = 0; r < model->rowCount(); ++r) {
|
61
|
for (int c = 0; c < model->columnCount(); ++c) {
|
62
|
model->setData(model->index(r, c), r + c);
|
63
|
}
|
64
|
}
|
65
|
|
66
|
for (int r = 0; r < GRID_ROWS; ++r) {
|
67
|
for (int c = 0; c < GRID_COLS; ++c) {
|
68
|
auto tableView = std::make_unique<TableView>(tableViewInstanceCounter_);
|
69
|
auto tv = tableView.get();
|
70
|
tv->setSortingEnabled(false);
|
71
|
tableViews_.push_back(tv);
|
72
|
tableView->setModel(model);
|
73
|
topLayout->addWidget(std::move(tableView), r, c);
|
74
|
}
|
75
|
}
|
76
|
|
77
|
root()->setLayout(std::move(topLayout));
|
78
|
|
79
|
int timer_ms = 1000;
|
80
|
for (auto tv: tableViews_) {
|
81
|
WTimer::singleShot(std::chrono::milliseconds(timer_ms), std::bind([=] () {
|
82
|
tv->scrollTo(model->index(400, 0));
|
83
|
}));
|
84
|
timer_ms += TIMER_INTERVAL_MS;
|
85
|
}
|
86
|
}
|
87
|
|
88
|
int main(int argc, char **argv)
|
89
|
{
|
90
|
return WRun(argc, argv, [](const WEnvironment& env) {return std::make_unique<TestApp>(env);});
|
91
|
}
|