2 #ifndef __WTX_DBO_LOOKUPITEMDELEGATE_H___ 3 #define __WTX_DBO_LOOKUPITEMDELEGATE_H___ 5 #include <Wt/WItemDelegate.h> 7 #include <Wt/Dbo/Transaction.h> 8 #include <Wt/WString.h> 9 #include <Wt/WModelIndex.h> 10 #include <Wt/WAbstractItemModel.h> 25 :
public Wt::WItemDelegate
35 Options m_options = NoOptions;
43 virtual std::unique_ptr<Wt::WWidget> update( Wt::WWidget * widget,
const Wt::WModelIndex & index, Wt::WFlags< Wt::ViewItemRenderFlag > flags )
45 auto w = Wt::WItemDelegate::update( widget, index, flags );
47 Wt::WText * text =
static_cast<Wt::WText *
>(w.get());
51 int id = Wt::asNumber( index.model()-> data( index.row(), index.column() ) );
55 Wt::Dbo::Transaction t(*session());
58 Wt::WString(
"SELECT COUNT(1) FROM \"{1}\" WHERE id = {2}")
59 .arg( std::string(C::TableDef().tableName()) )
66 template query<int>( filter );
70 auto item = session()->
template load<C>(id);
73 Wt::WString(
"{1}").arg( item-> keyField().value() );
75 if( m_options != NoCfy )
76 if( item-> cfyField().value() !=
"" )
78 Wt::WString(
"~{1}").arg( item-> cfyField().value() );
80 text-> setText( textValue );
84 text-> setText( Wt::WString(
"not found: {1}").arg(
id) );
90 text-> setText(
"~ ~ ~" );
117 #endif // #ifndef __WTX_DBO_LOOKUPITEMDELEGATE_H___