Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt6 #11

Merged
merged 10 commits into from Nov 24, 2021
Merged

Qt6 #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: CMake
on:
push:
branches:
- master
- devel
- cmake
- svgscene
- rv-core
Expand All @@ -26,6 +28,12 @@ jobs:
build_type: "Release",
cc: "gcc", cxx: "g++", qt_version: "5.11.2"
}
- {
name: "Ubuntu Latest GCC + Qt6",
os: ubuntu-latest,
build_type: "Release",
cc: "gcc", cxx: "g++", qt_version: "6.2.1"
}
- {
name: "Ubuntu 18 GCC",
os: ubuntu-18.04,
Expand Down
23 changes: 18 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,25 @@ if("${WASM}" OR "${FORCE_ELFLIB_STATIC}" OR NOT "${LibElf_FOUND}")
add_subdirectory("external/libelf")
endif()

find_package(Qt5
REQUIRED COMPONENTS Core Widgets Gui Test
OPTIONAL_COMPONENTS PrintSupport)
# Detect Qt used qt version
# Based on article https://www.steinzone.de/wordpress/how-to-support-both-qt5-and-qt6-using-cmake/
# Cannot use version-less approach due to Qt 5.9.5 support constraint.
find_package(OpenGL)

message(STATUS "Qt5 version: ${Qt5Core_VERSION}")
message(STATUS "Qt5 print support: ${Qt5PrintSupport_FOUND}")
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
# Normally, we would use variable Qt5 or Qt6 to reference the Qt library. Here we do that through
# this variable based on detected version major of Qt.
set(QtLib "Qt${QT_VERSION_MAJOR}")
find_package(${QtLib}
REQUIRED COMPONENTS Core Widgets Gui Test
OPTIONAL_COMPONENTS PrintSupport)

message(STATUS "${QtLib} version: ${${QtLib}Core_VERSION}")
message(STATUS "${QtLib} print support: ${${QtLib}PrintSupport_FOUND}")


# Qt 5.9.5 is the oldest supported
add_compile_definitions(QT_DISABLE_DEPRECATED_BEFORE=0x050905)

add_subdirectory("external/svgscene")

Expand Down
63 changes: 34 additions & 29 deletions external/svgscene/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
cmake_minimum_required(VERSION 3.10)
project(svgscene)

find_package(Qt5
REQUIRED COMPONENTS Core Widgets Gui)

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
# Normally, we would use variable Qt5 or Qt6 to reference the Qt library. Here we do that through
# this variable based on detected version major of Qt.
set(QtLib "Qt${QT_VERSION_MAJOR}")
find_package(${QtLib}
REQUIRED COMPONENTS Core Widgets Gui)

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

add_library(svgscene STATIC
src/svgscene/components/groupitem.cpp
src/svgscene/components/groupitem.h
src/svgscene/components/hyperlinkitem.cpp
src/svgscene/components/hyperlinkitem.h
src/svgscene/components/simpletextitem.cpp
src/svgscene/components/simpletextitem.h
src/svgscene/graphicsview/svggraphicsview.cpp
src/svgscene/graphicsview/svggraphicsview.h
src/svgscene/svgdocument.cpp
src/svgscene/svgdocument.h
src/svgscene/svggraphicsscene.cpp
src/svgscene/svggraphicsscene.h
src/svgscene/svghandler.cpp
src/svgscene/svghandler.h
src/svgscene/svgmetadata.cpp
src/svgscene/svgmetadata.h
src/svgscene/svgspec.h
src/svgscene/utils/logging.h
src/svgscene/utils/memory_ownership.h
)
src/svgscene/components/groupitem.cpp
src/svgscene/components/groupitem.h
src/svgscene/components/hyperlinkitem.cpp
src/svgscene/components/hyperlinkitem.h
src/svgscene/components/simpletextitem.cpp
src/svgscene/components/simpletextitem.h
src/svgscene/graphicsview/svggraphicsview.cpp
src/svgscene/graphicsview/svggraphicsview.h
src/svgscene/svgdocument.cpp
src/svgscene/svgdocument.h
src/svgscene/svggraphicsscene.cpp
src/svgscene/svggraphicsscene.h
src/svgscene/svghandler.cpp
src/svgscene/svghandler.h
src/svgscene/svgmetadata.cpp
src/svgscene/svgmetadata.h
src/svgscene/svgspec.h
src/svgscene/utils/logging.h
src/svgscene/utils/memory_ownership.h
)
target_link_libraries(svgscene
PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets)
PRIVATE ${QtLib}::Core ${QtLib}::Gui ${QtLib}::Widgets)
target_include_directories(svgscene PUBLIC src PRIVATE src/svgscene)

