From a6a1c319ee5a77cc8341eaeccc72da35cbcf17c5 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 14 May 2011 10:32:19 +0200 Subject: Add field isLocal to SeriesTreeModel Indicate if SeriesPart has local files in SeriesTreeModel. The cost for this is an additional Query when populating the model, but fortunately the performance impact isn't noticeable. Also introduced a new enum NumFields to SeriesTreeModel. It represents the number of fields for a SmTreeItem so extending the model isn't that cumbersome any more. --- seriestreemodel.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'seriestreemodel.cpp') diff --git a/seriestreemodel.cpp b/seriestreemodel.cpp index c091576..ca8e10d 100644 --- a/seriestreemodel.cpp +++ b/seriestreemodel.cpp @@ -48,6 +48,8 @@ SeriesTreeModel::SeriesTreeModel(QStringList &headers, QObject *parent) : SmTree mFavoriteSeriesPartsQuery = new QSqlQuery(mDb); mFavoriteSeriesPartsQuery->prepare("SELECT iseriesparts_id, iseriespart, tsubtitle FROM seriesparts WHERE iseries_id = :id AND bfavorite = true"); mUpdateGenericTemplate = QString("UPDATE seriesparts SET %1 = :value WHERE iseriesparts_id = :id"); + mIsLocalQuery = new QSqlQuery(mDb); + mIsLocalQuery->prepare("SELECT COUNT(*) FROM files WHERE iseriespart_id = :id AND sifiletype = 1 AND idvd = -1"); mUpdateGenericMap.insert(Favorite, "bfavorite"); mUpdateGenericMap.insert(Subtitle, "tsubtitle"); mUpdateGenericMap.insert(SeriesPart, "iseriespart"); @@ -276,6 +278,16 @@ QFileInfoList SeriesTreeModel::findSortedMovies(const QModelIndex &from) const{ return retval; } +bool SeriesTreeModel::hasLocals(int sPartId) const { + bool retval = false; + mIsLocalQuery->bindValue(":id", sPartId); + mIsLocalQuery->exec(); + while(mIsLocalQuery->next()){ + retval = mIsLocalQuery->value(0).toBool(); + } + return retval; +} + int SeriesTreeModel::seriesIdByPartId(int partId){ if(mSeriesPartSeriesMap.contains(partId)){ return mSeriesPartSeriesMap.value(partId); @@ -327,7 +339,7 @@ bool SeriesTreeModel::addSeries(const QVariant &seriesName, const QModelIndex &p if(lastId.next()){ int id = lastId.value(0).toInt(); QList seriesData; - seriesData << name << id << QVariant() << QVariant() << Series << false << QVariant(); + seriesData << name << id << QVariant() << QVariant() << Series << false << QVariant() << QVariant(); if(addRow(seriesData, parent)){ mDb.commit(); return true; @@ -360,7 +372,7 @@ bool SeriesTreeModel::addSeriesPart(int seriesPart, const QModelIndex &parent, c if(lastId.next()){ int id = lastId.value(0).toInt(); QList partData; - partData << parent.data(NameRole) << seriesId << id << seriesPart << Part << false << subTitle; + partData << parent.data(NameRole) << seriesId << id << seriesPart << Part << false << subTitle << true; if(addRow(partData, parent)){ mDb.commit(); mSeriesPartSeriesMap.insert(id, seriesId); @@ -385,7 +397,7 @@ void SeriesTreeModel::setMappingFilter(const QString &filter, const QString &tab if(tableIdQuery.exec()){ mSeriesPartSeriesMap.clear(); QStringList ids; - SmTreeItem *rootItem = new SmTreeItem(7); + SmTreeItem *rootItem = new SmTreeItem(NumFields); while(tableIdQuery.next()){ ids << QString::number(tableIdQuery.value(0).toInt()); } @@ -408,6 +420,7 @@ void SeriesTreeModel::setMappingFilter(const QString &filter, const QString &tab while(partsQuery.next()){ QList partData; partData << seriesData.at(Name) << seriesData.at(SeriesId) << partsQuery.value(0) << partsQuery.value(1) << Part << partsQuery.value(2) << partsQuery.value(3); + partData << hasLocals(partsQuery.value(0).toInt()); SmTreeItem *partItem = new SmTreeItem(partData, seriesItem); seriesItem->appendChild(partItem); mSeriesPartSeriesMap.insert(partsQuery.value(0).toInt(), seriesData.at(1).toInt()); @@ -443,7 +456,7 @@ void SeriesTreeModel::setFileFilter(const QString &filter, const QString &column } if(seriesIdQuery.exec()){ mSeriesPartSeriesMap.clear(); - SmTreeItem *rootItem = new SmTreeItem(7); + SmTreeItem *rootItem = new SmTreeItem(NumFields); while(seriesIdQuery.next()){ QList seriesData; seriesData << seriesIdQuery.value(1) << seriesIdQuery.value(0) << QVariant() << QVariant() << Series << false << QVariant(); @@ -464,6 +477,7 @@ void SeriesTreeModel::setFileFilter(const QString &filter, const QString &column while(partsQuery.next()){ QList partData; partData << seriesData.at(Name) << seriesData.at(SeriesId) << partsQuery.value(0) << partsQuery.value(1) << Part << partsQuery.value(2) << partsQuery.value(3); + partData << hasLocals(partsQuery.value(0).toInt()); SmTreeItem *partItem = new SmTreeItem(partData, seriesItem); seriesItem->appendChild(partItem); mSeriesPartSeriesMap.insert(partsQuery.value(0).toInt(), seriesData.at(1).toInt()); @@ -477,7 +491,7 @@ void SeriesTreeModel::setFileFilter(const QString &filter, const QString &column void SeriesTreeModel::setFavoriteFilter(){ if(mFavoriteSeriesIdQuery->exec()){ mSeriesPartSeriesMap.clear(); - SmTreeItem *rootItem = new SmTreeItem(7); + SmTreeItem *rootItem = new SmTreeItem(NumFields); while(mFavoriteSeriesIdQuery->next()){ QList seriesData; seriesData << mFavoriteSeriesIdQuery->value(1) << mFavoriteSeriesIdQuery->value(0) << QVariant() << QVariant() << Series << false << QVariant(); @@ -488,6 +502,7 @@ void SeriesTreeModel::setFavoriteFilter(){ while(mFavoriteSeriesPartsQuery->next()){ QList partData; partData << seriesData.at(Name) << seriesData.at(SeriesId) << mFavoriteSeriesPartsQuery->value(0) << mFavoriteSeriesPartsQuery->value(1) << Part << true << mFavoriteSeriesPartsQuery->value(2); + partData << hasLocals(mFavoriteSeriesPartsQuery->value(0).toInt()); SmTreeItem *partItem = new SmTreeItem(partData, seriesItem); seriesItem->appendChild(partItem); mSeriesPartSeriesMap.insert(mFavoriteSeriesPartsQuery->value(0).toInt(), seriesData.at(1).toInt()); @@ -527,10 +542,10 @@ void SeriesTreeModel::conditionalUpdate(const QModelIndex &parent, int field, co void SeriesTreeModel::populate(){ QSqlQuery seriesQuery = QSqlQuery("SELECT iseries_id, tseries_name FROM series ORDER BY tseries_name", mDb); mSeriesPartSeriesMap.clear(); - SmTreeItem *rootItem = new SmTreeItem(7); + SmTreeItem *rootItem = new SmTreeItem(NumFields); while(seriesQuery.next()){ QList seriesData; - seriesData << seriesQuery.value(1) << seriesQuery.value(0) << QVariant() << QVariant() << Series << false << QVariant(); + seriesData << seriesQuery.value(1) << seriesQuery.value(0) << QVariant() << QVariant() << Series << false << QVariant() << QVariant(); SmTreeItem *seriesItem = new SmTreeItem(seriesData, rootItem); rootItem->appendChild(seriesItem); mSeriesPartsQuery->bindValue(":id", seriesData.at(1)); @@ -538,6 +553,7 @@ void SeriesTreeModel::populate(){ while(mSeriesPartsQuery->next()){ QList partData; partData << seriesData.at(Name) << seriesData.at(SeriesId) << mSeriesPartsQuery->value(0) << mSeriesPartsQuery->value(1) << Part << mSeriesPartsQuery->value(2) << mSeriesPartsQuery->value(3); + partData << hasLocals(seriesData.at(1).toInt()); SmTreeItem *partItem = new SmTreeItem(partData, seriesItem); seriesItem->appendChild(partItem); mSeriesPartSeriesMap.insert(mSeriesPartsQuery->value(0).toInt(), seriesData.at(1).toInt()); -- cgit v1.2.3-70-g09d2