all repos — mgba @ 2ec57def29358df37ea5ed0a145bc34d68fad23f

mGBA Game Boy Advance Emulator

Qt: The `mutable` keyword exists for a reason
Vicki Pfau vi@endrift.com
Thu, 25 Jun 2020 18:11:16 -0700
commit

2ec57def29358df37ea5ed0a145bc34d68fad23f

parent

3c73afb7a94e3fab0adc45b04093b3f96fdbe147

2 files changed, 3 insertions(+), 3 deletions(-)

jump to
M src/platform/qt/ShortcutModel.cppsrc/platform/qt/ShortcutModel.cpp

@@ -80,7 +80,7 @@ if (parent.isValid()) {

pmenu = static_cast<Item*>(parent.internalPointer())->name; } QString name = m_controller->name(row, pmenu); - Item* item = &(*const_cast<QHash<QString, Item>*>(&m_cache))[name]; + Item* item = &m_cache[name]; item->name = name; item->shortcut = m_controller->shortcut(name); return createIndex(row, column, item);

@@ -95,7 +95,7 @@ QString parent = m_controller->parent(item->name);

if (parent.isNull()) { return QModelIndex(); } - Item* pitem = &(*const_cast<QHash<QString, Item>*>(&m_cache))[parent]; + Item* pitem = &m_cache[parent]; pitem->name = parent; pitem->shortcut = m_controller->shortcut(parent); return createIndex(m_controller->indexIn(parent), 0, pitem);
M src/platform/qt/ShortcutModel.hsrc/platform/qt/ShortcutModel.h

@@ -44,7 +44,7 @@ QString name;

const Shortcut* shortcut = nullptr; }; - QHash<QString, Item> m_cache; + mutable QHash<QString, Item> m_cache; }; }