Project

General

Profile

Bug #3719 ยป main.cpp

Anonymous, 01/08/2015 11:22 AM

 
#include <Wt/WServer>
#include <Wt/WApplication>
#include <Wt/WHBoxLayout>
#include <Wt/WVBoxLayout>
#include <Wt/WContainerWidget>
#include <Wt/WTableView>
#include <Wt/WAbstractTableModel>
#include <Wt/WPushButton>
#include <Wt/WDialog>

using namespace std;
using namespace Wt;

class MyTableModel : public WAbstractTableModel
{
public:
MyTableModel(WTableView *parent) : WAbstractTableModel(parent), rcnt(0), ccnt(0)
{
int col;
for(int row=0; row<100; ++row)
{
for(col=0; col<5; ++col)
{
map<int,boost::any> valmap;
valmap[DisplayRole] = to_string(row) + "." + to_string(col);
WModelIndex ix = index(row,col);
daten[ix] = valmap;
}
}
rcnt = 100;
ccnt = 5;
}
int rowCount(const WModelIndex &) const { return rcnt; }
int columnCount(const WModelIndex &) const { return ccnt; }
boost::any data(const WModelIndex& index, int role = DisplayRole) const
{
boost::any retval;
try
{
std::map<int,boost::any> valmap = daten.at(index);
retval = valmap[role];
}
catch(...)
{
retval = boost::any();
}
return retval;
}
map<WModelIndex, map<int,boost::any> > daten;
map<pair<pair<Wt::Orientation,int>,int>,boost::any> headers;
int rcnt;
int ccnt;
};

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

WVBoxLayout *vbl = new WVBoxLayout(app->root());
WHBoxLayout *hbl = new WHBoxLayout;
vbl->addLayout(hbl);

WTableView *tv = new WTableView;
MyTableModel *model = new MyTableModel(tv);
tv->setModel(model);

hbl->addStretch(1);
hbl->addWidget(tv);
hbl->addStretch(1);

hbl = new WHBoxLayout;
vbl->addLayout(hbl);
WPushButton *b = new WPushButton("do something");
b->clicked().connect(bind([=] ()
{
WDialog *dia = new WDialog;
WPushButton *b = new WPushButton("Disappear!", dia->contents());
b->clicked().connect(bind([=] ()
{
delete dia;
}));
dia->show();
}));
b->setMinimumSize(WLength::Auto, WLength(2,WLength::FontEm));
hbl->addStretch(1);
hbl->addWidget(b);
hbl->addStretch(1);


return app;
}

int main(int argc, char **argv)
{
return WRun(argc, argv, createApplication);
}

    (1-1/1)