Project

General

Profile

Bug #1158 ยป hello.C

Pieter Libin, 02/14/2012 03:59 PM

 
/*
* Copyright (C) 2008 Emweb bvba, Heverlee, Belgium.
*
* See the LICENSE file for terms of use.
*/

#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WStandardItem>
#include <Wt/WStandardItemModel>
#include <Wt/WTreeView>
#include <Wt/WPushButton>
#include <Wt/WSortFilterProxyModel>

using namespace Wt;

class HelloApplication : public WApplication
{
public:
HelloApplication(const WEnvironment& env);

private:
Wt::WStandardItemModel *model;
void removeCell();
};

HelloApplication::HelloApplication(const WEnvironment& env)
: WApplication(env)
{
int topLevelRows = 5;
int secondLevelRows = 7;
model = new Wt::WStandardItemModel();
Wt::WStandardItem *r = model->invisibleRootItem();
for (int row = 0; row < topLevelRows; ++row) {
Wt::WStandardItem *topLevel = new Wt::WStandardItem();
topLevel->setText("Item " + boost::lexical_cast<std::string>(row));
for (int row2 = 0; row2 < secondLevelRows; ++row2) {
Wt::WStandardItem *item = new Wt::WStandardItem();
item->setText("Item " + boost::lexical_cast<std::string>(row)
+ ": " + boost::lexical_cast<std::string>(row2));
topLevel->appendRow(item);
}
r->appendRow(topLevel);
}

WPushButton *b = new WPushButton("remove", root());
b->clicked().connect(boost::bind(&HelloApplication::removeCell, this));

WTreeView *tv = new WTreeView(root());
Wt::WSortFilterProxyModel *m_fileProxyModel
= new Wt::WSortFilterProxyModel(this);
m_fileProxyModel->setSourceModel(model);
tv->setModel(m_fileProxyModel);

tv->resize(300, Wt::WLength::Auto);
tv->setSortingEnabled(false);
tv->setModel(model);
}

void HelloApplication::removeCell()
{
model->takeItem(0, 0);
model->item(1,0)->takeChild(0,0);
}

WApplication *createApplication(const WEnvironment& env)
{
return new HelloApplication(env);
}

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

    (1-1/1)