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(m_databaseSettingsWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool)));
connect(this, SIGNAL(currentChanged(int)), this, SLOT(emitCurrentModeChanged())); connect(this, SIGNAL(currentChanged(int)), this, SLOT(emitCurrentModeChanged()));
connect(m_searchUi->searchEdit, SIGNAL(textChanged(QString)), this, SLOT(startSearchTimer())); 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(m_searchTimer, SIGNAL(timeout()), this, SLOT(search()));
connect(closeAction, SIGNAL(triggered()), this, SLOT(closeSearch())); connect(closeAction, SIGNAL(triggered()), this, SLOT(closeSearch()));
connect(m_entryView, SIGNAL(entrySelectionChanged()), SLOT(updateEntryActions())); connect(m_entryView, SIGNAL(entrySelectionChanged()), SLOT(updateEntryActions()));
@ -491,7 +492,14 @@ void DatabaseWidget::showSearch()
void DatabaseWidget::search() void DatabaseWidget::search()
{ {
Group* searchGroup = m_db->rootGroup(); 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(); Group* group = m_groupView->currentGroup();
if (group) { if (group) {
@ -510,6 +518,14 @@ void DatabaseWidget::startSearchTimer()
m_searchTimer->start(100); m_searchTimer->start(100);
} }
void DatabaseWidget::startSearch()
{
if (!m_searchTimer->isActive()) {
m_searchTimer->stop();
}
search();
}
bool DatabaseWidget::dbHasKey() bool DatabaseWidget::dbHasKey()
{ {
return m_db->hasKey(); return m_db->hasKey();

View File

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

View File

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