add_executable(svgscene-example EXCLUDE_FROM_ALL
src/example/main.cpp
src/example/mainwindow.cpp
src/example/mainwindow.h
src/example/mainwindow.ui
)
src/example/main.cpp
src/example/mainwindow.cpp
src/example/mainwindow.h
src/example/mainwindow.ui
)
target_link_libraries(svgscene-example
PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets svgscene)
PRIVATE ${QtLib}::Core ${QtLib}::Gui ${QtLib}::Widgets svgscene)
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void SvgGraphicsView::paintEvent(QPaintEvent *event) {
}

void SvgGraphicsView::wheelEvent(QWheelEvent *ev) {
if (ev->orientation() == Qt::Vertical) {
if (ev->angleDelta().y() != 0) { // vertical orientation
if (ev->modifiers() == Qt::ControlModifier) {
double delta = ev->angleDelta().y();
zoom(delta / 10, ev->pos());
Expand Down
2 changes: 1 addition & 1 deletion src/assembler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ add_library(assembler STATIC
${assembler_SOURCES}
${assembler_HEADERS})
target_link_libraries(assembler
PRIVATE Qt5::Core)
PRIVATE ${QtLib}::Core)
2 changes: 1 addition & 1 deletion src/assembler/fixmatheval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ bool FmeExpression::parse(const QString &expression, QString &error) {
bool is_unary = true;
QString optxtx;
for (i = 0; true; i++) {
QChar ch = 0;
QChar ch {};
if (i < expression.size()) {
ch = expression.at(i);
}
Expand Down
60 changes: 40 additions & 20 deletions src/assembler/simpleasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,36 +454,56 @@ bool SimpleAsm::process_line(
}
s = s.mid(1, s.count() - 2);
for (pos = 0; pos < s.count(); pos++) {
QChar ch = s.at(pos);
if (ch == '\\') {
ch = 0;
if (pos + 1 < s.count()) {
switch (s.at(++pos).toLatin1()) {
case '\\': ch = '\\'; break;
case '0': ch = 0x00; break;
case 'r': ch = 0x0d; break;
case 'n': ch = 0x0a; break;
case 't': ch = 0x09; break;
case 'b': ch = 0x08; break;
case '"': ch = '"'; break;
default: ch = 0;
// target byte is in ASCII encoding
uint8_t target_byte = 0x00;

QChar host_char = s.at(pos);
if (host_char == '\\') {
// if the host encoding recognizes this as a backslash (escape char)

// handle end of the string check
if (pos + 1 >= s.count()) {
error = "ascii - invalid escape sequence at the end of the string";
emit report_message(messagetype::MSG_ERROR, filename, line_number, 0, error, "");
error_occured = true;
if (error_ptr != nullptr) {
*error_ptr = error;
}
return false;
}
if (ch == '\0') {
error = "ascii - incorrect escape sequence";
emit report_message(
messagetype::MSG_ERROR, filename, line_number, 0,
error, "");

// compare the host_char in host encoding but emit byte in ASCII encoding
host_char = s.at(++pos);
if (host_char == '0') {
target_byte = 0x00;
} else if (host_char == 'b') {
target_byte = 0x08;
} else if (host_char == 't') {
target_byte = 0x09;
} else if (host_char == 'n') {
target_byte = 0x0A;
} else if (host_char == 'r') {
target_byte = 0x0D;
} else if (host_char == '"') {
target_byte = 0x22;
} else if (host_char == '\\') {
target_byte = 0x5C;
} else {
error = QString("ascii - incorrect escape sequence '\\") + host_char + "'";
emit report_message(messagetype::MSG_ERROR, filename, line_number, 0, error, "");
error_occured = true;
if (error_ptr != nullptr) {
*error_ptr = error;
}
return false;
}
} else {
// otherwise convert it to ASCII and write it as-is
target_byte = host_char.toLatin1();
}

if (!fatal_occured) {
mem->write_u8(
address, (uint8_t)ch.toLatin1(), ae::INTERNAL);
mem->write_u8(address, target_byte, ae::INTERNAL);
}
address += 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ add_executable(cli
${cli_SOURCES}
${cli_HEADERS})
target_link_libraries(cli
PRIVATE Qt5::Core machine assembler)
PRIVATE ${QtLib}::Core machine assembler)
target_compile_definitions(cli
PRIVATE
APP_ORGANIZATION=\"${MAIN_PROJECT_ORGANIZATION}\"
Expand Down
29 changes: 16 additions & 13 deletions src/common/polyfills/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
project(polyfills
DESCRIPTION "Helper code to unify access to compiler intrinsics and
DESCRIPTION "Helper code to unify access to compiler intrinsics and
provide fallback implementations.")

set(polyfills_HEADERS
endian_detection.h
mulh64.h
clz32.h
byteswap.h
qstring_hash.h
)
endian_detection.h
mulh64.h
clz32.h
byteswap.h
qstring_hash.h
qt5/qfontmetrics.h
qt5/qlinef.h
qt5/qtableview.h
)

# =============================================================================
# Target for usage of this header library
Expand All @@ -26,12 +29,12 @@ if(NOT "${WASM}")
set(CMAKE_AUTOMOC ON)

add_executable(mulh64_test
mulh64.h
mulh64.test.h
mulh64.test.cpp
)
target_link_libraries(mulh64_test PRIVATE Qt5::Test)
mulh64.h
mulh64.test.h
mulh64.test.cpp
)
target_link_libraries(mulh64_test PRIVATE ${QtLib}::Test)
add_test(NAME mulh64
COMMAND mulh64_test)
COMMAND mulh64_test)
endif()

12 changes: 12 additions & 0 deletions src/common/polyfills/qt5/qfontmetrics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef POLYFILLS_QFONTMETRICS_H
#define POLYFILLS_QFONTMETRICS_H

int QFontMetrics_horizontalAdvance(const QFontMetrics &self, const QString &str, int len = -1) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
return self.horizontalAdvance(str, len);
#else
return self.width(str, len);
#endif
}

#endif // QTMIPS_QFONTMETRICS_H
15 changes: 15 additions & 0 deletions src/common/polyfills/qt5/qlinef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef POLYFILLS_QLINEF_H
#define POLYFILLS_QLINEF_H

#include <QLine>

QLineF::IntersectType
QLineF_intersect(const QLineF &l1, const QLineF &l2, QPointF *intersectionPoint) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
return l1.intersects(l2, intersectionPoint);
#else
return l1.intersect(l2, intersectionPoint);
#endif
}

#endif // QTMIPS_QLINEF_H
23 changes: 23 additions & 0 deletions src/common/polyfills/qt5/qtableview.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef POLYFILLS_QTABLEVIEW_H
#define POLYFILLS_QTABLEVIEW_H

#include <QTableView>

/**
* QTableView polyfill
*
* initViewItemOption is protected, therefore the whole class needs to be wrapped.
*/
class Poly_QTableView : public QTableView {
public:
explicit Poly_QTableView(QWidget *parent) : QTableView(parent) {}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
protected:
void initViewItemOption(QStyleOptionViewItem *viewOpts) {
*viewOpts = QTableView::viewOptions();
}
#endif
};

#endif // QTMIPS_QTABLEVIEW_H
10 changes: 5 additions & 5 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ add_executable(gui
${gui_RESOURCES})
target_include_directories(gui PUBLIC . coreview)
target_link_libraries(gui
PRIVATE Qt5::Core Qt5::Widgets Qt5::Gui
PRIVATE machine os_emulation assembler svgscene)
PRIVATE ${QtLib}::Core ${QtLib}::Widgets ${QtLib}::Gui
PRIVATE machine os_emulation assembler svgscene)
target_compile_definitions(gui
PRIVATE
APP_ORGANIZATION=\"${MAIN_PROJECT_ORGANIZATION}\"
Expand All @@ -152,9 +152,9 @@ target_compile_definitions(gui
set_target_properties(gui PROPERTIES
OUTPUT_NAME "${MAIN_PROJECT_NAME_LOWER}_${PROJECT_NAME}")

if(${Qt5PrintSupport_FOUND})
target_link_libraries(gui PRIVATE Qt5::PrintSupport)
target_compile_definitions(gui PRIVATE WITH_PRINTING=1)
if(${${QtLib}PrintSupport_FOUND})
target_link_libraries(gui PRIVATE ${QtLib}::PrintSupport)
target_compile_definitions(gui PRIVATE WITH_PRINTING=1)
endif()

# MACOS
Expand Down
Loading