/** Constructor for View /usr/lib/Wt/examples/widgetgallery/examples/ComboBoxModel.cpp https://www.webtoolkit.eu/widgets/forms/combo-box https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WComboBox.html */ View::View(const Wt::WEnvironment& env) : Wt::WApplication(env) { setTitle("DropDown Demo"); log("info") << "Test"; // This is the container for the full screen. Wt::WContainerWidget *pScreenContainer = new Wt::WContainerWidget(); pScreenContainer->resize(Wt::WLength::Auto, Wt::WLength::Auto); // Add the primary container to the root widget? root()->addWidget(pScreenContainer); // Choose the grid layout. Wt::WGridLayout *pScreenLayout = new Wt::WGridLayout(); pScreenContainer->setLayout(pScreenLayout); int nRow = 0; int nColoumn = 0; // Create the label Wt::WText *lblSeriesChoice = new Wt::WText("Series:"); // set right align the label lblSeriesChoice->setTextAlignment(Wt::AlignRight); pScreenLayout->addWidget(lblSeriesChoice, nRow, nColoumn+0); // Create the dropdown Wt::WComboBox *cbSeries = new Wt::WComboBox(); cbSeries->addItem(""); cbSeries->addItem("New"); cbSeries->addItem("Krakken awoke"); cbSeries->addItem("Appocalypse survival"); cbSeries->setCurrentIndex(0); // Empty string pScreenLayout->addWidget(cbSeries, nRow, nColoumn+1); // Create the connection cbSeries->activated().connect(this, &View::DropDownSelectionChangeOtherDropDown); cbSeries->activated().connect(this, &View::DropDownSelectionChangeTab); /* Signals connect to Slots. * You may specify up to 6 arguments which may be of arbitrary types that are Copyable, that may be passed through the signal to connected slots. * https://www.webtoolkit.eu/wt/doc/reference/html/group__signalslot.html * I think the * first parm - is a pointer to the target class. * second parm - is the name of the method? * * See: Wt::Signal. */ /* * Let row 1 and column 1 take the excess space.? */ pScreenLayout->setRowStretch(0, 0); pScreenLayout->setColumnStretch(0, 0); } // end
MenuBar::MenuBar(WContainerWidget * parent) : WContainerWidget(parent) { // create demo menu Wt::WComboBox *cb = new Wt::WComboBox(this); cb->addItem("Display a map"); cb->addItem("Create and style clusters"); cb->addItem("Change a map's style"); cb->addItem("Create a heatmap from points"); cb->addItem("Height Lines"); cb->addItem("Raster Tiles"); cb->addItem("Fit to Bounds"); cb->addItem("Set Language"); cb->addItem("Pitch and Bearing"); cb->addItem("Change map colors"); cb->addItem("Layer Order"); cb->addItem("Add a GeoJSON line"); cb->addItem("Add a GeoJSON polygon"); cb->addItem("Draw GeoJSON points"); cb->addItem("Get coordinates from mouse"); cb->addItem("Display a Popup"); cb->addItem("Get features below mouse pointer"); cb->addItem("Get feature on click"); cb->addItem("Info in Popup"); cb->addItem("Mouse Highlight"); cb->addItem("Data Driven Colors"); cb->addItem("Add an image"); cb->addItem("Add a video"); cb->addItem("Realtime Data"); cb->addItem("Add Controls"); cb->setCurrentIndex(0); cb->setMargin(10); // add all demo's to stack Wt::WStackedWidget * stack = new Wt::WStackedWidget(this); stack->addWidget(new DisplayMap()); stack->addWidget(new CreateClusters()); stack->addWidget(new MapStyle()); stack->addWidget(new Heatmap()); stack->addWidget(new HeightLines()); stack->addWidget(new RasterTiles()); stack->addWidget(new FitBounds()); stack->addWidget(new SetLanguage()); stack->addWidget(new PitchAndBearing()); stack->addWidget(new ChangeColors()); stack->addWidget(new LayerOrder()); stack->addWidget(new GeoJSONLine()); stack->addWidget(new GeoJSONPoly()); stack->addWidget(new GeoJSONPoint()); stack->addWidget(new GetCoordinates()); stack->addWidget(new DisplayPopup()); stack->addWidget(new FeaturesBelowMouse()); stack->addWidget(new FeatureOnClick()); stack->addWidget(new InfoPopup()); stack->addWidget(new MouseHighlight()); stack->addWidget(new DataDrivenColors()); stack->addWidget(new AddImage()); stack->addWidget(new AddVideo()); stack->addWidget(new RealtimeData()); stack->addWidget(new AddControls()); cb->changed().connect(std::bind([=]() { int choice = cb->currentIndex(); if (choice < stack->count()) { ((Demo *)stack->currentWidget())->onHide(); stack->setCurrentIndex(choice); ((Demo *)stack->currentWidget())->onShow(); } })); }
// 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_); }