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

@@ -160,7 +160,8 @@ void projectDataBase::removeElement(Element *element)
void projectDataBase::elementInfoChanged(Element *element)
{
auto hash = elementInfoToString(element);
for (auto str : QETInformation::elementInfoKeys()) {
for (const auto& str : QETInformation::elementInfoKeys())
{
m_update_element_query.bindValue(":" + str, hash.value(str));
}
m_update_element_query.bindValue(":uuid", element->uuid().toString());
@@ -540,7 +541,8 @@ void projectDataBase::prepareQuery()
//UPDATE DIAGRAM INFO
QString update_diagram_str("UPDATE diagram_info SET ");
for (auto str : QETInformation::diagramInfoKeys()) {
for (const auto& str : QETInformation::diagramInfoKeys())
{
update_diagram_str.append(str + " = :" + str + ", ");
}
update_diagram_str.remove(update_diagram_str.length()-2, 2); //Remove the last ", "
@@ -580,7 +582,8 @@ void projectDataBase::prepareQuery()
//UPDATE ELEMENT INFO
QString update_str("UPDATE element_info SET ");
for (auto string : QETInformation::elementInfoKeys()) {
for (const auto& string : QETInformation::elementInfoKeys())
{
update_str.append(string + " = :" + string + ", ");
}
update_str.remove(update_str.length()-2, 2); //Remove the last ", "
@@ -597,7 +600,7 @@ void projectDataBase::prepareQuery()
QHash<QString, QString> projectDataBase::elementInfoToString(Element *elmt)
{
QHash<QString, QString> hash; //Store the value for each columns
for (auto key : QETInformation::elementInfoKeys())
for (const auto& key : QETInformation::elementInfoKeys())
{
if (key == "label") {
hash.insert(key, elmt->actualLabel());

View File

@@ -130,9 +130,9 @@ void ElementQueryWidget::setQuery(const QString &query)
//Get the select -> the item in the right list
QStringList split = select.split(",");
for (auto str : split)
for (const auto& str : std::as_const(split))
{
for (auto item : m_items_list)
for (auto item : std::as_const(m_items_list))
{
if (item->data(Qt::UserRole).toString() == str) {
ui->m_var_list->takeItem(ui->m_var_list->row(item));
@@ -209,7 +209,8 @@ void ElementQueryWidget::setQuery(const QString &query)
//Filter for selected data
QStringList strl;
for (auto item : m_items_list) {
for (auto item : std::as_const(m_items_list))
{
strl.append(item->data(Qt::UserRole).toString());
}
@@ -236,7 +237,7 @@ void ElementQueryWidget::setQuery(const QString &query)
QRegularExpressionMatch rxm;
for (auto str : split_where)
for (const auto& str : split_where)
{
rxm = rx_is_not_null.match(str);
if (rxm.hasMatch()) {
@@ -297,7 +298,8 @@ QString ElementQueryWidget::queryStr() const
QString column;
bool first = true;
for (auto key: keys) {
for (auto key : std::as_const(keys))
{
if (first) {
first = false;
} else {
@@ -454,7 +456,7 @@ QStringList ElementQueryWidget::selectedKeys() const
*/
void ElementQueryWidget::setUpItems()
{
for(QString key : QETInformation::elementInfoKeys())
for (const QString& key : QETInformation::elementInfoKeys())
{
if (key == "formula")
continue;
@@ -464,8 +466,7 @@ void ElementQueryWidget::setUpItems()
m_items_list << item;
}
for (auto key : m_export_info.keys())
for (const auto& key : m_export_info.keys())
{
auto item = new QListWidgetItem(m_export_info.value(key), ui->m_var_list);
item->setData(Qt::UserRole, key);

View File

@@ -67,7 +67,8 @@ QString SummaryQueryWidget::queryStr() const
QString column;
bool first = true;
for (auto key: keys) {
for (const auto& key : std::as_const(keys))
{
if (first) {
first = false;
} else {
@@ -104,9 +105,9 @@ void SummaryQueryWidget::setQuery(const QString &query)
//Get the select -> the item in the right list
QStringList split = select.split(",");
for (auto str : split)
for (const auto& str : std::as_const(split))
{
for (auto item : m_items_list)
for (auto item : std::as_const(m_items_list))
{
if (item->data(Qt::UserRole).toString() == str) {
ui->m_available_list->takeItem(ui->m_available_list->row(item));
@@ -123,7 +124,7 @@ void SummaryQueryWidget::setQuery(const QString &query)
*/
void SummaryQueryWidget::setUpItems()
{
for (auto key : QETInformation::diagramInfoKeys())
for (const auto& key : QETInformation::diagramInfoKeys())
{
if (key == "filename" || key == "display_folio") {
continue;