From b3c09b65d8e5276f07fcd4b190b1df3308a3d912 Mon Sep 17 00:00:00 2001 From: nerix Date: Sat, 20 Jul 2024 11:35:59 +0200 Subject: [PATCH] chore: mini refactorings and dead code removal (#5512) --- src/Application.cpp | 1 - src/CMakeLists.txt | 3 - src/common/ConcurrentMap.hpp | 102 ------------------- src/common/Credentials.cpp | 1 - src/providers/irc/IrcCommands.cpp | 1 - src/providers/twitch/PubSubClient.cpp | 1 - src/providers/twitch/PubSubManager.cpp | 1 - src/providers/twitch/PubSubMessages.hpp | 17 ++-- src/singletons/Settings.cpp | 6 +- src/singletons/WindowManager.cpp | 1 - src/util/Clamp.hpp | 13 --- src/util/ConcurrentMap.hpp | 102 ------------------- src/util/DisplayBadge.hpp | 1 + src/util/DistanceBetweenPoints.hpp | 8 +- src/util/ExponentialBackoff.hpp | 4 +- src/util/Helpers.cpp | 6 +- src/util/Helpers.hpp | 4 +- src/util/LayoutCreator.hpp | 96 +++++++---------- src/util/Overloaded.hpp | 13 --- src/util/PersistSignalVector.hpp | 28 ----- src/util/PostToThread.hpp | 24 ----- src/util/SplitCommand.cpp | 97 ------------------ src/util/SplitCommand.hpp | 15 --- src/util/StreamLink.cpp | 7 +- src/widgets/settingspages/ModerationPage.cpp | 7 +- src/widgets/settingspages/ModerationPage.hpp | 5 +- src/widgets/splits/SplitInput.cpp | 5 +- tests/src/Helpers.cpp | 2 +- 28 files changed, 65 insertions(+), 506 deletions(-) delete mode 100644 src/common/ConcurrentMap.hpp delete mode 100644 src/util/Clamp.hpp delete mode 100644 src/util/ConcurrentMap.hpp delete mode 100644 src/util/Overloaded.hpp delete mode 100644 src/util/PersistSignalVector.hpp delete mode 100644 src/util/SplitCommand.cpp delete mode 100644 src/util/SplitCommand.hpp diff --git a/src/Application.cpp b/src/Application.cpp index 2c97b8fd2..30e7cdb26 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -42,7 +42,6 @@ #include "providers/twitch/PubSubActions.hpp" #include "providers/twitch/PubSubManager.hpp" #include "providers/twitch/PubSubMessages.hpp" -#include "providers/twitch/pubsubmessages/LowTrustUsers.hpp" #include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchIrcServer.hpp" #include "providers/twitch/TwitchMessageBuilder.hpp" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9df047665..3e6f0939b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -487,7 +487,6 @@ set(SOURCE_FILES util/ChannelHelpers.hpp util/Clipboard.cpp util/Clipboard.hpp - util/ConcurrentMap.hpp util/DebugCount.cpp util/DebugCount.hpp util/DisplayBadge.cpp @@ -517,8 +516,6 @@ set(SOURCE_FILES util/SampleData.cpp util/SampleData.hpp util/SharedPtrElementLess.hpp - util/SplitCommand.cpp - util/SplitCommand.hpp util/StreamLink.cpp util/StreamLink.hpp util/ThreadGuard.hpp diff --git a/src/common/ConcurrentMap.hpp b/src/common/ConcurrentMap.hpp deleted file mode 100644 index 6f385559b..000000000 --- a/src/common/ConcurrentMap.hpp +++ /dev/null @@ -1,102 +0,0 @@ -#pragma once - -#include -#include -#include - -#include -#include -#include - -namespace chatterino { - -template -class ConcurrentMap -{ -public: - ConcurrentMap() = default; - - bool tryGet(const TKey &name, TValue &value) const - { - QMutexLocker lock(&this->mutex); - - auto a = this->data.find(name); - if (a == this->data.end()) - { - return false; - } - - value = a.value(); - - return true; - } - - TValue getOrAdd(const TKey &name, std::function addLambda) - { - QMutexLocker lock(&this->mutex); - - auto a = this->data.find(name); - if (a == this->data.end()) - { - TValue value = addLambda(); - this->data.insert(name, value); - return value; - } - - return a.value(); - } - - TValue &operator[](const TKey &name) - { - QMutexLocker lock(&this->mutex); - - return this->data[name]; - } - - void clear() - { - QMutexLocker lock(&this->mutex); - - this->data.clear(); - } - - void insert(const TKey &name, const TValue &value) - { - QMutexLocker lock(&this->mutex); - - this->data.insert(name, value); - } - - void each( - std::function func) const - { - QMutexLocker lock(&this->mutex); - - QMapIterator it(this->data); - - while (it.hasNext()) - { - it.next(); - func(it.key(), it.value()); - } - } - - void each(std::function func) - { - QMutexLocker lock(&this->mutex); - - QMutableMapIterator it(this->data); - - while (it.hasNext()) - { - it.next(); - func(it.key(), it.value()); - } - } - -private: - mutable QMutex mutex; - QMap data; -}; - -} // namespace chatterino diff --git a/src/common/Credentials.cpp b/src/common/Credentials.cpp index 5784436f1..5fffe013f 100644 --- a/src/common/Credentials.cpp +++ b/src/common/Credentials.cpp @@ -6,7 +6,6 @@ #include "singletons/Paths.hpp" #include "singletons/Settings.hpp" #include "util/CombinePath.hpp" -#include "util/Overloaded.hpp" #include "util/Variant.hpp" #include diff --git a/src/providers/irc/IrcCommands.cpp b/src/providers/irc/IrcCommands.cpp index 3dff08cb6..cd5f7d5e6 100644 --- a/src/providers/irc/IrcCommands.cpp +++ b/src/providers/irc/IrcCommands.cpp @@ -3,7 +3,6 @@ #include "messages/MessageBuilder.hpp" #include "providers/irc/IrcChannel2.hpp" #include "providers/irc/IrcServer.hpp" -#include "util/Overloaded.hpp" #include "util/QStringHash.hpp" namespace chatterino { diff --git a/src/providers/twitch/PubSubClient.cpp b/src/providers/twitch/PubSubClient.cpp index 80b6d66ed..514fd487d 100644 --- a/src/providers/twitch/PubSubClient.cpp +++ b/src/providers/twitch/PubSubClient.cpp @@ -4,7 +4,6 @@ #include "providers/twitch/PubSubActions.hpp" #include "providers/twitch/PubSubHelpers.hpp" #include "providers/twitch/PubSubMessages.hpp" -#include "providers/twitch/pubsubmessages/Unlisten.hpp" #include "singletons/Settings.hpp" #include "util/DebugCount.hpp" #include "util/Helpers.hpp" diff --git a/src/providers/twitch/PubSubManager.cpp b/src/providers/twitch/PubSubManager.cpp index 447909812..9f16951a7 100644 --- a/src/providers/twitch/PubSubManager.cpp +++ b/src/providers/twitch/PubSubManager.cpp @@ -7,7 +7,6 @@ #include "providers/twitch/PubSubHelpers.hpp" #include "providers/twitch/PubSubMessages.hpp" #include "providers/twitch/TwitchAccount.hpp" -#include "pubsubmessages/LowTrustUsers.hpp" #include "util/DebugCount.hpp" #include "util/Helpers.hpp" #include "util/RapidjsonHelpers.hpp" diff --git a/src/providers/twitch/PubSubMessages.hpp b/src/providers/twitch/PubSubMessages.hpp index f9cc5c501..48c4066b3 100644 --- a/src/providers/twitch/PubSubMessages.hpp +++ b/src/providers/twitch/PubSubMessages.hpp @@ -1,10 +1,11 @@ #pragma once -#include "providers/twitch/pubsubmessages/AutoMod.hpp" -#include "providers/twitch/pubsubmessages/Base.hpp" -#include "providers/twitch/pubsubmessages/ChannelPoints.hpp" -#include "providers/twitch/pubsubmessages/ChatModeratorAction.hpp" -#include "providers/twitch/pubsubmessages/Listen.hpp" -#include "providers/twitch/pubsubmessages/Message.hpp" -#include "providers/twitch/pubsubmessages/Unlisten.hpp" -#include "providers/twitch/pubsubmessages/Whisper.hpp" +#include "providers/twitch/pubsubmessages/AutoMod.hpp" // IWYU pragma: export +#include "providers/twitch/pubsubmessages/Base.hpp" // IWYU pragma: export +#include "providers/twitch/pubsubmessages/ChannelPoints.hpp" // IWYU pragma: export +#include "providers/twitch/pubsubmessages/ChatModeratorAction.hpp" // IWYU pragma: export +#include "providers/twitch/pubsubmessages/Listen.hpp" // IWYU pragma: export +#include "providers/twitch/pubsubmessages/LowTrustUsers.hpp" // IWYU pragma: export +#include "providers/twitch/pubsubmessages/Message.hpp" // IWYU pragma: export +#include "providers/twitch/pubsubmessages/Unlisten.hpp" // IWYU pragma: export +#include "providers/twitch/pubsubmessages/Whisper.hpp" // IWYU pragma: export diff --git a/src/singletons/Settings.cpp b/src/singletons/Settings.cpp index 451692aa0..09e2b410a 100644 --- a/src/singletons/Settings.cpp +++ b/src/singletons/Settings.cpp @@ -10,8 +10,6 @@ #include "controllers/nicknames/Nickname.hpp" #include "debug/Benchmark.hpp" #include "pajlada/settings/signalargs.hpp" -#include "util/Clamp.hpp" -#include "util/PersistSignalVector.hpp" #include "util/WindowsHelper.hpp" #include @@ -267,12 +265,12 @@ void Settings::restoreSnapshot() float Settings::getClampedUiScale() const { - return clamp(this->uiScale.getValue(), 0.2f, 10); + return std::clamp(this->uiScale.getValue(), 0.2F, 10.F); } void Settings::setClampedUiScale(float value) { - this->uiScale.setValue(clamp(value, 0.2f, 10)); + this->uiScale.setValue(std::clamp(value, 0.2F, 10.F)); } Settings &Settings::instance() diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index 1e0f78451..66a0f606e 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -12,7 +12,6 @@ #include "singletons/Paths.hpp" #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" -#include "util/Clamp.hpp" #include "util/CombinePath.hpp" #include "widgets/AccountSwitchPopup.hpp" #include "widgets/dialogs/SettingsDialog.hpp" diff --git a/src/util/Clamp.hpp b/src/util/Clamp.hpp deleted file mode 100644 index 33030f70a..000000000 --- a/src/util/Clamp.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -namespace chatterino { - -// http://en.cppreference.com/w/cpp/algorithm/clamp - -template -constexpr const T &clamp(const T &v, const T &lo, const T &hi) -{ - return assert(!(hi < lo)), (v < lo) ? lo : (hi < v) ? hi : v; -} - -} // namespace chatterino diff --git a/src/util/ConcurrentMap.hpp b/src/util/ConcurrentMap.hpp deleted file mode 100644 index 0346bcae6..000000000 --- a/src/util/ConcurrentMap.hpp +++ /dev/null @@ -1,102 +0,0 @@ -#pragma once - -#include -#include -#include - -#include -#include -#include - -namespace chatterino { - -template -class ConcurrentMap -{ -public: - ConcurrentMap() = default; - - bool tryGet(const TKey &name, TValue &value) const - { - QMutexLocker lock(&this->mutex_); - - auto a = this->data_.find(name); - if (a == this->data_.end()) - { - return false; - } - - value = a.value(); - - return true; - } - - TValue getOrAdd(const TKey &name, std::function addLambda) - { - QMutexLocker lock(&this->mutex_); - - auto a = this->data_.find(name); - if (a == this->data_.end()) - { - TValue value = addLambda(); - this->data_.insert(name, value); - return value; - } - - return a.value(); - } - - TValue &operator[](const TKey &name) - { - QMutexLocker lock(&this->mutex_); - - return this->data_[name]; - } - - void clear() - { - QMutexLocker lock(&this->mutex_); - - this->data_.clear(); - } - - void insert(const TKey &name, const TValue &value) - { - QMutexLocker lock(&this->mutex_); - - this->data_.insert(name, value); - } - - void each( - std::function func) const - { - QMutexLocker lock(&this->mutex_); - - QMapIterator it(this->data_); - - while (it.hasNext()) - { - it.next(); - func(it.key(), it.value()); - } - } - - void each(std::function func) - { - QMutexLocker lock(&this->mutex_); - - QMutableMapIterator it(this->data_); - - while (it.hasNext()) - { - it.next(); - func(it.key(), it.value()); - } - } - -private: - mutable QMutex mutex_; - QMap data_; -}; - -} // namespace chatterino diff --git a/src/util/DisplayBadge.hpp b/src/util/DisplayBadge.hpp index e07e63bbb..69c23bdb7 100644 --- a/src/util/DisplayBadge.hpp +++ b/src/util/DisplayBadge.hpp @@ -3,6 +3,7 @@ #include namespace chatterino { + class DisplayBadge { public: diff --git a/src/util/DistanceBetweenPoints.hpp b/src/util/DistanceBetweenPoints.hpp index 7a2a834cc..332aee87e 100644 --- a/src/util/DistanceBetweenPoints.hpp +++ b/src/util/DistanceBetweenPoints.hpp @@ -6,15 +6,13 @@ namespace chatterino { -inline float distanceBetweenPoints(const QPointF &p1, const QPointF &p2) +inline qreal distanceBetweenPoints(const QPointF &p1, const QPointF &p2) { QPointF tmp = p1 - p2; - float distance = 0.f; - distance += tmp.x() * tmp.x(); - distance += tmp.y() * tmp.y(); + qreal distance = tmp.x() * tmp.x() + tmp.y() * tmp.y(); - return sqrt(distance); + return std::sqrt(distance); } } // namespace chatterino diff --git a/src/util/ExponentialBackoff.hpp b/src/util/ExponentialBackoff.hpp index 44eca67e1..bc7e1ec91 100644 --- a/src/util/ExponentialBackoff.hpp +++ b/src/util/ExponentialBackoff.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include namespace chatterino { @@ -20,7 +19,6 @@ public: **/ ExponentialBackoff(const std::chrono::milliseconds &start) : start_(start) - , step_{1} { static_assert(maxSteps > 1, "maxSteps must be higher than 1"); } @@ -54,7 +52,7 @@ public: private: const std::chrono::milliseconds start_; - unsigned step_; + unsigned step_ = 1; }; } // namespace chatterino diff --git a/src/util/Helpers.cpp b/src/util/Helpers.cpp index 7d66184d1..836214d05 100644 --- a/src/util/Helpers.cpp +++ b/src/util/Helpers.cpp @@ -9,7 +9,7 @@ namespace chatterino { -namespace _helpers_internal { +namespace helpers::detail { SizeType skipSpace(QStringView view, SizeType startPos) { @@ -110,8 +110,8 @@ namespace _helpers_internal { return std::make_pair(0, false); } -} // namespace _helpers_internal -using namespace _helpers_internal; +} // namespace helpers::detail +using namespace helpers::detail; bool startsWithOrContains(const QString &str1, const QString &str2, Qt::CaseSensitivity caseSensitivity, bool startsWith) diff --git a/src/util/Helpers.hpp b/src/util/Helpers.hpp index 6f0552487..02bf572e9 100644 --- a/src/util/Helpers.hpp +++ b/src/util/Helpers.hpp @@ -11,7 +11,7 @@ namespace chatterino { // only qualified for tests -namespace _helpers_internal { +namespace helpers::detail { using SizeType = QStringView::size_type; @@ -52,7 +52,7 @@ namespace _helpers_internal { std::pair findUnitMultiplierToSec(QStringView view, SizeType &pos); -} // namespace _helpers_internal +} // namespace helpers::detail /** * @brief startsWithOrContains is a wrapper for checking diff --git a/src/util/LayoutCreator.hpp b/src/util/LayoutCreator.hpp index 82f729d26..41f605d47 100644 --- a/src/util/LayoutCreator.hpp +++ b/src/util/LayoutCreator.hpp @@ -6,11 +6,12 @@ #include #include -#include +#include namespace chatterino { template + requires std::derived_from || std::derived_from class LayoutCreator { public: @@ -34,49 +35,41 @@ public: return this->item_; } - template - LayoutCreator append(T2 *_item) + template + LayoutCreator append(U *item) { - this->addItem(this->getOrCreateLayout(), _item); + addItem(this->getOrCreateLayout(), item); - return LayoutCreator(_item); + return LayoutCreator(item); } - template - // clang-format off - // clang-format can be enabled once clang-format v11+ has been installed in CI - LayoutCreator emplace(Args &&...args) - // clang-format on + template + LayoutCreator emplace(auto &&...args) { - T2 *t = new T2(std::forward(args)...); + auto *t = new U(std::forward(args)...); - this->addItem(this->getOrCreateLayout(), t); + addItem(this->getOrCreateLayout(), t); - return LayoutCreator(t); + return LayoutCreator(t); } - template ::value, - int>::type = 0> LayoutCreator emplaceScrollAreaWidget() + requires std::derived_from { - QWidget *widget = new QWidget; + auto *widget = new QWidget; this->item_->setWidget(widget); - return LayoutCreator(widget); + return {widget}; } - template ::value, - int>::type = 0, - typename std::enable_if::value, - int>::type = 0> - LayoutCreator setLayoutType() + template U> + LayoutCreator setLayoutType() + requires std::derived_from { - T2 *layout = new T2; + U *layout = new U; this->item_->setLayout(layout); - return LayoutCreator(layout); + return LayoutCreator(layout); } LayoutCreator assign(T **ptr) @@ -86,9 +79,6 @@ public: return *this; } - template ::value, - int>::type = 0> LayoutCreator withoutMargin() { this->item_->setContentsMargins(0, 0, 0, 0); @@ -97,36 +87,31 @@ public: } LayoutCreator withoutSpacing() + requires std::derived_from { this->item_->setSpacing(0); return *this; } - template ::value, - int>::type = 0> LayoutCreator hidden() + requires std::derived_from { this->item_->setVisible(false); return *this; } - template ::value, - int>::type = 0> - LayoutCreator appendTab(T2 *item, const QString &title) + template U> + LayoutCreator appendTab(U *item, const QString &title) + requires std::derived_from { - static_assert(std::is_base_of::value, - "needs to be QLayout"); - - QWidget *widget = new QWidget; + auto *widget = new QWidget; widget->setLayout(item); this->item_->addTab(widget, title); - return LayoutCreator(item); + return LayoutCreator(item); } template @@ -146,36 +131,26 @@ public: private: T *item_; - template ::value, - int>::type = 0> - void addItem(QLayout *layout, T2 *item) + static void addItem(QLayout *layout, QWidget *item) { layout->addWidget(item); } - template ::value, - int>::type = 0> - void addItem(QLayout *layout, T2 *item) + static void addItem(QLayout *layout, QLayout *item) { - QWidget *widget = new QWidget(); + auto *widget = new QWidget(); widget->setLayout(item); layout->addWidget(widget); } - template ::value, - int>::type = 0> QLayout *getOrCreateLayout() + requires std::derived_from { return this->item_; } - template ::value, - int>::type = 0> QLayout *getOrCreateLayout() + requires std::derived_from { if (!this->item_->layout()) { @@ -186,13 +161,10 @@ private: } }; -template -// clang-format off -// clang-format can be enabled once clang-format v11+ has been installed in CI -LayoutCreator makeDialog(Args &&...args) -// clang-format on +template +LayoutCreator makeDialog(auto &&...args) { - T *t = new T(std::forward(args)...); + T *t = new T(std::forward(args)...); t->setAttribute(Qt::WA_DeleteOnClose); return LayoutCreator(t); } diff --git a/src/util/Overloaded.hpp b/src/util/Overloaded.hpp deleted file mode 100644 index e5bc805f5..000000000 --- a/src/util/Overloaded.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -namespace chatterino { - -template -struct Overloaded : Ts... { - using Ts::operator()...; -}; - -template -Overloaded(Ts...) -> Overloaded; - -} // namespace chatterino diff --git a/src/util/PersistSignalVector.hpp b/src/util/PersistSignalVector.hpp deleted file mode 100644 index 9d6d8fd92..000000000 --- a/src/util/PersistSignalVector.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "common/ChatterinoSetting.hpp" -#include "common/SignalVector.hpp" - -#include - -namespace chatterino { - -template -inline void persist(SignalVector &vec, const std::string &name) -{ - auto setting = std::make_unique>>(name); - - for (auto &&item : setting->getValue()) - { - vec.append(item); - } - - vec.delayedItemsChanged.connect([setting = setting.get(), vec = &vec] { - setting->setValue(vec->raw()); - }); - - // TODO: Delete when appropriate. - setting.release(); -} - -} // namespace chatterino diff --git a/src/util/PostToThread.hpp b/src/util/PostToThread.hpp index e0db1fdd0..fa4792941 100644 --- a/src/util/PostToThread.hpp +++ b/src/util/PostToThread.hpp @@ -3,33 +3,9 @@ #include "debug/AssertInGuiThread.hpp" #include -#include -#include - -#include - -#define async_exec(a) \ - QThreadPool::globalInstance()->start(new LambdaRunnable(a)); namespace chatterino { -class LambdaRunnable : public QRunnable -{ -public: - LambdaRunnable(std::function action) - : action_(std::move(action)) - { - } - - void run() override - { - this->action_(); - } - -private: - std::function action_; -}; - // Taken from // https://stackoverflow.com/questions/21646467/how-to-execute-a-functor-or-a-lambda-in-a-given-thread-in-qt-gcd-style // Qt 5/4 - preferred, has least allocations diff --git a/src/util/SplitCommand.cpp b/src/util/SplitCommand.cpp deleted file mode 100644 index 3d71e040f..000000000 --- a/src/util/SplitCommand.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "SplitCommand.hpp" - -#include -#include -#include - -QStringList chatterino::splitCommand(QStringView command) -{ - QStringList args; - QString tmp; - int quoteCount = 0; - bool inQuote = false; - - // handle quoting. tokens can be surrounded by double quotes - // "hello world". three consecutive double quotes represent - // the quote character itself. - for (int i = 0; i < command.size(); ++i) - { - if (command.at(i) == QLatin1Char('"')) - { - ++quoteCount; - if (quoteCount == 3) - { - // third consecutive quote - quoteCount = 0; - tmp += command.at(i); - } - continue; - } - if (quoteCount) - { - if (quoteCount == 1) - { - inQuote = !inQuote; - } - quoteCount = 0; - } - if (!inQuote && command.at(i).isSpace()) - { - if (!tmp.isEmpty()) - { - args += tmp; - tmp.clear(); - } - } - else - { - tmp += command.at(i); - } - } - if (!tmp.isEmpty()) - { - args += tmp; - } - - return args; -} diff --git a/src/util/SplitCommand.hpp b/src/util/SplitCommand.hpp deleted file mode 100644 index 9db79c727..000000000 --- a/src/util/SplitCommand.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include -#include - -namespace chatterino { - -// Splits the string command into a list of tokens, and returns the list. -// Tokens with spaces can be surrounded by double quotes; -// three consecutive double quotes represent the quote character itself. -// -// Backported from QProcess 5.15 -QStringList splitCommand(QStringView command); - -} // namespace chatterino diff --git a/src/util/StreamLink.cpp b/src/util/StreamLink.cpp index a3596f9b4..b4e4370d2 100644 --- a/src/util/StreamLink.cpp +++ b/src/util/StreamLink.cpp @@ -7,7 +7,6 @@ #include "singletons/Settings.hpp" #include "singletons/WindowManager.hpp" #include "util/Helpers.hpp" -#include "util/SplitCommand.hpp" #include "widgets/dialogs/QualityPopup.hpp" #include "widgets/splits/Split.hpp" #include "widgets/Window.hpp" @@ -162,16 +161,16 @@ void openStreamlink(const QString &channelURL, const QString &quality, { auto *proc = createStreamlinkProcess(); auto arguments = proc->arguments() - << extraArguments << channelURL << quality; + << std::move(extraArguments) << channelURL << quality; // Remove empty arguments before appending additional streamlink options // as the options might purposely contain empty arguments arguments.removeAll(QString()); QString additionalOptions = getSettings()->streamlinkOpts.getValue(); - arguments << splitCommand(additionalOptions); + arguments << QProcess::splitCommand(additionalOptions); - proc->setArguments(std::move(arguments)); + proc->setArguments(arguments); bool res = proc->startDetached(); if (!res) diff --git a/src/widgets/settingspages/ModerationPage.cpp b/src/widgets/settingspages/ModerationPage.cpp index 95669cce9..c00c03667 100644 --- a/src/widgets/settingspages/ModerationPage.cpp +++ b/src/widgets/settingspages/ModerationPage.cpp @@ -274,17 +274,16 @@ ModerationPage::ModerationPage() }); } - this->addModerationButtonSettings(tabs); + this->addModerationButtonSettings(tabs.getElement()); // ---- misc this->itemsChangedTimer_.setSingleShot(true); } -void ModerationPage::addModerationButtonSettings( - LayoutCreator &tabs) +void ModerationPage::addModerationButtonSettings(QTabWidget *tabs) { auto timeoutLayout = - tabs.appendTab(new QVBoxLayout, "User Timeout Buttons"); + LayoutCreator{tabs}.appendTab(new QVBoxLayout, "User Timeout Buttons"); auto texts = timeoutLayout.emplace().withoutMargin(); { auto infoLabel = texts.emplace(); diff --git a/src/widgets/settingspages/ModerationPage.hpp b/src/widgets/settingspages/ModerationPage.hpp index 24662ec0d..88a251d8e 100644 --- a/src/widgets/settingspages/ModerationPage.hpp +++ b/src/widgets/settingspages/ModerationPage.hpp @@ -9,9 +9,6 @@ class QPushButton; namespace chatterino { -template -class LayoutCreator; - class ModerationPage : public SettingsPage { public: @@ -20,7 +17,7 @@ public: void selectModerationActions(); private: - void addModerationButtonSettings(LayoutCreator &); + void addModerationButtonSettings(QTabWidget *); QTimer itemsChangedTimer_; QTabWidget *tabWidget_{}; diff --git a/src/widgets/splits/SplitInput.cpp b/src/widgets/splits/SplitInput.cpp index 66940b280..29ed3929f 100644 --- a/src/widgets/splits/SplitInput.cpp +++ b/src/widgets/splits/SplitInput.cpp @@ -12,7 +12,6 @@ #include "providers/twitch/TwitchIrcServer.hpp" #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" -#include "util/Clamp.hpp" #include "util/Helpers.hpp" #include "util/LayoutCreator.hpp" #include "widgets/dialogs/EmotePopup.hpp" @@ -811,7 +810,7 @@ void SplitInput::updateCompletionPopup() return; } - for (int i = clamp(position, 0, (int)text.length() - 1); i >= 0; i--) + for (int i = std::clamp(position, 0, (int)text.length() - 1); i >= 0; i--) { if (text[i] == ' ') { @@ -894,7 +893,7 @@ void SplitInput::insertCompletionText(const QString &input_) const auto text = edit.toPlainText(); auto position = edit.textCursor().position() - 1; - for (int i = clamp(position, 0, (int)text.length() - 1); i >= 0; i--) + for (int i = std::clamp(position, 0, (int)text.length() - 1); i >= 0; i--) { bool done = false; if (text[i] == ':') diff --git a/tests/src/Helpers.cpp b/tests/src/Helpers.cpp index a98868bfa..4327bf51a 100644 --- a/tests/src/Helpers.cpp +++ b/tests/src/Helpers.cpp @@ -3,7 +3,7 @@ #include "Test.hpp" using namespace chatterino; -using namespace _helpers_internal; +using namespace helpers::detail; TEST(Helpers, formatUserMention) {