Ajout de boutons pour gerer les collections et elements

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@109 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavierqet
2007-08-28 21:17:11 +00:00
parent 0fb7b02285
commit d3ef7a5f02
17 changed files with 298 additions and 58 deletions

35
elementdeleter.cpp Normal file
View File

@@ -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(".")
);
}
}

22
elementdeleter.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef ELEMENT_DELETER_H
#define ELEMENT_DELETER_H
#include "elementscategory.h"
#include <QtGui>
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

View File

@@ -1,6 +1,7 @@
#include "elementscategorieswidget.h" #include "elementscategorieswidget.h"
#include "elementscategorieslist.h" #include "elementscategorieslist.h"
#include "elementscategoryeditor.h" #include "elementscategoryeditor.h"
#include "elementscategorydeleter.h"
#include "elementscategory.h" #include "elementscategory.h"
/** /**
@@ -13,9 +14,9 @@ ElementsCategoriesWidget::ElementsCategoriesWidget(QWidget *parent) : QWidget(pa
// actions // actions
action_reload = new QAction(QIcon(":/ico/reload.png"), tr("Recharger les cat\351gories"), this); 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_new = new QAction(QIcon(":/ico/category_new.png"), tr("Nouvelle cat\351gorie"), this);
action_open = new QAction(QIcon(":/ico/open.png"), tr("\311diter la cat\351gorie"), this); action_open = new QAction(QIcon(":/ico/category_edit.png"), tr("\311diter la cat\351gorie"), this);
action_delete = new QAction(QIcon(":/ico/editdelete.png"), tr("Supprimer la cat\351gorie"), this); action_delete = new QAction(QIcon(":/ico/category_delete.png"), tr("Supprimer la cat\351gorie"), this);
// initialise la barre d'outils // initialise la barre d'outils
toolbar = new QToolBar(this); toolbar = new QToolBar(this);
@@ -74,46 +75,12 @@ void ElementsCategoriesWidget::editCategory() {
Supprime la categorie selectionnee Supprime la categorie selectionnee
*/ */
void ElementsCategoriesWidget::removeCategory() { void ElementsCategoriesWidget::removeCategory() {
// recupere le nom et le chemin de la categorie // recupere le chemin de la categorie
QString s_c_name = elementscategorieslist -> selectedCategoryName();
QString s_c_path = elementscategorieslist -> selectedCategoryPath(); 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 // supprime la categorie
if (!category.remove()) { ElementsCategoryDeleter cat_deleter(s_c_path, this);
QMessageBox::warning( cat_deleter.exec();
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(".")
);
}
// recharge la liste des categories // recharge la liste des categories
elementscategorieslist -> reload(); elementscategorieslist -> reload();

View File

@@ -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(".")
);
}
}

23
elementscategorydeleter.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef ELEMENTS_CATEGORY_DELETER_H
#define ELEMENTS_CATEGORY_DELETER_H
#include "elementscategory.h"
#include <QtGui>
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

View File

