Project

General

Profile

Bug #797 ยป hello.C

example that reproduces the problem - Pieter Libin, 04/20/2011 03:43 PM

 
#include <Wt/WApplication>
#include <Wt/WHBoxLayout>
#include <Wt/WTable>
#include <Wt/WText>
#include <Wt/WLength>
#include <Wt/Chart/WPieChart>
#include <Wt/WStandardItemModel>
#include <Wt/WWidgetItem>

using namespace Wt;

class HelloApplication : public WApplication
{
public:
HelloApplication(const WEnvironment& env);
WStandardItemModel* createModel();
};


WStandardItemModel* HelloApplication::createModel()
{
WStandardItemModel *model = new WStandardItemModel(this);
//headers
model->insertColumns(model->columnCount(), 2);
model->setHeaderData(0, WString("Item"));
model->setHeaderData(1, WString("Sales"));

//data
model->insertRows(model->rowCount(), 6);
int row = 0;
model->setData(row, 0, WString("Blueberry"));
model->setData(row, 1, 120);
// model->setData(row, 1, WString("Blueberry"), ToolTipRole);
row++;
model->setData(row, 0, WString("Cherry"));
model->setData(row, 1, 30);
row++;
model->setData(row, 0, WString("Apple"));
model->setData(row, 1, 260);

return model;
}

HelloApplication::HelloApplication(const WEnvironment& env)
: WApplication(env)
{
WTable* table = new WTable();
for (int r = 0; r < 10; r++)
for (int c = 0; c < 4; c++) {
std::string cell = "cell-"
+ boost::lexical_cast<std::string>(r)
+ boost::lexical_cast<std::string>(c);
table->elementAt(r, c)->addWidget(new WText(cell));
}
table->resize(WLength(200), WLength::Auto);

Chart::WPieChart* plot = new Chart::WPieChart();
plot->setModel(createModel());
plot->setLabelsColumn(0);
plot->setDataColumn(1);

WHBoxLayout* plotLayout = new WHBoxLayout();
plotLayout->addWidget(plot, 1);
plotLayout->addWidget(table);

plotLayout
->setResizable(plotLayout->indexOf(plotLayout->findWidgetItem(plot)));
root()->setLayout(plotLayout);
}

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

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

    (1-1/1)