summaryrefslogtreecommitdiffstats
path: root/seriestreemodel.cpp
diff options
context:
space:
mode:
authorArno Moeller <am@mindwerk.de>2010-06-18 10:28:38 +0200
committerArno Moeller <am@mindwerk.de>2010-06-18 10:28:38 +0200
commitbf883fc87c19f10dd4bc74947883792d3af0537c (patch)
tree75f2dc078975d98b18c3659bc66230fe917ffadd /seriestreemodel.cpp
parente730da87d51fea35f30782abab836c69ab8876d2 (diff)
downloadSheMov-bf883fc87c19f10dd4bc74947883792d3af0537c.tar.gz
SheMov-bf883fc87c19f10dd4bc74947883792d3af0537c.tar.bz2
SheMov-bf883fc87c19f10dd4bc74947883792d3af0537c.zip
Streamline SeriesTreeModel::findFiles
Avoid code duplication by handling the two different queries more generic so the result set can be fetched in just one while loop.
Diffstat (limited to 'seriestreemodel.cpp')
-rw-r--r--seriestreemodel.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/seriestreemodel.cpp b/seriestreemodel.cpp
index 748f870..0da1b04 100644
--- a/seriestreemodel.cpp
+++ b/seriestreemodel.cpp
@@ -155,26 +155,26 @@ QModelIndex SeriesTreeModel::findValue(const QVariant &value, const QModelIndex
QFileInfoList SeriesTreeModel::findFiles(const QModelIndex &where) const{
int type = where.data(TypeRole).toInt();
QFileInfoList retval;
+
+ QSqlQuery *query = 0;
if(type == Series){
- mSeriesFilesQuery->bindValue(":id", where.data(SeriesIdRole));
- if(mSeriesFilesQuery->exec()){
- while(mSeriesFilesQuery->next()){
- QString path = Helper::createArchivePath(mSeriesFilesQuery->value(0).toString(), mSeriesFilesQuery->value(1).toString());
- retval << QFileInfo(path);
- }
- return retval;
- }
+ query = mSeriesFilesQuery;
+ query->bindValue(":id", where.data(SeriesIdRole));
}else if(type == Part){
- mSeriesPartFilesQuery->bindValue(":id", where.data(SeriesPartIdRole));
- if(mSeriesPartFilesQuery->exec()){
- while(mSeriesPartFilesQuery->next()){
- QString path = Helper::createArchivePath(mSeriesFilesQuery->value(0).toString(), mSeriesFilesQuery->value(1).toString());
+ query = mSeriesPartFilesQuery;
+ query->bindValue(":id", where.data(SeriesPartIdRole));
+ }
+
+ if(query){
+ if(query->exec()){
+ while(query->next()){
+ QString path = Helper::createArchivePath(query->value(0).toString(), query->value(1).toString());
retval << QFileInfo(path);
}
- return retval;
}
}
- return QFileInfoList();
+
+ return retval;
}
void SeriesTreeModel::populate(){