diff --git a/.clang-tidy b/.clang-tidy index 77686d9d3c..1f6fc1b5e2 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -13,6 +13,7 @@ Checks: "-* , modernize-use-override , readability-container-* , readability-else-after-return +, readability-make-member-function-const , readability-named-parameter , readability-inconsistent-declaration-parameter-name " diff --git a/src/model/debug/debugobjecttreemodel.cpp b/src/model/debug/debugobjecttreemodel.cpp index 0447fff191..df97b054e1 100644 --- a/src/model/debug/debugobjecttreemodel.cpp +++ b/src/model/debug/debugobjecttreemodel.cpp @@ -52,7 +52,7 @@ class DebugObjectTreeModel::TreeItem qFatal("Parent tree item does not contain this item"); } - TreeItem* parentItem() + TreeItem* parentItem() const { return parent; } diff --git a/src/model/friendlist/friendlistmanager.cpp b/src/model/friendlist/friendlistmanager.cpp index b3cc053fe5..4daa8bf198 100644 --- a/src/model/friendlist/friendlistmanager.cpp +++ b/src/model/friendlist/friendlistmanager.cpp @@ -176,7 +176,7 @@ void FriendListManager::removeAll(IFriendListItem* item) } } -bool FriendListManager::cmpByName(const IFriendListItemPtr& a, const IFriendListItemPtr& b) +bool FriendListManager::cmpByName(const IFriendListItemPtr& a, const IFriendListItemPtr& b) const { if (a->isConference() && !b->isConference()) { if (conferencesOnTop) { diff --git a/src/model/friendlist/friendlistmanager.h b/src/model/friendlist/friendlistmanager.h index 171cb25837..1e1aaed78b 100644 --- a/src/model/friendlist/friendlistmanager.h +++ b/src/model/friendlist/friendlistmanager.h @@ -52,7 +52,7 @@ class FriendListManager : public QObject } filterParams; void removeAll(IFriendListItem* item); - bool cmpByName(const IFriendListItemPtr& itemA, const IFriendListItemPtr& itemB); + bool cmpByName(const IFriendListItemPtr& itemA, const IFriendListItemPtr& itemB) const; bool cmpByActivity(const IFriendListItemPtr& itemA, const IFriendListItemPtr& itemB); bool byName = true; diff --git a/src/video/scopedavdictionary.cpp b/src/video/scopedavdictionary.cpp index a4a3aec5b2..c0e1d9b36f 100644 --- a/src/video/scopedavdictionary.cpp +++ b/src/video/scopedavdictionary.cpp @@ -12,7 +12,7 @@ extern "C" void ScopedAVDictionary::Setter::operator=(const char* value) { - av_dict_set(dict, key, value, 0); + av_dict_set(dict_, key_, value, 0); } void ScopedAVDictionary::Setter::operator=(const QString& value) @@ -22,7 +22,7 @@ void ScopedAVDictionary::Setter::operator=(const QString& value) void ScopedAVDictionary::Setter::operator=(std::int64_t value) { - av_dict_set_int(dict, key, value, 0); + av_dict_set_int(dict_, key_, value, 0); } ScopedAVDictionary::~ScopedAVDictionary() diff --git a/src/video/scopedavdictionary.h b/src/video/scopedavdictionary.h index 79d631693b..c732c50964 100644 --- a/src/video/scopedavdictionary.h +++ b/src/video/scopedavdictionary.h @@ -15,10 +15,17 @@ class ScopedAVDictionary { AVDictionary* options = nullptr; - struct Setter + class Setter { - AVDictionary** dict; - const char* key; + AVDictionary** dict_; + const char* key_; + + public: + Setter(AVDictionary** dict, const char* key) + : dict_(dict) + , key_(key) + { + } void operator=(const char* value); void operator=(const QString& value); diff --git a/src/widget/contentlayout.cpp b/src/widget/contentlayout.cpp index eff9b64cb7..ead1731da2 100644 --- a/src/widget/contentlayout.cpp +++ b/src/widget/contentlayout.cpp @@ -65,7 +65,7 @@ void ContentLayout::reloadTheme() #endif } -void ContentLayout::clear() +void ContentLayout::clear() const { QLayoutItem* item; while ((item = mainHead->layout()->takeAt(0)) != nullptr) { diff --git a/src/widget/contentlayout.h b/src/widget/contentlayout.h index b3ed6de525..a64226c1f5 100644 --- a/src/widget/contentlayout.h +++ b/src/widget/contentlayout.h @@ -18,7 +18,7 @@ class ContentLayout : public QVBoxLayout explicit ContentLayout(Settings& settings, Style& style, QWidget* parent); ~ContentLayout() override; - void clear(); + void clear() const; QFrame mainHLine; QHBoxLayout mainHLineLayout; diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 689747c6df..ac91677813 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -567,7 +567,7 @@ void ChatForm::onScreenshotClicked() QTimer::singleShot(SCREENSHOT_GRABBER_OPENING_DELAY, this, &ChatForm::hideFileMenu); } -void ChatForm::doScreenshot() +void ChatForm::doScreenshot() const { // note: grabber is self-managed and will destroy itself when done ScreenshotGrabber* grabber = new ScreenshotGrabber; diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index 84ba350761..cd000f7d49 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -97,7 +97,7 @@ private slots: void previewImage(const QPixmap& pixmap); void cancelImagePreview(); void sendImageFromPreview(); - void doScreenshot(); + void doScreenshot() const; void onCopyStatusMessage(); void callUpdateFriendActivity(); diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index 951a735938..eb3826b4b0 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -145,7 +145,7 @@ void AVForm::open(const QString& devName, const VideoMode& mode) camera.setupDevice(devName, mode); } -void AVForm::trackNewScreenGeometry(QScreen* qScreen) +void AVForm::trackNewScreenGeometry(QScreen* qScreen) const { connect(qScreen, &QScreen::geometryChanged, this, &AVForm::rescanDevices); } @@ -628,13 +628,13 @@ void AVForm::retranslateUi() Ui::AVForm::retranslateUi(this); } -int AVForm::getStepsFromValue(qreal val, qreal valMin, qreal valMax) +int AVForm::getStepsFromValue(qreal val, qreal valMin, qreal valMax) const { const float norm = (val - valMin) / (valMax - valMin); return norm * totalSliderSteps; } -qreal AVForm::getValueFromSteps(int steps, qreal valMin, qreal valMax) +qreal AVForm::getValueFromSteps(int steps, qreal valMin, qreal valMax) const { return (static_cast(steps) / totalSliderSteps) * (valMax - valMin) + valMin; } diff --git a/src/widget/form/settings/avform.h b/src/widget/form/settings/avform.h index 88160d23a0..39cc19a9c7 100644 --- a/src/widget/form/settings/avform.h +++ b/src/widget/form/settings/avform.h @@ -77,9 +77,9 @@ private slots: void hideEvent(QHideEvent* event) final; void showEvent(QShowEvent* event) final; void open(const QString& devName, const VideoMode& mode); - int getStepsFromValue(qreal val, qreal valMin, qreal valMax); - qreal getValueFromSteps(int steps, qreal valMin, qreal valMax); - void trackNewScreenGeometry(QScreen* qScreen); + int getStepsFromValue(qreal val, qreal valMin, qreal valMax) const; + qreal getValueFromSteps(int steps, qreal valMin, qreal valMax) const; + void trackNewScreenGeometry(QScreen* qScreen) const; private: IAudioControl& audio; diff --git a/src/widget/genericchatroomwidget.cpp b/src/widget/genericchatroomwidget.cpp index fe10a5aef9..8eb3797443 100644 --- a/src/widget/genericchatroomwidget.cpp +++ b/src/widget/genericchatroomwidget.cpp @@ -106,7 +106,7 @@ void GenericChatroomWidget::compactChange(bool _compact) } } -bool GenericChatroomWidget::isActive() +bool GenericChatroomWidget::isActive() const { return active; } diff --git a/src/widget/genericchatroomwidget.h b/src/widget/genericchatroomwidget.h index 350493a5ee..35313138c7 100644 --- a/src/widget/genericchatroomwidget.h +++ b/src/widget/genericchatroomwidget.h @@ -42,7 +42,7 @@ public slots: bool eventFilter(QObject* object, QEvent* event) final; - bool isActive(); + bool isActive() const; void setName(const QString& name); void setStatusMsg(const QString& status); diff --git a/src/widget/searchtypes.h b/src/widget/searchtypes.h index 34403ef1bd..95490852a3 100644 --- a/src/widget/searchtypes.h +++ b/src/widget/searchtypes.h @@ -40,12 +40,12 @@ struct ParameterSearch QDate date; bool isUpdate{false}; - bool operator==(const ParameterSearch& other) + bool operator==(const ParameterSearch& other) const { return filter == other.filter && period == other.period && date == other.date; } - bool operator!=(const ParameterSearch& other) + bool operator!=(const ParameterSearch& other) const { return !(*this == other); } diff --git a/src/widget/tool/removechatdialog.h b/src/widget/tool/removechatdialog.h index 1dbbfda5af..38c2066c84 100644 --- a/src/widget/tool/removechatdialog.h +++ b/src/widget/tool/removechatdialog.h @@ -17,12 +17,12 @@ class RemoveChatDialog : public QDialog public: explicit RemoveChatDialog(QWidget* parent, const Chat& contact); - inline bool removeHistory() + bool removeHistory() const { return ui.removeHistory->isChecked(); } - inline bool accepted() + bool accepted() const { return _accepted; } diff --git a/src/widget/tool/screenshotgrabber.cpp b/src/widget/tool/screenshotgrabber.cpp index de4c216f00..84540d4fae 100644 --- a/src/widget/tool/screenshotgrabber.cpp +++ b/src/widget/tool/screenshotgrabber.cpp @@ -203,7 +203,7 @@ void ScreenshotGrabber::reject() deleteLater(); } -QPixmap ScreenshotGrabber::grabScreen() +QPixmap ScreenshotGrabber::grabScreen() const { QScreen* screen = QGuiApplication::primaryScreen(); QRect rec = screen->virtualGeometry(); diff --git a/src/widget/tool/screenshotgrabber.h b/src/widget/tool/screenshotgrabber.h index fc7ee7c645..417d37a3b6 100644 --- a/src/widget/tool/screenshotgrabber.h +++ b/src/widget/tool/screenshotgrabber.h @@ -54,7 +54,7 @@ public slots: bool handleKeyPress(QKeyEvent* event); void reject(); - QPixmap grabScreen(); + QPixmap grabScreen() const; void hideVisibleWindows(); void restoreHiddenWindows(); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 7c94962866..6285a4f322 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -2710,12 +2710,12 @@ void Widget::refreshPeerListsLocal(const QString& username) } } -void Widget::connectCircleWidget(CircleWidget& circleWidget) +void Widget::connectCircleWidget(CircleWidget& circleWidget) const { connect(&circleWidget, &CircleWidget::newContentDialog, this, &Widget::registerContentDialog); } -void Widget::connectFriendWidget(FriendWidget& friendWidget) +void Widget::connectFriendWidget(FriendWidget& friendWidget) const { connect(&friendWidget, &FriendWidget::updateFriendActivity, this, &Widget::updateFriendActivity); } diff --git a/src/widget/widget.h b/src/widget/widget.h index 5b4ec093ad..d40698f069 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -245,8 +245,8 @@ private slots: void dispatchFile(ToxFile file); void dispatchFileWithBool(ToxFile file, bool pausedOrBroken); void dispatchFileSendFailed(uint32_t friendId, const QString& fileName); - void connectCircleWidget(CircleWidget& circleWidget); - void connectFriendWidget(FriendWidget& friendWidget); + void connectCircleWidget(CircleWidget& circleWidget) const; + void connectFriendWidget(FriendWidget& friendWidget) const; void searchCircle(CircleWidget& circleWidget); void updateFriendActivity(const Friend& frnd); void registerContentDialog(ContentDialog& contentDialog) const; diff --git a/test/model/friendlistmanager_test.cpp b/test/model/friendlistmanager_test.cpp index e24ddc6db9..0d09bd5c0e 100644 --- a/test/model/friendlistmanager_test.cpp +++ b/test/model/friendlistmanager_test.cpp @@ -204,7 +204,7 @@ class FriendItemsBuilder return this; } - bool getConferencesOnTop() + bool getConferencesOnTop() const { return conferencesOnTop; } diff --git a/test/persistence/dbschema_test.cpp b/test/persistence/dbschema_test.cpp index 1bb4e9eadd..9be9845ee1 100644 --- a/test/persistence/dbschema_test.cpp +++ b/test/persistence/dbschema_test.cpp @@ -100,7 +100,7 @@ class MockMessageBoxManager : public IMessageBoxManager { std::ignore = file; } - int getErrorsShown() + int getErrorsShown() const { return errorsShown; }