#include "VisitorRecordsPage.h" #include "BoostLog.h" #include "Database/Session.h" #include #include #include #include #include "VisitorRecordTableModel.h" class CheckBoxDelegate : public Wt::WAbstractItemDelegate { public: CheckBoxDelegate() : Wt::WAbstractItemDelegate() { } std::unique_ptr update(Wt::WWidget *widget, const Wt::WModelIndex &index, Wt::WFlags flags) final { auto checkBox = dynamic_cast(widget); if (!checkBox) { checkBox = new Wt::WCheckBox(); } LOG(info) << Wt::asString(index.data()); // checkBox->setChecked(index.data().toBool()); checkBox->setEnabled(true); return std::unique_ptr(checkBox); } }; VisitorRecordsPage::VisitorRecordsPage(Session &session) { addNew("访客数据统计"); auto view = addNew(); view->setColumnWidth(0, Wt::WLength::Auto); view->setColumnWidth(1, Wt::WLength::Auto); view->setHeaderHeight(30); // 设置表头的高度 view->setWidth(Wt::WLength("99%")); view->setColumnResizeEnabled(true); view->setAlternatingRowColors(true); view->setRowHeight(50); // view->setSelectable(true); view->setSelectionMode(Wt::SelectionMode::Extended); // view->setEditTriggers(Wt::EditTrigger::None); // view->setItemDelegateForColumn(0, std::make_shared()); // view->setHeaderItemDelegate( std::make_shared()); // auto model = std::make_shared>>(); // model->setQuery(session.find()); // model->addColumn("id", "ID",Wt::ItemFlag::UserCheckable); // model->addColumn("url", "URL"); // model->addColumn("time", "Time"); // model->addColumn("user_agent", "User Agent"); auto model = std::make_shared(); view->setModel(model); /* * Configure column widths and matching table width */ const int WIDTH = 240; for (int i = 0; i < view->model()->columnCount(); ++i) view->setColumnWidth(i, 120); }