mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Search and replace : Independent text item can be changed (and mass changed) through the search and replace widget.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5582 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -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<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);
|
||||
}
|
||||
|
||||
@@ -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 <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 @@ class SearchAndReplaceWorker
|
||||
private:
|
||||
TitleBlockProperties m_titleblock_properties;
|
||||
DiagramContext m_element_context;
|
||||
QString m_indi_text;
|
||||
|
||||
friend class SearchAndReplaceWidget;
|
||||
};
|
||||
|
||||
@@ -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<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_pb_clicked()
|
||||
*/
|
||||
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 @@ 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 *> 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 <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
|
||||
|
||||
Reference in New Issue
Block a user