Changed search method from eventFilter to textChanged-signal.

The search is also updated if one of the checkbuttons is clicked.
develop
tastytea 2019-01-14 20:45:22 +01:00
parent daefd245f0
commit ccf31d072e
No known key found for this signature in database
GPG Key ID: CFC39497F1B26E07
6 changed files with 121 additions and 88 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.2) cmake_minimum_required (VERSION 3.2)
project (whyblocked project (whyblocked
VERSION 0.14.1 VERSION 0.14.2
LANGUAGES CXX LANGUAGES CXX
) )

View File

@ -103,7 +103,6 @@ MainWindow::MainWindow(QMainWindow *parent)
} }
widget_find->hide(); widget_find->hide();
text_find->installEventFilter(this);
reload(); reload();
@ -258,62 +257,6 @@ void MainWindow::dropEvent(QDropEvent *event)
dialog->show(); dialog->show();
} }
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
wstring searchfor;
if (obj == text_find)
{
if (event->type() == QEvent::KeyRelease)
{
searchfor = text_find->text().toLower().toStdWString();
}
else if (event->type() == QEvent::Drop)
{
QDropEvent *drop = static_cast<QDropEvent*>(event);
searchfor = drop->mimeData()->text().toLower().toStdWString();
}
else
{
return QObject::eventFilter(obj, event);
}
}
else
{
return QObject::eventFilter(obj, event);
}
vector<Database::data> filtered_entries;
if (!_dbdata.empty())
{
for (const Database::data &entry : _dbdata)
{
wstring searchstring;
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> convert;
if (check_user->isChecked())
{
searchstring += convert.from_bytes(entry.user);
}
if (check_reason->isChecked())
{
searchstring += convert.from_bytes(entry.reason);
}
std::transform(searchstring.begin(), searchstring.end(),
searchstring.begin(), ::towlower);
if (searchstring.find(searchfor) != std::string::npos)
{
filtered_entries.push_back(entry);
}
}
}
populate_tableview(filtered_entries);
return QObject::eventFilter(obj, event);
}
void MainWindow::add() void MainWindow::add()
{ {
DialogAdd *dialog = new DialogAdd(_database, this); DialogAdd *dialog = new DialogAdd(_database, this);
@ -414,3 +357,40 @@ void MainWindow::find()
text_find->setFocus(); text_find->setFocus();
} }
} }
void MainWindow::update_search(const QString &text)
{
const wstring searchfor = text.toLower().toStdWString();
vector<Database::data> filtered_entries;
if (!_dbdata.empty())
{
for (const Database::data &entry : _dbdata)
{
wstring searchstring;
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> convert;
if (check_user->isChecked())
{
searchstring += convert.from_bytes(entry.user);
}
if (check_reason->isChecked())
{
searchstring += convert.from_bytes(entry.reason);
}
std::transform(searchstring.begin(), searchstring.end(),
searchstring.begin(), ::towlower);
if (searchstring.find(searchfor) != std::string::npos)
{
filtered_entries.push_back(entry);
}
}
}
populate_tableview(filtered_entries);
}
void MainWindow::update_search()
{
update_search(text_find->text());
}

View File

@ -49,7 +49,6 @@ private:
const string urls_to_hyperlinks(const string &text); const string urls_to_hyperlinks(const string &text);
void dragEnterEvent(QDragEnterEvent *event); void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event); void dropEvent(QDropEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
QStandardItemModel *_model; QStandardItemModel *_model;
xdgcfg _config; xdgcfg _config;
@ -65,6 +64,8 @@ private slots:
void populate_tableview(const vector<Database::data> &entries); void populate_tableview(const vector<Database::data> &entries);
void reload(); void reload();
void find(); void find();
void update_search(const QString &text);
void update_search();
}; };

View File

