mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 19:38:12 +00:00
LibGUI: Add 64-bit signed integer support to GVariant
What was previously the "Int" type is now "Int32" and "Int64".
This commit is contained in:
parent
137a45dff2
commit
6906edee9a
8 changed files with 120 additions and 64 deletions
|
@ -282,7 +282,7 @@ void DirectoryView::update_statusbar()
|
||||||
current_view().selection().for_each_index([&](auto& index) {
|
current_view().selection().for_each_index([&](auto& index) {
|
||||||
auto& model = *current_view().model();
|
auto& model = *current_view().model();
|
||||||
auto size_index = model.sibling(index.row(), GFileSystemModel::Column::Size, model.parent_index(index));
|
auto size_index = model.sibling(index.row(), GFileSystemModel::Column::Size, model.parent_index(index));
|
||||||
auto file_size = model.data(size_index).to_int();
|
auto file_size = model.data(size_index).to_i32();
|
||||||
selected_byte_count += file_size;
|
selected_byte_count += file_size;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -56,5 +56,5 @@ pid_t ProcessTableView::selected_pid() const
|
||||||
{
|
{
|
||||||
if (selection().is_empty())
|
if (selection().is_empty())
|
||||||
return -1;
|
return -1;
|
||||||
return model()->data(model()->index(selection().first().row(), ProcessModel::Column::PID), GModel::Role::Sort).as_int();
|
return model()->data(model()->index(selection().first().row(), ProcessModel::Column::PID), GModel::Role::Sort).as_i32();
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,7 +258,7 @@ public:
|
||||||
virtual void paint(GPainter& painter, const Rect& a_rect, const Palette& palette, const GModel& model, const GModelIndex& index) override
|
virtual void paint(GPainter& painter, const Rect& a_rect, const Palette& palette, const GModel& model, const GModelIndex& index) override
|
||||||
{
|
{
|
||||||
auto rect = a_rect.shrunken(2, 2);
|
auto rect = a_rect.shrunken(2, 2);
|
||||||
auto percentage = model.data(index, GModel::Role::Custom).to_int();
|
auto percentage = model.data(index, GModel::Role::Custom).to_i32();
|
||||||
|
|
||||||
auto data = model.data(index, GModel::Role::Display);
|
auto data = model.data(index, GModel::Role::Display);
|
||||||
String text;
|
String text;
|
||||||
|
|
|
@ -431,8 +431,10 @@ void VBForm::write_to_file(const String& path)
|
||||||
widget.for_each_property([&](auto& property) {
|
widget.for_each_property([&](auto& property) {
|
||||||
if (property.value().is_bool())
|
if (property.value().is_bool())
|
||||||
widget_object.set(property.name(), property.value().to_bool());
|
widget_object.set(property.name(), property.value().to_bool());
|
||||||
else if (property.value().is_int())
|
else if (property.value().is_i32())
|
||||||
widget_object.set(property.name(), property.value().to_int());
|
widget_object.set(property.name(), property.value().to_i32());
|
||||||
|
else if (property.value().is_i64())
|
||||||
|
widget_object.set(property.name(), property.value().to_i64());
|
||||||
else
|
else
|
||||||
widget_object.set(property.name(), property.value().to_string());
|
widget_object.set(property.name(), property.value().to_string());
|
||||||
});
|
});
|
||||||
|
|
|
@ -95,7 +95,7 @@ VBPropertiesWindow::VBPropertiesWindow()
|
||||||
if (!m_table_view->model())
|
if (!m_table_view->model())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
auto type_index = m_table_view->model()->index(index.row(), VBWidgetPropertyModel::Column::Type);
|
auto type_index = m_table_view->model()->index(index.row(), VBWidgetPropertyModel::Column::Type);
|
||||||
auto type = m_table_view->model()->data(type_index, GModel::Role::Custom).to_int();
|
auto type = m_table_view->model()->data(type_index, GModel::Role::Custom).to_i32();
|
||||||
switch ((GVariant::Type)type) {
|
switch ((GVariant::Type)type) {
|
||||||
case GVariant::Type::Bool:
|
case GVariant::Type::Bool:
|
||||||
return make<BoolModelEditingDelegate>();
|
return make<BoolModelEditingDelegate>();
|
||||||
|
|
|
@ -140,10 +140,10 @@ void VBWidget::setup_properties()
|
||||||
{
|
{
|
||||||
VB_ADD_PROPERTY(CObject, "name", name, set_name, string);
|
VB_ADD_PROPERTY(CObject, "name", name, set_name, string);
|
||||||
|
|
||||||
VB_ADD_PROPERTY(GWidget, "width", width, set_width, int);
|
VB_ADD_PROPERTY(GWidget, "width", width, set_width, i32);
|
||||||
VB_ADD_PROPERTY(GWidget, "height", height, set_height, int);
|
VB_ADD_PROPERTY(GWidget, "height", height, set_height, i32);
|
||||||
VB_ADD_PROPERTY(GWidget, "x", x, set_x, int);
|
VB_ADD_PROPERTY(GWidget, "x", x, set_x, i32);
|
||||||
VB_ADD_PROPERTY(GWidget, "y", y, set_y, int);
|
VB_ADD_PROPERTY(GWidget, "y", y, set_y, i32);
|
||||||
VB_ADD_PROPERTY(GWidget, "visible", is_visible, set_visible, bool);
|
VB_ADD_PROPERTY(GWidget, "visible", is_visible, set_visible, bool);
|
||||||
VB_ADD_PROPERTY(GWidget, "enabled", is_enabled, set_enabled, bool);
|
VB_ADD_PROPERTY(GWidget, "enabled", is_enabled, set_enabled, bool);
|
||||||
VB_ADD_PROPERTY(GWidget, "tooltip", tooltip, set_tooltip, string);
|
VB_ADD_PROPERTY(GWidget, "tooltip", tooltip, set_tooltip, string);
|
||||||
|
@ -164,28 +164,28 @@ void VBWidget::setup_properties()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_type == VBWidgetType::GScrollBar) {
|
if (m_type == VBWidgetType::GScrollBar) {
|
||||||
VB_ADD_PROPERTY(GScrollBar, "min", min, set_min, int);
|
VB_ADD_PROPERTY(GScrollBar, "min", min, set_min, i32);
|
||||||
VB_ADD_PROPERTY(GScrollBar, "max", max, set_max, int);
|
VB_ADD_PROPERTY(GScrollBar, "max", max, set_max, i32);
|
||||||
VB_ADD_PROPERTY(GScrollBar, "value", value, set_value, int);
|
VB_ADD_PROPERTY(GScrollBar, "value", value, set_value, i32);
|
||||||
VB_ADD_PROPERTY(GScrollBar, "step", step, set_step, int);
|
VB_ADD_PROPERTY(GScrollBar, "step", step, set_step, i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_type == VBWidgetType::GSpinBox) {
|
if (m_type == VBWidgetType::GSpinBox) {
|
||||||
VB_ADD_PROPERTY(GSpinBox, "min", min, set_min, int);
|
VB_ADD_PROPERTY(GSpinBox, "min", min, set_min, i32);
|
||||||
VB_ADD_PROPERTY(GSpinBox, "max", max, set_max, int);
|
VB_ADD_PROPERTY(GSpinBox, "max", max, set_max, i32);
|
||||||
VB_ADD_PROPERTY(GSpinBox, "value", value, set_value, int);
|
VB_ADD_PROPERTY(GSpinBox, "value", value, set_value, i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_type == VBWidgetType::GProgressBar) {
|
if (m_type == VBWidgetType::GProgressBar) {
|
||||||
VB_ADD_PROPERTY(GProgressBar, "min", min, set_min, int);
|
VB_ADD_PROPERTY(GProgressBar, "min", min, set_min, i32);
|
||||||
VB_ADD_PROPERTY(GProgressBar, "max", max, set_max, int);
|
VB_ADD_PROPERTY(GProgressBar, "max", max, set_max, i32);
|
||||||
VB_ADD_PROPERTY(GProgressBar, "value", value, set_value, int);
|
VB_ADD_PROPERTY(GProgressBar, "value", value, set_value, i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_type == VBWidgetType::GSlider) {
|
if (m_type == VBWidgetType::GSlider) {
|
||||||
VB_ADD_PROPERTY(GSlider, "min", min, set_min, int);
|
VB_ADD_PROPERTY(GSlider, "min", min, set_min, i32);
|
||||||
VB_ADD_PROPERTY(GSlider, "max", max, set_max, int);
|
VB_ADD_PROPERTY(GSlider, "max", max, set_max, i32);
|
||||||
VB_ADD_PROPERTY(GSlider, "value", value, set_value, int);
|
VB_ADD_PROPERTY(GSlider, "value", value, set_value, i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_type == VBWidgetType::GTextEditor) {
|
if (m_type == VBWidgetType::GTextEditor) {
|
||||||
|
|
|
@ -30,19 +30,34 @@
|
||||||
const char* to_string(GVariant::Type type)
|
const char* to_string(GVariant::Type type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case GVariant::Type::Invalid: return "Invalid";
|
case GVariant::Type::Invalid:
|
||||||
case GVariant::Type::Bool: return "Bool";
|
return "Invalid";
|
||||||
case GVariant::Type::Int: return "Int";
|
case GVariant::Type::Bool:
|
||||||
case GVariant::Type::UnsignedInt: return "UnsignedInt";
|
return "Bool";
|
||||||
case GVariant::Type::Float: return "Float";
|
case GVariant::Type::Int32:
|
||||||
case GVariant::Type::String: return "String";
|
return "Int32";
|
||||||
case GVariant::Type::Bitmap: return "Bitmap";
|
case GVariant::Type::Int64:
|
||||||
case GVariant::Type::Color: return "Color";
|
return "Int64";
|
||||||
case GVariant::Type::Icon: return "Icon";
|
case GVariant::Type::UnsignedInt:
|
||||||
case GVariant::Type::Point: return "Point";
|
return "UnsignedInt";
|
||||||
case GVariant::Type::Size: return "Size";
|
case GVariant::Type::Float:
|
||||||
case GVariant::Type::Rect: return "Rect";
|
return "Float";
|
||||||
case GVariant::Type::Font: return "Font";
|
case GVariant::Type::String:
|
||||||
|
return "String";
|
||||||
|
case GVariant::Type::Bitmap:
|
||||||
|
return "Bitmap";
|
||||||
|
case GVariant::Type::Color:
|
||||||
|
return "Color";
|
||||||
|
case GVariant::Type::Icon:
|
||||||
|
return "Icon";
|
||||||
|
case GVariant::Type::Point:
|
||||||
|
return "Point";
|
||||||
|
case GVariant::Type::Size:
|
||||||
|
return "Size";
|
||||||
|
case GVariant::Type::Rect:
|
||||||
|
return "Rect";
|
||||||
|
case GVariant::Type::Font:
|
||||||
|
return "Font";
|
||||||
}
|
}
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -76,10 +91,16 @@ void GVariant::clear()
|
||||||
m_value.as_string = nullptr;
|
m_value.as_string = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GVariant::GVariant(int value)
|
GVariant::GVariant(i32 value)
|
||||||
: m_type(Type::Int)
|
: m_type(Type::Int32)
|
||||||
{
|
{
|
||||||
m_value.as_int = value;
|
m_value.as_i32 = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
GVariant::GVariant(i64 value)
|
||||||
|
: m_type(Type::Int64)
|
||||||
|
{
|
||||||
|
m_value.as_i64 = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
GVariant::GVariant(unsigned value)
|
GVariant::GVariant(unsigned value)
|
||||||
|
@ -120,8 +141,8 @@ GVariant::GVariant(const JsonValue& value)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.is_i32()) {
|
if (value.is_i32()) {
|
||||||
m_type = Type::Int;
|
m_type = Type::Int32;
|
||||||
m_value.as_int = value.as_i32();
|
m_value.as_i32 = value.as_i32();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,9 +153,8 @@ GVariant::GVariant(const JsonValue& value)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.is_i64()) {
|
if (value.is_i64()) {
|
||||||
// FIXME: GVariant should have a 64-bit internal type.
|
m_type = Type::Int64;
|
||||||
m_type = Type::Int;
|
m_value.as_i64 = value.as_i64();
|
||||||
m_value.as_int = value.to_i32();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,8 +259,11 @@ void GVariant::copy_from(const GVariant& other)
|
||||||
case Type::Bool:
|
case Type::Bool:
|
||||||
m_value.as_bool = other.m_value.as_bool;
|
m_value.as_bool = other.m_value.as_bool;
|
||||||
break;
|
break;
|
||||||
case Type::Int:
|
case Type::Int32:
|
||||||
m_value.as_int = other.m_value.as_int;
|
m_value.as_i32 = other.m_value.as_i32;
|
||||||
|
break;
|
||||||
|
case Type::Int64:
|
||||||
|
m_value.as_i64 = other.m_value.as_i64;
|
||||||
break;
|
break;
|
||||||
case Type::UnsignedInt:
|
case Type::UnsignedInt:
|
||||||
m_value.as_uint = other.m_value.as_uint;
|
m_value.as_uint = other.m_value.as_uint;
|
||||||
|
@ -288,8 +311,10 @@ bool GVariant::operator==(const GVariant& other) const
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case Type::Bool:
|
case Type::Bool:
|
||||||
return as_bool() == other.as_bool();
|
return as_bool() == other.as_bool();
|
||||||
case Type::Int:
|
case Type::Int32:
|
||||||
return as_int() == other.as_int();
|
return as_i32() == other.as_i32();
|
||||||
|
case Type::Int64:
|
||||||
|
return as_i64() == other.as_i64();
|
||||||
case Type::UnsignedInt:
|
case Type::UnsignedInt:
|
||||||
return as_uint() == other.as_uint();
|
return as_uint() == other.as_uint();
|
||||||
case Type::Float:
|
case Type::Float:
|
||||||
|
@ -323,8 +348,10 @@ bool GVariant::operator<(const GVariant& other) const
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case Type::Bool:
|
case Type::Bool:
|
||||||
return as_bool() < other.as_bool();
|
return as_bool() < other.as_bool();
|
||||||
case Type::Int:
|
case Type::Int32:
|
||||||
return as_int() < other.as_int();
|
return as_i32() < other.as_i32();
|
||||||
|
case Type::Int64:
|
||||||
|
return as_i64() < other.as_i64();
|
||||||
case Type::UnsignedInt:
|
case Type::UnsignedInt:
|
||||||
return as_uint() < other.as_uint();
|
return as_uint() < other.as_uint();
|
||||||
case Type::Float:
|
case Type::Float:
|
||||||
|
@ -356,8 +383,10 @@ String GVariant::to_string() const
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case Type::Bool:
|
case Type::Bool:
|
||||||
return as_bool() ? "true" : "false";
|
return as_bool() ? "true" : "false";
|
||||||
case Type::Int:
|
case Type::Int32:
|
||||||
return String::number(as_int());
|
return String::number(as_i32());
|
||||||
|
case Type::Int64:
|
||||||
|
return String::number(as_i64());
|
||||||
case Type::UnsignedInt:
|
case Type::UnsignedInt:
|
||||||
return String::number(as_uint());
|
return String::number(as_uint());
|
||||||
case Type::Float:
|
case Type::Float:
|
||||||
|
|
|
@ -40,7 +40,8 @@ public:
|
||||||
GVariant();
|
GVariant();
|
||||||
GVariant(bool);
|
GVariant(bool);
|
||||||
GVariant(float);
|
GVariant(float);
|
||||||
GVariant(int);
|
GVariant(i32);
|
||||||
|
GVariant(i64);
|
||||||
GVariant(unsigned);
|
GVariant(unsigned);
|
||||||
GVariant(const char*);
|
GVariant(const char*);
|
||||||
GVariant(const String&);
|
GVariant(const String&);
|
||||||
|
@ -65,7 +66,8 @@ public:
|
||||||
enum class Type {
|
enum class Type {
|
||||||
Invalid,
|
Invalid,
|
||||||
Bool,
|
Bool,
|
||||||
Int,
|
Int32,
|
||||||
|
Int64,
|
||||||
UnsignedInt,
|
UnsignedInt,
|
||||||
Float,
|
Float,
|
||||||
String,
|
String,
|
||||||
|
@ -80,7 +82,8 @@ public:
|
||||||
|
|
||||||
bool is_valid() const { return m_type != Type::Invalid; }
|
bool is_valid() const { return m_type != Type::Invalid; }
|
||||||
bool is_bool() const { return m_type == Type::Bool; }
|
bool is_bool() const { return m_type == Type::Bool; }
|
||||||
bool is_int() const { return m_type == Type::Int; }
|
bool is_i32() const { return m_type == Type::Int32; }
|
||||||
|
bool is_i64() const { return m_type == Type::Int64; }
|
||||||
bool is_uint() const { return m_type == Type::UnsignedInt; }
|
bool is_uint() const { return m_type == Type::UnsignedInt; }
|
||||||
bool is_float() const { return m_type == Type::Float; }
|
bool is_float() const { return m_type == Type::Float; }
|
||||||
bool is_string() const { return m_type == Type::String; }
|
bool is_string() const { return m_type == Type::String; }
|
||||||
|
@ -105,8 +108,10 @@ public:
|
||||||
return as_bool();
|
return as_bool();
|
||||||
if (type() == Type::String)
|
if (type() == Type::String)
|
||||||
return !!m_value.as_string;
|
return !!m_value.as_string;
|
||||||
if (type() == Type::Int)
|
if (type() == Type::Int32)
|
||||||
return m_value.as_int != 0;
|
return m_value.as_i32 != 0;
|
||||||
|
if (type() == Type::Int64)
|
||||||
|
return m_value.as_i64 != 0;
|
||||||
if (type() == Type::UnsignedInt)
|
if (type() == Type::UnsignedInt)
|
||||||
return m_value.as_uint != 0;
|
return m_value.as_uint != 0;
|
||||||
if (type() == Type::Rect)
|
if (type() == Type::Rect)
|
||||||
|
@ -118,10 +123,16 @@ public:
|
||||||
return is_valid();
|
return is_valid();
|
||||||
}
|
}
|
||||||
|
|
||||||
int as_int() const
|
int as_i32() const
|
||||||
{
|
{
|
||||||
ASSERT(type() == Type::Int);
|
ASSERT(type() == Type::Int32);
|
||||||
return m_value.as_int;
|
return m_value.as_i32;
|
||||||
|
}
|
||||||
|
|
||||||
|
int as_i64() const
|
||||||
|
{
|
||||||
|
ASSERT(type() == Type::Int64);
|
||||||
|
return m_value.as_i64;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned as_uint() const
|
unsigned as_uint() const
|
||||||
|
@ -130,10 +141,13 @@ public:
|
||||||
return m_value.as_uint;
|
return m_value.as_uint;
|
||||||
}
|
}
|
||||||
|
|
||||||
int to_int() const
|
template<typename T>
|
||||||
|
T to_integer() const
|
||||||
{
|
{
|
||||||
if (is_int())
|
if (is_i32())
|
||||||
return as_int();
|
return as_i32();
|
||||||
|
if (is_i64())
|
||||||
|
return as_i64();
|
||||||
if (is_bool())
|
if (is_bool())
|
||||||
return as_bool() ? 1 : 0;
|
return as_bool() ? 1 : 0;
|
||||||
if (is_float())
|
if (is_float())
|
||||||
|
@ -152,6 +166,16 @@ public:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i32 to_i32() const
|
||||||
|
{
|
||||||
|
return to_integer<i32>();
|
||||||
|
}
|
||||||
|
|
||||||
|
i64 to_i64() const
|
||||||
|
{
|
||||||
|
return to_integer<i64>();
|
||||||
|
}
|
||||||
|
|
||||||
float as_float() const
|
float as_float() const
|
||||||
{
|
{
|
||||||
ASSERT(type() == Type::Float);
|
ASSERT(type() == Type::Float);
|
||||||
|
@ -244,7 +268,8 @@ private:
|
||||||
GIconImpl* as_icon;
|
GIconImpl* as_icon;
|
||||||
Font* as_font;
|
Font* as_font;
|
||||||
bool as_bool;
|
bool as_bool;
|
||||||
int as_int;
|
i32 as_i32;
|
||||||
|
i64 as_i64;
|
||||||
unsigned as_uint;
|
unsigned as_uint;
|
||||||
float as_float;
|
float as_float;
|
||||||
RGBA32 as_color;
|
RGBA32 as_color;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue