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) {
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 */
/* connect query with common global database */
query = QSqlQuery(db);
/* retrieve professione and fonte from database */
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());
}
model = new QSqlRelationalTableModel(this);
model->setTable("socio");
model->setFilter(QString("socio.id = %1").arg(idSocio));
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
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());
}
int professioneIdx = model->fieldIndex("professione");
int fonteIdx = model->fieldIndex("fonte");
/* populate fields from database */
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();
model->setJoinMode(QSqlRelationalTableModel::LeftJoin);
/* 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() );
}
model->setRelation(professioneIdx, QSqlRelation("professione", "id", "professione"));
model->setRelation(fonteIdx, QSqlRelation("fonte", "id", "fonte"));
void EditWindow::on_buttonSalva_clicked() {
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() ) {
if (! model->select()) {
qDebug() << fullQuery(query);
qDebug() << db.lastError().text();
Ui::status(Ui::ERROR, "query error");
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() {
@ -92,5 +79,7 @@ void EditWindow::on_buttonAnnulla_clicked() {
EditWindow::~EditWindow()
{
delete mapper;
delete model;
delete ui;
}

View File

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

View File

@ -257,14 +257,14 @@
<widget class="QCheckBox" name="checkAbilitaQuestionario">
<property name="geometry">
<rect>
<x>120</x>
<y>180</y>
<width>151</width>
<x>450</x>
<y>170</y>
<width>71</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Abilita compilazione</string>
<string>Abilita</string>
</property>
</widget>
<widget class="QDateEdit" name="dateDataCompilazione">
@ -273,8 +273,8 @@
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>180</y>
<x>230</x>
<y>170</y>
<width>101</width>
<height>32</height>
</rect>
@ -293,13 +293,13 @@
<property name="geometry">
<rect>
<x>10</x>
<y>160</y>
<width>201</width>
<height>21</height>
<y>170</y>
<width>80</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Data compilazione questionario</string>
<string>Questionario</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -318,6 +318,54 @@
<string>Annulla</string>
</property>
</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>
<layoutdefault spacing="6" margin="11"/>

View File

@ -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; }
@ -74,7 +70,7 @@ void MainWindow::on_buttonNuovo_clicked() {
void MainWindow::on_tableSoci_clicked(const QModelIndex& index) {
if (index.isValid()) {
/* 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... */
EditWindow* w = new EditWindow(id, this);
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;
QSqlQuery query;
QLineEdit* lineNome = nullptr;
QLineEdit* lineCognome = nullptr;
QTableView* tableSoci = nullptr;
Ui::MainWindow *ui;
void connectDatabase(void);

View File

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

View File

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

View File

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

View File

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

View File

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