Don't add same paths to searchresult list

This commit is contained in:
Albert S. 2018-09-02 20:38:21 +02:00
parent cd3a160aa6
commit 9c30fa70a1

View File

@ -121,17 +121,23 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
this->pdfSearchResults.clear(); this->pdfSearchResults.clear();
ui->treeResultsList->clear(); ui->treeResultsList->clear();
ui->lblSearchResults->setText("Results: " + QString::number(results.size())); ui->lblSearchResults->setText("Results: " + QString::number(results.size()));
QString lastpath = "";
for(const SearchResult &result : results) for(const SearchResult &result : results)
{ {
QFileInfo pathInfo(result.path); if(lastpath != result.path)
QString fileName =pathInfo.fileName(); {
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeResultsList); QFileInfo pathInfo(result.path);
QDateTime dt = QDateTime::fromSecsSinceEpoch(result.mtime); QString fileName =pathInfo.fileName();
item->setIcon(0, iconProvider.icon(pathInfo)); QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeResultsList);
item->setText(0, fileName);
item->setText(1, result.path); QDateTime dt = QDateTime::fromSecsSinceEpoch(result.mtime);
item->setText(2, dt.toString(Qt::ISODate)); item->setIcon(0, iconProvider.icon(pathInfo));
//TODO: this must be user definied or done more intelligently item->setText(0, fileName);
item->setText(1, result.path);
item->setText(2, dt.toString(Qt::ISODate));
}
//TODO: this must be user defined or done more intelligently
if(this->pdfSearchResults.size() < 300) if(this->pdfSearchResults.size() < 300)
{ {
if(result.path.endsWith(".pdf")) if(result.path.endsWith(".pdf"))
@ -139,6 +145,7 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
this->pdfSearchResults.append(result); this->pdfSearchResults.append(result);
} }
} }
lastpath = result.path;
} }
ui->treeResultsList->resizeColumnToContents(0); ui->treeResultsList->resizeColumnToContents(0);
ui->treeResultsList->resizeColumnToContents(1); ui->treeResultsList->resizeColumnToContents(1);