Skip to content

Commit

Permalink
Get qt6 build working
Browse files Browse the repository at this point in the history
Adjust obselete gui code and other changes to accomodate building simc gui with both qt5 and qt6

Also extend the WinRelease script a bit

Change qmake as well as cmake related build setup to support both qt5 and qt6 builds
  • Loading branch information
scamille committed Oct 3, 2021
1 parent 9e03c23 commit 1686ce4
Show file tree
Hide file tree
Showing 26 changed files with 116 additions and 83 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,8 @@ env/
# Visual Studio CMake settings
CMakeSettings.json

# Cmake user file from QtCreator
CMakeLists.txt.user

UpgradeLog.htm
libsimcengine.prl
34 changes: 16 additions & 18 deletions WinReleaseScripts/build-simc.bat
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ if ERRORLEVEL 1 goto :enderror
if defined RELEASE if not defined RELEASE_CREDENTIALS call :error RELEASE builds must set RELEASE_CREDENTIALS
if ERRORLEVEL 1 goto :enderror

if not defined QMAKE_SPEC set QMAKE_SPEC=win32-msvc

if defined RELEASE set SC_DEFAULT_APIKEY=%RELEASE_CREDENTIALS%

:: Setup GIT HEAD commithash for the package name if GIT is found
Expand All @@ -47,13 +49,6 @@ if ERRORLEVEL 0 for /F "delims=" %%i IN ('git --git-dir=%SIMCDIR%\.git\ rev-pars
if defined RELEASE set GITREV=
)

:: Setup archive name and installation directory
if "%PLATFORM%" == "x64" set PACKAGESUFFIX=win64
if "%PLATFORM%" == "x86" set PACKAGESUFFIX=win32

if not defined PACKAGESUFFIX call :error Unable to determine target architecture
if ERRORLEVEL 1 goto :enderror

set PACKAGENAME=%INSTALL%\simc-%SIMCVERSION%-%PACKAGESUFFIX%-%GITREV%
set INSTALLDIR=%INSTALL%\simc-%SIMCVERSION%-%PACKAGESUFFIX%

Expand All @@ -70,7 +65,7 @@ if "%3" == "" set TARGET=/t:Clean,Build

:: Generate solution before building
del /Q "%SIMCDIR%\.qmake.stash"
%QTDIR%\bin\qmake.exe -r -tp vc -spec win32-msvc -o "%SIMCDIR%\simulationcraft.sln" "%SIMCDIR%\simulationcraft.pro"
call %QTDIR%\bin\qmake -r -tp vc -spec %QMAKE_SPEC% -o "%SIMCDIR%\simulationcraft.sln" "%SIMCDIR%\simulationcraft.pro"

:: Figure out the platform target, Qt creates "Win32" for x86, x64 is intact
set VSPLATFORM=%PLATFORM%
Expand All @@ -84,7 +79,7 @@ call :copy_base

:: Copy release-specific files
call :copy_simc
call :copy_simcgui
if not defined NO_GUI call :copy_simcgui
:: Build the Inno Setup installer
call :build_installer

Expand Down Expand Up @@ -158,15 +153,18 @@ goto :enderror
echo.
echo To build, set the following environment variables:
echo ============================================================
echo SIMCVERSION: Simulationcraft release version (default from %SIMCDIR%\engine\simulationcraft.hpp)
echo SIMCDIR : Simulationcraft source directory root
echo QTDIR : Root directory of the Qt (5) release, including the platform path (e.g., msvc2017_64)
echo SZIP : Directory containing 7-Zip compressor (optional, if omitted no compressed file)
echo ISCC : Diretory containing Inno Setup (optional, if omitted no setup will be built)
echo INSTALL : Base Directory to make an installation package in. Files will be located in directory INSTALL\simc-%SIMCVERSION%-%PACKAGESUFFIX%
echo GITREV : Short Git-Hash identifying the source commit. If not provided, the script attempts to retrieve it
echo RELEASE : Set to build a "release version" (no git commit hash suffix)
echo : If set, set RELEASE_CREDENTIALS to the Battle.net key for the release
echo SIMCVERSION : Simulationcraft release version (default from %SIMCDIR%\engine\simulationcraft.hpp)
echo SIMCDIR : Simulationcraft source directory root
echo QTDIR : Root directory of the Qt (5) release, including the platform path (e.g., msvc2017_64)
echo SZIP : Directory containing 7-Zip compressor (optional, if omitted no compressed file)
echo ISCC : Diretory containing Inno Setup (optional, if omitted no setup will be built)
echo INSTALL : Base Directory to make an installation package in. Files will be located in directory INSTALL\simc-%SIMCVERSION%-%PACKAGESUFFIX%
echo PACKAGESUFFIX : Suffix for install directory and package name. Eg. win64_qt6
echo GITREV : Short Git-Hash identifying the source commit. If not provided, the script attempts to retrieve it
echo RELEASE : Set to build a "release version" (no git commit hash suffix)
echo NO_GUI : If defined, no gui files are copied to the install folder
echo QMAKE_SPEC : qmake -spec argument. Default: win32-msvc
echo : If set, set RELEASE_CREDENTIALS to the Battle.net key for the release
goto :end

