From 5cc531f046c635e9575d253a81d96caef5ce3dc1 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 2 Mar 2023 05:56:21 -0600 Subject: [PATCH] adding a way to get modelIndex from songProxyModel --- src/cpp/songsqlmodel.cpp | 12 ++++++++++++ src/cpp/songsqlmodel.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/cpp/songsqlmodel.cpp b/src/cpp/songsqlmodel.cpp index 6ef0624..9c19628 100644 --- a/src/cpp/songsqlmodel.cpp +++ b/src/cpp/songsqlmodel.cpp @@ -710,6 +710,13 @@ void SongSqlModel::updateFontSize(const int &row, const int &fontSize) { submitAll(); emit fontSizeChanged(); } + +QModelIndex SongSqlModel::idx(int row) { + QModelIndex idx = index(row, 0); + // qDebug() << idx; + return idx; +} + // SongProxyModel SongProxyModel::SongProxyModel(QObject *parent) @@ -734,6 +741,11 @@ QModelIndex SongProxyModel::idx(int row) { return idx; } +QModelIndex SongProxyModel::modelIndex(int row) { + QModelIndex idx = m_songModel->idx(mapToSource(index(row, 0)).row()); + return idx; +} + QStringList SongProxyModel::getLyricList(const int &row) { QStringList lyrics = m_songModel->getLyricList(mapToSource(index(row, 0)).row()); return lyrics; diff --git a/src/cpp/songsqlmodel.h b/src/cpp/songsqlmodel.h index d33b5da..288bee4 100644 --- a/src/cpp/songsqlmodel.h +++ b/src/cpp/songsqlmodel.h @@ -70,6 +70,7 @@ public: const QString &horizontalTextAlignment); Q_INVOKABLE void updateFont(const int &row, const QString &font); Q_INVOKABLE void updateFontSize(const int &row, const int &fontSize); + Q_INVOKABLE QModelIndex idx(int row); Q_INVOKABLE void newSong(); Q_INVOKABLE void deleteSong(const int &row); @@ -121,6 +122,7 @@ public: SongSqlModel *songModel(); Q_INVOKABLE QModelIndex idx(int row); + Q_INVOKABLE QModelIndex modelIndex(int row); // Q_INVOKABLE bool selected(const int &row); // QVariant data(const QModelIndex &index, int role) const override;