Extend Table/TreeTable's interface.
- Add NotifyNodesCleared() hook to table model as a shortcut for removing all rows. - TreeTable::_RemoveChildRows() now recognizes the special case of the above and optimizes it by calling BColumnListView::Clear() rather than removing each row individually. - Add TableModelReset()/NotifyTableModelReset(). This notification is used to tell the underlying table that a full rebuild is needed due to the model changing completely.
This commit is contained in:
@@ -63,6 +63,12 @@ TableModelListener::TableRowsChanged(TableModel* model, int32 rowIndex,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TableModelListener::TableModelReset(TableModel* model)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - TableModel
|
||||
|
||||
|
||||
@@ -118,6 +124,28 @@ TableModel::NotifyRowsChanged(int32 rowIndex, int32 count)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TableModel::NotifyRowsCleared()
|
||||
{
|
||||
int32 listenerCount = fListeners.CountItems();
|
||||
for (int32 i = listenerCount - 1; i >= 0; i--) {
|
||||
TableModelListener* listener = fListeners.ItemAt(i);
|
||||
listener->TableRowsRemoved(this, 0, CountRows());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TableModel::NotifyTableModelReset()
|
||||
{
|
||||
int32 listenerCount = fListeners.CountItems();
|
||||
for (int32 i = listenerCount - 1; i >= 0; i--) {
|
||||
TableModelListener* listener = fListeners.ItemAt(i);
|
||||
listener->TableModelReset(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - TableSelectionModel
|
||||
|
||||
TableSelectionModel::TableSelectionModel(Table* table)
|
||||
@@ -639,6 +667,14 @@ Table::TableRowsChanged(TableModel* model, int32 rowIndex, int32 count)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Table::TableModelReset(TableModel* model)
|
||||
{
|
||||
Clear();
|
||||
TableRowsAdded(model, 0, model->CountRows());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Table::ItemInvoked()
|
||||
{
|
||||
|
||||
@@ -29,6 +29,7 @@ public:
|
||||
int32 rowIndex, int32 count);
|
||||
virtual void TableRowsChanged(TableModel* model,
|
||||
int32 rowIndex, int32 count);
|
||||
virtual void TableModelReset(TableModel* model);
|
||||
};
|
||||
|
||||
|
||||
@@ -51,6 +52,8 @@ protected:
|
||||
void NotifyRowsAdded(int32 rowIndex, int32 count);
|
||||
void NotifyRowsRemoved(int32 rowIndex, int32 count);
|
||||
void NotifyRowsChanged(int32 rowIndex, int32 count);
|
||||
void NotifyRowsCleared();
|
||||
void NotifyTableModelReset();
|
||||
|
||||
protected:
|
||||
ListenerList fListeners;
|
||||
@@ -154,6 +157,7 @@ private:
|
||||
int32 rowIndex, int32 count);
|
||||
virtual void TableRowsChanged(TableModel* model,
|
||||
int32 rowIndex, int32 count);
|
||||
virtual void TableModelReset(TableModel* model);
|
||||
|
||||
private:
|
||||
class Column;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Copyright 2012, Rene Gollent, [email protected].
|
||||
* Copyright 2012-2013, Rene Gollent, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@@ -156,6 +156,12 @@ TreeTableModelListener::TableNodesChanged(TreeTableModel* model,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeTableModelListener::TableModelReset(TreeTableModel* model)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - TreeTableModel
|
||||
|
||||
|
||||
@@ -227,6 +233,28 @@ TreeTableModel::NotifyNodesChanged(const TreeTablePath& path, int32 childIndex,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeTableModel::NotifyNodesCleared()
|
||||
{
|
||||
int32 listenerCount = fListeners.CountItems();
|
||||
for (int32 i = listenerCount - 1; i >= 0; i--) {
|
||||
TreeTableModelListener* listener = fListeners.ItemAt(i);
|
||||
listener->TableNodesRemoved(this, TreeTablePath(), 0,
|
||||
CountChildren(Root()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeTableModel::NotifyTableModelReset()
|
||||
{
|
||||
int32 listenerCount = fListeners.CountItems();
|
||||
for (int32 i = listenerCount - 1; i >= 0; i--) {
|
||||
TreeTableModelListener* listener = fListeners.ItemAt(i);
|
||||
listener->TableModelReset(this);
|
||||
}
|
||||
}
|
||||
|
||||
// #pragma mark - TreeTableToolTipProvider
|
||||
|
||||
|
||||
@@ -965,6 +993,15 @@ TreeTable::TableNodesChanged(TreeTableModel* model, const TreeTablePath& path,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeTable::TableModelReset(TreeTableModel* model)
|
||||
{
|
||||
_RemoveChildRows(fRootNode, 0, fRootNode->CountChildren());
|
||||
_AddChildRows(fRootNode, 0, fModel->CountChildren(
|
||||
fModel->Root()), fModel->CountColumns());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeTable::ExpandOrCollapse(BRow* _row, bool expand)
|
||||
{
|
||||
@@ -1038,6 +1075,14 @@ void
|
||||
TreeTable::_RemoveChildRows(TreeTableNode* parentNode, int32 childIndex,
|
||||
int32 count)
|
||||
{
|
||||
// check if the removal request would in effect remove all
|
||||
// existing nodes.
|
||||
if (parentNode == fRootNode && childIndex == 0
|
||||
&& count == parentNode->CountChildren()) {
|
||||
Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
for (int32 i = childIndex + count - 1; i >= childIndex; i--) {
|
||||
if (TreeTableNode* child = parentNode->RemoveChild(i)) {
|
||||
int32 childCount = child->CountChildren();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Copyright 2012, Rene Gollent, rene@gollent.com.
|
||||
* Copyright 2012-2013, Rene Gollent, rene@gollent.com.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef TREE_TABLE_H
|
||||
@@ -61,6 +61,7 @@ public:
|
||||
virtual void TableNodesChanged(TreeTableModel* model,
|
||||
const TreeTablePath& path, int32 childIndex,
|
||||
int32 count);
|
||||
virtual void TableModelReset(TreeTableModel* model);
|
||||
};
|
||||
|
||||
|
||||
@@ -93,6 +94,8 @@ protected:
|
||||
int32 childIndex, int32 count);
|
||||
void NotifyNodesChanged(const TreeTablePath& path,
|
||||
int32 childIndex, int32 count);
|
||||
void NotifyNodesCleared();
|
||||
void NotifyTableModelReset();
|
||||
|
||||
protected:
|
||||
ListenerList fListeners;
|
||||
@@ -217,6 +220,7 @@ private:
|
||||
virtual void TableNodesChanged(TreeTableModel* model,
|
||||
const TreeTablePath& path, int32 childIndex,
|
||||
int32 count);
|
||||
virtual void TableModelReset(TreeTableModel* model);
|
||||
|
||||
private:
|
||||
class Column;
|
||||
|
||||
Reference in New Issue
Block a user