using song_model now
This commit is contained in:
parent
68b30877ed
commit
184ad4fe57
4 changed files with 76 additions and 19 deletions
|
@ -722,7 +722,8 @@ QModelIndex SongSqlModel::idx(int row) {
|
|||
SongProxyModel::SongProxyModel(QObject *parent)
|
||||
:QSortFilterProxyModel(parent)
|
||||
{
|
||||
m_songModel = new SongSqlModel;
|
||||
m_songModel = new SongModel;
|
||||
m_songModel->setup();
|
||||
// m_selectionModel = new QItemSelectionModel;
|
||||
// m_selectionModel->setModel(this);
|
||||
setSourceModel(m_songModel);
|
||||
|
@ -731,7 +732,7 @@ SongProxyModel::SongProxyModel(QObject *parent)
|
|||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
SongSqlModel *SongProxyModel::songModel() {
|
||||
SongModel *SongProxyModel::songModel() {
|
||||
return m_songModel;
|
||||
}
|
||||
|
||||
|
@ -742,7 +743,7 @@ QModelIndex SongProxyModel::idx(int row) {
|
|||
}
|
||||
|
||||
QModelIndex SongProxyModel::modelIndex(int row) {
|
||||
QModelIndex idx = m_songModel->idx(mapToSource(index(row, 0)).row());
|
||||
QModelIndex idx = m_songModel->index(mapToSource(index(row, 0)).row());
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
@ -752,21 +753,21 @@ QStringList SongProxyModel::getLyricList(const int &row) {
|
|||
}
|
||||
|
||||
QVariantMap SongProxyModel::getSong(const int &row) {
|
||||
QVariantMap song = m_songModel->getSong(mapToSource(index(row, 0)).row());
|
||||
QVariantMap song = m_songModel->getItem(mapToSource(index(row, 0)).row());
|
||||
return song;
|
||||
}
|
||||
|
||||
void SongProxyModel::deleteSong(const int &row) {
|
||||
auto model = qobject_cast<SongSqlModel *>(sourceModel());
|
||||
model->deleteSong(row);
|
||||
auto model = qobject_cast<SongModel *>(sourceModel());
|
||||
model->removeItem(row);
|
||||
}
|
||||
|
||||
void SongProxyModel::deleteSongs(const QVector<int> &rows) {
|
||||
auto model = qobject_cast<SongSqlModel *>(sourceModel());
|
||||
auto model = qobject_cast<SongModel *>(sourceModel());
|
||||
qDebug() << "DELETING!!!!!!!!!!!!!!!!!!!!!!!" << rows;
|
||||
for (int i = rows.size() - 1; i >= 0; i--) {
|
||||
qDebug() << "deleting" << rows.at(i);
|
||||
model->deleteSong(rows.at(i));
|
||||
model->removeItem(rows.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <qobjectdefs.h>
|
||||
#include <qqml.h>
|
||||
#include <qvariant.h>
|
||||
#include "cxx-qt-gen/song_model.cxxqt.h"
|
||||
|
||||
class SongSqlModel : public QSqlTableModel
|
||||
{
|
||||
|
@ -113,14 +114,14 @@ private:
|
|||
class SongProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(SongSqlModel *songModel READ songModel)
|
||||
Q_PROPERTY(SongModel *songModel READ songModel)
|
||||
// Q_PROPERTY(bool hasSelection READ hasSelection NOTIFY selectedChanged)
|
||||
|
||||
public:
|
||||
explicit SongProxyModel(QObject *parent = nullptr);
|
||||
~SongProxyModel() = default;
|
||||
|
||||
SongSqlModel *songModel();
|
||||
SongModel *songModel();
|
||||
Q_INVOKABLE QModelIndex idx(int row);
|
||||
Q_INVOKABLE QModelIndex modelIndex(int row);
|
||||
// Q_INVOKABLE bool selected(const int &row);
|
||||
|
@ -142,7 +143,7 @@ signals:
|
|||
// Q_INVOKABLE void selectedChanged(bool selected);
|
||||
|
||||
private:
|
||||
SongSqlModel *m_songModel;
|
||||
SongModel *m_songModel;
|
||||
// QItemSelectionModel *m_selectionModel;
|
||||
// bool m_selected;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue