From 0e4897969b8e132f2f675c84f418c9412ac1d313 Mon Sep 17 00:00:00 2001 From: unknown <1310440+hemirt@users.noreply.github.com> Date: Wed, 23 Oct 2024 00:57:57 +0200 Subject: [PATCH] replace ChannelViewProxy with ChannelViewId --- src/widgets/helper/NotebookTab.cpp | 57 ++++++++++-------------------- src/widgets/helper/NotebookTab.hpp | 38 +++++++++----------- 2 files changed, 34 insertions(+), 61 deletions(-) diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 1040ebe38..eddb44123 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -56,27 +56,6 @@ namespace { } } // namespace -std::size_t NotebookTab::HighlightSources::ChannelViewProxyHash::operator()( - const ChannelViewProxy &cp) const noexcept -{ - std::size_t seed = 0; - auto first = qHash(cp.channelView->underlyingChannel()->getName()); - auto second = qHash(cp.channelView->getFilterIds()); - - boost::hash_combine(seed, first); - boost::hash_combine(seed, second); - - return seed; -} - -bool NotebookTab::HighlightSources::ChannelViewProxyEqual::operator()( - const ChannelViewProxy &lp, const ChannelViewProxy &rp) const -{ - return lp.channelView->underlyingChannel() == - rp.channelView->underlyingChannel() && - lp.channelView->getFilterIds() == rp.channelView->getFilterIds(); -} - NotebookTab::NotebookTab(Notebook *notebook) : Button(notebook) , positionChangedAnimation_(this, "pos") @@ -327,13 +306,13 @@ bool NotebookTab::isSelected() const } void NotebookTab::removeNewMessageSource( - const HighlightSources::ChannelViewProxy &source) + const HighlightSources::ChannelViewId &source) { this->highlightSources_.newMessageSource.erase(source); } void NotebookTab::removeHighlightedSource( - const HighlightSources::ChannelViewProxy &source) + const HighlightSources::ChannelViewId &source) { this->highlightSources_.highlightedSource.erase(source); } @@ -354,10 +333,12 @@ void NotebookTab::removeHighlightStateChangeSources( void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource) { - auto channelViewProxy = - HighlightSources::ChannelViewProxy{&channelViewSource}; - this->removeHighlightedSource(channelViewProxy); - this->removeNewMessageSource(channelViewProxy); + const auto &channelName = channelViewSource.underlyingChannel()->getName(); + const auto &channelFilterIds = channelViewSource.getFilterIds(); + auto channelViewId = + HighlightSources::GetChannelViewId(channelName, channelFilterIds); + this->removeHighlightedSource(channelViewId); + this->removeNewMessageSource(channelViewId); this->updateHighlightStateDueSourcesChange(); auto *splitNotebook = dynamic_cast(this->notebook_); @@ -372,8 +353,8 @@ void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource) auto *tab = splitContainer->getTab(); if (tab && tab != this) { - tab->removeHighlightedSource(channelViewProxy); - tab->removeNewMessageSource(channelViewProxy); + tab->removeHighlightedSource(channelViewId); + tab->removeNewMessageSource(channelViewId); tab->updateHighlightStateDueSourcesChange(); } } @@ -575,28 +556,26 @@ void NotebookTab::updateHighlightState(HighlightState newHighlightStyle, // message is highlighting unvisible tab - auto underlyingChannel = channelViewSource.underlyingChannel(); - auto newFilters = channelViewSource.getFilterIds(); - auto channelViewProxy = - HighlightSources::ChannelViewProxy{&channelViewSource}; + const auto &channelName = channelViewSource.underlyingChannel()->getName(); + const auto &channelFilterIds = channelViewSource.getFilterIds(); + auto channelViewId = + HighlightSources::GetChannelViewId(channelName, channelFilterIds); switch (newHighlightStyle) { case HighlightState::Highlighted: { if (!this->highlightSources_.highlightedSource.contains( - channelViewProxy)) + channelViewId)) { - this->highlightSources_.highlightedSource.insert( - channelViewProxy); + this->highlightSources_.highlightedSource.insert(channelViewId); } break; } case HighlightState::NewMessage: { if (!this->highlightSources_.newMessageSource.contains( - channelViewProxy)) + channelViewId)) { - this->highlightSources_.newMessageSource.insert( - channelViewProxy); + this->highlightSources_.newMessageSource.insert(channelViewId); } break; } diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index ec0ad0ad9..5bef5fbee 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -126,40 +126,34 @@ private: const MessagePtr &message) const; struct HighlightSources { - struct ChannelViewProxy { - const ChannelView *channelView; - }; + using ChannelViewId = std::size_t; - struct ChannelViewProxyHash { - using is_transparent = void; - std::size_t operator()(const ChannelViewProxy &cp) const noexcept; - }; + static ChannelViewId GetChannelViewId( + const QString &channelName, const QList &channelFilterIds) + { + std::size_t seed = 0; + auto first = qHash(channelName); + auto second = qHash(channelFilterIds); - struct ChannelViewProxyEqual { - bool operator()(const ChannelViewProxy &l, - const ChannelViewProxy &r) const; - }; + boost::hash_combine(seed, first); + boost::hash_combine(seed, second); - std::unordered_set - newMessageSource; - std::unordered_set - highlightedSource; + return seed; + } + + std::unordered_set newMessageSource; + std::unordered_set highlightedSource; void clear() { this->newMessageSource.clear(); this->highlightedSource.clear(); } - } highlightSources_; void removeHighlightStateChangeSources(const HighlightSources &toRemove); - void removeNewMessageSource( - const HighlightSources::ChannelViewProxy &source); - void removeHighlightedSource( - const HighlightSources::ChannelViewProxy &source); + void removeNewMessageSource(const HighlightSources::ChannelViewId &source); + void removeHighlightedSource(const HighlightSources::ChannelViewId &source); void updateHighlightStateDueSourcesChange(); QPropertyAnimation positionChangedAnimation_;