@ -46,7 +46,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="clearButtonEnabled"> <property name="clearButtonEnabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
@ -453,6 +453,54 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>text_find</sender>
<signal>textChanged(QString)</signal>
<receiver>MainWindow</receiver>
<slot>update_search(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>201</x>
<y>83</y>
</hint>
<hint type="destinationlabel">
<x>299</x>
<y>299</y>
</hint>
</hints>
</connection>
<connection>
<sender>check_user</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>update_search()</slot>
<hints>
<hint type="sourcelabel">
<x>455</x>
<y>82</y>
</hint>
<hint type="destinationlabel">
<x>299</x>
<y>299</y>
</hint>
</hints>
</connection>
<connection>
<sender>check_reason</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>update_search()</slot>
<hints>
<hint type="sourcelabel">
<x>553</x>
<y>82</y>
</hint>
<hint type="destinationlabel">
<x>299</x>
<y>299</y>
</hint>
</hints>
</connection>
</connections> </connections>
<slots> <slots>
<slot>add()</slot> <slot>add()</slot>
@ -463,5 +511,9 @@
<slot>edit()</slot> <slot>edit()</slot>
<slot>find()</slot> <slot>find()</slot>
<slot>reload()</slot> <slot>reload()</slot>
<slot>check_user_changed(int)</slot>
<slot>check_reason_changed(int)</slot>
<slot>update_search(QString)</slot>
<slot>update_search()</slot>
</slots> </slots>
</ui> </ui>

View File

@ -93,7 +93,7 @@
</message> </message>
<message> <message>
<location filename="../src/qt/whyblocked.ui" line="59"/> <location filename="../src/qt/whyblocked.ui" line="59"/>
<location filename="../src/qt/mainwindow.cpp" line="383"/> <location filename="../src/qt/mainwindow.cpp" line="326"/>
<source>User/Instance</source> <source>User/Instance</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -104,7 +104,7 @@
</message> </message>
<message> <message>
<location filename="../src/qt/whyblocked.ui" line="72"/> <location filename="../src/qt/whyblocked.ui" line="72"/>
<location filename="../src/qt/mainwindow.cpp" line="385"/> <location filename="../src/qt/mainwindow.cpp" line="328"/>
<source>Reason</source> <source>Reason</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -210,7 +210,7 @@
</message> </message>
<message> <message>
<location filename="../src/qt/whyblocked.ui" line="285"/> <location filename="../src/qt/whyblocked.ui" line="285"/>
<location filename="../src/qt/mainwindow.cpp" line="333"/> <location filename="../src/qt/mainwindow.cpp" line="276"/>
<source>Edit entry</source> <source>Edit entry</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -230,57 +230,57 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="110"/> <location filename="../src/qt/mainwindow.cpp" line="109"/>
<source>Try dragging an account from your webbrowser into this window.</source> <source>Try dragging an account from your webbrowser into this window.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="186"/> <location filename="../src/qt/mainwindow.cpp" line="185"/>
<source>blocked</source> <source>blocked</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="190"/> <location filename="../src/qt/mainwindow.cpp" line="189"/>
<source>silenced</source> <source>silenced</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="211"/> <location filename="../src/qt/mainwindow.cpp" line="210"/>
<source>Nothing selected</source> <source>Nothing selected</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="212"/> <location filename="../src/qt/mainwindow.cpp" line="211"/>
<source>Please select entries to remove.</source> <source>Please select entries to remove.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="327"/> <location filename="../src/qt/mainwindow.cpp" line="270"/>
<source>Invalid selection</source> <source>Invalid selection</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="328"/> <location filename="../src/qt/mainwindow.cpp" line="271"/>
<source>Please select only 1 entry to edit.</source> <source>Please select only 1 entry to edit.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="346"/> <location filename="../src/qt/mainwindow.cpp" line="289"/>
<source>About Whyblocked</source> <source>About Whyblocked</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="347"/> <location filename="../src/qt/mainwindow.cpp" line="290"/>
<source>&lt;p&gt;&lt;b&gt;Whyblocked&lt;/b&gt; %1&lt;/p&gt;&lt;p&gt;Reminds you why you blocked someone.&lt;/p&gt;&lt;p&gt;Sourcecode: &lt;a href=&quot;https://schlomp.space/tastytea/whyblocked&quot;&gt;https://schlomp.space/tastytea/whyblocked&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;small&gt;Copyright © 2018 &lt;a href=&quot;mailto:tastytea@tastytea.de&quot;&gt;tastytea&lt;/a&gt;.&lt;br&gt;Licence GPLv3: &lt;a href=&quot;https://www.gnu.org/licenses/gpl-3.0.html&quot;&gt;GNU GPL version 3&lt;/a&gt;.&lt;br&gt;This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions.&lt;/small&gt;&lt;/p&gt;</source> <source>&lt;p&gt;&lt;b&gt;Whyblocked&lt;/b&gt; %1&lt;/p&gt;&lt;p&gt;Reminds you why you blocked someone.&lt;/p&gt;&lt;p&gt;Sourcecode: &lt;a href=&quot;https://schlomp.space/tastytea/whyblocked&quot;&gt;https://schlomp.space/tastytea/whyblocked&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;small&gt;Copyright © 2018 &lt;a href=&quot;mailto:tastytea@tastytea.de&quot;&gt;tastytea&lt;/a&gt;.&lt;br&gt;Licence GPLv3: &lt;a href=&quot;https://www.gnu.org/licenses/gpl-3.0.html&quot;&gt;GNU GPL version 3&lt;/a&gt;.&lt;br&gt;This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions.&lt;/small&gt;&lt;/p&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="368"/> <location filename="../src/qt/mainwindow.cpp" line="311"/>
<source>Receipts:</source> <source>Receipts:</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="384"/> <location filename="../src/qt/mainwindow.cpp" line="327"/>
<source>Blocked/Silenced</source> <source>Blocked/Silenced</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -198,7 +198,7 @@
</message> </message>
<message> <message>
<location filename="../src/qt/whyblocked.ui" line="285"/> <location filename="../src/qt/whyblocked.ui" line="285"/>
<location filename="../src/qt/mainwindow.cpp" line="333"/> <location filename="../src/qt/mainwindow.cpp" line="276"/>
<source>Edit entry</source> <source>Edit entry</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -219,68 +219,68 @@
</message> </message>
<message> <message>
<location filename="../src/qt/whyblocked.ui" line="59"/> <location filename="../src/qt/whyblocked.ui" line="59"/>
<location filename="../src/qt/mainwindow.cpp" line="383"/> <location filename="../src/qt/mainwindow.cpp" line="326"/>
<source>User/Instance</source> <source>User/Instance</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="384"/> <location filename="../src/qt/mainwindow.cpp" line="327"/>
<source>Blocked/Silenced</source> <source>Blocked/Silenced</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/whyblocked.ui" line="72"/> <location filename="../src/qt/whyblocked.ui" line="72"/>
<location filename="../src/qt/mainwindow.cpp" line="385"/> <location filename="../src/qt/mainwindow.cpp" line="328"/>
<source>Reason</source> <source>Reason</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="110"/> <location filename="../src/qt/mainwindow.cpp" line="109"/>
<source>Try dragging an account from your webbrowser into this window.</source> <source>Try dragging an account from your webbrowser into this window.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="186"/> <location filename="../src/qt/mainwindow.cpp" line="185"/>
<source>blocked</source> <source>blocked</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="190"/> <location filename="../src/qt/mainwindow.cpp" line="189"/>
<source>silenced</source> <source>silenced</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="327"/> <location filename="../src/qt/mainwindow.cpp" line="270"/>
<source>Invalid selection</source> <source>Invalid selection</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="328"/> <location filename="../src/qt/mainwindow.cpp" line="271"/>
<source>Please select only 1 entry to edit.</source> <source>Please select only 1 entry to edit.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="211"/> <location filename="../src/qt/mainwindow.cpp" line="210"/>
<source>Nothing selected</source> <source>Nothing selected</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="212"/> <location filename="../src/qt/mainwindow.cpp" line="211"/>
<source>Please select entries to remove.</source> <source>Please select entries to remove.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="346"/> <location filename="../src/qt/mainwindow.cpp" line="289"/>
<source>About Whyblocked</source> <source>About Whyblocked</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="347"/> <location filename="../src/qt/mainwindow.cpp" line="290"/>
<source>&lt;p&gt;&lt;b&gt;Whyblocked&lt;/b&gt; %1&lt;/p&gt;&lt;p&gt;Reminds you why you blocked someone.&lt;/p&gt;&lt;p&gt;Sourcecode: &lt;a href=&quot;https://schlomp.space/tastytea/whyblocked&quot;&gt;https://schlomp.space/tastytea/whyblocked&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;small&gt;Copyright © 2018 &lt;a href=&quot;mailto:tastytea@tastytea.de&quot;&gt;tastytea&lt;/a&gt;.&lt;br&gt;Licence GPLv3: &lt;a href=&quot;https://www.gnu.org/licenses/gpl-3.0.html&quot;&gt;GNU GPL version 3&lt;/a&gt;.&lt;br&gt;This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions.&lt;/small&gt;&lt;/p&gt;</source> <source>&lt;p&gt;&lt;b&gt;Whyblocked&lt;/b&gt; %1&lt;/p&gt;&lt;p&gt;Reminds you why you blocked someone.&lt;/p&gt;&lt;p&gt;Sourcecode: &lt;a href=&quot;https://schlomp.space/tastytea/whyblocked&quot;&gt;https://schlomp.space/tastytea/whyblocked&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;small&gt;Copyright © 2018 &lt;a href=&quot;mailto:tastytea@tastytea.de&quot;&gt;tastytea&lt;/a&gt;.&lt;br&gt;Licence GPLv3: &lt;a href=&quot;https://www.gnu.org/licenses/gpl-3.0.html&quot;&gt;GNU GPL version 3&lt;/a&gt;.&lt;br&gt;This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions.&lt;/small&gt;&lt;/p&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/qt/mainwindow.cpp" line="368"/> <location filename="../src/qt/mainwindow.cpp" line="311"/>
<source>Receipts:</source> <source>Receipts:</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>