@@ -1,6 +1,8 @@
#include "elementspanel.h" #include "elementspanel.h"
#include "elementscategory.h" #include "elementscategory.h"
#include "elementscategoryeditor.h" #include "elementscategoryeditor.h"
#include "elementscategorydeleter.h"
#include "elementdeleter.h"
#include "customelement.h" #include "customelement.h"
#include "qetelementeditor.h" #include "qetelementeditor.h"
@@ -46,6 +48,20 @@ ElementsPanel::ElementsPanel(QWidget *parent) : QTreeWidget(parent) {
ElementsPanel::~ElementsPanel() { 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 Gere le mouvement lors d'un drag'n drop
*/ */
@@ -167,24 +183,73 @@ void ElementsPanel::reload() {
addDir(invisibleRootItem(), QETApp::customElementsDir(), tr("Collection utilisateur")); addDir(invisibleRootItem(), QETApp::customElementsDir(), tr("Collection utilisateur"));
} }
void ElementsPanel::slot_doubleClick(QTreeWidgetItem *qtwi, int) { void ElementsPanel::editCategory() {
// recupere le fichier ou le dossier correspondant au QTreeWidgetItem QFileInfo infos_file = selectedFile();
QString filename = qtwi -> data(0, 42).toString(); 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 // le fichier doit exister
QFileInfo infos_file(filename); QFileInfo infos_file = selectedFile();
if (!infos_file.exists()) return; if (!infos_file.exists()) return;
if (infos_file.isFile()) { if (infos_file.isFile()) {
// il s'agit d'un element // il s'agit d'un element
launchElementEditor(infos_file.absoluteFilePath());
} else if (infos_file.isDir()) {
// il s'agit d'une categorie
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(); QETElementEditor *editor = new QETElementEditor();
editor -> fromFile(filename); editor -> fromFile(filename);
editor -> show(); editor -> show();
} else if (infos_file.isDir()) { }
// il s'agit d'une categorie
ElementsCategory c(filename); void ElementsPanel::lauchCategoryEditor(const QString &filename) {
ElementsCategoryEditor ece(filename, true); ElementsCategoryEditor ece(filename, true);
if (ece.exec() == QDialog::Accepted) reload(); if (ece.exec() == QDialog::Accepted) reload();
} }
}

View File

@@ -19,9 +19,17 @@ class ElementsPanel : public QTreeWidget {
ElementsPanel(const ElementsPanel &); ElementsPanel(const ElementsPanel &);
// methodes // methodes
public:
bool selectedItemIsAnElement() const;
bool selectedItemIsACategory() const;
private: private:
void addFile(QTreeWidgetItem *, QString); void addFile(QTreeWidgetItem *, QString);
void addDir(QTreeWidgetItem *, QString, QString = QString()); void addDir(QTreeWidgetItem *, QString, QString = QString());
QFileInfo selectedFile() const;
void launchElementEditor(const QString &);
void lauchCategoryEditor(const QString &);
public slots: public slots:
void slot_doubleClick(QTreeWidgetItem *, int); void slot_doubleClick(QTreeWidgetItem *, int);
@@ -29,5 +37,9 @@ class ElementsPanel : public QTreeWidget {
void dropEvent(QDropEvent *); void dropEvent(QDropEvent *);
void startDrag(Qt::DropActions); void startDrag(Qt::DropActions);
void reload(); void reload();
void editCategory();
void editElement();
void deleteCategory();
void deleteElement();
}; };
#endif #endif

View File

@@ -1,6 +1,6 @@
#include "elementspanelwidget.h" #include "elementspanelwidget.h"
#include "newelementwizard.h" #include "newelementwizard.h"
#include "elementscategorieswidget.h"
/** /**
Constructeur Constructeur
@param parent Le QWidget parent de ce widget @param parent Le QWidget parent de ce widget
@@ -9,11 +9,37 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) {
// initalise le panel d'elements // initalise le panel d'elements
elements_panel = new ElementsPanel(this); 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 // initialise la barre d'outils
toolbar = new QToolBar(this); toolbar = new QToolBar(this);
toolbar -> setMovable(false); toolbar -> setMovable(false);
toolbar -> addAction(QIcon(":/ico/reload.png"), tr("Recharger les collections"), elements_panel, SLOT(reload())); toolbar -> addAction(reload);
toolbar -> addAction(QIcon(":/ico/new.png"), tr("Nouvel \351l\351ment"), this, SLOT(newElement())); 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 // disposition verticale
QVBoxLayout *vlayout = new QVBoxLayout(this); QVBoxLayout *vlayout = new QVBoxLayout(this);
@@ -38,3 +64,33 @@ void ElementsPanelWidget::newElement() {
NewElementWizard new_element_wizard; NewElementWizard new_element_wizard;
new_element_wizard.exec(); 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);
}

View File

@@ -22,6 +22,9 @@ class ElementsPanelWidget : public QWidget {
private: private:
ElementsPanel *elements_panel; ElementsPanel *elements_panel;
QToolBar *toolbar; QToolBar *toolbar;
QAction *reload;
QAction *new_category, *edit_category, *delete_category;
QAction *new_element, *edit_element, *delete_element;
// methodes // methodes
public: public:
@@ -29,6 +32,8 @@ class ElementsPanelWidget : public QWidget {
public slots: public slots:
void newElement(); void newElement();
void newCategory();
void updateButtons();
}; };
/** /**

BIN
ico/category_delete.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
ico/category_edit.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
ico/category_new.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
ico/edit.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 686 B

After

Width:  |  Height:  |  Size: 825 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 411 B

After

Width:  |  Height:  |  Size: 523 B

View File

@@ -58,7 +58,9 @@ HEADERS += aboutqet.h \
editor/styleeditor.h \ editor/styleeditor.h \
editor/terminaleditor.h \ editor/terminaleditor.h \
editor/texteditor.h \ editor/texteditor.h \
editor/textfieldeditor.h editor/textfieldeditor.h \
elementscategorydeleter.h \
elementdeleter.h
SOURCES += aboutqet.cpp \ SOURCES += aboutqet.cpp \
borderinset.cpp \ borderinset.cpp \
conducer.cpp \ conducer.cpp \
@@ -110,8 +112,10 @@ SOURCES += aboutqet.cpp \
editor/styleeditor.cpp \ editor/styleeditor.cpp \
editor/terminaleditor.cpp \ editor/terminaleditor.cpp \
editor/texteditor.cpp \ editor/texteditor.cpp \
editor/textfieldeditor.cpp editor/textfieldeditor.cpp \
elementscategorydeleter.cpp \
elementdeleter.cpp
RESOURCES += qelectrotech.qrc RESOURCES += qelectrotech.qrc
TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts
QT += xml QT += xml
CONFIG += release CONFIG += debug_and_release

View File

@@ -8,12 +8,16 @@
<file>ico/arc.png</file> <file>ico/arc.png</file>
<file>ico/button_cancel.png</file> <file>ico/button_cancel.png</file>
<file>ico/button_ok.png</file> <file>ico/button_ok.png</file>
<file>ico/category_delete.png</file>
<file>ico/category_edit.png</file>
<file>ico/category_new.png</file>
<file>ico/circle.png</file> <file>ico/circle.png</file>
<file>ico/configure.png</file> <file>ico/configure.png</file>
<file>ico/copy.png</file> <file>ico/copy.png</file>
<file>ico/cut.png</file> <file>ico/cut.png</file>
<file>ico/delete.png</file> <file>ico/delete.png</file>
<file>ico/east.png</file> <file>ico/east.png</file>
<file>ico/edit.png</file>
<file>ico/editdelete.png</file> <file>ico/editdelete.png</file>
<file>ico/ellipse.png</file> <file>ico/ellipse.png</file>
<file>ico/entrer_fs.png</file> <file>ico/entrer_fs.png</file>