From Qt docs:
If our model was hierarchical, we would also have to implement the
index()andparent()functions.
Default implementations of the
index()andparent()functions are provided byQAbstractTableModel.
From Qt docs:
If our model was hierarchical, we would also have to implement the
index()andparent()functions.
Default implementations of the
index()andparent()functions are provided byQAbstractTableModel.
ACK 199830ff920825f5306555e9f6fc08be8534e9bb
Tested on macOS Big Sur 11.1 with Qt 5.15.2. Tested that there were no weird side-effects under Transactions and the Peers Window. This is a welcome change as it adheres to the Qt docs and removes unnecessary code.
195 | @@ -196,7 +196,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const 196 | if(!index.isValid()) 197 | return QVariant(); 198 | 199 | - AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer()); 200 | + const AddressTableEntry* rec{priv->index(index.row())};
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.
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.