mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Rapatriement de la branche 0.2 dans le trunk
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@558 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2006-2008 Xavier Guerrin
|
||||
Copyright 2006-2009 Xavier Guerrin
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
@@ -16,9 +16,12 @@
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "elementscategoryeditor.h"
|
||||
#include "elementscollection.h"
|
||||
#include "elementscategory.h"
|
||||
#include "nameslistwidget.h"
|
||||
#include "qet.h"
|
||||
#include "qetapp.h"
|
||||
#include "qfilenameedit.h"
|
||||
|
||||
/**
|
||||
Constructeur fournissant un dialogue d'edition de categorie.
|
||||
@@ -26,36 +29,55 @@
|
||||
@param edit booleen a true pour le mode edition, a false pour le mode creation
|
||||
@param parent QWidget parent du dialogue
|
||||
*/
|
||||
ElementsCategoryEditor::ElementsCategoryEditor(const QString &category_path, bool edit, QWidget *parent) : QDialog(parent) {
|
||||
mode_edit = edit;
|
||||
ElementsCategoryEditor::ElementsCategoryEditor(const ElementsLocation &category_path, bool edit, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
mode_edit(edit)
|
||||
{
|
||||
// dialogue basique
|
||||
buildDialog();
|
||||
category = new ElementsCategory(category_path);
|
||||
|
||||
// recupere la categorie a editer
|
||||
ElementsCollectionItem *category_item = QETApp::collectionItem(category_path);
|
||||
if (category_item) category_item = category_item -> toCategory();
|
||||
|
||||
if (!category_item || !category_item -> isCategory()) {
|
||||
QMessageBox::warning(
|
||||
this,
|
||||
tr("Cat\351gorie inexistante", "message box title"),
|
||||
tr("La cat\351gorie demand\351e n'existe pas. Abandon.", "message box content")
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
category = category_item -> toPureCategory();
|
||||
}
|
||||
|
||||
if (mode_edit) {
|
||||
setWindowTitle(tr("\311diter une cat\351gorie"));
|
||||
setWindowTitle(tr("\311diter une cat\351gorie", "window title"));
|
||||
connect(buttons, SIGNAL(accepted()), this, SLOT(acceptUpdate()));
|
||||
|
||||
// edition de categorie = affichage des noms deja existants
|
||||
names_list -> setNames(category -> categoryNames());
|
||||
internal_name_ -> setText(category -> pathName());
|
||||
internal_name_ -> setReadOnly(true);
|
||||
} else {
|
||||
setWindowTitle(tr("Cr\351er une nouvelle cat\351gorie"));
|
||||
setWindowTitle(tr("Cr\351er une nouvelle cat\351gorie", "window title"));
|
||||
connect(buttons, SIGNAL(accepted()), this, SLOT(acceptCreation()));
|
||||
|
||||
// nouvelle categorie = une ligne pre-machee
|
||||
NamesList cat_names;
|
||||
cat_names.addName(QLocale::system().name().left(2), tr("Nom de la nouvelle cat\351gorie"));
|
||||
cat_names.addName(QLocale::system().name().left(2), tr("Nom de la nouvelle cat\351gorie", "default name when creating a new category"));
|
||||
names_list -> setNames(cat_names);
|
||||
//names_list -> openPersistentEditor(qtwi, 1);
|
||||
}
|
||||
|
||||
// gestion de la lecture seule
|
||||
if (!category -> isWritable()) {
|
||||
QMessageBox::warning(
|
||||
this,
|
||||
tr("\311dition en lecture seule"),
|
||||
tr("Vous n'avez pas les privil\350ges n\351cessaires pour modifier cette cat\351gorie. Elle sera donc ouverte en lecture seule.")
|
||||
tr("\311dition en lecture seule", "message box title"),
|
||||
tr("Vous n'avez pas les privil\350ges n\351cessaires pour modifier cette cat\351gorie. Elle sera donc ouverte en lecture seule.", "message box content")
|
||||
);
|
||||
names_list -> setReadOnly(true);
|
||||
internal_name_ -> setReadOnly(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +85,6 @@ ElementsCategoryEditor::ElementsCategoryEditor(const QString &category_path, boo
|
||||
Destructeur
|
||||
*/
|
||||
ElementsCategoryEditor::~ElementsCategoryEditor() {
|
||||
delete category;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,10 +95,17 @@ void ElementsCategoryEditor::buildDialog() {
|
||||
setLayout(editor_layout);
|
||||
|
||||
names_list = new NamesListWidget();
|
||||
internal_name_label_ = new QLabel(tr("Nom interne : "));
|
||||
internal_name_ = new QFileNameEdit();
|
||||
|
||||
buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QHBoxLayout *internal_name_layout = new QHBoxLayout();
|
||||
internal_name_layout -> addWidget(internal_name_label_);
|
||||
internal_name_layout -> addWidget(internal_name_);
|
||||
|
||||
editor_layout -> addLayout(internal_name_layout);
|
||||
editor_layout -> addWidget(new QLabel(tr("Vous pouvez sp\351cifier un nom par langue pour la cat\351gorie.")));
|
||||
editor_layout -> addWidget(names_list);
|
||||
editor_layout -> addWidget(buttons);
|
||||
@@ -93,18 +121,57 @@ void ElementsCategoryEditor::acceptCreation() {
|
||||
// il doit y avoir au moins un nom
|
||||
if (!names_list -> checkOneName()) return;
|
||||
|
||||
// chargement des noms
|
||||
category -> clearNames();
|
||||
NamesList names = names_list -> names();
|
||||
foreach(QString lang, names.langs()) {
|
||||
category -> addName(lang, names[lang]);
|
||||
// exige un nom de dossier de la part de l'utilisateur
|
||||
if (!internal_name_ -> isValid()) {
|
||||
QMessageBox::critical(
|
||||
this,
|
||||
tr("Nom interne manquant", "message box title"),
|
||||
tr("Vous devez sp\351cifier un nom interne.", "message box content")
|
||||
);
|
||||
return;
|
||||
}
|
||||
QString dirname = internal_name_ -> text();
|
||||
|
||||
// verifie que le nom interne n'est pas deja pris
|
||||
if (category -> category(dirname)) {
|
||||
QMessageBox::critical(
|
||||
this,
|
||||
tr("Nom interne d\351j\340 utilis\351", "message box title"),
|
||||
tr(
|
||||
"Le nom interne que vous avez choisi est d\351j\340 utilis\351 "
|
||||
"par une cat\351gorie existante. Veuillez en choisir un autre.",
|
||||
"message box content"
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// cree un nom de dossier a partir du 1er nom de la categorie
|
||||
QString dirname = names[names.langs().first()].toLower().replace(" ", "_");
|
||||
foreach(QChar c, QET::forbiddenCharacters()) dirname = dirname.replace(c, "_");
|
||||
category -> setPath(category -> path() + "/" + dirname);
|
||||
category -> write();
|
||||
// cree la nouvelle categorie
|
||||
ElementsCategory *new_category = category -> createCategory(dirname);
|
||||
if (!new_category) {
|
||||
QMessageBox::critical(
|
||||
this,
|
||||
tr("Erreur", "message box title"),
|
||||
tr("Impossible de cr\351er la cat\351gorie", "message box content")
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// chargement des noms
|
||||
NamesList names = names_list -> names();
|
||||
foreach(QString lang, names.langs()) {
|
||||
new_category -> addName(lang, names[lang]);
|
||||
}
|
||||
|
||||
// ecriture de la
|
||||
if (!new_category -> write()) {
|
||||
QMessageBox::critical(
|
||||
this,
|
||||
tr("Erreur", "message box title"),
|
||||
tr("Impossible d'enregistrer la cat\351gorie", "message box content")
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
@@ -114,6 +181,7 @@ void ElementsCategoryEditor::acceptCreation() {
|
||||
categorie
|
||||
*/
|
||||
void ElementsCategoryEditor::acceptUpdate() {
|
||||
|
||||
if (!category -> isWritable()) QDialog::accept();
|
||||
|
||||
// il doit y avoir au moins un nom
|
||||
|
||||
Reference in New Issue
Block a user