Skip to content

Commit

Permalink
support Qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
nschimme committed Jul 28, 2023
1 parent 4f46959 commit 92071cb
Show file tree
Hide file tree
Showing 21 changed files with 131 additions and 63 deletions.
Binary file removed .github/workflows/.build-test.yml.swp
Binary file not shown.
37 changes: 30 additions & 7 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ jobs:
include:
- os: ubuntu-22.04
compiler: 'gcc'
qt: qt5
- os: ubuntu-22.04
compiler: 'clang'
qt: qt5
- os: macos-11.0
compiler: 'clang'
qt: qt5
- os: windows-2022
compiler: msvc
qt: qt5
- os: macos-11.0
compiler: 'clang'
qt: qt6
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -41,7 +46,15 @@ jobs:
name: Install Packages for Ubuntu
run: |
sudo apt update -qq
sudo apt install -y build-essential git qt5-qmake libqt5opengl5-dev zlib1g-dev libssl-dev libminiupnpc-dev
sudo apt install -y build-essential git zlib1g-dev libssl-dev libminiupnpc-dev
- if: contains( matrix.os, 'ubuntu' ) && matrix.qt == 'qt5'
name: Install Qt5 for Ubuntu
run: |
sudo apt install -y qt5-qmake libqt5opengl5-dev
- if: contains( matrix.os, 'ubuntu' ) && matrix.qt == 'qt6'
name: Install Qt6 for Ubuntu
run: |
sudo apt install -y qmake6 libqt6opengl6-dev libqt6core5compat6-dev
- if: contains( matrix.os, 'ubuntu' ) && matrix.compiler == 'gcc'
name: Install GCC for Ubuntu
run: |
Expand All @@ -67,11 +80,21 @@ jobs:
- if: runner.os == 'macOS'
name: Install Packages for Mac
run: |
brew install qt5 openssl\@1.1 lcov miniupnpc
brew install lcov miniupnpc
- if: runner.os == 'macOS' && matrix.qt == 'qt5'
name: Install Qt5 for Mac
run: |
brew install qt5 openssl\@1.1
brew link qt5 --force
echo "$(brew --prefix qt5)/bin" >> $GITHUB_PATH
echo "MMAPPER_CMAKE_EXTRA=-DUSE_CODE_COVERAGE=true -DOPENSSL_ROOT_DIR=/usr/local/opt/[email protected]" >> $GITHUB_ENV
echo "COVERAGE=true" >> $GITHUB_ENV
echo "MMAPPER_CMAKE_EXTRA=-DOPENSSL_ROOT_DIR=/usr/local/opt/[email protected]" >> $GITHUB_ENV
- if: runner.os == 'macOS' && matrix.qt == 'qt6'
name: Install Qt6 for Mac
run: |
brew install qt6 openssl\@3
brew link qt6 --force
echo "$(brew --prefix qt6)/bin" >> $GITHUB_PATH
echo "MMAPPER_CMAKE_EXTRA=-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@3" >> $GITHUB_ENV
#
Expand Down Expand Up @@ -171,17 +194,17 @@ jobs:
name: Upload Package for Mac
uses: actions/upload-artifact@v3
with:
name: build-test Mac ${{ matrix.os }} ${{ matrix.compiler }}
name: build-test Mac ${{ matrix.os }} ${{ matrix.compiler }} ${{ matrix.qt }}
path: ${{ github.workspace }}/artifact/*.dmg
- if: contains( matrix.os, 'ubuntu' )
name: Upload Package for Ubuntu
uses: actions/upload-artifact@v3
with:
name: build-test Linux ${{ matrix.os }} ${{ matrix.compiler }}
name: build-test Linux ${{ matrix.os }} ${{ matrix.compiler }} ${{ matrix.qt }}
path: ${{ github.workspace }}/artifact/*.deb
- if: runner.os == 'Windows'
name: Upload Package for Windows
uses: actions/upload-artifact@v3
with:
name: build-test Windows ${{ matrix.os }} ${{ matrix.compiler }}
name: build-test Windows ${{ matrix.os }} ${{ matrix.compiler }} ${{ matrix.qt }}
path: ${{ github.workspace }}/artifact/*.exe
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,23 @@ if(WIN32 AND MINGW)
option(WITH_DRMINGW "Include Dr. Mingw crash dumping (Windows only)" ON)
endif()

find_package(QT NAMES Qt5 COMPONENTS Core REQUIRED)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS REQUIRED Core Widgets Network OpenGL Test)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

if(Qt5Core_FOUND)
if(Qt5Core_VERSION VERSION_LESS 5.15.0)
message(FATAL_ERROR "Minimum supported Qt version is 5.15")
if(Qt5Core_FOUND OR Qt6Core_FOUND)
if(QT_VERSION_MAJOR MATCHES 5)
message(STATUS "Qt5 found")
if (Qt5Core_VERSION VERSION_LESS 5.15.0)
message(FATAL_ERROR "Minimum supported Qt version is 5.15")
endif()
elseif(QT_VERSION_MAJOR MATCHES 6)
message(STATUS "Qt6 found")
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS REQUIRED OpenGLWidgets Core5Compat)
endif()
endif()

Expand Down
24 changes: 21 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,13 @@ target_link_libraries(mmapper PUBLIC
Qt${QT_VERSION_MAJOR}::OpenGL
)

if (QT_VERSION_MAJOR MATCHES 6)
target_link_libraries(mmapper PUBLIC
Qt::OpenGLWidgets
Qt::Core5Compat
)
endif()

set_target_properties(
mmapper PROPERTIES
CXX_STANDARD 17
Expand Down Expand Up @@ -676,12 +683,20 @@ if(UNIX AND NOT APPLE)
# Debian
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "[email protected]")
set(CPACK_DEBIAN_PACKAGE_NAME "mmapper")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt5core5a (>= 5.15.0), libqt5gui5 (>= 5.15.0), libqt5opengl5 (>= 5.15.0), libqt5network5 (>= 5.15.0)")
if (QT_VERSION_MAJOR MATCHES 5)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt5core5a (>= 5.15.0), libqt5gui5 (>= 5.15.0), libqt5opengl5 (>= 5.15.0), libqt5network5 (>= 5.15.0)")
else()
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt6core6, libqt6gui6, libqt6opengl6, libqt6network6, libqt6core5compat6")
endif()
if(WITH_ZLIB)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, zlib1g")
endif()
if(WITH_OPENSSL)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libssl1.1")
if (QT_VERSION_MAJOR MATCHES 5)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libssl1.1")
else()
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libssl3")
endif()
endif()
if(WITH_MINIUPNPC)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libminiupnpc${MINIUPNPC_API_VERSION}")
Expand All @@ -701,7 +716,10 @@ if(WIN32)
)

# Bundle Library Files
set(WINDEPLOYQT_ARGS ${WINDEPLOYQT_ARGS} --dir ${CMAKE_CURRENT_BINARY_DIR}/bin --compiler-runtime --no-angle)
set(WINDEPLOYQT_ARGS ${WINDEPLOYQT_ARGS} --dir ${CMAKE_CURRENT_BINARY_DIR}/bin --compiler-runtime)
if (QT_VERSION_MAJOR MATCHES 5)
set(WINDEPLOYQT_ARGS ${WINDEPLOYQT_ARGS} --no-angle)
endif()
find_program(WINDEPLOYQT_APP windeployqt HINTS ${QTDIR} ENV QTDIR PATH_SUFFIXES bin)
message(" - windeployqt path: ${WINDEPLOYQT_APP}")
message(" - windeployqt args: ${WINDEPLOYQT_ARGS}")
Expand Down
4 changes: 4 additions & 0 deletions src/adventure/xpstatuswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ void XPStatusWidget::slot_updatedSession(const std::shared_ptr<AdventureSession>
updateContent();
}

#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
void XPStatusWidget::enterEvent(QEvent *event)
#else
void XPStatusWidget::enterEvent(QEnterEvent *event)
#endif
{
if (m_session) {
auto xpHourly = m_session->calculateHourlyRateXP();
Expand Down
4 changes: 4 additions & 0 deletions src/adventure/xpstatuswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public slots:
void slot_updatedSession(const std::shared_ptr<AdventureSession> &session);

protected:
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
void enterEvent(QEvent *event) override;
#else
void enterEvent(QEnterEvent *event) override;
#endif
void leaveEvent(QEvent *event) override;

private:
Expand Down
6 changes: 3 additions & 3 deletions src/client/displaywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ void DisplayWidget::slot_displayText(const QString &str)
QRegularExpressionMatchIterator it = ansiRx.globalMatch(str);
while (it.hasNext()) {
QRegularExpressionMatch match = it.next();
ansiIndex = match.capturedStart(0);
ansiIndex = static_cast<int>(match.capturedStart(0));
textList << str.mid(textIndex, ansiIndex - textIndex);
ansiList << match.captured(1);
textIndex = match.capturedEnd(0);
textIndex = static_cast<int>(match.capturedEnd(0));
}
if (textIndex < str.length()) {
textList << str.mid(textIndex);
Expand All @@ -149,7 +149,7 @@ void DisplayWidget::slot_displayText(const QString &str)
m_cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor, 1);
m_backspace = false;
}
int backspaceIndex = textStr.indexOf('\10');
auto backspaceIndex = textStr.indexOf('\10');
if (backspaceIndex == -1) {
// No backspace
m_cursor.insertText(textStr, m_format);
Expand Down
4 changes: 3 additions & 1 deletion src/client/inputwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ void InputWidget::tabComplete()
// Found a previous word to complete to
current.insertText(word);
if (current.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor)) {
current.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, m_tabFragment.size());
current.movePosition(QTextCursor::Right,
QTextCursor::KeepAnchor,
static_cast<int>(m_tabFragment.size()));
setTextCursor(current);
}
m_tabHistory.forward();
Expand Down
30 changes: 15 additions & 15 deletions src/global/TextUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ void AnsiColorParser::for_each(QStringView ansi) const
// ESC[...m -> ...
ansi = ansi.mid(2, ansi.length() - 3);

const int len = ansi.length();
int pos = 0;
const auto len = ansi.length();
qsizetype pos = 0;

const auto try_report = [this, &ansi, &pos](const auto idx) -> void {
if (idx <= pos)
Expand Down Expand Up @@ -181,7 +181,7 @@ int findTrailingWhitespace(const QStringView line)
auto m = trailingWhitespaceRegex.match(line);
if (!m.hasMatch())
return -1;
return m.capturedStart();
return static_cast<int>(m.capturedStart());
}

int findTrailingWhitespace(const QString &line)
Expand Down Expand Up @@ -618,7 +618,7 @@ struct NODISCARD Prefix final
{
auto m = quotePrefixRegex.match(line);
if (m.hasMatch()) {
const int len = m.capturedLength(0);
const auto len = m.capturedLength(0);
quotePrefix = line.left(len);
prefixLen = measureExpandedTabsOneLine(quotePrefix, 0);

Expand All @@ -639,7 +639,7 @@ struct NODISCARD Prefix final
if (m.hasMatch()) {
const QStringView sv = m.capturedView();
/* this could fail if someone breaks the regex pattern for the escaped asterisk */
bulletLength = sv.length();
bulletLength = static_cast<int>(sv.length());
prefixLen = measureExpandedTabsOneLine(sv, prefixLen);
hasPrefix2 = true;
append(sv);
Expand Down Expand Up @@ -771,7 +771,7 @@ TextBuffer normalizeAnsi(const QStringView old)
}

