summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--searchdialog.cpp48
-rw-r--r--searchdialog.h7
2 files changed, 49 insertions, 6 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){
diff --git a/searchdialog.h b/searchdialog.h
index 1cd9fdd..d469c28 100644
--- a/searchdialog.h
+++ b/searchdialog.h
@@ -57,14 +57,16 @@ class ActorsAndMore : public QWidget {
public slots:
void doSearch();
- void getData(const QModelIndex &cur, const QModelIndex &prev);
- void doData(const QModelIndex &cur, const QModelIndex &prev);
+ void fetchData(const QModelIndex &cur, const QModelIndex &prev);
+ void doDataActions(const QModelIndex &cur, const QModelIndex &prev);
+ void doResultActions(const QModelIndex &cur, const QModelIndex &prev);
void dataDoubleClicked(const QModelIndex &index);
void collapseAllResult() { mResultView->collapseAll(); }
void expandAllResult() { mResultView->expandAll(); }
void collapseAllData() { mDataView->collapseAll(); }
void expandAllData() { mDataView->expandAll(); }
void deleteSeries();
+ void deleteActor();
void refreshActors();
private:
@@ -79,6 +81,7 @@ class ActorsAndMore : public QWidget {
QStandardItemModel *mDataModel;
SmView *mResultView;
SmView *mDataView;
+ QAction *mDeleteActorA;
QAction *mDeleteSeriesA;
};