|
#include <iostream>
|
|
#include <Wt/WApplication.h>
|
|
#include <Wt/WTableView.h>
|
|
#include <Wt/WPushButton.h>
|
|
#include <Wt/WAbstractTableModel.h>
|
|
#include <Wt/WCheckBox.h>
|
|
#include <Wt/WContainerWidget.h>
|
|
|
|
const int columns = 5;
|
|
int rows = 0;
|
|
|
|
class VirtualModel : public Wt::WAbstractTableModel
|
|
{
|
|
public:
|
|
VirtualModel(int rows, int columns)
|
|
: WAbstractTableModel(),
|
|
rows_(rows),
|
|
columns_(columns)
|
|
{ }
|
|
|
|
virtual int rowCount(const Wt::WModelIndex& parent = Wt::WModelIndex()) const
|
|
{
|
|
if (!parent.isValid())
|
|
return rows_;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
virtual int columnCount(const Wt::WModelIndex& parent = Wt::WModelIndex()) const
|
|
{
|
|
if (!parent.isValid())
|
|
return columns_;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
virtual Wt::cpp17::any data(const Wt::WModelIndex& index, Wt::ItemDataRole role = Wt::ItemDataRole::Display) const
|
|
{
|
|
if (role == Wt::ItemDataRole::Display) {
|
|
if (index.column() == 0)
|
|
return Wt::WString("Row {1}").arg(index.row());
|
|
else
|
|
return Wt::WString("Item row {1}, col {2}")
|
|
.arg(index.row()).arg(index.column());
|
|
}
|
|
else {
|
|
return Wt::cpp17::any();
|
|
}
|
|
}
|
|
|
|
virtual Wt::cpp17::any headerData(int section,
|
|
Wt::Orientation orientation = Wt::Orientation::Horizontal,
|
|
Wt::ItemDataRole role = Wt::ItemDataRole::Display) const
|
|
{
|
|
if (orientation == Wt::Orientation::Horizontal) {
|
|
if (role == Wt::ItemDataRole::Display) {
|
|
return Wt::WString("Column {1}").arg(section);
|
|
}
|
|
else {
|
|
return Wt::cpp17::any();
|
|
}
|
|
}
|
|
else
|
|
return Wt::cpp17::any();
|
|
}
|
|
|
|
private:
|
|
int rows_, columns_;
|
|
};
|
|
|
|
class HelloApplication : public Wt::WApplication
|
|
{
|
|
public:
|
|
HelloApplication(const Wt::WEnvironment& env);
|
|
};
|
|
|
|
HelloApplication::HelloApplication(const Wt::WEnvironment& env)
|
|
: Wt::WApplication(env)
|
|
{
|
|
auto fillDataBtn = root()->addWidget(std::make_unique<Wt::WPushButton>("Fill with data"));
|
|
|
|
auto tableView = root()->addWidget(std::make_unique<Wt::WTableView>());
|
|
tableView->setRowHeaderCount(1);
|
|
tableView->setMaximumSize(500, 800);
|
|
tableView->setSortingEnabled(false);
|
|
tableView->setAlternatingRowColors(true);
|
|
|
|
// This would help
|
|
//tableView->setModel(std::make_shared<VirtualModel>(0, 5));
|
|
|
|
fillDataBtn->clicked().connect([tableView]() {
|
|
tableView->setModel(std::make_shared<VirtualModel>(50, 5));
|
|
});
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
return Wt::WRun(argc, argv, [](const Wt::WEnvironment& env) {
|
|
return std::make_unique<HelloApplication>(env);
|
|
});
|
|
}
|