From 0e3f3483bc8977efac22381d40d070f71f870b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vermot?= Date: Tue, 9 Jan 2024 23:02:11 +0100 Subject: [PATCH] Ajout de la fonction de suppression de vol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les vols non soumis au CE et non associés à une recette de balade/sortie peuvent être supprimés. Préparation de la mise en place de l'édition de vol. --- database/structure.sql | 3 +- ressources/airplane-edit.svg | 1 + ressources/airplane-remove.svg | 1 + src/AeroDms.cpp | 88 ++++++++++++++++++++++++++++++++-- src/AeroDms.h | 4 ++ src/AeroDmsTypes.h | 4 +- src/ManageDb.cpp | 19 ++++++++ src/ManageDb.h | 1 + src/main.cpp | 1 + 9 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 ressources/airplane-edit.svg create mode 100644 ressources/airplane-remove.svg diff --git a/database/structure.sql b/database/structure.sql index 1cd89ef..adf8014 100644 --- a/database/structure.sql +++ b/database/structure.sql @@ -1,5 +1,5 @@ -- --- File generated with SQLiteStudio v3.4.4 on lun. janv. 1 23:01:41 2024 +-- File generated with SQLiteStudio v3.4.4 on mar. janv. 9 21:38:21 2024 -- -- Text encoding used: UTF-8 -- @@ -175,6 +175,7 @@ ORDER BY annee, vol.pilote, typeDeVol; -- View: vols CREATE VIEW IF NOT EXISTS vols AS SELECT + vol.volId, vol.date, vol.pilote, pilote.nom, diff --git a/ressources/airplane-edit.svg b/ressources/airplane-edit.svg new file mode 100644 index 0000000..c06b045 --- /dev/null +++ b/ressources/airplane-edit.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ressources/airplane-remove.svg b/ressources/airplane-remove.svg new file mode 100644 index 0000000..5f6af25 --- /dev/null +++ b/ressources/airplane-remove.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/AeroDms.cpp b/src/AeroDms.cpp index 92a1f79..2732d00 100644 --- a/src/AeroDms.cpp +++ b/src/AeroDms.cpp @@ -27,7 +27,7 @@ along with this program. If not, see . AeroDms::AeroDms(QWidget* parent):QMainWindow(parent) { QApplication::setApplicationName("AeroDms"); - QApplication::setApplicationVersion("1.3"); + QApplication::setApplicationVersion("1.4"); QApplication::setWindowIcon(QIcon("./ressources/shield-airplane.svg")); QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::applicationDirPath()); @@ -125,9 +125,13 @@ AeroDms::AeroDms(QWidget* parent):QMainWindow(parent) vueVols->setHorizontalHeaderItem(AeroDmsTypes::VolTableElement_SUBVENTION, new QTableWidgetItem("Subvention")); vueVols->setHorizontalHeaderItem(AeroDmsTypes::VolTableElement_SOUMIS_CE, new QTableWidgetItem("Soumis CE")); vueVols->setHorizontalHeaderItem(AeroDmsTypes::VolTableElement_REMARQUE, new QTableWidgetItem("Remarque")); + vueVols->setHorizontalHeaderItem(AeroDmsTypes::VolTableElement_VOL_ID, new QTableWidgetItem("ID")); + vueVols->setColumnHidden(AeroDmsTypes::VolTableElement_VOL_ID, true); vueVols->setEditTriggers(QAbstractItemView::NoEditTriggers); vueVols->setSelectionBehavior(QAbstractItemView::SelectRows); + vueVols->setContextMenuPolicy(Qt::CustomContextMenu); mainTabWidget->addTab(vueVols, QIcon("./ressources/airplane.svg"), "Vols"); + connect(vueVols, &QTableWidget::customContextMenuRequested, this, &AeroDms::menuContextuelVols); //==========Onglet Ajout dépense QHBoxLayout* ajoutVol = new QHBoxLayout(this); @@ -398,6 +402,7 @@ AeroDms::AeroDms(QWidget* parent):QMainWindow(parent) //========================Initialisation des autres attributs piloteAEditer = ""; + volAEditer = ""; factureIdEnBdd = 0; peuplerListesPilotes(); @@ -479,6 +484,7 @@ void AeroDms::peuplerTableVols() vueVols->setItem(i, AeroDmsTypes::VolTableElement_SUBVENTION, new QTableWidgetItem(QString::number(vol.montantRembourse).append(" €"))); vueVols->setItem(i, AeroDmsTypes::VolTableElement_TYPE_DE_VOL, new QTableWidgetItem(vol.typeDeVol)); vueVols->setItem(i, AeroDmsTypes::VolTableElement_REMARQUE, new QTableWidgetItem(vol.remarque)); + vueVols->setItem(i, AeroDmsTypes::VolTableElement_VOL_ID, new QTableWidgetItem(QString::number(vol.volId))); } vueVols->resizeColumnsToContents(); @@ -1053,16 +1059,19 @@ void AeroDms::menuContextuelPilotes(const QPoint& pos) { if (vuePilotes->itemAt(pos) != nullptr) { - QMenu menuClicDroitVol(tr("Menu contextuel"), this); + QMenu menuClicDroitPilote(tr("Menu contextuel"), this); const int ligneSelectionnee = vuePilotes->itemAt(pos)->row(); piloteAEditer = vuePilotes->item( ligneSelectionnee, - AeroDmsTypes::PiloteTableElement_PILOTE_ID)->text(); + AeroDmsTypes::PiloteTableElement_PILOTE_ID)->text(); const QIcon iconeAjouterPilote = QIcon("./ressources/account-tie-hat.svg"); QAction editer(iconeAjouterPilote,"Editer le pilote", this); connect(&editer, SIGNAL(triggered()), this, SLOT(editerPilote())); - menuClicDroitVol.addAction(&editer); - menuClicDroitVol.exec(vuePilotes->mapToGlobal(pos)); + menuClicDroitPilote.addAction(&editer); + + //Afficher le menu sur la vue des pilotes + //menuClicDroitPilote.exec(vuePilotes->mapToGlobal(pos)); + menuClicDroitPilote.exec(vuePilotes->mapToGlobal(QCursor::pos())); } } @@ -1072,3 +1081,72 @@ void AeroDms::editerPilote() dialogueGestionPilote->exec(); } +void AeroDms::menuContextuelVols(const QPoint& pos) +{ + if (vueVols->itemAt(pos) != nullptr) + { + QMenu menuClicDroitVol(tr("Menu contextuel"), this); + const int ligneSelectionnee = vueVols->itemAt(pos)->row(); + volAEditer = vueVols->item( ligneSelectionnee, + AeroDmsTypes::VolTableElement_VOL_ID)->text(); + + const bool leVolEstSupprimable = (vueVols->item(ligneSelectionnee, AeroDmsTypes::VolTableElement_SOUMIS_CE)->text() == "Non"); + + + QAction editerLeVol(QIcon("./ressources/airplane-edit.svg"), "Editer le vol", this); + connect(&editerLeVol, SIGNAL(triggered()), this, SLOT(editerVol())); + menuClicDroitVol.addAction(&editerLeVol); + //TODO : pour le moment fonction non disponible : on desactive le bouton + editerLeVol.setEnabled(false); + + QAction supprimerLeVol(QIcon("./ressources/airplane-remove.svg"), "Supprimer le vol", this); + connect(&supprimerLeVol, SIGNAL(triggered()), this, SLOT(supprimerVol())); + menuClicDroitVol.addAction(&supprimerLeVol); + supprimerLeVol.setEnabled(leVolEstSupprimable); + + //Afficher le menu sur la vue des vols + //menuClicDroitVol.exec(vueVols->mapToGlobal(pos)); + menuClicDroitVol.exec(vueVols->mapToGlobal(QCursor::pos())); + } +} + +void AeroDms::editerVol() +{ + //TODO +} + +void AeroDms::supprimerVol() +{ + QMessageBox demandeConfirmationSuppression; + demandeConfirmationSuppression.setText("Voulez vous réellement supprimer le vol ?"); + demandeConfirmationSuppression.setWindowTitle("Suppression d'un vol"); + demandeConfirmationSuppression.setIcon(QMessageBox::Question); + demandeConfirmationSuppression.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + + const int ret = demandeConfirmationSuppression.exec(); + + switch (ret) + { + case QMessageBox::Yes: + { + if (db->supprimerUnVol(volAEditer)) + { + statusBar()->showMessage("Vol supprimé avec succès."); + } + else + { + statusBar()->showMessage("Vol non supprimé : le vol est associé à une recette d'une sortie. Suppression impossible."); + } + peuplerTablePilotes(); + peuplerTableVols(); + } + break; + case QMessageBox::No: + default: + { + //Rien à faire + } + break; + } +} + diff --git a/src/AeroDms.h b/src/AeroDms.h index 31c9ced..8da5c07 100644 --- a/src/AeroDms.h +++ b/src/AeroDms.h @@ -112,6 +112,7 @@ class AeroDms : public QMainWindow //Données internes QString piloteAEditer; + QString volAEditer; int factureIdEnBdd; public slots: @@ -139,6 +140,9 @@ public slots: void aPropos(); void menuContextuelPilotes(const QPoint& pos); void editerPilote(); + void editerVol(); + void supprimerVol(); + void menuContextuelVols(const QPoint& pos); }; diff --git a/src/AeroDmsTypes.h b/src/AeroDmsTypes.h index 79d71b0..349f0b4 100644 --- a/src/AeroDmsTypes.h +++ b/src/AeroDmsTypes.h @@ -50,7 +50,8 @@ class AeroDmsTypes VolTableElement_SUBVENTION = 0x5, VolTableElement_SOUMIS_CE = 0x6, VolTableElement_REMARQUE = 0x7, - VolTableElement_NB_COLONNES = 0x8, + VolTableElement_VOL_ID = 0x8, + VolTableElement_NB_COLONNES = 0x9, }; enum ResultatCreationPilote { @@ -121,6 +122,7 @@ class AeroDmsTypes QString estSoumisCe; float coutVol; float montantRembourse; + int volId; }; typedef QList ListeVols; diff --git a/src/ManageDb.cpp b/src/ManageDb.cpp index 55b441f..ba27d14 100644 --- a/src/ManageDb.cpp +++ b/src/ManageDb.cpp @@ -309,6 +309,7 @@ AeroDmsTypes::ListeVols ManageDb::recupererVols( const int p_annee, vol.prenomPilote = query.value("prenom").toString(); vol.remarque = query.value("remarque").toString(); vol.typeDeVol = query.value("typeDeVol").toString(); + vol.volId = query.value("volId").toInt(); liste.append(vol); } @@ -415,6 +416,24 @@ void ManageDb::enregistrerUnVolSortieOuBalade(const QString& p_piloteId, query.exec(); } +bool ManageDb::supprimerUnVol(const QString p_volAEditer) +{ + QSqlQuery query; + query.prepare("SELECT * 'xAssociationRecette-Vol' WHERE volId = :volId"); + query.bindValue(":volId", p_volAEditer); + query.exec(); + if (query.size() != 0) + { + //Le vol est associé a une recette de sortie : on refuse la suppression + return false; + } + + //Sinon on poursuit + query.prepare("DELETE FROM 'vol' WHERE volId = :volId"); + query.bindValue(":volId", p_volAEditer); + return query.exec(); +} + void ManageDb::enregistrerUneFacture( const QString& p_payeur, const int factureId, const QDate& p_date, diff --git a/src/ManageDb.h b/src/ManageDb.h index e0a7d83..9fc8118 100644 --- a/src/ManageDb.h +++ b/src/ManageDb.h @@ -57,6 +57,7 @@ class ManageDb : public QWidget { const int p_facture, const int p_idSortie, const QString& p_remarque); + bool supprimerUnVol(const QString p_volAEditer); void enregistrerUneFacture( const QString& p_payeur, const int factureId, const QDate& p_date, diff --git a/src/main.cpp b/src/main.cpp index 388f481..fc8ae3c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,6 +22,7 @@ along with this program. If not, see . int main(int argc, char *argv[]) { QApplication a(argc, argv); + AeroDms w; w.show(); return a.exec();