QElectroTech  0.70
searchandreplacewidget.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "searchandreplacewidget.h"
19 #include "ui_searchandreplacewidget.h"
20 #include "qetdiagrameditor.h"
21 #include "qetproject.h"
22 #include "diagram.h"
23 #include "qeticons.h"
24 #include "element.h"
25 #include "independenttextitem.h"
26 #include "conductor.h"
27 #include "replacefoliowidget.h"
28 #include "replaceelementdialog.h"
29 #include "qetapp.h"
30 #include "replaceconductordialog.h"
31 #include "replaceadvanceddialog.h"
32 #include "dynamicelementtextitem.h"
33 #include "elementtextitemgroup.h"
34 
35 #include <QSettings>
36 
43  QWidget(parent),
44  ui(new Ui::SearchAndReplaceWidget)
45 {
46  ui->setupUi(this);
47  setHideAdvanced(true);
49 
50  connect(ui->m_search_le, &QLineEdit::textEdited, this, &SearchAndReplaceWidget::search);
51 }
52 
58  delete ui;
59 }
60 
68 bool SearchAndReplaceWidget::event(QEvent *event)
69 {
70  if (event->type() == QEvent::Hide)
71  {
72  clear();
73  setHideAdvanced(true);
75  {
76  m_highlighted_element.data()->setHighlighted(false);
77  m_highlighted_element.clear();
78  }
79  }
80  else if (event->type() == QEvent::Show)
81  {
82  ui->m_search_le->setFocus();
83  fillItemsList();
84  m_root_qtwi->setExpanded(true);
85  }
86 
87  return QWidget::event(event);
88 }
89 
96 {
97  disconnect(ui->m_tree_widget, &QTreeWidget::itemChanged, this, &SearchAndReplaceWidget::itemChanged);
98 
99  qDeleteAll(m_diagram_hash.keys());
100  m_diagram_hash.clear();
101 
102  qDeleteAll(m_element_hash.keys());
103  m_element_hash.clear();
104 
105  qDeleteAll(m_text_hash.keys());
106  m_text_hash.clear();
107 
108  qDeleteAll(m_conductor_hash.keys());
109  m_conductor_hash.clear();
110 
111  for (QTreeWidgetItem *qtwi : m_category_qtwi)
112  qtwi->setHidden(false);
113 
114  ui->m_tree_widget->collapseAll();
115  ui->m_tree_widget->clearSelection();
116 
117  ui->m_search_le->clear();
118  ui->m_replace_le->clear();
120  ui->m_search_le->setPalette(QPalette());
121 }
122 
129  m_editor = editor;
130 }
131 
137 {
138  m_root_qtwi = new QTreeWidgetItem(ui->m_tree_widget);
140  m_root_qtwi->setText(0, tr("Correspondance :"));
141  m_root_qtwi->setCheckState(0, Qt::Checked);
143 
144  m_folio_qtwi = new QTreeWidgetItem(m_root_qtwi);
145  m_folio_qtwi->setIcon(0, QET::Icons::Diagram);
146  m_folio_qtwi->setText(0, tr("Folios"));
147  m_folio_qtwi->setCheckState(0, Qt::Checked);
149 
150  m_indi_text_qtwi = new QTreeWidgetItem(m_root_qtwi);
152  m_indi_text_qtwi->setText(0, tr("Champs texte"));
153  m_indi_text_qtwi->setCheckState(0, Qt::Checked);
155 
156  m_elements_qtwi = new QTreeWidgetItem(m_root_qtwi);
158  m_elements_qtwi->setText(0, tr("Eléments"));
159  m_elements_qtwi->setCheckState(0, Qt::Checked);
161 
162  m_simple_elmt_qtwi = new QTreeWidgetItem(m_elements_qtwi);
163  m_simple_elmt_qtwi->setText(0, tr("Eléments simple"));
165  m_simple_elmt_qtwi->setCheckState(0, Qt::Checked);
167 
168  m_master_elmt_qtwi= new QTreeWidgetItem(m_elements_qtwi);
169  m_master_elmt_qtwi->setText(0, tr("Eléments maître"));
171  m_master_elmt_qtwi->setCheckState(0, Qt::Checked);
173 
174  m_slave_elmt_qtwi = new QTreeWidgetItem(m_elements_qtwi);
175  m_slave_elmt_qtwi->setText(0, tr("Eléments esclave"));
177  m_slave_elmt_qtwi->setCheckState(0, Qt::Checked);
179 
180  m_report_elmt_qtwi = new QTreeWidgetItem(m_elements_qtwi);
181  m_report_elmt_qtwi->setText(0, tr("Eléments report de folio"));
183  m_report_elmt_qtwi->setCheckState(0, Qt::Checked);
185 
186  m_terminal_elmt_qtwi = new QTreeWidgetItem(m_elements_qtwi);
187  m_terminal_elmt_qtwi->setText(0, tr("Eléments bornier"));
189  m_terminal_elmt_qtwi->setCheckState(0, Qt::Checked);
192 
193  m_conductor_qtwi = new QTreeWidgetItem(m_root_qtwi);
195  m_conductor_qtwi->setText(0, tr("Conducteurs"));
196  m_conductor_qtwi->setCheckState(0, Qt::Checked);
198 
200 }
201 
208 {
209  ui->m_advanced_pb ->setChecked(!hide);
210  ui->m_replace ->setHidden(hide);
211  ui->m_replace_le ->setHidden(hide);
212  ui->m_folio_pb ->setHidden(hide);
213  ui->m_element_pb ->setHidden(hide);
214  ui->m_conductor_pb ->setHidden(hide);
215  ui->m_tree_widget ->setHidden(hide);
216  ui->m_replace_pb ->setHidden(hide);
217  ui->m_replace_all_pb ->setHidden(hide);
218  ui->m_mode_cb ->setHidden(hide);
219  ui->m_case_sensitive_cb->setHidden(hide);
220  ui->m_advanced_replace_pb->setHidden(hide);
221 }
222 
228 {
229  disconnect(ui->m_tree_widget, &QTreeWidget::itemChanged, this, &SearchAndReplaceWidget::itemChanged);
230 
231  qDeleteAll(m_element_hash.keys());
232  m_element_hash.clear();
233 
234  QETProject *project_ = m_editor->currentProject();
235  if (!project_)
236  {
237  ui->m_replace_all_pb->setDisabled(true);
238  return;
239  }
240  ui->m_replace_all_pb->setEnabled(true);
241  connect(project_, &QETProject::destroyed, this, &SearchAndReplaceWidget::on_m_reload_pb_clicked);
242 
243 
244  DiagramContent dc;
245  for (Diagram *diagram : project_->diagrams())
246  {
247  QString str;
248 
249  QSettings settings;
250  if (settings.value("genericpanel/folio", true).toBool()) {
251  str = diagram->border_and_titleblock.finalfolio();
252  } else {
253  str = QString::number(diagram->folioIndex());
254  }
255 
256  str.append(" " + diagram->title());
257 
258  QTreeWidgetItem *qtwi = new QTreeWidgetItem(m_folio_qtwi);
259  qtwi->setText(0, str);
260  qtwi->setData(0, Qt::UserRole, searchTerms(diagram));
261  qtwi->setCheckState(0, Qt::Checked);
262  m_diagram_hash.insert(qtwi, QPointer<Diagram>(diagram));
263  dc += DiagramContent(diagram, false);
264  }
265 
266  for (Element *elmt : dc.m_elements)
267  addElement(elmt);
268 
269  //Sort child of each "element type" tree item.
270  //we hide, "element type" tree item, if they do not have children
271  for(QTreeWidgetItem *qtwi : m_qtwi_elmts)
272  {
273  qtwi->sortChildren(0, Qt::AscendingOrder);
274  qtwi->setHidden(qtwi->childCount() ? false : true);
275  }
276 
277  for (IndependentTextItem *iti : dc.m_text_fields)
278  {
279  QTreeWidgetItem *qtwi = new QTreeWidgetItem(m_indi_text_qtwi);
280  qtwi->setText(0, iti->toPlainText());
281  qtwi->setCheckState(0, Qt::Checked);
282  qtwi->setData(0, Qt::UserRole, iti->toPlainText());
283  m_text_hash.insert(qtwi, QPointer<IndependentTextItem>(iti));
284  }
285  m_indi_text_qtwi->sortChildren(0, Qt::AscendingOrder);
286 
287  for (Conductor *c : dc.m_potential_conductors)
288  {
289  QTreeWidgetItem *qtwi = new QTreeWidgetItem(m_conductor_qtwi);
290  qtwi->setText(0, c->properties().text);
291  qtwi->setCheckState(0, Qt::Checked);
292  qtwi->setData(0, Qt::UserRole, searchTerms(c));
293  m_conductor_hash.insert(qtwi, QPointer<Conductor>(c));
294  }
295  m_conductor_qtwi->sortChildren(0, Qt::AscendingOrder);
296 
298  connect(ui->m_tree_widget, &QTreeWidget::itemChanged, this, &SearchAndReplaceWidget::itemChanged);
299 }
300 
307 {
308  QTreeWidgetItem *parent = m_elements_qtwi;
309  switch (element->linkType()) {
310  case Element::Simple:
311  parent = m_simple_elmt_qtwi;
312  break;
313  case Element::NextReport:
314  parent = m_report_elmt_qtwi;
315  break;
317  parent = m_report_elmt_qtwi;
318  break;
319  case Element::Master:
320  parent = m_master_elmt_qtwi;
321  break;
322  case Element::Slave:
323  parent = m_slave_elmt_qtwi;
324  break;
325  case Element::Terminale:
326  parent = m_terminal_elmt_qtwi;
327  break;
328  default:
329  break;
330  }
331  QTreeWidgetItem *qtwi = new QTreeWidgetItem(parent);
332  m_element_hash.insert(qtwi, QPointer<Element>(element));
333 
334  QString str;
335  str += element->elementInformations().value("label").toString();
336  if(!str.isEmpty())
337  str += (" ");
338  str += element->elementInformations().value("comment").toString();
339  if (str.isEmpty())
340  str = tr("Inconnue");
341  qtwi->setText(0, str);
342  qtwi->setCheckState(0, Qt::Checked);
343  qtwi->setData(0, Qt::UserRole, searchTerms(element));
344 }
345 
351 {
352  QString str = ui->m_search_le->text();
353  if(str.isEmpty())
354  {
355  for (QTreeWidgetItemIterator it(m_root_qtwi) ; *it ; ++it) {
356  (*it)->setHidden(false);
357  }
358 
359  for (QTreeWidgetItem *item : m_category_qtwi) {
360  item->setExpanded(false);
361  }
362  m_root_qtwi->setExpanded(true);
363 
364  ui->m_tree_widget->setCurrentItem(m_root_qtwi);
365  ui->m_search_le->setPalette(QPalette());
366  }
367  else
368  {
369  for (QTreeWidgetItemIterator it(m_root_qtwi) ; *it ; ++it) {
370  (*it)->setHidden(true);
371  }
372 
373  bool match = false;
374 
375  //Extended search,
376  //on each string stored in column 0 with role : UserRole
377  QList<QTreeWidgetItem *> qtwi_list;
378  qtwi_list.append(m_diagram_hash.keys());
379  qtwi_list.append(m_element_hash.keys());
380  qtwi_list.append(m_text_hash.keys());
381  qtwi_list.append(m_conductor_hash.keys());
382  for (QTreeWidgetItem *qtwi : qtwi_list)
383  {
384  QStringList list = qtwi->data(0, Qt::UserRole).toStringList();
385 
386  if(ui->m_mode_cb->currentIndex() == 0)
387  {
388  //Contain string
389  list = list.filter(str, ui->m_case_sensitive_cb->isChecked()? Qt::CaseSensitive : Qt::CaseInsensitive);
390  }
391  else
392  {
393  //entire word
394  QRegularExpression rx("\\b" + str + "\\b");
395  if (!ui->m_case_sensitive_cb->isChecked()) {
396  rx.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
397  }
398  list = list.filter(rx);
399  }
400  if (!list.isEmpty())
401  {
402  match = true;
403  qtwi->setHidden(false);
404  setVisibleAllParents(qtwi);
405  }
406  }
407 
408  QPalette background = ui->m_search_le->palette();
409  background.setColor(QPalette::Base, match ? QColor("#E0FFF0") : QColor("#FFE0EF"));
410  ui->m_search_le->setPalette(background);
411 
412  //Go to the first occurence
413  ui->m_tree_widget->setCurrentItem(m_root_qtwi);
415  }
416 }
417 
424 void SearchAndReplaceWidget::setVisibleAllParents(QTreeWidgetItem *item, bool expend_parent)
425 {
426  if (item->parent())
427  {
428  QTreeWidgetItem *parent = item->parent();
429  parent->setHidden(false);
430  setVisibleAllParents(parent);
431  parent->setExpanded(expend_parent);
432  }
433 }
434 
441 QTreeWidgetItem *SearchAndReplaceWidget::nextItem(QTreeWidgetItem *item, QTreeWidgetItemIterator::IteratorFlag flags) const
442 {
443  QTreeWidgetItem *qtwi = item;
444  if (!item) {
445  qtwi = ui->m_tree_widget->currentItem();
446  }
447 
448  if (!qtwi) {
449  qtwi = m_root_qtwi;
450  }
451 
452  QTreeWidgetItemIterator it(qtwi, flags);
453 
454  ++it;
455  QTreeWidgetItem *next_ = *it;
456  if (next_) {
457  return next_;
458  }
459  else {
460  return nullptr;
461  }
462 }
463 
470 QTreeWidgetItem *SearchAndReplaceWidget::previousItem(QTreeWidgetItem *item, QTreeWidgetItemIterator::IteratorFlag flags) const
471 {
472  QTreeWidgetItem *qtwi = item;
473  if (!item) {
474  qtwi = ui->m_tree_widget->currentItem();
475  }
476 
477  if (!qtwi) {
478  qtwi = m_root_qtwi;
479  }
480 
481  QTreeWidgetItemIterator it(qtwi, flags);
482 
483  --it;
484  QTreeWidgetItem *previous_ = *it;
485  if (previous_) {
486  return previous_;
487  }
488  else {
489  return nullptr;
490  }
491 }
492 
499 {
500  QTreeWidgetItem *item_ = ui->m_tree_widget->currentItem();
501  if (!item_)
502  {
503  ui->m_next_pb->setEnabled(true);
504  ui->m_previous_pb->setDisabled(true);
505  return;
506  }
507 
508  QTreeWidgetItem *next_ = item_;
509  do
510  {
511  next_ = nextItem(next_, QTreeWidgetItemIterator::NotHidden);
512  if (!next_)
513  {
514  ui->m_next_pb->setDisabled(true);
515  break;
516  }
517  else if (!m_category_qtwi.contains(next_))
518  {
519  ui->m_next_pb->setEnabled(true);
520  break;
521  }
522  } while (m_category_qtwi.contains(next_));
523 
524  QTreeWidgetItem *previous_ = item_;
525  do
526  {
527  previous_ = previousItem(previous_, QTreeWidgetItemIterator::NotHidden);
528  if (!previous_)
529  {
530  ui->m_previous_pb->setDisabled(true);
531  break;
532  }
533  else if (!m_category_qtwi.contains(previous_))
534  {
535  ui->m_previous_pb->setEnabled(true);
536  break;
537  }
538  } while (m_category_qtwi.contains(previous_));
539 }
540 
548 void SearchAndReplaceWidget::itemChanged(QTreeWidgetItem *item, int column)
549 {
550  Q_UNUSED(column);
551  ui->m_tree_widget->blockSignals(true);
552 
553  setChildCheckState(item, item->checkState(0));
555 
556  ui->m_tree_widget->blockSignals(false);
557 }
558 
565 void SearchAndReplaceWidget::setChildCheckState(QTreeWidgetItem *item, Qt::CheckState check, bool deep)
566 {
567  for (int i=0 ; i<item->childCount() ; ++i)
568  {
569  item->child(i)->setCheckState(0, check);
570  if (deep && item->child(i)->childCount()) {
571  setChildCheckState(item->child(i), check, deep);
572  }
573  }
574 }
575 
581 void SearchAndReplaceWidget::updateParentCheckState(QTreeWidgetItem *item, bool all_parents)
582 {
583  QTreeWidgetItem *parent = item->parent();
584 
585  if (!parent) {
586  parent = item;
587  }
588 
589  int check=0,
590  partially=0;
591 
592  for (int i=0 ; i<parent->childCount() ; ++i)
593  {
594  switch (parent->child(i)->checkState(0)) {
595  case Qt::Checked:
596  ++check;
597  break;
598  case Qt::PartiallyChecked:
599  ++partially;
600  break;
601  default:
602  break;
603  }
604  }
605 
606  if (check == parent->childCount()) {
607  parent->setCheckState(0, Qt::Checked);
608  }
609  else if (partially || check) {
610  parent->setCheckState(0, Qt::PartiallyChecked);
611  }
612  else {
613  parent->setCheckState(0, Qt::Unchecked);
614  }
615 
616  if (all_parents && item->parent()) {
617  updateParentCheckState(parent, all_parents);
618  }
619 }
620 
626 {
627  //Next button is disabled, so there is not a next item.
628  if (!ui->m_next_pb->isEnabled())
629  return;
630 
631  do {
633  } while ((ui->m_tree_widget->currentItem()->checkState(0) != Qt::Checked) &&
634  ui->m_next_pb->isEnabled());
635 }
636 
642 {
643  QList <Diagram *> diagram_list;
644 
645  for (QTreeWidgetItem *qtwi : m_diagram_hash.keys())
646  {
647  if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked)
648  {
649  QPointer <Diagram> p = m_diagram_hash.value(qtwi);
650  if (p) {
651  diagram_list.append(p.data());
652  }
653  }
654  }
655 
656  return diagram_list;
657 }
658 
664 {
665  QList <Element *> element_list;
666 
667  for (QTreeWidgetItem *qtwi : m_element_hash.keys())
668  {
669  if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked)
670  {
671  QPointer <Element> p = m_element_hash.value(qtwi);
672  if (p) {
673  element_list.append(p.data());
674  }
675  }
676  }
677 
678  return element_list;
679 }
680 
686 {
687  QList <Conductor *> conductor_list;
688 
689  for (QTreeWidgetItem *qtwi : m_conductor_hash.keys())
690  {
691  if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked)
692  {
693  QPointer <Conductor> c = m_conductor_hash.value(qtwi);
694  if (c) {
695  conductor_list.append(c.data());
696  }
697  }
698  }
699 
700  return conductor_list;
701 }
702 
707 QList<IndependentTextItem *> SearchAndReplaceWidget::selectedText() const
708 {
709  QList <IndependentTextItem *> text_list;
710 
711  for(QTreeWidgetItem *qtwi : m_text_hash.keys())
712  {
713  if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked)
714  {
715  QPointer<IndependentTextItem> t = m_text_hash.value(qtwi);
716  if (t) {
717  text_list.append(t.data());
718  }
719  }
720  }
721 
722  return text_list;
723 }
724 
731 {
732  QStringList list;
734  list.append(prop.title);
735  list.append(prop.author);
736  list.append(prop.filename);
737  list.append(prop.plant);
738  list.append(prop.locmach);
739  list.append(prop.indexrev);
740  list.append(prop.folio);
741  list.append(prop.date.toString());
742  for (QString key : prop.context.keys()) {
743  list.append(prop.context.value(key).toString());
744  }
745 
746  return list;
747 }
748 
755 {
756  QStringList list;
757  DiagramContext context = element->elementInformations();
758  for (QString key : QETApp::elementInfoKeys())
759  {
760  QString str = context.value(key).toString();
761  if (!str.isEmpty()) {
762  list.append(str);
763  }
764  }
765 
766  for (DynamicElementTextItem *deti : element->dynamicTextItems())
767  {
768  if (deti->textFrom() == DynamicElementTextItem::UserText || deti->textFrom() == DynamicElementTextItem::CompositeText) {
769  list.append(deti->toPlainText());
770  }
771  }
772  for (ElementTextItemGroup *group : element->textGroups())
773  {
774  list.append(group->name());
775 
776  for (DynamicElementTextItem *deti : group->texts()) {
777  if (deti->textFrom() == DynamicElementTextItem::UserText || deti->textFrom() == DynamicElementTextItem::CompositeText) {
778  list.append(deti->toPlainText());
779  }
780  }
781  }
782 
783  return list;
784 }
785 
792 {
793  QStringList list;
794  ConductorProperties properties = conductor->properties();
795 
796  list.append(properties.text);
797  list.append(properties.m_function);
798  list.append(properties.m_tension_protocol);
799 
800  return list;
801 }
802 
804  this->setHidden(true);
805 }
806 
808  setHideAdvanced(!checked);
809 }
810 
811 void SearchAndReplaceWidget::on_m_tree_widget_itemDoubleClicked(QTreeWidgetItem *item, int column)
812 {
813  Q_UNUSED(column);
814 
815  if (m_diagram_hash.keys().contains(item))
816  {
817  QPointer<Diagram> diagram = m_diagram_hash.value(item);
818  if(diagram) {
819  diagram.data()->showMe();
820  }
821  }
822  else if (m_element_hash.keys().contains(item))
823  {
824  QPointer<Element> elmt = m_element_hash.value(item);
825  if (elmt) {
826  elmt.data()->diagram()->showMe();
827  }
828  }
829  else if (m_text_hash.keys().contains(item))
830  {
831  QPointer<IndependentTextItem> text = m_text_hash.value(item);
832  if (text) {
833  text.data()->diagram()->showMe();
834  }
835  }
836  else if (m_conductor_hash.keys().contains(item))
837  {
838  QPointer<Conductor> cond = m_conductor_hash.value(item);
839  if (cond) {
840  cond.data()->diagram()->showMe();
841  }
842  }
843 }
844 
846 {
847  clear();
849  {
850  m_highlighted_element.data()->setHighlighted(false);
851  m_highlighted_element.clear();
852  }
853  if (m_last_selected)
854  {
855  m_last_selected.data()->setSelected(false);
856  m_last_selected.clear();
857  }
858 
859  ui->m_search_le->setFocus();
860  fillItemsList();
861  m_root_qtwi->setExpanded(true);
862 }
863 
864 void SearchAndReplaceWidget::on_m_tree_widget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
865 {
866  Q_UNUSED(previous);
867 
869  m_highlighted_element.data()->setHighlighted(false);
870  }
871  if (m_last_selected) {
872  m_last_selected.data()->setSelected(false);
873  }
874 
875  if (m_element_hash.keys().contains(current))
876  {
877  QPointer<Element> elmt = m_element_hash.value(current);
878  if (elmt)
879  {
880  m_highlighted_element = elmt;
881  elmt.data()->setHighlighted(true);
882  }
883  }
884  else if (m_text_hash.keys().contains(current))
885  {
886  QPointer<IndependentTextItem> text = m_text_hash.value(current);
887  if (text)
888  {
889  text.data()->setSelected(true);
890  m_last_selected = text;
891  }
892  }
893  else if (m_conductor_hash.keys().contains(current))
894  {
895  QPointer<Conductor> cond = m_conductor_hash.value(current);
896  if (cond)
897  {
898  cond.data()->setSelected(true);
899  m_last_selected = cond;
900  }
901  }
902 
904  if (!current) {
905  return;
906  }
907 
908  if (current->checkState(0) == Qt::Checked && !m_category_qtwi.contains(current)) {
909  ui->m_replace_pb->setEnabled(true);
910  } else {
911  ui->m_replace_pb->setDisabled(true);
912  }
913 }
914 
916 {
917  QTreeWidgetItem *item = nullptr;
918 
919  do
920  {
921  item = nextItem(nullptr, QTreeWidgetItemIterator::NotHidden);
922  if (item) {
923  ui->m_tree_widget->setCurrentItem(item);
924  } else {
925  return;
926  }
927  } while (m_category_qtwi.contains(item));
928 
929  ui->m_tree_widget->setCurrentItem(item);
930  ui->m_tree_widget->scrollToItem(item);
932 }
933 
935 {
936  QTreeWidgetItem *item = nullptr;
937 
938  do
939  {
940  item = previousItem(nullptr, QTreeWidgetItemIterator::NotHidden);
941  if (item) {
942  ui->m_tree_widget->setCurrentItem(item);
943  }
944  else
945  {
946  //There is not a previous selected item, so the current item is m_root_qtwi but we know he must not be selected
947  //we user click on the button 'next item'.
948  //So we select the first selectable item by calling on_m_next_pb_clicked
950  return;
951  }
952  } while (m_category_qtwi.contains(item));
953 
954  ui->m_tree_widget->setCurrentItem(item);
955  ui->m_tree_widget->scrollToItem(item);
957 }
958 
960 {
961  ReplaceFolioDialog *dialog = new ReplaceFolioDialog(this);
963 
964  int result = dialog->exec();
965  if (result == QDialogButtonBox::AcceptRole)
966  {
967  QString text = ui->m_folio_pb->text();
968  if (!text.endsWith(tr(" [édité]"))) {
969  text.append(tr(" [édité]"));
970  }
971  ui->m_folio_pb->setText(text);
973  }
974  else if (result == QDialogButtonBox::ResetRole)
975  {
976  QString text = ui->m_folio_pb->text();
977  if (text.endsWith(tr(" [édité]"))) {
978  text.remove(tr(" [édité]"));
979  }
980  ui->m_folio_pb->setText(text);
982  }
983 }
984 
990 {
991  QTreeWidgetItem *qtwi = ui->m_tree_widget->currentItem();
992  if(!qtwi) {
993  return;
994  }
995  if (!m_category_qtwi.contains(qtwi) && qtwi->checkState(0) == Qt::Checked)
996  {
997  if (ui->m_folio_pb->text().endsWith(tr(" [édité]")) &&
998  m_diagram_hash.keys().contains(qtwi))
999  {
1000  QPointer<Diagram> d = m_diagram_hash.value(qtwi);
1001  if (d) {
1002  m_worker.replaceDiagram(d.data());
1003  }
1004  }
1005  else if (ui->m_element_pb->text().endsWith(tr(" [édité]")) &&
1006  m_element_hash.keys().contains(qtwi))
1007  {
1008  QPointer<Element> e = m_element_hash.value(qtwi);
1009  if (e) {
1010  m_worker.replaceElement(e.data());
1011  }
1012  }
1013  else if (!ui->m_replace_le->text().isEmpty() &&
1014  m_text_hash.keys().contains(qtwi))
1015  {
1016  m_worker.m_indi_text = ui->m_replace_le->text();
1017  QPointer<IndependentTextItem> t = m_text_hash.value(qtwi);
1018  if (t) {
1019  m_worker.replaceIndiText(t.data());
1020  }
1021 
1022  }
1023  else if (ui->m_conductor_pb->text().endsWith(tr(" [édité]")) &&
1024  m_conductor_hash.keys().contains(qtwi))
1025  {
1026  QPointer<Conductor> c = m_conductor_hash.value(qtwi);
1027  if (c) {
1028  m_worker.replaceConductor(c.data());
1029  }
1030  }
1031 
1032  //Replace advanced
1033  if (ui->m_advanced_replace_pb->text().endsWith(tr(" [édité]")))
1034  {
1035  QList <Diagram *>dl;
1036  QList <Element *>el;
1037  QList <IndependentTextItem *>tl;
1038  QList <Conductor *>cl;
1039 
1040  if (m_diagram_hash.keys().contains(qtwi))
1041  {
1042  QPointer<Diagram> d = m_diagram_hash.value(qtwi);
1043  if (d) {
1044  dl.append(d.data());
1045  }
1046  }
1047  else if (m_element_hash.keys().contains(qtwi))
1048  {
1049  QPointer<Element> e = m_element_hash.value(qtwi);
1050  if (e) {
1051  el.append(e.data());
1052  }
1053  }
1054  else if (m_text_hash.keys().contains(qtwi))
1055  {
1056  QPointer<IndependentTextItem> t = m_text_hash.value(qtwi);
1057  if (t) {
1058  tl.append(t.data());
1059  }
1060  }
1061  else if (m_conductor_hash.keys().contains(qtwi))
1062  {
1063  QPointer<Conductor> c = m_conductor_hash.value(qtwi);
1064  if (c) {
1065  cl.append(c.data());
1066  }
1067  }
1068 
1069  m_worker.replaceAdvanced(dl, el, tl, cl);
1070  }
1071  }
1072 
1074  ui->m_replace_pb->setEnabled(ui->m_next_pb->isEnabled());
1075 }
1076 
1082 {
1083  if (ui->m_folio_pb->text().endsWith(tr(" [édité]"))) {
1085  }
1086  if (ui->m_element_pb->text().endsWith(tr(" [édité]"))) {
1088  }
1089  if (!ui->m_replace_le->text().isEmpty()) {
1090  m_worker.m_indi_text = ui->m_replace_le->text();
1092  }
1093  if (ui->m_conductor_pb->text().endsWith(tr(" [édité]"))) {
1095  }
1096  if (ui->m_advanced_replace_pb->text().endsWith(tr(" [édité]"))) {
1097 
1099  }
1100 
1101  //Change was made, we reload the panel
1102  //and search again to keep up to date the tree widget
1103  //and the match item of search
1104  QString txt = ui->m_search_le->text();
1106  ui->m_search_le->setText(txt);
1107  search();
1108 }
1109 
1111 {
1113 
1114  int result = dialog->exec();
1115  if (result == QDialogButtonBox::AcceptRole)
1116  {
1117  QString text = ui->m_element_pb->text();
1118  if (!text.endsWith(tr(" [édité]"))) {
1119  text.append(tr(" [édité]"));
1120  }
1121  ui->m_element_pb->setText(text);
1122  m_worker.m_element_context = dialog->context();
1123  }
1124  else if (result == QDialogButtonBox::ResetRole)
1125  {
1126  QString text = ui->m_element_pb->text();
1127  if (text.endsWith(tr(" [édité]"))) {
1128  text.remove(tr(" [édité]"));
1129  }
1130  ui->m_element_pb->setText(text);
1132  }
1133 }
1134 
1141 {
1142  Q_UNUSED(index);
1143  search();
1144 }
1145 
1152 {
1153  Q_UNUSED(arg1);
1154  search();
1155 }
1156 
1162 {
1164  int result = dialog->exec();
1165 
1166  if (result == QDialogButtonBox::AcceptRole)
1167  {
1168  QString text = ui->m_conductor_pb->text();
1169  if (!text.endsWith(tr(" [édité]"))) {
1170  text.append(tr(" [édité]"));
1171  }
1172  ui->m_conductor_pb->setText(text);
1174  }
1175  else if (result == QDialogButtonBox::ResetRole)
1176  {
1177  QString text = ui->m_conductor_pb->text();
1178  if (text.endsWith(tr(" [édité]"))) {
1179  text.remove(tr(" [édité]"));
1180  }
1181  ui->m_conductor_pb->setText(text);
1183  }
1184 }
1185 
1191 {
1193  int result = dialog->exec();
1194 
1195  if (result == QDialogButtonBox::AcceptRole)
1196  {
1197  QString text = ui->m_advanced_replace_pb->text();
1198  if (!text.endsWith(tr(" [édité]"))) {
1199  text.append(tr(" [édité]"));
1200  }
1201  ui->m_advanced_replace_pb->setText(text);
1203  }
1204  else if (result == QDialogButtonBox::ResetRole)
1205  {
1206  QString text = ui->m_advanced_replace_pb->text();
1207  if (text.endsWith(tr(" [édité]"))) {
1208  text.remove(tr(" [édité]"));
1209  }
1210  ui->m_advanced_replace_pb->setText(text);
1212  }
1213 }
QList< Conductor * > m_potential_conductors
QString locmach
Location(displayed by the default template)
QList< Diagram * > diagrams() const
Definition: qetproject.cpp:210
ConductorProperties properties
Conductor::properties.
Definition: conductor.h:48
virtual kind linkType() const
Definition: element.h:138
QIcon Element
Definition: qeticons.cpp:83
QPointer< Element > m_highlighted_element
QList< Diagram * > selectedDiagram() const
SearchAndReplaceWidget::selectedDiagram.
QTreeWidgetItem * m_report_elmt_qtwi
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
void updateParentCheckState(QTreeWidgetItem *item, bool all_parents=true)
SearchAndReplaceWidget::updateParentCheckState.
QString plant
Plant (displayed by the default template)
void setEditor(QETDiagramEditor *editor)
SearchAndReplaceWidget::setEditor Set the diagram editor of this widget.
void replaceDiagram(QList< Diagram *> diagram_list)
SearchAndReplaceWorker::replaceDiagram Replace all properties of each diagram in , by the current titleblock propertie of this worker.
void on_m_advanced_replace_pb_clicked()
SearchAndReplaceWidget::on_m_advanced_replace_pb_clicked Open the advanced editor.
DiagramContext elementInformations() const
Definition: element.h:89
~SearchAndReplaceWidget()
SearchAndReplaceWidget::~SearchAndReplaceWidget Destructor.
QTreeWidgetItem * m_elements_qtwi
void fillItemsList()
SearchAndReplaceWidget::fillItemsList Fill the tree.
QTreeWidgetItem * m_slave_elmt_qtwi
QIcon ElementTerminal
Definition: qeticons.cpp:219
QList< Element * > selectedElement() const
SearchAndReplaceWidget::selectedElement.
void on_m_advanced_pb_toggled(bool checked)
TitleBlockProperties exportTitleBlock()
void on_m_replace_all_pb_clicked()
SearchAndReplaceWidget::on_m_replace_all_pb_clicked Replace all checked item.
QIcon Hide
Definition: qeticons.cpp:113
void activateNextChecked()
SearchAndReplaceWidget::activateNextChecked Activate the next checked (and visible) item...
QTreeWidgetItem * m_simple_elmt_qtwi
QTreeWidgetItem * previousItem(QTreeWidgetItem *item=nullptr, QTreeWidgetItemIterator::IteratorFlag flags=QTreeWidgetItemIterator::All) const
SearchAndReplaceWidget::previousItem.
QVariant value(const QString &key) const
advancedReplaceStruct m_advanced_struct
QIcon PartText
Definition: qeticons.cpp:134
QHash< QTreeWidgetItem *, QPointer< Diagram > > m_diagram_hash
QList< QTreeWidgetItem * > m_qtwi_elmts
void setTitleBlockProperties(const TitleBlockProperties &properties)
ReplaceFolioDialog::setTitleBlockProperties.
void updateNextPreviousButtons()
SearchAndReplaceWidget::updateNextPreviousButtons According to the current item, if there is a next o...
static ConductorProperties invalidConductorProperties()
QDate date
Date (displayed by the default template)
void search()
SearchAndReplaceWidget::search Start the search.
QIcon Conductor
Definition: qeticons.cpp:35
QTreeWidgetItem * m_folio_qtwi
QString filename
Filename (displayed by the default template)
QIcon ProjectProperties
Definition: qeticons.cpp:149
void on_m_conductor_pb_clicked()
SearchAndReplaceWidget::on_m_conductor_pb_clicked Open a dialog to edit the condutor properties...
void setChildCheckState(QTreeWidgetItem *item, Qt::CheckState check, bool deep=true)
SearchAndReplaceWidget::setChildCheckState.
The ReplaceConductorDialog class A Qdialog to edit a conductor properties, use for the search and rep...
Ui::SearchAndReplaceWidget * ui
QSet< IndependentTextItem * > m_text_fields
QTreeWidgetItem * nextItem(QTreeWidgetItem *item=nullptr, QTreeWidgetItemIterator::IteratorFlag flags=QTreeWidgetItemIterator::All) const
SearchAndReplaceWidget::nextItem.
QList< QString > keys(KeyOrder=None) const
DiagramContext context
Container for the additional, user-defined fields.
QList< QTreeWidgetItem * > m_category_qtwi
void itemChanged(QTreeWidgetItem *item, int column)
SearchAndReplaceWidget::itemChanged Reimplemented from QTreeWidget. Use to update the check state of ...
QTreeWidgetItem * m_indi_text_qtwi
QHash< QTreeWidgetItem *, QPointer< IndependentTextItem > > m_text_hash
QTreeWidgetItem * m_terminal_elmt_qtwi
void addElement(Element *element)
SearchAndReplaceWidget::addElement Add a tree widget item for .
SearchAndReplaceWorker m_worker
TitleBlockProperties titleBlockProperties() const
ReplaceFolioDialog::titleBlockProperties.
void on_m_replace_pb_clicked()
SearchAndReplaceWidget::on_m_replace_pb_clicked Replace the current selection.
void on_m_tree_widget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
void replaceIndiText(QList< IndependentTextItem *> list)
SearchAndReplaceWorker::replaceIndiText Replace all displayed text of independent text of Each must ...
QIcon tr
Definition: qeticons.cpp:204
static QStringList elementInfoKeys()
QETApp::elementInfoKeys.
Definition: qetapp.cpp:289
QList< Conductor * > selectedConductor() const
SearchAndReplaceWidget::selectedConductor.
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
void replaceElement(QList< Element *> list)
SearchAndReplaceWorker::replaceElement Replace all properties of each elements in All element must b...
QList< Element * > m_elements
void on_m_mode_cb_currentIndexChanged(int index)
SearchAndReplaceWidget::on_m_mode_cb_currentIndexChanged Update the search when user change mode...
void setUpTreeItems()
SearchAndReplaceWidget::setUpTreeItems Set up the main tree widget items.
QString author
Author of the diagram/folio (displayed by the default template)
DiagramContext context() const
ReplaceElementDialog::context.
advancedReplaceStruct advancedStruct() const
replaceAdvancedDialog::advancedStruct
void clear()
SearchAndReplaceWidget::clear Clear the content of the search and replace line edit Clear all tree it...
void on_m_tree_widget_itemDoubleClicked(QTreeWidgetItem *item, int column)
QString indexrev
Revision Index (displayed by the default template)
QHash< QTreeWidgetItem *, QPointer< Element > > m_element_hash
TitleBlockProperties m_titleblock_properties
QHash< QTreeWidgetItem *, QPointer< Conductor > > m_conductor_hash
void replaceConductor(QList< Conductor *> list)
SearchAndReplaceWorker::replaceConductor Replace all properties of each conductor in All conductor m...
void on_m_case_sensitive_cb_stateChanged(int arg1)
SearchAndReplaceWidget::on_m_case_sensitive_cb_stateChanged Update the search when change the case se...
bool event(QEvent *event) override
SearchAndReplaceWidget::event Reimplemented to clear the the lines edit and hide the advanced widgets...
void setVisibleAllParents(QTreeWidgetItem *item, bool expend_parent=true)
SearchAndReplaceWidget::setVisibleAllParents Set visible all parents of until the invisible root ite...
QPointer< QGraphicsObject > m_last_selected
QETProject * currentProject() const
QETDiagramEditor::currentProject.
QTreeWidgetItem * m_conductor_qtwi
void setHideAdvanced(bool hide) const
SearchAndReplaceWidget::setHideAdvanced Hide advanced widgets.
QList< IndependentTextItem * > selectedText() const
SearchAndReplaceWidget::selectedText.
QString folio
Folio information (displayed by the default template)
QTreeWidgetItem * m_master_elmt_qtwi
void replaceAdvanced(QList< Diagram *> diagrams=QList< Diagram *>(), QList< Element *> elements=QList< Element *>(), QList< IndependentTextItem *> texts=QList< IndependentTextItem *>(), QList< Conductor *> conductors=QList< Conductor *>())
SearchAndReplaceWorker::replaceAdvanced Apply the change of text according to the current advancedStr...
QIcon ElementSlave
Definition: qeticons.cpp:217
QIcon FolioXrefComing
Definition: qeticons.cpp:218
QIcon ElementMaster
Definition: qeticons.cpp:216
BorderTitleBlock border_and_titleblock
Diagram dimensions and title block.
Definition: diagram.h:74
ConductorProperties m_conductor_properties
QList< DynamicElementTextItem * > dynamicTextItems() const
Element::dynamicTextItems.
Definition: element.cpp:1197
QString title
Folio title (displayed by the default template)
QIcon it
Definition: qeticons.cpp:196
SearchAndReplaceWidget(QWidget *parent=nullptr)
SearchAndReplaceWidget::SearchAndReplaceWidget Constructor.
QIcon Diagram
Definition: qeticons.cpp:43
ConductorProperties properties() const
ReplaceConductorDialog::properties.
QList< ElementTextItemGroup * > textGroups() const
Element::textGroups.
Definition: element.cpp:1298
static QStringList searchTerms(Diagram *diagram)
SearchAndReplaceWidget::searchTerms.