Project

General

Profile

Bug #913 ยป test192.cc

Koen Deforche, 08/09/2011 02:58 PM

 
#include <Wt/WApplication>
#include <Wt/WText>
#include <Wt/WHBoxLayout>
#include <Wt/WVBoxLayout>
#include <Wt/WContainerWidget>
#include <Wt/WStandardItemModel>
#include <Wt/WStandardItem>
#include <Wt/WTreeView>
#include <Wt/WLineEdit>
#include <Wt/WLabel>
#include <Wt/WTableView>
#include <Wt/WPushButton>
#include <Wt/WLength>

#include <boost/lexical_cast.hpp>

#include <cstdlib>
#include <string>

using namespace Wt;

struct WebApp: public WApplication {
WebApp( const WEnvironment& env );

void setModel(int, int);
void doit();

WContainerWidget* head;
WContainerWidget* menu;
WContainerWidget* main;
WContainerWidget* tail;
WTableView* view;
WStandardItemModel* data;
WLineEdit *input;
};

void WebApp::setModel(int nr, int nc)
{
data = new WStandardItemModel( nr,nc ); // r,c
for( int r=0; r<nr; r++ ) {
for( int c=0; c<nc; c++ ) {
WStandardItem* item = new WStandardItem();
item->setText( "hello!" );
data->setItem( r,c,item );
}
}
view->setModel( data );
}

WebApp::WebApp( const WEnvironment& env ):
WApplication( env )
{
useStyleSheet( "notorand.css" );

head = new WContainerWidget();
head->setId( "head" );
head->addWidget( new WText( "This is the title" ) );

menu = new WContainerWidget();
menu->setId( "menu" );

main = new WContainerWidget();
main->setId( "main" );
main->setStyleClass( "lean" );
WVBoxLayout* vb1 = new WVBoxLayout();
main->setLayout( vb1 );
view = new WTableView();
view->setAlternatingRowColors( true );
view->setHeaderHeight( 0 );
view->setSelectionMode(SingleSelection);

setModel(30, 6);

vb1->addWidget( view );

tail = new WContainerWidget();
tail->setId( "tail" );

WPushButton *reset = new WPushButton("Reset");
reset->clicked().connect(this, &WebApp::doit);
tail->addWidget( reset );

vb1 = new WVBoxLayout();
vb1->addWidget( head,2 );
vb1->addWidget( menu,8 );
WVBoxLayout* vb2 = new WVBoxLayout();
vb2->addWidget( main,8 );
vb2->addWidget( tail,2 );

WHBoxLayout* hbl = new WHBoxLayout();
hbl->addLayout( vb1,2 );
hbl->addLayout( vb2,8 );
root()->setLayout( hbl );

}

void WebApp::doit()
{
int nr = 200;
setModel(nr, 6);
view->select(data->index(nr - 1, 0));
view->scrollTo(data->index(nr - 1, 0));
}

WApplication* ApplicationFactory( const WEnvironment& env ) {
WebApp* wa = new WebApp( env );
return wa;
}

int main( int argc, char* argv[] ) {
return WRun( argc,argv,&ApplicationFactory );
}

//EOF
    (1-1/1)