This commit is contained in:
giomba 2019-08-16 23:33:05 +02:00
commit 819c0c4b57
12 changed files with 174 additions and 162 deletions

23
README
View File

@ -1,23 +0,0 @@
Argento
===============
A management software for GOLEM - Gruppo Operativo Linux Empoli.
== Components ==
argento:
president's interface to run on Sala-Corsi
nicolodi:
socio's interface to run on Limortouch
== Dependencies ==
On Debian/Ubuntu/Mint:
qt5-default
... TODO ...
== Build ==
$ cd $REPOSITORY
$ mkdir build-component
$ cd build-component
$ qmake ../component
$ make -j$(nproc)

19
README.md Normal file
View File

@ -0,0 +1,19 @@
# Gestionale da Paura
A management software for GOLEM - Gruppo Operativo Linux Empoli.
## Components
* argento: president's interface to run on Sala-Corsi
* nicolodi: socio's interface to run on Limortouch
## Dependencies
On Debian/Ubuntu/Mint:
* qt5-default
* TODO
# Build
$ cd $REPOSITORY
$ mkdir build-component
$ cd build-component
$ qmake ../component
$ make -j$(nproc)

View File

@ -3,87 +3,74 @@
EditWindow::EditWindow(int idSocio, QWidget* parent) : QMainWindow(parent), ui(new Ui::EditWindow) { EditWindow::EditWindow(int idSocio, QWidget* parent) : QMainWindow(parent), ui(new Ui::EditWindow) {
ui->setupUi(this); ui->setupUi(this);
/* retrieve all elements of the GUI */ /* connect query with common global database */
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); query = QSqlQuery(db);
/* retrieve professione and fonte from database */ model = new QSqlRelationalTableModel(this);
query.prepare("SELECT id, professione FROM professione ORDER BY professione"); model->setTable("socio");
query.exec(); model->setFilter(QString("socio.id = %1").arg(idSocio));
while (query.next()) { model->setEditStrategy(QSqlTableModel::OnManualSubmit);
comboProfessione->addItem(query.value(1).toString(), query.value(0).toInt());
}
query.prepare("SELECT id, fonte FROM fonte ORDER BY fonte"); int professioneIdx = model->fieldIndex("professione");
query.exec(); int fonteIdx = model->fieldIndex("fonte");
while (query.next()) {
comboFonte->addItem(query.value(1).toString(), query.value(0).toInt());
}
/* populate fields from database */ model->setJoinMode(QSqlRelationalTableModel::LeftJoin);
query.prepare("SELECT s.id, s.nome, s.cognome, \
s.dataNascita, s.comuneResidenza, s.email, s.professione, s.fonte, s.abilitaQuestionario, \
q.dataCompilazione \
FROM socio AS s LEFT OUTER JOIN questionario AS q ON s.id = q.socio \
WHERE s.id = :id");
query.bindValue( ":id", idSocio );
query.exec();
query.first();
/* show everything in the interface */ model->setRelation(professioneIdx, QSqlRelation("professione", "id", "professione"));
lineID->setText(query.value( query.record().indexOf("id") ).toString()); model->setRelation(fonteIdx, QSqlRelation("fonte", "id", "fonte"));
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() );
}
void EditWindow::on_buttonSalva_clicked() { if (! model->select()) {
query.prepare("UPDATE socio \
SET nome = NULLIF(:nome, ''), \
cognome = NULLIF(:cognome, ''), \
dataNascita = NULLIF(:dataNascita, '1900-01-01'), \
comuneResidenza = NULLIF(:comuneResidenza, ''), \
email = NULLIF(:email, ''), \
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());
if ( ! query.exec() ) {
qDebug() << fullQuery(query); qDebug() << fullQuery(query);
qDebug() << db.lastError().text(); qDebug() << db.lastError().text();
Ui::status(Ui::ERROR, "query error"); Ui::status(Ui::ERROR, "query error");
return; return;
} }
Ui::status(Ui::SUCCESS, "successfull update"); QSqlTableModel* professioneModel = model->relationModel(professioneIdx);
ui->comboProfessione->setModel(professioneModel);
ui->comboProfessione->setModelColumn(professioneModel->fieldIndex("professione"));
QSqlTableModel* fonteModel = model->relationModel(fonteIdx);
ui->comboFonte->setModel(fonteModel);
ui->comboFonte->setModelColumn(fonteModel->fieldIndex("fonte"));
mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
mapper->addMapping(ui->lineID, model->fieldIndex("id"));
mapper->addMapping(ui->lineCognome, model->fieldIndex("cognome"));
mapper->addMapping(ui->lineNome, model->fieldIndex("nome"));
mapper->addMapping(ui->dateDataNascita, model->fieldIndex("dataNascita"));
mapper->addMapping(ui->lineComuneResidenza, model->fieldIndex("comuneResidenza"));
mapper->addMapping(ui->lineEmail, model->fieldIndex("email"));
mapper->addMapping(ui->comboProfessione, professioneIdx);
mapper->addMapping(ui->comboFonte, fonteIdx);
mapper->addMapping(ui->checkAbilitaQuestionario, model->fieldIndex("abilitaQuestionario"));
mapper->addMapping(ui->linePin, model->fieldIndex("pin"));
mapper->toFirst();
}
void EditWindow::on_buttonSalva_clicked() {
if (model->isDirty()) {
model->database().transaction();
if (model->submitAll()) {
model->database().commit();
Ui::status(Ui::SUCCESS, "successfull update");
/* update ui */
model->select();
mapper->toFirst();
} else {
model->database().rollback();
qDebug() << model->lastError();
Ui::status(Ui::ERROR, "model transaction submit error");
}
} else {
Ui::status(Ui::INFO, "nothing done");
}
} }
void EditWindow::on_buttonAnnulla_clicked() { void EditWindow::on_buttonAnnulla_clicked() {
@ -92,5 +79,7 @@ void EditWindow::on_buttonAnnulla_clicked() {
EditWindow::~EditWindow() EditWindow::~EditWindow()
{ {
delete mapper;
delete model;
delete ui; delete ui;
} }

View File

@ -4,6 +4,8 @@
#include <QDebug> #include <QDebug>
#include <QMainWindow> #include <QMainWindow>
#include <QMessageBox> #include <QMessageBox>
#include <QtSql>
#include <QtWidgets>
#include <iostream> #include <iostream>
@ -29,18 +31,9 @@ private slots:
void on_buttonAnnulla_clicked(); void on_buttonAnnulla_clicked();
private: 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; QSqlQuery query;
QSqlRelationalTableModel* model = nullptr;
QDataWidgetMapper* mapper = nullptr;
Ui::EditWindow *ui; Ui::EditWindow *ui;
}; };

View File

@ -257,14 +257,14 @@
<widget class="QCheckBox" name="checkAbilitaQuestionario"> <widget class="QCheckBox" name="checkAbilitaQuestionario">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>120</x> <x>450</x>
<y>180</y> <y>170</y>
<width>151</width> <width>71</width>
<height>31</height> <height>31</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>Abilita compilazione</string> <string>Abilita</string>
</property> </property>
</widget> </widget>
<widget class="QDateEdit" name="dateDataCompilazione"> <widget class="QDateEdit" name="dateDataCompilazione">
@ -273,8 +273,8 @@
</property> </property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>230</x>
<y>180</y> <y>170</y>
<width>101</width> <width>101</width>
<height>32</height> <height>32</height>
</rect> </rect>
@ -293,13 +293,13 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>10</x>
<y>160</y> <y>170</y>
<width>201</width> <width>80</width>
<height>21</height> <height>31</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>Data compilazione questionario</string> <string>Questionario</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
@ -318,6 +318,54 @@
<string>Annulla</string> <string>Annulla</string>
</property> </property>
</widget> </widget>
<widget class="QLabel" name="label_12">
<property name="geometry">
<rect>
<x>100</x>
<y>170</y>
<width>131</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Ultima compilazione</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QLineEdit" name="linePin">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>370</x>
<y>170</y>
<width>71</width>
<height>32</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="label_13">
<property name="geometry">
<rect>
<x>340</x>
<y>170</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>OTP</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</widget> </widget>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>

View File

@ -4,10 +4,6 @@ MainWindow* mw;
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this); ui->setupUi(this);
lineCognome = this->findChild<QLineEdit*>("lineCognome");
lineNome = this->findChild<QLineEdit*>("lineNome");
tableSoci = this->findChild<QTableView*>("tableSoci");
} }
void MainWindow::connectDatabase(void) { void MainWindow::connectDatabase(void) {
@ -39,8 +35,8 @@ void MainWindow::on_buttonCerca_clicked() {
if (!db.open()) connectDatabase(); 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.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( ":nome", QString("%%1%").arg(ui->lineNome->text()) );
query.bindValue( ":cognome", QString("%%1%").arg(lineCognome->text()) ); query.bindValue( ":cognome", QString("%%1%").arg(ui->lineCognome->text()) );
if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; } if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; }
if ( query.size() == 0) { status(Ui::INFO, "no results found"); 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())); 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 */ /* 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&))); //QObject::connect(tableSoci, SIGNAL(clicked(const QModelIndex&)), this, SLOT(on_tableSoci_clicked(const QModelIndex&)));
tableSoci->show(); ui->tableSoci->show();
} }
void MainWindow::on_buttonNuovo_clicked() { void MainWindow::on_buttonNuovo_clicked() {
if (! db.open()) connectDatabase(); if (! db.open()) connectDatabase();
query.prepare("INSERT INTO socio (nome, cognome) VALUES (NULLIF(:nome, ''), NULLIF(:cognome, ''))"); query.prepare("INSERT INTO socio (nome, cognome) VALUES (NULLIF(:nome, ''), NULLIF(:cognome, ''))");
query.bindValue(":nome", lineNome->text()); query.bindValue(":nome", ui->lineNome->text());
query.bindValue(":cognome", lineCognome->text()); query.bindValue(":cognome", ui->lineCognome->text());
if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; } if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; }
if (! query.lastInsertId().isValid()) { status(Ui::ERROR, fullQuery(query)); return; } if (! query.lastInsertId().isValid()) { status(Ui::ERROR, fullQuery(query)); return; }
@ -74,7 +70,7 @@ void MainWindow::on_buttonNuovo_clicked() {
void MainWindow::on_tableSoci_clicked(const QModelIndex& index) { void MainWindow::on_tableSoci_clicked(const QModelIndex& index) {
if (index.isValid()) { if (index.isValid()) {
/* extracts id socio from first column of table view */ /* extracts id socio from first column of table view */
int id = index.model()->data(index.siblingAtColumn(0)).toInt(); int id = index.model()->data(index.sibling(index.row(), 0)).toInt();
if (id != 0) { /* if click is not on other fields than id... */ if (id != 0) { /* if click is not on other fields than id... */
EditWindow* w = new EditWindow(id, this); EditWindow* w = new EditWindow(id, this);
w->setAttribute(Qt::WA_DeleteOnClose); /* delete window at the end */ w->setAttribute(Qt::WA_DeleteOnClose); /* delete window at the end */
@ -82,4 +78,4 @@ void MainWindow::on_tableSoci_clicked(const QModelIndex& index) {
} }
} }
} }

