|
#include <Wt/WApplication>
|
|
#include <Wt/WContainerWidget>
|
|
#include <Wt/WWidget>
|
|
#include <Wt/WPushButton>
|
|
#include <Wt/WMessageBox>
|
|
#include <Wt/WStandardItemModel>
|
|
#include <Wt/WTreeView>
|
|
#include <Wt/WBreak>
|
|
|
|
using namespace Wt;
|
|
|
|
class TestApplication : public Wt::WApplication
|
|
{
|
|
private:
|
|
WContainerWidget *rootContainer_;
|
|
|
|
public:
|
|
TestApplication(const WEnvironment& env);
|
|
|
|
void showFirstButton();
|
|
void showTreeView();
|
|
};
|
|
|
|
TestApplication::TestApplication(const WEnvironment& env):
|
|
WApplication(env),
|
|
rootContainer_(NULL)
|
|
{
|
|
rootContainer_ = new WContainerWidget(root());
|
|
showFirstButton();
|
|
}
|
|
|
|
void TestApplication::showFirstButton()
|
|
{
|
|
rootContainer_->clear();
|
|
|
|
WPushButton* firstButton = new WPushButton("show the treeview");
|
|
firstButton->resize(WLength(200, WLength::Pixel), WLength(35, WLength::Pixel));
|
|
firstButton->clicked().connect(this, &TestApplication::showTreeView);
|
|
|
|
rootContainer_->addWidget(firstButton);
|
|
}
|
|
|
|
void TestApplication::showTreeView()
|
|
{
|
|
rootContainer_->clear();
|
|
|
|
//button
|
|
WPushButton* secondButton = new WPushButton("close the table view");
|
|
secondButton->resize(WLength(200, WLength::Pixel), WLength(35, WLength::Pixel));
|
|
secondButton->clicked().connect(this, &TestApplication::showFirstButton);
|
|
|
|
//table view
|
|
WStandardItemModel* model = new WStandardItemModel();
|
|
model->insertColumns(0, 4);
|
|
|
|
model->setHeaderData(0, boost::any(std::string("column 0")));
|
|
model->setHeaderData(1, boost::any(std::string("column 1")));
|
|
model->setHeaderData(2, boost::any(std::string("column 2")));
|
|
model->setHeaderData(3, boost::any(std::string("column 3")));
|
|
|
|
model->insertRows(0, 4);
|
|
for (int i=0; i<4; i++)
|
|
for (int j=0; j<4; j++)
|
|
{
|
|
WString cellData("({1}, {2})");
|
|
model->setData(model->index(i, j), boost::any(cellData.arg(i).arg(j)));
|
|
}
|
|
|
|
WTreeView* treeView = new WTreeView();
|
|
treeView->setModel(model);
|
|
|
|
treeView->setColumnWidth(0, 100);
|
|
treeView->setColumnWidth(1, 110);
|
|
treeView->setColumnWidth(2, 120);
|
|
treeView->setColumnWidth(3, 130);
|
|
treeView->resize(WLength(500, WLength::Pixel), WLength(160, WLength::Pixel));
|
|
|
|
treeView->setRowHeaderCount(1); //!!!!
|
|
|
|
//breaks
|
|
WBreak* br1 = new WBreak();
|
|
WBreak* br2 = new WBreak();
|
|
|
|
//collect widgets
|
|
rootContainer_->addWidget(secondButton);
|
|
rootContainer_->addWidget(br1);
|
|
rootContainer_->addWidget(br2);
|
|
rootContainer_->addWidget(treeView);
|
|
}
|
|
|
|
WApplication *createApplication(const WEnvironment& env)
|
|
{
|
|
return new TestApplication(env);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
return WRun(argc, argv, &createApplication);
|
|
}
|