From 9aa9b29c6b028e677d8fc9aec952951e41e31842 Mon Sep 17 00:00:00 2001 From: birkeh Date: Thu, 19 Oct 2017 19:37:15 +0200 Subject: [PATCH] . --- cmainwindow.cpp | 71 +++++++++++++++++++++++++++----------- cmainwindow.ui | 2 +- cmoviesearch.cpp | 2 +- cmovieviewitemdelegate.cpp | 39 +++++++++++++-------- 4 files changed, 76 insertions(+), 38 deletions(-) diff --git a/cmainwindow.cpp b/cmainwindow.cpp index ccc7597..a8ed8b0 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -39,6 +39,34 @@ #include +static bool serieSort(cSerie* s1, cSerie* s2) +{ + QString str1 = s1->seriesName(); + QString str2 = s2->seriesName(); + return(str1 < str2); +} + +static bool movieSort(cMovie* s1, cMovie* s2) +{ + QString collection1 = s1->belongsToCollection(); + QString collection2 = s2->belongsToCollection(); + + QString title1 = s1->movieTitle(); + QString title2 = s2->movieTitle(); + + if(collection1.isEmpty() && collection2.isEmpty()) + return(title1 < title2); + + if(!collection1.isEmpty() && !collection2.isEmpty()) + { + if(collection1 == collection2) + return(title1 < title2); + return(collection1 < collection2); + } + + return(title1 < title2); +} + cMainWindow::cMainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::cMainWindow), @@ -317,7 +345,7 @@ void cMainWindow::loadMoviesDB() QSqlQuery query; qint32 iMovieID; - if(query.exec("SELECT movieID, movieTitle, originalTitle, backdropPath, posterPath, overview, releaseDate, genre, imdbid, originalLanguage, popularity, productionCompanies, productionCountries, voteAverage, voteCount, adult, belongsToCollection, budget, homepage, revenue, runtime, spokenLanguages, status, tagline, video, `cast`, crew, state FROM movie ORDER BY movieTitle, releaseDate;")) + if(query.exec("SELECT movieID, movieTitle, originalTitle, backdropPath, posterPath, overview, releaseDate, genre, imdbid, originalLanguage, popularity, productionCompanies, productionCountries, voteAverage, voteCount, adult, belongsToCollection, budget, homepage, revenue, runtime, spokenLanguages, status, tagline, video, `cast`, crew, state, sortText FROM (SELECT *, IFNULL(belongsToCollection, movieTitle) AS sortText FROM movie) ORDER BY sortText, releaseDate;")) { while(query.next()) { @@ -574,7 +602,6 @@ void cMainWindow::displaySeries() void cMainWindow::displayMovies() { m_lpMoviesListModel->clear(); - m_lpMoviesListModel->setColumnCount(1); QStringList header; @@ -582,13 +609,32 @@ void cMainWindow::displayMovies() m_lpMoviesListModel->setHorizontalHeaderLabels(header); + QString szOldCollection(""); + QStandardItem* lpRoot = 0; + for(int x = 0;x < m_movieList.count();x++) { cMovie* lpMovie = m_movieList.at(x); + if(lpMovie->belongsToCollection() != szOldCollection) + { + szOldCollection = lpMovie->belongsToCollection(); + if(szOldCollection.isEmpty()) + lpRoot = 0; + else + { + lpRoot = new QStandardItem(szOldCollection); + m_lpMoviesListModel->appendRow(lpRoot); + } + } + QStandardItem* lpItem = new QStandardItem(QString("%1 (%2)  
%3
").arg(lpMovie->movieTitle()).arg(lpMovie->releaseDate().year()).arg(lpMovie->tagline())); lpItem->setData(QVariant::fromValue(lpMovie), Qt::UserRole); - m_lpMoviesListModel->appendRow(lpItem); + + if(lpRoot) + lpRoot->appendRow(lpItem); + else + m_lpMoviesListModel->appendRow(lpItem); } } @@ -658,21 +704,6 @@ void cMainWindow::showMoviesContextMenu(QTreeView* lpTreeView, const QPoint &pos lpMenu->popup(lpTreeView->viewport()->mapToGlobal(pos)); } - -static bool serieSort(cSerie* s1, cSerie* s2) -{ - QString str1 = s1->seriesName(); - QString str2 = s2->seriesName(); - return(str1 < str2); -} - -static bool movieSort(cMovie* s1, cMovie* s2) -{ - QString str1 = s1->movieTitle(); - QString str2 = s2->movieTitle(); - return(str1 < str2); -} - bool cMainWindow::runEdit(cSerie* lpSerie, QString& szDownload) { cEdit* lpEdit = new cEdit; @@ -902,9 +933,7 @@ void cMainWindow::onActionMovieAdd() */ } - m_movieList.add(lpMovie); - std::sort(m_movieList.begin(), m_movieList.end(), movieSort); - + loadMoviesDB(); displayMovies(); delete lpDialog; diff --git a/cmainwindow.ui b/cmainwindow.ui index 1e8041a..5da6c0e 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -130,7 +130,7 @@ QAbstractItemView::ExtendedSelection - false + true true diff --git a/cmoviesearch.cpp b/cmoviesearch.cpp index 5771ad2..9f6e7b6 100644 --- a/cmoviesearch.cpp +++ b/cmoviesearch.cpp @@ -40,7 +40,7 @@ void cMovieSearch::on_m_lpSearchButton_clicked() lpDialog->show(); cTheMovieDBV3 theMovieDBV3; - QList movieList = theMovieDBV3.search(ui->m_lpSearch->text()); + QList movieList = theMovieDBV3.search(ui->m_lpSearch->text(), -1, "de"); ui->m_lpResults->clear(); diff --git a/cmovieviewitemdelegate.cpp b/cmovieviewitemdelegate.cpp index 5f4de73..b27acbb 100644 --- a/cmovieviewitemdelegate.cpp +++ b/cmovieviewitemdelegate.cpp @@ -36,25 +36,34 @@ void cMovieViewItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem //doc.drawContents(painter, clip); painter->setClipRect(clip); - oldBrush = painter->brush(); - switch(lpMovie->state()) + if(!lpMovie) { - case cMovie::StateInit: - painter->setBrush(STATE_INIT); - break; - case cMovie::StateProgress: - painter->setBrush(STATE_PROGRESS); - break; - case cMovie::StateDone: - painter->setBrush(STATE_DONE); - break; - default: - break; + QItemModel* lpModel = (QItemModel*)index.model(); + aaaaa } - painter->drawRect(clip); + if(lpMovie) + { + oldBrush = painter->brush(); - painter->setBrush(oldBrush); + switch(lpMovie->state()) + { + case cMovie::StateInit: + painter->setBrush(STATE_INIT); + break; + case cMovie::StateProgress: + painter->setBrush(STATE_PROGRESS); + break; + case cMovie::StateDone: + painter->setBrush(STATE_DONE); + break; + default: + break; + } + painter->drawRect(clip); + + painter->setBrush(oldBrush); + } QAbstractTextDocumentLayout::PaintContext ctx; // set text color to red for selected item