Disable buttons Find Next and Find Previous if the search field is empty.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-08-26 16:16:06 +03:00
parent c35f050b66
commit 6baa623be3
4 changed files with 48 additions and 6 deletions

View File

@ -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);
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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);

View File

@ -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);
}
}

View File

@ -29,6 +29,7 @@
#ifndef VTABLESEARCH_H
#define VTABLESEARCH_H
#include <QObject>
#include <QList>
#include <QString>
#include <QTableWidget>
@ -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)