From 6baa623be32ae2db3524c5a24936a0b9ef420a79 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 26 Aug 2016 16:16:06 +0300 Subject: [PATCH] Disable buttons Find Next and Find Previous if the search field is empty. --HG-- branch : develop --- src/app/tape/tmainwindow.cpp | 21 +++++++++++++++++-- .../valentina/dialogs/dialogincrements.cpp | 9 ++++++++ src/libs/vmisc/vtablesearch.cpp | 15 +++++++++++-- src/libs/vmisc/vtablesearch.h | 9 ++++++-- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 6be39a824..c5c48968b 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -1984,6 +1984,15 @@ void TMainWindow::InitWindow() connect(ui->toolButtonFindPrevious, &QToolButton::clicked, [=] (){search->FindPrevious();}); connect(ui->toolButtonFindNext, &QToolButton::clicked, [=] (){search->FindNext();}); + connect(search.data(), &VTableSearch::HasResult, [this] (bool state) + { + ui->toolButtonFindPrevious->setEnabled(state); + }); + connect(search.data(), &VTableSearch::HasResult, [this] (bool state) + { + ui->toolButtonFindNext->setEnabled(state); + }); + ui->plainTextEditNotes->setPlainText(m->Notes()); connect(ui->plainTextEditNotes, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveNotes); @@ -2433,8 +2442,16 @@ void TMainWindow::MFields(bool enabled) } ui->lineEditFind->setEnabled(enabled); - ui->toolButtonFindPrevious->setEnabled(enabled); - ui->toolButtonFindNext->setEnabled(enabled); + if (enabled && not ui->lineEditFind->text().isEmpty()) + { + ui->toolButtonFindPrevious->setEnabled(enabled); + ui->toolButtonFindNext->setEnabled(enabled); + } + else + { + ui->toolButtonFindPrevious->setEnabled(false); + ui->toolButtonFindNext->setEnabled(false); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/dialogs/dialogincrements.cpp b/src/app/valentina/dialogs/dialogincrements.cpp index 614f7f720..45f750104 100644 --- a/src/app/valentina/dialogs/dialogincrements.cpp +++ b/src/app/valentina/dialogs/dialogincrements.cpp @@ -113,6 +113,15 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par connect(ui->toolButtonFindPrevious, &QToolButton::clicked, [=](){search->FindPrevious();}); connect(ui->toolButtonFindNext, &QToolButton::clicked, [=](){search->FindNext();}); + connect(search.data(), &VTableSearch::HasResult, [this] (bool state) + { + ui->toolButtonFindPrevious->setEnabled(state); + }); + connect(search.data(), &VTableSearch::HasResult, [this] (bool state) + { + ui->toolButtonFindNext->setEnabled(state); + }); + if (ui->tableWidgetIncrement->rowCount() > 0) { ui->tableWidgetIncrement->selectRow(0); diff --git a/src/libs/vmisc/vtablesearch.cpp b/src/libs/vmisc/vtablesearch.cpp index e33498572..b03cc4f83 100644 --- a/src/libs/vmisc/vtablesearch.cpp +++ b/src/libs/vmisc/vtablesearch.cpp @@ -37,8 +37,9 @@ #include "../vmisc/def.h" //--------------------------------------------------------------------------------------------------------------------- -VTableSearch::VTableSearch(QTableWidget *table) - :table(table), +VTableSearch::VTableSearch(QTableWidget *table, QObject *parent) + : QObject(parent), + table(table), searchIndex(-1), searchList() { @@ -69,6 +70,8 @@ void VTableSearch::Clear() searchList.clear(); searchIndex = -1; + + emit HasResult(false); } //--------------------------------------------------------------------------------------------------------------------- @@ -112,6 +115,8 @@ void VTableSearch::Find(const QString &term) QTableWidgetItem *item = searchList.at(searchIndex); item->setBackground(Qt::red); table->scrollToItem(item); + + emit HasResult(true); } } } @@ -217,5 +222,11 @@ void VTableSearch::RefreshList(const QString &term) QTableWidgetItem *item = searchList.at(searchIndex); item->setBackground(Qt::red); table->scrollToItem(item); + + emit HasResult(true); + } + else + { + emit HasResult(false); } } diff --git a/src/libs/vmisc/vtablesearch.h b/src/libs/vmisc/vtablesearch.h index 0e8515144..d7ff81e77 100644 --- a/src/libs/vmisc/vtablesearch.h +++ b/src/libs/vmisc/vtablesearch.h @@ -29,6 +29,7 @@ #ifndef VTABLESEARCH_H #define VTABLESEARCH_H +#include #include #include #include @@ -37,10 +38,11 @@ class QTableWidget; class QTableWidgetItem; -class VTableSearch +class VTableSearch: public QObject { + Q_OBJECT public: - explicit VTableSearch(QTableWidget *table); + explicit VTableSearch(QTableWidget *table, QObject *parent = nullptr); void Find(const QString &term); void FindPrevious(); @@ -49,6 +51,9 @@ public: void AddRow(int row); void RefreshList(const QString &term); +signals: + void HasResult(bool state); + private: Q_DISABLE_COPY(VTableSearch)