Factored subclass DelagateBasedTableColumn out of TableColumn. This allows to

implement the TableColumn interface without a column delegate.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30323 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2009-04-22 12:16:25 +00:00
parent fc0965bb05
commit 3e9f9e8672
2 changed files with 86 additions and 45 deletions

View File

@ -39,12 +39,11 @@ TableModel::~TableModel()
// #pragma mark - TableColumn
TableColumn::TableColumn(BColumn* columnDelegate, int32 modelIndex, float width,
float minWidth, float maxWidth, alignment align)
TableColumn::TableColumn(int32 modelIndex, float width, float minWidth,
float maxWidth, alignment align)
:
BColumn(width, minWidth, maxWidth, align),
fModel(NULL),
fColumnDelegate(columnDelegate),
fModelIndex(modelIndex)
{
}
@ -62,20 +61,6 @@ TableColumn::SetTableModel(TableModel* model)
}
void
TableColumn::DrawTitle(BRect rect, BView* targetView)
{
fColumnDelegate->DrawTitle(rect, targetView);
}
void
TableColumn::GetColumnName(BString* into) const
{
fColumnDelegate->GetColumnName(into);
}
void
TableColumn::DrawValue(const Variant& value, BRect rect, BView* targetView)
{
@ -152,6 +137,54 @@ TableColumn::GetPreferredWidth(BField* _field, BView* parent) const
}
// #pragma mark - DelagateBasedTableColumn
DelagateBasedTableColumn::DelagateBasedTableColumn(BColumn* columnDelegate,
int32 modelIndex, float width, float minWidth, float maxWidth,
alignment align)
:
TableColumn(modelIndex, width, minWidth, maxWidth, align),
fColumnDelegate(columnDelegate)
{
}
DelagateBasedTableColumn::~DelagateBasedTableColumn()
{
}
void
DelagateBasedTableColumn::DrawTitle(BRect rect, BView* targetView)
{
fColumnDelegate->DrawTitle(rect, targetView);
}
void
DelagateBasedTableColumn::GetColumnName(BString* into) const
{
fColumnDelegate->GetColumnName(into);
}
void
DelagateBasedTableColumn::DrawValue(const Variant& value, BRect rect,
BView* targetView)
{
fColumnDelegate->DrawField(PrepareField(value), rect, targetView);
}
float
DelagateBasedTableColumn::GetPreferredValueWidth(const Variant& value,
BView* parent) const
{
return fColumnDelegate->GetPreferredWidth(PrepareField(value), parent);
}
// #pragma mark - StringTableColumn
@ -159,7 +192,8 @@ StringTableColumn::StringTableColumn(int32 modelIndex, const char* title,
float width, float minWidth, float maxWidth, uint32 truncate,
alignment align)
:
TableColumn(&fColumn, modelIndex, width, minWidth, maxWidth, align),
DelagateBasedTableColumn(&fColumn, modelIndex, width, minWidth, maxWidth,
align),
fColumn(title, width, minWidth, maxWidth, truncate, align),
fField("")
{
@ -171,13 +205,12 @@ StringTableColumn::~StringTableColumn()
}
void
StringTableColumn::DrawValue(const Variant& value, BRect rect,
BView* targetView)
BField*
StringTableColumn::PrepareField(const Variant& value) const
{
fField.SetString(value.ToString());
fField.SetWidth(Width());
fColumn.DrawField(&fField, rect, targetView);
return &fField;
}
@ -188,16 +221,6 @@ StringTableColumn::CompareValues(const Variant& a, const Variant& b)
}
float
StringTableColumn::GetPreferredValueWidth(const Variant& value,
BView* parent) const
{
fField.SetString(value.ToString());
fField.SetWidth(Width());
return fColumn.GetPreferredWidth(&fField, parent);
}
// #pragma mark - Table

View File

@ -30,10 +30,9 @@ public:
};
class TableColumn : private BColumn {
class TableColumn : protected BColumn {
public:
TableColumn(BColumn* columnDelegate,
int32 modelIndex, float width,
TableColumn(int32 modelIndex, float width,
float minWidth, float maxWidth,
alignment align);
virtual ~TableColumn();
@ -43,9 +42,6 @@ public:
float Width() const { return BColumn::Width(); }
protected:
virtual void DrawTitle(BRect rect, BView* targetView);
virtual void GetColumnName(BString* into) const;
virtual void DrawValue(const Variant& value, BRect rect,
BView* targetView);
virtual int CompareValues(const Variant& a,
@ -53,7 +49,7 @@ protected:
virtual float GetPreferredValueWidth(const Variant& value,
BView* parent) const;
private:
protected:
virtual void DrawField(BField* field, BRect rect,
BView* targetView);
virtual int CompareFields(BField* field1, BField* field2);
@ -69,12 +65,36 @@ private:
private:
TableModel* fModel;
BColumn* fColumnDelegate;
int32 fModelIndex;
};
class StringTableColumn : public TableColumn {
class DelagateBasedTableColumn : public TableColumn {
public:
DelagateBasedTableColumn(
BColumn* columnDelegate,
int32 modelIndex, float width,
float minWidth, float maxWidth,
alignment align);
virtual ~DelagateBasedTableColumn();
protected:
virtual void DrawTitle(BRect rect, BView* targetView);
virtual void GetColumnName(BString* into) const;
virtual void DrawValue(const Variant& value, BRect rect,
BView* targetView);
virtual float GetPreferredValueWidth(const Variant& value,
BView* parent) const;
virtual BField* PrepareField(const Variant& value) const = 0;
protected:
BColumn* fColumnDelegate;
};
class StringTableColumn : public DelagateBasedTableColumn {
public:
StringTableColumn(int32 modelIndex,
const char* title, float width,
@ -84,12 +104,10 @@ public:
virtual ~StringTableColumn();
protected:
virtual void DrawValue(const Variant& value, BRect rect,
BView* targetView);
virtual BField* PrepareField(const Variant& value) const;
virtual int CompareValues(const Variant& a,
const Variant& b);
virtual float GetPreferredValueWidth(const Variant& value,
BView* parent) const;
private:
BStringColumn fColumn;