diff options
author | Arno <arno@disconnect.de> | 2020-07-29 16:25:31 +0200 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2020-07-29 16:26:49 +0200 |
commit | 37207b5a188ba7b49165eacb82abc1e19434dcf2 (patch) | |
tree | aaaf63ebc4e8403e7acb41f1ed4be47cb6aa00c8 /searchdialog.cpp | |
parent | ae18a15210ce28b0aee9f0a894b29a8b74103817 (diff) | |
download | SheMov-37207b5a188ba7b49165eacb82abc1e19434dcf2.tar.gz SheMov-37207b5a188ba7b49165eacb82abc1e19434dcf2.tar.bz2 SheMov-37207b5a188ba7b49165eacb82abc1e19434dcf2.zip |
Implement delete actor from search dialog
The context menu item is only enabled if the actor has no children, ie.
no genres associated.
Since naming is hard, also rename some slots to more descriptive names.
Diffstat (limited to 'searchdialog.cpp')
-rw-r--r-- | searchdialog.cpp | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/searchdialog.cpp b/searchdialog.cpp index b06e487..086be9f 100644 --- a/searchdialog.cpp +++ b/searchdialog.cpp @@ -170,13 +170,19 @@ ActorsAndMore::ActorsAndMore(QWidget *parent, Qt::WindowFlags flags) : QWidget(p resultProxy->setSourceModel(mResultModel); mResultView = new SmView; mResultView->setModel(resultProxy); - connect(mResultView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ActorsAndMore::getData); + connect(mResultView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ActorsAndMore::fetchData); QAction *resultCollapseAllA = new QAction(Helper::icon(Qt::transparent, qApp->palette().color(QPalette::Text), QChar(0x2191), true, false), tr("Collapse all"), this); connect(resultCollapseAllA, &QAction::triggered, this, &ActorsAndMore::collapseAllResult); mResultView->addAction(resultCollapseAllA); QAction *resultExpandAllA = new QAction(Helper::icon(Qt::transparent, qApp->palette().color(QPalette::Text), QChar(0x2193), true, false), tr("Expand all"), this); connect(resultExpandAllA, &QAction::triggered, this, &ActorsAndMore::expandAllResult); mResultView->addAction(resultExpandAllA); + mResultView->addAction(Helper::createSeparator(this)); + mDeleteActorA = new QAction(Helper::icon(Qt::transparent, qApp->palette().color(QPalette::Text), QChar(0x2718), true, false), tr("Delete Actor..."), this); + mDeleteActorA->setEnabled(false); + connect(mDeleteActorA, &QAction::triggered, this, &ActorsAndMore::deleteActor); + connect(mResultView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ActorsAndMore::doResultActions); + mResultView->addAction(mDeleteActorA); QAction *resultRefreshA = new QAction(Helper::icon(Qt::transparent, qApp->palette().color(QPalette::Text), QChar(0x21bb), true, false), tr("Refresh"), this); connect(resultRefreshA, &QAction::triggered, this, &ActorsAndMore::refreshActors); mResultView->addAction(Helper::createSeparator(this)); @@ -200,7 +206,7 @@ ActorsAndMore::ActorsAndMore(QWidget *parent, Qt::WindowFlags flags) : QWidget(p mDeleteSeriesA = new QAction(Helper::icon(Qt::transparent, qApp->palette().color(QPalette::Text), QChar(0x2718), true, false), tr("Delete Series..."), this); mDeleteSeriesA->setEnabled(false); connect(mDeleteSeriesA, &QAction::triggered, this, &ActorsAndMore::deleteSeries); - connect(mDataView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ActorsAndMore::doData); + connect(mDataView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ActorsAndMore::doDataActions); mDataView->addAction(Helper::createSeparator(this)); mDataView->addAction(mDeleteSeriesA); resultHBL->addWidget(mResultView); @@ -308,7 +314,7 @@ void ActorsAndMore::getGenresForActor(QStandardItem *actorItem){ } } -void ActorsAndMore::getData(const QModelIndex &cur, const QModelIndex &prev){ +void ActorsAndMore::fetchData(const QModelIndex &cur, const QModelIndex &prev){ Q_UNUSED(prev) int searchType = mTypeSel->currentData().toInt(); if(searchType == Actor){ @@ -318,7 +324,7 @@ void ActorsAndMore::getData(const QModelIndex &cur, const QModelIndex &prev){ } } -void ActorsAndMore::doData(const QModelIndex &cur, const QModelIndex &prev){ +void ActorsAndMore::doDataActions(const QModelIndex &cur, const QModelIndex &prev){ Q_UNUSED(prev) int searchType = mTypeSel->currentData().toInt(); if(searchType == Actor){ @@ -334,6 +340,20 @@ void ActorsAndMore::doData(const QModelIndex &cur, const QModelIndex &prev){ mDeleteSeriesA->setEnabled(false); } +void ActorsAndMore::doResultActions(const QModelIndex &cur, const QModelIndex &prev){ + Q_UNUSED(prev) + int searchType = mTypeSel->currentData().toInt(); + if(searchType == Actor){ + if(cur.parent() == QModelIndex()){ + if(!mResultView->model()->hasChildren(cur)){ + mDeleteActorA->setEnabled(true); + return; + } + } + } + mDeleteActorA->setEnabled(false); +} + void ActorsAndMore::dataDoubleClicked(const QModelIndex &index){ QModelIndex cur = index; while(cur.parent().isValid()){ @@ -363,6 +383,26 @@ void ActorsAndMore::deleteSeries(){ } } +void ActorsAndMore::deleteActor(){ + QModelIndex cur = mResultView->selectionModel()->currentIndex(); + int actorId = cur.data(IdRole).toInt(); + QString question = QString("Delete Actor %1 (ID: %2)?").arg(cur.data().toString()).arg(actorId); + int res = QMessageBox::question(this, "Delete", question); + if(res == QMessageBox::Yes){ + QSqlDatabase db = QSqlDatabase::database("treedb"); + QSqlQuery deleteQ(db); + deleteQ.prepare("DELETE FROM actors WHERE iactors_id = :id"); + deleteQ.bindValue(":id", actorId); + if(deleteQ.exec()){ + QModelIndex newIdx = cur.siblingAtRow(cur.row() - 1); + if(newIdx.isValid()){ + mResultView->selectionModel()->select(newIdx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current | QItemSelectionModel::Rows); + refreshActors(); + } + } + } +} + void ActorsAndMore::refreshActors(){ int searchType = mTypeSel->currentData().toInt(); if(searchType == Actor){ |