Added BoolStringTableColumn for boolean values.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33579 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "table/TableColumns.h"
|
#include "table/TableColumns.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -92,6 +93,38 @@ StringTableColumn::CompareValues(const BVariant& a, const BVariant& b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - BoolStringTableColumn
|
||||||
|
|
||||||
|
|
||||||
|
BoolStringTableColumn::BoolStringTableColumn(int32 modelIndex, const char* title,
|
||||||
|
float width, float minWidth, float maxWidth, const BString& trueString,
|
||||||
|
const BString& falseString, uint32 truncate, alignment align)
|
||||||
|
:
|
||||||
|
StringTableColumn(modelIndex, title, width, minWidth, maxWidth, truncate,
|
||||||
|
align),
|
||||||
|
fTrueString(trueString),
|
||||||
|
fFalseString(falseString)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BField*
|
||||||
|
BoolStringTableColumn::PrepareField(const BVariant& value) const
|
||||||
|
{
|
||||||
|
return StringTableColumn::PrepareField(
|
||||||
|
BVariant(value.ToBool() ? fTrueString : fFalseString,
|
||||||
|
B_VARIANT_DONT_COPY_DATA));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
BoolStringTableColumn::CompareValues(const BVariant& a, const BVariant& b)
|
||||||
|
{
|
||||||
|
bool aValue = a.ToBool();
|
||||||
|
return aValue == b.ToBool() ? 0 : (aValue ? 1 : -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - Int32TableColumn
|
// #pragma mark - Int32TableColumn
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#ifndef TABLE_COLUMNS_H
|
#ifndef TABLE_COLUMNS_H
|
||||||
#define TABLE_COLUMNS_H
|
#define TABLE_COLUMNS_H
|
||||||
|
|
||||||
|
|
||||||
#include <ColumnTypes.h>
|
#include <ColumnTypes.h>
|
||||||
|
|
||||||
#include "table/TableColumn.h"
|
#include "table/TableColumn.h"
|
||||||
@@ -56,6 +57,28 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class BoolStringTableColumn : public StringTableColumn {
|
||||||
|
public:
|
||||||
|
BoolStringTableColumn(int32 modelIndex,
|
||||||
|
const char* title, float width,
|
||||||
|
float minWidth, float maxWidth,
|
||||||
|
const BString& trueString = "true",
|
||||||
|
const BString& falseString = "false",
|
||||||
|
uint32 truncate = B_TRUNCATE_MIDDLE,
|
||||||
|
alignment align = B_ALIGN_LEFT);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual BField* PrepareField(const BVariant& value) const;
|
||||||
|
|
||||||
|
virtual int CompareValues(const BVariant& a,
|
||||||
|
const BVariant& b);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BString fTrueString;
|
||||||
|
BString fFalseString;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Int32TableColumn : public StringTableColumn {
|
class Int32TableColumn : public StringTableColumn {
|
||||||
public:
|
public:
|
||||||
Int32TableColumn(int32 modelIndex,
|
Int32TableColumn(int32 modelIndex,
|
||||||
|
|||||||
Reference in New Issue
Block a user