Try Clazy fix-its

clazy is a compiler plugin which allows clang to understand Qt
semantics. You get more than 50 Qt related compiler warnings, ranging
from unneeded memory allocations to misusage of API, including fix-its
for automatic refactoring.

https://invent.kde.org/sdk/clazy
This commit is contained in:
Laurent Trinques
2025-02-14 15:52:23 +01:00
parent adcf77e34a
commit dba7caed30
88 changed files with 512 additions and 409 deletions

View File

@@ -236,7 +236,7 @@ void AboutQETDialog::addAuthor(QLabel *label, const QString &name, const QString
QString author_template = "<span style=\"text-decoration: underline;\">%1</span> : %2 &lt;<a href=\"mailto:%3\">%3</a>&gt;&lrm;<br/><br/>";
// Add the function of the person
new_text += author_template.arg(work).arg(name).arg(email);
new_text += author_template.arg(work, name, email);
label->setText(new_text);
}
@@ -253,7 +253,7 @@ void AboutQETDialog::addLibrary(QLabel *label, const QString &name, const QStrin
QString Library_template = "<span style=\"text-decoration: underline;\">%1</span> : &lt;<a href=\"%3\">%3</a>&gt;&lrm;<br/><br/>";
// Add the function of the person
new_text += Library_template.arg(name).arg(link);
new_text += Library_template.arg(name, link);
label->setText(new_text);
}

View File

@@ -71,7 +71,7 @@ void DiagramContextWidget::setContext (const DiagramContext &context)
clear();
int i = 0;
for (QString key : context.keys(DiagramContext::Alphabetical))
for (const QString& key : context.keys(DiagramContext::Alphabetical))
{
ui->m_table->setItem(i, 0, new QTableWidgetItem(key));
ui->m_table->setItem(i, 1, new QTableWidgetItem(context[key].toString()));

View File

@@ -79,23 +79,23 @@ void DynamicElementTextItemEditor::apply()
deti_list << m_element.data()->dynamicTextItems();
for(ElementTextItemGroup *group : m_element.data()->textGroups())
deti_list << group->texts();
for (DynamicElementTextItem *deti : deti_list)
{
QUndoCommand *undo = m_model->undoForEditedText(deti);
if (undo->childCount() == 1)
for (DynamicElementTextItem* deti : std::as_const(deti_list))
{
QPropertyUndoCommand *quc = new QPropertyUndoCommand(static_cast<const QPropertyUndoCommand *>(undo->child(0)));
if (quc->text().isEmpty())
quc->setText(undo->text());
undo_list << quc;
delete undo;
}
else if(undo->childCount() > 1)
undo_list << undo;
else
delete undo;
QUndoCommand* undo = m_model->undoForEditedText(deti);
if (undo->childCount() == 1)
{
QPropertyUndoCommand* quc = new QPropertyUndoCommand(
static_cast<const QPropertyUndoCommand*>(undo->child(0)));
if (quc->text().isEmpty()) quc->setText(undo->text());
undo_list << quc;
delete undo;
}
else if (undo->childCount() > 1)
undo_list << undo;
else
delete undo;
}
//Get all texts groups of the edited element
@@ -127,8 +127,7 @@ void DynamicElementTextItemEditor::apply()
{
QUndoStack &us = m_element->diagram()->undoStack();
us.beginMacro(tr("Modifier des textes d'élément"));
for (QUndoCommand *quc : undo_list)
us.push(quc);
for (QUndoCommand* quc : std::as_const(undo_list)) us.push(quc);
us.endMacro();
}
}

View File

