[qet] qet/qet: [5582] Search and replace : Independent text item can be changed (and mass changed) through the search and replace widget.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 5582
Author:   blacksun
Date:     2018-11-10 14:32:27 +0100 (Sat, 10 Nov 2018)
Log Message:
-----------
Search and replace : Independent text item can be changed (and mass changed) through the search and replace widget.

Modified Paths:
--------------
    trunk/sources/SearchAndReplace/searchandreplaceworker.cpp
    trunk/sources/SearchAndReplace/searchandreplaceworker.h
    trunk/sources/SearchAndReplace/ui/searchandreplacewidget.cpp

Modified: trunk/sources/SearchAndReplace/searchandreplaceworker.cpp
===================================================================
--- trunk/sources/SearchAndReplace/searchandreplaceworker.cpp	2018-11-10 12:46:46 UTC (rev 5581)
+++ trunk/sources/SearchAndReplace/searchandreplaceworker.cpp	2018-11-10 13:32:27 UTC (rev 5582)
@@ -21,7 +21,10 @@
 #include "changeelementinformationcommand.h"
 #include "element.h"
 #include "qetapp.h"
+#include "independenttextitem.h"
+#include "diagramcommands.h"
 
+
 SearchAndReplaceWorker::SearchAndReplaceWorker()
 {}
 
@@ -205,3 +208,39 @@
 	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<IndependentTextItem *> 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)
+{
+	QList<IndependentTextItem *>list;
+	list.append(text);
+	replaceIndiText(list);
+}

Modified: trunk/sources/SearchAndReplace/searchandreplaceworker.h
===================================================================
--- trunk/sources/SearchAndReplace/searchandreplaceworker.h	2018-11-10 12:46:46 UTC (rev 5581)
+++ trunk/sources/SearchAndReplace/searchandreplaceworker.h	2018-11-10 13:32:27 UTC (rev 5582)
@@ -24,6 +24,7 @@
 
 class Diagram;
 class Element;
+class IndependentTextItem;
 
 /**
  * @brief The SearchAndReplaceWorker class
@@ -39,6 +40,8 @@
 		void replaceDiagram(Diagram *diagram);
 		void replaceElement(QList <Element *> list);
 		void replaceElement(Element *element);
+		void replaceIndiText(QList<IndependentTextItem *> list);
+		void replaceIndiText(IndependentTextItem *text);
 		
 		static QString eraseText() {return QString("XXXXXXXXXXXXXXXXXXX");}
 		static QDate eraseDate() {return QDate(1900, 1, 1);}
@@ -46,6 +49,7 @@
 	private:
 		TitleBlockProperties m_titleblock_properties;
 		DiagramContext m_element_context;
+		QString m_indi_text;
 		
 		friend class SearchAndReplaceWidget;
 };

Modified: trunk/sources/SearchAndReplace/ui/searchandreplacewidget.cpp
===================================================================
--- trunk/sources/SearchAndReplace/ui/searchandreplacewidget.cpp	2018-11-10 12:46:46 UTC (rev 5581)
+++ trunk/sources/SearchAndReplace/ui/searchandreplacewidget.cpp	2018-11-10 13:32:27 UTC (rev 5582)
@@ -867,6 +867,16 @@
 				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<IndependentTextItem> 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_all_pb_clicked()
 {
+		//Replace folio
     if (ui->m_folio_pb->text().endsWith(tr(" [Édité]")))
 	{
 		QList <Diagram *> diagram_list;
@@ -893,6 +904,7 @@
 		}
 		m_worker.replaceDiagram(diagram_list);
 	}
+		//Replace text
 	if (ui->m_element_pb->text().endsWith(tr(" [Édité]")))
 	{
 		QList <Element *> element_list;
@@ -908,6 +920,23 @@
 		}
 		m_worker.replaceElement(element_list);
 	}
+		//Replace indi text
+	if (!ui->m_replace_le->text().isEmpty())
+	{
+		QList <IndependentTextItem*> text_list;
+		for(QTreeWidgetItem *qtwi : m_text_hash.keys())
+		{
+			if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked)
+			{
+				QPointer<IndependentTextItem> 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


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/