diff --git a/qelectrotech.pro b/qelectrotech.pro index 3b5342684..6fbf358b3 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -94,7 +94,9 @@ INCLUDEPATH += sources \ sources/autoNum/ui \ sources/ui/configpage \ sources/SearchAndReplace \ - sources/SearchAndReplace/ui + sources/SearchAndReplace/ui \ + sources/NameList \ + sources/NameList/ui # Fichiers sources @@ -117,7 +119,9 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \ $$files(sources/autoNum/ui/*.h) \ $$files(sources/ui/configpage/*.h) \ $$files(sources/SearchAndReplace/*.h) \ - $$files(sources/SearchAndReplace/ui/*.h) + $$files(sources/SearchAndReplace/ui/*.h) \ + $$files(sources/NameList/*.h) \ + $$files(sources/NameList/ui/*.h) SOURCES += $$files(sources/*.cpp) \ $$files(sources/editor/*.cpp) \ @@ -139,7 +143,9 @@ SOURCES += $$files(sources/*.cpp) \ $$files(sources/autoNum/ui/*.cpp) \ $$files(sources/ui/configpage/*.cpp) \ $$files(sources/SearchAndReplace/*.cpp) \ - $$files(sources/SearchAndReplace/ui/*.cpp) + $$files(sources/SearchAndReplace/ui/*.cpp) \ + $$files(sources/NameList/*.cpp) \ + $$files(sources/NameList/ui/*.cpp) # Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt RESOURCES += qelectrotech.qrc @@ -160,7 +166,8 @@ FORMS += $$files(sources/richtext/*.ui) \ $$files(sources/ElementsCollection/ui/*.ui) \ $$files(sources/autoNum/ui/*.ui) \ $$files(sources/ui/configpage/*.ui) \ - $$files(sources/SearchAndReplace/ui/*.ui) + $$files(sources/SearchAndReplace/ui/*.ui) \ + $$files(sources/NameList/ui/*.ui) UI_SOURCES_DIR = sources/ui/ UI_HEADERS_DIR = sources/ui/ diff --git a/sources/nameslist.cpp b/sources/NameList/nameslist.cpp similarity index 100% rename from sources/nameslist.cpp rename to sources/NameList/nameslist.cpp diff --git a/sources/nameslist.h b/sources/NameList/nameslist.h similarity index 100% rename from sources/nameslist.h rename to sources/NameList/nameslist.h diff --git a/sources/NameList/ui/namelistdialog.cpp b/sources/NameList/ui/namelistdialog.cpp new file mode 100644 index 000000000..5b23b10c8 --- /dev/null +++ b/sources/NameList/ui/namelistdialog.cpp @@ -0,0 +1,67 @@ +/* + Copyright 2006-2018 The QElectroTech Team + 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 . +*/ +#include "namelistdialog.h" +#include "ui_namelistdialog.h" +#include "namelistwidget.h" + +#include +#include + +NameListDialog::NameListDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::NameListDialog) +{ + ui->setupUi(this); + + m_namelist_widget = new NameListWidget(this); + ui->m_main_layout->insertWidget(1, m_namelist_widget); +#ifdef Q_OS_MAC + this->setWindowFlags(Qt::Sheet); +#endif +} + +NameListDialog::~NameListDialog() { + delete ui; +} + +void NameListDialog::setInformationText(const QString &text) { + ui->m_top_label->setText(text); +} + +/** + * @brief NameListDialog::namelistWidget + * @return the name list widget used by this dialog. + * The ownership of the namelistwidget stay to this dialog + */ +NameListWidget *NameListDialog::namelistWidget() const { + return m_namelist_widget; +} + +void NameListDialog::setHelpText(const QString &text) +{ + m_help_text = text; + if (!m_help_text.isEmpty()) + { + QPushButton *button = ui->m_button_box->addButton(QDialogButtonBox::Help); + connect(button, &QPushButton::clicked, this, &NameListDialog::showHelpDialog); + } +} + +void NameListDialog::showHelpDialog() { + QMessageBox::information(this, tr("Variables de cartouche"), m_help_text); +} diff --git a/sources/NameList/ui/namelistdialog.h b/sources/NameList/ui/namelistdialog.h new file mode 100644 index 000000000..101a73f49 --- /dev/null +++ b/sources/NameList/ui/namelistdialog.h @@ -0,0 +1,52 @@ +/* + Copyright 2006-2018 The QElectroTech Team + 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 . +*/ +#ifndef NAMELISTDIALOG_H +#define NAMELISTDIALOG_H + +#include + +class NameListWidget; + +namespace Ui { + class NameListDialog; +} + +/** + * @brief The NameListDialog class + * Provide a dialog for let user define localized string; + */ +class NameListDialog : public QDialog +{ + Q_OBJECT + + public: + explicit NameListDialog(QWidget *parent = nullptr); + ~NameListDialog(); + + void setInformationText(const QString &text); + NameListWidget *namelistWidget() const; + void setHelpText(const QString &text); + void showHelpDialog(); + + private: + Ui::NameListDialog *ui; + NameListWidget *m_namelist_widget = nullptr; + QString m_help_text; +}; + +#endif // NAMELISTDIALOG_H diff --git a/sources/NameList/ui/namelistdialog.ui b/sources/NameList/ui/namelistdialog.ui new file mode 100644 index 000000000..94a10e335 --- /dev/null +++ b/sources/NameList/ui/namelistdialog.ui @@ -0,0 +1,77 @@ + + + NameListDialog + + + + 0 + 0 + 507 + 370 + + + + Dialog + + + + + + + + + Qt::RichText + + + true + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + m_button_box + accepted() + NameListDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + m_button_box + rejected() + NameListDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sources/NameList/ui/namelistwidget.cpp b/sources/NameList/ui/namelistwidget.cpp new file mode 100644 index 000000000..3e037f8f3 --- /dev/null +++ b/sources/NameList/ui/namelistwidget.cpp @@ -0,0 +1,168 @@ +/* + Copyright 2006-2018 The QElectroTech Team + 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 . +*/ +#include "namelistwidget.h" +#include "ui_namelistwidget.h" + +#include +#include + +NameListWidget::NameListWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::NameListWidget) +{ + ui->setupUi(this); + ui->m_clipboard_cb->setHidden(true); + connect(ui->m_add_line_pb, &QPushButton::clicked, this, &NameListWidget::addLine); +} + +NameListWidget::~NameListWidget() +{ + delete ui; +} + +/** + * @brief NameListWidget::addLine + * Add a new line to the name list widget + */ +void NameListWidget::addLine() +{ + clean(); + if (m_read_only) { + return; + } + QTreeWidgetItem *qtwi = new QTreeWidgetItem(); + qtwi->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + ui->m_tree->addTopLevelItem(qtwi); + ui->m_tree->setCurrentItem(qtwi); + ui->m_tree->editItem(qtwi); +} + +/** + * @brief NameListWidget::setNames + * Set the current names of this dialog from @name_list + * @param name_list + */ +void NameListWidget::setNames(const NamesList &name_list) +{ + for (QString lang : name_list.langs()) + { + QString value = name_list[lang]; + QStringList values; + values << lang << value; + QTreeWidgetItem *qtwi = new QTreeWidgetItem(values); + if (!m_read_only) { + qtwi->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + } + ui->m_tree->addTopLevelItem(qtwi); + ui->m_tree->sortItems(0, Qt::AscendingOrder); + } +} + +/** + * @brief NameListWidget::names + * @return the current name list edited by this dialog + */ +NamesList NameListWidget::names() const +{ + NamesList nl_; + + int names_count = ui->m_tree->topLevelItemCount(); + for (int i = 0 ; i < names_count ; ++ i) + { + QString lang = ui->m_tree->topLevelItem(i)->text(0); + QString value = ui->m_tree->topLevelItem(i)->text(1); + if (lang != "" && value != "") { + nl_.addName(lang, value); + } + } + + return nl_; +} + +/** + * @brief NameListWidget::setReadOnly + * Set this dialog to read only or not. + * @param ro + */ +void NameListWidget::setReadOnly(bool ro) +{ + m_read_only = ro; + + int names_count = ui->m_tree->topLevelItemCount() - 1; + for (int i = names_count ; i >= 0 ; -- i) + { + Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable; + if (!m_read_only) { + flags |= Qt::ItemIsEditable; + } + ui->m_tree->topLevelItem(i)->setFlags(flags); + } + ui->m_add_line_pb->setEnabled(!ro); +} + +/** + * @brief NameListWidget::isEmpty + * @return true if empty. + * An empty dialog, is a dialog without any edited lang. + */ +bool NameListWidget::isEmpty() const { + return names().isEmpty(); +} + +void NameListWidget::setClipboardValue(QHash value) +{ + if (value.isEmpty()) { + ui->m_clipboard_cb->setHidden(true); + } + else + { + ui->m_clipboard_cb->setVisible(true); + + QStringList list = value.keys(); + list.sort(); + for (QString key : list) { + ui->m_clipboard_cb->addItem(key, value.value(key)); + } + } +} + +/** + * @brief NameListWidget::clean + * Clean the lists of names by removing the emtpy lines + */ +void NameListWidget::clean() +{ + int names_count = ui->m_tree->topLevelItemCount() - 1; + for (int i = names_count ; i >= 0 ; -- i) + { + if (ui->m_tree->topLevelItem(i)->text(0).isEmpty() && + ui->m_tree->topLevelItem(i)->text(1).isEmpty()) + { + ui->m_tree->takeTopLevelItem(i); + } + } +} + +void NameListWidget::on_m_clipboard_cb_activated(int index) +{ + Q_UNUSED(index); + + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(ui->m_clipboard_cb->currentData().toString()); + ui->m_clipboard_cb->setCurrentIndex(0); +} diff --git a/sources/NameList/ui/namelistwidget.h b/sources/NameList/ui/namelistwidget.h new file mode 100644 index 000000000..c959892c0 --- /dev/null +++ b/sources/NameList/ui/namelistwidget.h @@ -0,0 +1,58 @@ +/* + Copyright 2006-2018 The QElectroTech Team + 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 . +*/ +#ifndef NAMELISTWIDGET_H +#define NAMELISTWIDGET_H + +#include "nameslist.h" +#include + +namespace Ui { + class NameListWidget; +} + +/** + * @brief The NameListWidget class + * Provide a widget for let user define localized string; + */ +class NameListWidget : public QWidget +{ + Q_OBJECT + + public: + explicit NameListWidget(QWidget *parent = nullptr); + ~NameListWidget(); + + void addLine(); + void setNames (const NamesList &name_list); + NamesList names() const; + void setReadOnly(bool ro); + bool isEmpty() const; + void setClipboardValue (QHash value); + + private slots: + void on_m_clipboard_cb_activated(int index); + + private: + void clean(); + + private: + Ui::NameListWidget *ui; + bool m_read_only = false; +}; + +#endif // NAMELISTWIDGET_H diff --git a/sources/NameList/ui/namelistwidget.ui b/sources/NameList/ui/namelistwidget.ui new file mode 100644 index 000000000..f021a77a3 --- /dev/null +++ b/sources/NameList/ui/namelistwidget.ui @@ -0,0 +1,65 @@ + + + NameListWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + Langue + + + + + Texte + + + + + + + + + + Ajouter une ligne + + + + :/ico/16x16/list-add.png:/ico/16x16/list-add.png + + + + + + + + Copier dans le presse papier + + + + :/ico/16x16/edit-paste.png:/ico/16x16/edit-paste.png + + + + + + + + + + + + + diff --git a/sources/editor/elementscene.cpp b/sources/editor/elementscene.cpp index dc03397e7..207fd7c42 100644 --- a/sources/editor/elementscene.cpp +++ b/sources/editor/elementscene.cpp @@ -1,5 +1,5 @@ /* - Copyright 2006-2017 The QElectroTech Team + Copyright 2006-2018 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify @@ -28,12 +28,13 @@ #include "partarc.h" #include "editorcommands.h" #include "elementcontent.h" -#include "nameslist.h" #include "ui/elementpropertieseditorwidget.h" #include "eseventinterface.h" #include "QetGraphicsItemModeler/qetgraphicshandleritem.h" #include "partdynamictextfield.h" #include "QPropertyUndoCommand/qpropertyundocommand.h" +#include "namelistdialog.h" +#include "namelistwidget.h" #include #include @@ -725,44 +726,31 @@ void ElementScene::slot_editProperties() } /** - Lance un dialogue pour editer les noms de cet element -*/ -void ElementScene::slot_editNames() { + * @brief ElementScene::slot_editNames + * Launch a dialog for edit the names of the edited element + */ +void ElementScene::slot_editNames() +{ bool is_read_only = m_element_editor && m_element_editor -> isReadOnly(); - // cree un dialogue - QDialog dialog(m_element_editor); -#ifdef Q_OS_MAC - dialog.setWindowFlags(Qt::Sheet); -#endif - dialog.setModal(true); - dialog.setMinimumSize(400, 330); - dialog.setWindowTitle(tr("Éditer les noms", "window title")); - QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog); + NameListDialog dialog_(m_element_editor); - // ajoute un champ explicatif au dialogue - QLabel *information_label = new QLabel(tr("Vous pouvez spécifier le nom de l'élément dans plusieurs langues.")); - information_label -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter); - information_label -> setWordWrap(true); - dialog_layout -> addWidget(information_label); + dialog_.setModal(true); + dialog_.setMinimumSize(400, 330); + dialog_.setWindowTitle(tr("Éditer les noms", "window title")); - // ajoute un NamesListWidget au dialogue - NamesListWidget *names_widget = new NamesListWidget(); - names_widget -> setNames(m_names_list); - names_widget -> setReadOnly(is_read_only); - dialog_layout -> addWidget(names_widget); + dialog_.setInformationText(tr("Vous pouvez spécifier le nom de l'élément dans plusieurs langues.")); - // ajoute deux boutons au dialogue - QDialogButtonBox *dialog_buttons = new QDialogButtonBox(is_read_only ? QDialogButtonBox::Ok : QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - dialog_layout -> addWidget(dialog_buttons); - connect(dialog_buttons, SIGNAL(accepted()), names_widget, SLOT(check())); - connect(names_widget, SIGNAL(inputChecked()), &dialog, SLOT(accept())); - connect(dialog_buttons, SIGNAL(rejected()), &dialog, SLOT(reject())); + NameListWidget *nlw_ = dialog_.namelistWidget(); + nlw_->setNames(m_names_list); + nlw_->setReadOnly(is_read_only); - // lance le dialogue - if (dialog.exec() == QDialog::Accepted && !is_read_only) { - NamesList new_names(names_widget -> names()); - if (new_names != m_names_list) undoStack().push(new ChangeNamesCommand(this, m_names_list, new_names)); + if (dialog_.exec() == QDialog::Accepted && !is_read_only && !nlw_->isEmpty()) + { + NamesList new_names = nlw_->names(); + if (new_names != m_names_list) { + undoStack().push(new ChangeNamesCommand(this, m_names_list, new_names)); + } } } diff --git a/sources/editor/elementscene.h b/sources/editor/elementscene.h index b49cb5bd7..e8e871b71 100644 --- a/sources/editor/elementscene.h +++ b/sources/editor/elementscene.h @@ -19,10 +19,10 @@ #define ELEMENT_SCENE_H #include #include -#include "nameslistwidget.h" #include "qgimanager.h" #include "elementcontent.h" #include "diagramcontext.h" +#include "nameslist.h" class CustomElementPart; class ElementEditionCommand; diff --git a/sources/elementscategoryeditor.cpp b/sources/elementscategoryeditor.cpp index 16a396e0c..d77bc8646 100644 --- a/sources/elementscategoryeditor.cpp +++ b/sources/elementscategoryeditor.cpp @@ -16,11 +16,16 @@ along with QElectroTech. If not, see . */ #include "elementscategoryeditor.h" -#include "nameslistwidget.h" #include "qet.h" #include "qfilenameedit.h" #include "qetmessagebox.h" #include "elementcollectionhandler.h" +#include "namelistwidget.h" + +#include +#include +#include +#include /** * @brief ElementsCategoryEditor::ElementsCategoryEditor @@ -102,7 +107,7 @@ void ElementsCategoryEditor::setUpWidget() QVBoxLayout *editor_layout = new QVBoxLayout(); setLayout(editor_layout); - m_names_list = new NamesListWidget(); + m_names_list = new NameListWidget(this); m_file_name = new QLabel(tr("Nom interne : ")); m_file_line_edit = new QFileNameEdit(); @@ -130,7 +135,7 @@ void ElementsCategoryEditor::acceptCreation() } //there must be at least one name - if (!m_names_list -> checkOneName()) { + if (m_names_list->isEmpty()) { return; } @@ -181,7 +186,7 @@ void ElementsCategoryEditor::acceptUpdate() } //There must be at least one name - if (!m_names_list -> checkOneName()) { + if (m_names_list->isEmpty()) { return; } diff --git a/sources/elementscategoryeditor.h b/sources/elementscategoryeditor.h index 4c10a009c..6db16f132 100644 --- a/sources/elementscategoryeditor.h +++ b/sources/elementscategoryeditor.h @@ -21,7 +21,7 @@ #include #include "elementslocation.h" -class NamesListWidget; +class NameListWidget; class QFileNameEdit; class QDialogButtonBox; class QLabel; @@ -45,7 +45,7 @@ class ElementsCategoryEditor : public QDialog private: QDialogButtonBox *m_buttons; - NamesListWidget *m_names_list; + NameListWidget *m_names_list; QLabel *m_file_name; QFileNameEdit *m_file_line_edit; bool m_edit_mode; diff --git a/sources/nameslistwidget.cpp b/sources/nameslistwidget.cpp deleted file mode 100644 index 1ae8c9f59..000000000 --- a/sources/nameslistwidget.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - Copyright 2006-2017 The QElectroTech Team - 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 . -*/ -#include "nameslistwidget.h" -#include "qetmessagebox.h" -#include "qeticons.h" - -/** - Constructeur - @param parent QWidget parent de la liste de noms -*/ -NamesListWidget::NamesListWidget(QWidget *parent) : QWidget(parent), read_only(false) { - QVBoxLayout *names_list_layout = new QVBoxLayout(); - setLayout(names_list_layout); - - tree_names = new QTreeWidget(); - tree_names -> setRootIsDecorated(false); - tree_names -> setColumnCount(2); - QStringList headers; - headers << tr("Langue") << tr("Texte"); - tree_names -> setHeaderLabels(headers); - tree_names -> setWhatsThis( - tr( - "Cette liste vous permet de saisir un court texte de façon à ce" - " qu'il soit traduisible dans d'autres langues. Pour ce faire, elle" - " associe des codes ISO 639-1 de langues (ex. : \"fr\" pour" - " français) aux traductions du texte en question dans ces" - " mêmes langues.", - "\"What's this\" tip" - ) - ); - - button_add_line = new QPushButton(QET::Icons::Add, tr("Ajouter une ligne")); - button_add_line -> setWhatsThis( - tr( - "Ce bouton permet d'ajouter une association langue / traduction " - "dans la liste ci-dessus.", - "\"What's this\" tip" - ) - ); - connect(button_add_line, SIGNAL(released()), this, SLOT(addLine())); - - names_list_layout -> addWidget(tree_names); - names_list_layout -> addWidget(button_add_line); -} - -/** - Destructeur -*/ -NamesListWidget::~NamesListWidget() { -} - -/** - Ajoute une ligne a l'editeur -*/ -void NamesListWidget::addLine() { - clean(); - if (read_only) return; - QTreeWidgetItem *qtwi = new QTreeWidgetItem(); - qtwi -> setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - tree_names -> addTopLevelItem(qtwi); - tree_names -> setCurrentItem(qtwi); - tree_names -> editItem(qtwi); -} - -/** - Verifie qu'il y a au moins un nom -*/ -bool NamesListWidget::checkOneName() { - updateHash(); - if (!hash_names.count()) { - QET::QetMessageBox::critical( - this, - tr("Il doit y avoir au moins un nom.", "message box title"), - tr("Vous devez entrer au moins un nom.", "message box content") - ); - return(false); - } - return(true); -} - -/** - Lit les noms valides dans hash_names -*/ -void NamesListWidget::updateHash() { - hash_names.clearNames(); - int names_count = tree_names -> topLevelItemCount(); - for (int i = 0 ; i < names_count ; ++ i) { - QString lang = tree_names -> topLevelItem(i) -> text(0); - QString value = tree_names -> topLevelItem(i) -> text(1); - if (lang != "" && value != "") hash_names.addName(lang, value); - } -} - -/** - Nettoie la liste des noms en enlevant les lignes vides -*/ -void NamesListWidget::clean() { - int names_count = tree_names -> topLevelItemCount() - 1; - for (int i = names_count ; i >= 0 ; -- i) { - if ( - tree_names -> topLevelItem(i) -> text(0).isEmpty() &&\ - tree_names -> topLevelItem(i) -> text(1).isEmpty() - ) { - tree_names -> takeTopLevelItem(i); - } - } -} - -/** - @return Les noms entres dans la Names List -*/ -NamesList NamesListWidget::names() { - updateHash(); - return(hash_names); -} - -/** - Definit les noms que le widget doit afficher -*/ -void NamesListWidget::setNames(const NamesList &provided_names) { - foreach(QString lang, provided_names.langs()) { - QString value = provided_names[lang]; - QStringList values; - values << lang << value; - QTreeWidgetItem *qtwi = new QTreeWidgetItem(values); - if (!read_only) qtwi -> setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - tree_names -> addTopLevelItem(qtwi); - tree_names -> sortItems(0, Qt::AscendingOrder); - } -} - -/** - Verifie qu'il y a au moins un nom de saisi - si c'est le cas, le signal - imputChecked() est emis. -*/ -void NamesListWidget::check() { - if (checkOneName()) emit(inputChecked()); -} - -/** - Definit le mode d'edition du widget - @param ro true pour que la liste de noms soit en lecture seule, false sinon -*/ -void NamesListWidget::setReadOnly(bool ro) { - read_only = ro; - int names_count = tree_names -> topLevelItemCount() - 1; - for (int i = names_count ; i >= 0 ; -- i) { - Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable; - if (!read_only) flags |= Qt::ItemIsEditable; - tree_names -> topLevelItem(i) -> setFlags(flags); - } - button_add_line -> setEnabled(!read_only); -} - -/// @return true si la liste de noms est en lecture seule, false sinon -bool NamesListWidget::isReadOnly() const { - return(read_only); -} diff --git a/sources/nameslistwidget.h b/sources/nameslistwidget.h deleted file mode 100644 index b7669a110..000000000 --- a/sources/nameslistwidget.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - Copyright 2006-2017 The QElectroTech Team - 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 . -*/ -#ifndef NAMES_LIST_WIDGET_H -#define NAMES_LIST_WIDGET_H -#include -#include "nameslist.h" -/** - This class provides a widget enabling users to enter localized names for - categories and elements. -*/ -class NamesListWidget : public QWidget { - Q_OBJECT - - // constructors, destructor - public: - NamesListWidget(QWidget * = nullptr); - ~NamesListWidget() override; - - private: - NamesListWidget(const NamesListWidget &); - - // attributes - private: - QTreeWidget *tree_names; - QPushButton *button_add_line; - NamesList hash_names; - bool read_only; - - // methods - public: - bool checkOneName(); - NamesList names(); - void setNames(const NamesList &); - void setReadOnly(bool); - bool isReadOnly() const; - - private: - void clean(); - void updateHash(); - - public slots: - void addLine(); - void check(); - - signals: - /** - Signal emitted after the widget successfully checked there was at least one - name entered - */ - void inputChecked(); -}; -#endif diff --git a/sources/newelementwizard.cpp b/sources/newelementwizard.cpp index 190572718..424610349 100644 --- a/sources/newelementwizard.cpp +++ b/sources/newelementwizard.cpp @@ -16,7 +16,7 @@ along with QElectroTech. If not, see . */ #include "newelementwizard.h" -#include "nameslistwidget.h" +#include "namelistwidget.h" #include "qetelementeditor.h" #include "qfilenameedit.h" #include "qetmessagebox.h" @@ -130,7 +130,7 @@ QWizardPage *NewElementWizard::buildStep3() { page -> setSubTitle(tr("Indiquez le ou les noms de l'élément.", "wizard page subtitle")); QVBoxLayout *layout = new QVBoxLayout(); - m_names_list = new NamesListWidget(); + m_names_list = new NameListWidget(this); NamesList hash_name; hash_name.addName(QLocale::system().name().left(2), tr("Nom du nouvel élément", "default name when creating a new element")); m_names_list -> setNames(hash_name); @@ -144,14 +144,22 @@ QWizardPage *NewElementWizard::buildStep3() { * @brief NewElementWizard::validateCurrentPage * @return true if the current step is valid */ -bool NewElementWizard::validateCurrentPage() { +bool NewElementWizard::validateCurrentPage() +{ WizardState wizard_state = static_cast(currentPage() -> property("WizardState").toInt()); - if (wizard_state == Category) return(validStep1()); - else if (wizard_state == Filename) return(validStep2()); - else if (wizard_state == Names) { - // must have one name minimum - if (m_names_list -> checkOneName()) + + if (wizard_state == Category) { + return(validStep1()); + } + else if (wizard_state == Filename) { + return(validStep2()); + } + else if (wizard_state == Names) + { + // must have one name minimum + if (!m_names_list->isEmpty()) { createNewElement(); + } return true; } else return(true); diff --git a/sources/newelementwizard.h b/sources/newelementwizard.h index 102388dd5..fda40aad3 100644 --- a/sources/newelementwizard.h +++ b/sources/newelementwizard.h @@ -21,7 +21,7 @@ #include #include "elementslocation.h" -class NamesListWidget; +class NameListWidget; class QFileNameEdit; class QTreeView; class ElementsCollectionModel; @@ -53,7 +53,7 @@ class NewElementWizard : public QWizard private: enum WizardState { Category, Filename, Names }; QFileNameEdit *m_qle_filename; - NamesListWidget *m_names_list; + NameListWidget *m_names_list; QString m_chosen_file; QTreeView *m_tree_view = nullptr; ElementsLocation m_chosen_location; diff --git a/sources/qetinformation.cpp b/sources/qetinformation.cpp new file mode 100644 index 000000000..482f1f4ca --- /dev/null +++ b/sources/qetinformation.cpp @@ -0,0 +1,128 @@ +/* + Copyright 2006-2018 The QElectroTech Team + 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 . +*/ +#include "qetinformation.h" + +#include +#include + +/** + * @brief QETInformation::titleblockInfoKeys + * @return all available key for use with a titleblock + */ +QStringList QETInformation::titleblockInfoKeys() +{ + QStringList info_list; + info_list << "author"; + info_list << "date"; + info_list << "title"; + info_list << "filename"; + info_list << "plant"; + info_list << "locmach"; + info_list << "indexrev"; + info_list << "version"; + info_list << "folio"; + info_list << "folio-id"; + info_list << "folio-total"; + info_list << "previous-folio-num"; + info_list << "next-folio-num"; + info_list << "projecttitle"; + info_list << "projectpath"; + info_list << "projectfilename"; + info_list << "saveddate"; + info_list << "savedtime"; + info_list << "savedfilename"; + info_list << "savedfilepath"; + + return info_list; +} + +/** + * @brief QETInformation::titleblockTranslatedInfoKey + * @param info : info key to be translated + * @return the translated information given by @info + * If @info don't match, return an empty string + */ +QString QETInformation::titleblockTranslatedInfoKey(const QString &info) +{ + if (info == "author") return QObject::tr("Auteur"); + else if (info == "date") return QObject::tr("Date"); + else if (info == "title") return QObject::tr("Titre"); + else if (info == "filename") return QObject::tr("Fichier"); + else if (info == "plant") return QObject::tr("Installation (=)"); + else if (info == "locmach") return QObject::tr("Localisation (+)"); + else if (info == "indexrev") return QObject::tr("Indice de révision"); + else if (info == "version") return QObject::tr("Version de QElectroTech"); + else if (info == "folio") return QObject::tr("Numéro de folio"); + else if (info == "folio-id") return QObject::tr("Position du folio"); + else if (info == "folio-total") return QObject::tr("Nombre de folio"); + else if (info == "previous-folio-num") return QObject::tr("Numéro du folio précédent"); + else if (info == "next-folio-num") return QObject::tr("Numéro du folio suivant"); + else if (info == "projecttitle") return QObject::tr("Titre du projet"); + else if (info == "projectpath") return QObject::tr("Chemin du fichier du projet"); + else if (info == "projectfilename") return QObject::tr("Nom du fichier"); + else if (info == "saveddate") return QObject::tr("Date d'enregistrement du fichier"); + else if (info == "savedtime") return QObject::tr("Heure d'enregistrement du fichier"); + else if (info == "savedfilename") return QObject::tr("Nom du fichier enregistré"); + else if (info == "savedfilepath") return QObject::tr("Chemin du fichier enregistré"); + else return QString(); +} + +/** + * @brief QETInformation::titleblockInfoKeysToVar + * @param info + * @return var in form %{my-var} corresponding to the info. + * if there is not available var for the given info, the returned var is %{void} + */ +QString QETInformation::titleblockInfoKeysToVar(const QString &info) +{ + if (info == "author") return QString("%{author}"); + else if (info == "date") return QString("%{date}"); + else if (info == "title") return QString("%{title}"); + else if (info == "filename") return QString("%{filename}"); + else if (info == "plant") return QString("%{plant}"); + else if (info == "locmach") return QString("%{locmach}"); + else if (info == "indexrev") return QString("%{indexrev}"); + else if (info == "version") return QString("%{version}"); + else if (info == "folio") return QString("%{folio}"); + else if (info == "folio-id") return QString("%{folio-id}"); + else if (info == "folio-total") return QString("%{folio-total}"); + else if (info == "previous-folio-num") return QString("%{previous-folio-num}"); + else if (info == "next-folio-num") return QString("%{next-folio-num}"); + else if (info == "projecttitle") return QString("%{projecttitle}"); + else if (info == "projectpath") return QString("%{projectpath}"); + else if (info == "projectfilename") return QString("%{projectfilename}"); + else if (info == "saveddate") return QString("%{saveddate}"); + else if (info == "savedtime") return QString("%{savedtime}"); + else if (info == "savedfilename") return QString("%{savedfilename}"); + else if (info == "savedfilepath") return QString("%{savedfilepath}"); + else return QString("%{void"); +} + +/** + * @brief QETInformation::titleblockTranslatedKeyHashVar + * @return a QHash with for key, the translated information key of title block, + * and for value the corresponding var. + */ +QHash QETInformation::titleblockTranslatedKeyHashVar() +{ + QHash hash_; + for (QString str : titleblockInfoKeys()) { + hash_.insert(titleblockTranslatedInfoKey(str), titleblockInfoKeysToVar(str)); + } + return hash_; +} diff --git a/sources/qetinformation.h b/sources/qetinformation.h new file mode 100644 index 000000000..7afb271f1 --- /dev/null +++ b/sources/qetinformation.h @@ -0,0 +1,31 @@ +/* + Copyright 2006-2018 The QElectroTech Team + 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 . +*/ +#ifndef QETINFORMATION_H +#define QETINFORMATION_H + +#include + +namespace QETInformation +{ + QStringList titleblockInfoKeys(); + QString titleblockTranslatedInfoKey(const QString &info); + QString titleblockInfoKeysToVar(const QString &info); + QHash titleblockTranslatedKeyHashVar(); +} + +#endif // QETINFORMATION_H diff --git a/sources/titleblock/templatecellwidget.cpp b/sources/titleblock/templatecellwidget.cpp index d00405092..48d04f85f 100644 --- a/sources/titleblock/templatecellwidget.cpp +++ b/sources/titleblock/templatecellwidget.cpp @@ -18,10 +18,12 @@ #include "templatecellwidget.h" #include "titleblockcell.h" #include "nameslist.h" -#include "nameslistwidget.h" #include "titleblocktemplate.h" #include "templatecommands.h" #include "qeticons.h" +#include "namelistdialog.h" +#include "namelistwidget.h" +#include "qetinformation.h" /** Constructor @@ -374,33 +376,20 @@ bool TitleBlockTemplateCellWidget::isReadOnly() const { @param attribute Name of the edited cell attribute @param title Title of the dialog window */ -void TitleBlockTemplateCellWidget::editTranslatableValue(NamesList &names, const QString &attribute, const QString &title) const { - NamesListWidget *names_widget = new NamesListWidget(); - names_widget -> setNames(names); - QDialogButtonBox * buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); +void TitleBlockTemplateCellWidget::editTranslatableValue(NamesList &names, const QString &attribute, const QString &title) const +{ + NameListDialog dialog_; + + dialog_.setWindowTitle(title); + dialog_.setInformationText(labelValueInformationString()); + dialog_.setHelpText(defaultVariablesString()); - QLabel *information = new QLabel(labelValueInformationString()); - information -> setTextFormat(Qt::RichText); - information -> setWordWrap(true); + NameListWidget *nlw_ = dialog_.namelistWidget(); + nlw_->setNames(names); + nlw_->setClipboardValue(QETInformation::titleblockTranslatedKeyHashVar()); - QLabel *def_var_label = new QLabel(defaultVariablesString()); - def_var_label -> setTextFormat(Qt::RichText); - def_var_label -> setTextInteractionFlags(Qt::TextSelectableByMouse); - - QVBoxLayout *editor_layout = new QVBoxLayout(); - editor_layout -> addWidget(information); - editor_layout -> addWidget(names_widget); - editor_layout -> addWidget(def_var_label); - editor_layout -> addWidget(buttons); - - QDialog edit_dialog; - edit_dialog.setWindowTitle(title); - connect(buttons, SIGNAL(rejected()), &edit_dialog, SLOT(reject())); - connect(buttons, SIGNAL(accepted()), &edit_dialog, SLOT(accept())); - edit_dialog.setLayout(editor_layout); - if (edit_dialog.exec() == QDialog::Accepted) { - emitModification(attribute, qVariantFromValue(names_widget -> names())); - + if(dialog_.exec() == QDialog::Accepted) { + emitModification(attribute, qVariantFromValue(nlw_->names())); } }