From 1f43253d4a6e3becc8130524016cb613c3c66135 Mon Sep 17 00:00:00 2001 From: Andre Meyering Date: Wed, 13 May 2020 15:55:19 +0200 Subject: [PATCH] [MovieListDialog] Remove singleton for dialog --- src/ui/main/MainWindow.cpp | 1 - src/ui/movie_sets/MovieListDialog.cpp | 17 ---------- src/ui/movie_sets/MovieListDialog.h | 1 - src/ui/movie_sets/SetsWidget.cpp | 49 ++++++++++++++------------- src/ui/movies/CertificationWidget.cpp | 24 ++++++------- src/ui/movies/GenreWidget.cpp | 32 ++++++++--------- 6 files changed, 53 insertions(+), 71 deletions(-) diff --git a/src/ui/main/MainWindow.cpp b/src/ui/main/MainWindow.cpp index 4346d0ce84..884ab195c5 100644 --- a/src/ui/main/MainWindow.cpp +++ b/src/ui/main/MainWindow.cpp @@ -216,7 +216,6 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi TvShowSearch::instance(this); ImageDialog::instance(this); - MovieListDialog::instance(this); NameFormatter::instance(this); Notificator::instance(nullptr, ui->centralWidget); diff --git a/src/ui/movie_sets/MovieListDialog.cpp b/src/ui/movie_sets/MovieListDialog.cpp index 9f9473e768..dba5ea3d68 100644 --- a/src/ui/movie_sets/MovieListDialog.cpp +++ b/src/ui/movie_sets/MovieListDialog.cpp @@ -20,28 +20,11 @@ MovieListDialog::MovieListDialog(QWidget* parent) : QDialog(parent), ui(new Ui:: connect(ui->filter, &QLineEdit::textEdited, this, &MovieListDialog::onFilterEdited); } -/** - * @brief MovieListDialog::~MovieListDialog - */ MovieListDialog::~MovieListDialog() { delete ui; } -/** - * @brief Returns an instance of MovieListDialog - * @param parent Parent widget (used the first time for constructing) - * @return Instance of MovieListDialog - */ -MovieListDialog* MovieListDialog::instance(QWidget* parent) -{ - static MovieListDialog* m_instance = nullptr; - if (m_instance == nullptr) { - m_instance = new MovieListDialog(parent); - } - return m_instance; -} - /** * @brief Executes the dialog * @return Result of QDialog::exec diff --git a/src/ui/movie_sets/MovieListDialog.h b/src/ui/movie_sets/MovieListDialog.h index 7d9964ade8..547eaa4542 100644 --- a/src/ui/movie_sets/MovieListDialog.h +++ b/src/ui/movie_sets/MovieListDialog.h @@ -21,7 +21,6 @@ class MovieListDialog : public QDialog explicit MovieListDialog(QWidget* parent = nullptr); ~MovieListDialog() override; QVector selectedMovies(); - static MovieListDialog* instance(QWidget* parent = nullptr); public slots: int exec() override; diff --git a/src/ui/movie_sets/SetsWidget.cpp b/src/ui/movie_sets/SetsWidget.cpp index b206f054f5..fed6f1586a 100644 --- a/src/ui/movie_sets/SetsWidget.cpp +++ b/src/ui/movie_sets/SetsWidget.cpp @@ -299,35 +299,38 @@ void SetsWidget::onSortTitleChanged(QTableWidgetItem* item) void SetsWidget::onAddMovie() { if (ui->sets->currentRow() < 0 || ui->sets->currentRow() >= ui->sets->rowCount()) { - qDebug() << "Invalid current row"; + qDebug() << "[SetsWidget] Invalid current row"; return; } - if (MovieListDialog::instance()->exec() == QDialog::Accepted) { - QVector movies = MovieListDialog::instance()->selectedMovies(); - if (movies.isEmpty()) { - return; - } - int row = ui->sets->currentRow(); - if (row < 0 || row >= ui->sets->rowCount()) { - return; - } + auto* listDialog = new MovieListDialog(this); + QVector movies = listDialog->selectedMovies(); + const int exitCode = listDialog->exec(); + listDialog->deleteLater(); - QString setName = ui->sets->item(ui->sets->currentRow(), 0)->text(); - for (Movie* movie : movies) { - if (movie->set().name == setName) { - continue; - } - MovieSet set = movie->set(); - set.name = setName; - movie->setSet(set); - m_sets[setName].append(movie); - if (!m_moviesToSave[setName].contains(movie)) { - m_moviesToSave[setName].append(movie); - } + if (exitCode != QDialog::Accepted || movies.isEmpty()) { + return; + } + + const int row = ui->sets->currentRow(); + if (row < 0 || row >= ui->sets->rowCount()) { + return; + } + + QString setName = ui->sets->item(ui->sets->currentRow(), 0)->text(); + for (Movie* movie : movies) { + if (movie->set().name == setName) { + continue; + } + MovieSet set = movie->set(); + set.name = setName; + movie->setSet(set); + m_sets[setName].append(movie); + if (!m_moviesToSave[setName].contains(movie)) { + m_moviesToSave[setName].append(movie); } - loadSet(setName); } + loadSet(setName); } /** diff --git a/src/ui/movies/CertificationWidget.cpp b/src/ui/movies/CertificationWidget.cpp index 3f38b06082..7af467a73c 100644 --- a/src/ui/movies/CertificationWidget.cpp +++ b/src/ui/movies/CertificationWidget.cpp @@ -253,9 +253,6 @@ void CertificationWidget::removeMovie() ui->movies->removeRow(ui->movies->currentRow()); } -/** - * @brief Add a movie to the current certification - */ void CertificationWidget::addMovie() { if (ui->certifications->currentRow() < 0 || ui->certifications->currentRow() >= ui->certifications->rowCount()) { @@ -265,16 +262,19 @@ void CertificationWidget::addMovie() const auto cert = Certification(ui->certifications->item(ui->certifications->currentRow(), 0)->text()); - if (MovieListDialog::instance()->execWithoutCertification(cert) == QDialog::Accepted) { - QVector movies = MovieListDialog::instance()->selectedMovies(); - if (movies.isEmpty()) { - return; - } - for (Movie* movie : movies) { - movie->setCertification(cert); - } - onCertificationSelected(); + auto* listDialog = new MovieListDialog(this); + const int exitCode = listDialog->execWithoutCertification(cert); + QVector movies = listDialog->selectedMovies(); + listDialog->deleteLater(); + + if (exitCode != QDialog::Accepted || movies.isEmpty()) { + return; + } + + for (Movie* movie : movies) { + movie->setCertification(cert); } + onCertificationSelected(); } /** diff --git a/src/ui/movies/GenreWidget.cpp b/src/ui/movies/GenreWidget.cpp index 16d98726d6..90050afd50 100644 --- a/src/ui/movies/GenreWidget.cpp +++ b/src/ui/movies/GenreWidget.cpp @@ -252,32 +252,30 @@ void GenreWidget::removeMovie() ui->movies->removeRow(ui->movies->currentRow()); } -/** - * @brief Add a movie to the current genre - */ void GenreWidget::addMovie() { if (ui->genres->currentRow() < 0 || ui->genres->currentRow() >= ui->genres->rowCount()) { - qWarning() << "Invalid genre row" << ui->genres->currentRow(); + qWarning() << "[GenreWidget] Invalid genre row" << ui->genres->currentRow(); return; } - if (MovieListDialog::instance()->execWithoutGenre(ui->genres->item(ui->genres->currentRow(), 0)->text()) - == QDialog::Accepted) { - QVector movies = MovieListDialog::instance()->selectedMovies(); - if (movies.isEmpty()) { - return; - } + auto* listDialog = new MovieListDialog(this); + const int exitCode = listDialog->execWithoutGenre(ui->genres->item(ui->genres->currentRow(), 0)->text()); + QVector movies = listDialog->selectedMovies(); + listDialog->deleteLater(); - QString genreName = ui->genres->item(ui->genres->currentRow(), 0)->text(); - for (Movie* movie : movies) { - if (movie->genres().contains(genreName)) { - continue; - } - movie->addGenre(genreName); + if (exitCode != QDialog::Accepted || movies.isEmpty()) { + return; + } + + QString genreName = ui->genres->item(ui->genres->currentRow(), 0)->text(); + for (Movie* movie : movies) { + if (movie->genres().contains(genreName)) { + continue; } - onGenreSelected(); + movie->addGenre(genreName); } + onGenreSelected(); } /**