Пример #1
0
Wt::WWidget* Tester::Input()
{

    Wt::WContainerWidget* container = new Wt::WContainerWidget();
    container->setStyleClass("input_container");

    Wt::WText* t = new Wt::WText("Input", container);
    t->setStyleClass("area_title");
    new Wt::WBreak(container);
    mInput = new Wt::WTextArea(container);
    mInput->setText("20131220T094700");

    new Wt::WBreak(container);

    t = new Wt::WText("Grammar", container);
    t->setStyleClass("area_title");
    new Wt::WBreak(container);
    mGrammar = new Wt::WTextArea(container);
    mGrammar->setRows(15);
    mGrammar->setText("local l = require 'lpeg'\nl.locale(l)\ngrammar = l.C(l.digit^-4)");

    Wt::WPushButton* button = new Wt::WPushButton("Test Grammar", container);
    button->clicked().connect(this, &Tester::GrammarButton);

    button = new Wt::WPushButton("Benchmark Grammar", container);
    button->clicked().connect(this, &Tester::BenchmarkButton);

    button = new Wt::WPushButton("Share Grammar", container);
    button->clicked().connect(this, &Tester::ShareGrammar);

    return container;
}
Пример #2
0
    // inline constructor
    UserFormView() {
        model_ = new UserFormModel(this);

        setTemplateText(tr("userForm-template"));
        addFunction("id", &WTemplate::Functions::id);

        /*
	 * First Name
	 */
	setFormWidget(UserFormModel::FirstNameField, new Wt::WLineEdit());

	/*
	 * Last Name
	 */
	setFormWidget(UserFormModel::LastNameField, new Wt::WLineEdit());

	/*
	 * Country
	 */
	Wt::WComboBox *countryCB = new Wt::WComboBox();
	countryCB->setModel(model_->countryModel());

	countryCB->activated().connect(std::bind([=] () {
	    std::string code = model_->countryCode(countryCB->currentIndex());
	    model_->updateCityModel(code);
	}));

	setFormWidget(UserFormModel::CountryField, countryCB,
            [=] () { // updateViewValue()
	        std::string code = boost::any_cast<std::string>
		    (model_->value(UserFormModel::CountryField));
		int row = model_->countryModelRow(code);
		countryCB->setCurrentIndex(row);
	    },

            [=] () { // updateModelValue()
	        std::string code = model_->countryCode(countryCB->currentIndex());
		model_->setValue(UserFormModel::CountryField, code);
            });

	/*
	 * City
	 */
	Wt::WComboBox *cityCB = new Wt::WComboBox();
	cityCB->setModel(model_->cityModel());
	setFormWidget(UserFormModel::CityField, cityCB);

	/*
	 * Birth Date
	 */
	Wt::WLineEdit *dateEdit = new Wt::WLineEdit();
	Wt::WDatePicker *birthDP = new Wt::WDatePicker(dateEdit);
	bindWidget("birth-dp", birthDP);

	setFormWidget(UserFormModel::BirthField, dateEdit,
	    [=] () { // updateViewValue()
	        Wt::WDate date = boost::any_cast<Wt::WDate>
		    (model_->value(UserFormModel::BirthField));
                birthDP->setDate(date);
	    }, 

            [=] () { // updateModelValue()
	        Wt::WDate date = birthDP->date();
                model_->setValue(UserFormModel::BirthField, date);
	    });

        /*
	 * Children
	 */ 
	setFormWidget(UserFormModel::ChildrenField, new Wt::WSpinBox());

	/*
	 * Remarks
	 */
	Wt::WTextArea *remarksTA = new Wt::WTextArea();
	remarksTA->setColumns(40);
	remarksTA->setRows(5);
	setFormWidget(UserFormModel::RemarksField, remarksTA);

	/*
	 * Title & Buttons
	 */
        Wt::WString title = Wt::WString("Create new user");
        bindString("title", title);

        Wt::WPushButton *button = new Wt::WPushButton("Save");
        bindWidget("submit-button", button);

        bindString("submit-info", Wt::WString());

        button->clicked().connect(this, &UserFormView::process);

        updateView(model_);
    }