replace ChannelViewProxy with ChannelViewId

This commit is contained in:
unknown 2024-10-23 00:57:57 +02:00
parent 374e0c5fa0
commit 0e4897969b
2 changed files with 34 additions and 61 deletions

View file

@ -56,27 +56,6 @@ namespace {
} }
} // 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) NotebookTab::NotebookTab(Notebook *notebook)
: Button(notebook) : Button(notebook)
, positionChangedAnimation_(this, "pos") , positionChangedAnimation_(this, "pos")
@ -327,13 +306,13 @@ bool NotebookTab::isSelected() const
} }
void NotebookTab::removeNewMessageSource( void NotebookTab::removeNewMessageSource(
const HighlightSources::ChannelViewProxy &source) const HighlightSources::ChannelViewId &source)
{ {
this->highlightSources_.newMessageSource.erase(source); this->highlightSources_.newMessageSource.erase(source);
} }
void NotebookTab::removeHighlightedSource( void NotebookTab::removeHighlightedSource(
const HighlightSources::ChannelViewProxy &source) const HighlightSources::ChannelViewId &source)
{ {
this->highlightSources_.highlightedSource.erase(source); this->highlightSources_.highlightedSource.erase(source);
} }
@ -354,10 +333,12 @@ void NotebookTab::removeHighlightStateChangeSources(
void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource) void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
{ {
auto channelViewProxy = const auto &channelName = channelViewSource.underlyingChannel()->getName();
HighlightSources::ChannelViewProxy{&channelViewSource}; const auto &channelFilterIds = channelViewSource.getFilterIds();
this->removeHighlightedSource(channelViewProxy); auto channelViewId =
this->removeNewMessageSource(channelViewProxy); HighlightSources::GetChannelViewId(channelName, channelFilterIds);
this->removeHighlightedSource(channelViewId);
this->removeNewMessageSource(channelViewId);
this->updateHighlightStateDueSourcesChange(); this->updateHighlightStateDueSourcesChange();
auto *splitNotebook = dynamic_cast<SplitNotebook *>(this->notebook_); auto *splitNotebook = dynamic_cast<SplitNotebook *>(this->notebook_);
@ -372,8 +353,8 @@ void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
auto *tab = splitContainer->getTab(); auto *tab = splitContainer->getTab();
if (tab && tab != this) if (tab && tab != this)
{ {
tab->removeHighlightedSource(channelViewProxy); tab->removeHighlightedSource(channelViewId);
tab->removeNewMessageSource(channelViewProxy); tab->removeNewMessageSource(channelViewId);
tab->updateHighlightStateDueSourcesChange(); tab->updateHighlightStateDueSourcesChange();
} }
} }
@ -575,28 +556,26 @@ void NotebookTab::updateHighlightState(HighlightState newHighlightStyle,
// message is highlighting unvisible tab // message is highlighting unvisible tab
auto underlyingChannel = channelViewSource.underlyingChannel(); const auto &channelName = channelViewSource.underlyingChannel()->getName();
auto newFilters = channelViewSource.getFilterIds(); const auto &channelFilterIds = channelViewSource.getFilterIds();
auto channelViewProxy = auto channelViewId =
HighlightSources::ChannelViewProxy{&channelViewSource}; HighlightSources::GetChannelViewId(channelName, channelFilterIds);
switch (newHighlightStyle) switch (newHighlightStyle)
{ {
case HighlightState::Highlighted: { case HighlightState::Highlighted: {
if (!this->highlightSources_.highlightedSource.contains( if (!this->highlightSources_.highlightedSource.contains(
channelViewProxy)) channelViewId))
{ {
this->highlightSources_.highlightedSource.insert( this->highlightSources_.highlightedSource.insert(channelViewId);
channelViewProxy);
} }
break; break;
} }
case HighlightState::NewMessage: { case HighlightState::NewMessage: {
if (!this->highlightSources_.newMessageSource.contains( if (!this->highlightSources_.newMessageSource.contains(
channelViewProxy)) channelViewId))
{ {
this->highlightSources_.newMessageSource.insert( this->highlightSources_.newMessageSource.insert(channelViewId);
channelViewProxy);
} }
break; break;
} }

View file

@ -126,40 +126,34 @@ private:
const MessagePtr &message) const; const MessagePtr &message) const;
struct HighlightSources { struct HighlightSources {
struct ChannelViewProxy { using ChannelViewId = std::size_t;
const ChannelView *channelView;
};
struct ChannelViewProxyHash { static ChannelViewId GetChannelViewId(
using is_transparent = void; const QString &channelName, const QList<QUuid> &channelFilterIds)
std::size_t operator()(const ChannelViewProxy &cp) const noexcept; {
}; std::size_t seed = 0;
auto first = qHash(channelName);
auto second = qHash(channelFilterIds);
struct ChannelViewProxyEqual { boost::hash_combine(seed, first);
bool operator()(const ChannelViewProxy &l, boost::hash_combine(seed, second);
const ChannelViewProxy &r) const;
};
std::unordered_set<ChannelViewProxy, ChannelViewProxyHash, return seed;
ChannelViewProxyEqual> }
newMessageSource;
std::unordered_set<ChannelViewProxy, ChannelViewProxyHash, std::unordered_set<ChannelViewId> newMessageSource;
ChannelViewProxyEqual> std::unordered_set<ChannelViewId> highlightedSource;
highlightedSource;
void clear() void clear()
{ {
this->newMessageSource.clear(); this->newMessageSource.clear();
this->highlightedSource.clear(); this->highlightedSource.clear();
} }
} highlightSources_; } highlightSources_;
void removeHighlightStateChangeSources(const HighlightSources &toRemove); void removeHighlightStateChangeSources(const HighlightSources &toRemove);
void removeNewMessageSource( void removeNewMessageSource(const HighlightSources::ChannelViewId &source);
const HighlightSources::ChannelViewProxy &source); void removeHighlightedSource(const HighlightSources::ChannelViewId &source);
void removeHighlightedSource(
const HighlightSources::ChannelViewProxy &source);
void updateHighlightStateDueSourcesChange(); void updateHighlightStateDueSourcesChange();
QPropertyAnimation positionChangedAnimation_; QPropertyAnimation positionChangedAnimation_;