diff --git a/elementdeleter.cpp b/elementdeleter.cpp new file mode 100644 index 000000000..f10e69ee4 --- /dev/null +++ b/elementdeleter.cpp @@ -0,0 +1,35 @@ +#include "elementdeleter.h" + +ElementDeleter::ElementDeleter(const QString &elmt_path, QWidget *parent) : + QWidget(parent), + element_path(elmt_path) +{ +} + +ElementDeleter::~ElementDeleter() { +} + +void ElementDeleter::exec() { + // verifie l'existence de l'element + QFile elmt_file(element_path); + if (!elmt_file.exists()) return; + + // confirmation #1 + QMessageBox::StandardButton answer_1 = QMessageBox::question( + this, + tr("Supprimer l'\351l\351ment ?"), + tr("\312tes-vous s\373r de vouloir supprimer cet \351l\351ment ?\n"), + QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel + ); + if (answer_1 != QMessageBox::Yes) return; + + // supprime l'element + if (!elmt_file.remove()) { + QMessageBox::warning( + this, + tr("Suppression de l'\351l\351ment"), + tr("La suppression de l'\351l\351ment a \351chou\351.\n" + "V\351rifiez vos droits sur le fichier ") + element_path + tr(".") + ); + } +} diff --git a/elementdeleter.h b/elementdeleter.h new file mode 100644 index 000000000..192e819c1 --- /dev/null +++ b/elementdeleter.h @@ -0,0 +1,22 @@ +#ifndef ELEMENT_DELETER_H +#define ELEMENT_DELETER_H +#include "elementscategory.h" +#include +class ElementDeleter : public QWidget { + Q_OBJECT + // constructeurs, destructeur + public: + ElementDeleter(const QString &, QWidget * = 0); + virtual ~ElementDeleter(); + private: + ElementDeleter(const ElementsCategory &); + + // methodes + public slots: + void exec(); + + // attributs + private: + QString element_path; +}; +#endif diff --git a/elementscategorieswidget.cpp b/elementscategorieswidget.cpp index 373c824e9..dd46094f2 100644 --- a/elementscategorieswidget.cpp +++ b/elementscategorieswidget.cpp @@ -1,6 +1,7 @@ #include "elementscategorieswidget.h" #include "elementscategorieslist.h" #include "elementscategoryeditor.h" +#include "elementscategorydeleter.h" #include "elementscategory.h" /** @@ -12,10 +13,10 @@ ElementsCategoriesWidget::ElementsCategoriesWidget(QWidget *parent) : QWidget(pa elementscategorieslist = new ElementsCategoriesList(this); // actions - action_reload = new QAction(QIcon(":/ico/reload.png"), tr("Recharger les cat\351gories"), this); - action_new = new QAction(QIcon(":/ico/new.png"), tr("Nouvelle cat\351gorie"), this); - action_open = new QAction(QIcon(":/ico/open.png"), tr("\311diter la cat\351gorie"), this); - action_delete = new QAction(QIcon(":/ico/editdelete.png"), tr("Supprimer la cat\351gorie"), this); + action_reload = new QAction(QIcon(":/ico/reload.png"), tr("Recharger les cat\351gories"), this); + action_new = new QAction(QIcon(":/ico/category_new.png"), tr("Nouvelle cat\351gorie"), this); + action_open = new QAction(QIcon(":/ico/category_edit.png"), tr("\311diter la cat\351gorie"), this); + action_delete = new QAction(QIcon(":/ico/category_delete.png"), tr("Supprimer la cat\351gorie"), this); // initialise la barre d'outils toolbar = new QToolBar(this); @@ -74,46 +75,12 @@ void ElementsCategoriesWidget::editCategory() { Supprime la categorie selectionnee */ void ElementsCategoriesWidget::removeCategory() { - // recupere le nom et le chemin de la categorie - QString s_c_name = elementscategorieslist -> selectedCategoryName(); + // recupere le chemin de la categorie QString s_c_path = elementscategorieslist -> selectedCategoryPath(); - if (s_c_path.isNull()) return; - - // confirmation #1 - QMessageBox::StandardButton answer_1 = QMessageBox::question( - this, - tr("Supprimer la cat\351gorie ?"), - tr("\312tes-vous s\373r de vouloir supprimer cette cat\351gorie ?\n" - "Tous les \351l\351ments et les cat\351gories contenus dans cette " - "cat\351gorie seront supprim\351s"), - QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel - ); - if (answer_1 != QMessageBox::Yes) return; - - // confirmation #2 - QMessageBox::StandardButton answer_2 = QMessageBox::question( - this, - tr("Supprimer la cat\351gorie ?"), - tr("\312tes-vous vraiment s\373r de vouloir supprimer cette " - "cat\351gorie ?\nLes changements seront d\351finitifs."), - QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel - ); - if (answer_2 != QMessageBox::Yes) return; - - // verifie l'existence de la categorie - ElementsCategory category(s_c_path); - if (!category.exists()) return; - // supprime la categorie - if (!category.remove()) { - QMessageBox::warning( - this, - tr("Suppression de la cat\351gorie"), - tr("La suppression de la cat\351gorie a \351chou\351.\n" - "V\351rifiez vos droits sur le dossier ") + s_c_path + tr(".") - ); - } + ElementsCategoryDeleter cat_deleter(s_c_path, this); + cat_deleter.exec(); // recharge la liste des categories elementscategorieslist -> reload(); diff --git a/elementscategorydeleter.cpp b/elementscategorydeleter.cpp new file mode 100644 index 000000000..19adfbce5 --- /dev/null +++ b/elementscategorydeleter.cpp @@ -0,0 +1,47 @@ +#include "elementscategorydeleter.h" + +ElementsCategoryDeleter::ElementsCategoryDeleter(const QString &category_path, QWidget *parent) : + QWidget(parent), + cat(category_path), + empty_category_path(category_path.isNull()) +{ +} + +ElementsCategoryDeleter::~ElementsCategoryDeleter() { +} + +void ElementsCategoryDeleter::exec() { + // verifie l'existence de la categorie + if (!cat.exists() || empty_category_path) return; + + // confirmation #1 + QMessageBox::StandardButton answer_1 = QMessageBox::question( + this, + tr("Supprimer la cat\351gorie ?"), + tr("\312tes-vous s\373r de vouloir supprimer cette cat\351gorie ?\n" + "Tous les \351l\351ments et les cat\351gories contenus dans cette " + "cat\351gorie seront supprim\351s"), + QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel + ); + if (answer_1 != QMessageBox::Yes) return; + + // confirmation #2 + QMessageBox::StandardButton answer_2 = QMessageBox::question( + this, + tr("Supprimer la cat\351gorie ?"), + tr("\312tes-vous vraiment s\373r de vouloir supprimer cette " + "cat\351gorie ?\nLes changements seront d\351finitifs."), + QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel + ); + if (answer_2 != QMessageBox::Yes) return; + + // supprime la categorie + if (!cat.remove()) { + QMessageBox::warning( + this, + tr("Suppression de la cat\351gorie"), + tr("La suppression de la cat\351gorie a \351chou\351.\n" + "V\351rifiez vos droits sur le dossier ") + cat.absolutePath() + tr(".") + ); + } +} diff --git a/elementscategorydeleter.h b/elementscategorydeleter.h new file mode 100644 index 000000000..663d1758d --- /dev/null +++ b/elementscategorydeleter.h @@ -0,0 +1,23 @@ +#ifndef ELEMENTS_CATEGORY_DELETER_H +#define ELEMENTS_CATEGORY_DELETER_H +#include "elementscategory.h" +#include +class ElementsCategoryDeleter : public QWidget { + Q_OBJECT + // constructeurs, destructeur + public: + ElementsCategoryDeleter(const QString &, QWidget * = 0); + virtual ~ElementsCategoryDeleter(); + private: + ElementsCategoryDeleter(const ElementsCategory &); + + // methodes + public slots: + void exec(); + + // attributs + private: + ElementsCategory cat; + bool empty_category_path; +}; +#endif diff --git a/elementspanel.cpp b/elementspanel.cpp index 7c9e4aa05..c0647b39f 100644 --- a/elementspanel.cpp +++ b/elementspanel.cpp @@ -1,6 +1,8 @@ #include "elementspanel.h" #include "elementscategory.h" #include "elementscategoryeditor.h" +#include "elementscategorydeleter.h" +#include "elementdeleter.h" #include "customelement.h" #include "qetelementeditor.h" @@ -46,6 +48,20 @@ ElementsPanel::ElementsPanel(QWidget *parent) : QTreeWidget(parent) { ElementsPanel::~ElementsPanel() { } +/// @return true si un element est selectionne, false sinon +bool ElementsPanel::selectedItemIsAnElement() const { + QFileInfo infos_file = selectedFile(); + if (!infos_file.exists()) return(false); + return(infos_file.isFile()); +} + +/// @return true si une categorie est selectionnee, false sinon +bool ElementsPanel::selectedItemIsACategory() const { + QFileInfo infos_file = selectedFile(); + if (!infos_file.exists()) return(false); + return(infos_file.isDir()); +} + /** Gere le mouvement lors d'un drag'n drop */ @@ -167,24 +183,73 @@ void ElementsPanel::reload() { addDir(invisibleRootItem(), QETApp::customElementsDir(), tr("Collection utilisateur")); } -void ElementsPanel::slot_doubleClick(QTreeWidgetItem *qtwi, int) { - // recupere le fichier ou le dossier correspondant au QTreeWidgetItem - QString filename = qtwi -> data(0, 42).toString(); +void ElementsPanel::editCategory() { + QFileInfo infos_file = selectedFile(); + if (!infos_file.exists() || !infos_file.isDir()) return; + lauchCategoryEditor(infos_file.absoluteFilePath()); +} + +void ElementsPanel::editElement() { + QFileInfo infos_file = selectedFile(); + if (!infos_file.exists() || !infos_file.isFile()) return; + launchElementEditor(infos_file.absoluteFilePath()); +} + +void ElementsPanel::deleteCategory() { + QFileInfo infos_file = selectedFile(); + if (!infos_file.exists() || !infos_file.isDir()) return; + // supprime la categorie + ElementsCategoryDeleter cat_deleter(infos_file.absoluteFilePath(), this); + cat_deleter.exec(); + + // recharge la liste des categories + reload(); +} + +/** + supprime l'element selectionne +*/ +void ElementsPanel::deleteElement() { + QFileInfo infos_file = selectedFile(); + if (!infos_file.exists() || !infos_file.isFile()) return; + + // supprime l'element + ElementDeleter elmt_deleter(infos_file.absoluteFilePath(), this); + elmt_deleter.exec(); + + // recharge la liste des categories + reload(); +} + +void ElementsPanel::slot_doubleClick(QTreeWidgetItem *, int) { // le fichier doit exister - QFileInfo infos_file(filename); + QFileInfo infos_file = selectedFile(); if (!infos_file.exists()) return; - if (infos_file.isFile()) { // il s'agit d'un element - QETElementEditor *editor = new QETElementEditor(); - editor -> fromFile(filename); - editor -> show(); + launchElementEditor(infos_file.absoluteFilePath()); } else if (infos_file.isDir()) { // il s'agit d'une categorie - ElementsCategory c(filename); - ElementsCategoryEditor ece(filename, true); - if (ece.exec() == QDialog::Accepted) reload(); + lauchCategoryEditor(infos_file.absoluteFilePath()); } } + +/// @return un QFileInfo decrivant le fichier ou le dossier correspondant au QTreeWidgetItem selectionne +QFileInfo ElementsPanel::selectedFile() const { + QTreeWidgetItem *current_qtwi = currentItem(); + if(!current_qtwi) return(QFileInfo()); + return(QFileInfo(currentItem() -> data(0, 42).toString())); +} + +void ElementsPanel::launchElementEditor(const QString &filename) { + QETElementEditor *editor = new QETElementEditor(); + editor -> fromFile(filename); + editor -> show(); +} + +void ElementsPanel::lauchCategoryEditor(const QString &filename) { + ElementsCategoryEditor ece(filename, true); + if (ece.exec() == QDialog::Accepted) reload(); +} diff --git a/elementspanel.h b/elementspanel.h index c7bb510e9..4af587107 100644 --- a/elementspanel.h +++ b/elementspanel.h @@ -19,9 +19,17 @@ class ElementsPanel : public QTreeWidget { ElementsPanel(const ElementsPanel &); // methodes + public: + bool selectedItemIsAnElement() const; + bool selectedItemIsACategory() const; + private: void addFile(QTreeWidgetItem *, QString); void addDir(QTreeWidgetItem *, QString, QString = QString()); + QFileInfo selectedFile() const; + void launchElementEditor(const QString &); + void lauchCategoryEditor(const QString &); + public slots: void slot_doubleClick(QTreeWidgetItem *, int); @@ -29,5 +37,9 @@ class ElementsPanel : public QTreeWidget { void dropEvent(QDropEvent *); void startDrag(Qt::DropActions); void reload(); + void editCategory(); + void editElement(); + void deleteCategory(); + void deleteElement(); }; #endif diff --git a/elementspanelwidget.cpp b/elementspanelwidget.cpp index 37df6a2e3..2706a4d66 100644 --- a/elementspanelwidget.cpp +++ b/elementspanelwidget.cpp @@ -1,6 +1,6 @@ #include "elementspanelwidget.h" #include "newelementwizard.h" - +#include "elementscategorieswidget.h" /** Constructeur @param parent Le QWidget parent de ce widget @@ -9,11 +9,37 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) { // initalise le panel d'elements elements_panel = new ElementsPanel(this); + // initialise les actions + reload = new QAction(QIcon(":/ico/reload.png"), tr("Recharger les collections"), this); + new_category = new QAction(QIcon(":/ico/category_new.png"), tr("Nouvelle cat\351gorie"), this); + edit_category = new QAction(QIcon(":/ico/category_edit.png"), tr("\311diter la cat\351gorie"), this); + delete_category = new QAction(QIcon(":/ico/category_delete.png"), tr("Supprimer la cat\351gorie"), this); + new_element = new QAction(QIcon(":/ico/new.png"), tr("Nouvel \351l\351ment"), this); + edit_element = new QAction(QIcon(":/ico/edit.png"), tr("\311diter l'\351l\351ment"), this); + delete_element = new QAction(QIcon(":/ico/delete.png"), tr("Supprimer l'\351l\351ment"), this); + + connect(reload, SIGNAL(triggered()), elements_panel, SLOT(reload())); + connect(new_category, SIGNAL(triggered()), this, SLOT(newCategory())); + connect(edit_category, SIGNAL(triggered()), elements_panel, SLOT(editCategory())); + connect(delete_category, SIGNAL(triggered()), elements_panel, SLOT(deleteCategory())); + connect(new_element, SIGNAL(triggered()), this, SLOT(newElement())); + connect(edit_element, SIGNAL(triggered()), elements_panel, SLOT(editElement())); + connect(delete_element, SIGNAL(triggered()), elements_panel, SLOT(deleteElement())); + + connect(elements_panel, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(updateButtons())); + // initialise la barre d'outils toolbar = new QToolBar(this); toolbar -> setMovable(false); - toolbar -> addAction(QIcon(":/ico/reload.png"), tr("Recharger les collections"), elements_panel, SLOT(reload())); - toolbar -> addAction(QIcon(":/ico/new.png"), tr("Nouvel \351l\351ment"), this, SLOT(newElement())); + toolbar -> addAction(reload); + toolbar -> addSeparator(); + toolbar -> addAction(new_category); + toolbar -> addAction(edit_category); + toolbar -> addAction(delete_category); + toolbar -> addSeparator(); + toolbar -> addAction(new_element); + toolbar -> addAction(edit_element); + toolbar -> addAction(delete_element); // disposition verticale QVBoxLayout *vlayout = new QVBoxLayout(this); @@ -38,3 +64,33 @@ void ElementsPanelWidget::newElement() { NewElementWizard new_element_wizard; new_element_wizard.exec(); } + +void ElementsPanelWidget::newCategory() { + QDialog new_category_dialog; + new_category_dialog.setFixedSize(480, 280); + new_category_dialog.setWindowTitle(tr("Gestionnaire de cat\351gories")); + + QVBoxLayout *layout = new QVBoxLayout(&new_category_dialog); + QLabel *explication = new QLabel(tr("Vous pouvez utiliser ce gestionnaire pour ajouter, supprimer ou modifier les cat\351gories.")); + explication -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter); + explication -> setWordWrap(true); + layout -> addWidget(explication); + + layout -> addWidget(new ElementsCategoriesWidget()); + + QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close); + connect(buttons, SIGNAL(rejected()), &new_category_dialog, SLOT(accept())); + layout -> addWidget(buttons); + + new_category_dialog.exec(); + elements_panel -> reload(); +} + +void ElementsPanelWidget::updateButtons() { + bool category_selected = elements_panel -> selectedItemIsACategory(); + bool element_selected = elements_panel -> selectedItemIsAnElement(); + edit_category -> setEnabled(category_selected); + delete_category -> setEnabled(category_selected); + edit_element -> setEnabled(element_selected); + delete_element -> setEnabled(element_selected); +} diff --git a/elementspanelwidget.h b/elementspanelwidget.h index 384caaef7..b483617a9 100644 --- a/elementspanelwidget.h +++ b/elementspanelwidget.h @@ -22,6 +22,9 @@ class ElementsPanelWidget : public QWidget { private: ElementsPanel *elements_panel; QToolBar *toolbar; + QAction *reload; + QAction *new_category, *edit_category, *delete_category; + QAction *new_element, *edit_element, *delete_element; // methodes public: @@ -29,6 +32,8 @@ class ElementsPanelWidget : public QWidget { public slots: void newElement(); + void newCategory(); + void updateButtons(); }; /** diff --git a/ico/category_delete.png b/ico/category_delete.png new file mode 100755 index 000000000..cebff9233 Binary files /dev/null and b/ico/category_delete.png differ diff --git a/ico/category_edit.png b/ico/category_edit.png new file mode 100755 index 000000000..a204425da Binary files /dev/null and b/ico/category_edit.png differ diff --git a/ico/category_new.png b/ico/category_new.png new file mode 100755 index 000000000..1277281fc Binary files /dev/null and b/ico/category_new.png differ diff --git a/ico/edit.png b/ico/edit.png new file mode 100755 index 000000000..ce8b22671 Binary files /dev/null and b/ico/edit.png differ diff --git a/ico/new.png b/ico/new.png index 84c407153..004ca033e 100644 Binary files a/ico/new.png and b/ico/new.png differ diff --git a/ico/select.png b/ico/select.png index 06fa1aa75..22dfe6963 100644 Binary files a/ico/select.png and b/ico/select.png differ diff --git a/qelectrotech.pro b/qelectrotech.pro index 1f1269902..69eb34db1 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -58,7 +58,9 @@ HEADERS += aboutqet.h \ editor/styleeditor.h \ editor/terminaleditor.h \ editor/texteditor.h \ - editor/textfieldeditor.h + editor/textfieldeditor.h \ + elementscategorydeleter.h \ + elementdeleter.h SOURCES += aboutqet.cpp \ borderinset.cpp \ conducer.cpp \ @@ -110,8 +112,10 @@ SOURCES += aboutqet.cpp \ editor/styleeditor.cpp \ editor/terminaleditor.cpp \ editor/texteditor.cpp \ - editor/textfieldeditor.cpp + editor/textfieldeditor.cpp \ + elementscategorydeleter.cpp \ + elementdeleter.cpp RESOURCES += qelectrotech.qrc TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts QT += xml -CONFIG += release +CONFIG += debug_and_release diff --git a/qelectrotech.qrc b/qelectrotech.qrc index 803f06186..67b1ed701 100644 --- a/qelectrotech.qrc +++ b/qelectrotech.qrc @@ -8,12 +8,16 @@ ico/arc.png ico/button_cancel.png ico/button_ok.png + ico/category_delete.png + ico/category_edit.png + ico/category_new.png ico/circle.png ico/configure.png ico/copy.png ico/cut.png ico/delete.png ico/east.png + ico/edit.png ico/editdelete.png ico/ellipse.png ico/entrer_fs.png