diff --git a/.clang-tidy b/.clang-tidy index c3bfe5720b..ed1417b029 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,6 @@ Checks: "-* , modernize-loop-convert +, modernize-return-braced-init-list , modernize-use-bool-literals , modernize-use-emplace , modernize-use-equals-* diff --git a/src/chatlog/chatlinecontent.cpp b/src/chatlog/chatlinecontent.cpp index b1a8681a61..443007d252 100644 --- a/src/chatlog/chatlinecontent.cpp +++ b/src/chatlog/chatlinecontent.cpp @@ -56,7 +56,7 @@ bool ChatLineContent::isOverSelection(QPointF scenePos) const QString ChatLineContent::getSelectedText() const { - return QString(); + return {}; } void ChatLineContent::fontChanged(const QFont& font) @@ -78,5 +78,5 @@ void ChatLineContent::reloadTheme() {} QString ChatLineContent::getText() const { - return QString(); + return {}; } diff --git a/src/chatlog/chatmessage.cpp b/src/chatlog/chatmessage.cpp index 1bc9be7592..218586abcb 100644 --- a/src/chatlog/chatmessage.cpp +++ b/src/chatlog/chatmessage.cpp @@ -255,7 +255,7 @@ QString ChatMessage::toString() const if (c) return c->getText(); - return QString(); + return {}; } bool ChatMessage::isAction() const diff --git a/src/chatlog/chatwidget.cpp b/src/chatlog/chatwidget.cpp index 0b3ca2e248..2f443da6cb 100644 --- a/src/chatlog/chatwidget.cpp +++ b/src/chatlog/chatwidget.cpp @@ -675,7 +675,7 @@ QString ChatWidget::getSelectedText() const return out; } - return QString(); + return {}; } bool ChatWidget::isEmpty() const @@ -994,7 +994,7 @@ ChatLine::Ptr ChatWidget::findLineByPosY(qreal yPos) const if (itr != chatLineStorage->end()) return *itr; - return ChatLine::Ptr(); + return {}; } void ChatWidget::removeLines(ChatLogIdx begin, ChatLogIdx end) @@ -1030,8 +1030,12 @@ QRectF ChatWidget::calculateSceneRect() const if (typingNotification.get() != nullptr) bottom += typingNotification->sceneBoundingRect().height() + lineSpacing; - return QRectF(-margins.left(), -margins.top(), useableWidth(), - bottom + margins.bottom() + margins.top()); + return { + static_cast(-margins.left()), + static_cast(-margins.top()), + useableWidth(), + bottom + margins.bottom() + margins.top(), + }; } void ChatWidget::onSelectionTimerTimeout() diff --git a/src/chatlog/content/notificationicon.cpp b/src/chatlog/content/notificationicon.cpp index 70f6ffadf4..8d6c1d2db0 100644 --- a/src/chatlog/content/notificationicon.cpp +++ b/src/chatlog/content/notificationicon.cpp @@ -26,7 +26,7 @@ NotificationIcon::NotificationIcon(Settings& settings, Style& style, QSize Size) QRectF NotificationIcon::boundingRect() const { - return QRectF(QPointF(-size.width() / 2.0, -size.height() / 2.0), size); + return {{-size.width() / 2.0, -size.height() / 2.0}, size}; } void NotificationIcon::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) diff --git a/src/chatlog/content/spinner.cpp b/src/chatlog/content/spinner.cpp index 085c5bc8b8..fdd37c9ef0 100644 --- a/src/chatlog/content/spinner.cpp +++ b/src/chatlog/content/spinner.cpp @@ -39,7 +39,7 @@ Spinner::Spinner(const QString& img, QSize Size, qreal speed) QRectF Spinner::boundingRect() const { - return QRectF(QPointF(-size.width() / 2.0, -size.height() / 2.0), size); + return {{-size.width() / 2.0, -size.height() / 2.0}, size}; } void Spinner::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index d8f6f032d4..f75d9c3e7e 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -202,7 +202,7 @@ void Text::fontChanged(const QFont& font) QRectF Text::boundingRect() const { - return QRectF(QPointF(0, 0), size); + return {{0, 0}, size}; } void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) @@ -445,7 +445,7 @@ QString Text::extractImgTooltip(int pos) const } } - return QString(); + return {}; } void Text::selectText(QTextCursor& cursor, const std::pair& point) diff --git a/src/chatlog/content/timestamp.cpp b/src/chatlog/content/timestamp.cpp index 1e53604d7c..cccc7781a2 100644 --- a/src/chatlog/content/timestamp.cpp +++ b/src/chatlog/content/timestamp.cpp @@ -21,7 +21,7 @@ QDateTime Timestamp::getTime() QSizeF Timestamp::idealSize() { if (doc) { - return QSizeF(qMin(doc->idealWidth(), width), doc->size().height()); + return {qMin(doc->idealWidth(), width), doc->size().height()}; } return size; } diff --git a/src/core/chatid.cpp b/src/core/chatid.cpp index 90c57acf23..456576425e 100644 --- a/src/core/chatid.cpp +++ b/src/core/chatid.cpp @@ -24,7 +24,7 @@ ChatId::~ChatId() = default; */ ChatId::ChatId(const QByteArray& rawId) { - id = QByteArray(rawId); + id = rawId; } /** @@ -86,7 +86,7 @@ const uint8_t* ChatId::getData() const */ QByteArray ChatId::getByteArray() const { - return QByteArray(id); // TODO: Is a copy really necessary? + return id; } /** diff --git a/src/core/core.cpp b/src/core/core.cpp index 7d8a39d5ba..6e48ca6503 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -1293,7 +1293,7 @@ ToxPk Core::getFriendPublicKey(uint32_t friendNumber) const tox_friend_get_public_key(tox.get(), friendNumber, rawid.data(), &error); if (!PARSE_ERR(error)) { qWarning() << "getFriendPublicKey: Getting public key failed"; - return ToxPk(); + return {}; } return ToxPk(rawid.data()); @@ -1309,13 +1309,13 @@ QString Core::getFriendUsername(uint32_t friendNumber) const Tox_Err_Friend_Query error; size_t nameSize = tox_friend_get_name_size(tox.get(), friendNumber, &error); if (!PARSE_ERR(error) || !nameSize) { - return QString(); + return {}; } std::vector nameBuf(nameSize); tox_friend_get_name(tox.get(), friendNumber, nameBuf.data(), &error); if (!PARSE_ERR(error)) { - return QString(); + return {}; } return ToxString(nameBuf.data(), nameSize).getQString(); } diff --git a/src/model/chatlogitem.cpp b/src/model/chatlogitem.cpp index eb0b382d74..15d8544cb6 100644 --- a/src/model/chatlogitem.cpp +++ b/src/model/chatlogitem.cpp @@ -118,7 +118,7 @@ QDateTime ChatLogItem::getTimestamp() const } assert(false); - return QDateTime(); + return {}; } void ChatLogItem::setDisplayName(QString name) diff --git a/src/model/conference.cpp b/src/model/conference.cpp index dbe8d98694..4de683f97f 100644 --- a/src/model/conference.cpp +++ b/src/model/conference.cpp @@ -185,7 +185,7 @@ QString Conference::resolveToxPk(const ToxPk& id) const return *it; } - return QString(); + return {}; } void Conference::setSelfName(const QString& name) diff --git a/src/model/debug/debuglogmodel.cpp b/src/model/debug/debuglogmodel.cpp index 860f8ac8ab..fd6bae9ac9 100644 --- a/src/model/debug/debuglogmodel.cpp +++ b/src/model/debug/debuglogmodel.cpp @@ -125,7 +125,7 @@ int DebugLogModel::rowCount(const QModelIndex& parent) const QVariant DebugLogModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) { - return QVariant(); + return {}; } if (role == Qt::DisplayRole) { @@ -147,7 +147,7 @@ QVariant DebugLogModel::data(const QModelIndex& index, int role) const } } - return QVariant(); + return {}; } void DebugLogModel::reload(const QStringList& newLogs) diff --git a/src/model/debug/debugobjecttreemodel.cpp b/src/model/debug/debugobjecttreemodel.cpp index 737ca9d59c..0447fff191 100644 --- a/src/model/debug/debugobjecttreemodel.cpp +++ b/src/model/debug/debugobjecttreemodel.cpp @@ -32,7 +32,7 @@ class DebugObjectTreeModel::TreeItem case 2: return QString::number(address, 16); default: - return QVariant(); + return {}; } } diff --git a/src/persistence/history.cpp b/src/persistence/history.cpp index 36b0035446..6d53504657 100644 --- a/src/persistence/history.cpp +++ b/src/persistence/history.cpp @@ -752,7 +752,7 @@ QDateTime History::getDateWhereFindPhrase(const ChatId& chatId, const QDateTime& QString phrase, const ParameterSearch& parameter) { if (historyAccessBlocked()) { - return QDateTime(); + return {}; } QDateTime result; diff --git a/src/persistence/profilelocker.cpp b/src/persistence/profilelocker.cpp index f9ec23d675..ed6d7f7836 100644 --- a/src/persistence/profilelocker.cpp +++ b/src/persistence/profilelocker.cpp @@ -134,5 +134,5 @@ QString ProfileLocker::getCurLockName() if (lockfile) return curLockName; else - return QString(); + return {}; } diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 6a84a2fb58..b55a21ed8f 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -1281,7 +1281,7 @@ QString Settings::getAutoAcceptDir(const ToxPk& id) const if (it != friendLst.end()) return it->autoAcceptDir; - return QString(); + return {}; } void Settings::setAutoAcceptDir(const ToxPk& id, const QString& dir) @@ -1310,7 +1310,7 @@ Settings::AutoAcceptCallFlags Settings::getAutoAcceptCall(const ToxPk& id) const if (it != friendLst.end()) return it->autoAcceptCall; - return Settings::AutoAcceptCallFlags(); + return {}; } void Settings::setAutoAcceptCall(const ToxPk& id, AutoAcceptCallFlags accept) @@ -1370,7 +1370,7 @@ QString Settings::getContactNote(const ToxPk& id) const if (it != friendLst.end()) return it->note; - return QString(); + return {}; } void Settings::setContactNote(const ToxPk& id, const QString& note) @@ -1883,7 +1883,7 @@ QString Settings::getFriendAlias(const ToxPk& id) const if (it != friendLst.end()) return it->alias; - return QString(); + return {}; } void Settings::setFriendAlias(const ToxPk& id, const QString& alias) @@ -1917,7 +1917,7 @@ QDateTime Settings::getFriendActivity(const ToxPk& id) const if (it != friendLst.end()) return it->activity; - return QDateTime(); + return {}; } void Settings::setFriendActivity(const ToxPk& id, const QDateTime& activity) diff --git a/src/platform/camera/v4l2.cpp b/src/platform/camera/v4l2.cpp index 2cf01d6c13..bde62a542f 100644 --- a/src/platform/camera/v4l2.cpp +++ b/src/platform/camera/v4l2.cpp @@ -205,7 +205,7 @@ QString v4l2::getPixelFormatString(uint32_t pixel_format) { if (pixFmtToName.find(pixel_format) == pixFmtToName.end()) { qWarning() << "Pixel format not found"; - return QString("invalid"); + return QStringLiteral("invalid"); } return pixFmtToName.at(pixel_format); } @@ -214,7 +214,8 @@ bool v4l2::betterPixelFormat(uint32_t a, uint32_t b) { if (pixFmtToQuality.find(a) == pixFmtToQuality.end()) { return false; - } else if (pixFmtToQuality.find(b) == pixFmtToQuality.end()) { + } + if (pixFmtToQuality.find(b) == pixFmtToQuality.end()) { return true; } return pixFmtToQuality.at(a) > pixFmtToQuality.at(b); diff --git a/src/video/videomode.cpp b/src/video/videomode.cpp index e1800095f0..a8a598b5d0 100644 --- a/src/video/videomode.cpp +++ b/src/video/videomode.cpp @@ -30,7 +30,7 @@ VideoMode::VideoMode(QRect rect) QRect VideoMode::toRect() const { - return QRect(x, y, width, height); + return {x, y, width, height}; } bool VideoMode::operator==(const VideoMode& other) const diff --git a/src/widget/form/filesform.cpp b/src/widget/form/filesform.cpp index 241f41d4ed..ffe341cd51 100644 --- a/src/widget/form/filesform.cpp +++ b/src/widget/form/filesform.cpp @@ -36,7 +36,7 @@ QRect pauseRect(const QStyleOptionViewItem& option) // our width from it int buttonXPos = std::round(option.rect.x() + buttonHorizontalArea / 2 - controlSize / 2); int buttonYPos = std::round(option.rect.y() + option.rect.height() * 0.1f); - return QRect(buttonXPos, buttonYPos, controlSize, controlSize); + return {buttonXPos, buttonYPos, static_cast(controlSize), static_cast(controlSize)}; } QRect stopRect(const QStyleOptionViewItem& option) @@ -50,7 +50,7 @@ QRect stopRect(const QStyleOptionViewItem& option) int buttonXPos = std::round(option.rect.x() + buttonHorizontalArea + buttonHorizontalArea / 2 - controlSize / 2); int buttonYPos = std::round(option.rect.y() + option.rect.height() * 0.1f); - return QRect(buttonXPos, buttonYPos, controlSize, controlSize); + return {buttonXPos, buttonYPos, static_cast(controlSize), static_cast(controlSize)}; } QString fileStatusString(ToxFile file) @@ -168,11 +168,11 @@ Model::Model(FriendList& friendList_, QObject* parent) QVariant Model::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole) { - return QVariant(); + return {}; } if (orientation != Qt::Orientation::Horizontal) { - return QVariant(); + return {}; } const auto column = toFileTransferListColumn(section); @@ -242,7 +242,7 @@ QVariant Model::data(const QModelIndex& index, int role) const const auto row = index.row(); if (row < 0 || static_cast(row) > files.size()) { qWarning("Invalid file transfer row %d (files: %zu)", row, files.size()); - return QVariant(); + return {}; } if (role == Qt::UserRole) { @@ -250,7 +250,7 @@ QVariant Model::data(const QModelIndex& index, int role) const } if (role != Qt::DisplayRole) { - return QVariant(); + return {}; } const auto column = toFileTransferListColumn(index.column()); @@ -281,7 +281,7 @@ QVariant Model::data(const QModelIndex& index, int role) const break; } - return QVariant(); + return {}; } bool Model::setData(const QModelIndex& index, const QVariant& value, int role) diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 66ceda6173..32460b3054 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -320,7 +320,7 @@ void GenericChatForm::hideFileMenu() QDateTime GenericChatForm::getLatestTime() const { if (chatLog.getFirstIdx() == chatLog.getNextIdx()) - return QDateTime(); + return {}; const auto shouldUseTimestamp = [this](ChatLogIdx idx) { if (chatLog.at(idx).getContentType() != ChatLogItem::ContentType::systemMessage) { @@ -359,7 +359,7 @@ QDateTime GenericChatForm::getLatestTime() const } } - return QDateTime(); + return {}; } void GenericChatForm::reloadTheme() @@ -525,11 +525,11 @@ QDateTime GenericChatForm::getTime(const ChatLine::Ptr& chatLine) const if (timestamp) { return timestamp->getTime(); } else { - return QDateTime(); + return {}; } } - return QDateTime(); + return {}; } diff --git a/src/widget/imagepreviewwidget.cpp b/src/widget/imagepreviewwidget.cpp index 2804db9e79..900705b4fd 100644 --- a/src/widget/imagepreviewwidget.cpp +++ b/src/widget/imagepreviewwidget.cpp @@ -27,12 +27,12 @@ QPixmap pixmapFromFile(const QString& filename) }; if (!previewExtensions.contains(QFileInfo(filename).suffix().toLower())) { - return QPixmap(); + return {}; } QFile imageFile(filename); if (!imageFile.open(QIODevice::ReadOnly)) { - return QPixmap(); + return {}; } const QByteArray imageFileData = imageFile.readAll(); diff --git a/src/widget/searchform.cpp b/src/widget/searchform.cpp index a73e179653..0c856cbcff 100644 --- a/src/widget/searchform.cpp +++ b/src/widget/searchform.cpp @@ -151,7 +151,7 @@ ParameterSearch SearchForm::getAndCheckParameterSearch() return sendParam; } - return ParameterSearch(); + return {}; } void SearchForm::setStateName(QPushButton* btn, ToolButtonState state) diff --git a/src/widget/tool/croppinglabel.cpp b/src/widget/tool/croppinglabel.cpp index c911e68ad0..18859577b8 100644 --- a/src/widget/tool/croppinglabel.cpp +++ b/src/widget/tool/croppinglabel.cpp @@ -88,12 +88,12 @@ void CroppingLabel::resizeEvent(QResizeEvent* ev) QSize CroppingLabel::sizeHint() const { - return QSize(0, QLabel::sizeHint().height()); + return {0, QLabel::sizeHint().height()}; } QSize CroppingLabel::minimumSizeHint() const { - return QSize(fontMetrics().horizontalAdvance("..."), QLabel::minimumSizeHint().height()); + return {fontMetrics().horizontalAdvance("..."), QLabel::minimumSizeHint().height()}; } void CroppingLabel::mouseReleaseEvent(QMouseEvent* e) diff --git a/src/widget/tool/screengrabberchooserrectitem.cpp b/src/widget/tool/screengrabberchooserrectitem.cpp index d099aebefa..e4713595ea 100644 --- a/src/widget/tool/screengrabberchooserrectitem.cpp +++ b/src/widget/tool/screengrabberchooserrectitem.cpp @@ -45,8 +45,12 @@ ScreenGrabberChooserRectItem::~ScreenGrabberChooserRectItem() = default; QRectF ScreenGrabberChooserRectItem::boundingRect() const { - return QRectF(-HandleSize - 1, -HandleSize - 1, rectWidth + HandleSize + 1, - rectHeight + HandleSize + 1); + return { + -HandleSize - 1, + -HandleSize - 1, + static_cast(rectWidth + HandleSize + 1), + static_cast(rectHeight + HandleSize + 1), + }; } void ScreenGrabberChooserRectItem::beginResize(QPointF mousePos) @@ -214,30 +218,30 @@ void ScreenGrabberChooserRectItem::mouseReleaseHandle(int x, int y, QGraphicsSce QPoint ScreenGrabberChooserRectItem::getHandleMultiplier(QGraphicsItem* handle) { if (handle == topLeft) - return QPoint(-1, -1); + return {-1, -1}; if (handle == topCenter) - return QPoint(0, -1); + return {0, -1}; if (handle == topRight) - return QPoint(1, -1); + return {1, -1}; if (handle == rightCenter) - return QPoint(1, 0); + return {1, 0}; if (handle == bottomRight) - return QPoint(1, 1); + return {1, 1}; if (handle == bottomCenter) - return QPoint(0, 1); + return {0, 1}; if (handle == bottomLeft) - return QPoint(-1, 1); + return {-1, 1}; if (handle == leftCenter) - return QPoint(-1, 0); + return {-1, 0}; - return QPoint(); + return {}; } void ScreenGrabberChooserRectItem::updateHandlePositions() diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 5059297f1c..0cd12da88e 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -52,7 +52,6 @@ #include "src/model/status.h" #include "src/net/updatecheck.h" #include "src/nexus.h" -#include "src/persistence/offlinemsgengine.h" #include "src/persistence/profile.h" #include "src/persistence/settings.h" #include "src/persistence/smileypack.h" @@ -1642,7 +1641,7 @@ QString Widget::fromDialogType(DialogType type) } assert(false); - return QString(); + return {}; } bool Widget::newMessageAlert(QWidget* currentWindow, bool isActive, bool sound, bool notify) @@ -2492,7 +2491,7 @@ inline QIcon Widget::prepareIcon(QString path, int w, int h) QPainter painter(&pm); renderer.render(&painter, pm.rect()); - return QIcon(pm); + return pm; } } #else diff --git a/test/mock/include/mock/mockcoreidhandler.h b/test/mock/include/mock/mockcoreidhandler.h index cd0402ef7d..b20bb96e50 100644 --- a/test/mock/include/mock/mockcoreidhandler.h +++ b/test/mock/include/mock/mockcoreidhandler.h @@ -20,7 +20,7 @@ class MockCoreIdHandler : public ICoreIdHandler ToxId getSelfId() const override { std::terminate(); - return ToxId(); + return {}; } ToxPk getSelfPublicKey() const override diff --git a/test/mock/include/mock/mockcoresettings.h b/test/mock/include/mock/mockcoresettings.h index 83c63c5da5..4080e390e0 100644 --- a/test/mock/include/mock/mockcoresettings.h +++ b/test/mock/include/mock/mockcoresettings.h @@ -5,10 +5,7 @@ #pragma once -#include "src/core/dhtserver.h" #include "src/core/icoresettings.h" -#include "src/core/toxpk.h" -#include "src/model/status.h" #include #include @@ -80,7 +77,7 @@ class MockSettings : public QObject, public ICoreSettings QNetworkProxy getProxy() const override { - return QNetworkProxy(QNetworkProxy::ProxyType::NoProxy); + return {QNetworkProxy::ProxyType::NoProxy}; } SIGNAL_IMPL(MockSettings, enableIPv6Changed, bool enabled)