Merge pull request #566 from DieterMayerOSS/pr/hash-contains

Replace hash.keys().contains(k) with hash.contains(k) (35 call sites)
This commit is contained in:
Laurent Trinques
2026-07-28 17:41:23 +02:00
committed by GitHub
7 changed files with 35 additions and 35 deletions
@@ -1,4 +1,4 @@
/* /*
Copyright 2006-2026 The QElectroTech Team Copyright 2006-2026 The QElectroTech Team
This file is part of QElectroTech. This file is part of QElectroTech.
@@ -475,7 +475,7 @@ void SearchAndReplaceWidget::setUpConenctions()
connect(ui->m_tree_widget, &QTreeWidget::customContextMenuRequested, [this](const QPoint &pos) connect(ui->m_tree_widget, &QTreeWidget::customContextMenuRequested, [this](const QPoint &pos)
{ {
if (m_diagram_hash.keys().contains(ui->m_tree_widget->currentItem())) if (m_diagram_hash.contains(ui->m_tree_widget->currentItem()))
{ {
QMenu *menu = new QMenu(ui->m_tree_widget); QMenu *menu = new QMenu(ui->m_tree_widget);
menu->addAction(m_select_elements); menu->addAction(m_select_elements);
@@ -951,28 +951,28 @@ void SearchAndReplaceWidget::on_m_tree_widget_itemDoubleClicked(
{ {
Q_UNUSED(column) Q_UNUSED(column)
if (m_diagram_hash.keys().contains(item)) if (m_diagram_hash.contains(item))
{ {
QPointer<Diagram> diagram = m_diagram_hash.value(item); QPointer<Diagram> diagram = m_diagram_hash.value(item);
if(diagram) { if(diagram) {
diagram.data()->showMe(); diagram.data()->showMe();
} }
} }
else if (m_element_hash.keys().contains(item)) else if (m_element_hash.contains(item))
{ {
QPointer<Element> elmt = m_element_hash.value(item); QPointer<Element> elmt = m_element_hash.value(item);
if (elmt && elmt->diagram()) { if (elmt && elmt->diagram()) {
elmt.data()->diagram()->showMe(); elmt.data()->diagram()->showMe();
} }
} }
else if (m_text_hash.keys().contains(item)) else if (m_text_hash.contains(item))
{ {
QPointer<IndependentTextItem> text = m_text_hash.value(item); QPointer<IndependentTextItem> text = m_text_hash.value(item);
if (text && text->diagram()) { if (text && text->diagram()) {
text.data()->diagram()->showMe(); text.data()->diagram()->showMe();
} }
} }
else if (m_conductor_hash.keys().contains(item)) else if (m_conductor_hash.contains(item))
{ {
QPointer<Conductor> cond = m_conductor_hash.value(item); QPointer<Conductor> cond = m_conductor_hash.value(item);
if (cond && cond->diagram()) { if (cond && cond->diagram()) {
@@ -1013,7 +1013,7 @@ void SearchAndReplaceWidget::on_m_tree_widget_currentItemChanged(
m_last_selected.data()->setSelected(false); m_last_selected.data()->setSelected(false);
} }
if (m_element_hash.keys().contains(current)) if (m_element_hash.contains(current))
{ {
QPointer<Element> elmt = m_element_hash.value(current); QPointer<Element> elmt = m_element_hash.value(current);
if (elmt) if (elmt)
@@ -1022,7 +1022,7 @@ void SearchAndReplaceWidget::on_m_tree_widget_currentItemChanged(
elmt.data()->setHighlighted(true); elmt.data()->setHighlighted(true);
} }
} }
else if (m_text_hash.keys().contains(current)) else if (m_text_hash.contains(current))
{ {
QPointer<IndependentTextItem> text = m_text_hash.value(current); QPointer<IndependentTextItem> text = m_text_hash.value(current);
if (text) if (text)
@@ -1031,7 +1031,7 @@ void SearchAndReplaceWidget::on_m_tree_widget_currentItemChanged(
m_last_selected = text; m_last_selected = text;
} }
} }
else if (m_conductor_hash.keys().contains(current)) else if (m_conductor_hash.contains(current))
{ {
QPointer<Conductor> cond = m_conductor_hash.value(current); QPointer<Conductor> cond = m_conductor_hash.value(current);
if (cond) if (cond)
@@ -1144,7 +1144,7 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked()
&& qtwi->checkState(0) == Qt::Checked) && qtwi->checkState(0) == Qt::Checked)
{ {
if (ui->m_folio_pb->text().endsWith(tr(" [édité]")) && if (ui->m_folio_pb->text().endsWith(tr(" [édité]")) &&
m_diagram_hash.keys().contains(qtwi)) m_diagram_hash.contains(qtwi))
{ {
QPointer<Diagram> d = m_diagram_hash.value(qtwi); QPointer<Diagram> d = m_diagram_hash.value(qtwi);
if (d) { if (d) {
@@ -1152,7 +1152,7 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked()
} }
} }
else if (ui->m_element_pb->text().endsWith(tr(" [édité]")) && else if (ui->m_element_pb->text().endsWith(tr(" [édité]")) &&
m_element_hash.keys().contains(qtwi)) m_element_hash.contains(qtwi))
{ {
QPointer<Element> e = m_element_hash.value(qtwi); QPointer<Element> e = m_element_hash.value(qtwi);
if (e) { if (e) {
@@ -1160,7 +1160,7 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked()
} }
} }
else if (!ui->m_replace_le->text().isEmpty() && else if (!ui->m_replace_le->text().isEmpty() &&
m_text_hash.keys().contains(qtwi)) m_text_hash.contains(qtwi))
{ {
m_worker.m_indi_text = ui->m_replace_le->text(); m_worker.m_indi_text = ui->m_replace_le->text();
QPointer<IndependentTextItem> t = QPointer<IndependentTextItem> t =
@@ -1171,7 +1171,7 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked()
} }
else if (ui->m_conductor_pb->text().endsWith(tr(" [édité]")) && else if (ui->m_conductor_pb->text().endsWith(tr(" [édité]")) &&
m_conductor_hash.keys().contains(qtwi)) m_conductor_hash.contains(qtwi))
{ {
QPointer<Conductor> c = m_conductor_hash.value(qtwi); QPointer<Conductor> c = m_conductor_hash.value(qtwi);
if (c) { if (c) {
@@ -1187,7 +1187,7 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked()
QList <IndependentTextItem *>tl; QList <IndependentTextItem *>tl;
QList <Conductor *>cl; QList <Conductor *>cl;
if (m_diagram_hash.keys().contains(qtwi)) if (m_diagram_hash.contains(qtwi))
{ {
QPointer<Diagram> d = QPointer<Diagram> d =
m_diagram_hash.value(qtwi); m_diagram_hash.value(qtwi);
@@ -1195,7 +1195,7 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked()
dl.append(d.data()); dl.append(d.data());
} }
} }
else if (m_element_hash.keys().contains(qtwi)) else if (m_element_hash.contains(qtwi))
{ {
QPointer<Element> e = QPointer<Element> e =
m_element_hash.value(qtwi); m_element_hash.value(qtwi);
@@ -1203,7 +1203,7 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked()
el.append(e.data()); el.append(e.data());
} }
} }
else if (m_text_hash.keys().contains(qtwi)) else if (m_text_hash.contains(qtwi))
{ {
QPointer<IndependentTextItem> t = QPointer<IndependentTextItem> t =
m_text_hash.value(qtwi); m_text_hash.value(qtwi);
@@ -1211,7 +1211,7 @@ void SearchAndReplaceWidget::on_m_replace_pb_clicked()
tl.append(t.data()); tl.append(t.data());
} }
} }
else if (m_conductor_hash.keys().contains(qtwi)) else if (m_conductor_hash.contains(qtwi))
{ {
QPointer<Conductor> c = QPointer<Conductor> c =
m_conductor_hash.value(qtwi); m_conductor_hash.value(qtwi);
+1 -1
View File
@@ -54,7 +54,7 @@ void ElementPictureFactory::getPictures(const ElementsLocation &location, QPictu
return; return;
} }
if(m_pictures_H.keys().contains(uuid)) if(m_pictures_H.contains(uuid))
{ {
picture = m_pictures_H.value(uuid); picture = m_pictures_H.value(uuid);
low_picture = m_low_pictures_H.value(uuid); low_picture = m_low_pictures_H.value(uuid);
+3 -3
View File
@@ -419,7 +419,7 @@ void ProjectAutoNumConfigPage::saveContextElement()
m_saw_element->contextComboBox()->addItem(tr("Sans nom")); m_saw_element->contextComboBox()->addItem(tr("Sans nom"));
} }
// If the text isn't yet to the autonum of the project, add this new item to the combo box. // If the text isn't yet to the autonum of the project, add this new item to the combo box.
else if ( !m_project -> elementAutoNum().keys().contains( m_saw_element->contextComboBox()->currentText())) else if ( !m_project -> elementAutoNum().contains( m_saw_element->contextComboBox()->currentText()))
{ {
m_project->addElementAutoNum(m_saw_element->contextComboBox()->currentText(), m_saw_element->toNumContext()); m_project->addElementAutoNum(m_saw_element->contextComboBox()->currentText(), m_saw_element->toNumContext());
m_project->setCurrrentElementAutonum(m_saw_element->contextComboBox()->currentText()); m_project->setCurrrentElementAutonum(m_saw_element->contextComboBox()->currentText());
@@ -461,7 +461,7 @@ void ProjectAutoNumConfigPage::saveContextConductor()
m_saw_conductor->contextComboBox()-> addItem(tr("Sans nom")); m_saw_conductor->contextComboBox()-> addItem(tr("Sans nom"));
} }
// If the text isn't yet to the autonum of the project, add this new item to the combo box. // If the text isn't yet to the autonum of the project, add this new item to the combo box.
else if ( !m_project -> conductorAutoNum().keys().contains( m_saw_conductor->contextComboBox()->currentText())) else if ( !m_project -> conductorAutoNum().contains( m_saw_conductor->contextComboBox()->currentText()))
{ {
project()->addConductorAutoNum(m_saw_conductor->contextComboBox()->currentText(), m_saw_conductor->toNumContext()); project()->addConductorAutoNum(m_saw_conductor->contextComboBox()->currentText(), m_saw_conductor->toNumContext());
project()->setCurrentConductorAutoNum(m_saw_conductor->contextComboBox()->currentText()); project()->setCurrentConductorAutoNum(m_saw_conductor->contextComboBox()->currentText());
@@ -489,7 +489,7 @@ void ProjectAutoNumConfigPage::saveContextFolio()
m_saw_folio->contextComboBox() -> addItem(tr("Sans nom")); m_saw_folio->contextComboBox() -> addItem(tr("Sans nom"));
} }
// If the text isn't yet to the autonum of the project, add this new item to the combo box. // If the text isn't yet to the autonum of the project, add this new item to the combo box.
else if ( !m_project -> folioAutoNum().keys().contains( m_saw_folio->contextComboBox()->currentText())) { else if ( !m_project -> folioAutoNum().contains( m_saw_folio->contextComboBox()->currentText())) {
project()->addFolioAutoNum(m_saw_folio->contextComboBox()->currentText(), m_saw_folio->toNumContext()); project()->addFolioAutoNum(m_saw_folio->contextComboBox()->currentText(), m_saw_folio->toNumContext());
m_saw_folio->contextComboBox() -> addItem(m_saw_folio->contextComboBox()->currentText()); m_saw_folio->contextComboBox() -> addItem(m_saw_folio->contextComboBox()->currentText());
} }
+9 -9
View File
@@ -130,7 +130,7 @@ QList<QStandardItem *> DynamicElementTextModel::itemsForText(
{ {
QList <QStandardItem *> qsi_list; QList <QStandardItem *> qsi_list;
if(m_texts_list.keys().contains(deti)) if(m_texts_list.contains(deti))
return qsi_list; return qsi_list;
QStandardItem *qsi = new QStandardItem(deti->toPlainText()); QStandardItem *qsi = new QStandardItem(deti->toPlainText());
@@ -718,7 +718,7 @@ QUndoCommand *DynamicElementTextModel::undoForEditedGroup(
*/ */
void DynamicElementTextModel::addGroup(ElementTextItemGroup *group) void DynamicElementTextModel::addGroup(ElementTextItemGroup *group)
{ {
if(m_groups_list.keys().contains(group)) if(m_groups_list.contains(group))
return; return;
//Group //Group
@@ -869,7 +869,7 @@ void DynamicElementTextModel::addGroup(ElementTextItemGroup *group)
*/ */
void DynamicElementTextModel::removeGroup(ElementTextItemGroup *group) void DynamicElementTextModel::removeGroup(ElementTextItemGroup *group)
{ {
if(m_groups_list.keys().contains(group)) if(m_groups_list.contains(group))
{ {
QModelIndex group_index = m_groups_list.value(group)->index(); QModelIndex group_index = m_groups_list.value(group)->index();
this->removeRow(group_index.row(), group_index.parent()); this->removeRow(group_index.row(), group_index.parent());
@@ -896,7 +896,7 @@ void DynamicElementTextModel::removeTextFromGroup(DynamicElementTextItem *deti,
{ {
Q_UNUSED(group) Q_UNUSED(group)
if(m_texts_list.keys().contains(deti)) if(m_texts_list.contains(deti))
{ {
QStandardItem *text_item = m_texts_list.value(deti); QStandardItem *text_item = m_texts_list.value(deti);
QModelIndex text_index = indexFromItem(text_item); QModelIndex text_index = indexFromItem(text_item);
@@ -961,7 +961,7 @@ ElementTextItemGroup *DynamicElementTextModel::groupFromItem(
QModelIndex DynamicElementTextModel::indexFromGroup( QModelIndex DynamicElementTextModel::indexFromGroup(
ElementTextItemGroup *group) const ElementTextItemGroup *group) const
{ {
if(m_groups_list.keys().contains(group)) if(m_groups_list.contains(group))
return m_groups_list.value(group)->index(); return m_groups_list.value(group)->index();
else else
return QModelIndex(); return QModelIndex();
@@ -1371,7 +1371,7 @@ void DynamicElementTextModel::setConnection(DynamicElementTextItem *deti, bool s
{ {
if(set) if(set)
{ {
if(m_hash_text_connect.keys().contains(deti)) if(m_hash_text_connect.contains(deti))
return; return;
QList<QMetaObject::Connection> connection_list; QList<QMetaObject::Connection> connection_list;
@@ -1390,7 +1390,7 @@ void DynamicElementTextModel::setConnection(DynamicElementTextItem *deti, bool s
} }
else else
{ {
if(!m_hash_text_connect.keys().contains(deti)) if(!m_hash_text_connect.contains(deti))
return; return;
for (const QMetaObject::Connection& con : m_hash_text_connect.value(deti)) for (const QMetaObject::Connection& con : m_hash_text_connect.value(deti))
@@ -1412,7 +1412,7 @@ void DynamicElementTextModel::setConnection(ElementTextItemGroup *group, bool se
{ {
if(set) if(set)
{ {
if(m_hash_group_connect.keys().contains(group)) if(m_hash_group_connect.contains(group))
return; return;
QList<QMetaObject::Connection> connection_list; QList<QMetaObject::Connection> connection_list;
@@ -1429,7 +1429,7 @@ void DynamicElementTextModel::setConnection(ElementTextItemGroup *group, bool se
} }
else else
{ {
if(!m_hash_group_connect.keys().contains(group)) if(!m_hash_group_connect.contains(group))
return; return;
for (const QMetaObject::Connection& con : m_hash_group_connect.value(group)) for (const QMetaObject::Connection& con : m_hash_group_connect.value(group))
@@ -447,7 +447,7 @@ void AlignmentTextsGroupCommand::undo()
{ {
for(DynamicElementTextItem *deti : m_group.data()->texts()) for(DynamicElementTextItem *deti : m_group.data()->texts())
{ {
if(m_texts_pos.keys().contains(deti)) if(m_texts_pos.contains(deti))
deti->setPos(m_texts_pos.value(deti)); deti->setPos(m_texts_pos.value(deti));
} }
} }
@@ -61,7 +61,7 @@ bool ChangeElementInformationCommand::mergeWith(const QUndoCommand *other)
if (m_map.size() == other_undo->m_map.size()) if (m_map.size() == other_undo->m_map.size())
{ {
for (auto key : other_undo->m_map.keys()) { for (auto key : other_undo->m_map.keys()) {
if (!m_map.keys().contains(key)) { if (!m_map.contains(key)) {
return false; return false;
} }
} }
@@ -86,7 +86,7 @@ DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand(
for (auto table : m_removed_contents.m_tables) for (auto table : m_removed_contents.m_tables)
{ {
//Table is already managed, jump to next loop //Table is already managed, jump to next loop
if (m_table_scene_hash.keys().contains(table)) if (m_table_scene_hash.contains(table))
continue; continue;
auto first_table = table; //The first table if the table is linked to another auto first_table = table; //The first table if the table is linked to another
@@ -290,9 +290,9 @@ void DeleteQGraphicsItemCommand::undo()
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts) for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
{ {
if(m_elmt_text_hash.keys().contains(deti)) if(m_elmt_text_hash.contains(deti))
m_elmt_text_hash.value(deti)->addDynamicTextItem(deti); m_elmt_text_hash.value(deti)->addDynamicTextItem(deti);
else if (m_grp_texts_hash.keys().contains(deti)) else if (m_grp_texts_hash.contains(deti))
{ {
Element *elmt = m_grp_texts_hash.value(deti)->parentElement(); Element *elmt = m_grp_texts_hash.value(deti)->parentElement();
elmt->addDynamicTextItem(deti); elmt->addDynamicTextItem(deti);