Implemented No Results Found warning when search result is empty (#2258)

This commit is contained in:
batuhanakcay 2020-06-24 03:50:51 -04:00 committed by GitHub
parent 061636d714
commit e88ad82968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -190,11 +190,13 @@ SearchWidget::SearchWidget(MainWindow *main) :
QShortcut *enter_press = new QShortcut(QKeySequence(Qt::Key_Return), this);
connect(enter_press, &QShortcut::activated, this, [this]() {
refreshSearch();
checkSearchResultEmpty();
});
enter_press->setContext(Qt::WidgetWithChildrenShortcut);
connect(ui->searchButton, &QAbstractButton::clicked, this, [this]() {
refreshSearch();
checkSearchResultEmpty();
});
connect(ui->searchspaceCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
@ -265,6 +267,19 @@ void SearchWidget::refreshSearch()
qhelpers::adjustColumns(ui->searchTreeView, 3, 0);
}
// No Results Found information message when search returns empty
// Called by &QShortcut::activated and &QAbstractButton::clicked signals
void SearchWidget::checkSearchResultEmpty()
{
if (search.isEmpty()){
QString noResultsMessage="<b>";
noResultsMessage.append(tr("No results found for:"));
noResultsMessage.append("</b><br>");
noResultsMessage.append(ui->filterLineEdit->text().toHtmlEscaped());
QMessageBox::information(this, tr("No Results Found"), noResultsMessage);
}
}
void SearchWidget::setScrollMode()
{
qhelpers::setVerticalScrollMode(ui->searchTreeView);

View File

@ -81,6 +81,7 @@ private:
QList<SearchDescription> search;
void refreshSearch();
void checkSearchResultEmpty();
void setScrollMode();
void updatePlaceholderText(int index);
};