Qt: The `mutable` keyword exists for a reason

This commit is contained in:
Vicki Pfau 2020-06-25 18:11:16 -07:00
parent 3c73afb7a9
commit 2ec57def29
2 changed files with 3 additions and 3 deletions

View File

@ -80,7 +80,7 @@ QModelIndex ShortcutModel::index(int row, int column, const QModelIndex& parent)
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 @@ QModelIndex ShortcutModel::parent(const QModelIndex& index) const {
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);

View File

@ -44,7 +44,7 @@ private:
const Shortcut* shortcut = nullptr;
};
QHash<QString, Item> m_cache;
mutable QHash<QString, Item> m_cache;
};
}