search: Avoid redundant results by placing pages into vector instead of returning searchresult for each page
This commit is contained in:
@ -105,10 +105,10 @@ void MainWindow::pdfPreviewReceived(PdfPreview preview)
|
||||
label->setPixmap(QPixmap::fromImage(preview.previewImage));
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(label);
|
||||
ui->pdfProcessBar->setValue(++processedPdfPreviews);
|
||||
|
||||
connect(label, &ClickLabel::clicked, [=]() {
|
||||
QSettings settings;
|
||||
QString command = settings.value("pdfviewer").toString();
|
||||
qDebug() << command;
|
||||
if(command != "" && command.contains("%p") && command.contains("%f"))
|
||||
{
|
||||
command = command.replace("%f", preview.documentPath);
|
||||
@ -146,21 +146,17 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
|
||||
this->pdfSearchResults.clear();
|
||||
ui->treeResultsList->clear();
|
||||
ui->lblSearchResults->setText("Results: " + QString::number(results.size()));
|
||||
QString lastpath = "";
|
||||
for(const SearchResult &result : results)
|
||||
{
|
||||
if(lastpath != result.fileData.absPath)
|
||||
{
|
||||
QFileInfo pathInfo(result.fileData.absPath);
|
||||
QString fileName =pathInfo.fileName();
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeResultsList);
|
||||
QFileInfo pathInfo(result.fileData.absPath);
|
||||
QString fileName =pathInfo.fileName();
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeResultsList);
|
||||
|
||||
QDateTime dt = QDateTime::fromSecsSinceEpoch(result.fileData.mtime);
|
||||
item->setIcon(0, iconProvider.icon(pathInfo));
|
||||
item->setText(0, fileName);
|
||||
item->setText(1, result.fileData.absPath);
|
||||
item->setText(2, dt.toString(Qt::ISODate));
|
||||
}
|
||||
QDateTime dt = QDateTime::fromSecsSinceEpoch(result.fileData.mtime);
|
||||
item->setIcon(0, iconProvider.icon(pathInfo));
|
||||
item->setText(0, fileName);
|
||||
item->setText(1, result.fileData.absPath);
|
||||
item->setText(2, dt.toString(Qt::ISODate));
|
||||
|
||||
//TODO: this must be user defined or done more intelligently
|
||||
if(this->pdfSearchResults.size() < 300)
|
||||
@ -170,7 +166,6 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
|
||||
this->pdfSearchResults.append(result);
|
||||
}
|
||||
}
|
||||
lastpath = result.fileData.absPath;
|
||||
}
|
||||
ui->treeResultsList->resizeColumnToContents(0);
|
||||
ui->treeResultsList->resizeColumnToContents(1);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <QApplication>
|
||||
#include <QScreen>
|
||||
#include <QDebug>
|
||||
#include <QScopedPointer>
|
||||
#include "pdfworker.h"
|
||||
|
||||
PdfWorker::PdfWorker()
|
||||
@ -42,17 +43,21 @@ void PdfWorker::generatePreviews(QVector<SearchResult> paths, double scalefactor
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int p = (int)sr.page - 1;
|
||||
if(p < 0)
|
||||
p = 0;
|
||||
Poppler::Page *pdfpage = doc->page(p);
|
||||
QImage image = pdfpage->renderToImage(QGuiApplication::primaryScreen()->physicalDotsPerInchX() * scalefactor, QGuiApplication::primaryScreen()->physicalDotsPerInchY() *scalefactor);
|
||||
for(unsigned int page : sr.pages)
|
||||
{
|
||||
int p = (int)page - 1;
|
||||
if(p < 0)
|
||||
p = 0;
|
||||
Poppler::Page *pdfPage = doc->page(p);
|
||||
QImage image = pdfPage->renderToImage(QGuiApplication::primaryScreen()->physicalDotsPerInchX() * scalefactor, QGuiApplication::primaryScreen()->physicalDotsPerInchY() *scalefactor);
|
||||
|
||||
PdfPreview preview;
|
||||
preview.previewImage = image;
|
||||
preview.documentPath = sr.fileData.absPath;
|
||||
preview.page = page;
|
||||
emit previewReady(preview);
|
||||
}
|
||||
|
||||
PdfPreview preview;
|
||||
preview.previewImage = image;
|
||||
preview.documentPath = sr.fileData.absPath;
|
||||
preview.page = sr.page;
|
||||
emit previewReady(preview);
|
||||
}
|
||||
isFreeMutex.lock();
|
||||
isFree.wakeOne();
|
||||
|
مرجع در شماره جدید
Block a user