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<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); 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<SearchDescription> search; void refreshSearch(); + void checkSearchResultEmpty(); void setScrollMode(); void updatePlaceholderText(int index); };