diff --git a/sources/SearchAndReplace/searchandreplaceworker.cpp b/sources/SearchAndReplace/searchandreplaceworker.cpp index 3b12b0d02..9e329cbfb 100644 --- a/sources/SearchAndReplace/searchandreplaceworker.cpp +++ b/sources/SearchAndReplace/searchandreplaceworker.cpp @@ -21,6 +21,9 @@ #include "changeelementinformationcommand.h" #include "element.h" #include "qetapp.h" +#include "independenttextitem.h" +#include "diagramcommands.h" + SearchAndReplaceWorker::SearchAndReplaceWorker() {} @@ -205,3 +208,39 @@ void SearchAndReplaceWorker::replaceElement(Element *element) list.append(element); replaceElement(list); } + +/** + * @brief SearchAndReplaceWorker::replaceIndiText + * Replace all displayed text of independent text of @list + * Each must belong to the same project, if not this function do nothing + * @param list + */ +void SearchAndReplaceWorker::replaceIndiText(QList list) +{ + if (list.isEmpty() || !list.first()->diagram()) { + return; + } + QETProject *project_ = list.first()->diagram()->project(); + for (IndependentTextItem *text : list) { + if (!text->diagram() || + text->diagram()->project() != project_) { + return; + } + } + + project_->undoStack()->beginMacro(QObject::tr("Chercher remplacer des textes independant")); + for (IndependentTextItem *text : list) + { + QString before = text->toPlainText(); + text->setPlainText(m_indi_text); + project_->undoStack()->push(new ChangeDiagramTextCommand(text, before, m_indi_text)); + } + project_->undoStack()->endMacro(); +} + +void SearchAndReplaceWorker::replaceIndiText(IndependentTextItem *text) +{ + QListlist; + list.append(text); + replaceIndiText(list); +} diff --git a/sources/SearchAndReplace/searchandreplaceworker.h b/sources/SearchAndReplace/searchandreplaceworker.h index f009a67a4..5154fcc44 100644 --- a/sources/SearchAndReplace/searchandreplaceworker.h +++ b/sources/SearchAndReplace/searchandreplaceworker.h @@ -24,6 +24,7 @@ class Diagram; class Element; +class IndependentTextItem; /** * @brief The SearchAndReplaceWorker class @@ -39,6 +40,8 @@ class SearchAndReplaceWorker void replaceDiagram(Diagram *diagram); void replaceElement(QList list); void replaceElement(Element *element); + void replaceIndiText(QList list); + void replaceIndiText(IndependentTextItem *text); static QString eraseText() {return QString("XXXXXXXXXXXXXXXXXXX");} static QDate eraseDate() {return QDate(1900, 1, 1);} @@ -46,6 +49,7 @@ class SearchAndReplaceWorker private: TitleBlockProperties m_titleblock_properties; DiagramContext m_element_context; + QString m_indi_text; friend class SearchAndReplaceWidget; }; diff --git a/sources/SearchAndReplace/ui/searchandreplacewidget.cpp b/sources/SearchAndReplace/ui/searchandreplacewidget.cpp index d81cc0426..38ccc7226 100644 --- a/sources/SearchAndReplace/ui/searchandreplacewidget.cpp +++ b/sources/SearchAndReplace/ui/searchandreplacewidget.cpp @@ -867,6 +867,16 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked() m_worker.replaceElement(e.data()); } } + else if (!ui->m_replace_le->text().isEmpty() && + m_text_hash.keys().contains(qtwi)) + { + m_worker.m_indi_text = ui->m_replace_le->text(); + QPointer t = m_text_hash.value(qtwi); + if (t) { + m_worker.replaceIndiText(t.data()); + } + + } } activateNextChecked(); ui->m_replace_pb->setEnabled(ui->m_next_pb->isEnabled()); @@ -878,6 +888,7 @@ 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; @@ -893,6 +904,7 @@ void SearchAndReplaceWidget::on_m_replace_all_pb_clicked() } m_worker.replaceDiagram(diagram_list); } + //Replace text if (ui->m_element_pb->text().endsWith(tr(" [Édité]"))) { QList element_list; @@ -908,6 +920,23 @@ void SearchAndReplaceWidget::on_m_replace_all_pb_clicked() } m_worker.replaceElement(element_list); } + //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()); + } + } + } + m_worker.m_indi_text = ui->m_replace_le->text(); + m_worker.replaceIndiText(text_list ); + } //Change was made, we reload the panel //and search again to keep up to date the tree widget