2 #include <Wt/WContainerWidget.h> 3 #include <Wt/WAbstractItemModel.h> 4 #include <Wt/Dbo/Transaction.h> 6 #include <Wtx/Dbo/Session.h> 9 #include "ItemDelegate.h" 16 std::unique_ptr<Wt::WWidget> Wtx::Sys::Lookup::ItemDelegate::update( Wt::WWidget * widget,
const Wt::WModelIndex & index, Wt::WFlags< Wt::ViewItemRenderFlag > flags )
18 auto w = Wt::WItemDelegate::update( widget, index, flags );
20 auto _getValue = [=]()
22 int id = Wt::asNumber( index.model()-> data( index.row(), index.column() ) );
26 Wt::Dbo::Transaction t(*
session());
29 Wt::WString(
"SELECT COUNT(1) FROM \"{1}\" WHERE id = {2}")
30 .arg( Wtx::Sys::Lookup::Item::TableDef().tableName() )
37 template query<int>( filter );
41 Wt::Dbo::Transaction t(*
session());
42 auto item =
session()->
template load<Wtx::Sys::Lookup::Item>(id);
43 return item-> keyField().value();
47 return Wt::WString(
"not found: {1}").arg(
id).toUTF8();
53 return std::string(
"~ ~ ~");
58 auto text =
dynamic_cast<Wt::WText *
>(w.get());
61 text-> setText( _getValue() );
65 auto checkBox =
dynamic_cast<Wt::WCheckBox *
>(w.get());
68 checkBox-> setText( _getValue() );
79 auto containerWidget =
dynamic_cast<Wt::WContainerWidget *
>(w.get());
82 auto t =
dynamic_cast<Wt::WText*
>( containerWidget-> find(
"t") );
85 t-> setText( _getValue() );
88 auto cb =
dynamic_cast<Wt::WCheckBox*
>( containerWidget-> find(
"c") );
92 cb-> setCheckState( checkState( index ) );
105 return Wt::CheckState::Unchecked;
113 Wt::WItemDelegate * Wtx::Sys::Lookup::ItemDelegate::create(
Wtx::Dbo::Session * s )
Wtx::Dbo::Session * session()
Current Session.
virtual Wt::CheckState checkState(const Wt::WModelIndex &index)