-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: No need to implement index for non-hierarchical models #174
Conversation
ACK 199830f Tested on macOS Big Sur 11.1 with Qt 5.15.2. Tested that there were no weird side-effects under |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think custom QModelIndex
with internal pointers are nice when it saves duplicate long lookups on the internal model. Typically, views makes lots of data(index, role)
calls and this approach increases lookups to the underlaying model. Maybe that's not a concern since views only queries data for visible items and we are using containers with O(1) lookups. Still, for addresses and transactions models it would be nice to make sure we don't make user experience worse.
@@ -196,7 +196,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const | |||
if(!index.isValid()) | |||
return QVariant(); | |||
|
|||
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer()); | |||
const AddressTableEntry* rec{priv->index(index.row())}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check if rec != nullptr
, index.isValid()
doesn't check for out of bounds.
Alternatively you could inline priv->index
and use reference instead const AddressTableEntry&
. You still need to check for out of bounds.
Right. Blind applying such changes to all models is not warranted. Closing for now. |
From Qt docs: