fix: reset wide bar settings when the list of actions changes
This prevents changes to the actions to cause non-intuitive issues in the Wide bar, hiding items that previously weren't hidden. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
2d69d63efe
commit
20c281d6f8
@ -1,6 +1,7 @@
|
|||||||
#include "WideBar.h"
|
#include "WideBar.h"
|
||||||
|
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
|
#include <QCryptographicHash>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
|
||||||
class ActionButton : public QToolButton {
|
class ActionButton : public QToolButton {
|
||||||
@ -211,23 +212,53 @@ void WideBar::contextMenuEvent(QContextMenuEvent* event)
|
|||||||
state.append(entry.bar_action->isVisible() ? '1' : '0');
|
state.append(entry.bar_action->isVisible() ? '1' : '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state.append(',');
|
||||||
|
state.append(getHash());
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WideBar::setVisibilityState(QByteArray&& state)
|
void WideBar::setVisibilityState(QByteArray&& state)
|
||||||
{
|
{
|
||||||
|
auto split = state.split(',');
|
||||||
|
|
||||||
|
auto bits = split.first();
|
||||||
|
auto hash = split.last();
|
||||||
|
|
||||||
|
// If the actions changed, we better not try to load the old one to avoid unwanted hiding
|
||||||
|
if (!checkHash(hash))
|
||||||
|
return;
|
||||||
|
|
||||||
qsizetype i = 0;
|
qsizetype i = 0;
|
||||||
for (auto& entry : m_entries) {
|
for (auto& entry : m_entries) {
|
||||||
if (entry.type != BarEntry::Type::Action)
|
if (entry.type != BarEntry::Type::Action)
|
||||||
continue;
|
continue;
|
||||||
if (i == state.size())
|
if (i == bits.size())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
entry.bar_action->setVisible(state.at(i++) == '1');
|
entry.bar_action->setVisible(bits.at(i++) == '1');
|
||||||
|
|
||||||
// NOTE: This is needed so that disabled actions get reflected on the button when it is made visible.
|
// NOTE: This is needed so that disabled actions get reflected on the button when it is made visible.
|
||||||
static_cast<ActionButton*>(widgetForAction(entry.bar_action))->actionChanged();
|
static_cast<ActionButton*>(widgetForAction(entry.bar_action))->actionChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray WideBar::getHash() const
|
||||||
|
{
|
||||||
|
QCryptographicHash hash(QCryptographicHash::Sha1);
|
||||||
|
for (auto const& entry : m_entries) {
|
||||||
|
if (entry.type != BarEntry::Type::Action)
|
||||||
|
continue;
|
||||||
|
hash.addData(entry.menu_action->text().toLatin1());
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash.result().toBase64();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WideBar::checkHash(QByteArray const& old_hash) const
|
||||||
|
{
|
||||||
|
return old_hash == getHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#include "WideBar.moc"
|
#include "WideBar.moc"
|
||||||
|
@ -41,6 +41,10 @@ class WideBar : public QToolBar {
|
|||||||
|
|
||||||
auto getMatching(QAction* act) -> QList<BarEntry>::iterator;
|
auto getMatching(QAction* act) -> QList<BarEntry>::iterator;
|
||||||
|
|
||||||
|
/** Used to distinguish between versions of the WideBar with different actions */
|
||||||
|
[[nodiscard]] QByteArray getHash() const;
|
||||||
|
[[nodiscard]] bool checkHash(QByteArray const&) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<BarEntry> m_entries;
|
QList<BarEntry> m_entries;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user