Project

General

Profile

Bug #3719 ยป main.cpp

Anonymous, 01/08/2015 11:22 AM

 
1
#include <Wt/WServer>
2
#include <Wt/WApplication>
3
#include <Wt/WHBoxLayout>
4
#include <Wt/WVBoxLayout>
5
#include <Wt/WContainerWidget>
6
#include <Wt/WTableView>
7
#include <Wt/WAbstractTableModel>
8
#include <Wt/WPushButton>
9
#include <Wt/WDialog>
10

    
11
using namespace std;
12
using namespace Wt;
13

    
14
class MyTableModel : public WAbstractTableModel
15
{
16
public:
17
    MyTableModel(WTableView *parent) : WAbstractTableModel(parent), rcnt(0), ccnt(0)
18
    {
19
        int col;
20
        for(int row=0; row<100; ++row)
21
        {
22
            for(col=0; col<5; ++col)
23
            {
24
                map<int,boost::any> valmap;
25
                valmap[DisplayRole] = to_string(row) + "." + to_string(col);
26
                WModelIndex ix = index(row,col);
27
                daten[ix] = valmap;
28
            }
29
        }
30
        rcnt = 100;
31
        ccnt = 5;
32
    }
33
    int                 rowCount(const WModelIndex &) const { return rcnt; }
34
    int                 columnCount(const WModelIndex &) const { return ccnt; }
35
    boost::any          data(const WModelIndex& index, int role = DisplayRole) const
36
    {
37
        boost::any retval;
38
        try
39
        {
40
            std::map<int,boost::any> valmap = daten.at(index);
41
            retval = valmap[role];
42
        }
43
        catch(...)
44
        {
45
            retval = boost::any();
46
        }
47
        return retval;
48
    }
49
    map<WModelIndex, map<int,boost::any> >              daten;
50
    map<pair<pair<Wt::Orientation,int>,int>,boost::any> headers;
51
    int                 rcnt;
52
    int                 ccnt;
53
};
54

    
55
WApplication *createApplication(const Wt::WEnvironment& env)
56
{
57
    WApplication *app = new WApplication(env);
58

    
59
    WVBoxLayout *vbl = new WVBoxLayout(app->root());
60
    WHBoxLayout *hbl = new WHBoxLayout;
61
    vbl->addLayout(hbl);
62

    
63
    WTableView *tv = new WTableView;
64
    MyTableModel *model = new MyTableModel(tv);
65
    tv->setModel(model);
66

    
67
    hbl->addStretch(1);
68
    hbl->addWidget(tv);
69
    hbl->addStretch(1);
70

    
71
    hbl = new WHBoxLayout;
72
    vbl->addLayout(hbl);
73
    WPushButton *b = new WPushButton("do something");
74
    b->clicked().connect(bind([=] ()
75
    {
76
        WDialog *dia = new WDialog;
77
        WPushButton *b = new WPushButton("Disappear!", dia->contents());
78
        b->clicked().connect(bind([=] ()
79
        {
80
            delete dia;
81
        }));
82
        dia->show();
83
    }));
84
    b->setMinimumSize(WLength::Auto, WLength(2,WLength::FontEm));
85
    hbl->addStretch(1);
86
    hbl->addWidget(b);
87
    hbl->addStretch(1);
88

    
89

    
90
    return app;
91
}
92

    
93
int main(int argc, char **argv)
94
{
95
    return WRun(argc, argv, createApplication);
96
}
97

    
    (1-1/1)