git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@80 bfdf4180-ca20-0410-9c96-a3a8aa849046

This commit is contained in:
xavierqet
2007-04-05 18:02:40 +00:00
parent 0347680f03
commit df322aeeaf
4 changed files with 89 additions and 17 deletions

View File

@@ -58,11 +58,15 @@ void ElementsCategoryEditor::buildDialog() {
headers << tr("Langue") << tr("Nom");
category_names -> setHeaderLabels(headers);
button_add_line = new QPushButton(tr("Ajouter une ligne"));
connect(button_add_line, SIGNAL(released()), this, SLOT(addLine()));
buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
editor_layout -> addWidget(new QLabel(tr("Vous pouvez sp\351cifier un nom par langue pour la cat\351gorie.")));
editor_layout -> addWidget(category_names);
editor_layout -> addWidget(button_add_line);
editor_layout -> addWidget(buttons);
}
@@ -72,22 +76,15 @@ void ElementsCategoryEditor::buildDialog() {
*/
void ElementsCategoryEditor::acceptCreation() {
// il doit y avoir au moins un nom
int names_count = category_names -> topLevelItemCount();
if (!names_count || (category_names -> topLevelItem(0) -> text(1)) == QString()) {
QMessageBox::critical(
this,
tr("La cat\351gorie doit avoir au moins un nom."),
tr("Vous devez entrer au moins un nom pour la cat\351gorie.")
);
}
if (!checkOneName()) return;
// chargement des noms
category -> clearNames();
int names_count = category_names -> topLevelItemCount();
for (int i = 0 ; i < names_count ; ++ i) {
category -> addName(
category_names -> topLevelItem(i) -> text(0),
category_names -> topLevelItem(i) -> text(1)
);
QString lang = category_names -> topLevelItem(i) -> text(0);
QString value = category_names -> topLevelItem(i) -> text(1);
if (lang != "" && value != "") category -> addName(lang, value);
}
// cree un nom de dossier a partir du 1er nom de la categorie
@@ -103,5 +100,73 @@ void ElementsCategoryEditor::acceptCreation() {
categorie
*/
void ElementsCategoryEditor::acceptUpdate() {
qDebug() << "acceptUpdate";
// il doit y avoir au moins un nom
if (!checkOneName()) return;
// chargement des noms
category -> clearNames();
int names_count = category_names -> topLevelItemCount();
for (int i = 0 ; i < names_count ; ++ i) {
QString lang = category_names -> topLevelItem(i) -> text(0);
QString value = category_names -> topLevelItem(i) -> text(1);
if (lang != "" && value != "") category -> addName(lang, value);
}
category -> write();
QDialog::accept();
}
/**
Nettoie la liste des noms en enlevant les lignes vides
*/
void ElementsCategoryEditor::clean() {
int names_count = category_names -> topLevelItemCount() - 1;
for (int i = names_count ; i >= 0 ; -- i) {
if (
category_names -> topLevelItem(i) -> text(0) == QString() &&\
category_names -> topLevelItem(i) -> text(1) == QString()
) {
category_names -> takeTopLevelItem(i);
}
}
}
/**
Ajoute une ligne a l'editeur
*/
void ElementsCategoryEditor::addLine() {
clean();
QTreeWidgetItem *qtwi = new QTreeWidgetItem();
qtwi -> setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
category_names -> addTopLevelItem(qtwi);
}
/**
Verifie qu'il y a au moins un nom
*/
bool ElementsCategoryEditor::checkOneName() {
updateHash();
if (!hash_names.size()) {
QMessageBox::critical(
this,
tr("La cat\351gorie doit avoir au moins un nom."),
tr("Vous devez entrer au moins un nom pour la cat\351gorie.")
);
return(false);
}
return(true);
}
/**
Lit les noms valides dans hash_names
*/
void ElementsCategoryEditor::updateHash() {
hash_names.clear();
int names_count = category_names -> topLevelItemCount();
for (int i = 0 ; i < names_count ; ++ i) {
QString lang = category_names -> topLevelItem(i) -> text(0);
QString value = category_names -> topLevelItem(i) -> text(1);
if (lang != "" && value != "") hash_names.insert(lang, value);
}
}

View File

@@ -1,6 +1,10 @@
#ifndef ELEMENTS_CATEGORY_EDITOR_H
#define ELEMENTS_CATEGORY_EDITOR_H
#include <QtGui>
/**
Cette classe permet d'editer une categorie existante ou de creer une
categorie.
*/
class ElementsCategory;
class ElementsCategoryEditor : public QDialog {
Q_OBJECT
@@ -15,13 +19,20 @@ class ElementsCategoryEditor : public QDialog {
QTreeWidget *category_names;
ElementsCategory *category;
QDialogButtonBox *buttons;
QPushButton *button_add_line;
QHash<QString, QString> hash_names;
bool mode_edit;
// methodes
private:
void buildDialog();
void clean();
bool checkOneName();
void updateHash();
public slots:
void acceptCreation();
void acceptUpdate();
void addLine();
};
#endif

View File

@@ -92,10 +92,7 @@ void NewElementWizard::valid() {
case Dimensions:
case Category:
current_state = Dimensions;
button_next -> setText(tr("Suivant"));
}
}

View File

@@ -26,7 +26,6 @@ HEADERS += aboutqet.h \
newelementwizard.h \
qetapp.h \
terminal.h \
ui_export_fichier.h \
elementscategoryeditor.h \
elementscategory.h
SOURCES += aboutqet.cpp \