Skip to content

Commit

Permalink
[MovieListDialog] Remove singleton for dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
bugwelle committed May 13, 2020
1 parent 1e1f7c2 commit 1f43253
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 71 deletions.
1 change: 0 additions & 1 deletion src/ui/main/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
17 changes: 0 additions & 17 deletions src/ui/movie_sets/MovieListDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/ui/movie_sets/MovieListDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class MovieListDialog : public QDialog
explicit MovieListDialog(QWidget* parent = nullptr);
~MovieListDialog() override;
QVector<Movie*> selectedMovies();
static MovieListDialog* instance(QWidget* parent = nullptr);

public slots:
int exec() override;
Expand Down
49 changes: 26 additions & 23 deletions src/ui/movie_sets/SetsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Movie*> 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<Movie*> 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);
}

/**
Expand Down
24 changes: 12 additions & 12 deletions src/ui/movies/CertificationWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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<Movie*> 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<Movie*> movies = listDialog->selectedMovies();
listDialog->deleteLater();

if (exitCode != QDialog::Accepted || movies.isEmpty()) {
return;
}

for (Movie* movie : movies) {
movie->setCertification(cert);
}
onCertificationSelected();
}

/**
Expand Down
32 changes: 15 additions & 17 deletions src/ui/movies/GenreWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Movie*> 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<Movie*> 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();
}

/**
Expand Down

0 comments on commit 1f43253

Please sign in to comment.