diff options
author | Arno <am@disconnect.de> | 2013-02-08 03:57:41 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2013-02-08 03:57:41 +0100 |
commit | 534ca73d64b13c4604e6823e7d3a7f290b225e1d (patch) | |
tree | b155a08517a059a4d88e2beb4d6933c40568aa03 /filestreewidget.cpp | |
parent | a2c0865ca9491d403ae0032bbc9894c452cc09d0 (diff) | |
download | SheMov-534ca73d64b13c4604e6823e7d3a7f290b225e1d.tar.gz SheMov-534ca73d64b13c4604e6823e7d3a7f290b225e1d.tar.bz2 SheMov-534ca73d64b13c4604e6823e7d3a7f290b225e1d.zip |
Fix "suggest file for burning"
Don't use a SQL-Query to find files. Traverse the model instead. Also
check if the resulting index is already selected. All in all, make it
usable again.
Diffstat (limited to 'filestreewidget.cpp')
-rw-r--r-- | filestreewidget.cpp | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/filestreewidget.cpp b/filestreewidget.cpp index cc92a67..ffe1343 100644 --- a/filestreewidget.cpp +++ b/filestreewidget.cpp @@ -269,25 +269,14 @@ void FilesTreeWidget::suggest(){ return; } qint64 neededSize = dvdSize - size; - QModelIndexList possibleFiles = mModel->fileSizeLessThan(neededSize); - if(possibleFiles.isEmpty()){ - QLocale l; - float mb = size / 1024 / 1024; - QString message = QString(tr("No file smaller than %1 MiB found")).arg(l.toString(mb, 'f', 2)); - QMessageBox::critical(this, tr("Error"), message); - return; - } - QModelIndex last; - QStringList selectedFiles; - foreach(QModelIndex sIdx, possibleFiles){ - QModelIndex vIdx = mProxy->mapFromSource(sIdx); - last = vIdx; - mView->selectionModel()->select(vIdx, QItemSelectionModel::Select | QItemSelectionModel::Rows); - selectedFiles << sIdx.data(FilesTreeModel::FileNameRole).toString(); - } - QString message = QString(tr("Selected %1 items: %2")).arg(QString::number(selectedFiles.count())).arg(selectedFiles.join(", ")); - emit statusMessage(message); - mView->scrollTo(last, QAbstractItemView::PositionAtCenter); + QModelIndex candidate = mModel->fileSizeLessThan(neededSize); + QModelIndex real = mProxy->mapFromSource(candidate); + if(!real.isValid() || mView->selectionModel()->isSelected(real)){ + QMessageBox::critical(this, tr("Error"), tr("Out of suggestions!")); + return; + } + mView->selectionModel()->select(real, QItemSelectionModel::Select | QItemSelectionModel::Rows); + mView->scrollTo(real, QAbstractItemView::PositionAtCenter); } void FilesTreeWidget::playSelected(){ |