Removed redundant references to ui elements
This commit is contained in:
parent
dc5387b63c
commit
ac102857f9
|
@ -3,18 +3,6 @@
|
|||
EditWindow::EditWindow(int idSocio, QWidget* parent) : QMainWindow(parent), ui(new Ui::EditWindow) {
|
||||
ui->setupUi(this);
|
||||
|
||||
/* retrieve all elements of the GUI */
|
||||
lineID = this->findChild<QLineEdit*>("lineID");
|
||||
lineNome = this->findChild<QLineEdit*>("lineNome");
|
||||
lineCognome = this->findChild<QLineEdit*>("lineCognome");
|
||||
lineComuneResidenza = this->findChild<QLineEdit*>("lineComuneResidenza");
|
||||
lineEmail = this->findChild<QLineEdit*>("lineEmail");
|
||||
dateDataNascita = this->findChild<QDateEdit*>("dateDataNascita");
|
||||
dateDataCompilazione = this->findChild<QDateEdit*>("dateDataCompilazione");
|
||||
comboProfessione = this->findChild<QComboBox*>("comboProfessione");
|
||||
comboFonte = this->findChild<QComboBox*>("comboFonte");
|
||||
checkAbilitaQuestionario = this->findChild<QCheckBox*>("checkAbilitaQuestionario");
|
||||
|
||||
/* connect query with common database */
|
||||
query = QSqlQuery(db);
|
||||
|
||||
|
@ -22,13 +10,13 @@ EditWindow::EditWindow(int idSocio, QWidget* parent) : QMainWindow(parent), ui(n
|
|||
query.prepare("SELECT id, professione FROM professione ORDER BY professione");
|
||||
query.exec();
|
||||
while (query.next()) {
|
||||
comboProfessione->addItem(query.value(1).toString(), query.value(0).toInt());
|
||||
ui->comboProfessione->addItem(query.value(1).toString(), query.value(0).toInt());
|
||||
}
|
||||
|
||||
query.prepare("SELECT id, fonte FROM fonte ORDER BY fonte");
|
||||
query.exec();
|
||||
while (query.next()) {
|
||||
comboFonte->addItem(query.value(1).toString(), query.value(0).toInt());
|
||||
ui->comboFonte->addItem(query.value(1).toString(), query.value(0).toInt());
|
||||
}
|
||||
|
||||
/* populate fields from database */
|
||||
|
@ -42,16 +30,16 @@ EditWindow::EditWindow(int idSocio, QWidget* parent) : QMainWindow(parent), ui(n
|
|||
query.first();
|
||||
|
||||
/* show everything in the interface */
|
||||
lineID->setText(query.value( query.record().indexOf("id") ).toString());
|
||||
lineNome->setText(query.value( query.record().indexOf("nome") ).toString());
|
||||
lineCognome->setText(query.value( query.record().indexOf("cognome") ).toString());
|
||||
lineComuneResidenza->setText(query.value(query.record().indexOf("comuneResidenza")).toString());
|
||||
lineEmail->setText(query.value(query.record().indexOf("email")).toString());
|
||||
comboProfessione->setCurrentIndex(comboProfessione->findData(query.value(query.record().indexOf("professione")).toInt()));
|
||||
comboFonte->setCurrentIndex(comboFonte->findData(query.value(query.record().indexOf("fonte")).toInt()));
|
||||
dateDataNascita->setDate(QDate(1900, 1, 1)); dateDataNascita->setDate(query.value(query.record().indexOf("dataNascita")).toDate());
|
||||
dateDataCompilazione->setDate(QDate(1900, 1, 1)); dateDataCompilazione->setDate(query.value(query.record().indexOf("dataCompilazione")).toDate());
|
||||
checkAbilitaQuestionario->setChecked( query.value(query.record().indexOf("abilitaQuestionario")).toBool() );
|
||||
ui->lineID->setText(query.value( query.record().indexOf("id") ).toString());
|
||||
ui->lineNome->setText(query.value( query.record().indexOf("nome") ).toString());
|
||||
ui->lineCognome->setText(query.value( query.record().indexOf("cognome") ).toString());
|
||||
ui->lineComuneResidenza->setText(query.value(query.record().indexOf("comuneResidenza")).toString());
|
||||
ui->lineEmail->setText(query.value(query.record().indexOf("email")).toString());
|
||||
ui->comboProfessione->setCurrentIndex(ui->comboProfessione->findData(query.value(query.record().indexOf("professione")).toInt()));
|
||||
ui->comboFonte->setCurrentIndex(ui->comboFonte->findData(query.value(query.record().indexOf("fonte")).toInt()));
|
||||
ui->dateDataNascita->setDate(QDate(1900, 1, 1)); ui->dateDataNascita->setDate(query.value(query.record().indexOf("dataNascita")).toDate());
|
||||
ui->dateDataCompilazione->setDate(QDate(1900, 1, 1)); ui->dateDataCompilazione->setDate(query.value(query.record().indexOf("dataCompilazione")).toDate());
|
||||
ui->checkAbilitaQuestionario->setChecked( query.value(query.record().indexOf("abilitaQuestionario")).toBool() );
|
||||
}
|
||||
|
||||
void EditWindow::on_buttonSalva_clicked() {
|
||||
|
@ -66,15 +54,15 @@ professione = NULLIF(:professione, 0), \
|
|||
fonte = NULLIF(:fonte, 0), \
|
||||
abilitaQuestionario = :abilitaQuestionario \
|
||||
WHERE id = :id");
|
||||
query.bindValue(":id", lineID->text());
|
||||
query.bindValue(":nome", lineNome->text());
|
||||
query.bindValue(":cognome", lineCognome->text());
|
||||
query.bindValue(":comuneResidenza", lineComuneResidenza->text());
|
||||
query.bindValue(":email", lineEmail->text());
|
||||
query.bindValue(":dataNascita", (dateDataNascita->date()).toString("yyyy-MM-dd"));
|
||||
query.bindValue(":professione", comboProfessione->currentData().toInt());
|
||||
query.bindValue(":fonte", comboFonte->currentData().toInt());
|
||||
query.bindValue(":abilitaQuestionario", checkAbilitaQuestionario->isChecked());
|
||||
query.bindValue(":id", ui->lineID->text());
|
||||
query.bindValue(":nome", ui->lineNome->text());
|
||||
query.bindValue(":cognome", ui->lineCognome->text());
|
||||
query.bindValue(":comuneResidenza", ui->lineComuneResidenza->text());
|
||||
query.bindValue(":email", ui->lineEmail->text());
|
||||
query.bindValue(":dataNascita", (ui->dateDataNascita->date()).toString("yyyy-MM-dd"));
|
||||
query.bindValue(":professione", ui->comboProfessione->currentData().toInt());
|
||||
query.bindValue(":fonte", ui->comboFonte->currentData().toInt());
|
||||
query.bindValue(":abilitaQuestionario", ui->checkAbilitaQuestionario->isChecked());
|
||||
|
||||
if ( ! query.exec() ) {
|
||||
qDebug() << fullQuery(query);
|
||||
|
|
|
@ -29,17 +29,6 @@ private slots:
|
|||
void on_buttonAnnulla_clicked();
|
||||
|
||||
private:
|
||||
QLineEdit* lineID = nullptr;
|
||||
QLineEdit* lineNome = nullptr;
|
||||
QLineEdit* lineCognome = nullptr;
|
||||
QLineEdit* lineComuneResidenza = nullptr;
|
||||
QLineEdit* lineEmail = nullptr;
|
||||
QDateEdit* dateDataNascita = nullptr;
|
||||
QDateEdit* dateDataCompilazione = nullptr;
|
||||
QComboBox* comboProfessione = nullptr;
|
||||
QComboBox* comboFonte = nullptr;
|
||||
QCheckBox* checkAbilitaQuestionario = nullptr;
|
||||
|
||||
QSqlQuery query;
|
||||
|
||||
Ui::EditWindow *ui;
|
||||
|
|
|
@ -4,10 +4,6 @@ MainWindow* mw;
|
|||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||
ui->setupUi(this);
|
||||
|
||||
lineCognome = this->findChild<QLineEdit*>("lineCognome");
|
||||
lineNome = this->findChild<QLineEdit*>("lineNome");
|
||||
tableSoci = this->findChild<QTableView*>("tableSoci");
|
||||
}
|
||||
|
||||
void MainWindow::connectDatabase(void) {
|
||||
|
@ -39,8 +35,8 @@ void MainWindow::on_buttonCerca_clicked() {
|
|||
if (!db.open()) connectDatabase();
|
||||
|
||||
query.prepare("SELECT id, nome, cognome FROM socio WHERE LOWER(nome) LIKE LOWER(:nome) AND LOWER(cognome) LIKE LOWER(:cognome)");
|
||||
query.bindValue( ":nome", QString("%%1%").arg(lineNome->text()) );
|
||||
query.bindValue( ":cognome", QString("%%1%").arg(lineCognome->text()) );
|
||||
query.bindValue( ":nome", QString("%%1%").arg(ui->lineNome->text()) );
|
||||
query.bindValue( ":cognome", QString("%%1%").arg(ui->lineCognome->text()) );
|
||||
|
||||
if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; }
|
||||
if ( query.size() == 0) { status(Ui::INFO, "no results found"); return; }
|
||||
|
@ -50,18 +46,18 @@ void MainWindow::on_buttonCerca_clicked() {
|
|||
|
||||
status(Ui::INFO, QString("%1 results found").arg(query.size()));
|
||||
|
||||
tableSoci->setModel(sociModel);
|
||||
ui->tableSoci->setModel(sociModel);
|
||||
/* the signal is automagically added by some obscure qt build system, provided the function is named in a standard way */
|
||||
//QObject::connect(tableSoci, SIGNAL(clicked(const QModelIndex&)), this, SLOT(on_tableSoci_clicked(const QModelIndex&)));
|
||||
tableSoci->show();
|
||||
ui->tableSoci->show();
|
||||
}
|
||||
|
||||
void MainWindow::on_buttonNuovo_clicked() {
|
||||
if (! db.open()) connectDatabase();
|
||||
|
||||
query.prepare("INSERT INTO socio (nome, cognome) VALUES (NULLIF(:nome, ''), NULLIF(:cognome, ''))");
|
||||
query.bindValue(":nome", lineNome->text());
|
||||
query.bindValue(":cognome", lineCognome->text());
|
||||
query.bindValue(":nome", ui->lineNome->text());
|
||||
query.bindValue(":cognome", ui->lineCognome->text());
|
||||
if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; }
|
||||
|
||||
if (! query.lastInsertId().isValid()) { status(Ui::ERROR, fullQuery(query)); return; }
|
||||
|
|
|
@ -33,10 +33,6 @@ private:
|
|||
SociModel* sociModel = nullptr;
|
||||
QSqlQuery query;
|
||||
|
||||
QLineEdit* lineNome = nullptr;
|
||||
QLineEdit* lineCognome = nullptr;
|
||||
QTableView* tableSoci = nullptr;
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
void connectDatabase(void);
|
||||
|
|
Loading…
Reference in New Issue