2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2015-02-20 14:56:22 +00:00
|
|
|
Copyright 2006-2015 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-08-28 21:17:11 +00:00
|
|
|
#include "elementscategorydeleter.h"
|
2009-04-03 19:30:25 +00:00
|
|
|
#include "qetapp.h"
|
2009-08-09 16:02:14 +00:00
|
|
|
#include "qetmessagebox.h"
|
2007-08-28 21:17:11 +00:00
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
2009-04-03 19:30:25 +00:00
|
|
|
@param category_path Chemin virtuel de la categorie a supprimer
|
2007-10-10 17:50:26 +00:00
|
|
|
@param parent QWidget parent
|
|
|
|
*/
|
2009-04-03 19:30:25 +00:00
|
|
|
ElementsCategoryDeleter::ElementsCategoryDeleter(const ElementsLocation &category_path, QWidget *parent) :
|
2007-08-28 21:17:11 +00:00
|
|
|
QWidget(parent),
|
2009-04-03 19:30:25 +00:00
|
|
|
category(0)
|
2007-08-28 21:17:11 +00:00
|
|
|
{
|
2009-04-03 19:30:25 +00:00
|
|
|
// recupere la categorie a supprimer
|
|
|
|
ElementsCollectionItem *category_item = QETApp::collectionItem(category_path);
|
|
|
|
if (!category_item) return;
|
|
|
|
|
|
|
|
// on exige une collection ou une categorie
|
|
|
|
if (!category_item -> isCollection() && !category_item -> isCategory()) return;
|
|
|
|
|
|
|
|
category = category_item;
|
2007-08-28 21:17:11 +00:00
|
|
|
}
|
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/// Destructeur
|
2007-08-28 21:17:11 +00:00
|
|
|
ElementsCategoryDeleter::~ElementsCategoryDeleter() {
|
|
|
|
}
|
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/**
|
|
|
|
Supprime la categorie et ses elements : verifie l'existence du dossier,
|
|
|
|
demande deux fois confirmation a l'utilisateur et avertit ce dernier si la
|
|
|
|
suppression a echoue.
|
2009-04-03 19:30:25 +00:00
|
|
|
@return true si la suppression a ete effectuee, false sinon
|
2007-10-10 17:50:26 +00:00
|
|
|
*/
|
2009-04-03 19:30:25 +00:00
|
|
|
bool ElementsCategoryDeleter::exec() {
|
2007-08-28 21:17:11 +00:00
|
|
|
// verifie l'existence de la categorie
|
2009-04-03 19:30:25 +00:00
|
|
|
if (!category) return(false);
|
2007-08-28 21:17:11 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// gere le cas ou la suppression d'une collection est demandee
|
|
|
|
if (category -> isCollection()) {
|
2009-08-09 16:02:14 +00:00
|
|
|
QMessageBox::StandardButton answer_0 = QET::MessageBox::question(
|
2009-04-03 19:30:25 +00:00
|
|
|
this,
|
|
|
|
tr("Vider la collection ?", "message box title"),
|
|
|
|
tr("\312tes-vous s\373r de vouloir vider cette collection ?", "message box content"),
|
|
|
|
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel
|
|
|
|
);
|
|
|
|
if (answer_0 != QMessageBox::Yes) return(false);
|
|
|
|
}
|
2007-12-23 01:15:16 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
|
|
|
@todo Regression : rafficher le nom de la categorie supprimee
|
|
|
|
*/
|
|
|
|
// QString cat_name(category -> name().replace("<", "<").replace(">", ">"));
|
|
|
|
|
|
|
|
|
|
|
|
// avertissement pour la suppression d'une collection
|
2007-08-28 21:17:11 +00:00
|
|
|
// confirmation #1
|
2009-08-09 16:02:14 +00:00
|
|
|
QMessageBox::StandardButton answer_1 = QET::MessageBox::question(
|
2007-08-28 21:17:11 +00:00
|
|
|
this,
|
2009-04-03 19:30:25 +00:00
|
|
|
tr("Supprimer la cat\351gorie ?", "message box title"),
|
|
|
|
tr(
|
|
|
|
"\312tes-vous s\373r de vouloir supprimer la cat\351gorie ?\nTous "
|
|
|
|
"les \351l\351ments et les cat\351gories contenus dans cette "
|
|
|
|
"cat\351gorie seront supprim\351s.",
|
|
|
|
"message box content"
|
|
|
|
),
|
|
|
|
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel
|
2007-08-28 21:17:11 +00:00
|
|
|
);
|
2009-04-03 19:30:25 +00:00
|
|
|
if (answer_1 != QMessageBox::Yes) return(false);
|
2007-08-28 21:17:11 +00:00
|
|
|
|
|
|
|
// confirmation #2
|
2009-08-09 16:02:14 +00:00
|
|
|
QMessageBox::StandardButton answer_2 = QET::MessageBox::question(
|
2007-08-28 21:17:11 +00:00
|
|
|
this,
|
2009-04-03 19:30:25 +00:00
|
|
|
tr("Supprimer la cat\351gorie ?", "message box title"),
|
|
|
|
tr(
|
|
|
|
"\312tes-vous vraiment s\373r de vouloir supprimer cette "
|
|
|
|
"cat\351gorie ?\nLes changements seront d\351finitifs.",
|
|
|
|
"message box content"
|
|
|
|
),
|
2007-08-28 21:17:11 +00:00
|
|
|
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel
|
|
|
|
);
|
2009-04-03 19:30:25 +00:00
|
|
|
if (answer_2 != QMessageBox::Yes) return(false);
|
2007-08-28 21:17:11 +00:00
|
|
|
|
|
|
|
// supprime la categorie
|
2009-04-03 19:30:25 +00:00
|
|
|
if (!category -> remove()) {
|
2009-08-09 16:02:14 +00:00
|
|
|
QET::MessageBox::warning(
|
2007-08-28 21:17:11 +00:00
|
|
|
this,
|
2009-04-03 19:30:25 +00:00
|
|
|
tr("Suppression de la cat\351gorie", "message box title"),
|
|
|
|
tr("La suppression de la cat\351gorie a \351chou\351.", "message box content")
|
2007-08-28 21:17:11 +00:00
|
|
|
);
|
2009-04-03 19:30:25 +00:00
|
|
|
return(false);
|
2007-08-28 21:17:11 +00:00
|
|
|
}
|
2009-04-03 19:30:25 +00:00
|
|
|
|
|
|
|
return(true);
|
2007-08-28 21:17:11 +00:00
|
|
|
}
|