Project

General

Profile

Bug #713 ยป Table.C

Pieter Libin, 02/16/2011 10:17 AM

 
#include <Wt/WText>
#include <Wt/WStandardItem>
#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WString>
#include <Wt/WTableView>
#include <Wt/WStandardItemModel>
#include <Wt/WHBoxLayout>
#include <Wt/WOverlayLoadingIndicator>

using namespace Wt;

class Table : public Wt::WContainerWidget
{
public:
Table();
};

Table::Table()
{
setContentAlignment(Wt::AlignCenter);

WStandardItemModel* pModel = new WStandardItemModel(this);

WTableView* pTable = new WTableView();
pTable->setSortingEnabled(true);
pTable->setColumnResizeEnabled(true);
pTable->setAlternatingRowColors(true);
pTable->setRowHeight(22);
pTable->setModel(pModel);
pTable->setEditTriggers(WAbstractItemView::NoEditTrigger);

addWidget(pTable);

pModel->insertColumns(0, 2);
pModel->setHeaderData(0, Wt::WString("Name"));
pModel->setHeaderData(1, Wt::WString("emaN"));

WString ws[] = { "W", "i", "t", "t", "y" };
WString wsURL = L"http://www.webtoolkit.eu/wt";

pModel->insertRows(0, 5);

for (size_t row = 0; row < 5; ++row)
{
pModel->setData(row, 0, ws[row], UserRole);
pModel->setData(row, 0, wsURL, UrlRole);

pModel->setData(row, 1, ws[4-row], UserRole);
pModel->setData(row, 1, wsURL, UrlRole);
}

pTable->setColumnWidth(0, WLength(5, Wt::WLength::FontEm));
pTable->setColumnWidth(1, WLength(5, Wt::WLength::FontEm));

pTable->resize(700, 600);
}

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

app->setCssTheme("polished");

WHBoxLayout *layout = new WHBoxLayout(app->root());
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(new Table());

app->setTitle("Table");
app->useStyleSheet("style/everywidget.css");
app->useStyleSheet("style/dragdrop.css");
app->useStyleSheet("style/combostyle.css");

return app;
}

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