diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-05-29 10:08:46 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-05-31 11:54:31 -0400 |
| commit | 98b3be3e9bbca73640842f6dadaa159dcec04f7b (patch) | |
| tree | 8da1d56ae5e737197172856eecec45e1a1728743 | |
| parent | 4d90e502266dfb886e1d089fb26780d19a38e5a7 (diff) | |
removed buddy from FilterWidget, the intention was to hook a ctrl+f shortcut to it, but that won't work as a general solution, it would need to be on tabs for the modinfo dialog
added a simple matches() that just searches for the string
FilterWidget can cleanly unhook itself
| -rw-r--r-- | src/filterwidget.cpp | 40 | ||||
| -rw-r--r-- | src/filterwidget.h | 12 | ||||
| -rw-r--r-- | src/modinfodialog.cpp | 7 |
3 files changed, 49 insertions, 10 deletions
diff --git a/src/filterwidget.cpp b/src/filterwidget.cpp index 39324bc6..7c47980e 100644 --- a/src/filterwidget.cpp +++ b/src/filterwidget.cpp @@ -2,24 +2,23 @@ #include "eventfilter.h" FilterWidget::FilterWidget() - : m_edit(nullptr), m_clear(nullptr), m_buddy(nullptr) + : m_edit(nullptr), m_eventFilter(nullptr), m_clear(nullptr) { } void FilterWidget::set(QLineEdit* edit) { - if (m_clear) { - delete m_clear; - m_clear = nullptr; - } + unhook(); m_edit = edit; + if (!m_edit) { return; } createClear(); hookEvents(); + clear(); } void FilterWidget::clear() @@ -31,6 +30,23 @@ void FilterWidget::clear() m_edit->clear(); } +bool FilterWidget::matches(const QString& s) const +{ + return s.contains(m_text); +} + +void FilterWidget::unhook() +{ + if (m_clear) { + delete m_clear; + m_clear = nullptr; + } + + if (m_edit) { + m_edit->removeEventFilter(m_eventFilter); + } +} + void FilterWidget::createClear() { m_clear = new QToolButton(m_edit); @@ -50,7 +66,7 @@ void FilterWidget::createClear() void FilterWidget::hookEvents() { - auto* f = new EventFilter(m_edit, [&](auto* w, auto* e) { + m_eventFilter = new EventFilter(m_edit, [&](auto* w, auto* e) { if (e->type() == QEvent::Resize) { onResized(); } @@ -58,12 +74,22 @@ void FilterWidget::hookEvents() return false; }); - m_edit->installEventFilter(f); + m_edit->installEventFilter(m_eventFilter); } void FilterWidget::onTextChanged() { m_clear->setVisible(!m_edit->text().isEmpty()); + + const auto text = m_edit->text(); + + if (text != m_text) { + m_text = text; + + if (changed) { + changed(); + } + } } void FilterWidget::onResized() diff --git a/src/filterwidget.h b/src/filterwidget.h index 07e216f1..ca731dc1 100644 --- a/src/filterwidget.h +++ b/src/filterwidget.h @@ -1,21 +1,27 @@ #ifndef FILTERWIDGET_H #define FILTERWIDGET_H +class EventFilter; + class FilterWidget { public: + std::function<void ()> changed; + FilterWidget(); void set(QLineEdit* edit); - void buddy(QWidget* w); - void clear(); + bool matches(const QString& s) const; + private: QLineEdit* m_edit; + EventFilter* m_eventFilter; QToolButton* m_clear; - QWidget* m_buddy; + QString m_text; + void unhook(); void createClear(); void hookEvents(); void repositionClearButton(); diff --git a/src/modinfodialog.cpp b/src/modinfodialog.cpp index 1e933a74..0f18033a 100644 --- a/src/modinfodialog.cpp +++ b/src/modinfodialog.cpp @@ -454,6 +454,7 @@ ModInfoDialog::ModInfoDialog(ModInfo::Ptr modInfo, const DirectoryEntry *directo m_advancedConflictFilter.set(ui->conflictsAdvancedFilter); + m_advancedConflictFilter.changed = [&]{ refreshConflictLists(false, true); }; // left-elide the overwrites column so that the nearest are visible ui->conflictsAdvancedList->setItemDelegateForColumn( @@ -873,6 +874,12 @@ QTreeWidgetItem* ModInfoDialog::createAdvancedConflictItem( } } + if (!m_advancedConflictFilter.matches(before) && + !m_advancedConflictFilter.matches(relativeName) && + !m_advancedConflictFilter.matches(after)) { + return nullptr; + } + QTreeWidgetItem* item = new QTreeWidgetItem; item->setText(0, before); item->setText(1, relativeName); |
