Skip to content

Commit

Permalink
cleanup: Return braced initialiser list where possible.
Browse files Browse the repository at this point in the history
```
run-clang-tidy -p _build -fix $(find . -name "*.h" -or -name "*.cpp" \
  -or -name "*.c" | grep -v "/_build/") \
  -checks="-*,modernize-return-braced-init-list"
```
  • Loading branch information
iphydf committed Jan 8, 2025
1 parent 075218e commit 93cdc7e
Show file tree
Hide file tree
Showing 28 changed files with 73 additions and 67 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Checks: "-*
, modernize-loop-convert
, modernize-return-braced-init-list
, modernize-use-bool-literals
, modernize-use-emplace
, modernize-use-equals-*
Expand Down
4 changes: 2 additions & 2 deletions src/chatlog/chatlinecontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool ChatLineContent::isOverSelection(QPointF scenePos) const

QString ChatLineContent::getSelectedText() const
{
return QString();
return {};
}

void ChatLineContent::fontChanged(const QFont& font)
Expand All @@ -78,5 +78,5 @@ void ChatLineContent::reloadTheme() {}

QString ChatLineContent::getText() const
{
return QString();
return {};
}
2 changes: 1 addition & 1 deletion src/chatlog/chatmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ QString ChatMessage::toString() const
if (c)
return c->getText();

return QString();
return {};
}

bool ChatMessage::isAction() const
Expand Down
12 changes: 8 additions & 4 deletions src/chatlog/chatwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ QString ChatWidget::getSelectedText() const
return out;
}

return QString();
return {};
}

bool ChatWidget::isEmpty() const
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<qreal>(-margins.left()),
static_cast<qreal>(-margins.top()),
useableWidth(),
bottom + margins.bottom() + margins.top(),
};
}

void ChatWidget::onSelectionTimerTimeout()
Expand Down
2 changes: 1 addition & 1 deletion src/chatlog/content/notificationicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/chatlog/content/spinner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/chatlog/content/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -445,7 +445,7 @@ QString Text::extractImgTooltip(int pos) const
}
}

return QString();
return {};
}

void Text::selectText(QTextCursor& cursor, const std::pair<int, int>& point)
Expand Down
2 changes: 1 addition & 1 deletion src/chatlog/content/timestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/core/chatid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ChatId::~ChatId() = default;
*/
ChatId::ChatId(const QByteArray& rawId)
{
id = QByteArray(rawId);
id = rawId;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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<uint8_t> 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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/chatlogitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ QDateTime ChatLogItem::getTimestamp() const
}

assert(false);
return QDateTime();
return {};
}

void ChatLogItem::setDisplayName(QString name)
Expand Down
2 changes: 1 addition & 1 deletion src/model/conference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ QString Conference::resolveToxPk(const ToxPk& id) const
return *it;
}

return QString();
return {};
}

void Conference::setSelfName(const QString& name)
Expand Down
4 changes: 2 additions & 2 deletions src/model/debug/debuglogmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -147,7 +147,7 @@ QVariant DebugLogModel::data(const QModelIndex& index, int role) const
}
}

return QVariant();
return {};
}

void DebugLogModel::reload(const QStringList& newLogs)
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 @@ -32,7 +32,7 @@ class DebugObjectTreeModel::TreeItem
case 2:
return QString::number(address, 16);
default:
return QVariant();
return {};
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/persistence/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ QDateTime History::getDateWhereFindPhrase(const ChatId& chatId, const QDateTime&
QString phrase, const ParameterSearch& parameter)
{
if (historyAccessBlocked()) {
return QDateTime();
return {};
}

QDateTime result;
Expand Down
2 changes: 1 addition & 1 deletion src/persistence/profilelocker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,5 @@ QString ProfileLocker::getCurLockName()
if (lockfile)
return curLockName;
else
return QString();
return {};
}
10 changes: 5 additions & 5 deletions src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/platform/camera/v4l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/video/videomode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/widget/form/filesform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(controlSize), static_cast<int>(controlSize)};
}

QRect stopRect(const QStyleOptionViewItem& option)
Expand All @@ -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<int>(controlSize), static_cast<int>(controlSize)};
}

QString fileStatusString(ToxFile file)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -242,15 +242,15 @@ QVariant Model::data(const QModelIndex& index, int role) const
const auto row = index.row();
if (row < 0 || static_cast<size_t>(row) > files.size()) {
qWarning("Invalid file transfer row %d (files: %zu)", row, files.size());
return QVariant();
return {};
}

if (role == Qt::UserRole) {
return files[row].filePath;
}

if (role != Qt::DisplayRole) {
return QVariant();
return {};
}

const auto column = toFileTransferListColumn(index.column());
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/widget/form/genericchatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -359,7 +359,7 @@ QDateTime GenericChatForm::getLatestTime() const
}
}

return QDateTime();
return {};
}

void GenericChatForm::reloadTheme()
Expand Down Expand Up @@ -525,11 +525,11 @@ QDateTime GenericChatForm::getTime(const ChatLine::Ptr& chatLine) const
if (timestamp) {
return timestamp->getTime();
} else {
return QDateTime();
return {};
}
}

return QDateTime();
return {};
}


Expand Down
4 changes: 2 additions & 2 deletions src/widget/imagepreviewwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 93cdc7e

Please sign in to comment.