2 #ifndef __WTX_QUERYMODEL_H___ 3 #define __WTX_QUERYMODEL_H___ 5 #include <Wt/Dbo/QueryModel.h> 7 #include <Wtx/TableViewDef.h> 14 :
public Wt::Dbo::QueryModel<C>
16 typedef Wt::Dbo::QueryModel<C> Base;
20 virtual int rowCount(
const Wt::WModelIndex & parent = Wt::WModelIndex() )
const 22 if( m_countTable !=
"" && session() )
24 if( m_cachedRowCount == -1 )
32 #ifndef DO_TRADITIONAL_COUNT 34 Wt::WString(
"SELECT COUNT(1) FROM \"{1}\" " )
50 Wt::WString(
"SELECT reltuples::BIGINT FROM pg_class WHERE relname = '{1}'" )
56 if( m_countWhere !=
"" )
58 query += m_countWhere;
61 Wt::Dbo::Transaction t(*session());
62 m_cachedRowCount = session()->
template query<int>(query);
66 return m_cachedRowCount;
70 return Wt::Dbo::QueryModel<C>::rowCount( parent );
74 Wt::Dbo::Session * session()
const 79 void setSession( Wt::Dbo::Session * value )
84 void setCountTable(
const std::string & table )
89 void setCountWhere(
const std::string & where )
92 m_cachedRowCount = -1;
100 virtual Wt::WFlags<Wt::ItemFlag> flags(
const Wt::WModelIndex & index )
const 104 auto result = Base::flags(index);
106 if( index.column() == 0 )
107 result |= Wt::ItemFlag::UserCheckable;
114 virtual Wt::cpp17::any data(
const Wt::WModelIndex& index, Wt::ItemDataRole role )
const 119 if( m_viewDef-> m_def.checkBoxSelect )
121 if( index.column() == 0 && role == Wt::ItemDataRole::Checked )
132 return Base::data( index, role );
135 void refreshModelData()
142 Wt::Dbo::Session * m_session =
nullptr;
143 std::string m_countTable;
144 std::string m_countWhere;
145 mutable int m_cachedRowCount = -1;
152 #endif // __WTX_QUERYMODEL_H___