Older/WebApplication/VisitorRecordsPage.cpp
luocai 5f3bf1067d
All checks were successful
Deploy / Build (push) Successful in 6m4s
add model.
2024-11-28 19:34:24 +08:00

62 lines
2.2 KiB
C++

#include "VisitorRecordsPage.h"
#include "BoostLog.h"
#include "Database/Session.h"
#include <Wt/Dbo/QueryModel.h>
#include <Wt/WItemDelegate.h>
#include <Wt/WLabel.h>
#include <Wt/WTableView.h>
#include "VisitorRecordTableModel.h"
class CheckBoxDelegate : public Wt::WAbstractItemDelegate {
public:
CheckBoxDelegate() : Wt::WAbstractItemDelegate() {
}
std::unique_ptr<Wt::WWidget> update(Wt::WWidget *widget, const Wt::WModelIndex &index,
Wt::WFlags<Wt::ViewItemRenderFlag> flags) final {
auto checkBox = dynamic_cast<Wt::WCheckBox *>(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<Wt::WWidget>(checkBox);
}
};
VisitorRecordsPage::VisitorRecordsPage(Session &session) {
addNew<Wt::WLabel>("访客数据统计");
auto view = addNew<Wt::WTableView>();
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<CheckBoxDelegate>());
// view->setHeaderItemDelegate( std::make_shared<CheckBoxDelegate>());
// auto model = std::make_shared<Wt::Dbo::QueryModel<Wt::Dbo::ptr<VisitorRecord>>>();
// model->setQuery(session.find<VisitorRecord>());
// 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<VisitorRecordTableModel>();
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);
}