:end
Expand Down
10 changes: 9 additions & 1 deletion gui/gui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include(../simulationcraft.pri)
TEMPLATE = app
TARGET = SimulationCraft
CONFIG += link_prl
QT += network widgets webengine webenginewidgets
QT += network widgets
LIBS += -L../lib -lsimcengine
INCLUDEPATH += ../qt
MOC_DIR = moc
Expand All @@ -15,6 +15,14 @@ TRANSLATIONS = \
../locale/sc_it.ts \
../locale/sc_ko.ts

lessThan( QT_MAJOR_VERSION, 6 ) {
QT += webengine webenginewidgets
}

greaterThan( QT_MAJOR_VERSION, 5 ) {
QT += webenginecore webenginewidgets
}

# Linux puts binaries to a different place (see simulationcraft.pri)
win32|macx {
DESTDIR = ..
Expand Down
13 changes: 7 additions & 6 deletions qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
if(APPLE)
list(APPEND CMAKE_PREFIX_PATH /usr/local/opt/qt5)
endif()
find_package(Qt5Core CONFIG REQUIRED)
find_package(Qt5Gui CONFIG REQUIRED)
find_package(Qt5Widgets CONFIG REQUIRED)
find_package(Qt5WebEngine CONFIG REQUIRED)
find_package(Qt5WebEngineWidgets CONFIG REQUIRED)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS WebEngineCore REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS WebEngineWidgets REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
Expand All @@ -24,4 +25,4 @@ FILE(COPY ../qt/Error.html DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
include(../source_files/cmake_gui.txt)
add_executable(SimulationCraft ${source_files})
target_include_directories(SimulationCraft PUBLIC ../engine/)
target_link_libraries(SimulationCraft engine Qt5::Core Qt5::Gui Qt5::Widgets Qt5::WebEngine Qt5::WebEngineWidgets)
target_link_libraries(SimulationCraft engine Qt::Core Qt::Gui Qt::Widgets Qt::WebEngineCore Qt::WebEngineWidgets)
16 changes: 6 additions & 10 deletions qt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "util/sc_mainwindowcommandline.hpp"

#include <QString>
#include <QWebEngineHistory>
#include <sstream>
#include <string>

Expand Down Expand Up @@ -545,17 +546,12 @@ void SC_MainWindow::deleteSim( std::shared_ptr<sim_t>& sim, SC_TextEdit* append_
std::list<QString> directoriesWithPermissionIssues;
std::list<QString> filesWithPermissionIssues;
std::list<QString> filesThatAreDirectories;
std::string windowsPermissionRecommendation;
std::string windowsPermissionRecommendation =
"Try running the program with administrative privileges by right clicking and selecting \"Run as "
"administrator\"\n Or even installing the program to a different directory may help resolve these "
"permission issues.";
std::string suggestions;
#ifdef SC_WINDOWS
if ( QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA )
{
windowsPermissionRecommendation =
"Try running the program with administrative privileges by right clicking and selecting \"Run as "
"administrator\"\n Or even installing the program to a different directory may help resolve these "
"permission issues.";
}
#endif

for ( std::list<std::string>::iterator it = files.begin(); it != files.end(); ++it )
{
if ( !( *it ).empty() )
Expand Down
1 change: 0 additions & 1 deletion qt/MainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class SC_MainWindow : public QWidget
QGroupBox* createCustomCharData;
SC_RecentlyClosedTabItemModel* recentlyClosedTabModel;
SC_RecentlyClosedTabWidget* recentlyClosedTabImport;
QDesktopWidget desktopWidget;

QTimer* timer;
QTimer* soloChar;
Expand Down
6 changes: 3 additions & 3 deletions qt/WebEngineConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#pragma once

#include <QtWebEngine/QtWebEngine>
#include <QtWebEngineWidgets/QtWebEngineWidgets>
#include <QWebEnginePage>
#include <QWebEngineView>

using SC_WebEngineView = QWebEngineView;
using SC_WebEnginePage = QWebEnginePage;
using SC_WebEnginePage = QWebEnginePage;
3 changes: 2 additions & 1 deletion qt/WebPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// ==========================================================================

#include "WebPage.hpp"
#include <QDesktopServices>

SC_WebPage::SC_WebPage( QObject* parent ) : SC_WebEnginePage( parent )
{
Expand All @@ -25,4 +26,4 @@ bool SC_WebPage::acceptNavigationRequest( const QUrl& url, NavigationType, bool
QDesktopServices::openUrl( url_to_show );
return false;
}
#endif // QT5.5.0+
#endif // QT5.5.0+
9 changes: 5 additions & 4 deletions qt/WebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include "WebPage.hpp"
#include "util/sc_searchbox.hpp"

#include <QtWidgets/QShortcut>
#include <QShortcut>
#include <QNetworkDiskCache>

SC_WebView::SC_WebView( SC_MainWindow* mw, QWidget* parent, const QString& h )
: SC_WebEngineView( parent ),
Expand Down Expand Up @@ -217,7 +218,7 @@ void SC_WebView::findSomeText( const QString& text, SC_WebEnginePage::FindFlags

void SC_WebView::findSomeText( const QString& text )
{
SC_WebEnginePage::FindFlags flags = 0;
SC_WebEnginePage::FindFlags flags;
if ( searchBox->reverseSearch() )
{
flags |= SC_WebEnginePage::FindBackward;
Expand All @@ -232,5 +233,5 @@ void SC_WebView::findPrev()

void SC_WebView::findNext()
{
findSomeText( searchBox->text(), 0 );
}
findSomeText( searchBox->text(), SC_WebEnginePage::FindFlags() );
}
3 changes: 1 addition & 2 deletions qt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void parse_additional_args( SC_MainWindow& w, QStringList args )
if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
QTextStream ts( &file );
ts.setCodec( "UTF-8" );
ts.setAutoDetectUnicode( true );
w.simulateTab->add_Text( ts.readAll(), args[ i ] );
file.close();
Expand Down Expand Up @@ -125,7 +124,7 @@ int main( int argc, char* argv[] )
a.installTranslator( &myappTranslator );

QString iconlocation =
QStandardPaths::locate( QStandardPaths::DataLocation, QString( "icon" ), QStandardPaths::LocateDirectory );
QStandardPaths::locate( QStandardPaths::AppDataLocation, QString( "icon" ), QStandardPaths::LocateDirectory );
QDir::addSearchPath( "icon", iconlocation );

SC_MainWindow w;
Expand Down
13 changes: 7 additions & 6 deletions qt/sc_OptionsTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ QString RemoveBadFileChar( QString& filename )

#if defined SC_WINDOWS
// Prevent Windows Devices
static const char* windowsDevices = "CON|AUX|PRN|COM1|COM2|COM3|LPT1|LPT2|LPT3|NUL";
static QRegExp regexWindowsDevice( QLatin1String( windowsDevices ), Qt::CaseInsensitive );
bool matchesWinDevice = regexWindowsDevice.exactMatch( filename );
if ( matchesWinDevice )
static const char* windowsDevices = "^(CON|AUX|PRN|COM1|COM2|COM3|LPT1|LPT2|LPT3|NUL)$";
static QRegularExpression regexWindowsDevice( QLatin1String( windowsDevices ), QRegularExpression::CaseInsensitiveOption );
auto matchesWinDevice = regexWindowsDevice.match( filename );
if ( matchesWinDevice.hasMatch() )
filename = "";
#endif

Expand Down Expand Up @@ -859,7 +859,7 @@ void SC_OptionsTab::decodeOptions()
load_scaling_groups( settings, "plots_buttons", plotsButtonGroup );
load_scaling_groups( settings, "reforgeplots_buttons", reforgeplotsButtonGroup );

QStringList item_db_order = settings.value( "item_db_order" ).toString().split( "/", QString::SkipEmptyParts );
QStringList item_db_order = settings.value( "item_db_order" ).toString().split( "/", Qt::SkipEmptyParts );
if ( !item_db_order.empty() )
{
for ( int i = 0; i < item_db_order.size(); ++i )
Expand Down Expand Up @@ -1617,7 +1617,8 @@ void SC_OptionsTab::_savefilelocation()
{
QFileDialog f( this );
f.setDirectory( auto_save_location );
f.setFileMode( QFileDialog::DirectoryOnly );
f.setFileMode( QFileDialog::Directory );
f.setOption( QFileDialog::ShowDirsOnly, true );
f.setWindowTitle( tr( "Default Save Location" ) );

f.exec();
Expand Down
8 changes: 4 additions & 4 deletions qt/sc_SpellQueryTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ SC_SpellQueryTab::SC_SpellQueryTab( SC_MainWindow* parent ) : QWidget( parent ),

// Add a label
label.input = new QLabel( tr( "Input Options" ) );
gridLayout->addWidget( label.input, 0, 0, nullptr );
gridLayout->addWidget( label.input, 0, 0 );

// Element (1,0) is a GroupBox containing the inputs
QGroupBox* inputGroupBox = new QGroupBox();
gridLayout->addWidget( inputGroupBox, 1, 0, nullptr );
gridLayout->addWidget( inputGroupBox, 1, 0 );

// Layout of the groupbox
QGridLayout* inputGroupBoxLayout = new QGridLayout();
Expand Down Expand Up @@ -245,8 +245,8 @@ SC_SpellQueryTab::SC_SpellQueryTab( SC_MainWindow* parent ) : QWidget( parent ),
QFont f( "monospace" );
f.setStyleHint( QFont::Monospace );
textbox.result->setFont( f );
gridLayout->addWidget( label.output, 2, 0, nullptr );
gridLayout->addWidget( textbox.result, 3, 0, nullptr );
gridLayout->addWidget( label.output, 2, 0 );
gridLayout->addWidget( textbox.result, 3, 0 );

// this adjusts the relative width of each column
// gridLayout -> setColumnStretch( 0, 1 );
Expand Down
7 changes: 4 additions & 3 deletions qt/sc_importWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ void BattleNetImportWidget::parseRealmListFile( QFile& file )
realmList.push_back( std::make_pair( obj[ "name" ].toString(), obj[ "slug" ].toString() ) );
}

QRegExp region( "([A-Za-z]+).json$" );
QRegularExpression region( "([A-Za-z]+).json$" );
QString region_str;

if ( region.indexIn( file.fileName() ) >= 0 )
auto region_match = region.match( file.fileName() );
if ( region_match.hasMatch() )
{
region_str = region.cap( 1 ).toUpper();
region_str = region_match.captured( 1 ).toUpper();
}

if ( region_str.size() > 0 )
Expand Down
1 change: 0 additions & 1 deletion qt/sc_importWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ struct IUnknown;
#include <QDebug>
#include <QFile>
#include <QMap>
#include <QRegExpValidator>
#include <QSettings>
#include <QStandardItemModel>
#include <QVector>
Expand Down
2 changes: 1 addition & 1 deletion qt/sc_importWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct IUnknown;
#endif

#include <QDebug>
#include <QtWidgets/QShortcut>
#include <QShortcut>
#include <QtWidgets/QtWidgets>

class SC_MainWindow;
Expand Down
2 changes: 1 addition & 1 deletion qt/util/ComboBoxIntegerValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void SC_ComboBoxIntegerValidator::stripNonNumbersAndAdjustCursorPos( QString& in
if ( cursorPos > 0 )
{
// move the cursor to the left by how many characters to the left gets removed
QString charactersLeftOfCursor = input.leftRef( cursorPos ).toString();
QString charactersLeftOfCursor = input.left( cursorPos );
int characterCountLeftOfCursor = charactersLeftOfCursor.length();
// count how many characters are removed left of cursor
charactersLeftOfCursor = charactersLeftOfCursor.remove( nonIntegerRegExp );
Expand Down
2 changes: 1 addition & 1 deletion qt/util/ComboBoxIntegerValidator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SC_ComboBoxIntegerValidator : public QValidator
int upperBoundInclusive;
int lowerBoundDigitCount;
int upperBoundDigitCount;
QRegExp nonIntegerRegExp;
QRegularExpression nonIntegerRegExp;
QComboBox* comboBox;

public:
Expand Down
4 changes: 4 additions & 0 deletions qt/util/sc_hoverarea.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ class SC_HoverArea : public QWidget
}

protected:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void enterEvent( QEvent* /* event */ ) override
#else
void enterEvent( QEnterEvent* /* event */ ) override
#endif
{
if ( underMouse() && timeSinceMouseEntered.isActive() == false )
timeSinceMouseEntered.start( timeout_ );
Expand Down
Loading

0 comments on commit 1686ce4

Please sign in to comment.