From a7fb35d93ddef70d6e5b7953e0482a048d4c72b5 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 12 Oct 2009 03:14:34 +0000 Subject: [PATCH] When rows are added to/removed from the model, we need to adjust the row indices we store in the fields of subsequent BRows. Fixes the broken threads list in Debugger (should be some ticket -- can't access Trac ATM). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33539 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/debuganalyzer/gui/table/Table.cpp | 27 ++++++++++++++++++++++ src/apps/debuganalyzer/gui/table/Table.h | 1 + 2 files changed, 28 insertions(+) diff --git a/src/apps/debuganalyzer/gui/table/Table.cpp b/src/apps/debuganalyzer/gui/table/Table.cpp index fd37a385df..b7773f37b2 100644 --- a/src/apps/debuganalyzer/gui/table/Table.cpp +++ b/src/apps/debuganalyzer/gui/table/Table.cpp @@ -24,6 +24,11 @@ public: return fRowIndex; } + void SetRowIndex(int32 rowIndex) + { + fRowIndex = rowIndex; + } + private: int32 fRowIndex; }; @@ -508,18 +513,27 @@ Table::TableRowsAdded(TableModel* model, int32 rowIndex, int32 count) AddRow(row, i); } + + // re-index the subsequent rows + _UpdateRowIndices(endRow); } void Table::TableRowsRemoved(TableModel* model, int32 rowIndex, int32 count) { + int32 rowsRemoved = 0; + for (int32 i = rowIndex + count - 1; i >= rowIndex; i--) { if (BRow* row = fRows.RemoveItemAt(i)) { RemoveRow(row); delete row; + rowsRemoved++; } } + + // re-index the subsequent rows + _UpdateRowIndices(rowIndex); } @@ -550,6 +564,19 @@ Table::ItemInvoked() } +void +Table::_UpdateRowIndices(int32 fromIndex) +{ + for (int32 i = fromIndex; BRow* row = fRows.ItemAt(i); i++) { + for (int32 k = 0; + TableField* field = dynamic_cast(row->GetField(k)); + k++) { + field->SetRowIndex(i); + } + } +} + + int32 Table::_ModelIndexOfRow(BRow* row) { diff --git a/src/apps/debuganalyzer/gui/table/Table.h b/src/apps/debuganalyzer/gui/table/Table.h index cd734517ff..57901c713b 100644 --- a/src/apps/debuganalyzer/gui/table/Table.h +++ b/src/apps/debuganalyzer/gui/table/Table.h @@ -135,6 +135,7 @@ private: private: virtual void ItemInvoked(); + void _UpdateRowIndices(int32 fromIndex); int32 _ModelIndexOfRow(BRow* row); private: