Add a timer in SharedFilesDialog filter to not so often triggs search in

files.
This commit is contained in:
Phenom 2018-03-04 16:45:51 +01:00
parent c19919962d
commit eccff5358a
2 changed files with 50 additions and 21 deletions

View File

@ -186,7 +186,14 @@ SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareD
connect(ui.filterClearButton, SIGNAL(clicked()), this, SLOT(clearFilter())); connect(ui.filterClearButton, SIGNAL(clicked()), this, SLOT(clearFilter()));
connect(ui.filterStartButton, SIGNAL(clicked()), this, SLOT(startFilter())); connect(ui.filterStartButton, SIGNAL(clicked()), this, SLOT(startFilter()));
connect(ui.filterPatternLineEdit, SIGNAL(returnPressed()), this, SLOT(startFilter())); connect(ui.filterPatternLineEdit, SIGNAL(returnPressed()), this, SLOT(startFilter()));
connect(ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged())); connect(ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(onFilterTextEdited()));
//Hidden by default, shown on onFilterTextEdited
ui.filterClearButton->hide();
ui.filterStartButton->hide();
mFilterTimer = new RsProtectedTimer( this );
mFilterTimer->setSingleShot( true ); // Ensure the timer will fire only once after it was started
connect(mFilterTimer, SIGNAL(timeout()), this, SLOT(filterRegExpChanged()));
/* Set header resize modes and initial section sizes */ /* Set header resize modes and initial section sizes */
QHeaderView * header = ui.dirTreeView->header () ; QHeaderView * header = ui.dirTreeView->header () ;
@ -1246,34 +1253,40 @@ void SharedFilesDialog::indicatorChanged(int index)
updateDisplay() ; updateDisplay() ;
} }
void SharedFilesDialog::filterRegExpChanged() void SharedFilesDialog::onFilterTextEdited()
{ {
QString text = ui.filterPatternLineEdit->text(); QString text = ui.filterPatternLineEdit->text();
if (text.isEmpty()) { if (text.isEmpty()) {
ui.filterClearButton->hide(); ui.filterClearButton->hide();
} else { } else {
ui.filterClearButton->show(); ui.filterClearButton->show();
} }
if (text == lastFilterString) { if (text == lastFilterString) {
ui.filterStartButton->hide(); ui.filterStartButton->hide();
} else { } else {
ui.filterStartButton->show(); ui.filterStartButton->show();
} }
//bool valid = false ;
//QColor color ;
if(text.length() > 0 && text.length() < 3) if(text.length() > 0 && text.length() < 3)
{ {
//valid = false;
ui.filterStartButton->setEnabled(false) ; ui.filterStartButton->setEnabled(false) ;
ui.filterPatternFrame->setToolTip(tr("Search string should be at least 3 characters long.")) ; ui.filterPatternFrame->setToolTip(tr("Search string should be at least 3 characters long.")) ;
return ; return ;
} }
ui.filterStartButton->setEnabled(true) ;
ui.filterPatternFrame->setToolTip(QString());
mFilterTimer->start( 500 ); // This will fire filterRegExpChanged after 500 ms.
// If the user types something before it fires, the timer restarts counting
}
void SharedFilesDialog::filterRegExpChanged()
{
QString text = ui.filterPatternLineEdit->text();
if(text.length() > 0 && proxyModel == tree_proxyModel) if(text.length() > 0 && proxyModel == tree_proxyModel)
{ {
std::list<DirDetails> result_list ; std::list<DirDetails> result_list ;
@ -1497,8 +1510,19 @@ void SharedFilesDialog::FilterItems()
std::cerr << "Found " << result_list.size() << " results" << std::endl; std::cerr << "Found " << result_list.size() << " results" << std::endl;
#endif #endif
if(result_list.size() > MAX_SEARCH_RESULTS) size_t resSize = result_list.size();
if(resSize == 0)
{
ui.filterPatternFrame->setToolTip(tr("No result.")) ;
return ; return ;
}
if(resSize > MAX_SEARCH_RESULTS)
{
ui.filterPatternFrame->setToolTip(tr("More than %1 results. Add more/longer search words to select less.").arg(MAX_SEARCH_RESULTS)) ;
return ;
}
ui.filterPatternFrame->setToolTip(tr("Found %1 results.").arg(resSize)) ;
#ifdef DEBUG_SHARED_FILES_DIALOG #ifdef DEBUG_SHARED_FILES_DIALOG
std::cerr << "Found this result: " << std::endl; std::cerr << "Found this result: " << std::endl;
#endif #endif

View File

@ -22,10 +22,13 @@
#ifndef _SHAREDFILESDIALOG_H #ifndef _SHAREDFILESDIALOG_H
#define _SHAREDFILESDIALOG_H #define _SHAREDFILESDIALOG_H
#include <set> #include "ui_SharedFilesDialog.h"
#include "RsAutoUpdatePage.h" #include "RsAutoUpdatePage.h"
#include "gui/RetroShareLink.h" #include "gui/RetroShareLink.h"
#include "ui_SharedFilesDialog.h" #include "util/RsProtectedTimer.h"
#include <set>
class RetroshareDirModel; class RetroshareDirModel;
class QSortFilterProxyModel; class QSortFilterProxyModel;
@ -73,6 +76,7 @@ private slots:
void indicatorChanged(int index); void indicatorChanged(int index);
void onFilterTextEdited();
void filterRegExpChanged(); void filterRegExpChanged();
void clearFilter(); void clearFilter();
void startFilter(); void startFilter();
@ -137,6 +141,7 @@ protected:
QString lastFilterString; QString lastFilterString;
QString mLastFilterText ; QString mLastFilterText ;
RsProtectedTimer* mFilterTimer;
QList<QModelIndex> mHiddenIndexes; QList<QModelIndex> mHiddenIndexes;
}; };