|
#include <Wt/WApplication>
|
|
#include <Wt/WTableView>
|
|
#include <Wt/WStandardItemModel>
|
|
#include <Wt/WStandardItem>
|
|
#include <Wt/WText>
|
|
#include <Wt/WVBoxLayout>
|
|
|
|
#include <cstdio> // I hate iostreams!
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
using namespace Wt;
|
|
using namespace std;
|
|
using namespace boost;
|
|
|
|
struct WebApp: public WApplication {
|
|
WTableView* table;
|
|
WStandardItemModel* model;
|
|
|
|
WebApp( const WEnvironment& env );
|
|
|
|
void itemChanged( WStandardItem* item );
|
|
void headChanged( Orientation o, int fp, int lp );
|
|
};
|
|
|
|
void WebApp::headChanged( Orientation o, int fp, int lp ) {
|
|
fprintf( stderr,"headChanged called for item at column (%d,%d)\n",fp,lp );
|
|
any s = model->headerData( fp,Horizontal,CheckStateRole );
|
|
CheckState cs = any_cast<CheckState>( s );
|
|
char c;
|
|
switch( cs ) {
|
|
case PartiallyChecked: c = 'P'; break;
|
|
case Checked: c = 'C'; break;
|
|
case Unchecked: c = 'U'; break;
|
|
default: c = '?'; // Just in case ...
|
|
}
|
|
fprintf( stderr,"Current status: %c\n",c );
|
|
}
|
|
|
|
void WebApp::itemChanged( WStandardItem* item ) {
|
|
fprintf( stderr,"itemChanged called for item at (%d,%d)\n",item->row(),item->column() );
|
|
}
|
|
|
|
WebApp::WebApp( const WEnvironment& env ): WApplication( env ) {
|
|
int cn = 3;
|
|
int rn = 3;
|
|
WVBoxLayout* vbl = new WVBoxLayout();
|
|
table = new WTableView();
|
|
model = new WStandardItemModel( rn,cn );
|
|
table->setModel( model );
|
|
table->setHeaderAlignment( 0,AlignCenter );
|
|
table->setColumnAlignment( 0,AlignCenter );
|
|
table->setColumnWidth( 0,WLength( "5ex" ) );
|
|
table->setSortingEnabled( 0,false );
|
|
|
|
WStandardItem* i;
|
|
for( int c=0; c<cn; c++ ) {
|
|
if( c > 0 )
|
|
model->setHeaderData( c,any( "Col. no. "+lexical_cast<string>(c) ) );
|
|
else {
|
|
model->setHeaderData( c,any( WString( "" ) ) );
|
|
model->setHeaderFlags( c,Horizontal,HeaderIsUserCheckable|HeaderIsTristate );
|
|
model->setHeaderData( c,Horizontal,any( Unchecked ),CheckStateRole );
|
|
}
|
|
for( int r=0; r<rn; r++ ) {
|
|
i = new WStandardItem();
|
|
if( c > 0 )
|
|
i->setText( "Item @ ("+lexical_cast<string>(r)+","+lexical_cast<string>(c)+")" );
|
|
else {
|
|
i->setText( "" );
|
|
i->setCheckable( true );
|
|
}
|
|
model->setItem( r,c,i );
|
|
}
|
|
}
|
|
model->itemChanged().connect( this,&WebApp::itemChanged );
|
|
model->headerDataChanged().connect( this,&WebApp::headChanged );
|
|
root()->setLayout( vbl );
|
|
vbl->addWidget( table );
|
|
}
|
|
|
|
WApplication* ApplicationFactory( const WEnvironment& env ) {
|
|
WebApp* wa = new WebApp( env );
|
|
return wa;
|
|
}
|
|
|
|
int main( int argc, char* argv[] ) {
|
|
locale::global(locale(""));
|
|
return WRun( argc,argv,&ApplicationFactory );
|
|
}
|
|
|
|
//EOF
|