@@ -1936,8 +1936,8 @@ QStringList DynamicTextItemDelegate::availableInfo(
QStringList info_list = QETInformation::elementInfoKeys();
info_list.removeAll("formula"); //No need to have formula
DiagramContext dc = elmt->elementInformations();
for(const QString& info : info_list)
for (const QString& info : std::as_const(info_list))
{
if(dc.contains(info))
qstrl << info;

View File

@@ -158,7 +158,7 @@ bool ElementInfoWidget::event(QEvent *event)
*/
void ElementInfoWidget::enableLiveEdit()
{
for (ElementInfoPartWidget *eipw : m_eipw_list)
for (ElementInfoPartWidget* eipw : std::as_const(m_eipw_list))
connect(eipw, &ElementInfoPartWidget::textChanged, this, &ElementInfoWidget::apply);
}
@@ -168,7 +168,7 @@ void ElementInfoWidget::enableLiveEdit()
*/
void ElementInfoWidget::disableLiveEdit()
{
for (ElementInfoPartWidget *eipw : m_eipw_list)
for (ElementInfoPartWidget* eipw : std::as_const(m_eipw_list))
disconnect(eipw, &ElementInfoPartWidget::textChanged, this, &ElementInfoWidget::apply);
}
@@ -185,11 +185,14 @@ void ElementInfoWidget::buildInterface()
keys = QETInformation::elementInfoKeys();
}
for (auto str : keys)
{
ElementInfoPartWidget *eipw = new ElementInfoPartWidget(str, QETInformation::translatedInfoKey(str), this);
ui->scroll_vlayout->addWidget(eipw);
m_eipw_list << eipw;
for (const auto& str : std::as_const(keys))
{
ElementInfoPartWidget* eipw = new ElementInfoPartWidget(
str,
QETInformation::translatedInfoKey(str),
this);
ui->scroll_vlayout->addWidget(eipw);
m_eipw_list << eipw;
}
ui->scroll_vlayout->addStretch();
@@ -227,8 +230,9 @@ void ElementInfoWidget::updateUi()
if (m_live_edit) disableLiveEdit();
const auto element_info{m_element->elementInformations()};
for (ElementInfoPartWidget *eipw : m_eipw_list) {
for (ElementInfoPartWidget* eipw : std::as_const(m_eipw_list))
{
eipw -> setText (element_info[eipw->key()].toString());
}

View File

@@ -140,7 +140,8 @@ void ElementPropertiesWidget::setDynamicText(DynamicElementTextItem *text)
if(text->parentElement())
{
setElement(text->parentElement());
for(AbstractElementPropertiesEditorWidget *aepew : m_list_editor)
for (AbstractElementPropertiesEditorWidget* aepew :
std::as_const(m_list_editor))
{
if (QString(aepew->metaObject()->className()) == "DynamicElementTextItemEditor")
{
@@ -166,7 +167,8 @@ void ElementPropertiesWidget::setTextsGroup(ElementTextItemGroup *group)
if(group->parentItem() && group->parentItem()->type() == Element::Type)
{
setElement(static_cast<Element *>(group->parentItem()));
for(AbstractElementPropertiesEditorWidget *aepew : m_list_editor)
for (AbstractElementPropertiesEditorWidget* aepew :
std::as_const(m_list_editor))
{
if (QString(aepew->metaObject()->className()) == "DynamicElementTextItemEditor")
{
@@ -314,7 +316,8 @@ void ElementPropertiesWidget::updateUi()
m_list_editor << new DynamicElementTextItemEditor(m_element, this);
//Add each editors in tab widget
for (AbstractElementPropertiesEditorWidget *aepew : m_list_editor)
for (AbstractElementPropertiesEditorWidget* aepew :
std::as_const(m_list_editor))
{
aepew->setLiveEdit(m_live_edit);
m_tab->addTab(aepew, aepew->title());

View File

@@ -71,7 +71,8 @@ IndiTextPropertiesWidget::~IndiTextPropertiesWidget()
void IndiTextPropertiesWidget::setText(IndependentTextItem *text)
{
if (m_text) {
for (QMetaObject::Connection c : m_connect_list) {
for (const QMetaObject::Connection& c : std::as_const(m_connect_list))
{
disconnect(c);
}
}
@@ -89,7 +90,8 @@ void IndiTextPropertiesWidget::setText(IndependentTextItem *text)
void IndiTextPropertiesWidget::setText(QList<IndependentTextItem *> text_list)
{
for (QMetaObject::Connection c : m_connect_list) {
for (const QMetaObject::Connection& c : std::as_const(m_connect_list))
{
disconnect(c);
}
m_connect_list.clear();
@@ -125,7 +127,9 @@ void IndiTextPropertiesWidget::apply()
if (m_text && m_text->diagram()) {
d = m_text->diagram();
} else if (!m_text_list.isEmpty()) {
for (QPointer<IndependentTextItem> piti : m_text_list) {
for (const QPointer<IndependentTextItem>& piti :
std::as_const(m_text_list))
{
if (piti->diagram()) {
d = piti->diagram();
break;
@@ -158,7 +162,9 @@ bool IndiTextPropertiesWidget::setLiveEdit(bool live_edit)
setUpEditConnection();
}
else {
for (QMetaObject::Connection c : m_edit_connection) {
for (const QMetaObject::Connection& c :
std::as_const(m_edit_connection))
{
disconnect(c);
}
m_edit_connection.clear();
@@ -220,7 +226,7 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const
qreal rotation_ = m_text_list.first()->rotation();
int size_ = m_text_list.first()->font().pointSize();
QFont font_ = m_text_list.first()->font();
for (QPointer<IndependentTextItem> piti : m_text_list)
for (const QPointer<IndependentTextItem>& piti : m_text_list)
{
if (piti->rotation() != rotation_) {
angle_equal = false;
@@ -236,7 +242,7 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const
if ((angle_equal && (ui->m_angle_sb->value() != rotation_)) ||
(!angle_equal && (ui->m_angle_sb->value() != ui->m_angle_sb->minimum())))
{
for (QPointer<IndependentTextItem> piti : m_text_list)
for (const QPointer<IndependentTextItem>& piti : m_text_list)
{
if (piti)
{
@@ -251,7 +257,7 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const
else if ((size_equal && (ui->m_size_sb->value() != size_)) ||
(!size_equal && (ui->m_size_sb->value() != ui->m_size_sb->minimum())))
{
for (QPointer<IndependentTextItem> piti : m_text_list)
for (const QPointer<IndependentTextItem>& piti : m_text_list)
{
if (piti)
{
@@ -267,7 +273,7 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const
else if ((m_font_is_selected && !font_equal) ||
(m_font_is_selected && (font_equal && (m_selected_font != font_))))
{
for (QPointer<IndependentTextItem> piti : m_text_list)
for (const QPointer<IndependentTextItem>& piti : m_text_list)
{
if (piti)
{
@@ -324,7 +330,8 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const
*/
void IndiTextPropertiesWidget::setUpEditConnection()
{
for (QMetaObject::Connection c : m_edit_connection) {
for (const QMetaObject::Connection& c : std::as_const(m_edit_connection))
{
disconnect(c);
}
m_edit_connection.clear();
@@ -354,7 +361,8 @@ void IndiTextPropertiesWidget::updateUi()
//Disconnect every connections of editor widgets
//to avoid an unwanted edition (QSpinBox emit valueChanged no matter if changer by user or by program)
for (QMetaObject::Connection c : m_edit_connection) {
for (const QMetaObject::Connection& c : std::as_const(m_edit_connection))
{
disconnect(c);
}
m_edit_connection.clear();
@@ -388,7 +396,8 @@ void IndiTextPropertiesWidget::updateUi()
int size_ = m_text_list.first()->font().pointSize();
QFont font_ = m_text_list.first()->font();
for (QPointer<IndependentTextItem> piti : m_text_list)
for (const QPointer<IndependentTextItem>& piti :
std::as_const(m_text_list))
{
if (piti->rotation() != rotation_) {
angle_equal = false;
@@ -403,7 +412,9 @@ void IndiTextPropertiesWidget::updateUi()
ui->m_angle_sb->setValue(angle_equal ? rotation_ : 0);
bool valid_ = true;
for (QPointer<IndependentTextItem> piti : m_text_list) {
for (const QPointer<IndependentTextItem>& piti :
std::as_const(m_text_list))
{
if (piti->isHtml()) {
valid_ = false;
}
@@ -436,10 +447,11 @@ void IndiTextPropertiesWidget::on_m_break_html_pb_clicked()
if (m_text) {
m_text->setPlainText(m_text->toPlainText());
}
for (QPointer<IndependentTextItem> piti : m_text_list) {
for (const QPointer<IndependentTextItem>& piti : std::as_const(m_text_list))
{
piti->setPlainText(piti->toPlainText());
}
updateUi();
}

View File

@@ -117,7 +117,7 @@ void MultiPasteDialog::on_m_button_box_accepted()
m_diagram->clearSelection();
m_diagram->undoStack().push(new PasteDiagramCommand(m_diagram, m_pasted_content));
for(DiagramContent dc : m_pasted_content_list)
for (const DiagramContent& dc : std::as_const(m_pasted_content_list))
{
QList<Element *> pasted_elements = dc.m_elements;
//Sort the list element by there pos (top -> bottom)

View File

@@ -204,7 +204,7 @@ ConductorProperties PotentialSelectorDialog::chosenProperties(QList<ConductorPro
layout.addWidget(&label);
QHash <QRadioButton *, ConductorProperties> H;
for (ConductorProperties cp : list)
for (const ConductorProperties& cp : list)
{
QString text;
if(!cp.text.isEmpty())

View File

@@ -121,7 +121,7 @@ void ShapeGraphicsItemPropertiesWidget::apply()
}
else if (!m_shapes_list.isEmpty())
{
for (QPointer<QetShapeItem> qsi : m_shapes_list)
for (const QPointer<QetShapeItem>& qsi : std::as_const(m_shapes_list))
{
if (qsi->diagram()) {
d = qsi->diagram();
@@ -222,7 +222,7 @@ QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const
if (ui->m_style_cb->currentIndex() != -1 &&
Qt::PenStyle(ui->m_style_cb->currentIndex() + 1) != shape_->pen().style())
{
for (QPointer<QetShapeItem> qsi : m_shapes_list)
for (const QPointer<QetShapeItem>& qsi : m_shapes_list)
{
QPen pen = qsi->pen();
@@ -239,7 +239,7 @@ QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const
if (ui->m_size_dsb->value() > 0 &&
ui->m_size_dsb->value() != shape_->pen().widthF())
{
for (QPointer<QetShapeItem> qsi : m_shapes_list)
for (const QPointer<QetShapeItem>& qsi : m_shapes_list)
{
QPen pen = pen_H.contains(qsi) ? pen_H.value(qsi) : qsi->pen();
pen.setWidthF(ui->m_size_dsb->value());
@@ -250,7 +250,7 @@ QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const
QColor c =ui->m_color_kpb->color();
if (c != QPalette().color(QPalette::Button) && shape_->pen().color() != c)
{
for (QPointer<QetShapeItem> qsi : m_shapes_list)
for (const QPointer<QetShapeItem>& qsi : m_shapes_list)
{
QPen pen = pen_H.contains(qsi) ? pen_H.value(qsi) : qsi->pen();
pen.setColor(c);
@@ -258,7 +258,7 @@ QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const
}
}
for (QPointer<QetShapeItem> qsi : pen_H.keys())
for (const QPointer<QetShapeItem>& qsi : pen_H.keys())
{
if (!parent_undo) {
parent_undo = new QUndoCommand(tr("Modifier une forme simple"));
@@ -271,7 +271,7 @@ QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const
if (ui->m_brush_style_cb->currentIndex() != -1 &&
shape_->brush().style() != Qt::BrushStyle(ui->m_brush_style_cb->currentIndex()))
{
for (QPointer<QetShapeItem> qsi : m_shapes_list)
for (const QPointer<QetShapeItem>& qsi : m_shapes_list)
{
QBrush brush = qsi->brush();
brush.setStyle(Qt::BrushStyle(ui->m_brush_style_cb->currentIndex()));
@@ -282,7 +282,7 @@ QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const
c = ui->m_brush_color_kpb->color();
if (c != QPalette().color(QPalette::Button) && shape_->brush().color() != c)
{
for (QPointer<QetShapeItem> qsi : m_shapes_list)
for (const QPointer<QetShapeItem>& qsi : m_shapes_list)
{
QBrush brush = brush_H.contains(qsi) ? brush_H.value(qsi) : qsi->brush();
brush.setColor(c);
@@ -290,7 +290,7 @@ QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const
}
}
for (QPointer<QetShapeItem> qsi : brush_H.keys())
for (const QPointer<QetShapeItem>& qsi : brush_H.keys())
{
if (!parent_undo) {
parent_undo = new QUndoCommand(tr("Modifier une forme simple"));
@@ -383,7 +383,8 @@ void ShapeGraphicsItemPropertiesWidget::updateUi()
bool same = true;
//Pen
Qt::PenStyle ps = m_shapes_list.first()->pen().style();
for (QetShapeItem *qsi : m_shapes_list) {
for (QetShapeItem* qsi : std::as_const(m_shapes_list))
{
if (qsi->pen().style() != ps) {
same = false;
break;
@@ -393,7 +394,8 @@ void ShapeGraphicsItemPropertiesWidget::updateUi()
same = true;
qreal pw = m_shapes_list.first()->pen().widthF();
for (QetShapeItem *qsi : m_shapes_list) {
for (QetShapeItem* qsi : std::as_const(m_shapes_list))
{
if (qsi->pen().widthF() != pw) {
same = false;
break;
@@ -403,7 +405,8 @@ void ShapeGraphicsItemPropertiesWidget::updateUi()
same = true;
QColor pc = m_shapes_list.first()->pen().color();
for (QetShapeItem *qsi : m_shapes_list) {
for (QetShapeItem* qsi : std::as_const(m_shapes_list))
{
if (qsi->pen().color() != pc) {
same = false;
break;
@@ -416,7 +419,8 @@ void ShapeGraphicsItemPropertiesWidget::updateUi()
same = true;
Qt::BrushStyle bs = m_shapes_list.first()->brush().style();
for (QetShapeItem *qsi : m_shapes_list) {
for (QetShapeItem* qsi : std::as_const(m_shapes_list))
{
if (qsi->brush().style() != bs) {
same = false;
break;
@@ -426,7 +430,8 @@ void ShapeGraphicsItemPropertiesWidget::updateUi()
same = true;
QColor bc = m_shapes_list.first()->brush().color();
for (QetShapeItem *qsi : m_shapes_list) {
for (QetShapeItem* qsi : std::as_const(m_shapes_list))
{
if (qsi->brush().color() != bc) {
same = false;
break;
@@ -516,7 +521,8 @@ void ShapeGraphicsItemPropertiesWidget::on_m_lock_pos_cb_clicked()
m_shape->setMovable(!ui->m_lock_pos_cb->isChecked());
}
else if (!m_shapes_list.isEmpty()) {
for (QPointer<QetShapeItem> qsi : m_shapes_list) {
for (const QPointer<QetShapeItem>& qsi : std::as_const(m_shapes_list))
{
qsi->setMovable(!ui->m_lock_pos_cb->isChecked());
}
}