Skip to content

Commit

Permalink
feat: add Qt 6 support (#1420)
Browse files Browse the repository at this point in the history
  • Loading branch information
trollixx authored Oct 2, 2022
1 parent b38a1cc commit 990be92
Show file tree
Hide file tree
Showing 30 changed files with 176 additions and 80 deletions.
45 changes: 28 additions & 17 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,36 @@ jobs:
matrix:
config:
- {
name: "Windows Server 2019",
name: "Windows Server 2019 / Qt 5",
os: windows-2019,
qt_version: '5.15.0',
qt_modules: "qtwebengine",
qt_version: "5.15.0",
configurePreset: "ninja-multi-vcpkg",
buildPreset: "ninja-multi-vcpkg-release"
}
- {
name: "Windows Server 2019, Portable",
name: "Windows Server 2019 / Qt 5 / Portable",
os: windows-2019,
qt_version: '5.15.0',
configurePreset: "ninja-multi-vcpkg-portable",
buildPreset: "ninja-multi-vcpkg-portable-release"
qt_modules: "qtwebengine",
qt_version: "5.15.0",
configurePreset: ninja-multi-vcpkg-portable,
buildPreset: ninja-multi-vcpkg-portable-release
}
- {
name: "Windows Server 2022 / Qt 6",
os: windows-2022,
qt_modules: "qtwebengine qtwebchannel qtpositioning",
qt_version: "6.3.1",
configurePreset: ninja-multi-vcpkg,
buildPreset: ninja-multi-vcpkg-release
}
- {
name: "Windows Server 2022 / Qt 6 / Portable",
os: windows-2022,
qt_modules: "qtwebengine qtwebchannel qtpositioning",
qt_version: "6.3.1",
configurePreset: ninja-multi-vcpkg-portable,
buildPreset: ninja-multi-vcpkg-portable-release
}

env:
Expand All @@ -92,21 +110,14 @@ jobs:
vcpkgDirectory: ${{ runner.workspace }}/vcpkg
vcpkgGitCommitId: cef0b3ec767df6e83806899fe9525f6cf8d7bc91 # 2022.06.16.1

- name: Cache Qt
id: cache-qt
uses: actions/cache@v3
with:
path: ${{ runner.workspace }}/Qt/
key: ${{ runner.os }}-qt-${{ matrix.config.qt_version }}

- name: Install Qt
uses: jurplel/install-qt-action@v2
uses: jurplel/install-qt-action@v3
with:
arch: win64_msvc2019_64
modules: qtwebengine
cached: ${{ steps.cache-qt.outputs.cache-hit }}
extra: --external 7z
modules: ${{ matrix.config.qt_modules }}
version: ${{ matrix.config.qt_version }}
cache: true
extra: --external 7z

- name: Print Environment
run: gci env:* | sort-object name
Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ set(PROJECT_COPYRIGHT "© 2013-2020 Oleg Shparber and other contributors")
set(PROJECT_DESCRIPTION "A simple documentation browser.")
set(PROJECT_URL "https://zealdocs.org")

set(QT_MINIMUM_VERSION 5.9.5)
# Find available major Qt version. It will be stored in QT_VERSION_MAJOR.
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
if(QT_VERSION_MAJOR EQUAL 6)
set(QT_MINIMUM_VERSION 6.2.0)
else()
set(QT_MINIMUM_VERSION 5.9.5)
endif()

# Determine version for dev builds.
if(NOT RELEASE_VERSION)
Expand Down
11 changes: 10 additions & 1 deletion assets/freedesktop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ if(UNIX AND NOT APPLE)
find_package(ECM 1.0.0 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
include(ECMInstallIcons)
include(KDEInstallDirs)

if(QT_VERSION_MAJOR EQUAL 5)
include(KDEInstallDirs)
else()
# Workaround until KDEInstallDirs6 is ready to use.
include(GNUInstallDirs)
set(KDE_INSTALL_APPDIR "${CMAKE_INSTALL_DATAROOTDIR}/applications")
set(KDE_INSTALL_ICONDIR "${CMAKE_INSTALL_DATAROOTDIR}/icons")
set(KDE_INSTALL_METAINFODIR "${CMAKE_INSTALL_DATAROOTDIR}/metainfo")
endif()

ecm_install_icons(ICONS "16-apps-zeal.png"
"24-apps-zeal.png"
Expand Down
13 changes: 5 additions & 8 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ add_executable(App WIN32

target_link_libraries(App Core Util)

find_package(Qt5 COMPONENTS Widgets REQUIRED)
if (Qt5Widgets_VERSION VERSION_LESS QT_MINIMUM_VERSION)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
if (Qt${QT_VERSION_MAJOR}Widgets_VERSION VERSION_LESS QT_MINIMUM_VERSION)
message(FATAL_ERROR "Qt version >= ${QT_MINIMUM_VERSION} is required.")
endif()

target_link_libraries(App Qt5::Widgets)
target_link_libraries(App Qt${QT_VERSION_MAJOR}::Widgets)

set_target_properties(App PROPERTIES
OUTPUT_NAME ${PROJECT_OUTPUT_NAME}
Expand All @@ -40,11 +40,8 @@ if(APPLE)
RESOURCE "resources/zeal.icns"
)
elseif(UNIX)
find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_KDE_MODULE_DIR})
include(KDEInstallDirs)

install(TARGETS App DESTINATION ${KDE_INSTALL_BINDIR})
include(GNUInstallDirs)
install(TARGETS App DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

#
Expand Down
19 changes: 13 additions & 6 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,17 @@ struct CommandLineParameters

QString stripParameterUrl(const QString &url, const QString &scheme)
{
QStringRef ref = url.midRef(scheme.length() + 1);
if (ref.startsWith(QLatin1String("//")))
ref = ref.mid(2);
if (ref.endsWith(QLatin1Char('/')))
ref = ref.left(ref.length() - 1);
return ref.toString();
QString str = url.mid(scheme.length() + 1);

if (str.startsWith(QLatin1String("//"))) {
str = str.mid(2);
}

if (str.endsWith(QLatin1Char('/'))) {
str = str.left(str.length() - 1);
}

return str;
}

CommandLineParameters parseCommandLine(const QStringList &arguments)
Expand Down Expand Up @@ -179,8 +184,10 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationDomain(QStringLiteral("zealdocs.org"));
QCoreApplication::setOrganizationName(QStringLiteral("Zeal"));

#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif

QScopedPointer<QApplication> qapp(new QApplication(argc, argv));

Expand Down
4 changes: 2 additions & 2 deletions src/libs/browser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ add_library(Browser STATIC

target_link_libraries(Browser)

find_package(Qt5 COMPONENTS WebEngineWidgets WebChannel REQUIRED)
target_link_libraries(Browser Qt5::WebEngineWidgets Qt5::WebChannel)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS WebChannel WebEngineWidgets REQUIRED)
target_link_libraries(Browser Qt${QT_VERSION_MAJOR}::WebChannel Qt${QT_VERSION_MAJOR}::WebEngineWidgets)
29 changes: 26 additions & 3 deletions src/libs/browser/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@
#include <QMessageBox>
#include <QPushButton>
#include <QVector>
#include <QWebEngineContextMenuData>
#include <QWebEngineProfile>
#include <QWebEngineSettings>
#include <QWheelEvent>

#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
#include <QWebEngineContextMenuData>
#else
#include <QWebEngineContextMenuRequest>
#endif

using namespace Zeal::Browser;

WebView::WebView(QWidget *parent)
Expand Down Expand Up @@ -116,13 +121,20 @@ QWebEngineView *WebView::createWindow(QWebEnginePage::WebWindowType type)

void WebView::contextMenuEvent(QContextMenuEvent *event)
{
QWebEnginePage *p = page();
const QWebEngineContextMenuData& contextData = p->contextMenuData();
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
const QWebEngineContextMenuData& contextData = page()->contextMenuData();

if (!contextData.isValid()) {
QWebEngineView::contextMenuEvent(event);
return;
}
#else
QWebEngineContextMenuRequest *contextMenuRequest = lastContextMenuRequest();
if (contextMenuRequest == nullptr) {
QWebEngineView::contextMenuEvent(event);
return;
}
#endif

event->accept();

Expand All @@ -132,7 +144,12 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)

m_contextMenu = new QMenu(this);

#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
QUrl linkUrl = contextData.linkUrl();
#else
QUrl linkUrl = contextMenuRequest->linkUrl();
#endif

if (linkUrl.isValid()) {
const QString scheme = linkUrl.scheme();

Expand All @@ -153,7 +170,13 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
}
}


#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
const QString selectedText = contextData.selectedText();
#else
const QString selectedText = contextMenuRequest->selectedText();
#endif

if (!selectedText.isEmpty()) {
if (!m_contextMenu->isEmpty()) {
m_contextMenu->addSeparator();
Expand Down
12 changes: 10 additions & 2 deletions src/libs/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ add_definitions(-DCPPHTTPLIB_USE_POLL)

target_link_libraries(Core Registry Ui)

find_package(Qt5 COMPONENTS Network WebEngine Widgets REQUIRED)
target_link_libraries(Core Qt5::Network Qt5::WebEngine Qt5::Widgets)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Network WebEngineCore Widgets REQUIRED)
target_link_libraries(Core Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::WebEngineCore Qt${QT_VERSION_MAJOR}::Widgets)

if(QT_VERSION_MAJOR EQUAL 6)
find_package(Qt6 COMPONENTS WebEngineCore Widgets REQUIRED)
target_link_libraries(Core Qt6::WebEngineCore)
else()
find_package(Qt5 COMPONENTS WebEngine Widgets REQUIRED)
target_link_libraries(Core Qt5::WebEngine)
endif()

find_package(LibArchive REQUIRED)

Expand Down
7 changes: 5 additions & 2 deletions src/libs/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <QStandardPaths>
#include <QUrl>
#include <QUuid>
#include <QWebEngineProfile>
#include <QWebEngineSettings>

namespace {
Expand All @@ -50,7 +51,9 @@ using namespace Zeal::Core;
Settings::Settings(QObject *parent)
: QObject(parent)
{
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
qRegisterMetaTypeStreamOperators<ExternalLinkPolicy>("ExternalLinkPolicy");
#endif

load();
}
Expand Down Expand Up @@ -87,7 +90,7 @@ void Settings::load()

settings->beginGroup(GroupContent);
// Fonts
QWebEngineSettings *webSettings = QWebEngineSettings::defaultSettings();
QWebEngineSettings *webSettings = QWebEngineProfile::defaultProfile()->settings();
serifFontFamily = settings->value(QStringLiteral("serif_font_family"),
webSettings->fontFamily(QWebEngineSettings::SerifFont)).toString();
sansSerifFontFamily = settings->value(QStringLiteral("sans_serif_font_family"),
Expand Down Expand Up @@ -150,7 +153,7 @@ void Settings::load()
docsetPath = settings->value(QStringLiteral("path")).toString();
} else {
#ifndef PORTABLE_BUILD
docsetPath = QStandardPaths::writableLocation(QStandardPaths::DataLocation)
docsetPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
+ QLatin1String("/docsets");
#else
docsetPath = QStringLiteral("docsets");
Expand Down
4 changes: 2 additions & 2 deletions src/libs/registry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ add_library(Registry STATIC
searchresult.h
)

find_package(Qt5 COMPONENTS Concurrent Gui Network REQUIRED)
target_link_libraries(Registry Util Qt5::Concurrent Qt5::Gui Qt5::Network)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Concurrent Gui Network REQUIRED)
target_link_libraries(Registry Util Qt${QT_VERSION_MAJOR}::Concurrent Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Network)
2 changes: 1 addition & 1 deletion src/libs/registry/docset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ void Docset::createIndex()
m_db->execute(indexDropQuery.arg(oldIndexName));
}

m_db->execute(indexCreateQuery.arg(IndexNamePrefix, IndexNameVersion, tableName, columnName));
m_db->execute(indexCreateQuery.arg(IndexNamePrefix).arg(IndexNameVersion).arg(tableName).arg(columnName));
}

void Docset::createView()
Expand Down
5 changes: 4 additions & 1 deletion src/libs/registry/docsetregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ Docset *DocsetRegistry::docset(int index) const
{
if (index < 0 || index >= m_docsets.size())
return nullptr;
return (m_docsets.cbegin() + index).value();

auto it = m_docsets.cbegin();
std::advance(it, index);
return *it;
}

Docset *DocsetRegistry::docsetForUrl(const QUrl &url)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/registry/docsetregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define ZEAL_REGISTRY_DOCSETREGISTRY_H

#include "cancellationtoken.h"
#include "searchresult.h"

#include <QMap>
#include <QObject>
Expand All @@ -36,7 +37,6 @@ namespace Zeal {
namespace Registry {

class Docset;
struct SearchResult;

class DocsetRegistry final : public QObject
{
Expand Down
6 changes: 4 additions & 2 deletions src/libs/registry/listmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ QVariant ListModel::data(const QModelIndex &index, int role) const
}
case Level::SymbolLevel: {
auto groupItem = static_cast<GroupItem *>(index.internalPointer());
auto it = groupItem->docsetItem->docset->symbols(groupItem->symbolType).cbegin() + index.row();
auto it = groupItem->docsetItem->docset->symbols(groupItem->symbolType).cbegin();
std::advance(it, index.row());
return it.key();
}
default:
Expand All @@ -102,7 +103,8 @@ QVariant ListModel::data(const QModelIndex &index, int role) const
return itemInRow(index.row())->docset->indexFileUrl();
case Level::SymbolLevel: {
auto groupItem = static_cast<GroupItem *>(index.internalPointer());
auto it = groupItem->docsetItem->docset->symbols(groupItem->symbolType).cbegin() + index.row();
auto it = groupItem->docsetItem->docset->symbols(groupItem->symbolType).cbegin();
std::advance(it, index.row());
return it.value();
}
default:
Expand Down
4 changes: 2 additions & 2 deletions src/libs/sidebar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ add_library(Sidebar STATIC

target_link_libraries(Sidebar)

find_package(Qt5 COMPONENTS Widgets REQUIRED)
target_link_libraries(Sidebar Qt5::Widgets)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
target_link_libraries(Sidebar Qt${QT_VERSION_MAJOR}::Widgets)
4 changes: 2 additions & 2 deletions src/libs/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ add_library(Ui STATIC

target_link_libraries(Ui Browser Sidebar QxtGlobalShortcut Widgets Registry)

find_package(Qt5 COMPONENTS WebEngineWidgets REQUIRED)
target_link_libraries(Ui Qt5::WebEngineWidgets)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS WebEngineWidgets REQUIRED)
target_link_libraries(Ui Qt${QT_VERSION_MAJOR}::WebEngineWidgets)
6 changes: 2 additions & 4 deletions src/libs/ui/docsetsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,7 @@ void DocsetsDialog::downloadCompleted()
const QString msg = tr("Download failed!<br><br><b>Error:</b> %1<br><b>URL:</b> %2")
.arg(reply->errorString(), reply->request().url().toString());
const int ret = QMessageBox::warning(this, QStringLiteral("Zeal"), msg,
QMessageBox::Retry | QMessageBox::Default,
QMessageBox::Cancel | QMessageBox::Escape,
QMessageBox::NoButton);
QMessageBox::Retry | QMessageBox::Cancel);

if (ret == QMessageBox::Retry) {
QNetworkReply *newReply = download(reply->request().url());
Expand Down Expand Up @@ -772,7 +770,7 @@ void DocsetsDialog::downloadDashDocset(const QModelIndex &index)
QUrl url;
if (!m_userFeeds.contains(name)) {
// No feed present means that this is a Kapeli docset
QString urlString = QString(RedirectServerUrl).arg("com.kapeli", name);
QString urlString = QString(RedirectServerUrl).arg("com.kapeli").arg(name);
url = QUrl(urlString);
} else {
url = m_userFeeds[name].url();
Expand Down
Loading

0 comments on commit 990be92

Please sign in to comment.