Project

General

Profile

RE: Wt internal error and application stops working ยป main.cpp

Valeriy Fedyunin, 09/30/2015 10:52 PM

 
#include <Wt/WApplication>
#include <Wt/WServer>
#include <Wt/WDialog>
#include <Wt/WMenu>
#include <Wt/WStackedWidget>
#include <Wt/WCheckBox>
#include <Wt/WContainerWidget>
#include <Wt/WHBoxLayout>
#include <Wt/WVBoxLayout>
#include <Wt/WScrollArea>
#include <Wt/WPushButton>
#include <string>
#include <vector>

using namespace Wt;

std::vector<std::string> GetValues();

class CTestDialog : public WDialog
{
public:
CTestDialog()
{
WStackedWidget* stack = new WStackedWidget();
WMenu* menu = new WMenu( stack, Vertical );

WContainerWidget* container = new WContainerWidget();
WHBoxLayout* rootLayout = new WHBoxLayout();
container->setLayout( rootLayout );

std::vector<std::string> values = GetValues();
int columnsNum = values.size() / 15;
size_t widgetsInColumn;
int MinColumnsNum = 2;

if( values.size() < 15 ) {
columnsNum = 1;
widgetsInColumn = values.size();
} else if( columnsNum < 5 ) {
columnsNum = MinColumnsNum;
widgetsInColumn = values.size() / columnsNum;
}

std::vector<Wt::WVBoxLayout*> columns;
std::vector<WCheckBox*> options;
for( int i = 0; i < columnsNum; ++i ) {
columns.push_back( new Wt::WVBoxLayout() );
}

for( auto attributeValue : values ) {
options.push_back( new Wt::WCheckBox( attributeValue ) );
}

size_t columnIndex = 0;
size_t currColumnSize = 0;
for( size_t i = 0; i < options.size(); ++i ) {
columns[columnIndex]->addWidget( options[i] );
currColumnSize++;
if( ( currColumnSize == widgetsInColumn && columnIndex >= values.size() % widgetsInColumn ) ||
currColumnSize == widgetsInColumn + 1 )
{
columnIndex++;
currColumnSize = 0;
}
}

for( int i = 0; i < columnsNum; ++i ) {
rootLayout->addLayout( columns[i], 1 );
}
int MaxColumnWidth = 300;
container->setMinimumSize( Wt::WLength( 50 * columnsNum ), Wt::WLength( 15 * widgetsInColumn ) );
container->setMaximumSize( Wt::WLength( MaxColumnWidth * columnsNum ), Wt::WLength( 50 * widgetsInColumn ) );
rootLayout = new WHBoxLayout();
contents()->setLayout( rootLayout );

WScrollArea* scrollArea = new WScrollArea();
scrollArea->setHorizontalScrollBarPolicy( WScrollArea::ScrollBarAlwaysOff );
scrollArea->setWidget( container );
menu->addItem( "birth", scrollArea );

rootLayout->addWidget( menu, 0 );
rootLayout->addWidget( stack, 1 );

rejectWhenEscapePressed();
}
private:
};

class MyApp : public WApplication
{
public:
MyApp( const WEnvironment& env ) : dialog( nullptr ), WApplication( env )
{
setTitle( "test case" );

WPushButton* btn = new WPushButton( "start" );
btn->clicked().connect( std::bind( [=] {
dialog.reset( new CTestDialog() );
dialog->show();
} ) );

root()->addWidget( btn );
}
private:
std::unique_ptr<CTestDialog> dialog;
};

WApplication* createApp( const WEnvironment& env )
{
return new MyApp( env );
}

int main( int argc, char** argv )
{
return WRun( argc, argv, &createApp );
}


std::vector<std::string> GetValues()
{
std::vector<std::string> values;
values.push_back("0000");
values.push_back("1880");
values.push_back("1881");
values.push_back("1882");
values.push_back("1883");
values.push_back("1884");
values.push_back("1885");
values.push_back("1886");
values.push_back("1887");
values.push_back("1888");
values.push_back("1889");
values.push_back("1890");
values.push_back("1891");
values.push_back("1892");
values.push_back("1893");
values.push_back("1894");
values.push_back("1895");
values.push_back("1896");
values.push_back("1897");
values.push_back("1898");
values.push_back("1899");
values.push_back("1900");
values.push_back("1901");
values.push_back("1902");
values.push_back("1903");
values.push_back("1904");
values.push_back("1905");
values.push_back("1906");
values.push_back("1907");
values.push_back("1908");
values.push_back("1909");
values.push_back("1910");
values.push_back("1911");
values.push_back("1912");
values.push_back("1913");
values.push_back("1914");
values.push_back("1915");
values.push_back("1916");
values.push_back("1917");
values.push_back("1918");
values.push_back("1919");
values.push_back("1920");
values.push_back("1921");
values.push_back("1922");
values.push_back("1923");
values.push_back("1924");
values.push_back("1925");
values.push_back("1926");
values.push_back("1927");
values.push_back("1928");
values.push_back("1929");
values.push_back("1930");
values.push_back("1931");
values.push_back("1932");
values.push_back("1933");
values.push_back("1934");
values.push_back("1935");
values.push_back("1936");
values.push_back("1937");
values.push_back("1938");
values.push_back("1939");
values.push_back("1940");
values.push_back("1941");
values.push_back("1942");
values.push_back("1943");
values.push_back("1944");
values.push_back("1945");
values.push_back("1946");
values.push_back("1947");
values.push_back("1948");
values.push_back("1949");
values.push_back("1950");
values.push_back("1951");
values.push_back("1952");
values.push_back("1953");
values.push_back("1954");
values.push_back("1955");
values.push_back("1956");
values.push_back("1957");
values.push_back("1958");
values.push_back("1959");
values.push_back("1960");
values.push_back("1961");
values.push_back("1962");
values.push_back("1963");
values.push_back("1964");
values.push_back("1965");
values.push_back("1966");
values.push_back("1967");
values.push_back("1968");
values.push_back("1969");
values.push_back("1970");
values.push_back("1971");
values.push_back("1972");
values.push_back("1973");
values.push_back("1974");
values.push_back("1975");
values.push_back("1976");
values.push_back("1977");
values.push_back("1978");
values.push_back("1979");
values.push_back("1980");
values.push_back("1981");
values.push_back("1982");
values.push_back("1983");
values.push_back("1984");
values.push_back("1985");
values.push_back("1986");
values.push_back("1987");
values.push_back("1988");
values.push_back("1989");
values.push_back("1990");
values.push_back("1991");
values.push_back("1992");
values.push_back("1993");
values.push_back("1994");
values.push_back("1995");
values.push_back("1996");
values.push_back("1997");
values.push_back("1998");
values.push_back("1999");
values.push_back("2000");
values.push_back("2001");
values.push_back("2002");
values.push_back("2003");
values.push_back("2004");
values.push_back("2005");
values.push_back("2006");
values.push_back("2007");
values.push_back("2008");
values.push_back("2009");
values.push_back("2010");
values.push_back("2011");
values.push_back("2012");
values.push_back("2013");
return values;
}
    (1-1/1)