View File

@ -33,10 +33,6 @@ private:
SociModel* sociModel = nullptr; SociModel* sociModel = nullptr;
QSqlQuery query; QSqlQuery query;
QLineEdit* lineNome = nullptr;
QLineEdit* lineCognome = nullptr;
QTableView* tableSoci = nullptr;
Ui::MainWindow *ui; Ui::MainWindow *ui;
void connectDatabase(void); void connectDatabase(void);

View File

@ -1,14 +1,10 @@
#include "EditWindow.h" #include "EditWindow.h"
#include "ui_EditWindow.h" #include "ui_EditWindow.h"
EditWindow::EditWindow(int idSocio, QString pin, QWidget *parent) : EditWindow::EditWindow(int idSocio, QWidget* parent) : QMainWindow(parent), ui(new Ui::EditWindow) {
QMainWindow(parent),
ui(new Ui::EditWindow)
{
ui->setupUi(this); ui->setupUi(this);
if (!db.open()) { if (!db.open()) {
// QMessageBox::critical(this, "Nicolodi", "Problemi con la connessione al db");
showError(db.lastError()); showError(db.lastError());
this->doNotShow = true; this->doNotShow = true;
return; return;
@ -21,10 +17,10 @@ EditWindow::EditWindow(int idSocio, QString pin, QWidget *parent) :
model->setEditStrategy(QSqlTableModel::OnManualSubmit); model->setEditStrategy(QSqlTableModel::OnManualSubmit);
// Indici dei campi in join // Indici dei campi in join
//professioneIdx = model->fieldIndex("professione"); professioneIdx = model->fieldIndex("professione");
//fonteIdx = model->fieldIndex("fonte"); fonteIdx = model->fieldIndex("fonte");
// La strategia di join da usare per le rleazioni e' LeftJoin // La strategia di join da usare per le relazioni è LeftJoin
model->setJoinMode(QSqlRelationalTableModel::LeftJoin); model->setJoinMode(QSqlRelationalTableModel::LeftJoin);
// Imposta le relazioni // Imposta le relazioni
@ -73,6 +69,7 @@ void EditWindow::showError(const QSqlError &err)
EditWindow::~EditWindow() EditWindow::~EditWindow()
{ {
delete model;
delete ui; delete ui;
} }

View File

@ -17,7 +17,7 @@ class EditWindow : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit EditWindow(int idSocio, QString pin, QWidget *parent = nullptr); explicit EditWindow(int idSocio, QWidget* parent = nullptr);
~EditWindow(); ~EditWindow();
bool doNotShow = false; bool doNotShow = false;
@ -29,7 +29,7 @@ private slots:
private: private:
Ui::EditWindow *ui; Ui::EditWindow *ui;
QSqlRelationalTableModel *model; QSqlRelationalTableModel *model = nullptr;
bool doNotShow_; bool doNotShow_;
int professioneIdx; int professioneIdx;
int fonteIdx; int fonteIdx;

View File

@ -2,10 +2,7 @@
#include "ui_Pin.h" #include "ui_Pin.h"
#include "EditWindow.h" #include "EditWindow.h"
Pin::Pin(QWidget *parent) : Pin::Pin(QWidget *parent) : QDialog(parent), ui(new Ui::Pin) {
QDialog(parent),
ui(new Ui::Pin)
{
ui->setupUi(this); ui->setupUi(this);
// Imposta la dialog come non ingrandibile/riducibile // Imposta la dialog come non ingrandibile/riducibile
@ -30,8 +27,6 @@ void Pin::on_pushButtonOk_clicked()
bool questionarioAbilitato; bool questionarioAbilitato;
QString pin = ui->lineEditPin->text(); QString pin = ui->lineEditPin->text();
connectDatabase();
if (db.open()) { if (db.open()) {
query = QSqlQuery(db); query = QSqlQuery(db);
query.prepare("SELECT id, abilitaQuestionario FROM socio WHERE pin = :pin"); query.prepare("SELECT id, abilitaQuestionario FROM socio WHERE pin = :pin");
@ -60,7 +55,7 @@ void Pin::on_pushButtonOk_clicked()
// sono risorse preziose che si devono aprire, usare per il minor // sono risorse preziose che si devono aprire, usare per il minor
// tempo possibile e quindi chiudere // tempo possibile e quindi chiudere
query.clear(); query.clear();
db.close(); //db.close();
} else { } else {
QMessageBox::critical(this, "Nicolodi", "Impossibile connettersi al database, verificare impostazioni."); QMessageBox::critical(this, "Nicolodi", "Impossibile connettersi al database, verificare impostazioni.");
} }
@ -72,7 +67,7 @@ void Pin::on_pushButtonOk_clicked()
// delle editwindow // delle editwindow
// Un socio e' valido se ha idSocio maggiore di zero // Un socio e' valido se ha idSocio maggiore di zero
if (idSocio > 0) { if (idSocio > 0) {
EditWindow *ew = new EditWindow(idSocio, pin, this); EditWindow *ew = new EditWindow(idSocio, this);
ew->setAttribute(Qt::WA_DeleteOnClose); ew->setAttribute(Qt::WA_DeleteOnClose);
ew->setWindowModality(Qt::ApplicationModal); ew->setWindowModality(Qt::ApplicationModal);
if (!ew->doNotShow) { if (!ew->doNotShow) {

View File

@ -10,10 +10,10 @@ void connectDatabase() {
/* open database and attach query */ /* open database and attach query */
db = QSqlDatabase::addDatabase("QMYSQL"); /* QMYSQL <-- database driver */ db = QSqlDatabase::addDatabase("QMYSQL"); /* QMYSQL <-- database driver */
// db.setHostName(settings.value("hostname").toString()); db.setHostName(settings.value("hostname").toString());
// db.setDatabaseName(settings.value("database").toString()); db.setDatabaseName(settings.value("database").toString());
// db.setUserName(settings.value("username").toString()); db.setUserName(settings.value("username").toString());
// db.setPassword(settings.value("password").toString()); db.setPassword(settings.value("password").toString());
// db.setHostName(settings.value("hostname","serverozzo.golem.linux.it").toString()); // db.setHostName(settings.value("hostname","serverozzo.golem.linux.it").toString());
// db.setDatabaseName(settings.value("database","golem_gestionale").toString()); // db.setDatabaseName(settings.value("database","golem_gestionale").toString());
@ -21,17 +21,17 @@ void connectDatabase() {
// db.setUserName(settings.value("username").toString()); // db.setUserName(settings.value("username").toString());
// db.setPassword(settings.value("password").toString()); // db.setPassword(settings.value("password").toString());
QString hostname = settings.value("hostname","localhost").toString(); // QString hostname = settings.value("hostname","localhost").toString();
QString database = settings.value("database","golem_gestionale").toString(); // QString database = settings.value("database","golem_gestionale").toString();
int port = settings.value("port", "3306").toInt(); // int port = settings.value("port", "3306").toInt();
QString username = settings.value("username", "admin").toString(); // QString username = settings.value("username", "admin").toString();
QString password = settings.value("password", "password").toString(); // QString password = settings.value("password", "password").toString();
db.setHostName(hostname); // db.setHostName(hostname);
db.setDatabaseName(database); // db.setDatabaseName(database);
db.setPort(port); // db.setPort(port);
db.setUserName(username); // db.setUserName(username);
db.setPassword(password); // db.setPassword(password);
// query = QSqlQuery(db); // query = QSqlQuery(db);
} }

View File

@ -4,7 +4,9 @@
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
QApplication a(argc, argv); QApplication a(argc, argv);
// MainWindow w;
connectDatabase();
Pin w; Pin w;
w.show(); w.show();