mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 00:30:53 +01:00
Improve code style, Wrap code for better readability
This commit is contained in:
@@ -46,8 +46,15 @@ SearchAndReplaceWidget::SearchAndReplaceWidget(QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_horizontal_animation = new QWidgetAnimation(ui->m_advanced_button_widget, Qt::Horizontal, QWidgetAnimation::minimumSizeHint, 250);
|
||||
m_vertical_animation = new QWidgetAnimation(ui->m_advanced_widget, Qt::Vertical, QWidgetAnimation::availableSpace, 250);
|
||||
m_horizontal_animation = new QWidgetAnimation(
|
||||
ui->m_advanced_button_widget,
|
||||
Qt::Horizontal,
|
||||
QWidgetAnimation::minimumSizeHint,
|
||||
250);
|
||||
m_vertical_animation = new QWidgetAnimation(
|
||||
ui->m_advanced_widget,
|
||||
Qt::Vertical,
|
||||
QWidgetAnimation::availableSpace, 250);
|
||||
QVector<QWidget *> v;
|
||||
v << ui->m_header_widget;
|
||||
m_vertical_animation->widgetToSubtract(v);
|
||||
@@ -55,7 +62,8 @@ SearchAndReplaceWidget::SearchAndReplaceWidget(QWidget *parent) :
|
||||
setHideAdvanced(true);
|
||||
setUpTreeItems();
|
||||
|
||||
connect(ui->m_search_le, &QLineEdit::textEdited, this, &SearchAndReplaceWidget::search);
|
||||
connect(ui->m_search_le, &QLineEdit::textEdited,
|
||||
this, &SearchAndReplaceWidget::search);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +109,8 @@ bool SearchAndReplaceWidget::event(QEvent *event)
|
||||
*/
|
||||
void SearchAndReplaceWidget::clear()
|
||||
{
|
||||
disconnect(ui->m_tree_widget, &QTreeWidget::itemChanged, this, &SearchAndReplaceWidget::itemChanged);
|
||||
disconnect(ui->m_tree_widget, &QTreeWidget::itemChanged,
|
||||
this, &SearchAndReplaceWidget::itemChanged);
|
||||
|
||||
qDeleteAll(m_diagram_hash.keys());
|
||||
m_diagram_hash.clear();
|
||||
@@ -223,7 +232,8 @@ void SearchAndReplaceWidget::setHideAdvanced(bool hide)
|
||||
*/
|
||||
void SearchAndReplaceWidget::fillItemsList()
|
||||
{
|
||||
disconnect(ui->m_tree_widget, &QTreeWidget::itemChanged, this, &SearchAndReplaceWidget::itemChanged);
|
||||
disconnect(ui->m_tree_widget, &QTreeWidget::itemChanged,
|
||||
this, &SearchAndReplaceWidget::itemChanged);
|
||||
|
||||
qDeleteAll(m_element_hash.keys());
|
||||
m_element_hash.clear();
|
||||
@@ -235,7 +245,8 @@ void SearchAndReplaceWidget::fillItemsList()
|
||||
return;
|
||||
}
|
||||
ui->m_replace_all_pb->setEnabled(true);
|
||||
connect(project_, &QETProject::destroyed, this, &SearchAndReplaceWidget::on_m_reload_pb_clicked);
|
||||
connect(project_, &QETProject::destroyed, this,
|
||||
&SearchAndReplaceWidget::on_m_reload_pb_clicked);
|
||||
|
||||
|
||||
DiagramContent dc;
|
||||
@@ -263,8 +274,8 @@ void SearchAndReplaceWidget::fillItemsList()
|
||||
for (Element *elmt : dc.m_elements)
|
||||
addElement(elmt);
|
||||
|
||||
//Sort child of each "element type" tree item.
|
||||
//we hide, "element type" tree item, if they do not have children
|
||||
//Sort child of each "element type" tree item.
|
||||
//we hide, "element type" tree item, if they do not have children
|
||||
for(QTreeWidgetItem *qtwi : m_qtwi_elmts)
|
||||
{
|
||||
qtwi->sortChildren(0, Qt::AscendingOrder);
|
||||
@@ -292,7 +303,8 @@ void SearchAndReplaceWidget::fillItemsList()
|
||||
m_conductor_qtwi->sortChildren(0, Qt::AscendingOrder);
|
||||
|
||||
updateNextPreviousButtons();
|
||||
connect(ui->m_tree_widget, &QTreeWidget::itemChanged, this, &SearchAndReplaceWidget::itemChanged);
|
||||
connect(ui->m_tree_widget, &QTreeWidget::itemChanged,
|
||||
this, &SearchAndReplaceWidget::itemChanged);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -378,19 +390,25 @@ void SearchAndReplaceWidget::search()
|
||||
qtwi_list.append(m_conductor_hash.keys());
|
||||
for (QTreeWidgetItem *qtwi : qtwi_list)
|
||||
{
|
||||
QStringList list = qtwi->data(0, Qt::UserRole).toStringList();
|
||||
QStringList list = qtwi->data(0, Qt::UserRole)
|
||||
.toStringList();
|
||||
|
||||
if(ui->m_mode_cb->currentIndex() == 0)
|
||||
{
|
||||
//Contain string
|
||||
list = list.filter(str, ui->m_case_sensitive_cb->isChecked()? Qt::CaseSensitive : Qt::CaseInsensitive);
|
||||
list = list.filter(
|
||||
str,
|
||||
ui->m_case_sensitive_cb->isChecked()
|
||||
? Qt::CaseSensitive
|
||||
: Qt::CaseInsensitive);
|
||||
}
|
||||
else
|
||||
{
|
||||
//entire word
|
||||
QRegularExpression rx("\\b" + str + "\\b");
|
||||
if (!ui->m_case_sensitive_cb->isChecked()) {
|
||||
rx.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
||||
rx.setPatternOptions(
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
}
|
||||
list = list.filter(rx);
|
||||
}
|
||||
@@ -403,7 +421,9 @@ void SearchAndReplaceWidget::search()
|
||||
}
|
||||
|
||||
QPalette background = ui->m_search_le->palette();
|
||||
background.setColor(QPalette::Base, match ? QColor("#E0FFF0") : QColor("#FFE0EF"));
|
||||
background.setColor(QPalette::Base, match
|
||||
? QColor("#E0FFF0")
|
||||
: QColor("#FFE0EF"));
|
||||
ui->m_search_le->setPalette(background);
|
||||
|
||||
//Go to the first occurence
|
||||
@@ -418,7 +438,8 @@ void SearchAndReplaceWidget::search()
|
||||
@param item
|
||||
@param expend_parent
|
||||
*/
|
||||
void SearchAndReplaceWidget::setVisibleAllParents(QTreeWidgetItem *item, bool expend_parent)
|
||||
void SearchAndReplaceWidget::setVisibleAllParents(QTreeWidgetItem *item,
|
||||
bool expend_parent)
|
||||
{
|
||||
if (item->parent())
|
||||
{
|
||||
@@ -437,7 +458,9 @@ void SearchAndReplaceWidget::setVisibleAllParents(QTreeWidgetItem *item, bool ex
|
||||
@return the next item according to flag
|
||||
or nullptr if there is not a next item
|
||||
*/
|
||||
QTreeWidgetItem *SearchAndReplaceWidget::nextItem(QTreeWidgetItem *item, QTreeWidgetItemIterator::IteratorFlag flags) const
|
||||
QTreeWidgetItem *SearchAndReplaceWidget::nextItem(
|
||||
QTreeWidgetItem *item,
|
||||
QTreeWidgetItemIterator::IteratorFlag flags) const
|
||||
{
|
||||
QTreeWidgetItem *qtwi = item;
|
||||
if (!item) {
|
||||
@@ -468,7 +491,9 @@ QTreeWidgetItem *SearchAndReplaceWidget::nextItem(QTreeWidgetItem *item, QTreeWi
|
||||
@return the previous item according to flag
|
||||
or nullptr if there is not a previous item
|
||||
*/
|
||||
QTreeWidgetItem *SearchAndReplaceWidget::previousItem(QTreeWidgetItem *item, QTreeWidgetItemIterator::IteratorFlag flags) const
|
||||
QTreeWidgetItem *SearchAndReplaceWidget::previousItem(
|
||||
QTreeWidgetItem *item,
|
||||
QTreeWidgetItemIterator::IteratorFlag flags) const
|
||||
{
|
||||
QTreeWidgetItem *qtwi = item;
|
||||
if (!item) {
|
||||
@@ -525,7 +550,8 @@ void SearchAndReplaceWidget::updateNextPreviousButtons()
|
||||
QTreeWidgetItem *previous_ = item_;
|
||||
do
|
||||
{
|
||||
previous_ = previousItem(previous_, QTreeWidgetItemIterator::NotHidden);
|
||||
previous_ = previousItem(previous_,
|
||||
QTreeWidgetItemIterator::NotHidden);
|
||||
if (!previous_)
|
||||
{
|
||||
ui->m_previous_pb->setDisabled(true);
|
||||
@@ -563,7 +589,9 @@ void SearchAndReplaceWidget::itemChanged(QTreeWidgetItem *item, int column)
|
||||
@param check : check state
|
||||
@param deep : if true, we evaluate every subchilds.
|
||||
*/
|
||||
void SearchAndReplaceWidget::setChildCheckState(QTreeWidgetItem *item, Qt::CheckState check, bool deep)
|
||||
void SearchAndReplaceWidget::setChildCheckState(QTreeWidgetItem *item,
|
||||
Qt::CheckState check,
|
||||
bool deep)
|
||||
{
|
||||
for (int i=0 ; i<item->childCount() ; ++i)
|
||||
{
|
||||
@@ -580,7 +608,8 @@ void SearchAndReplaceWidget::setChildCheckState(QTreeWidgetItem *item, Qt::Check
|
||||
@param all_parents : if true, we evaluate every parents,
|
||||
until the root item.
|
||||
*/
|
||||
void SearchAndReplaceWidget::updateParentCheckState(QTreeWidgetItem *item, bool all_parents)
|
||||
void SearchAndReplaceWidget::updateParentCheckState(QTreeWidgetItem *item,
|
||||
bool all_parents)
|
||||
{
|
||||
QTreeWidgetItem *parent = item->parent();
|
||||
|
||||
@@ -632,8 +661,9 @@ void SearchAndReplaceWidget::activateNextChecked()
|
||||
|
||||
do {
|
||||
on_m_next_pb_clicked();
|
||||
} while ((ui->m_tree_widget->currentItem()->checkState(0) != Qt::Checked) &&
|
||||
ui->m_next_pb->isEnabled());
|
||||
} while ((ui->m_tree_widget->currentItem()->checkState(0)
|
||||
!= Qt::Checked
|
||||
) && ui->m_next_pb->isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -715,7 +745,8 @@ QList<IndependentTextItem *> SearchAndReplaceWidget::selectedText() const
|
||||
{
|
||||
if (!qtwi->isHidden() && qtwi->checkState(0) == Qt::Checked)
|
||||
{
|
||||
QPointer<IndependentTextItem> t = m_text_hash.value(qtwi);
|
||||
QPointer<IndependentTextItem> t =
|
||||
m_text_hash.value(qtwi);
|
||||
if (t) {
|
||||
text_list.append(t.data());
|
||||
}
|
||||
@@ -733,7 +764,8 @@ QList<IndependentTextItem *> SearchAndReplaceWidget::selectedText() const
|
||||
QStringList SearchAndReplaceWidget::searchTerms(Diagram *diagram)
|
||||
{
|
||||
QStringList list;
|
||||
TitleBlockProperties prop = diagram->border_and_titleblock.exportTitleBlock();
|
||||
TitleBlockProperties prop =
|
||||
diagram->border_and_titleblock.exportTitleBlock();
|
||||
list.append(prop.title);
|
||||
list.append(prop.author);
|
||||
list.append(prop.filename);
|
||||
@@ -768,7 +800,10 @@ QStringList SearchAndReplaceWidget::searchTerms(Element *element)
|
||||
|
||||
for (DynamicElementTextItem *deti : element->dynamicTextItems())
|
||||
{
|
||||
if (deti->textFrom() == DynamicElementTextItem::UserText || deti->textFrom() == DynamicElementTextItem::CompositeText) {
|
||||
if (deti->textFrom()
|
||||
== DynamicElementTextItem::UserText
|
||||
|| deti->textFrom()
|
||||
== DynamicElementTextItem::CompositeText) {
|
||||
list.append(deti->toPlainText());
|
||||
}
|
||||
}
|
||||
@@ -777,7 +812,10 @@ QStringList SearchAndReplaceWidget::searchTerms(Element *element)
|
||||
list.append(group->name());
|
||||
|
||||
for (DynamicElementTextItem *deti : group->texts()) {
|
||||
if (deti->textFrom() == DynamicElementTextItem::UserText || deti->textFrom() == DynamicElementTextItem::CompositeText) {
|
||||
if (deti->textFrom()
|
||||
== DynamicElementTextItem::UserText
|
||||
|| deti->textFrom()
|
||||
== DynamicElementTextItem::CompositeText) {
|
||||
list.append(deti->toPlainText());
|
||||
}
|
||||
}
|
||||
@@ -810,7 +848,9 @@ QStringList SearchAndReplaceWidget::searchTerms(Conductor *conductor)
|
||||
*/
|
||||
void SearchAndReplaceWidget::on_m_quit_button_clicked()
|
||||
{
|
||||
if (auto animator = this->findChild<QWidgetAnimation *>("search and replace animator")) {
|
||||
if (auto animator =
|
||||
this->findChild<QWidgetAnimation *>(
|
||||
"search and replace animator")) {
|
||||
animator->setHidden(!this->isHidden());
|
||||
} else {
|
||||
this->setHidden(true);
|
||||
@@ -818,10 +858,12 @@ void SearchAndReplaceWidget::on_m_quit_button_clicked()
|
||||
}
|
||||
|
||||
void SearchAndReplaceWidget::on_m_advanced_pb_toggled(bool checked) {
|
||||
setHideAdvanced(!checked);
|
||||
setHideAdvanced(!checked);
|
||||
}
|
||||
|
||||
void SearchAndReplaceWidget::on_m_tree_widget_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
||||
void SearchAndReplaceWidget::on_m_tree_widget_itemDoubleClicked(
|
||||
QTreeWidgetItem *item,
|
||||
int column)
|
||||
{
|
||||
Q_UNUSED(column)
|
||||
|
||||
@@ -874,7 +916,9 @@ void SearchAndReplaceWidget::on_m_reload_pb_clicked()
|
||||
m_root_qtwi->setExpanded(true);
|
||||
}
|
||||
|
||||
void SearchAndReplaceWidget::on_m_tree_widget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
|
||||
void SearchAndReplaceWidget::on_m_tree_widget_currentItemChanged(
|
||||
QTreeWidgetItem *current,
|
||||
QTreeWidgetItem *previous)
|
||||
{
|
||||
Q_UNUSED(previous);
|
||||
|
||||
@@ -918,7 +962,8 @@ void SearchAndReplaceWidget::on_m_tree_widget_currentItemChanged(QTreeWidgetItem
|
||||
return;
|
||||
}
|
||||
|
||||
if (current->checkState(0) == Qt::Checked && !m_category_qtwi.contains(current)) {
|
||||
if (current->checkState(0) == Qt::Checked
|
||||
&& !m_category_qtwi.contains(current)) {
|
||||
ui->m_replace_pb->setEnabled(true);
|
||||
} else {
|
||||
ui->m_replace_pb->setDisabled(true);
|
||||
@@ -950,15 +995,20 @@ void SearchAndReplaceWidget::on_m_previous_pb_clicked()
|
||||
|
||||
do
|
||||
{
|
||||
item = previousItem(nullptr, QTreeWidgetItemIterator::NotHidden);
|
||||
item = previousItem(nullptr,
|
||||
QTreeWidgetItemIterator::NotHidden);
|
||||
if (item) {
|
||||
ui->m_tree_widget->setCurrentItem(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
//There is not a previous selected item, so the current item is m_root_qtwi but we know he must not be selected
|
||||
//we user click on the button 'next item'.
|
||||
//So we select the first selectable item by calling on_m_next_pb_clicked
|
||||
/* There is not a previous selected item,
|
||||
* so the current item is m_root_qtwi
|
||||
* but we know he must not be selected
|
||||
* we user click on the button 'next item'.
|
||||
* So we select the first selectable item
|
||||
* by calling on_m_next_pb_clicked
|
||||
*/
|
||||
on_m_next_pb_clicked();
|
||||
return;
|
||||
}
|
||||
@@ -982,7 +1032,8 @@ void SearchAndReplaceWidget::on_m_folio_pb_clicked()
|
||||
text.append(tr(" [édité]"));
|
||||
}
|
||||
ui->m_folio_pb->setText(text);
|
||||
m_worker.m_titleblock_properties = dialog->titleBlockProperties();
|
||||
m_worker.m_titleblock_properties =
|
||||
dialog->titleBlockProperties();
|
||||
}
|
||||
else if (result == QDialogButtonBox::ResetRole)
|
||||
{
|
||||
@@ -1005,7 +1056,8 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked()
|
||||
if(!qtwi) {
|
||||
return;
|
||||
}
|
||||
if (!m_category_qtwi.contains(qtwi) && qtwi->checkState(0) == Qt::Checked)
|
||||
if (!m_category_qtwi.contains(qtwi)
|
||||
&& qtwi->checkState(0) == Qt::Checked)
|
||||
{
|
||||
if (ui->m_folio_pb->text().endsWith(tr(" [édité]")) &&
|
||||
m_diagram_hash.keys().contains(qtwi))
|
||||
@@ -1027,7 +1079,8 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked()
|
||||
m_text_hash.keys().contains(qtwi))
|
||||
{
|
||||
m_worker.m_indi_text = ui->m_replace_le->text();
|
||||
QPointer<IndependentTextItem> t = m_text_hash.value(qtwi);
|
||||
QPointer<IndependentTextItem> t =
|
||||
m_text_hash.value(qtwi);
|
||||
if (t) {
|
||||
m_worker.replaceIndiText(t.data());
|
||||
}
|
||||
@@ -1052,28 +1105,32 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked()
|
||||
|
||||
if (m_diagram_hash.keys().contains(qtwi))
|
||||
{
|
||||
QPointer<Diagram> d = m_diagram_hash.value(qtwi);
|
||||
QPointer<Diagram> d =
|
||||
m_diagram_hash.value(qtwi);
|
||||
if (d) {
|
||||
dl.append(d.data());
|
||||
}
|
||||
}
|
||||
else if (m_element_hash.keys().contains(qtwi))
|
||||
{
|
||||
QPointer<Element> e = m_element_hash.value(qtwi);
|
||||
QPointer<Element> e =
|
||||
m_element_hash.value(qtwi);
|
||||
if (e) {
|
||||
el.append(e.data());
|
||||
}
|
||||
}
|
||||
else if (m_text_hash.keys().contains(qtwi))
|
||||
{
|
||||
QPointer<IndependentTextItem> t = m_text_hash.value(qtwi);
|
||||
QPointer<IndependentTextItem> t =
|
||||
m_text_hash.value(qtwi);
|
||||
if (t) {
|
||||
tl.append(t.data());
|
||||
}
|
||||
}
|
||||
else if (m_conductor_hash.keys().contains(qtwi))
|
||||
{
|
||||
QPointer<Conductor> c = m_conductor_hash.value(qtwi);
|
||||
QPointer<Conductor> c =
|
||||
m_conductor_hash.value(qtwi);
|
||||
if (c) {
|
||||
cl.append(c.data());
|
||||
}
|
||||
@@ -1108,7 +1165,10 @@ void SearchAndReplaceWidget::on_m_replace_all_pb_clicked()
|
||||
}
|
||||
if (ui->m_advanced_replace_pb->text().endsWith(tr(" [édité]"))) {
|
||||
|
||||
m_worker.replaceAdvanced(selectedDiagram(), selectedElement(), selectedText(), selectedConductor());
|
||||
m_worker.replaceAdvanced(selectedDiagram(),
|
||||
selectedElement(),
|
||||
selectedText(),
|
||||
selectedConductor());
|
||||
}
|
||||
|
||||
//Change was made, we reload the panel
|
||||
@@ -1122,7 +1182,9 @@ void SearchAndReplaceWidget::on_m_replace_all_pb_clicked()
|
||||
|
||||
void SearchAndReplaceWidget::on_m_element_pb_clicked()
|
||||
{
|
||||
ReplaceElementDialog *dialog = new ReplaceElementDialog(m_worker.m_element_context, this);
|
||||
ReplaceElementDialog *dialog = new ReplaceElementDialog(
|
||||
m_worker.m_element_context,
|
||||
this);
|
||||
|
||||
int result = dialog->exec();
|
||||
if (result == QDialogButtonBox::AcceptRole)
|
||||
@@ -1173,7 +1235,9 @@ void SearchAndReplaceWidget::on_m_case_sensitive_cb_stateChanged(int arg1)
|
||||
*/
|
||||
void SearchAndReplaceWidget::on_m_conductor_pb_clicked()
|
||||
{
|
||||
ReplaceConductorDialog *dialog = new ReplaceConductorDialog(m_worker.m_conductor_properties, this);
|
||||
ReplaceConductorDialog *dialog = new ReplaceConductorDialog(
|
||||
m_worker.m_conductor_properties,
|
||||
this);
|
||||
int result = dialog->exec();
|
||||
|
||||
if (result == QDialogButtonBox::AcceptRole)
|
||||
@@ -1192,7 +1256,8 @@ void SearchAndReplaceWidget::on_m_conductor_pb_clicked()
|
||||
text.remove(tr(" [édité]"));
|
||||
}
|
||||
ui->m_conductor_pb->setText(text);
|
||||
m_worker.m_conductor_properties = m_worker.invalidConductorProperties();
|
||||
m_worker.m_conductor_properties =
|
||||
m_worker.invalidConductorProperties();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1202,7 +1267,9 @@ void SearchAndReplaceWidget::on_m_conductor_pb_clicked()
|
||||
*/
|
||||
void SearchAndReplaceWidget::on_m_advanced_replace_pb_clicked()
|
||||
{
|
||||
replaceAdvancedDialog *dialog = new replaceAdvancedDialog(m_worker.m_advanced_struct, this);
|
||||
replaceAdvancedDialog *dialog = new replaceAdvancedDialog(
|
||||
m_worker.m_advanced_struct,
|
||||
this);
|
||||
int result = dialog->exec();
|
||||
|
||||
if (result == QDialogButtonBox::AcceptRole)
|
||||
|
||||
Reference in New Issue
Block a user