TextBuffer output;
output.reserve(2 * old.length()); /* no idea */
output.reserve(2 * static_cast<int>(old.length())); /* no idea */

const auto reset = AnsiString::get_reset_string();

Expand All @@ -797,15 +797,15 @@ TextBuffer normalizeAnsi(const QStringView old)
output.append(sv);
};

int pos = 0;
auto pos = 0;
foreachAnsi(line, [&next, &line, &pos, &print](const auto begin, const QStringView ansiStr) {
assert(line.at(begin) == '\x1b');
if (begin > pos) {
print(line.mid(pos, begin - pos));
}

pos = begin + ansiStr.length();
ansiForeachColorCode(ansiStr, [&next](int code) { next.process_code(code); });
pos = static_cast<int>(begin + ansiStr.length());
ansiForeachColorCode(ansiStr, [&next](auto code) { next.process_code(code); });
});

if (pos < line.length()) {
Expand Down Expand Up @@ -839,9 +839,9 @@ AnsiStringToken::AnsiStringToken(AnsiStringToken::TokenTypeEnum _type,
, length_{_length}
{
const auto maxlen = _text.length();
assert(isClamped(start_offset(), 0, maxlen));
assert(isClamped(length(), 0, maxlen));
assert(isClamped(end_offset(), 0, maxlen));
assert(isClamped(start_offset(), static_cast<size_type>(0), maxlen));
assert(isClamped(length(), static_cast<size_type>(0), maxlen));
assert(isClamped(end_offset(), static_cast<size_type>(0), maxlen));
}

QStringView AnsiStringToken::getQStringView() const
Expand All @@ -859,17 +859,17 @@ AnsiTokenizer::Iterator::Iterator(const QString &_str, AnsiTokenizer::Iterator::
: str_{_str}
, pos_{_pos}
{
assert(isClamped(pos_, 0, str_.size()));
assert(isClamped(pos_, static_cast<size_type>(0), str_.size()));
}

AnsiStringToken AnsiTokenizer::Iterator::next()
{
assert(hasNext());
const auto len = str_.size();
const auto token = getCurrent();
assert(isClamped(pos_, 0, len));
assert(isClamped(pos_, static_cast<size_type>(0), len));
assert(token.start_offset() == pos_);
assert(isClamped(token.length(), 1, len - pos_));
assert(isClamped(token.length(), static_cast<size_type>(1), len - pos_));
pos_ = token.end_offset();
return token;
}
Expand Down
12 changes: 6 additions & 6 deletions src/global/TextUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void foreachChar(const QStringView input, char c, Callback &&callback)
assert(next >= pos);
assert(input[next] == c);
callback(next);
pos = static_cast<int>(next + 1);
pos = static_cast<int>(next) + 1;
}
}

Expand All @@ -102,7 +102,7 @@ void foreachLine(const QStringView input, Callback &&callback)
assert(next >= pos);
assert(input[next] == '\n');
callback(input.mid(pos, next - pos), true);
pos = static_cast<int>(next + 1);
pos = static_cast<int>(next) + 1;
}
if (pos < len)
callback(input.mid(pos, len - pos), false);
Expand All @@ -129,13 +129,13 @@ template<typename Callback>
void foreachAnsi(const QStringView line, Callback &&callback)
{
const auto len = line.size();
int pos = 0;
auto pos = 0;
while (pos < len) {
auto m = weakAnsiRegex.match(line, pos);
if (!m.hasMatch())
break;
callback(m.capturedStart(), m.capturedView());
pos = m.capturedEnd();
pos = static_cast<int>(m.capturedEnd());
}
}

Expand Down Expand Up @@ -389,7 +389,7 @@ class NODISCARD AnsiStringToken final
public:
NODISCARD QChar at(const size_type pos) const
{
assert(isClamped(pos, 0, length_));
assert(isClamped(pos, static_cast<size_type>(0), length_));
return text_.at(offset_ + pos);
}
NODISCARD QChar operator[](const size_type pos) const { return at(pos); }
Expand Down Expand Up @@ -467,7 +467,7 @@ struct NODISCARD AnsiTokenizer final
{
const auto len = str_.size();
const auto start = pos_;
assert(isClamped(start, 0, len));
assert(isClamped(start, static_cast<size_type>(0), len));
auto it = start + 1;
for (; it < len; ++it)
if (check(str_[it]) == ResultEnum::STOP)
Expand Down
Loading

0 comments on commit 92071cb

Please sign in to comment.