Pulled common base class AbstractTable out of Table and TreeTable.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30682 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ff74dc2e8b
commit
b8b22908a4
70
src/apps/debuganalyzer/gui/table/AbstractTable.cpp
Normal file
70
src/apps/debuganalyzer/gui/table/AbstractTable.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "table/AbstractTable.h"
|
||||
|
||||
#include <new>
|
||||
|
||||
#include "table/TableColumn.h"
|
||||
|
||||
|
||||
// #pragma mark - AbstractTableModel
|
||||
|
||||
|
||||
AbstractTableModel::~AbstractTableModel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - AbstractColumn
|
||||
|
||||
|
||||
AbstractTable::AbstractColumn::AbstractColumn(TableColumn* tableColumn)
|
||||
:
|
||||
BColumn(tableColumn->Width(), tableColumn->MinWidth(),
|
||||
tableColumn->MaxWidth(), tableColumn->Alignment()),
|
||||
fTableColumn(tableColumn)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AbstractTable::AbstractColumn::~AbstractColumn()
|
||||
{
|
||||
delete fTableColumn;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - AbstractTable
|
||||
|
||||
|
||||
AbstractTable::AbstractTable(const char* name, uint32 flags,
|
||||
border_style borderStyle, bool showHorizontalScrollbar)
|
||||
:
|
||||
BColumnListView(name, flags, borderStyle, showHorizontalScrollbar),
|
||||
fColumns(20, true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AbstractTable::~AbstractTable()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AbstractTable::AddColumn(TableColumn* column)
|
||||
{
|
||||
if (column == NULL)
|
||||
return;
|
||||
|
||||
AbstractColumn* privateColumn = CreateColumn(column);
|
||||
|
||||
if (!fColumns.AddItem(privateColumn)) {
|
||||
delete privateColumn;
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
BColumnListView::AddColumn(privateColumn, column->ModelIndex());
|
||||
}
|
63
src/apps/debuganalyzer/gui/table/AbstractTable.h
Normal file
63
src/apps/debuganalyzer/gui/table/AbstractTable.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef ABSTRACT_TABLE_H
|
||||
#define ABSTRACT_TABLE_H
|
||||
|
||||
#include <ObjectList.h>
|
||||
#include <ColumnListView.h>
|
||||
|
||||
|
||||
class TableColumn;
|
||||
|
||||
|
||||
class AbstractTableModel {
|
||||
public:
|
||||
virtual ~AbstractTableModel();
|
||||
|
||||
virtual int32 CountColumns() const = 0;
|
||||
};
|
||||
|
||||
|
||||
class AbstractTable : protected BColumnListView {
|
||||
public:
|
||||
AbstractTable(const char* name, uint32 flags,
|
||||
border_style borderStyle = B_NO_BORDER,
|
||||
bool showHorizontalScrollbar = true);
|
||||
virtual ~AbstractTable();
|
||||
|
||||
BView* ToView() { return this; }
|
||||
|
||||
virtual void AddColumn(TableColumn* column);
|
||||
|
||||
protected:
|
||||
class AbstractColumn;
|
||||
|
||||
typedef BObjectList<AbstractColumn> ColumnList;
|
||||
|
||||
protected:
|
||||
virtual AbstractColumn* CreateColumn(TableColumn* column) = 0;
|
||||
|
||||
protected:
|
||||
ColumnList fColumns;
|
||||
};
|
||||
|
||||
|
||||
// implementation private
|
||||
|
||||
class AbstractTable::AbstractColumn : public BColumn {
|
||||
public:
|
||||
AbstractColumn(TableColumn* tableColumn);
|
||||
virtual ~AbstractColumn();
|
||||
|
||||
virtual void SetModel(AbstractTableModel* model) = 0;
|
||||
|
||||
TableColumn* GetTableColumn() const { return fTableColumn; }
|
||||
|
||||
protected:
|
||||
TableColumn* fTableColumn;
|
||||
};
|
||||
|
||||
|
||||
#endif // ABSTRACT_TABLE_H
|
@ -8,6 +8,7 @@ UseHeaders $(HAIKU_DEBUG_ANALYZER_HEADERS) ;
|
||||
|
||||
MergeObject DebugAnalyzer_gui_table.o
|
||||
:
|
||||
AbstractTable.cpp
|
||||
Table.cpp
|
||||
TableColumn.cpp
|
||||
TableColumns.cpp
|
||||
|
@ -54,13 +54,13 @@ TableListener::TableRowInvoked(Table* table, int32 rowIndex)
|
||||
// #pragma mark - Column
|
||||
|
||||
|
||||
class Table::Column : public BColumn {
|
||||
class Table::Column : public AbstractColumn {
|
||||
public:
|
||||
Column(TableModel* model,
|
||||
TableColumn* tableColumn);
|
||||
virtual ~Column();
|
||||
|
||||
void SetModel(TableModel* model);
|
||||
virtual void SetModel(AbstractTableModel* model);
|
||||
|
||||
protected:
|
||||
virtual void DrawTitle(BRect rect, BView* targetView);
|
||||
@ -74,30 +74,26 @@ protected:
|
||||
|
||||
private:
|
||||
TableModel* fModel;
|
||||
TableColumn* fTableColumn;
|
||||
};
|
||||
|
||||
|
||||
Table::Column::Column(TableModel* model, TableColumn* tableColumn)
|
||||
:
|
||||
BColumn(tableColumn->Width(), tableColumn->MinWidth(),
|
||||
tableColumn->MaxWidth(), tableColumn->Alignment()),
|
||||
fModel(model),
|
||||
fTableColumn(tableColumn)
|
||||
AbstractColumn(tableColumn),
|
||||
fModel(model)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Table::Column::~Column()
|
||||
{
|
||||
delete fTableColumn;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Table::Column::SetModel(TableModel* model)
|
||||
Table::Column::SetModel(AbstractTableModel* model)
|
||||
{
|
||||
fModel = model;
|
||||
fModel = dynamic_cast<TableModel*>(model);
|
||||
}
|
||||
|
||||
|
||||
@ -180,7 +176,7 @@ Table::Column::GetPreferredWidth(BField* _field, BView* parent) const
|
||||
Table::Table(const char* name, uint32 flags, border_style borderStyle,
|
||||
bool showHorizontalScrollbar)
|
||||
:
|
||||
BColumnListView(name, flags, borderStyle, showHorizontalScrollbar),
|
||||
AbstractTable(name, flags, borderStyle, showHorizontalScrollbar),
|
||||
fModel(NULL)
|
||||
{
|
||||
}
|
||||
@ -189,9 +185,8 @@ Table::Table(const char* name, uint32 flags, border_style borderStyle,
|
||||
Table::Table(TableModel* model, const char* name, uint32 flags,
|
||||
border_style borderStyle, bool showHorizontalScrollbar)
|
||||
:
|
||||
BColumnListView(name, flags, borderStyle, showHorizontalScrollbar),
|
||||
fModel(NULL),
|
||||
fColumns(20, true)
|
||||
AbstractTable(name, flags, borderStyle, showHorizontalScrollbar),
|
||||
fModel(NULL)
|
||||
{
|
||||
SetTableModel(model);
|
||||
}
|
||||
@ -213,7 +208,7 @@ Table::SetTableModel(TableModel* model)
|
||||
if (fModel != NULL) {
|
||||
Clear();
|
||||
|
||||
for (int32 i = 0; Column* column = fColumns.ItemAt(i); i++)
|
||||
for (int32 i = 0; AbstractColumn* column = fColumns.ItemAt(i); i++)
|
||||
column->SetModel(NULL);
|
||||
}
|
||||
|
||||
@ -222,7 +217,7 @@ Table::SetTableModel(TableModel* model)
|
||||
if (fModel == NULL)
|
||||
return;
|
||||
|
||||
for (int32 i = 0; Column* column = fColumns.ItemAt(i); i++)
|
||||
for (int32 i = 0; AbstractColumn* column = fColumns.ItemAt(i); i++)
|
||||
column->SetModel(fModel);
|
||||
|
||||
// create the rows
|
||||
@ -257,23 +252,6 @@ Table::SetTableModel(TableModel* model)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Table::AddColumn(TableColumn* column)
|
||||
{
|
||||
if (column == NULL)
|
||||
return;
|
||||
|
||||
Column* privateColumn = new Column(fModel, column);
|
||||
|
||||
if (!fColumns.AddItem(privateColumn)) {
|
||||
delete privateColumn;
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
BColumnListView::AddColumn(privateColumn, column->ModelIndex());
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Table::AddTableListener(TableListener* listener)
|
||||
{
|
||||
@ -288,6 +266,13 @@ Table::RemoveTableListener(TableListener* listener)
|
||||
}
|
||||
|
||||
|
||||
AbstractTable::AbstractColumn*
|
||||
Table::CreateColumn(TableColumn* column)
|
||||
{
|
||||
return new Column(fModel, column);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Table::ItemInvoked()
|
||||
{
|
||||
|
@ -5,10 +5,9 @@
|
||||
#ifndef TABLE_H
|
||||
#define TABLE_H
|
||||
|
||||
#include <ColumnListView.h>
|
||||
#include <ColumnTypes.h>
|
||||
#include <ObjectList.h>
|
||||
|
||||
#include "table/AbstractTable.h"
|
||||
#include "table/TableColumn.h"
|
||||
|
||||
#include "Variant.h"
|
||||
@ -17,11 +16,10 @@
|
||||
class Table;
|
||||
|
||||
|
||||
class TableModel {
|
||||
class TableModel : public AbstractTableModel {
|
||||
public:
|
||||
virtual ~TableModel();
|
||||
|
||||
virtual int32 CountColumns() const = 0;
|
||||
virtual int32 CountRows() const = 0;
|
||||
|
||||
virtual bool GetValueAt(int32 rowIndex, int32 columnIndex,
|
||||
@ -37,7 +35,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class Table : private BColumnListView {
|
||||
class Table : public AbstractTable {
|
||||
public:
|
||||
Table(const char* name, uint32 flags,
|
||||
border_style borderStyle = B_NO_BORDER,
|
||||
@ -48,20 +46,18 @@ public:
|
||||
bool showHorizontalScrollbar = true);
|
||||
virtual ~Table();
|
||||
|
||||
BView* ToView() { return this; }
|
||||
|
||||
void SetTableModel(TableModel* model);
|
||||
TableModel* GetTableModel() const { return fModel; }
|
||||
|
||||
void AddColumn(TableColumn* column);
|
||||
|
||||
bool AddTableListener(TableListener* listener);
|
||||
void RemoveTableListener(TableListener* listener);
|
||||
|
||||
protected:
|
||||
virtual AbstractColumn* CreateColumn(TableColumn* column);
|
||||
|
||||
private:
|
||||
class Column;
|
||||
|
||||
typedef BObjectList<Column> ColumnList;
|
||||
typedef BObjectList<TableListener> ListenerList;
|
||||
|
||||
private:
|
||||
@ -69,7 +65,6 @@ private:
|
||||
|
||||
private:
|
||||
TableModel* fModel;
|
||||
ColumnList fColumns;
|
||||
ListenerList fListeners;
|
||||
};
|
||||
|
||||
|
@ -54,13 +54,13 @@ TreeTableListener::TreeTableNodeInvoked(TreeTable* table, void* node)
|
||||
// #pragma mark - Column
|
||||
|
||||
|
||||
class TreeTable::Column : public BColumn {
|
||||
class TreeTable::Column : public AbstractColumn {
|
||||
public:
|
||||
Column(TreeTableModel* model,
|
||||
TableColumn* tableColumn);
|
||||
virtual ~Column();
|
||||
|
||||
void SetModel(TreeTableModel* model);
|
||||
virtual void SetModel(AbstractTableModel* model);
|
||||
|
||||
protected:
|
||||
virtual void DrawTitle(BRect rect, BView* targetView);
|
||||
@ -74,30 +74,26 @@ protected:
|
||||
|
||||
private:
|
||||
TreeTableModel* fModel;
|
||||
TableColumn* fTableColumn;
|
||||
};
|
||||
|
||||
|
||||
TreeTable::Column::Column(TreeTableModel* model, TableColumn* tableColumn)
|
||||
:
|
||||
BColumn(tableColumn->Width(), tableColumn->MinWidth(),
|
||||
tableColumn->MaxWidth(), tableColumn->Alignment()),
|
||||
fModel(model),
|
||||
fTableColumn(tableColumn)
|
||||
AbstractColumn(tableColumn),
|
||||
fModel(model)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TreeTable::Column::~Column()
|
||||
{
|
||||
delete fTableColumn;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeTable::Column::SetModel(TreeTableModel* model)
|
||||
TreeTable::Column::SetModel(AbstractTableModel* model)
|
||||
{
|
||||
fModel = model;
|
||||
fModel = dynamic_cast<TreeTableModel*>(model);
|
||||
}
|
||||
|
||||
|
||||
@ -180,7 +176,7 @@ TreeTable::Column::GetPreferredWidth(BField* _field, BView* parent) const
|
||||
TreeTable::TreeTable(const char* name, uint32 flags, border_style borderStyle,
|
||||
bool showHorizontalScrollbar)
|
||||
:
|
||||
BColumnListView(name, flags, borderStyle, showHorizontalScrollbar),
|
||||
AbstractTable(name, flags, borderStyle, showHorizontalScrollbar),
|
||||
fModel(NULL)
|
||||
{
|
||||
}
|
||||
@ -189,9 +185,8 @@ TreeTable::TreeTable(const char* name, uint32 flags, border_style borderStyle,
|
||||
TreeTable::TreeTable(TreeTableModel* model, const char* name, uint32 flags,
|
||||
border_style borderStyle, bool showHorizontalScrollbar)
|
||||
:
|
||||
BColumnListView(name, flags, borderStyle, showHorizontalScrollbar),
|
||||
fModel(NULL),
|
||||
fColumns(20, true)
|
||||
AbstractTable(name, flags, borderStyle, showHorizontalScrollbar),
|
||||
fModel(NULL)
|
||||
{
|
||||
SetTreeTableModel(model);
|
||||
}
|
||||
@ -213,7 +208,7 @@ TreeTable::SetTreeTableModel(TreeTableModel* model)
|
||||
if (fModel != NULL) {
|
||||
Clear();
|
||||
|
||||
for (int32 i = 0; Column* column = fColumns.ItemAt(i); i++)
|
||||
for (int32 i = 0; AbstractColumn* column = fColumns.ItemAt(i); i++)
|
||||
column->SetModel(NULL);
|
||||
}
|
||||
|
||||
@ -222,7 +217,7 @@ TreeTable::SetTreeTableModel(TreeTableModel* model)
|
||||
if (fModel == NULL)
|
||||
return;
|
||||
|
||||
for (int32 i = 0; Column* column = fColumns.ItemAt(i); i++)
|
||||
for (int32 i = 0; AbstractColumn* column = fColumns.ItemAt(i); i++)
|
||||
column->SetModel(fModel);
|
||||
|
||||
// recursively create the rows
|
||||
@ -267,23 +262,6 @@ TreeTable::_AddChildRows(void* parent, BRow* parentRow, int32 columnCount)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeTable::AddColumn(TableColumn* column)
|
||||
{
|
||||
if (column == NULL)
|
||||
return;
|
||||
|
||||
Column* privateColumn = new Column(fModel, column);
|
||||
|
||||
if (!fColumns.AddItem(privateColumn)) {
|
||||
delete privateColumn;
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
BColumnListView::AddColumn(privateColumn, column->ModelIndex());
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TreeTable::AddTreeTableListener(TreeTableListener* listener)
|
||||
{
|
||||
@ -298,6 +276,13 @@ TreeTable::RemoveTreeTableListener(TreeTableListener* listener)
|
||||
}
|
||||
|
||||
|
||||
AbstractTable::AbstractColumn*
|
||||
TreeTable::CreateColumn(TableColumn* column)
|
||||
{
|
||||
return new Column(fModel, column);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeTable::ItemInvoked()
|
||||
{
|
||||
|
@ -5,10 +5,9 @@
|
||||
#ifndef TREE_TABLE_H
|
||||
#define TREE_TABLE_H
|
||||
|
||||
#include <ColumnListView.h>
|
||||
#include <ColumnTypes.h>
|
||||
#include <ObjectList.h>
|
||||
|
||||
#include "table/AbstractTable.h"
|
||||
#include "table/TableColumn.h"
|
||||
|
||||
#include "Variant.h"
|
||||
@ -17,7 +16,7 @@
|
||||
class TreeTable;
|
||||
|
||||
|
||||
class TreeTableModel {
|
||||
class TreeTableModel : public AbstractTableModel {
|
||||
public:
|
||||
virtual ~TreeTableModel();
|
||||
|
||||
@ -27,8 +26,6 @@ public:
|
||||
virtual int32 CountChildren(void* parent) const = 0;
|
||||
virtual void* ChildAt(void* parent, int32 index) const = 0;
|
||||
|
||||
virtual int32 CountColumns() const = 0;
|
||||
|
||||
virtual bool GetValueAt(void* object, int32 columnIndex,
|
||||
Variant& value) = 0;
|
||||
};
|
||||
@ -43,7 +40,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class TreeTable : private BColumnListView {
|
||||
class TreeTable : public AbstractTable {
|
||||
public:
|
||||
TreeTable(const char* name, uint32 flags,
|
||||
border_style borderStyle = B_NO_BORDER,
|
||||
@ -54,22 +51,20 @@ public:
|
||||
bool showHorizontalScrollbar = true);
|
||||
virtual ~TreeTable();
|
||||
|
||||
BView* ToView() { return this; }
|
||||
|
||||
void SetTreeTableModel(TreeTableModel* model);
|
||||
TreeTableModel* GetTreeTableModel() const { return fModel; }
|
||||
|
||||
void AddColumn(TableColumn* column);
|
||||
|
||||
bool AddTreeTableListener(
|
||||
TreeTableListener* listener);
|
||||
void RemoveTreeTableListener(
|
||||
TreeTableListener* listener);
|
||||
|
||||
protected:
|
||||
virtual AbstractColumn* CreateColumn(TableColumn* column);
|
||||
|
||||
private:
|
||||
class Column;
|
||||
|
||||
typedef BObjectList<Column> ColumnList;
|
||||
typedef BObjectList<TreeTableListener> ListenerList;
|
||||
|
||||
private:
|
||||
@ -78,10 +73,8 @@ private:
|
||||
void _AddChildRows(void* parent, BRow* parentRow,
|
||||
int32 columnCount);
|
||||
|
||||
|
||||
private:
|
||||
TreeTableModel* fModel;
|
||||
ColumnList fColumns;
|
||||
ListenerList fListeners;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user