* TableColumn no longer has BColumn as base class. We use another level of
indirection (Table::Column) instead. * Moved TableColumn to its own header/source files. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30414 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -9,5 +9,6 @@ UseHeaders $(HAIKU_DEBUG_ANALYZER_HEADERS) ;
|
|||||||
MergeObject DebugAnalyzer_gui_table.o
|
MergeObject DebugAnalyzer_gui_table.o
|
||||||
:
|
:
|
||||||
Table.cpp
|
Table.cpp
|
||||||
|
TableColumn.cpp
|
||||||
TableColumns.cpp
|
TableColumns.cpp
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -36,67 +36,94 @@ TableModel::~TableModel()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - TableColumn
|
// #pragma mark - TableListener
|
||||||
|
|
||||||
|
|
||||||
TableColumn::TableColumn(int32 modelIndex, float width, float minWidth,
|
TableListener::~TableListener()
|
||||||
float maxWidth, alignment align)
|
|
||||||
:
|
|
||||||
BColumn(width, minWidth, maxWidth, align),
|
|
||||||
fModel(NULL),
|
|
||||||
fModelIndex(modelIndex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TableColumn::~TableColumn()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TableColumn::SetTableModel(TableModel* model)
|
TableListener::TableRowInvoked(Table* table, int32 rowIndex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - Column
|
||||||
|
|
||||||
|
|
||||||
|
class Table::Column : public BColumn {
|
||||||
|
public:
|
||||||
|
Column(TableModel* model,
|
||||||
|
TableColumn* tableColumn);
|
||||||
|
virtual ~Column();
|
||||||
|
|
||||||
|
void SetTableModel(TableModel* model);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void DrawTitle(BRect rect, BView* targetView);
|
||||||
|
virtual void DrawField(BField* field, BRect rect,
|
||||||
|
BView* targetView);
|
||||||
|
virtual int CompareFields(BField* field1, BField* field2);
|
||||||
|
|
||||||
|
virtual void GetColumnName(BString* into) const;
|
||||||
|
virtual float GetPreferredWidth(BField* field,
|
||||||
|
BView* parent) const;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Table::Column::~Column()
|
||||||
|
{
|
||||||
|
delete fTableColumn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Table::Column::SetTableModel(TableModel* model)
|
||||||
{
|
{
|
||||||
fModel = model;
|
fModel = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TableColumn::DrawValue(const Variant& value, BRect rect, BView* targetView)
|
Table::Column::DrawTitle(BRect rect, BView* targetView)
|
||||||
{
|
{
|
||||||
}
|
fTableColumn->DrawTitle(rect, targetView);
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
TableColumn::CompareValues(const Variant& a, const Variant& b)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
float
|
|
||||||
TableColumn::GetPreferredValueWidth(const Variant& value, BView* parent) const
|
|
||||||
{
|
|
||||||
return Width();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TableColumn::DrawField(BField* _field, BRect rect, BView* targetView)
|
Table::Column::DrawField(BField* _field, BRect rect, BView* targetView)
|
||||||
{
|
{
|
||||||
TableField* field = dynamic_cast<TableField*>(_field);
|
TableField* field = dynamic_cast<TableField*>(_field);
|
||||||
if (field == NULL)
|
if (field == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
int32 modelIndex = fTableColumn->ModelIndex();
|
||||||
Variant value;
|
Variant value;
|
||||||
if (!fModel->GetValueAt(field->RowIndex(), fModelIndex, value))
|
if (!fModel->GetValueAt(field->RowIndex(), modelIndex, value))
|
||||||
return;
|
return;
|
||||||
DrawValue(value, rect, targetView);
|
fTableColumn->DrawValue(value, rect, targetView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
TableColumn::CompareFields(BField* _field1, BField* _field2)
|
Table::Column::CompareFields(BField* _field1, BField* _field2)
|
||||||
{
|
{
|
||||||
TableField* field1 = dynamic_cast<TableField*>(_field1);
|
TableField* field1 = dynamic_cast<TableField*>(_field1);
|
||||||
TableField* field2 = dynamic_cast<TableField*>(_field2);
|
TableField* field2 = dynamic_cast<TableField*>(_field2);
|
||||||
@@ -109,45 +136,40 @@ TableColumn::CompareFields(BField* _field1, BField* _field2)
|
|||||||
if (field2 == NULL)
|
if (field2 == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
int32 modelIndex = fTableColumn->ModelIndex();
|
||||||
Variant value1;
|
Variant value1;
|
||||||
bool valid1 = fModel->GetValueAt(field1->RowIndex(), fModelIndex, value1);
|
bool valid1 = fModel->GetValueAt(field1->RowIndex(), modelIndex, value1);
|
||||||
Variant value2;
|
Variant value2;
|
||||||
bool valid2 = fModel->GetValueAt(field2->RowIndex(), fModelIndex, value2);
|
bool valid2 = fModel->GetValueAt(field2->RowIndex(), modelIndex, value2);
|
||||||
|
|
||||||
if (!valid1)
|
if (!valid1)
|
||||||
return valid2 ? -1 : 0;
|
return valid2 ? -1 : 0;
|
||||||
if (!valid2)
|
if (!valid2)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return CompareValues(value1, value2);
|
return fTableColumn->CompareValues(value1, value2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Table::Column::GetColumnName(BString* into) const
|
||||||
|
{
|
||||||
|
fTableColumn->GetColumnName(into);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float
|
float
|
||||||
TableColumn::GetPreferredWidth(BField* _field, BView* parent) const
|
Table::Column::GetPreferredWidth(BField* _field, BView* parent) const
|
||||||
{
|
{
|
||||||
TableField* field = dynamic_cast<TableField*>(_field);
|
TableField* field = dynamic_cast<TableField*>(_field);
|
||||||
if (field == NULL)
|
if (field == NULL)
|
||||||
return Width();
|
return Width();
|
||||||
|
|
||||||
|
int32 modelIndex = fTableColumn->ModelIndex();
|
||||||
Variant value;
|
Variant value;
|
||||||
if (!fModel->GetValueAt(field->RowIndex(), fModelIndex, value))
|
if (!fModel->GetValueAt(field->RowIndex(), modelIndex, value))
|
||||||
return Width();
|
return Width();
|
||||||
return GetPreferredValueWidth(value, parent);
|
return fTableColumn->GetPreferredWidth(value, parent);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - TableListener
|
|
||||||
|
|
||||||
|
|
||||||
TableListener::~TableListener()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TableListener::TableRowInvoked(Table* table, int32 rowIndex)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -190,7 +212,7 @@ Table::SetTableModel(TableModel* model)
|
|||||||
if (fModel != NULL) {
|
if (fModel != NULL) {
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
for (int32 i = 0; TableColumn* column = fColumns.ItemAt(i); i++)
|
for (int32 i = 0; Column* column = fColumns.ItemAt(i); i++)
|
||||||
column->SetTableModel(NULL);
|
column->SetTableModel(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +221,7 @@ Table::SetTableModel(TableModel* model)
|
|||||||
if (fModel == NULL)
|
if (fModel == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int32 i = 0; TableColumn* column = fColumns.ItemAt(i); i++)
|
for (int32 i = 0; Column* column = fColumns.ItemAt(i); i++)
|
||||||
column->SetTableModel(fModel);
|
column->SetTableModel(fModel);
|
||||||
|
|
||||||
// create the rows
|
// create the rows
|
||||||
@@ -240,12 +262,14 @@ Table::AddColumn(TableColumn* column)
|
|||||||
if (column == NULL)
|
if (column == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!fColumns.AddItem(column))
|
Column* privateColumn = new Column(fModel, column);
|
||||||
|
|
||||||
|
if (!fColumns.AddItem(privateColumn)) {
|
||||||
|
delete privateColumn;
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
|
||||||
column->SetTableModel(fModel);
|
BColumnListView::AddColumn(privateColumn, column->ModelIndex());
|
||||||
|
|
||||||
BColumnListView::AddColumn(column, column->ModelIndex());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#include <ColumnTypes.h>
|
#include <ColumnTypes.h>
|
||||||
#include <ObjectList.h>
|
#include <ObjectList.h>
|
||||||
|
|
||||||
|
#include "table/TableColumn.h"
|
||||||
|
|
||||||
#include "Variant.h"
|
#include "Variant.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -27,45 +29,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class TableColumn : protected BColumn {
|
|
||||||
public:
|
|
||||||
TableColumn(int32 modelIndex, float width,
|
|
||||||
float minWidth, float maxWidth,
|
|
||||||
alignment align);
|
|
||||||
virtual ~TableColumn();
|
|
||||||
|
|
||||||
int32 ModelIndex() const { return fModelIndex; }
|
|
||||||
|
|
||||||
float Width() const { return BColumn::Width(); }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void DrawValue(const Variant& value, BRect rect,
|
|
||||||
BView* targetView);
|
|
||||||
virtual int CompareValues(const Variant& a,
|
|
||||||
const Variant& b);
|
|
||||||
virtual float GetPreferredValueWidth(const Variant& value,
|
|
||||||
BView* parent) const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void DrawField(BField* field, BRect rect,
|
|
||||||
BView* targetView);
|
|
||||||
virtual int CompareFields(BField* field1, BField* field2);
|
|
||||||
|
|
||||||
virtual float GetPreferredWidth(BField* field,
|
|
||||||
BView* parent) const;
|
|
||||||
|
|
||||||
void SetTableModel(TableModel* model);
|
|
||||||
// package private
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class Table;
|
|
||||||
|
|
||||||
private:
|
|
||||||
TableModel* fModel;
|
|
||||||
int32 fModelIndex;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class TableListener {
|
class TableListener {
|
||||||
public:
|
public:
|
||||||
virtual ~TableListener();
|
virtual ~TableListener();
|
||||||
@@ -96,7 +59,9 @@ public:
|
|||||||
void RemoveTableListener(TableListener* listener);
|
void RemoveTableListener(TableListener* listener);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef BObjectList<TableColumn> ColumnList;
|
class Column;
|
||||||
|
|
||||||
|
typedef BObjectList<Column> ColumnList;
|
||||||
typedef BObjectList<TableListener> ListenerList;
|
typedef BObjectList<TableListener> ListenerList;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ DelagateBasedTableColumn::DrawValue(const Variant& value, BRect rect,
|
|||||||
|
|
||||||
|
|
||||||
float
|
float
|
||||||
DelagateBasedTableColumn::GetPreferredValueWidth(const Variant& value,
|
DelagateBasedTableColumn::GetPreferredWidth(const Variant& value,
|
||||||
BView* parent) const
|
BView* parent) const
|
||||||
{
|
{
|
||||||
return fColumnDelegate->GetPreferredWidth(PrepareField(value), parent);
|
return fColumnDelegate->GetPreferredWidth(PrepareField(value), parent);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include <ColumnTypes.h>
|
#include <ColumnTypes.h>
|
||||||
|
|
||||||
#include "table/Table.h"
|
#include "table/TableColumn.h"
|
||||||
|
|
||||||
|
|
||||||
class DelagateBasedTableColumn : public TableColumn {
|
class DelagateBasedTableColumn : public TableColumn {
|
||||||
@@ -25,7 +25,7 @@ protected:
|
|||||||
|
|
||||||
virtual void DrawValue(const Variant& value, BRect rect,
|
virtual void DrawValue(const Variant& value, BRect rect,
|
||||||
BView* targetView);
|
BView* targetView);
|
||||||
virtual float GetPreferredValueWidth(const Variant& value,
|
virtual float GetPreferredWidth(const Variant& value,
|
||||||
BView* parent) const;
|
BView* parent) const;
|
||||||
|
|
||||||
virtual BField* PrepareField(const Variant& value) const = 0;
|
virtual BField* PrepareField(const Variant& value) const = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user