Search and replace : Element properties can be changed (and mass changed) through the search and replace widget.

Also improve the search for element


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5576 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2018-11-09 18:50:37 +00:00
parent b276d6517a
commit 1ead2aa0bb
11 changed files with 457 additions and 22 deletions

View File

@@ -0,0 +1,86 @@
/*
Copyright 2006-2018 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "replaceelementdialog.h"
#include "ui_replaceelementdialog.h"
#include "replaceelementdialog.h"
#include "elementinfopartwidget.h"
#include "qetapp.h"
#include "searchandreplaceworker.h"
#include <QAbstractButton>
ReplaceElementDialog::ReplaceElementDialog(DiagramContext context, QWidget *parent) :
QDialog(parent),
ui(new Ui::ReplaceElementDialog)
{
ui->setupUi(this);
buildWidget();
setContext(context);
}
ReplaceElementDialog::~ReplaceElementDialog()
{
delete ui;
}
/**
* @brief ReplaceElementDialog::setContext
* Set the current diagram context to be edited
* @param context
*/
void ReplaceElementDialog::setContext(DiagramContext context)
{
m_context = context;
for (ElementInfoPartWidget *eipw : m_eipw_list)
{
eipw->setText(m_context[eipw->key()].toString());
eipw->setEraseTextChecked(false);
}
}
/**
* @brief ReplaceElementDialog::context
* @return The edited diagram context
*/
DiagramContext ReplaceElementDialog::context() const
{
DiagramContext context;
for (ElementInfoPartWidget *eipw : m_eipw_list) {
context.addValue(eipw->key(), eipw->text());
}
return context;
}
void ReplaceElementDialog::buildWidget()
{
ui->m_button_box->disconnect();
connect(ui->m_button_box, &QDialogButtonBox::clicked, [this](QAbstractButton *button_)
{
this->done(ui->m_button_box->buttonRole(button_));
});
for (QString str : QETApp::elementInfoKeys())
{
ElementInfoPartWidget *eipw = new ElementInfoPartWidget(str, QETApp::elementTranslatedInfoKey(str), this);
eipw->setEraseTextVisible(true);
ui->m_scroll_layout->addWidget(eipw);
m_eipw_list << eipw;
}
}

View File

