Project

General

Profile

Bug #2604 ยป hidden.cc

Koen Deforche, 02/11/2014 12:14 PM

 
1
#include <Wt/WApplication>
2
#include <Wt/WStandardItemModel>
3
#include <Wt/WStandardItem>
4
#include <Wt/WContainerWidget>
5
#include <Wt/WPushButton>
6
#include <Wt/WTableView>
7

    
8
using namespace Wt;
9

    
10
int cols = 5;
11
int rows = 5;
12

    
13
class TestApp : public WApplication
14
{
15
public:
16
  void createRow(std::vector<WStandardItem *>& row, int size,
17
		 const std::string& s) {
18

    
19
    row.clear();
20

    
21
    for (int i = 0; i < size; ++i) {
22
      WStandardItem *t
23
	= new WStandardItem(s + " c" + boost::lexical_cast<std::string>(i));
24

    
25
      row.push_back(t);
26
    }
27
  }
28

    
29
  WStandardItemModel *createModel() {
30
    model_ = new WStandardItemModel(0, cols, this);
31

    
32
    for (int i = 0; i < cols; ++i)
33
      model_->setHeaderData(i, Horizontal,
34
			    "col " + boost::lexical_cast<std::string>(i));
35

    
36
    std::vector<WStandardItem *> row;
37

    
38
    for (unsigned i = 0; i < rows; ++i) {
39
      createRow(row, cols, "Item "+ boost::lexical_cast<std::string>(i));
40
      model_->appendRow(row);
41
    }
42

    
43
    return model_;
44
  }
45

    
46
  TestApp(const WEnvironment& env) : WApplication(env)
47
  {
48
    WTableView *tv = new WTableView(root());
49
    tv->setMaximumSize(WLength::Auto, 500);
50
    tv->setModel(createModel());
51

    
52
    WPushButton *add = new WPushButton("add", root());
53
    add->clicked().connect(this, &TestApp::add);
54
    tv->hide();
55

    
56
    tv_ = tv;
57
  }
58

    
59
  void add() {
60
    tv_->show();
61

    
62
    std::vector<WStandardItem *> row;
63

    
64
    for (unsigned i = 0; i < 5; ++i) {
65
      createRow(row, cols, "Item "+ boost::lexical_cast<std::string>(i));
66
      model_->appendRow(row);
67
    }
68
  }
69

    
70
private:
71
  WStandardItemModel *model_;
72
  WTableView *tv_;
73
};
74

    
75
WApplication *createApplication(const WEnvironment& env)
76
{
77
  TestApp *app = new TestApp(env);
78

    
79
  return app;
80
}
81

    
82
int main(int argc, char *argv[])
83
{
84
  return WRun(argc, argv, &createApplication);
85
}
    (1-1/1)