From e2f1452cb8b3a564b6520e97c548221f15e07590 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 25 Jul 2022 11:23:27 +0200 Subject: [PATCH] Spreadsheet: [skip ci] Fix several clazy issues: * Mixing iterators with const_iterators [-Wclazy-strict-iterators] * Q_PROPERTY should have either NOTIFY or CONSTANT [-Wclazy-qproperty-without-notify] * Missing reference in range-for with non trivial type [-Wclazy-range-loop-reference] * Missing emit keyword on signal call SpreadsheetGui::SheetViewHeader::resizeFinished [-Wclazy-incorrect-emit] * Missing emit keyword on signal call QAbstractItemModel::dataChanged [-Wclazy-incorrect-emit] * c++11 range-loop might detach Qt container (QStringList) [-Wclazy-range-loop-detach] --- src/Mod/Spreadsheet/Gui/Command.cpp | 6 +++--- src/Mod/Spreadsheet/Gui/SheetModel.cpp | 4 ++-- src/Mod/Spreadsheet/Gui/SheetTableView.cpp | 16 ++++++++-------- src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp | 2 +- src/Mod/Spreadsheet/Gui/qtcolorpicker.h | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Mod/Spreadsheet/Gui/Command.cpp b/src/Mod/Spreadsheet/Gui/Command.cpp index 3e9ed3a5d4..dc6e5b78cc 100644 --- a/src/Mod/Spreadsheet/Gui/Command.cpp +++ b/src/Mod/Spreadsheet/Gui/Command.cpp @@ -626,7 +626,7 @@ void CmdSpreadsheetStyleBold::activated(int iMsg) if (selection.size() > 0) { bool allBold = true; - for (QModelIndexList::const_iterator it = selection.begin(); it != selection.end(); ++it) { + for (QModelIndexList::const_iterator it = selection.cbegin(); it != selection.cend(); ++it) { const Cell * cell = sheet->getCell(CellAddress((*it).row(), (*it).column())); if (cell) { @@ -700,7 +700,7 @@ void CmdSpreadsheetStyleItalic::activated(int iMsg) if (selection.size() > 0) { bool allItalic = true; - for (QModelIndexList::const_iterator it = selection.begin(); it != selection.end(); ++it) { + for (QModelIndexList::const_iterator it = selection.cbegin(); it != selection.cend(); ++it) { const Cell * cell = sheet->getCell(CellAddress((*it).row(), (*it).column())); if (cell) { @@ -774,7 +774,7 @@ void CmdSpreadsheetStyleUnderline::activated(int iMsg) if (selection.size() > 0) { bool allUnderline = true; - for (QModelIndexList::const_iterator it = selection.begin(); it != selection.end(); ++it) { + for (QModelIndexList::const_iterator it = selection.cbegin(); it != selection.cend(); ++it) { const Cell * cell = sheet->getCell(CellAddress((*it).row(), (*it).column())); if (cell) { diff --git a/src/Mod/Spreadsheet/Gui/SheetModel.cpp b/src/Mod/Spreadsheet/Gui/SheetModel.cpp index ad0bcadacd..d1a57d92a4 100644 --- a/src/Mod/Spreadsheet/Gui/SheetModel.cpp +++ b/src/Mod/Spreadsheet/Gui/SheetModel.cpp @@ -516,7 +516,7 @@ void SheetModel::cellUpdated(CellAddress address) { QModelIndex i = index(address.row(), address.col()); - dataChanged(i, i); + Q_EMIT dataChanged(i, i); } void SheetModel::rangeUpdated(const Range &range) @@ -524,7 +524,7 @@ void SheetModel::rangeUpdated(const Range &range) QModelIndex i = index(range.from().row(), range.from().col()); QModelIndex j = index(range.to().row(), range.to().col()); - dataChanged(i, j); + Q_EMIT dataChanged(i, j); } #include "moc_SheetModel.cpp" diff --git a/src/Mod/Spreadsheet/Gui/SheetTableView.cpp b/src/Mod/Spreadsheet/Gui/SheetTableView.cpp index 86d8d36b57..cf9f27d709 100644 --- a/src/Mod/Spreadsheet/Gui/SheetTableView.cpp +++ b/src/Mod/Spreadsheet/Gui/SheetTableView.cpp @@ -60,7 +60,7 @@ namespace bp = boost::placeholders; void SheetViewHeader::mouseReleaseEvent(QMouseEvent *event) { QHeaderView::mouseReleaseEvent(event); - resizeFinished(); + Q_EMIT resizeFinished(); } bool SheetViewHeader::viewportEvent(QEvent *e) { @@ -314,7 +314,7 @@ void SheetTableView::insertRows() std::vector sortedRows; /* Make sure rows are sorted in ascending order */ - for (QModelIndexList::const_iterator it = rows.begin(); it != rows.end(); ++it) + for (QModelIndexList::const_iterator it = rows.cbegin(); it != rows.cend(); ++it) sortedRows.push_back(it->row()); std::sort(sortedRows.begin(), sortedRows.end()); @@ -365,7 +365,7 @@ void SheetTableView::removeRows() std::vector sortedRows; /* Make sure rows are sorted in descending order */ - for (QModelIndexList::const_iterator it = rows.begin(); it != rows.end(); ++it) + for (QModelIndexList::const_iterator it = rows.cbegin(); it != rows.cend(); ++it) sortedRows.push_back(it->row()); std::sort(sortedRows.begin(), sortedRows.end(), std::greater()); @@ -386,7 +386,7 @@ void SheetTableView::insertColumns() std::vector sortedColumns; /* Make sure rows are sorted in ascending order */ - for (QModelIndexList::const_iterator it = cols.begin(); it != cols.end(); ++it) + for (QModelIndexList::const_iterator it = cols.cbegin(); it != cols.cend(); ++it) sortedColumns.push_back(it->column()); std::sort(sortedColumns.begin(), sortedColumns.end()); @@ -438,7 +438,7 @@ void SheetTableView::removeColumns() std::vector sortedColumns; /* Make sure rows are sorted in descending order */ - for (QModelIndexList::const_iterator it = cols.begin(); it != cols.end(); ++it) + for (QModelIndexList::const_iterator it = cols.cbegin(); it != cols.cend(); ++it) sortedColumns.push_back(it->column()); std::sort(sortedColumns.begin(), sortedColumns.end(), std::greater()); @@ -694,13 +694,13 @@ void SheetTableView::pasteClipboard() Range range = ranges.back(); if (!mimeData->hasFormat(_SheetMime)) { CellAddress current = range.from(); - QStringList cells; QString text = mimeData->text(); + QStringList cells = text.split(QLatin1Char('\n')); int i=0; - for (auto it : text.split(QLatin1Char('\n'))) { + for (const auto& it : cells) { QStringList cols = it.split(QLatin1Char('\t')); int j=0; - for (auto jt : cols) { + for (const auto& jt : cols) { QModelIndex index = model()->index(current.row()+i, current.col()+j); model()->setData(index, jt); j++; diff --git a/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp b/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp index 8b0d104c7c..18b25074e9 100644 --- a/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp +++ b/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp @@ -581,7 +581,7 @@ Py::Object SheetViewPy::getattr(const char * attr) if (name == "__dict__" || name == "__class__") { Py::Dict dict_self(BaseType::getattr("__dict__")); Py::Dict dict_base(base.getattr("__dict__")); - for (auto it : dict_base) { + for (const auto& it : dict_base) { dict_self.setItem(it.first, it.second); } return dict_self; diff --git a/src/Mod/Spreadsheet/Gui/qtcolorpicker.h b/src/Mod/Spreadsheet/Gui/qtcolorpicker.h index 6122183b17..e7e344fdc3 100644 --- a/src/Mod/Spreadsheet/Gui/qtcolorpicker.h +++ b/src/Mod/Spreadsheet/Gui/qtcolorpicker.h @@ -76,7 +76,7 @@ class QT_QTCOLORPICKER_EXPORT QtColorPicker : public QPushButton { Q_OBJECT - Q_PROPERTY(bool colorDialog READ colorDialogEnabled WRITE setColorDialogEnabled) + Q_PROPERTY(bool colorDialog READ colorDialogEnabled WRITE setColorDialogEnabled) // clazy:exclude=qproperty-without-notify public: QtColorPicker(QWidget *parent = nullptr,