From e88ad82968be0d62285a8ff22458c4e947ada30f Mon Sep 17 00:00:00 2001 From: batuhanakcay <43937239+batuhanakcay@users.noreply.github.com> Date: Wed, 24 Jun 2020 03:50:51 -0400 Subject: [PATCH] Implemented No Results Found warning when search result is empty (#2258) --- src/widgets/SearchWidget.cpp | 15 +++++++++++++++ src/widgets/SearchWidget.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/widgets/SearchWidget.cpp b/src/widgets/SearchWidget.cpp index 813f11cf..7f22eb60 100644 --- a/src/widgets/SearchWidget.cpp +++ b/src/widgets/SearchWidget.cpp @@ -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(&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=""; + noResultsMessage.append(tr("No results found for:")); + noResultsMessage.append("
"); + noResultsMessage.append(ui->filterLineEdit->text().toHtmlEscaped()); + QMessageBox::information(this, tr("No Results Found"), noResultsMessage); + } +} + void SearchWidget::setScrollMode() { qhelpers::setVerticalScrollMode(ui->searchTreeView); diff --git a/src/widgets/SearchWidget.h b/src/widgets/SearchWidget.h index 3141ef64..d497ef36 100644 --- a/src/widgets/SearchWidget.h +++ b/src/widgets/SearchWidget.h @@ -81,6 +81,7 @@ private: QList search; void refreshSearch(); + void checkSearchResultEmpty(); void setScrollMode(); void updatePlaceholderText(int index); };