add checkbox for view.
All checks were successful
Deploy / Build (push) Successful in 8m1s

This commit is contained in:
amass 2024-11-28 23:39:15 +08:00
parent 5f3bf1067d
commit 51bfddd40f
3 changed files with 47 additions and 8 deletions

View File

@ -9,10 +9,45 @@ int VisitorRecordTableModel::rowCount(const Wt::WModelIndex &parent) const {
return 50; return 50;
} }
Wt::cpp17::any VisitorRecordTableModel::data(const Wt::WModelIndex &index, Wt::ItemDataRole role) const { Wt::WFlags<Wt::ItemFlag> VisitorRecordTableModel::flags(const Wt::WModelIndex &index) const {
LOG(info) << "VisitorRecordTableModel: " << role.value(); if (index.column() == 0) {
if (role == Wt::ItemDataRole::Checked && index.column() == 0) { // Assuming first column for checkbox return Wt::ItemFlag::UserCheckable | Wt::ItemFlag::Selectable;
} else {
return Wt::ItemFlag::Selectable;
}
}
Wt::WFlags<Wt::HeaderFlag> VisitorRecordTableModel::headerFlags(int section, Wt::Orientation orientation) const {
if (section == 0 && orientation== Wt::Orientation::Horizontal) {
return Wt::HeaderFlag::UserCheckable|Wt::HeaderFlag::XHTMLText;
} else {
return Wt::HeaderFlag::XHTMLText;
}
}
Wt::cpp17::any VisitorRecordTableModel::headerData(int section, Wt::Orientation orientation, Wt::ItemDataRole role) const {
if ((role == Wt::ItemDataRole::Checked || role == Wt::ItemDataRole::Edit) &&
section == 0) { // Assuming first column for checkbox
return true; return true;
} else if ((role == Wt::ItemDataRole::Display || role == Wt::ItemDataRole::Edit) &&
section == 0) { // Assuming first column for checkbox
return Wt::cpp17::any{};
} else {
return Wt::cpp17::any{};
}
}
Wt::cpp17::any VisitorRecordTableModel::data(const Wt::WModelIndex &index, Wt::ItemDataRole role) const {
LOG(info) << "VisitorRecordTableModel: " << role.value();
if ((role == Wt::ItemDataRole::Checked || role == Wt::ItemDataRole::Edit) &&
index.column() == 0) { // Assuming first column for checkbox
return true;
} else if ((role == Wt::ItemDataRole::Checked || role == Wt::ItemDataRole::Edit) &&
index.column() == 1) { // Assuming first column for checkbox
return false;
} else { } else {
return Wt::cpp17::any{}; return Wt::cpp17::any{};
} }

View File

@ -8,5 +8,9 @@ public:
Wt::cpp17::any data(const Wt::WModelIndex &index, Wt::ItemDataRole role = Wt::ItemDataRole::Display) const final; Wt::cpp17::any data(const Wt::WModelIndex &index, Wt::ItemDataRole role = Wt::ItemDataRole::Display) const final;
int columnCount(const Wt::WModelIndex &parent = Wt::WModelIndex()) const final; int columnCount(const Wt::WModelIndex &parent = Wt::WModelIndex()) const final;
int rowCount(const Wt::WModelIndex &parent = Wt::WModelIndex()) const final; int rowCount(const Wt::WModelIndex &parent = Wt::WModelIndex()) const final;
Wt::WFlags<Wt::ItemFlag> flags(const Wt::WModelIndex &index) const final;
Wt::WFlags<Wt::HeaderFlag> headerFlags(int section, Wt::Orientation orientation = Wt::Orientation::Horizontal) const final;
Wt::cpp17::any headerData(int section, Wt::Orientation orientation = Wt::Orientation::Horizontal,
Wt::ItemDataRole role = Wt::ItemDataRole::Display) const final;
}; };
#endif // __VISITORRECORDTABLEMODEL_H__ #endif // __VISITORRECORDTABLEMODEL_H__

View File

@ -1,11 +1,11 @@
#include "VisitorRecordsPage.h" #include "VisitorRecordsPage.h"
#include "BoostLog.h" #include "BoostLog.h"
#include "Database/Session.h" #include "Database/Session.h"
#include "VisitorRecordTableModel.h"
#include <Wt/Dbo/QueryModel.h> #include <Wt/Dbo/QueryModel.h>
#include <Wt/WItemDelegate.h> #include <Wt/WItemDelegate.h>
#include <Wt/WLabel.h> #include <Wt/WLabel.h>
#include <Wt/WTableView.h> #include <Wt/WTableView.h>
#include "VisitorRecordTableModel.h"
class CheckBoxDelegate : public Wt::WAbstractItemDelegate { class CheckBoxDelegate : public Wt::WAbstractItemDelegate {
public: public:
@ -36,8 +36,10 @@ VisitorRecordsPage::VisitorRecordsPage(Session &session) {
view->setColumnResizeEnabled(true); view->setColumnResizeEnabled(true);
view->setAlternatingRowColors(true); view->setAlternatingRowColors(true);
view->setRowHeight(50); view->setRowHeight(50);
// view->setSelectable(true); view->setSelectionMode(Wt::SelectionMode::None);
view->setSelectionMode(Wt::SelectionMode::Extended); view->setColumnAlignment(0, Wt::AlignmentFlag::Center);
view->setHeaderAlignment(0,Wt::AlignmentFlag::Center);
view->setSortingEnabled(0,false);
// view->setEditTriggers(Wt::EditTrigger::None); // view->setEditTriggers(Wt::EditTrigger::None);
// view->setItemDelegateForColumn(0, std::make_shared<CheckBoxDelegate>()); // view->setItemDelegateForColumn(0, std::make_shared<CheckBoxDelegate>());
// view->setHeaderItemDelegate( std::make_shared<CheckBoxDelegate>()); // view->setHeaderItemDelegate( std::make_shared<CheckBoxDelegate>());
@ -51,8 +53,6 @@ VisitorRecordsPage::VisitorRecordsPage(Session &session) {
auto model = std::make_shared<VisitorRecordTableModel>(); auto model = std::make_shared<VisitorRecordTableModel>();
view->setModel(model); view->setModel(model);
/* /*
* Configure column widths and matching table width * Configure column widths and matching table width
*/ */