{
m_paymentsTableModel = getPaymentsModel(); // m_paymentsTableModel is QSqlRelationalTableModel*
m_paymentsTableModel
->setRelation
(1,
QSqlRelation("students",
"studentId",
"surname"));
m_relatedModel = m_paymentsTableModel->relationModel(1); // m_relatedModel is from table "students", Column 1 is "studentId" in table "payments".
ui->studentComboBox->setModel(m_relatedModel);
ui->studentComboBox->setModelColumn(2); //column 2 is "surname" in table "students".
m_paymentsMapper->setModel(m_paymentsTableModel);
m_paymentsMapper->addMapping(ui->paymentNumberLineEdit, 0);
m_paymentsMapper->addMapping(ui->studentComboBox, 1);
m_paymentsMapper->addMapping(ui->startDateLineEdit, 2);
m_paymentsMapper->addMapping(ui->endDateLineEdit, 3);
m_paymentsMapper->addMapping(ui->allowedLessonsLineEdit, 4);
m_paymentsMapper->addMapping(ui->remainingLessonsLineEdit, 5);
m_paymentsMapper->toFirst();
QObject::connect(ui
->paymentsFirstButton,
&QPushButton
::clicked, m_paymentsMapper,
&QDataWidgetMapper::toFirst);
QObject::connect(ui
->paymentsNextButton,
&QPushButton
::clicked, m_paymentsMapper,
&QDataWidgetMapper::toNext);
QObject::connect(ui
->paymentsPreviousButton,
&QPushButton
::clicked, m_paymentsMapper,
&QDataWidgetMapper::toPrevious);
QObject::connect(ui
->paymentsLastButton,
&QPushButton
::clicked, m_paymentsMapper,
&QDataWidgetMapper::toLast);
QObject::connect(ui
->paymentsAddButton,
&QPushButton
::clicked,
this,
&AbonosWidget::addPayment);
QObject::connect(ui
->paymentsDeleteButton,
&QPushButton
::clicked,
this,
&AbonosWidget::deletePayment);
QObject::connect(m_paymentsMapper,
&QDataWidgetMapper
::currentIndexChanged, ui
->studentComboBox,
&QComboBox::setCurrentIndex);
}
{
m_paymentsTableModel = getPaymentsModel(); // m_paymentsTableModel is QSqlRelationalTableModel*
m_paymentsTableModel->setRelation(1, QSqlRelation("students", "studentId", "surname"));
m_relatedModel = m_paymentsTableModel->relationModel(1); // m_relatedModel is from table "students", Column 1 is "studentId" in table "payments".
ui->studentComboBox->setModel(m_relatedModel);
ui->studentComboBox->setModelColumn(2); //column 2 is "surname" in table "students".
m_paymentsMapper = new QDataWidgetMapper(this);
m_paymentsMapper->setModel(m_paymentsTableModel);
m_paymentsMapper->addMapping(ui->paymentNumberLineEdit, 0);
m_paymentsMapper->addMapping(ui->studentComboBox, 1);
m_paymentsMapper->addMapping(ui->startDateLineEdit, 2);
m_paymentsMapper->addMapping(ui->endDateLineEdit, 3);
m_paymentsMapper->addMapping(ui->allowedLessonsLineEdit, 4);
m_paymentsMapper->addMapping(ui->remainingLessonsLineEdit, 5);
m_paymentsMapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
m_paymentsMapper->setItemDelegate(new QSqlRelationalDelegate(m_paymentsMapper));
m_paymentsMapper->toFirst();
QObject::connect(ui->paymentsFirstButton, &QPushButton::clicked, m_paymentsMapper,
&QDataWidgetMapper::toFirst);
QObject::connect(ui->paymentsNextButton, &QPushButton::clicked, m_paymentsMapper,
&QDataWidgetMapper::toNext);
QObject::connect(ui->paymentsPreviousButton, &QPushButton::clicked, m_paymentsMapper,
&QDataWidgetMapper::toPrevious);
QObject::connect(ui->paymentsLastButton, &QPushButton::clicked, m_paymentsMapper,
&QDataWidgetMapper::toLast);
QObject::connect(ui->paymentsAddButton, &QPushButton::clicked, this,
&AbonosWidget::addPayment);
QObject::connect(ui->paymentsDeleteButton, &QPushButton::clicked, this,
&AbonosWidget::deletePayment);
QObject::connect(m_paymentsMapper, &QDataWidgetMapper::currentIndexChanged, ui->studentComboBox,
&QComboBox::setCurrentIndex);
}
To copy to clipboard, switch view to plain text mode
Bookmarks