Skip to content

Commit

Permalink
cleanup: Make member functions const where possible.
Browse files Browse the repository at this point in the history
```sh
run-clang-tidy -p _build -fix \
  $(find . -name "*.h" -or -name "*.cpp" -or -name "*.c" | grep -v "/_build/") \
  -checks="-*,readability-make-member-function-const"
```
  • Loading branch information
iphydf committed Jan 13, 2025
1 parent f905d61 commit 425524d
Show file tree
Hide file tree
Showing 22 changed files with 40 additions and 32 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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
"
Expand Down
2 changes: 1 addition & 1 deletion src/model/debug/debugobjecttreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DebugObjectTreeModel::TreeItem
qFatal("Parent tree item does not contain this item");
}

TreeItem* parentItem()
TreeItem* parentItem() const
{
return parent;
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/friendlist/friendlistmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/model/friendlist/friendlistmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/video/scopedavdictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
13 changes: 10 additions & 3 deletions src/video/scopedavdictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/widget/contentlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void ContentLayout::reloadTheme()
#endif
}

void ContentLayout::clear()
void ContentLayout::clear() const
{
QLayoutItem* item;
while ((item = mainHead->layout()->takeAt(0)) != nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion src/widget/contentlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/widget/form/chatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/widget/form/chatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private slots:
void previewImage(const QPixmap& pixmap);
void cancelImagePreview();
void sendImageFromPreview();
void doScreenshot();
void doScreenshot() const;
void onCopyStatusMessage();

void callUpdateFriendActivity();
Expand Down
6 changes: 3 additions & 3 deletions src/widget/form/settings/avform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<qreal>(steps) / totalSliderSteps) * (valMax - valMin) + valMin;
}
6 changes: 3 additions & 3 deletions src/widget/form/settings/avform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/widget/genericchatroomwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void GenericChatroomWidget::compactChange(bool _compact)
}
}

bool GenericChatroomWidget::isActive()
bool GenericChatroomWidget::isActive() const
{
return active;
}
Expand Down
2 changes: 1 addition & 1 deletion src/widget/genericchatroomwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/widget/searchtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/widget/tool/removechatdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/widget/tool/screenshotgrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void ScreenshotGrabber::reject()
deleteLater();
}

QPixmap ScreenshotGrabber::grabScreen()
QPixmap ScreenshotGrabber::grabScreen() const
{
QScreen* screen = QGuiApplication::primaryScreen();
QRect rec = screen->virtualGeometry();
Expand Down
2 changes: 1 addition & 1 deletion src/widget/tool/screenshotgrabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public slots:
bool handleKeyPress(QKeyEvent* event);
void reject();

QPixmap grabScreen();
QPixmap grabScreen() const;

void hideVisibleWindows();
void restoreHiddenWindows();
Expand Down
4 changes: 2 additions & 2 deletions src/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/widget/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/model/friendlistmanager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class FriendItemsBuilder
return this;
}

bool getConferencesOnTop()
bool getConferencesOnTop() const
{
return conferencesOnTop;
}
Expand Down
2 changes: 1 addition & 1 deletion test/persistence/dbschema_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class MockMessageBoxManager : public IMessageBoxManager
{
std::ignore = file;
}
int getErrorsShown()
int getErrorsShown() const
{
return errorsShown;
}
Expand Down

0 comments on commit 425524d

Please sign in to comment.