@@ -0,0 +1,50 @@
/*
Copyright 2006-2018 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef REPLACEELEMENTDIALOG_H
#define REPLACEELEMENTDIALOG_H
#include <QDialog>
#include "diagramcontext.h"
class ElementInfoPartWidget;
namespace Ui {
class ReplaceElementDialog;
}
class ReplaceElementDialog : public QDialog
{
Q_OBJECT
public:
explicit ReplaceElementDialog(DiagramContext context, QWidget *parent = nullptr);
~ReplaceElementDialog();
void setContext(DiagramContext context);
DiagramContext context() const;
private:
void buildWidget();
Ui::ReplaceElementDialog *ui;
QList <ElementInfoPartWidget *> m_eipw_list;
DiagramContext m_context;
};
#endif // REPLACEELEMENTDIALOG_H

View File

@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ReplaceElementDialog</class>
<widget class="QDialog" name="ReplaceElementDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>400</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>400</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>280</width>
<height>351</height>
</rect>
</property>
<layout class="QVBoxLayout" name="m_scroll_layout"/>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="m_button_box">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>m_button_box</sender>
<signal>accepted()</signal>
<receiver>ReplaceElementDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_button_box</sender>
<signal>rejected()</signal>
<receiver>ReplaceElementDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -25,6 +25,8 @@
#include "independenttextitem.h"
#include "conductor.h"
#include "replacefoliowidget.h"
#include "replaceelementdialog.h"
#include "qetapp.h"
#include <QSettings>
@@ -331,6 +333,7 @@ void SearchAndReplaceWidget::addElement(Element *element)
str = tr("Inconnue");
qtwi->setText(0, str);
qtwi->setCheckState(0, Qt::Checked);
qtwi->setData(0, Qt::UserRole, searchTerms(element));
}
/**
@@ -367,7 +370,10 @@ void SearchAndReplaceWidget::search()
qtwi->setHidden(false);
setVisibleAllParents(qtwi);
}
for (QTreeWidgetItem *qtwi : m_diagram_hash.keys()) //Search for diagrams items
QList<QTreeWidgetItem *> qtwi_list = m_diagram_hash.keys();
qtwi_list.append(m_element_hash.keys());
for (QTreeWidgetItem *qtwi : qtwi_list)
{
QStringList list = qtwi->data(0, Qt::UserRole).toStringList();
if (!list.filter(str, Qt::CaseInsensitive).isEmpty())
@@ -631,6 +637,26 @@ QStringList SearchAndReplaceWidget::searchTerms(Diagram *diagram) const
return list;
}
/**
* @brief SearchAndReplaceWidget::searchTerms
* @param element
* @return All QString use as terms for search
*/
QStringList SearchAndReplaceWidget::searchTerms(Element *element) const
{
QStringList list;
DiagramContext context = element->elementInformations();
for (QString key : QETApp::elementInfoKeys())
{
QString str = context.value(key).toString();
if (!str.isEmpty()) {
list.append(str);
}
}
return list;
}
void SearchAndReplaceWidget::on_m_quit_button_clicked() {
this->setHidden(true);
}
@@ -813,6 +839,10 @@ void SearchAndReplaceWidget::on_m_folio_pb_clicked()
}
}
/**
* @brief SearchAndReplaceWidget::on_m_replace_pb_clicked
* Replace the current selection
*/
void SearchAndReplaceWidget::on_m_replace_pb_clicked()
{
QTreeWidgetItem *qtwi = ui->m_tree_widget->currentItem();
@@ -829,26 +859,86 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked()
m_worker.replaceDiagram(d.data());
}
}
else if (ui->m_element_pb->text().endsWith(tr(" [Édité]")) &&
m_element_hash.keys().contains(qtwi))
{
QPointer<Element> e = m_element_hash.value(qtwi);
if (e) {
m_worker.replaceElement(e.data());
}
}
}
activateNextChecked();
ui->m_replace_pb->setEnabled(ui->m_next_pb->isEnabled());
}
/**
* @brief SearchAndReplaceWidget::on_m_replace_all_pb_clicked
* Replace all checked item
*/
void SearchAndReplaceWidget::on_m_replace_all_pb_clicked()
{
if (ui->m_folio_pb->text().endsWith(tr(" [Édité]")))
{
QList <Diagram *> d;
QList <Diagram *> diagram_list;
for (QTreeWidgetItem *qtwi : m_diagram_hash.keys())
{
if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked)
{
QPointer <Diagram> p = m_diagram_hash.value(qtwi);
if (p) {
d.append(p.data());
diagram_list.append(p.data());
}
}
}
m_worker.replaceDiagram(d);
m_worker.replaceDiagram(diagram_list);
}
if (ui->m_element_pb->text().endsWith(tr(" [Édité]")))
{
QList <Element *> element_list;
for (QTreeWidgetItem *qtwi : m_element_hash.keys())
{
if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked)
{
QPointer <Element> p = m_element_hash.value(qtwi);
if (p) {
element_list.append(p.data());
}
}
}
m_worker.replaceElement(element_list);
}
//Change was made, we reload the panel
//and search again to keep up to date the tree widget
//and the match item of search
QString txt = ui->m_search_le->text();
on_m_reload_pb_clicked();
ui->m_search_le->setText(txt);
search();
}
void SearchAndReplaceWidget::on_m_element_pb_clicked()
{
ReplaceElementDialog *dialog = new ReplaceElementDialog(m_worker.m_element_context, this);
int result = dialog->exec();
if (result == QDialogButtonBox::AcceptRole)
{
QString text = ui->m_element_pb->text();
if (!text.endsWith(tr(" [Édité]"))) {
text.append(tr(" [Édité]"));
}
ui->m_element_pb->setText(text);
m_worker.m_element_context = dialog->context();
}
else if (result == QDialogButtonBox::ResetRole)
{
QString text = ui->m_element_pb->text();
if (text.endsWith(tr(" [Édité]"))) {
text.remove(tr(" [Édité]"));
}
ui->m_element_pb->setText(text);
m_worker.m_element_context = DiagramContext();
}
}

View File

@@ -61,6 +61,7 @@ class SearchAndReplaceWidget : public QWidget
void updateParentCheckState(QTreeWidgetItem *item, bool all_parents = true);
void activateNextChecked();
QStringList searchTerms(Diagram *diagram) const;
QStringList searchTerms(Element *element) const;
private slots:
void on_m_quit_button_clicked();
@@ -73,6 +74,7 @@ class SearchAndReplaceWidget : public QWidget
void on_m_folio_pb_clicked();
void on_m_replace_pb_clicked();
void on_m_replace_all_pb_clicked();
void on_m_element_pb_clicked();
private:
Ui::SearchAndReplaceWidget *ui;

View File

@@ -184,7 +184,7 @@
<item row="1" column="4">
<widget class="QPushButton" name="m_element_pb">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>Élément</string>