Skip to content

Commit

Permalink
Ajout de la fonction de suppression de vol
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cvermot committed Jan 9, 2024
1 parent af826b1 commit 0e3f348
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 7 deletions.
3 changes: 2 additions & 1 deletion database/structure.sql
Original file line number Diff line number Diff line change
@@ -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
--
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions ressources/airplane-edit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ressources/airplane-remove.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 83 additions & 5 deletions src/AeroDms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -398,6 +402,7 @@ AeroDms::AeroDms(QWidget* parent):QMainWindow(parent)

//========================Initialisation des autres attributs
piloteAEditer = "";
volAEditer = "";
factureIdEnBdd = 0;

peuplerListesPilotes();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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()));
}
}

Expand All @@ -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;
}
}

4 changes: 4 additions & 0 deletions src/AeroDms.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class AeroDms : public QMainWindow

//Données internes
QString piloteAEditer;
QString volAEditer;
int factureIdEnBdd;

public slots:
Expand Down Expand Up @@ -139,6 +140,9 @@ public slots:
void aPropos();
void menuContextuelPilotes(const QPoint& pos);
void editerPilote();
void editerVol();
void supprimerVol();
void menuContextuelVols(const QPoint& pos);


};
Expand Down
4 changes: 3 additions & 1 deletion src/AeroDmsTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -121,6 +122,7 @@ class AeroDmsTypes
QString estSoumisCe;
float coutVol;
float montantRembourse;
int volId;
};
typedef QList<Vol> ListeVols;

Expand Down
19 changes: 19 additions & 0 deletions src/ManageDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/ManageDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);

AeroDms w;
w.show();
return a.exec();
Expand Down

0 comments on commit 0e3f348

Please sign in to comment.