mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Remove direct dependency on Qt 5 compatibility module (#4906)
This commit is contained in:
parent
12808d3154
commit
fcb6eff8cc
7 changed files with 45 additions and 40 deletions
|
@ -42,6 +42,7 @@
|
||||||
- Dev: Update vcpkg to use Qt6. (#4872)
|
- Dev: Update vcpkg to use Qt6. (#4872)
|
||||||
- Dev: Replace `boost::optional` with `std::optional`. (#4877)
|
- Dev: Replace `boost::optional` with `std::optional`. (#4877)
|
||||||
- Dev: Improve performance by reducing repaints caused by selections. (#4889)
|
- Dev: Improve performance by reducing repaints caused by selections. (#4889)
|
||||||
|
- Dev: Removed direct dependency on Qt 5 compatibility module. (#4906)
|
||||||
|
|
||||||
## 2.4.6
|
## 2.4.6
|
||||||
|
|
||||||
|
|
|
@ -110,13 +110,6 @@ find_package(Qt${MAJOR_QT_VERSION} REQUIRED
|
||||||
Concurrent
|
Concurrent
|
||||||
)
|
)
|
||||||
|
|
||||||
if (BUILD_WITH_QT6)
|
|
||||||
find_package(Qt${MAJOR_QT_VERSION} REQUIRED
|
|
||||||
COMPONENTS
|
|
||||||
Core5Compat
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
message(STATUS "Qt version: ${Qt${MAJOR_QT_VERSION}_VERSION}")
|
message(STATUS "Qt version: ${Qt${MAJOR_QT_VERSION}_VERSION}")
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
|
|
@ -712,13 +712,6 @@ if (CHATTERINO_PLUGINS)
|
||||||
target_link_libraries(${LIBRARY_PROJECT} PUBLIC lua)
|
target_link_libraries(${LIBRARY_PROJECT} PUBLIC lua)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (BUILD_WITH_QT6)
|
|
||||||
target_link_libraries(${LIBRARY_PROJECT}
|
|
||||||
PUBLIC
|
|
||||||
Qt${MAJOR_QT_VERSION}::Core5Compat
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (BUILD_WITH_QTKEYCHAIN)
|
if (BUILD_WITH_QTKEYCHAIN)
|
||||||
target_link_libraries(${LIBRARY_PROJECT}
|
target_link_libraries(${LIBRARY_PROJECT}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
#include <boost/variant.hpp>
|
#include <boost/variant.hpp>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QStringRef>
|
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace chatterino {
|
||||||
|
|
||||||
namespace _helpers_internal {
|
namespace _helpers_internal {
|
||||||
|
|
||||||
int skipSpace(const QStringRef &view, int startPos)
|
SizeType skipSpace(StringView view, SizeType startPos)
|
||||||
{
|
{
|
||||||
while (startPos < view.length() && view.at(startPos).isSpace())
|
while (startPos < view.length() && view.at(startPos).isSpace())
|
||||||
{
|
{
|
||||||
|
@ -20,26 +20,26 @@ namespace _helpers_internal {
|
||||||
return startPos - 1;
|
return startPos - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool matchesIgnorePlural(const QStringRef &word, const QString &singular)
|
bool matchesIgnorePlural(StringView word, const QString &expected)
|
||||||
{
|
{
|
||||||
if (!word.startsWith(singular))
|
if (!word.startsWith(expected))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (word.length() == singular.length())
|
if (word.length() == expected.length())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return word.length() == singular.length() + 1 &&
|
return word.length() == expected.length() + 1 &&
|
||||||
word.at(word.length() - 1).toLatin1() == 's';
|
word.at(word.length() - 1).toLatin1() == 's';
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<uint64_t, bool> findUnitMultiplierToSec(const QStringRef &view,
|
std::pair<uint64_t, bool> findUnitMultiplierToSec(StringView view,
|
||||||
int &pos)
|
SizeType &pos)
|
||||||
{
|
{
|
||||||
// Step 1. find end of unit
|
// Step 1. find end of unit
|
||||||
int startIdx = pos;
|
auto startIdx = pos;
|
||||||
int endIdx = view.length();
|
auto endIdx = view.length();
|
||||||
for (; pos < view.length(); pos++)
|
for (; pos < view.length(); pos++)
|
||||||
{
|
{
|
||||||
auto c = view.at(pos);
|
auto c = view.at(pos);
|
||||||
|
@ -207,16 +207,19 @@ int64_t parseDurationToSeconds(const QString &inputString,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(QT6): use QStringView
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
|
||||||
QStringRef input(&inputString);
|
StringView input(inputString);
|
||||||
|
#else
|
||||||
|
StringView input(&inputString);
|
||||||
|
#endif
|
||||||
input = input.trimmed();
|
input = input.trimmed();
|
||||||
|
|
||||||
uint64_t currentValue = 0;
|
uint64_t currentValue = 0;
|
||||||
|
|
||||||
bool visitingNumber = true; // input must start with a number
|
bool visitingNumber = true; // input must start with a number
|
||||||
int numberStartIdx = 0;
|
SizeType numberStartIdx = 0;
|
||||||
|
|
||||||
for (int pos = 0; pos < input.length(); pos++)
|
for (SizeType pos = 0; pos < input.length(); pos++)
|
||||||
{
|
{
|
||||||
QChar c = input.at(pos);
|
QChar c = input.at(pos);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
|
||||||
# include <QStringRef>
|
# include <QStringRef>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
@ -14,6 +17,13 @@ namespace chatterino {
|
||||||
// only qualified for tests
|
// only qualified for tests
|
||||||
namespace _helpers_internal {
|
namespace _helpers_internal {
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
|
||||||
|
using StringView = QStringView;
|
||||||
|
#else
|
||||||
|
using StringView = QStringRef;
|
||||||
|
#endif
|
||||||
|
using SizeType = StringView::size_type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skips all spaces.
|
* Skips all spaces.
|
||||||
* The caller must guarantee view.at(startPos).isSpace().
|
* The caller must guarantee view.at(startPos).isSpace().
|
||||||
|
@ -22,7 +32,7 @@ namespace _helpers_internal {
|
||||||
* @param startPos The starting position (there must be a space in the view).
|
* @param startPos The starting position (there must be a space in the view).
|
||||||
* @return The position of the last space.
|
* @return The position of the last space.
|
||||||
*/
|
*/
|
||||||
int skipSpace(const QStringRef &view, int startPos);
|
SizeType skipSpace(StringView view, SizeType startPos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `word` equals `expected` (singular) or `expected` + 's' (plural).
|
* Checks if `word` equals `expected` (singular) or `expected` + 's' (plural).
|
||||||
|
@ -31,7 +41,7 @@ namespace _helpers_internal {
|
||||||
* @param expected Singular of the expected word.
|
* @param expected Singular of the expected word.
|
||||||
* @return true if `word` is singular or plural of `expected`.
|
* @return true if `word` is singular or plural of `expected`.
|
||||||
*/
|
*/
|
||||||
bool matchesIgnorePlural(const QStringRef &word, const QString &expected);
|
bool matchesIgnorePlural(StringView word, const QString &expected);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to find the unit starting at `pos` and returns its multiplier so
|
* Tries to find the unit starting at `pos` and returns its multiplier so
|
||||||
|
@ -48,8 +58,8 @@ namespace _helpers_internal {
|
||||||
* if it's a valid unit, undefined otherwise.
|
* if it's a valid unit, undefined otherwise.
|
||||||
* @return (multiplier, ok)
|
* @return (multiplier, ok)
|
||||||
*/
|
*/
|
||||||
std::pair<uint64_t, bool> findUnitMultiplierToSec(const QStringRef &view,
|
std::pair<uint64_t, bool> findUnitMultiplierToSec(StringView view,
|
||||||
int &pos);
|
SizeType &pos);
|
||||||
|
|
||||||
} // namespace _helpers_internal
|
} // namespace _helpers_internal
|
||||||
|
|
||||||
|
|
|
@ -252,12 +252,18 @@ TEST(Helpers, BatchDifferentInputType)
|
||||||
EXPECT_EQ(result, expectation);
|
EXPECT_EQ(result, expectation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
|
||||||
|
# define makeView(x) x
|
||||||
|
#else
|
||||||
|
# define makeView(str) (&(str))
|
||||||
|
#endif
|
||||||
|
|
||||||
TEST(Helpers, skipSpace)
|
TEST(Helpers, skipSpace)
|
||||||
{
|
{
|
||||||
struct TestCase {
|
struct TestCase {
|
||||||
QString input;
|
QString input;
|
||||||
int startIdx;
|
SizeType startIdx;
|
||||||
int expected;
|
SizeType expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<TestCase> tests{{"foo bar", 3, 6}, {"foo bar", 3, 3},
|
std::vector<TestCase> tests{{"foo bar", 3, 6}, {"foo bar", 3, 3},
|
||||||
|
@ -266,7 +272,7 @@ TEST(Helpers, skipSpace)
|
||||||
|
|
||||||
for (const auto &c : tests)
|
for (const auto &c : tests)
|
||||||
{
|
{
|
||||||
const auto actual = skipSpace(&c.input, c.startIdx);
|
const auto actual = skipSpace(makeView(c.input), c.startIdx);
|
||||||
|
|
||||||
EXPECT_EQ(actual, c.expected)
|
EXPECT_EQ(actual, c.expected)
|
||||||
<< actual << " (" << qUtf8Printable(c.input)
|
<< actual << " (" << qUtf8Printable(c.input)
|
||||||
|
@ -286,8 +292,8 @@ TEST(Helpers, findUnitMultiplierToSec)
|
||||||
|
|
||||||
struct TestCase {
|
struct TestCase {
|
||||||
QString input;
|
QString input;
|
||||||
int startPos;
|
SizeType startPos;
|
||||||
int expectedEndPos;
|
SizeType expectedEndPos;
|
||||||
uint64_t expectedMultiplier;
|
uint64_t expectedMultiplier;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -407,8 +413,8 @@ TEST(Helpers, findUnitMultiplierToSec)
|
||||||
|
|
||||||
for (const auto &c : tests)
|
for (const auto &c : tests)
|
||||||
{
|
{
|
||||||
int pos = c.startPos;
|
SizeType pos = c.startPos;
|
||||||
const auto actual = findUnitMultiplierToSec(&c.input, pos);
|
const auto actual = findUnitMultiplierToSec(makeView(c.input), pos);
|
||||||
|
|
||||||
if (c.expectedMultiplier == bad)
|
if (c.expectedMultiplier == bad)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue