#include "VisitorRecordsPage.h" #include "BoostLog.h" #include "Database/Session.h" #include "model/VisitorRecordTableModel.h" #include #include #include #include #include #include #include VisitorRecordsPage::VisitorRecordsPage(Session &session) : m_model{std::make_shared(session)} { addNew("访客数据统计"); addNew(); auto button = addNew("删除"); button->clicked().connect(this, &VisitorRecordsPage::onDeleteButtonClicked); auto view = addNew(); view->setColumnWidth(0, Wt::WLength::Auto); view->setColumnWidth(1, Wt::WLength::Auto); view->setHeaderHeight(30); // 设置表头的高度 view->setColumnResizeEnabled(true); view->setAlternatingRowColors(true); // 限制于 stripe-40px.gif 类似的文件,wt 有提供脚本生成 view->setRowHeight(50); view->setSelectionMode(Wt::SelectionMode::None); view->setColumnAlignment(0, Wt::AlignmentFlag::Center); view->setColumnAlignment(2, Wt::AlignmentFlag::Center); view->setColumnAlignment(4, Wt::AlignmentFlag::Center); view->setHeaderAlignment(0, Wt::AlignmentFlag::Center); view->setHeaderAlignment(1, Wt::AlignmentFlag::Center); view->setHeaderAlignment(2, Wt::AlignmentFlag::Center); view->setHeaderAlignment(3, Wt::AlignmentFlag::Center); view->setHeaderAlignment(4, Wt::AlignmentFlag::Center); view->setSortingEnabled(0, false); view->setSortingEnabled(1, false); view->setSortingEnabled(3, false); view->setSortingEnabled(4, false); // view->setEditTriggers(Wt::EditTrigger::None); // view->setItemDelegateForColumn(0, std::make_shared()); // view->setHeaderItemDelegate( std::make_shared()); view->setModel(m_model); view->setColumnWidth(0, 60); view->setColumnWidth(1, 180); view->setColumnWidth(2, 180); view->setColumnWidth(3, 480); } void VisitorRecordsPage::onDeleteButtonClicked() { auto selected = m_model->selectedIndexes(); if (selected.empty()) { Wt::WMessageBox::show("删除记录", "请先选择要删除的记录", Wt::StandardButton::Ok); } else { auto anwser = Wt::WMessageBox::show("删除记录", "确定删除选择的记录?", Wt::StandardButton::Ok | Wt::StandardButton::Cancel); if (anwser == Wt::StandardButton::Ok) { LOG(info) << "remove row: " << selected.size(); m_model->removeSelectedRows(selected); } } }