Skip to content

Commit

Permalink
Started switching to Qt6. (#16)
Browse files Browse the repository at this point in the history
Co-authored-by: Alessandro Gatti <a.gatti@frob.it>
  • Loading branch information
DorianBDev and agatti committed Jul 7, 2023
1 parent 39c2044 commit 56c3e2f
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 31 deletions.
31 changes: 18 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ set(CMAKE_VERBOSE_MAKEFILE true)
# Set flags
#
if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -fno-inline -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -fno-inline")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
endif()
Expand Down Expand Up @@ -85,8 +85,8 @@ include_directories(${Boost_INCLUDE_DIRS})
set(LIBS ${Boost_LIBRARIES})

############# Qt
find_package(Qt5 COMPONENTS Core Widgets Gui Xml OpenGL Concurrent LinguistTools REQUIRED)
set(LIBS ${LIBS} Qt5::Widgets Qt5::Gui Qt5::Core Qt5::Xml Qt5::OpenGL Qt5::Concurrent)
find_package(Qt6 COMPONENTS Core Widgets Gui Xml OpenGL OpenGLWidgets Concurrent LinguistTools REQUIRED)
set(LIBS ${LIBS} Qt6::Widgets Qt6::Gui Qt6::Core Qt6::Xml Qt6::OpenGL Qt6::OpenGLWidgets Qt6::Concurrent)


############################################################################
Expand All @@ -96,12 +96,12 @@ set(LIBS ${LIBS} Qt5::Widgets Qt5::Gui Qt5::Core Qt5::Xml Qt5::OpenGL Qt5::Concu
#
# Configuration
#
if (CMAKE_SIZEOF_VOID_P MATCHES 8) # if x64
message(STATUS "x64 configuration")
set(CONFIGURATION "x64")
else() # if x86
message(STATUS "x86 configuration")
set(CONFIGURATION "x86")
if (CMAKE_SIZEOF_VOID_P MATCHES 8) # if 64-bits
message(STATUS "64 bits configuration")
set(CONFIGURATION "BUILD_64")
else() # if 32-bits
message(STATUS "32 bits configuration")
set(CONFIGURATION "BUILD_32")
endif()

#
Expand Down Expand Up @@ -146,10 +146,15 @@ SET(TRANSLATION_FILES

list(TRANSFORM TRANSLATION_FILES PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/res/languages/)

# Redefine "qt5_create_translation" function because of a bug (it originally parse all boost files, and make the build VERY slow)
include(${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake/Qt5LinguistToolsMacros.cmake)
# Redefine "qt6_create_translation" function because of a bug (it originally parse all boost files, and make the build VERY slow)
include(${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake/Qt6LinguistToolsMacros.cmake)

qt5_create_translation(QM_FILES ${SRC_FILES} ${TRANSLATION_FILES} OPTIONS -no-obsolete)
# TODO: Figure out why this is needed.
if (WIN32)
qt6_create_translation(QM_FILES ${SRC_FILES} ${TRANSLATION_FILES})
else ()
qt6_create_translation(QM_FILES ${SRC_FILES} ${TRANSLATION_FILES} OPTIONS "-no-obsolete")
endif ()

configure_file(res/languages/translations.qrc ${CMAKE_BINARY_DIR} COPYONLY)

Expand Down Expand Up @@ -249,4 +254,4 @@ if(DOXYGEN_FOUND)

else()
message(STATUS "Doxygen not found")
endif()
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
include(CMakeParseArguments)

# redefine this function because of a bug (it originally parse all boost files, and make the build VERY slow)
function(QT5_CREATE_TRANSLATION _qm_files)
function(QT6_CREATE_TRANSLATION _qm_files)
set(options)
set(oneValueArgs)
set(multiValueArgs OPTIONS)
Expand Down Expand Up @@ -82,7 +82,7 @@ function(QT5_CREATE_TRANSLATION _qm_files)
get_source_file_property(_qm_output_location ${_ts_file} OUTPUT_LOCATION)

add_custom_command(OUTPUT ${_tmpts_file}
COMMAND ${Qt5_LUPDATE_EXECUTABLE}
COMMAND ${Qt6_LUPDATE_EXECUTABLE}
ARGS ${_lupdate_options} "@${_ts_lst_file}" -ts ${_ts_file}
COMMAND ${CMAKE_COMMAND} -E copy ${_ts_file} ${_tmpts_file}
DEPENDS ${_my_sources}
Expand All @@ -93,6 +93,6 @@ function(QT5_CREATE_TRANSLATION _qm_files)
endif()

endforeach()
qt5_add_translation(${_qm_files} ${_my_temptsfiles})
qt6_add_translation(${_qm_files} ${_my_temptsfiles})
set(${_qm_files} ${${_qm_files}} PARENT_SCOPE)
endfunction()
2 changes: 1 addition & 1 deletion src/Core/LogicModel/Gate/GateLibraryExporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void GateLibraryExporter::export_data(std::string const& filename, GateLibrary_s
}

QTextStream stream(&file);
stream.setCodec("UTF-8");
stream.setEncoding(QStringConverter::Utf8);
stream << doc.toString();

file.close();
Expand Down
2 changes: 1 addition & 1 deletion src/Core/LogicModel/LogicModelExporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void LogicModelExporter::export_data(std::string const& filename, LogicModel_shp
}

QTextStream stream(&file);
stream.setCodec("UTF-8");
stream.setEncoding(QStringConverter::Utf8);
stream << doc.toString();

file.close();
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Project/ProjectExporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void ProjectExporter::export_data(std::string const& filename, const Project_shp
}

QTextStream stream(&file);
stream.setCodec("UTF-8");
stream.setEncoding(QStringConverter::Utf8);
stream << doc.toString();

file.close();
Expand Down
2 changes: 1 addition & 1 deletion src/Core/RuleCheck/RCVBlacklistExporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void RCVBlacklistExporter::export_data(std::string const& filename,
}

QTextStream stream(&file);
stream.setCodec("UTF-8");
stream.setEncoding(QStringConverter::Utf8);
stream << doc.toString();

file.close();
Expand Down
9 changes: 9 additions & 0 deletions src/Core/Utils/MemoryMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,17 @@ namespace degate
return RET_ERR;
}

#ifdef SYS_APPLE

struct stat inf;
if (fstat(file, &inf) < 0)

#else

struct stat64 inf;
if (fstat64(file, &inf) < 0)

#endif
{
debug(TM, "can't get the size of file: %s", filename.c_str());
return RET_ERR;
Expand Down
4 changes: 2 additions & 2 deletions src/Core/XML/XMLImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace degate

const QString attribute = node.attribute(QString::fromStdString(attribute_str), 0);

if (attribute == 0)
if (attribute.isNull())
{
throw XMLAttributeMissingException(std::string("attribute is not present: ") + attribute_str);
}
Expand All @@ -69,7 +69,7 @@ namespace degate

const QString attribute = node.attribute(QString::fromStdString(attribute_str), 0);

if (attribute == 0) return default_value;
if (attribute.isNull()) return default_value;
else return parse_number<T>(attribute.toStdString());
}

Expand Down
3 changes: 3 additions & 0 deletions src/GUI/Dialog/GateEditDialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "GateEditDialog.h"
#include "TerminalDialog.h"

#include <QFileDialog>
#include <QMessageBox>

namespace degate
{
// Entity tab
Expand Down
1 change: 1 addition & 0 deletions src/GUI/Dialog/GateEditDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QDialogButtonBox>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
#include <QComboBox>
#include <QPushButton>
#include <QColorDialog>
Expand Down
2 changes: 2 additions & 0 deletions src/GUI/Dialog/GateLibraryDialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "GateLibraryDialog.h"

#include <QMessageBox>

namespace degate
{
GateLibraryDialog::GateLibraryDialog(QWidget* parent, const Project_shptr& project)
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/Dialog/GateListDialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace degate

// ID Filter
id_filter_label.setText(tr("ID filter:"));
id_filter_edit.setValidator(new QRegExpValidator(QRegExp("[0-9]*"), this));
id_filter_edit.setValidator(new QRegularExpressionValidator(QRegularExpression("[0-9]*"), this));

// Gate template name filter
gate_template_name_filter_label.setText(tr("Gate template filter:"));
Expand Down
1 change: 1 addition & 0 deletions src/GUI/Dialog/PortPlacementDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "GUI/Widget/PortPlacementWidget.h"

#include <QDialog>
#include <QPushButton>
#include <QVBoxLayout>

namespace degate
Expand Down
12 changes: 7 additions & 5 deletions src/GUI/MainWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
#include "Core/Version.h"
#include "Core/Utils/CrashReport.h"

#include <QScreen>

#ifdef SYS_WINDOWS
#include <QtPlatformHeaders/QWindowsWindowFunctions>
#include <windows.h>
#endif

#include <memory>
Expand All @@ -38,7 +40,7 @@ namespace degate
MainWindow::MainWindow(int width, int height) : status_bar(this), tools_group(this), updater(this)
{
if (width == 0 || height == 0)
resize(QDesktopWidget().availableGeometry(this).size() * 0.7);
resize(QGuiApplication::screenAt(this->pos())->availableGeometry().size() * 0.7);
else
resize(width, height);

Expand Down Expand Up @@ -407,10 +409,10 @@ namespace degate
QObject::connect(&auto_save_timer, SIGNAL(timeout()), this, SLOT(auto_save()));

// Workaround for a bug on Windows that occurs when using QOpenGLWidget + fullscreen mode.
// See: https://doc.qt.io/qt-5/windows-issues.html#fullscreen-opengl-based-windows.
// See: https://doc.qt.io/qt-6/windows-issues.html#fullscreen-opengl-based-windows.
#ifdef SYS_WINDOWS
this->topLevelWidget()->winId();
QWindowsWindowFunctions::setHasBorderInFullScreen(this->topLevelWidget()->windowHandle(), true);
HWND handle = reinterpret_cast<HWND>(window()->winId());
SetWindowLongPtr(handle, GWL_STYLE, GetWindowLongPtr(handle, GWL_STYLE) | WS_BORDER);
#endif

// Check for updates.
Expand Down
4 changes: 2 additions & 2 deletions src/GUI/Text/Text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ namespace degate
font_data->font = font;

QTextStream font_config_file_stream(&font_config_file);
font_config_file_stream.setCodec("UTF-8");
font_config_file_stream.setEncoding(QStringConverter::Utf8);

if (font_config_file_stream.readLine().toUInt() != font_data->font.font_size || font_config_file_stream.readLine().toStdString() != font_data->font.font_family_name)
{
Expand Down Expand Up @@ -703,7 +703,7 @@ namespace degate
}

QTextStream font_config_file_stream(&font_config_file);
font_config_file_stream.setCodec("UTF-8");
font_config_file_stream.setEncoding(QStringConverter::Utf8);

font_config_file_stream << font_data->font.font_size << Qt::endl;
font_config_file_stream << QString::fromStdString(font_data->font.font_family_name) << Qt::endl;
Expand Down
1 change: 1 addition & 0 deletions src/GUI/Utils/ImageRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "Core/Project/Project.h"

#include <QtOpenGL>
#include <QtOpenGLWidgets/QOpenGLWidget>

/**
* This define the zoom out factor (zoom *= zoom_out).
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/Utils/Updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace degate
: parent(parent)
{
connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(process_finished(int, QProcess::ExitStatus)));
connect(&process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(process_error(QProcess::ProcessError)));
connect(&process, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(process_error(QProcess::ProcessError)));

#if defined(Q_OS_WIN)
tool_name = "maintenancetool.exe";
Expand Down
1 change: 1 addition & 0 deletions src/GUI/Workspace/WorkspaceRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "GUI/Workspace/WorkspaceRegularGrid.h"

#include <QtOpenGL/QtOpenGL>
#include <QtOpenGLWidgets/QtOpenGLWidgets>
#include <list>
#include <tuple>

Expand Down

0 comments on commit 56c3e2f

Please sign in to comment.