Use Variant instead of void* for values in the table model.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30322 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -77,20 +77,20 @@ TableColumn::GetColumnName(BString* into) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TableColumn::DrawValue(void* value, BRect rect, BView* targetView)
|
TableColumn::DrawValue(const Variant& value, BRect rect, BView* targetView)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
TableColumn::CompareValues(void* a, void* b)
|
TableColumn::CompareValues(const Variant& a, const Variant& b)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float
|
float
|
||||||
TableColumn::GetPreferredValueWidth(void* value, BView* parent) const
|
TableColumn::GetPreferredValueWidth(const Variant& value, BView* parent) const
|
||||||
{
|
{
|
||||||
return Width();
|
return Width();
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,9 @@ TableColumn::DrawField(BField* _field, BRect rect, BView* targetView)
|
|||||||
if (field == NULL)
|
if (field == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
void* value = fModel->ValueAt(field->RowIndex(), fModelIndex);
|
Variant value;
|
||||||
|
if (!fModel->GetValueAt(field->RowIndex(), fModelIndex, value))
|
||||||
|
return;
|
||||||
DrawValue(value, rect, targetView);
|
DrawValue(value, rect, targetView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,8 +124,17 @@ TableColumn::CompareFields(BField* _field1, BField* _field2)
|
|||||||
if (field2 == NULL)
|
if (field2 == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return CompareValues(fModel->ValueAt(field1->RowIndex(), fModelIndex),
|
Variant value1;
|
||||||
fModel->ValueAt(field2->RowIndex(), fModelIndex));
|
bool valid1 = fModel->GetValueAt(field1->RowIndex(), fModelIndex, value1);
|
||||||
|
Variant value2;
|
||||||
|
bool valid2 = fModel->GetValueAt(field2->RowIndex(), fModelIndex, value2);
|
||||||
|
|
||||||
|
if (!valid1)
|
||||||
|
return valid2 ? -1 : 0;
|
||||||
|
if (!valid2)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return CompareValues(value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -134,7 +145,9 @@ TableColumn::GetPreferredWidth(BField* _field, BView* parent) const
|
|||||||
if (field == NULL)
|
if (field == NULL)
|
||||||
return Width();
|
return Width();
|
||||||
|
|
||||||
void* value = fModel->ValueAt(field->RowIndex(), fModelIndex);
|
Variant value;
|
||||||
|
if (!fModel->GetValueAt(field->RowIndex(), fModelIndex, value))
|
||||||
|
return Width();
|
||||||
return GetPreferredValueWidth(value, parent);
|
return GetPreferredValueWidth(value, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,25 +172,27 @@ StringTableColumn::~StringTableColumn()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
StringTableColumn::DrawValue(void* value, BRect rect, BView* targetView)
|
StringTableColumn::DrawValue(const Variant& value, BRect rect,
|
||||||
|
BView* targetView)
|
||||||
{
|
{
|
||||||
fField.SetString((const char*)value);
|
fField.SetString(value.ToString());
|
||||||
fField.SetWidth(Width());
|
fField.SetWidth(Width());
|
||||||
fColumn.DrawField(&fField, rect, targetView);
|
fColumn.DrawField(&fField, rect, targetView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
StringTableColumn::CompareValues(void* a, void* b)
|
StringTableColumn::CompareValues(const Variant& a, const Variant& b)
|
||||||
{
|
{
|
||||||
return strcmp((const char*)a, (const char*)b);
|
return strcmp(a.ToString(), b.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float
|
float
|
||||||
StringTableColumn::GetPreferredValueWidth(void* value, BView* parent) const
|
StringTableColumn::GetPreferredValueWidth(const Variant& value,
|
||||||
|
BView* parent) const
|
||||||
{
|
{
|
||||||
fField.SetString((const char*)value);
|
fField.SetString(value.ToString());
|
||||||
fField.SetWidth(Width());
|
fField.SetWidth(Width());
|
||||||
return fColumn.GetPreferredWidth(&fField, parent);
|
return fColumn.GetPreferredWidth(&fField, parent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#include <ColumnTypes.h>
|
#include <ColumnTypes.h>
|
||||||
#include <ObjectList.h>
|
#include <ObjectList.h>
|
||||||
|
|
||||||
|
#include "Variant.h"
|
||||||
|
|
||||||
|
|
||||||
class Table;
|
class Table;
|
||||||
|
|
||||||
@@ -23,7 +25,8 @@ public:
|
|||||||
virtual void GetColumnName(int columnIndex,
|
virtual void GetColumnName(int columnIndex,
|
||||||
BString& name) const = 0;
|
BString& name) const = 0;
|
||||||
|
|
||||||
virtual void* ValueAt(int32 rowIndex, int32 columnIndex) = 0;
|
virtual bool GetValueAt(int32 rowIndex, int32 columnIndex,
|
||||||
|
Variant& value) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -43,10 +46,11 @@ protected:
|
|||||||
virtual void DrawTitle(BRect rect, BView* targetView);
|
virtual void DrawTitle(BRect rect, BView* targetView);
|
||||||
virtual void GetColumnName(BString* into) const;
|
virtual void GetColumnName(BString* into) const;
|
||||||
|
|
||||||
virtual void DrawValue(void* value, BRect rect,
|
virtual void DrawValue(const Variant& value, BRect rect,
|
||||||
BView* targetView);
|
BView* targetView);
|
||||||
virtual int CompareValues(void* a, void* b);
|
virtual int CompareValues(const Variant& a,
|
||||||
virtual float GetPreferredValueWidth(void* value,
|
const Variant& b);
|
||||||
|
virtual float GetPreferredValueWidth(const Variant& value,
|
||||||
BView* parent) const;
|
BView* parent) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -80,10 +84,11 @@ public:
|
|||||||
virtual ~StringTableColumn();
|
virtual ~StringTableColumn();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void DrawValue(void* value, BRect rect,
|
virtual void DrawValue(const Variant& value, BRect rect,
|
||||||
BView* targetView);
|
BView* targetView);
|
||||||
virtual int CompareValues(void* a, void* b);
|
virtual int CompareValues(const Variant& a,
|
||||||
virtual float GetPreferredValueWidth(void* value,
|
const Variant& b);
|
||||||
|
virtual float GetPreferredValueWidth(const Variant& value,
|
||||||
BView* parent) const;
|
BView* parent) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -61,17 +61,18 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* ValueAt(int32 rowIndex, int32 columnIndex)
|
virtual bool GetValueAt(int32 rowIndex, int32 columnIndex, Variant& value)
|
||||||
{
|
{
|
||||||
Model::Thread* thread = fModel->ThreadAt(rowIndex);
|
Model::Thread* thread = fModel->ThreadAt(rowIndex);
|
||||||
if (thread == NULL)
|
if (thread == NULL)
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
switch (columnIndex) {
|
switch (columnIndex) {
|
||||||
case 1:
|
case 1:
|
||||||
return (void*)thread->Name();
|
value.SetTo(thread->Name(), VARIANT_DONT_COPY_DATA);
|
||||||
|
return true;
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user