diff --git a/sources/SearchAndReplace/searchandreplaceworker.cpp b/sources/SearchAndReplace/searchandreplaceworker.cpp index 83efd7508..73a6855ad 100644 --- a/sources/SearchAndReplace/searchandreplaceworker.cpp +++ b/sources/SearchAndReplace/searchandreplaceworker.cpp @@ -231,6 +231,122 @@ void SearchAndReplaceWorker::replaceConductor(Conductor *conductor) replaceConductor(list); } +/** + * @brief SearchAndReplaceWorker::replaceAdvanced + * Apply the change of text according to the current advancedStruct + * All items in the 4 list must belong to the same QETProject, + * if not this function do nothing + * @param d + * @param e + * @param t + * @param c + */ +void SearchAndReplaceWorker::replaceAdvanced(QList diagrams, QList elements, QList texts, QList conductors) +{ + QETProject *project_ = nullptr; + + //Some test to check if a least one list have one item + //and if all items belong to the same project + if (!diagrams.isEmpty()) { + project_ = diagrams.first()->project(); + } else if (!elements.isEmpty() && elements.first()->diagram()) { + project_ = elements.first()->diagram()->project(); + } else if (!texts.isEmpty() && texts.first()->diagram()) { + project_ = texts.first()->diagram()->project(); + } else if (!conductors.isEmpty() && conductors.first()->diagram()) { + project_ = conductors.first()->diagram()->project(); + } else { + return; + } + + for (Diagram *dd : diagrams) { + if (dd->project() != project_) { + return; + } + } + for (Element *elmt : elements) { + if (!elmt->diagram() || elmt->diagram()->project() != project_) { + return; + } + } + for (IndependentTextItem *text : texts) { + if (!text->diagram() || text->diagram()->project() != project_) { + return; + } + } + for (Conductor *cc : conductors) { + if (!cc->diagram() || cc->diagram()->project() != project_) { + return; + } + } + //The end of the test + + int who = m_advanced_struct.who; + if (who == -1) { + return; + } + + project_->undoStack()->beginMacro(QObject::tr("Rechercher / remplacer avancé")); + if (who == 0) + { + for (Diagram *diagram : diagrams) + { + TitleBlockProperties old_properties = diagram->border_and_titleblock.exportTitleBlock(); + TitleBlockProperties new_properties = replaceAdvanced(diagram); + if (old_properties != new_properties) { + project_->undoStack()->push(new ChangeTitleBlockCommand(diagram, old_properties, new_properties)); + } + } + } + else if (who == 1) + { + for (Element *element : elements) + { + DiagramContext old_context = element->elementInformations(); + DiagramContext new_context = replaceAdvanced(element); + if (old_context != new_context) { + project_->undoStack()->push(new ChangeElementInformationCommand(element, old_context, new_context)); + } + } + } + else if (who == 2) + { + for (Conductor *conductor : conductors) + { + ConductorProperties old_properties = conductor->properties(); + ConductorProperties new_properties = replaceAdvanced(conductor); + if (old_properties != new_properties) + { + QSet potential_conductors = conductor->relatedPotentialConductors(true); + potential_conductors << conductor; + + for (Conductor *c : potential_conductors) + { + QVariant old_value, new_value; + old_value.setValue(c->properties()); + new_value.setValue(new_properties); + project_->undoStack()->push(new QPropertyUndoCommand(c, "properties", old_value, new_value)); + } + } + } + } + else if (who == 3) + { + for (IndependentTextItem *text : texts) + { + QRegularExpression rx(m_advanced_struct.search); + QString replace = m_advanced_struct.replace; + QString after = text->toPlainText(); + after = after.replace(rx, replace); + + if (after != text->toPlainText()) { + project_->undoStack()->push(new ChangeDiagramTextCommand(text, text->toPlainText(), after)); + } + } + } + project_->undoStack()->endMacro(); +} + /** * @brief SearchAndReplaceWorker::setupLineEdit * With search and replace, when the variable to edit is a text, @@ -313,3 +429,79 @@ QString SearchAndReplaceWorker::applyChange(const QString &original, const QStri else if (change == eraseText()) {return QString();} else {return change;} } + +/** + * @brief SearchAndReplaceWorker::replaceAdvanced + * @param diagram + * @return the titleblock properties with the change applied, + * according to the state of @m_advanced_struct + */ +TitleBlockProperties SearchAndReplaceWorker::replaceAdvanced(Diagram *diagram) +{ + TitleBlockProperties p = diagram->border_and_titleblock.exportTitleBlock(); + + if (m_advanced_struct.who == 0) + { + QRegularExpression rx(m_advanced_struct.search); + QString replace = m_advanced_struct.replace; + QString what = m_advanced_struct.what; + if (what == "title") {p.title = p.title.replace(rx, replace);} + else if (what == "author") {p.author = p.author.replace(rx, replace);} + else if (what == "filename") {p.filename = p.filename.replace(rx, replace);} + else if (what == "folio") {p.folio = p.folio.replace(rx, replace);} + else if (what == "plant") {p.plant = p.plant.replace(rx, replace);} + else if (what == "locmach") {p.locmach = p.locmach.replace(rx, replace);} + else if (what == "indexrev") {p.indexrev = p.indexrev.replace(rx, replace);} + } + return p; +} + +/** + * @brief SearchAndReplaceWorker::replaceAdvanced + * @param element + * @return The diagram context with the change applied, + * according to the state of @m_advanced_struct + */ +DiagramContext SearchAndReplaceWorker::replaceAdvanced(Element *element) +{ + DiagramContext context = element->elementInformations(); + + if (m_advanced_struct.who == 1) + { + QString what = m_advanced_struct.what; + if (context.contains(what)) + { + QRegularExpression rx(m_advanced_struct.search); + QString replace = m_advanced_struct.replace; + QString value = context[what].toString(); + context.addValue(what, value.replace(rx, replace)); + } + } + + return context; +} + +/** + * @brief SearchAndReplaceWorker::replaceAdvanced + * @param conductor + * @return the conductor properties with the change applied, + * according to the state of @m_advanced_struct + */ +ConductorProperties SearchAndReplaceWorker::replaceAdvanced(Conductor *conductor) +{ + ConductorProperties properties = conductor->properties(); + + if (m_advanced_struct.who == 2) + { + QRegularExpression rx(m_advanced_struct.search); + QString what = m_advanced_struct.what; + QString replace = m_advanced_struct.replace; + + if (what == "formula") {properties.m_formula.replace(rx, replace);} + else if (what == "text") {properties.text.replace(rx, replace);} + else if (what == "function") {properties.m_function.replace(rx, replace);} + else if (what == "tension/protocol") {properties.m_tension_protocol.replace(rx, replace);} + } + + return properties; +} diff --git a/sources/SearchAndReplace/searchandreplaceworker.h b/sources/SearchAndReplace/searchandreplaceworker.h index 99400e988..4ad2409a9 100644 --- a/sources/SearchAndReplace/searchandreplaceworker.h +++ b/sources/SearchAndReplace/searchandreplaceworker.h @@ -30,6 +30,19 @@ class Conductor; class QLineEdit; class QCheckBox; +struct advancedReplaceStruct +{ + //Who : + // 0 == diagram + // 1 == element + // 2 == conductor + // 3 == independant text + int who = -1; + QString what; + QString search; + QString replace; +}; + /** * @brief The SearchAndReplaceWorker class * This class is the worker use to change properties when use the search and replace function of QET @@ -47,6 +60,8 @@ class SearchAndReplaceWorker void replaceIndiText(IndependentTextItem *text); void replaceConductor(QList list); void replaceConductor(Conductor *conductor); + void replaceAdvanced (QList diagrams = QList(), QList elements = QList(),\ + QList texts = QList(), QList conductors = QList()); static QString eraseText() {return QString("XXXXXXXXXXXXXXXXXXX");} static QDate eraseDate() {return QDate(1900, 1, 1);} @@ -57,10 +72,15 @@ class SearchAndReplaceWorker static QString applyChange(const QString &original, const QString &change); private: + TitleBlockProperties replaceAdvanced (Diagram *diagram); + DiagramContext replaceAdvanced (Element *element); + ConductorProperties replaceAdvanced (Conductor *conductor); + TitleBlockProperties m_titleblock_properties; DiagramContext m_element_context; QString m_indi_text; ConductorProperties m_conductor_properties; + advancedReplaceStruct m_advanced_struct; friend class SearchAndReplaceWidget; }; diff --git a/sources/SearchAndReplace/ui/replaceadvanceddialog.cpp b/sources/SearchAndReplace/ui/replaceadvanceddialog.cpp new file mode 100644 index 000000000..61c6154a9 --- /dev/null +++ b/sources/SearchAndReplace/ui/replaceadvanceddialog.cpp @@ -0,0 +1,118 @@ +/* + 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 "replaceadvanceddialog.h" +#include "ui_replaceadvanceddialog.h" +#include "qetapp.h" + +#include + +/** + * @brief replaceAdvancedDialog::replaceAdvancedDialog + * @param advanced + * @param parent + */ +replaceAdvancedDialog::replaceAdvancedDialog(advancedReplaceStruct advanced, QWidget *parent) : + QDialog(parent), + ui(new Ui::replaceAdvancedDialog) +{ + ui->setupUi(this); + + connect(ui->m_button_box, &QDialogButtonBox::clicked, [this](QAbstractButton *button_) { + this->done(ui->m_button_box->buttonRole(button_)); + }); + + fillWhatComboBox(ui->m_who_cb->currentIndex()); + ui->m_search_le->setFocus(); + setAdvancedStruct(advanced); +} + +replaceAdvancedDialog::~replaceAdvancedDialog() +{ + delete ui; +} + +/** + * @brief replaceAdvancedDialog::setAdvancedStruct + * Set the edited advanced struct + * @param advanced + */ +void replaceAdvancedDialog::setAdvancedStruct(advancedReplaceStruct advanced) +{ + int index = advanced.who; + if (index == -1) { + return; + } + ui->m_who_cb->setCurrentIndex(index); + + for (int i=0 ; i < ui->m_what_cb->count() ; i++) + { + if (ui->m_what_cb->itemData(i).toString() == advanced.what) + { + ui->m_what_cb->setCurrentIndex(i); + continue; + } + } + + ui->m_search_le->setText(advanced.search); + ui->m_replace_le->setText(advanced.replace); +} + +/** + * @brief replaceAdvancedDialog::advancedStruct + * @return the edited advanced struct + */ +advancedReplaceStruct replaceAdvancedDialog::advancedStruct() const +{ + advancedReplaceStruct a; + a.who = ui->m_who_cb->currentIndex(); + a.what = ui->m_what_cb->currentData().toString(); + a.search = ui->m_search_le->text(); + a.replace = ui->m_replace_le->text(); + + return a; +} + +void replaceAdvancedDialog::fillWhatComboBox(int index) +{ + ui->m_what_cb->clear(); + + if (index == 0) + { + for (QString str : QETApp::diagramInfoKeys()) { + ui->m_what_cb->addItem(QETApp::diagramTranslatedInfoKey(str), str); + } + } + else if (index == 1) { + for (QString str : QETApp::elementInfoKeys()) { + ui->m_what_cb->addItem(QETApp::elementTranslatedInfoKey(str), str); + } + } + else if (index == 2) { + for (QString str : QETApp::conductorInfoKeys()) { + ui->m_what_cb->addItem(QETApp::conductorTranslatedInfoKey(str), str); + } + } +} + +/** + * @brief replaceAdvancedDialog::on_m_who_cb_currentIndexChanged + * @param index + */ +void replaceAdvancedDialog::on_m_who_cb_currentIndexChanged(int index) { + fillWhatComboBox(index); +} diff --git a/sources/SearchAndReplace/ui/replaceadvanceddialog.h b/sources/SearchAndReplace/ui/replaceadvanceddialog.h new file mode 100644 index 000000000..6d5f480e1 --- /dev/null +++ b/sources/SearchAndReplace/ui/replaceadvanceddialog.h @@ -0,0 +1,50 @@ +/* + 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 REPLACEADVANCEDDIALOG_H +#define REPLACEADVANCEDDIALOG_H + +#include "searchandreplaceworker.h" + +#include + +namespace Ui { + class replaceAdvancedDialog; +} + +class replaceAdvancedDialog : public QDialog +{ + Q_OBJECT + + public: + explicit replaceAdvancedDialog(advancedReplaceStruct advanced, QWidget *parent = nullptr); + ~replaceAdvancedDialog(); + + void setAdvancedStruct(advancedReplaceStruct advanced); + advancedReplaceStruct advancedStruct() const; + + private: + void fillWhatComboBox(int index); + + private slots: + void on_m_who_cb_currentIndexChanged(int index); + + private: + Ui::replaceAdvancedDialog *ui; +}; + +#endif // REPLACEADVANCEDDIALOG_H diff --git a/sources/SearchAndReplace/ui/replaceadvanceddialog.ui b/sources/SearchAndReplace/ui/replaceadvanceddialog.ui new file mode 100644 index 000000000..b72af5a2d --- /dev/null +++ b/sources/SearchAndReplace/ui/replaceadvanceddialog.ui @@ -0,0 +1,113 @@ + + + replaceAdvancedDialog + + + + 0 + 0 + 508 + 178 + + + + Rechercher/Remplacer avancé + + + + + + false + + + + + + + par : + + + + + + + Remplacer : + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset + + + + + + + Qui : + + + + + + + Texte ou expression régulière + + + + + + + + + + + Folio + + + + + Élément + + + + + Conducteur + + + + + Texte indépendant + + + + + + + + Quoi : + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/sources/SearchAndReplace/ui/replaceconductordialog.h b/sources/SearchAndReplace/ui/replaceconductordialog.h index cb72133cf..a5a1f34d0 100644 --- a/sources/SearchAndReplace/ui/replaceconductordialog.h +++ b/sources/SearchAndReplace/ui/replaceconductordialog.h @@ -57,7 +57,7 @@ class ReplaceConductorDialog : public QDialog void on_m_color_pb_clicked(); void on_m_color_2_pb_clicked(); - private: + private: Ui::ReplaceConductorDialog *ui; ConductorProperties m_properties; }; diff --git a/sources/SearchAndReplace/ui/replaceelementdialog.cpp b/sources/SearchAndReplace/ui/replaceelementdialog.cpp index 5eb745589..db22bc531 100644 --- a/sources/SearchAndReplace/ui/replaceelementdialog.cpp +++ b/sources/SearchAndReplace/ui/replaceelementdialog.cpp @@ -68,9 +68,7 @@ DiagramContext ReplaceElementDialog::context() const void ReplaceElementDialog::buildWidget() { - ui->m_button_box->disconnect(); - connect(ui->m_button_box, &QDialogButtonBox::clicked, [this](QAbstractButton *button_) - { + connect(ui->m_button_box, &QDialogButtonBox::clicked, [this](QAbstractButton *button_) { this->done(ui->m_button_box->buttonRole(button_)); }); diff --git a/sources/SearchAndReplace/ui/replaceelementdialog.ui b/sources/SearchAndReplace/ui/replaceelementdialog.ui index 9ff7eb47b..1d94be33d 100644 --- a/sources/SearchAndReplace/ui/replaceelementdialog.ui +++ b/sources/SearchAndReplace/ui/replaceelementdialog.ui @@ -27,8 +27,8 @@ 0 0 - 280 - 351 + 284 + 346 @@ -48,38 +48,5 @@ - - - m_button_box - accepted() - ReplaceElementDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - m_button_box - rejected() - ReplaceElementDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - + diff --git a/sources/SearchAndReplace/ui/searchandreplacewidget.cpp b/sources/SearchAndReplace/ui/searchandreplacewidget.cpp index 7af52e3a8..ab609eedd 100644 --- a/sources/SearchAndReplace/ui/searchandreplacewidget.cpp +++ b/sources/SearchAndReplace/ui/searchandreplacewidget.cpp @@ -28,6 +28,7 @@ #include "replaceelementdialog.h" #include "qetapp.h" #include "replaceconductordialog.h" +#include "replaceadvanceddialog.h" #include @@ -214,6 +215,7 @@ void SearchAndReplaceWidget::setHideAdvanced(bool hide) const ui->m_replace_all_pb ->setHidden(hide); ui->m_mode_cb ->setHidden(hide); ui->m_case_sensitive_cb->setHidden(hide); + ui->m_advanced_replace_pb->setHidden(hide); } /** @@ -630,6 +632,94 @@ void SearchAndReplaceWidget::activateNextChecked() ui->m_next_pb->isEnabled()); } +/** + * @brief SearchAndReplaceWidget::selectedDiagram + * @return The list of visible and selected diagram in the tree widget + */ +QList SearchAndReplaceWidget::selectedDiagram() const +{ + QList diagram_list; + + for (QTreeWidgetItem *qtwi : m_diagram_hash.keys()) + { + if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked) + { + QPointer p = m_diagram_hash.value(qtwi); + if (p) { + diagram_list.append(p.data()); + } + } + } + + return diagram_list; +} + +/** + * @brief SearchAndReplaceWidget::selectedElement + * @return The list of visible and selected element in the tree widget + */ +QList SearchAndReplaceWidget::selectedElement() const +{ + QList element_list; + + for (QTreeWidgetItem *qtwi : m_element_hash.keys()) + { + if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked) + { + QPointer p = m_element_hash.value(qtwi); + if (p) { + element_list.append(p.data()); + } + } + } + + return element_list; +} + +/** + * @brief SearchAndReplaceWidget::selectedConductor + * @return The list of visible and selected conductor in the tree widget + */ +QList SearchAndReplaceWidget::selectedConductor() const +{ + QList conductor_list; + + for (QTreeWidgetItem *qtwi : m_conductor_hash.keys()) + { + if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked) + { + QPointer c = m_conductor_hash.value(qtwi); + if (c) { + conductor_list.append(c.data()); + } + } + } + + return conductor_list; +} + +/** + * @brief SearchAndReplaceWidget::selectedText + * @return The list of visible and selected independant text in the tree widget + */ +QList SearchAndReplaceWidget::selectedText() const +{ + QList text_list; + + for(QTreeWidgetItem *qtwi : m_text_hash.keys()) + { + if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked) + { + QPointer t = m_text_hash.value(qtwi); + if (t) { + text_list.append(t.data()); + } + } + } + + return text_list; +} + /** * @brief SearchAndReplaceWidget::searchTerms * @param diagram @@ -919,7 +1009,48 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked() m_worker.replaceConductor(c.data()); } } + + //Replace advanced + if (ui->m_advanced_replace_pb->text().endsWith(tr(" [édité]"))) + { + QList dl; + QList el; + QList tl; + QList cl; + + if (m_diagram_hash.keys().contains(qtwi)) + { + QPointer d = m_diagram_hash.value(qtwi); + if (d) { + dl.append(d.data()); + } + } + else if (m_element_hash.keys().contains(qtwi)) + { + QPointer e = m_element_hash.value(qtwi); + if (e) { + el.append(e.data()); + } + } + else if (m_text_hash.keys().contains(qtwi)) + { + QPointer t = m_text_hash.value(qtwi); + if (t) { + tl.append(t.data()); + } + } + else if (m_conductor_hash.keys().contains(qtwi)) + { + QPointer c = m_conductor_hash.value(qtwi); + if (c) { + cl.append(c.data()); + } + } + + m_worker.replaceAdvanced(dl, el, tl, cl); + } } + activateNextChecked(); ui->m_replace_pb->setEnabled(ui->m_next_pb->isEnabled()); } @@ -930,72 +1061,23 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked() */ void SearchAndReplaceWidget::on_m_replace_all_pb_clicked() { - //Replace folio - if (ui->m_folio_pb->text().endsWith(tr(" [édité]"))) - { - QList diagram_list; - for (QTreeWidgetItem *qtwi : m_diagram_hash.keys()) - { - if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked) - { - QPointer p = m_diagram_hash.value(qtwi); - if (p) { - diagram_list.append(p.data()); - } - } - } - m_worker.replaceDiagram(diagram_list); + if (ui->m_folio_pb->text().endsWith(tr(" [édité]"))) { + m_worker.replaceDiagram(selectedDiagram()); } - //Replace text - if (ui->m_element_pb->text().endsWith(tr(" [édité]"))) - { - QList element_list; - for (QTreeWidgetItem *qtwi : m_element_hash.keys()) - { - if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked) - { - QPointer p = m_element_hash.value(qtwi); - if (p) { - element_list.append(p.data()); - } - } - } - m_worker.replaceElement(element_list); + if (ui->m_element_pb->text().endsWith(tr(" [édité]"))) { + m_worker.replaceElement(selectedElement()); } - //Replace indi text - if (!ui->m_replace_le->text().isEmpty()) - { - QList text_list; - for(QTreeWidgetItem *qtwi : m_text_hash.keys()) - { - if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked) - { - QPointer t = m_text_hash.value(qtwi); - if (t) { - text_list.append(t.data()); - } - } - } + if (!ui->m_replace_le->text().isEmpty()) { m_worker.m_indi_text = ui->m_replace_le->text(); - m_worker.replaceIndiText(text_list ); + m_worker.replaceIndiText(selectedText() ); } - - //Replace conductor - if (ui->m_conductor_pb->text().endsWith(tr(" [édité]"))) - { - QList conductor_list; - for (QTreeWidgetItem *qtwi : m_conductor_hash.keys()) - { - if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked) - { - QPointer c = m_conductor_hash.value(qtwi); - if (c) { - conductor_list.append(c.data()); - } - } - } - m_worker.replaceConductor(conductor_list); + if (ui->m_conductor_pb->text().endsWith(tr(" [édité]"))) { + m_worker.replaceConductor(selectedConductor()); } + if (ui->m_advanced_replace_pb->text().endsWith(tr(" [édité]"))) { + + m_worker.replaceAdvanced(selectedDiagram(), selectedElement(), selectedText(), selectedConductor()); + } //Change was made, we reload the panel //and search again to keep up to date the tree widget @@ -1081,3 +1163,32 @@ void SearchAndReplaceWidget::on_m_conductor_pb_clicked() m_worker.m_conductor_properties = m_worker.invalidConductorProperties(); } } + +/** + * @brief SearchAndReplaceWidget::on_m_advanced_replace_pb_clicked + * Open the advanced editor. + */ +void SearchAndReplaceWidget::on_m_advanced_replace_pb_clicked() +{ + replaceAdvancedDialog *dialog = new replaceAdvancedDialog(m_worker.m_advanced_struct, this); + int result = dialog->exec(); + + if (result == QDialogButtonBox::AcceptRole) + { + QString text = ui->m_advanced_replace_pb->text(); + if (!text.endsWith(tr(" [édité]"))) { + text.append(tr(" [édité]")); + } + ui->m_advanced_replace_pb->setText(text); + m_worker.m_advanced_struct = dialog->advancedStruct(); + } + else if (result == QDialogButtonBox::ResetRole) + { + QString text = ui->m_advanced_replace_pb->text(); + if (text.endsWith(tr(" [édité]"))) { + text.remove(tr(" [édité]")); + } + ui->m_advanced_replace_pb->setText(text); + m_worker.m_advanced_struct = advancedReplaceStruct(); + } +} diff --git a/sources/SearchAndReplace/ui/searchandreplacewidget.h b/sources/SearchAndReplace/ui/searchandreplacewidget.h index e93b7ebe2..23a383bf7 100644 --- a/sources/SearchAndReplace/ui/searchandreplacewidget.h +++ b/sources/SearchAndReplace/ui/searchandreplacewidget.h @@ -60,6 +60,11 @@ class SearchAndReplaceWidget : public QWidget void setChildCheckState(QTreeWidgetItem *item, Qt::CheckState check, bool deep = true); void updateParentCheckState(QTreeWidgetItem *item, bool all_parents = true); void activateNextChecked(); + QList selectedDiagram() const; + QList selectedElement() const; + QList selectedConductor() const; + QList selectedText() const; + static QStringList searchTerms(Diagram *diagram); static QStringList searchTerms(Element *element); static QStringList searchTerms(Conductor *conductor); @@ -80,8 +85,9 @@ class SearchAndReplaceWidget : public QWidget void on_m_mode_cb_currentIndexChanged(int index); void on_m_case_sensitive_cb_stateChanged(int arg1); void on_m_conductor_pb_clicked(); + void on_m_advanced_replace_pb_clicked(); - private: + private: Ui::SearchAndReplaceWidget *ui; QETDiagramEditor *m_editor; QTreeWidgetItem *m_root_qtwi = nullptr, diff --git a/sources/SearchAndReplace/ui/searchandreplacewidget.ui b/sources/SearchAndReplace/ui/searchandreplacewidget.ui index 124eb3e1c..e5e7e350d 100644 --- a/sources/SearchAndReplace/ui/searchandreplacewidget.ui +++ b/sources/SearchAndReplace/ui/searchandreplacewidget.ui @@ -13,7 +13,14 @@ Form - + + + + + Chercher : + + + @@ -31,14 +38,7 @@ - - - - Chercher : - - - - + Mode @@ -58,14 +58,21 @@ - + Sensible à la casse - + + + + Remplacer : + + + + Aller à la correspondance suivante @@ -82,7 +89,7 @@ - + Aller à la correspondance précédente @@ -99,24 +106,7 @@ - - - - Actualiser - - - - - - - :/ico/16x16/view-refresh.png:/ico/16x16/view-refresh.png - - - true - - - - + <html><head/><body><p>Afficher les options avancées</p></body></html> @@ -139,10 +129,20 @@ - - + + + + Actualiser + - Remplacer : + + + + + :/ico/16x16/view-refresh.png:/ico/16x16/view-refresh.png + + + true @@ -189,7 +189,7 @@ - + false @@ -202,7 +202,7 @@ - + false @@ -215,14 +215,7 @@ - - - - true - - - - + true @@ -243,6 +236,20 @@ + + + + avancé + + + + + + + true + + + diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index 7c1ed7dfa..39e2be406 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -378,6 +378,72 @@ QString QETApp::elementInfoToVar(const QString &info) return (QString ("%{void}")); } +/** + * @brief QETApp::conductorInfoKeys + * @return the conductor information keys + */ +QStringList QETApp::conductorInfoKeys() +{ + QStringList keys; + keys.append("formula"); + keys.append("text"); + keys.append("function"); + keys.append("tension/protocol"); + + return keys; +} + +/** + * @brief QETApp::conductorTranslatedInfoKey + * @param key + * @return the translated information key given by @key + * If @key don't match, return an empty string + */ +QString QETApp::conductorTranslatedInfoKey(const QString &key) +{ + if (key == "formula") return tr("Formule du texte"); + else if (key == "text") return tr("Texte"); + else if (key == "function") return tr("Fonction"); + else if (key == "tension/protocol") return tr("Tension / Protocole"); + return QString(); +} + +/** + * @brief QETApp::diagramInfoKeys + * @return the diagram default information keys + */ +QStringList QETApp::diagramInfoKeys() +{ + QStringList list; + list.append("title"); + list.append("author"); + list.append("filename"); + list.append("folio"); + list.append("plant"); + list.append("locmach"); + list.append("indexrev"); + + return list; +} + +/** + * @brief QETApp::diagramTranslatedInfoKey + * @param key + * @return the translated information key given by @key + * If @key don't match, return an empty string + */ +QString QETApp::diagramTranslatedInfoKey(const QString &key) +{ + if (key == "title") return tr("Titre"); + else if (key == "author") return tr("Auteur"); + else if (key == "filename") return tr("Fichier"); + else if (key == "folio") return tr("Folio"); + else if (key == "plant") return tr("Installation"); + else if (key == "locmach") return tr("Localisation"); + else if (key == "indexrev") return tr("Indice Rev"); + else return QString(); +} + /** @return the common title block templates collection, i.e. the one provided by QElecrotTech diff --git a/sources/qetapp.h b/sources/qetapp.h index e3ca76880..3815ff8fc 100644 --- a/sources/qetapp.h +++ b/sources/qetapp.h @@ -76,6 +76,12 @@ class QETApp : public QObject static QString elementTranslatedInfoKey(const QString &); static QString elementInfoToVar(const QString &info); + static QStringList conductorInfoKeys(); + static QString conductorTranslatedInfoKey(const QString &key); + + static QStringList diagramInfoKeys(); + static QString diagramTranslatedInfoKey(const QString &key); + static TitleBlockTemplatesFilesCollection *commonTitleBlockTemplatesCollection(); static TitleBlockTemplatesFilesCollection *customTitleBlockTemplatesCollection(); static QList availableTitleBlockTemplatesCollections();