updated QskModelObjectBinder example

This commit is contained in:
Aldo Nicolas Bruno 2024-02-23 23:15:16 +01:00
parent 196d076fd5
commit a9e0716c06
1 changed files with 9 additions and 1 deletions

View File

@ -49,6 +49,7 @@ Window::Window( )
mapper->bindObject(spin, 0); // needs USER=true for value in QskBoundedInput mapper->bindObject(spin, 0); // needs USER=true for value in QskBoundedInput
mapper->bindObject(txt, 1); // needs USER=true for text in QskTextInput mapper->bindObject(txt, 1); // needs USER=true for text in QskTextInput
// this loads the record from the first row and updates the controls data.
mapper->selectRow(0); mapper->selectRow(0);
auto v = new QskLinearBox(Qt::Vertical); auto v = new QskLinearBox(Qt::Vertical);
@ -63,12 +64,19 @@ Window::Window( )
connect(next,&QskPushButton::clicked,[=]() { mapper->selectRow( 1 ); }); connect(next,&QskPushButton::clicked,[=]() { mapper->selectRow( 1 ); });
v->addItem(h); v->addItem(h);
auto save = new QskPushButton("Save",v); auto save = new QskPushButton("Save Data to Model",v);
connect(save,&QskPushButton::clicked,[=]() { connect(save,&QskPushButton::clicked,[=]() {
// this will update the current record with the data from the SpinBox and TextInput
mapper->updateModel(); mapper->updateModel();
// just for illustration we print out the record
auto r = table->record(mapper->currentRow()); auto r = table->record(mapper->currentRow());
qDebug() << r; qDebug() << r;
}); });
auto set0 = new QskPushButton("Set Model field to 0",v);
connect(set0,&QskPushButton::clicked,[=]() {
// this should trigger the binder and update the spinbox
table->setData( table->index(mapper->currentRow(),0),0 );
});
v->addSpacer( 0,100 ); v->addSpacer( 0,100 );
} }