Add case sensitivity option to search.

This commit is contained in:
Florian Geyer 2012-05-27 13:19:12 +02:00
parent 10321adc0b
commit a92ddc6d0b
3 changed files with 46 additions and 21 deletions

View File

@ -147,6 +147,7 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
connect(m_databaseSettingsWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool)));
connect(this, SIGNAL(currentChanged(int)), this, SLOT(emitCurrentModeChanged()));
connect(m_searchUi->searchEdit, SIGNAL(textChanged(QString)), this, SLOT(startSearchTimer()));
connect(m_searchUi->caseSensitiveCheckBox, SIGNAL(toggled(bool)), this, SLOT(startSearch()));
connect(m_searchTimer, SIGNAL(timeout()), this, SLOT(search()));
connect(closeAction, SIGNAL(triggered()), this, SLOT(closeSearch()));
connect(m_entryView, SIGNAL(entrySelectionChanged()), SLOT(updateEntryActions()));
@ -491,7 +492,14 @@ void DatabaseWidget::showSearch()
void DatabaseWidget::search()
{
Group* searchGroup = m_db->rootGroup();
QList<Entry*> searchResult = searchGroup->search(m_searchUi->searchEdit->text(), Qt::CaseInsensitive);
Qt::CaseSensitivity sensitivity;
if (m_searchUi->caseSensitiveCheckBox->isChecked()) {
sensitivity = Qt::CaseSensitive;
}
else {
sensitivity = Qt::CaseInsensitive;
}
QList<Entry*> searchResult = searchGroup->search(m_searchUi->searchEdit->text(), sensitivity);
Group* group = m_groupView->currentGroup();
if (group) {
@ -510,6 +518,14 @@ void DatabaseWidget::startSearchTimer()
m_searchTimer->start(100);
}
void DatabaseWidget::startSearch()
{
if (!m_searchTimer->isActive()) {
m_searchTimer->stop();
}
search();
}
bool DatabaseWidget::dbHasKey()
{
return m_db->hasKey();

View File

@ -100,6 +100,7 @@ private Q_SLOTS:
void emitCurrentModeChanged();
void clearLastGroup(Group* group);
void search();
void startSearch();
void startSearchTimer();
void showSearch();
void closeSearch();

View File

@ -6,34 +6,42 @@
<rect>
<x>0</x>
<y>0</y>
<width>466</width>
<height>53</height>
<width>630</width>
<height>87</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="closeSearchButton">
<layout class="QFormLayout" name="formLayout">
<item row="4" column="1">
<widget class="QCheckBox" name="caseSensitiveCheckBox">
<property name="text">
<string/>
</property>
<property name="autoRaise">
<bool>true</bool>
<string>Case sensitive</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Find:</string>
</property>
</widget>
</item>
<item>
<item row="2" column="1">
<widget class="LineEdit" name="searchEdit"/>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="closeSearchButton">
<property name="text">
<string/>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Find:</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>