Skip to content

Commit

Permalink
Initial work on porting to Qt6
Browse files Browse the repository at this point in the history
- CMake updates to require Qt 6, and use the unversioned target / command names to simplify future porting
- Remove ifdefs for supporting old Qt5 version
- Replace QStandardPaths::DataLocation with the recommended AppDataLocation
- Port to QRegularExpression
- Replace QFontMetrics::width() with horizontalAdvance()
- Many updates to music symbol handling now that we can't implicitly convert to QChar
- Only tested on macOS so far
  • Loading branch information
cameronwhite committed Sep 22, 2024
1 parent 19e3cf4 commit 4e1cd7e
Show file tree
Hide file tree
Showing 31 changed files with 195 additions and 252 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ jobs:
rm /usr/local/bin/idle3*
rm /usr/local/bin/pydoc3*
rm /usr/local/bin/python3*
brew install --overwrite boost cmake doctest minizip ninja nlohmann-json pugixml qt5 pugixml rtmidi
brew install --overwrite boost cmake doctest minizip ninja nlohmann-json pugixml qt6 pugixml rtmidi
- name: Generate Project
run: cmake -S ${GITHUB_WORKSPACE} -B ${{runner.workspace}}/build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/usr/local/opt/qt@5/lib/cmake
run: cmake -S ${GITHUB_WORKSPACE} -B ${{runner.workspace}}/build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/usr/local/opt/qt6/lib/cmake
- name: Build
run: cmake --build ${{runner.workspace}}/build
- name: Test
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Thanks to the following contributors who worked on this release:
- Chord diagrams now display the fret number of the top fret instead of the next fret after it (#408)
- Updated the minimum required version of `RtMidi` to 4.0
- Updated the minimum required version of `boost` to 1.74
- Updated the minimum required version of `Qt` to 6.2

### Fixed
- Fixed a bug that caused some preferences such as custom shortcuts to not persist on macOS. Note that all other preferences (such as MIDI settings) are reset by this fix and will need to be manually changed to the desired values (#447).
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Power Tab Editor 2.0 - A powerful cross platform guitar tablature viewer and edi
* rational
* signals2
* stacktrace
* [Qt](http://qt-project.org/) >= 5.10 version or greater
* [Qt](http://qt-project.org/) >= 6.2 version or greater
* [nlohmann-json](https://github.com/nlohmann/json) >= 3.7.3
* [RtMidi](https://www.music.mcgill.ca/~gary/rtmidi/) >= 4.0
* [pugixml](https://pugixml.org/)
Expand Down Expand Up @@ -129,10 +129,10 @@ You'll have to update the variables for your specific paths to `$vcpkg_exe_path`
#### OS X:
* Install Xcode along with its Command Line Tools.
* Install dependencies:
* `brew install boost cmake doctest minizip ninja nlohmann-json pugixml qt@5 pugixml rtmidi`
* `brew install boost cmake doctest minizip ninja nlohmann-json pugixml qt6 pugixml rtmidi`
* Build:
* `mkdir build && cd build`
* `cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/usr/local/opt/qt@5/lib/cmake ..`
* `cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/usr/local/opt/qt6/lib/cmake ..`
* To generate an Xcode project, switch to `-G Xcode` and then open and build `build/powertabeditor.xcodeproj`
* `ninja`
* Run:
Expand Down
2 changes: 1 addition & 1 deletion cmake/PTE_Executable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function( pte_executable )

set( generated_files )
if ( PTE_EXE_RESOURCES )
qt5_add_resources( generated_files ${PTE_EXE_RESOURCES} )
qt_add_resources( generated_files ${PTE_EXE_RESOURCES} )
endif ()

if ( PTE_EXE_CONSOLE )
Expand Down
4 changes: 2 additions & 2 deletions cmake/PTE_Library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ function( pte_library )
set( generated_headers )
set( moc_files )
if ( PTE_LIB_FORMS )
qt5_wrap_ui( generated_headers ${PTE_LIB_FORMS} )
qt_wrap_ui( generated_headers ${PTE_LIB_FORMS} )
endif ()
if ( PTE_LIB_MOC_HEADERS )
qt5_wrap_cpp( moc_files ${PTE_LIB_MOC_HEADERS} )
qt_wrap_cpp( moc_files ${PTE_LIB_MOC_HEADERS} )
endif ()

add_library( ${PTE_LIB_NAME} STATIC
Expand Down
20 changes: 11 additions & 9 deletions cmake/third_party/Qt.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
find_package( Qt5Widgets REQUIRED )
find_package( Qt5Network REQUIRED )
find_package( Qt5PrintSupport REQUIRED )
find_package( Qt5LinguistTools REQUIRED )
find_package( Qt6 REQUIRED COMPONENTS
Widgets
Network
PrintSupport
LinguistTools
)

set( QT5_PLUGINS )
set( QT_PLUGINS )
if ( PLATFORM_WIN )
set( QT5_PLUGINS
Qt5::QWindowsIntegrationPlugin
Qt5::QWindowsVistaStylePlugin
set( QT_PLUGINS
Qt::QWindowsIntegrationPlugin
Qt::QWindowsVistaStylePlugin
)
endif ()

# Find some standard paths to the Qt installation.
get_target_property( _uic_path Qt5::uic IMPORTED_LOCATION )
get_target_property( _uic_path Qt::lconvert IMPORTED_LOCATION )
get_filename_component( PTE_QT_BIN_DIR ${_uic_path} DIRECTORY )
get_filename_component( PTE_QT_ROOT_DIR ${PTE_QT_BIN_DIR} DIRECTORY )

Expand Down
2 changes: 1 addition & 1 deletion source/actions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,5 @@ pte_library(
MOC_HEADERS ${moc_headers}
DEPENDS
ptescore
Qt5::Widgets
Qt::Widgets
)
4 changes: 2 additions & 2 deletions source/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ pte_library(
ptepainters
ptewidgets
pteutil
Qt5::Widgets
Qt5::PrintSupport
Qt::Widgets
Qt::PrintSupport
)
7 changes: 3 additions & 4 deletions source/app/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ path getConfigDir()
path getUserDataDir()
{
return fromQString(
QStandardPaths::writableLocation(QStandardPaths::DataLocation));
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
}

std::vector<path> getDataDirs()
{
std::vector<path> paths;
for (const QString &p :
QStandardPaths::standardLocations(QStandardPaths::DataLocation))
QStandardPaths::standardLocations(QStandardPaths::AppDataLocation))
{
paths.push_back(fromQString(p));
}
Expand All @@ -67,8 +67,7 @@ getTranslationDirs()
p /= "translations";

// Also check in the Qt translations folder.
paths.push_back(
fromQString(QLibraryInfo::location(QLibraryInfo::TranslationsPath)));
paths.push_back(fromQString(QLibraryInfo::path(QLibraryInfo::TranslationsPath)));

return paths;
}
Expand Down
23 changes: 7 additions & 16 deletions source/app/powertabeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@

#include <formats/fileformatmanager.h>

#include <QActionGroup>
#include <QCoreApplication>
#include <QDebug>
#include <QDesktopServices>
Expand All @@ -138,6 +139,7 @@
#include <QPrinter>
#include <QPrintDialog>
#include <QPrintPreviewDialog>
#include <QRegularExpression>
#include <QScrollArea>
#include <QTabBar>
#include <QUrl>
Expand Down Expand Up @@ -457,11 +459,12 @@ bool PowerTabEditor::saveFileAs(int doc_index)
if (info.suffix().isEmpty())
{
const QString file_filter = dialog.selectedNameFilter();
QRegExp regex("\\*.(\\w+)");
if (regex.indexIn(file_filter, 0) < 0)
QRegularExpression regex("\\*.(\\w+)");
QRegularExpressionMatch match = regex.match(file_filter);
if (!match.hasMatch())
return false;

const QString extension = regex.cap(1);
const QString extension = match.captured(1);
path += ".";
path += extension;
}
Expand Down Expand Up @@ -2207,14 +2210,6 @@ void PowerTabEditor::updateWindowTitle()
setWindowTitle(name);
}

/// C++20 deprecated bitwise operations between different enum types, which
/// QKeySequence relies on.
inline constexpr int
operator|(Qt::Modifier m, Qt::Key k)
{
return static_cast<int>(m) | static_cast<int>(k);
}

void PowerTabEditor::createCommands()
{
// File-related commands.
Expand Down Expand Up @@ -3596,7 +3591,7 @@ void PowerTabEditor::createTabArea()
QVBoxLayout *layout = new QVBoxLayout(myPlaybackArea);
layout->addWidget(myTabWidget);
layout->addWidget(myPlaybackWidget, 0, Qt::AlignHCenter);
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);

enableEditing(false);
Expand Down Expand Up @@ -3759,11 +3754,7 @@ void PowerTabEditor::setupNewTab()
// Each tab is 200px wide, so we want to shorten the name if it's wider
// than 140px.
bool chopped = false;
#if (QT_VERSION >= QT_VERSION_CHECK(5,11,0))
while (fm.horizontalAdvance(title) > 140)
#else
while (fm.width(title) > 140)
#endif
{
title.chop(1);
chopped = true;
Expand Down
2 changes: 1 addition & 1 deletion source/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pte_library(
DEPENDS
PUBLIC
ptescore
Qt5::Core
Qt::Core
PRIVATE
rtmidi::rtmidi
${platform_deps}
Expand Down
6 changes: 3 additions & 3 deletions source/build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ pte_executable(
DEPENDS
pteapp
ptedialogs
Qt5::Network
Qt5::Widgets
Qt::Network
Qt::Widgets
${platform_deps}
PLUGINS
${QT5_PLUGINS}
${QT_PLUGINS}
)

if ( PLATFORM_OSX )
Expand Down
25 changes: 3 additions & 22 deletions source/build/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,7 @@
static void displayError(const std::string &reason)
{
std::string message = reason;
#if BOOST_VERSION >= 106900
message += boost::stacktrace::to_string(
boost::stacktrace::stacktrace());
#else
for (auto &&frame : boost::stacktrace::stacktrace())
{
message += boost::stacktrace::to_string(frame);
message += "\n";
}
#endif
message += boost::stacktrace::to_string(boost::stacktrace::stacktrace());

// If there is no QApplication instance, something went seriously wrong
// during startup - just dump the error to the console.
Expand Down Expand Up @@ -147,25 +138,15 @@ loadTranslations(QApplication &app, QTranslator &qt_translator,
ptb_translator.load(locale, QStringLiteral("powertabeditor"),
QStringLiteral("_"), dir))
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,0))
qDebug() << "Loaded application translations from"
<< ptb_translator.filePath();
#else
qDebug() << "Loaded application translations";
#endif
qDebug() << "Loaded application translations from" << ptb_translator.filePath();
app.installTranslator(&ptb_translator);
}

if (qt_translator.isEmpty() &&
qt_translator.load(locale, QStringLiteral("qtbase"),
QStringLiteral("_"), dir))
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,0))
qDebug() << "Loaded Qt base translations from"
<< qt_translator.filePath();
#else
qDebug() << "Loaded Qt base translations";
#endif
qDebug() << "Loaded Qt base translations from" << qt_translator.filePath();
app.installTranslator(&qt_translator);
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/dialogs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,5 @@ pte_library(
FORMS ${forms}
DEPENDS
ptescore
Qt5::Widgets
Qt::Widgets
)
16 changes: 2 additions & 14 deletions source/dialogs/chordnamedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,7 @@ ChordNameDialog::ChordNameDialog(QWidget *parent,
myTonicKeys->addButton(ui->tonicGButton, ChordName::G);
myTonicKeys->addButton(ui->tonicAButton, ChordName::A);
myTonicKeys->addButton(ui->tonicBButton, ChordName::B);
connect(myTonicKeys,
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,0))
&QButtonGroup::idClicked,
#else
qOverload<int>(&QButtonGroup::buttonClicked),
#endif
this, &ChordNameDialog::onTonicChanged);
connect(myTonicKeys, &QButtonGroup::idClicked, this, &ChordNameDialog::onTonicChanged);

myBassKeys = new QButtonGroup(this);
myBassKeys->addButton(ui->bassCButton, ChordName::C);
Expand All @@ -90,13 +84,7 @@ ChordNameDialog::ChordNameDialog(QWidget *parent,
myBassKeys->addButton(ui->bassGButton, ChordName::G);
myBassKeys->addButton(ui->bassAButton, ChordName::A);
myBassKeys->addButton(ui->bassBButton, ChordName::B);
connect(myBassKeys,
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,0))
&QButtonGroup::idClicked,
#else
qOverload<int>(&QButtonGroup::buttonClicked),
#endif
this, &ChordNameDialog::updateState);
connect(myBassKeys, &QButtonGroup::idClicked, this, &ChordNameDialog::updateState);

connect(ui->formulaListWidget,
qOverload<int>(&QComboBox::currentIndexChanged), this,
Expand Down
4 changes: 0 additions & 4 deletions source/dialogs/fileinformationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,7 @@ FileInformationDialog::FileInformationDialog(
ui->fileLocationValue->setText(filePath);
ui->fileSizeValue->setText(
tr("%1 bytes").arg(locale.toString(fileInfo.size())));
#if (QT_VERSION >= QT_VERSION_CHECK(5,10,0))
ui->fileCreatedValue->setText(locale.toString(fileInfo.birthTime()));
#else
ui->fileCreatedValue->setText(locale.toString(fileInfo.created()));
#endif
ui->fileModifiedValue->setText(locale.toString(fileInfo.lastModified()));
ui->fileAccessedValue->setText(locale.toString(fileInfo.lastRead()));
}
Expand Down
3 changes: 0 additions & 3 deletions source/dialogs/preferencesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ PreferencesDialog::PreferencesDialog(QWidget *parent,
{
ui->setupUi(this);

// Needed for findData() to work with QVariant's containing std::pair.
QMetaType::registerComparators<MidiApiAndPort>();

connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);

Expand Down
2 changes: 1 addition & 1 deletion source/painters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ pte_library(
MOC_HEADERS ${moc_headers}
DEPENDS
ptescore
Qt5::Widgets
Qt::Widgets
)
Loading

0 comments on commit 4e1cd7e

Please sign in to comment.