From f48e27a63c59840979dd848893ffba3faefdfdde Mon Sep 17 00:00:00 2001 From: Arno Date: Wed, 4 Apr 2018 18:52:09 +0200 Subject: MoviePropertiesDialog: implement add actors and genres Only adds items to the view, doesn't do any changes to the database yet. Had to implement a custom InputDialog, because the standard InputDialog doesn't have a setter for the completer. --- moviepropertiesdialog.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'moviepropertiesdialog.cpp') diff --git a/moviepropertiesdialog.cpp b/moviepropertiesdialog.cpp index 64a21ac..92b8a0c 100644 --- a/moviepropertiesdialog.cpp +++ b/moviepropertiesdialog.cpp @@ -6,7 +6,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -14,8 +16,11 @@ #include "moviepropertiesdialog.h" #include "smview.h" +#include "sminputdialog.h" MoviePropertiesDialog::MoviePropertiesDialog(QWidget *parent) : QDialog(parent){ + mActorDlg = new SmInputDialog(tr("Actor"), this); + mGenreDlg = new SmInputDialog(tr("Genre"), this); setupDialog(); } @@ -64,6 +69,10 @@ void MoviePropertiesDialog::setupDialog(){ mActorV->setAlternatingRowColors(true); mActorM = new QStandardItemModel; mActorV->setModel(mActorM); + QAction *addActorA = new QAction(QIcon(":/spreadingpants.png"), tr("Add actor..."), this); + connect(addActorA, &QAction::triggered, [=] { addItem(mActorDlg, mActorM, QIcon(":/diaper.png")); }); + QAction *removeActorA = new QAction(QIcon(":/delete.png"), tr("Remove actor"), this); + mActorV->addActions(QList() << addActorA << removeActorA); QGroupBox *actorsGB = new QGroupBox(tr("Actors")); QHBoxLayout *actorsGBL = new QHBoxLayout; actorsGBL->addWidget(mActorV); @@ -73,6 +82,10 @@ void MoviePropertiesDialog::setupDialog(){ mGenreV->setAlternatingRowColors(true); mGenreM = new QStandardItemModel; mGenreV->setModel(mGenreM); + QAction *addGenreA = new QAction(QIcon(":/spreadingpants.png"), tr("Add genre..."), this); + connect(addGenreA, &QAction::triggered, [=] { addItem(mGenreDlg, mGenreM, QIcon(":/dick_in_cage.png")); }); + QAction *removeGenreA = new QAction(QIcon(":/delete.png"), tr("Remove genre"), this); + mGenreV->addActions(QList() << addGenreA << removeGenreA); QGroupBox *genresGB = new QGroupBox(tr("Genres")); QHBoxLayout *genresGBL = new QHBoxLayout; genresGBL->addWidget(mGenreV); @@ -147,5 +160,48 @@ void MoviePropertiesDialog::init(int seriesPartsId){ i->setData(genresQ.value(1), GenreIdRole); genresRootItem->appendRow(i); } + QStringList seriesNames; + QSqlQuery allSeriesNamesQ("SELECT tseries_name FROM series", db); + while(allSeriesNamesQ.next()){ + seriesNames << allSeriesNamesQ.value(0).toString(); + } + QCompleter *snCompleter = new QCompleter(seriesNames); + mSeriesNameLE->setCompleter(snCompleter); + QStringList actorNames; + QSqlQuery allActorsQ("SELECT tactorname FROM actors", db); + while(allActorsQ.next()){ + actorNames << allActorsQ.value(0).toString(); + } + QCompleter *actorCompleter = new QCompleter(actorNames, mActorDlg); + mActorDlg->setCompleter(actorCompleter); + QStringList genreNames; + QSqlQuery allGenresQ("SELECT tgenrename FROM genres", db); + while(allGenresQ.next()){ + genreNames << allGenresQ.value(0).toString(); + } + QCompleter *genreCompleter = new QCompleter(genreNames, mGenreDlg); + mGenreDlg->setCompleter(genreCompleter); +} +void MoviePropertiesDialog::addItem(SmInputDialog *dlg, QStandardItemModel *model, QIcon icon){ + int retval = dlg->exec(); + if(retval == QDialog::Accepted){ + QString itemName = dlg->text().toLower(); + int idx = 0; + while(idx != model->rowCount()){ + QStandardItem *curItem = model->item(idx, 0); + if(curItem->text() == itemName){ + return; + } + if(curItem->text() > itemName){ + break; + } + ++idx; + } + QStandardItem *newItem = new QStandardItem; + newItem->setEditable(false); + newItem->setIcon(icon); + newItem->setText(itemName); + model->insertRow(idx, newItem); + } } -- cgit v1.2.3-70-g09d2