query.exec("CREATE TABLE IF NOT EXISTS plats "
"(id INTEGER PRIMARY KEY, description VARCHAR(200) NOT NULL, "
"qteDispo INT NOT NULL, qteMax INT NOT NULL, prix REAL NOT NULL, "
"type VARCHAR(15) NOT NULL"
")");
query.exec("CREATE TABLE IF NOT EXISTS boissons "
"(id INTEGER PRIMARY KEY, description VARCHAR(200) NOT NULL, "
"qteDispo INT NOT NULL, qteMax INT NOT NULL, prix REAL NOT NULL "
")");
query.exec("INSERT INTO boissons VALUES (0, 'non', 0, 0, 0.0)");
query.exec("CREATE TABLE IF NOT EXISTS sucreries "
"(id INTEGER PRIMARY KEY, description VARCHAR(200) NOT NULL, "
"qteDispo INT NOT NULL, qteMax INT NOT NULL, prix REAL NOT NULL "
")");
query.exec("CREATE TABLE IF NOT EXISTS comptes "
"(id INTEGER PRIMARY KEY, prenom_nom VARCHAR(50) NOT NULL, "
"description VARCHAR(200) NOT NULL, bips INT NOT NULL, argent REAL NOT NULL"
")");
query.exec("CREATE TABLE IF NOT EXISTS staff "
"(id INTEGER PRIMARY KEY, idStaffPerson INTEGER NOT NULL, alias VARCHAR(10) NOT NULL, "
"jour VARCHAR NOT NULL"
")");
query.exec("CREATE TABLE IF NOT EXISTS commandes "
"(idCom INTEGER PRIMARY KEY, idCompte INT NOT NULL, idStock INT NOT NULL, "
"idBoisson INT NOT NULL, prix REAL NOT NULL, "
"paid VARCHAR(10) NOT NULL, idStaff INTEGER NOT NULL, servi VARCHAR(10) NOT NULL, "
"FOREIGN KEY(idStock) REFERENCES stocks(id), "
"FOREIGN KEY(idCompte) REFERENCES comptes(id),"
"FOREIGN KEY(idStaff) REFERENCES staff(id)"
")");
QSqlQuery query(dbStock);
query.exec("CREATE TABLE IF NOT EXISTS plats "
"(id INTEGER PRIMARY KEY, description VARCHAR(200) NOT NULL, "
"qteDispo INT NOT NULL, qteMax INT NOT NULL, prix REAL NOT NULL, "
"type VARCHAR(15) NOT NULL"
")");
query.exec("CREATE TABLE IF NOT EXISTS boissons "
"(id INTEGER PRIMARY KEY, description VARCHAR(200) NOT NULL, "
"qteDispo INT NOT NULL, qteMax INT NOT NULL, prix REAL NOT NULL "
")");
query.exec("INSERT INTO boissons VALUES (0, 'non', 0, 0, 0.0)");
query.exec("CREATE TABLE IF NOT EXISTS sucreries "
"(id INTEGER PRIMARY KEY, description VARCHAR(200) NOT NULL, "
"qteDispo INT NOT NULL, qteMax INT NOT NULL, prix REAL NOT NULL "
")");
query.exec("CREATE TABLE IF NOT EXISTS comptes "
"(id INTEGER PRIMARY KEY, prenom_nom VARCHAR(50) NOT NULL, "
"description VARCHAR(200) NOT NULL, bips INT NOT NULL, argent REAL NOT NULL"
")");
query.exec("CREATE TABLE IF NOT EXISTS staff "
"(id INTEGER PRIMARY KEY, idStaffPerson INTEGER NOT NULL, alias VARCHAR(10) NOT NULL, "
"jour VARCHAR NOT NULL"
")");
query.exec("CREATE TABLE IF NOT EXISTS commandes "
"(idCom INTEGER PRIMARY KEY, idCompte INT NOT NULL, idStock INT NOT NULL, "
"idBoisson INT NOT NULL, prix REAL NOT NULL, "
"paid VARCHAR(10) NOT NULL, idStaff INTEGER NOT NULL, servi VARCHAR(10) NOT NULL, "
"FOREIGN KEY(idStock) REFERENCES stocks(id), "
"FOREIGN KEY(idCompte) REFERENCES comptes(id),"
"FOREIGN KEY(idStaff) REFERENCES staff(id)"
")");
To copy to clipboard, switch view to plain text mode
DockWidgetFormulaireCommande
::DockWidgetFormulaireCommande(QWidget *parent
) : ui(new Ui::DockWidgetFormulaireCommande)
{
ui->setupUi(this);
setupmodel();
/* Setup du mapper */
/* these relationModels work well, the ComboBoxes show the data coming from the idStock and idBoisson column of the "commandes" table*/
platsRelModel = model->relationModel(model->fieldIndex("idStock"));
ui->platsComboBox->setModel(platsRelModel);
ui->platsComboBox->setModelColumn(platsRelModel->fieldIndex("description"));
boissonsRelModel = model->relationModel(model->fieldIndex("idBoisson"));
ui->boissonComboBox->setModel(boissonsRelModel);
ui->boissonComboBox->setModelColumn(boissonsRelModel->fieldIndex("description"));
/* The issue starts here */
mapper->setModel(model);
mapper->addMapping(ui->prenomLineEdit, model->fieldIndex("paid")); // put this column only to see if it worked in a lineEdit (Spoiler, it doesn't)
mapper->addMapping(ui->platsComboBox, model->fieldIndex("idStock"));
mapper->addMapping(ui->boissonComboBox, model->fieldIndex("idBoisson"));
mapper->toFirst();
}
void DockWidgetFormulaireCommande::setupmodel()
{
model->setTable("commandes");
model
->setRelation
(model
->fieldIndex
("idCompte"),
QSqlRelation("comptes",
"id",
"prenom"));
model
->setRelation
(model
->fieldIndex
("idStock"),
QSqlRelation("plats",
"id",
"description"));
model
->setRelation
(model
->fieldIndex
("idBoisson"),
QSqlRelation("boissons",
"id",
"description"));
model
->setRelation
(model
->fieldIndex
("idStaff"),
QSqlRelation("staff",
"id",
"initials"));
model->select();
}
DockWidgetFormulaireCommande::DockWidgetFormulaireCommande(QWidget *parent) :
QDockWidget(parent),
ui(new Ui::DockWidgetFormulaireCommande)
{
ui->setupUi(this);
setupmodel();
/* Setup du mapper */
/* these relationModels work well, the ComboBoxes show the data coming from the idStock and idBoisson column of the "commandes" table*/
platsRelModel = model->relationModel(model->fieldIndex("idStock"));
ui->platsComboBox->setModel(platsRelModel);
ui->platsComboBox->setModelColumn(platsRelModel->fieldIndex("description"));
boissonsRelModel = model->relationModel(model->fieldIndex("idBoisson"));
ui->boissonComboBox->setModel(boissonsRelModel);
ui->boissonComboBox->setModelColumn(boissonsRelModel->fieldIndex("description"));
/* The issue starts here */
mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
mapper->addMapping(ui->prenomLineEdit, model->fieldIndex("paid")); // put this column only to see if it worked in a lineEdit (Spoiler, it doesn't)
mapper->addMapping(ui->platsComboBox, model->fieldIndex("idStock"));
mapper->addMapping(ui->boissonComboBox, model->fieldIndex("idBoisson"));
mapper->toFirst();
}
void DockWidgetFormulaireCommande::setupmodel()
{
model = new QSqlRelationalTableModel(this, QSqlDatabase::database("KFetDatabase"));
model->setTable("commandes");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setRelation(model->fieldIndex("idCompte"), QSqlRelation("comptes", "id", "prenom"));
model->setRelation(model->fieldIndex("idStock"), QSqlRelation("plats", "id", "description"));
model->setRelation(model->fieldIndex("idBoisson"), QSqlRelation("boissons", "id", "description"));
model->setRelation(model->fieldIndex("idStaff"), QSqlRelation("staff", "id", "initials"));
model->select();
}
To copy to clipboard, switch view to plain text mode
Bookmarks