Skip to content
Bitcoin Roots

v31.1-roots.1 · Commit 5: [PATCH 05/17] feat(net): preserve Roots peer controls and health view on v31

src/qt/peertablemodel.cpp

Before: src/qt/peertablemodel.cpp · After: src/qt/peertablemodel.cpp

File metadata
index 3c0dedfcc7d08928c2c94c20ded5589b1036cf00..6888d1d93b92ab20de0f98398b3e8cc8557625e8 100644

Download original patch · Release notes

Diff rows 1–33 of 33. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.

src/qt/peertablemodel.cpp CHANGED
@@ -57,10 +57,11 @@ int PeerTableModel::columnCount(const QModelIndex& parent) const
57
57
 
58
58
  QVariant PeerTableModel::data(const QModelIndex& index, int role) const
59
59
  {
60
- if(!index.isValid())
60
+ if (!index.isValid() || index.row() >= m_peers_data.size())
61
61
  return QVariant();
62
62
 
63
- CNodeCombinedStats *rec = static_cast<CNodeCombinedStats*>(index.internalPointer());
63
+ // Refresh swaps the storage; persistent indexes must resolve the current row.
64
+ auto* rec = const_cast<CNodeCombinedStats*>(&m_peers_data[index.row()]);
64
65
 
65
66
  const auto column = static_cast<ColumnIndex>(index.column());
66
67
  if (role == Qt::DisplayRole) {
@@ -142,7 +143,7 @@ QModelIndex PeerTableModel::index(int row, int column, const QModelIndex& parent
142
143
  Q_UNUSED(parent);
143
144
 
144
145
  if (0 <= row && row < rowCount() && 0 <= column && column < columnCount()) {
145
- return createIndex(row, column, const_cast<CNodeCombinedStats*>(&m_peers_data[row]));
146
+ return createIndex(row, column);
146
147
  }
147
148
 
148
149
  return QModelIndex();
@@ -184,7 +185,9 @@ void PeerTableModel::refresh()
184
185
  m_peers_data.swap(new_peers_data);
185
186
  }
186
187
 
187
- const auto top_left = index(0, 0);
188
- const auto bottom_right = index(rowCount() - 1, columnCount() - 1);
189
- Q_EMIT dataChanged(top_left, bottom_right);
188
+ if (rowCount() > 0) {
189
+ const auto top_left = index(0, 0);
190
+ const auto bottom_right = index(rowCount() - 1, columnCount() - 1);
191
+ Q_EMIT dataChanged(top_left, bottom_right);
192
+ }
190
193
  }