QElectroTech  0.70
searchandreplacewidget.h
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 #ifndef SEARCHANDREPLACEWIDGET_H
19 #define SEARCHANDREPLACEWIDGET_H
20 
21 #include <QWidget>
22 #include <QTreeWidgetItemIterator>
23 
24 #include "element.h"
25 #include "independenttextitem.h"
26 #include "searchandreplaceworker.h"
27 
28 class QTreeWidgetItem;
29 
30 namespace Ui {
32 }
33 
34 class QETDiagramEditor;
35 
36 class SearchAndReplaceWidget : public QWidget
37 {
38  Q_OBJECT
39 
40  public:
41  explicit SearchAndReplaceWidget(QWidget *parent = nullptr);
43 
44  bool event(QEvent *event) override;
45  void clear();
46  void setEditor(QETDiagramEditor *editor);
47 
48  private:
49  void setUpTreeItems();
50  void setHideAdvanced(bool hide) const;
51  void fillItemsList();
52  void addElement(Element *element);
53  void search();
54 
55  void setVisibleAllParents(QTreeWidgetItem *item, bool expend_parent = true);
56  QTreeWidgetItem *nextItem(QTreeWidgetItem *item=nullptr, QTreeWidgetItemIterator::IteratorFlag flags = QTreeWidgetItemIterator::All) const;
57  QTreeWidgetItem *previousItem(QTreeWidgetItem *item=nullptr, QTreeWidgetItemIterator::IteratorFlag flags = QTreeWidgetItemIterator::All) const;
59  void itemChanged(QTreeWidgetItem *item, int column);
60  void setChildCheckState(QTreeWidgetItem *item, Qt::CheckState check, bool deep = true);
61  void updateParentCheckState(QTreeWidgetItem *item, bool all_parents = true);
62  void activateNextChecked();
63  QList<Diagram *> selectedDiagram() const;
64  QList<Element *> selectedElement() const;
65  QList<Conductor *> selectedConductor() const;
66  QList<IndependentTextItem *> selectedText() const;
67 
68  static QStringList searchTerms(Diagram *diagram);
69  static QStringList searchTerms(Element *element);
70  static QStringList searchTerms(Conductor *conductor);
71  static QStringList searchTerms(QString str);
72 
73  private slots:
75  void on_m_advanced_pb_toggled(bool checked);
76  void on_m_tree_widget_itemDoubleClicked(QTreeWidgetItem *item, int column);
77  void on_m_reload_pb_clicked();
78  void on_m_tree_widget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
79  void on_m_next_pb_clicked();
81  void on_m_folio_pb_clicked();
85  void on_m_mode_cb_currentIndexChanged(int index);
89 
90  private:
91  Ui::SearchAndReplaceWidget *ui;
93  QTreeWidgetItem *m_root_qtwi = nullptr,
94  *m_folio_qtwi = nullptr,
95  *m_indi_text_qtwi = nullptr,
96  *m_elements_qtwi = nullptr,
97  *m_simple_elmt_qtwi = nullptr,
98  *m_master_elmt_qtwi = nullptr,
99  *m_slave_elmt_qtwi = nullptr,
100  *m_report_elmt_qtwi = nullptr,
102  *m_conductor_qtwi = nullptr;
103  QList<QTreeWidgetItem *> m_qtwi_elmts;
104  QList<QTreeWidgetItem *> m_category_qtwi;
105  QHash<QTreeWidgetItem *, QPointer <Element>> m_element_hash;
106  QHash<QTreeWidgetItem *, QPointer <IndependentTextItem>> m_text_hash;
107  QHash<QTreeWidgetItem *, QPointer <Conductor>> m_conductor_hash;
108  QPointer<Element> m_highlighted_element;
109  QPointer<QGraphicsObject> m_last_selected;
110  QHash<QTreeWidgetItem *, QPointer <Diagram>> m_diagram_hash;
112 };
113 
114 #endif // SEARCHANDREPLACEWIDGET_H
QPointer< Element > m_highlighted_element
QList< Diagram * > selectedDiagram() const
SearchAndReplaceWidget::selectedDiagram.
QTreeWidgetItem * m_report_elmt_qtwi
void updateParentCheckState(QTreeWidgetItem *item, bool all_parents=true)
SearchAndReplaceWidget::updateParentCheckState.
void setEditor(QETDiagramEditor *editor)
SearchAndReplaceWidget::setEditor Set the diagram editor of this widget.
void on_m_advanced_replace_pb_clicked()
SearchAndReplaceWidget::on_m_advanced_replace_pb_clicked Open the advanced editor.
~SearchAndReplaceWidget()
SearchAndReplaceWidget::~SearchAndReplaceWidget Destructor.
QTreeWidgetItem * m_elements_qtwi
void fillItemsList()
SearchAndReplaceWidget::fillItemsList Fill the tree.
QTreeWidgetItem * m_slave_elmt_qtwi
QList< Element * > selectedElement() const
SearchAndReplaceWidget::selectedElement.
void on_m_advanced_pb_toggled(bool checked)
void on_m_replace_all_pb_clicked()
SearchAndReplaceWidget::on_m_replace_all_pb_clicked Replace all checked item.
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.
QHash< QTreeWidgetItem *, QPointer< Diagram > > m_diagram_hash
QList< QTreeWidgetItem * > m_qtwi_elmts
void updateNextPreviousButtons()
SearchAndReplaceWidget::updateNextPreviousButtons According to the current item, if there is a next o...
void search()
SearchAndReplaceWidget::search Start the search.
QTreeWidgetItem * m_folio_qtwi
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.
Ui::SearchAndReplaceWidget * ui
QTreeWidgetItem * nextItem(QTreeWidgetItem *item=nullptr, QTreeWidgetItemIterator::IteratorFlag flags=QTreeWidgetItemIterator::All) const
SearchAndReplaceWidget::nextItem.
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
Definition: qet.h:108
QTreeWidgetItem * m_terminal_elmt_qtwi
void addElement(Element *element)
SearchAndReplaceWidget::addElement Add a tree widget item for .
SearchAndReplaceWorker m_worker
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)
QList< Conductor * > selectedConductor() const
SearchAndReplaceWidget::selectedConductor.
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.
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)
The SearchAndReplaceWorker class This class is the worker use to change properties when use the searc...
QHash< QTreeWidgetItem *, QPointer< Element > > m_element_hash
QHash< QTreeWidgetItem *, QPointer< Conductor > > m_conductor_hash
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
QTreeWidgetItem * m_conductor_qtwi
void setHideAdvanced(bool hide) const
SearchAndReplaceWidget::setHideAdvanced Hide advanced widgets.
QList< IndependentTextItem * > selectedText() const
SearchAndReplaceWidget::selectedText.
QTreeWidgetItem * m_master_elmt_qtwi
SearchAndReplaceWidget(QWidget *parent=nullptr)
SearchAndReplaceWidget::SearchAndReplaceWidget Constructor.
static QStringList searchTerms(Diagram *diagram)
SearchAndReplaceWidget::searchTerms.