Skip to content

Commit

Permalink
Merge pull request #462 from powertab/feature/cpp20
Browse files Browse the repository at this point in the history
Upgrade to C++20
  • Loading branch information
cameronwhite authored Dec 17, 2023
2 parents bbf42c0 + 8fa3908 commit eaaa4b4
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 100 deletions.
2 changes: 1 addition & 1 deletion cmake/PTE_CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function ( pte_add_compile_flags target )

# Use C++11.
set_target_properties( ${target} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
Expand Down
4 changes: 2 additions & 2 deletions source/actions/undomanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void UndoManager::push(QUndoCommand *cmd, int affectedSystem)
auto onUndo = new SignalOnUndo();
if (affectedSystem >= 0)
{
connect(onUndo, &SignalOnUndo::triggered, [=]() {
connect(onUndo, &SignalOnUndo::triggered, [=, this]() {
onSystemChanged(affectedSystem);
});
}
Expand All @@ -70,7 +70,7 @@ void UndoManager::push(QUndoCommand *cmd, int affectedSystem)
auto onRedo = new SignalOnRedo();
if (affectedSystem >= 0)
{
connect(onRedo, &SignalOnRedo::triggered, [=]() {
connect(onRedo, &SignalOnRedo::triggered, [=, this]() {
onSystemChanged(affectedSystem);
});
}
Expand Down
6 changes: 4 additions & 2 deletions source/app/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ getAppDirPath(const path &relative_path)

path fromQString(const QString &str)
{
return std::filesystem::u8path(str.toStdString());
std::string u8_str = str.toStdString();
return std::filesystem::path(std::u8string(u8_str.begin(), u8_str.end()));
}

QString toQString(const path &str)
{
return QString::fromStdString(str.u8string());
std::u8string u8_str = str.u8string();
return QString::fromStdString(std::string(u8_str.begin(), u8_str.end()));
}
}
144 changes: 76 additions & 68 deletions source/app/powertabeditor.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion source/app/recentfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void RecentFiles::updateMenu()
auto fileAction = new QAction(fileName, myRecentFilesMenu);
myRecentFilesMenu->addAction(fileAction);

connect(fileAction, &QAction::triggered, [=]() {
connect(fileAction, &QAction::triggered, [=, this]() {
handleFileSelection(fileName);
});
}
Expand Down
2 changes: 1 addition & 1 deletion source/app/scorearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void ScoreArea::renderDocument(const Document &document)

myCaretPainter = new CaretPainter(
document.getCaret(), document.getViewOptions(), *myActivePalette);
myCaretPainter->subscribeToMovement([=]() {
myCaretPainter->subscribeToMovement([this]() {
adjustScroll();
});

Expand Down
6 changes: 3 additions & 3 deletions source/dialogs/bulkconverterdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ BulkConverterDialog::BulkConverterDialog(QWidget *parent,
auto flags = windowFlags();
setWindowFlags(flags | Qt::WindowStaysOnTopHint);

connect(ui->fileLocatorSource, &QAbstractButton::clicked, [=]() {
connect(ui->fileLocatorSource, &QAbstractButton::clicked, [this]() {
setPath(ui->sourcePathEdit);
});

connect(ui->fileLocatorDestination, &QAbstractButton::clicked, [=]() {
connect(ui->fileLocatorDestination, &QAbstractButton::clicked, [this]() {
setPath(ui->destinationPathEdit);
});

Expand All @@ -170,7 +170,7 @@ BulkConverterDialog::BulkConverterDialog(QWidget *parent,

convertButton()->setEnabled(false);
convertButton()->setText(tr("Convert"));
connect(convertButton(), &QAbstractButton::clicked, [=](){ convert(); });
connect(convertButton(), &QAbstractButton::clicked, [this](){ convert(); });
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}

Expand Down
2 changes: 1 addition & 1 deletion source/dialogs/infodialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ InfoDialog::InfoDialog(QWidget *parent) :

setInfo();

connect(ui->copyToClipboardButton, &QAbstractButton::clicked, [=]() {
connect(ui->copyToClipboardButton, &QAbstractButton::clicked, [this]() {
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(ui->appInfo->toPlainText());
});
Expand Down
4 changes: 2 additions & 2 deletions source/dialogs/keysignaturedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ KeySignatureDialog::KeySignatureDialog(QWidget *parent,
else
ui->minorKeyButton->setChecked(true);

connect(ui->majorKeyButton, &QAbstractButton::clicked, [=]() {
connect(ui->majorKeyButton, &QAbstractButton::clicked, [this]() {
populateKeyTypes(KeySignature::Major);
});
connect(ui->minorKeyButton, &QAbstractButton::clicked, [=]() {
connect(ui->minorKeyButton, &QAbstractButton::clicked, [this]() {
populateKeyTypes(KeySignature::Minor);
});

Expand Down
4 changes: 2 additions & 2 deletions source/dialogs/viewfilterdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ void ViewFilterDialog::update(const std::vector<std::string> &names,
ui->filterRuleLayout->addWidget(widget);

connect(widget, &FilterRuleWidget::changed,
[=](const FilterRule &rule) {
[=, this](const FilterRule &rule) {
myPresenter->editRule(i, rule);
});
connect(widget, &FilterRuleWidget::removeRequested, [=]() {
connect(widget, &FilterRuleWidget::removeRequested, [=, this]() {
myPresenter->removeRule(i);
});
}
Expand Down
2 changes: 1 addition & 1 deletion source/painters/caretpainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CaretPainter::CaretPainter(const Caret &caret, const ViewOptions &view_options,
myViewOptions(view_options),
myPalette(palette),
myCaretConnection(
caret.subscribeToChanges([=]() { onLocationChanged(); }))
caret.subscribeToChanges([this]() { onLocationChanged(); }))
{
}

Expand Down
12 changes: 6 additions & 6 deletions source/score/serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@ namespace detail
template <typename T>
JSONValue convert(const T &obj)
{
// Save ints / bools / etc or strings as-is.
// Save enums as strings. The exception is the FileVersion enum
// which is left as an integer.
if constexpr (std::is_enum_v<T> && !std::is_same_v<T, FileVersion>)
if constexpr (std::is_arithmetic_v<T> || std::is_same_v<T, FileVersion> ||
std::is_same_v<T, std::string>)
{
return Util::enumToString(obj);
return obj;
}
// Save ints / bools / etc or strings as-is.
else if constexpr (std::is_pod_v<T> ||
std::is_same_v<T, std::string>)
else if constexpr (std::is_enum_v<T>)
{
return obj;
return Util::enumToString(obj);
}
else // score objects.
{
Expand Down
2 changes: 1 addition & 1 deletion source/widgets/clickablelabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ClickableLabel::ClickableLabel(QWidget *parent)

void ClickableLabel::enterEvent(QEvent *)
{
setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
setFrameStyle(static_cast<int>(QFrame::StyledPanel) | static_cast<int>(QFrame::Raised));
setCursor(Qt::PointingHandCursor);
}

Expand Down
4 changes: 2 additions & 2 deletions source/widgets/instruments/instrumentpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ void InstrumentPanel::reset(const Score &score)
{
auto item = new InstrumentPanelItem(this, i, score.getInstruments()[i]);
connect(item, &InstrumentPanelItem::instrumentEdited,
[=](const Instrument &inst) { instrumentEdited(i, inst); });
[=, this](const Instrument &inst) { instrumentEdited(i, inst); });
connect(item, &InstrumentPanelItem::instrumentRemoved,
[=]() { instrumentRemoved(i); });
[=, this]() { instrumentRemoved(i); });

myLayout->addWidget(item);
}
Expand Down
2 changes: 1 addition & 1 deletion source/widgets/instruments/instrumentpanelitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ InstrumentPanelItem::InstrumentPanelItem(QWidget *parent, int instrumentIndex,
ui->instrumentNameLabel, &QWidget::hide);
connect(ui->instrumentNameLabel, &ClickableLabel::clicked,
ui->instrumentNameEdit, &QWidget::show);
connect(ui->instrumentNameLabel, &ClickableLabel::clicked, [=]()
connect(ui->instrumentNameLabel, &ClickableLabel::clicked, [this]()
{ ui->instrumentNameEdit->setFocus(); });

connect(ui->instrumentNameEdit, &QLineEdit::editingFinished, this,
Expand Down
4 changes: 2 additions & 2 deletions source/widgets/mixer/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ void Mixer::reset(const Score &score)
{
auto item = new MixerItem(this, i, score.getPlayers()[i], myDictionary);
connect(item, &MixerItem::playerEdited,
[=](const Player &player, bool undoable) {
[=, this](const Player &player, bool undoable) {
playerEdited(i, player, undoable);
});
connect(item, &MixerItem::playerRemoved, [=]() { playerRemoved(i); });
connect(item, &MixerItem::playerRemoved, [=, this]() { playerRemoved(i); });
myLayout->addWidget(item);
}
}
Expand Down
6 changes: 3 additions & 3 deletions source/widgets/mixer/mixeritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ MixerItem::MixerItem(QWidget *parent, int playerIndex, const Player &player,
&QWidget::hide);
connect(ui->playerNameLabel, &ClickableLabel::clicked, ui->playerNameEdit,
&QWidget::show);
connect(ui->playerNameLabel, &ClickableLabel::clicked, [=]() {
connect(ui->playerNameLabel, &ClickableLabel::clicked, [this]() {
ui->playerNameEdit->setFocus();
});

connect(ui->playerNameEdit, &QLineEdit::editingFinished, this,
&MixerItem::onPlayerNameEdited);

connect(ui->playerVolume, &QSlider::valueChanged, [=]() {
connect(ui->playerVolume, &QSlider::valueChanged, [this]() {
onEdited(false);
});
connect(ui->playerPan, &QDial::valueChanged, [=]() {
connect(ui->playerPan, &QDial::valueChanged, [this]() {
onEdited(false);
});

Expand Down
2 changes: 1 addition & 1 deletion source/widgets/playback/playbackwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ PlaybackWidget::setupZoomComboBox(double initial_zoom)
ui->zoomComboBox->setValidator(new PercentageValidator(ui->zoomComboBox));

connect(ui->zoomComboBox, &QComboBox::currentTextChanged,
[=](const QString &text) {
[this](const QString &text) {
// Trigger an update for the stylesheet.
ui->zoomComboBox->style()->unpolish(ui->zoomComboBox);
ui->zoomComboBox->style()->polish(ui->zoomComboBox);
Expand Down
4 changes: 4 additions & 0 deletions test/score/test_voiceutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
#include <score/voiceutils.h>
#include <score/voice.h>

#if defined(__GNUC__) && !defined(__clang__) // Skip for gcc 11 due to a possible compiler bug in C++20 mode
TEST_CASE("Score/VoiceUtils/GetDurationTime" * doctest::skip())
#else
TEST_CASE("Score/VoiceUtils/GetDurationTime")
#endif
{
Voice voice;
voice.insertPosition(Position(7));
Expand Down

0 comments on commit eaaa4b4

Please sign in to comment.