From 28e92190e4494a1021419352534e1727b78ddf3e Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Wed, 23 Oct 2024 23:17:02 +0800 Subject: [PATCH] fix: should auto load playlist when using file>open Also fixed a bunch of clang-tidy and clazy issues --- widget/instrumentsmodel.cpp | 6 +++--- widget/main.cpp | 8 ++++---- widget/mainwindow.cpp | 13 ++++++------- widget/mainwindow.h | 6 +++--- widget/trackerwidget.cpp | 6 ++---- widget/trackerwidget.h | 4 ++-- 6 files changed, 20 insertions(+), 23 deletions(-) diff --git a/widget/instrumentsmodel.cpp b/widget/instrumentsmodel.cpp index 2070467..2735cc2 100644 --- a/widget/instrumentsmodel.cpp +++ b/widget/instrumentsmodel.cpp @@ -3,8 +3,8 @@ #include "player.h" InstrumentsModel::InstrumentsModel(Player * player, QObject *parent) - : m_player(player) - , QStringListModel(parent) + : QStringListModel(parent) + , m_player(player) { } @@ -39,7 +39,7 @@ bool InstrumentsModel::setData(const QModelIndex &index, const QVariant &value, QVariant InstrumentsModel::data(const QModelIndex &index, int role) const { - if (!index.isValid()) return QVariant(); + if (!index.isValid()) return {}; if (role == Qt::CheckStateRole) return m_mutedInstruments.contains(index) ? Qt::Unchecked : Qt::Checked; diff --git a/widget/main.cpp b/widget/main.cpp index a06557a..932cc05 100644 --- a/widget/main.cpp +++ b/widget/main.cpp @@ -12,7 +12,7 @@ int main(int argc, char *argv[]) QTranslator translator; if (translator.load(QLocale(), QLatin1String("pineapple-tracker-player"), QLatin1String("_"), QLatin1String(":/i18n"))) { - app.installTranslator(&translator); + QApplication::installTranslator(&translator); } QCommandLineParser parser; @@ -20,13 +20,13 @@ int main(int argc, char *argv[]) parser.addHelpOption(); parser.process(app); - QStringList urlStrList = parser.positionalArguments(); - QList urlsToLoad = Util::convertToUrlList(urlStrList); + const QStringList urlStrList = parser.positionalArguments(); + const QList urlsToLoad = Util::convertToUrlList(urlStrList); MainWindow w; w.show(); w.playFiles(urlsToLoad); - return app.exec(); + return QApplication::exec(); } diff --git a/widget/mainwindow.cpp b/widget/mainwindow.cpp index 30fd14e..aca61c9 100644 --- a/widget/mainwindow.cpp +++ b/widget/mainwindow.cpp @@ -26,14 +26,14 @@ MainWindow::MainWindow(QWidget *parent) , m_player(new Player(this)) , m_playlistManager(new PlaylistManager(this)) , m_instrumentsModel(new InstrumentsModel(m_player, this)) - , m_playlistFilderModel(new QSortFilterProxyModel(this)) + , m_playlistFilterModel(new QSortFilterProxyModel(this)) { ui->setupUi(this); ui->plainTextEdit->setFont(Util::defaultMonoFont()); ui->instrumentsListView->setFont(Util::defaultMonoFont()); ui->instrumentsListView->setModel(m_instrumentsModel); - m_playlistFilderModel->setSourceModel(m_playlistManager->model()); - ui->playlistView->setModel(m_playlistFilderModel); + m_playlistFilterModel->setSourceModel(m_playlistManager->model()); + ui->playlistView->setModel(m_playlistFilterModel); setWindowIcon(QIcon(":/icons/dist/pineapple-tracker-player.svg")); m_playlistManager->setAutoLoadFilterSuffixes({"*.xm", "*.it", "*.mod", "*.s3m", "*.mptm"}); @@ -128,8 +128,7 @@ MainWindow::MainWindow(QWidget *parent) this, "Select module file", {}, "Module Files (*.xm *.it *.mod *.s3m *.mptm)"); if (url.isValid()) { - m_player->load(url); - m_player->play(); + playFiles({url}); } }); @@ -205,7 +204,7 @@ void MainWindow::on_playlistBtn_clicked() void MainWindow::on_playlistView_activated(const QModelIndex &index) { - QModelIndex sourceIndex(m_playlistFilderModel->mapToSource(index)); + QModelIndex sourceIndex(m_playlistFilterModel->mapToSource(index)); m_playlistManager->setCurrentIndex(sourceIndex); playFiles({m_playlistManager->urlByIndex(sourceIndex)}); } @@ -242,7 +241,7 @@ void MainWindow::on_actionAbout_triggered() void MainWindow::on_filterEdit_textChanged(const QString &arg1) { - m_playlistFilderModel->setFilterFixedString(arg1); + m_playlistFilterModel->setFilterFixedString(arg1); } diff --git a/widget/mainwindow.h b/widget/mainwindow.h index 265e597..0b4128a 100644 --- a/widget/mainwindow.h +++ b/widget/mainwindow.h @@ -28,8 +28,8 @@ class MainWindow : public QMainWindow Q_PROPERTY(RepeatMode repeatMode MEMBER m_repeatMode NOTIFY repeatModeChanged) - MainWindow(QWidget *parent = nullptr); - ~MainWindow(); + explicit MainWindow(QWidget *parent = nullptr); + ~MainWindow() override; void playFiles(const QList &urls); @@ -56,6 +56,6 @@ private slots: Player * m_player = nullptr; PlaylistManager * m_playlistManager = nullptr; InstrumentsModel * m_instrumentsModel = nullptr; - QSortFilterProxyModel * m_playlistFilderModel = nullptr; + QSortFilterProxyModel * m_playlistFilterModel = nullptr; RepeatMode m_repeatMode = Repeat; }; diff --git a/widget/trackerwidget.cpp b/widget/trackerwidget.cpp index bbdff50..ac5ba7f 100644 --- a/widget/trackerwidget.cpp +++ b/widget/trackerwidget.cpp @@ -13,9 +13,7 @@ TrackerWidget::TrackerWidget(QWidget *parent) } TrackerWidget::~TrackerWidget() -{ - -} += default; void TrackerWidget::paintEvent(QPaintEvent *event) { @@ -34,7 +32,7 @@ void TrackerWidget::paintEvent(QPaintEvent *event) const int offset = (i - curRow) * fontHeight; QStringList curRow(patternContent().at(i)); std::transform(curRow.cbegin(), curRow.cend(), curRow.begin(), - [](const QString from) -> const QString { return from.first(3); }); + [](const QString& from) -> QString { return from.first(3); }); painter.drawText(0, centerY + offset, width(), fontHeight, Qt::AlignCenter, curRow.join(QStringLiteral(" "))); } diff --git a/widget/trackerwidget.h b/widget/trackerwidget.h index 59d1eb9..79e8546 100644 --- a/widget/trackerwidget.h +++ b/widget/trackerwidget.h @@ -14,9 +14,9 @@ class TrackerWidget : public QWidget public: explicit TrackerWidget(QWidget *parent = nullptr); - ~TrackerWidget(); + ~TrackerWidget() override; - QVector patternContent() { return m_patternContent.value(); } + QVector patternContent() const { return m_patternContent.value(); } void setPatternContent(const QVector & content) { m_patternContent = content; } QBindable> bindablePatternContent() { return &m_patternContent; }