summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-01-27 10:55:10 +0100
committerAndreas Kling <kling@serenityos.org>2020-01-27 10:55:10 +0100
commit6906edee9a89619eefbea614983fa0c61d20c8a7 (patch)
tree747858f7635aacd5724e8735a42707f9edff2964
parent137a45dff2a6c60dbca34ee6b1e27ff476fe9b40 (diff)
downloadserenity-6906edee9a89619eefbea614983fa0c61d20c8a7.zip
LibGUI: Add 64-bit signed integer support to GVariant
What was previously the "Int" type is now "Int32" and "Int64".
-rw-r--r--Applications/FileManager/DirectoryView.cpp2
-rw-r--r--Applications/SystemMonitor/ProcessTableView.cpp2
-rw-r--r--Applications/SystemMonitor/main.cpp2
-rw-r--r--DevTools/VisualBuilder/VBForm.cpp6
-rw-r--r--DevTools/VisualBuilder/VBPropertiesWindow.cpp2
-rw-r--r--DevTools/VisualBuilder/VBWidget.cpp34
-rw-r--r--Libraries/LibGUI/GVariant.cpp87
-rw-r--r--Libraries/LibGUI/GVariant.h49
8 files changed, 120 insertions, 64 deletions
diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp
index d0f4abf557..d77c139f0d 100644
--- a/Applications/FileManager/DirectoryView.cpp
+++ b/Applications/FileManager/DirectoryView.cpp
@@ -282,7 +282,7 @@ void DirectoryView::update_statusbar()
current_view().selection().for_each_index([&](auto& index) {
auto& model = *current_view().model();
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;
});
diff --git a/Applications/SystemMonitor/ProcessTableView.cpp b/Applications/SystemMonitor/ProcessTableView.cpp
index 05589d15da..bec942b6ae 100644
--- a/Applications/SystemMonitor/ProcessTableView.cpp
+++ b/Applications/SystemMonitor/ProcessTableView.cpp
@@ -56,5 +56,5 @@ pid_t ProcessTableView::selected_pid() const
{
if (selection().is_empty())
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();
}
diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp
index 578e0b47f1..8a551a0567 100644
--- a/Applications/SystemMonitor/main.cpp
+++ b/Applications/SystemMonitor/main.cpp
@@ -258,7 +258,7 @@ public:
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 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);
String text;
diff --git a/DevTools/VisualBuilder/VBForm.cpp b/DevTools/VisualBuilder/VBForm.cpp
index c289ef4f84..cb844cfa9f 100644
--- a/DevTools/VisualBuilder/VBForm.cpp
+++ b/DevTools/VisualBuilder/VBForm.cpp
@@ -431,8 +431,10 @@ void VBForm::write_to_file(const String& path)
widget.for_each_property([&](auto& property) {
if (property.value().is_bool())
widget_object.set(property.name(), property.value().to_bool());
- else if (property.value().is_int())
- widget_object.set(property.name(), property.value().to_int());
+ else if (property.value().is_i32())
+ 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
widget_object.set(property.name(), property.value().to_string());
});
diff --git a/DevTools/VisualBuilder/VBPropertiesWindow.cpp b/DevTools/VisualBuilder/VBPropertiesWindow.cpp
index ae557a8c6c..6965e31b38 100644
--- a/DevTools/VisualBuilder/VBPropertiesWindow.cpp
+++ b/DevTools/VisualBuilder/VBPropertiesWindow.cpp
@@ -95,7 +95,7 @@ VBPropertiesWindow::VBPropertiesWindow()
if (!m_table_view->model())
return nullptr;
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) {
case GVariant::Type::Bool:
return make<BoolModelEditingDelegate>();
diff --git a/DevTools/VisualBuilder/VBWidget.cpp b/DevTools/VisualBuilder/VBWidget.cpp
index a7d7f43213..96862f5d85 100644
--- a/DevTools/VisualBuilder/VBWidget.cpp
+++ b/DevTools/VisualBuilder/VBWidget.cpp
@@ -140,10 +140,10 @@ void VBWidget::setup_properties()
{
VB_ADD_PROPERTY(CObject, "name", name, set_name, string);
- VB_ADD_PROPERTY(GWidget, "width", width, set_width, int);
- VB_ADD_PROPERTY(GWidget, "height", height, set_height, int);
- VB_ADD_PROPERTY(GWidget, "x", x, set_x, int);
- VB_ADD_PROPERTY(GWidget, "y", y, set_y, int);
+ VB_ADD_PROPERTY(GWidget, "width", width, set_width, i32);
+ VB_ADD_PROPERTY(GWidget, "height", height, set_height, i32);
+ VB_ADD_PROPERTY(GWidget, "x", x, set_x, i32);
+ VB_ADD_PROPERTY(GWidget, "y", y, set_y, i32);
VB_ADD_PROPERTY(GWidget, "visible", is_visible, set_visible, bool);
VB_ADD_PROPERTY(GWidget, "enabled", is_enabled, set_enabled, bool);
VB_ADD_PROPERTY(GWidget, "tooltip", tooltip, set_tooltip, string);
@@ -164,28 +164,28 @@ void VBWidget::setup_properties()
}
if (m_type == VBWidgetType::GScrollBar) {
- VB_ADD_PROPERTY(GScrollBar, "min", min, set_min, int);
- VB_ADD_PROPERTY(GScrollBar, "max", max, set_max, int);
- VB_ADD_PROPERTY(GScrollBar, "value", value, set_value, int);
- VB_ADD_PROPERTY(GScrollBar, "step", step, set_step, int);
+ VB_ADD_PROPERTY(GScrollBar, "min", min, set_min, i32);
+ VB_ADD_PROPERTY(GScrollBar, "max", max, set_max, i32);
+ VB_ADD_PROPERTY(GScrollBar, "value", value, set_value, i32);
+ VB_ADD_PROPERTY(GScrollBar, "step", step, set_step, i32);
}
if (m_type == VBWidgetType::GSpinBox) {
- VB_ADD_PROPERTY(GSpinBox, "min", min, set_min, int);
- VB_ADD_PROPERTY(GSpinBox, "max", max, set_max, int);
- VB_ADD_PROPERTY(GSpinBox, "value", value, set_value, int);
+ VB_ADD_PROPERTY(GSpinBox, "min", min, set_min, i32);
+ VB_ADD_PROPERTY(GSpinBox, "max", max, set_max, i32);
+ VB_ADD_PROPERTY(GSpinBox, "value", value, set_value, i32);
}
if (m_type == VBWidgetType::GProgressBar) {
- VB_ADD_PROPERTY(GProgressBar, "min", min, set_min, int);
- VB_ADD_PROPERTY(GProgressBar, "max", max, set_max, int);
- VB_ADD_PROPERTY(GProgressBar, "value", value, set_value, int);
+ VB_ADD_PROPERTY(GProgressBar, "min", min, set_min, i32);
+ VB_ADD_PROPERTY(GProgressBar, "max", max, set_max, i32);
+ VB_ADD_PROPERTY(GProgressBar, "value", value, set_value, i32);
}
if (m_type == VBWidgetType::GSlider) {
- VB_ADD_PROPERTY(GSlider, "min", min, set_min, int);
- VB_ADD_PROPERTY(GSlider, "max", max, set_max, int);
- VB_ADD_PROPERTY(GSlider, "value", value, set_value, int);
+ VB_ADD_PROPERTY(GSlider, "min", min, set_min, i32);
+ VB_ADD_PROPERTY(GSlider, "max", max, set_max, i32);
+ VB_ADD_PROPERTY(GSlider, "value", value, set_value, i32);
}
if (m_type == VBWidgetType::GTextEditor) {
diff --git a/Libraries/LibGUI/GVariant.cpp b/Libraries/LibGUI/GVariant.cpp
index cfe43a70ad..676e81837e 100644
--- a/Libraries/LibGUI/GVariant.cpp
+++ b/Libraries/LibGUI/GVariant.cpp
@@ -30,19 +30,34 @@
const char* to_string(GVariant::Type type)
{
switch (type) {
- case GVariant::Type::Invalid: return "Invalid";
- case GVariant::Type::Bool: return "Bool";
- case GVariant::Type::Int: return "Int";
- case GVariant::Type::UnsignedInt: return "UnsignedInt";
- case GVariant::Type::Float: return "Float";
- 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";
+ case GVariant::Type::Invalid:
+ return "Invalid";
+ case GVariant::Type::Bool:
+ return "Bool";
+ case GVariant::Type::Int32:
+ return "Int32";
+ case GVariant::Type::Int64:
+ return "Int64";
+ case GVariant::Type::UnsignedInt:
+ return "UnsignedInt";
+ case GVariant::Type::Float:
+ return "Float";
+ 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();
}
@@ -76,10 +91,16 @@ void GVariant::clear()
m_value.as_string = nullptr;
}
-GVariant::GVariant(int value)
- : m_type(Type::Int)
+GVariant::GVariant(i32 value)
+ : 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)
@@ -120,8 +141,8 @@ GVariant::GVariant(const JsonValue& value)
}
if (value.is_i32()) {
- m_type = Type::Int;
- m_value.as_int = value.as_i32();
+ m_type = Type::Int32;
+ m_value.as_i32 = value.as_i32();
return;
}
@@ -132,9 +153,8 @@ GVariant::GVariant(const JsonValue& value)
}
if (value.is_i64()) {
- // FIXME: GVariant should have a 64-bit internal type.
- m_type = Type::Int;
- m_value.as_int = value.to_i32();
+ m_type = Type::Int64;
+ m_value.as_i64 = value.as_i64();
return;
}
@@ -239,8 +259,11 @@ void GVariant::copy_from(const GVariant& other)
case Type::Bool:
m_value.as_bool = other.m_value.as_bool;
break;
- case Type::Int:
- m_value.as_int = other.m_value.as_int;
+ case Type::Int32:
+ m_value.as_i32 = other.m_value.as_i32;
+ break;
+ case Type::Int64:
+ m_value.as_i64 = other.m_value.as_i64;
break;
case Type::UnsignedInt:
m_value.as_uint = other.m_value.as_uint;
@@ -288,8 +311,10 @@ bool GVariant::operator==(const GVariant& other) const
switch (m_type) {
case Type::Bool:
return as_bool() == other.as_bool();
- case Type::Int:
- return as_int() == other.as_int();
+ case Type::Int32:
+ return as_i32() == other.as_i32();
+ case Type::Int64:
+ return as_i64() == other.as_i64();
case Type::UnsignedInt:
return as_uint() == other.as_uint();
case Type::Float:
@@ -323,8 +348,10 @@ bool GVariant::operator<(const GVariant& other) const
switch (m_type) {
case Type::Bool:
return as_bool() < other.as_bool();
- case Type::Int:
- return as_int() < other.as_int();
+ case Type::Int32:
+ return as_i32() < other.as_i32();
+ case Type::Int64:
+ return as_i64() < other.as_i64();
case Type::UnsignedInt:
return as_uint() < other.as_uint();
case Type::Float:
@@ -356,8 +383,10 @@ String GVariant::to_string() const
switch (m_type) {
case Type::Bool:
return as_bool() ? "true" : "false";
- case Type::Int:
- return String::number(as_int());
+ case Type::Int32:
+ return String::number(as_i32());
+ case Type::Int64:
+ return String::number(as_i64());
case Type::UnsignedInt:
return String::number(as_uint());
case Type::Float:
diff --git a/Libraries/LibGUI/GVariant.h b/Libraries/LibGUI/GVariant.h
index 581611625c..a3fde901b4 100644
--- a/Libraries/LibGUI/GVariant.h
+++ b/Libraries/LibGUI/GVariant.h
@@ -40,7 +40,8 @@ public:
GVariant();
GVariant(bool);
GVariant(float);
- GVariant(int);
+ GVariant(i32);
+ GVariant(i64);
GVariant(unsigned);
GVariant(const char*);
GVariant(const String&);
@@ -65,7 +66,8 @@ public:
enum class Type {
Invalid,
Bool,
- Int,
+ Int32,
+ Int64,
UnsignedInt,
Float,
String,
@@ -80,7 +82,8 @@ public:
bool is_valid() const { return m_type != Type::Invalid; }
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_float() const { return m_type == Type::Float; }
bool is_string() const { return m_type == Type::String; }
@@ -105,8 +108,10 @@ public:
return as_bool();
if (type() == Type::String)
return !!m_value.as_string;
- if (type() == Type::Int)
- return m_value.as_int != 0;
+ if (type() == Type::Int32)
+ return m_value.as_i32 != 0;
+ if (type() == Type::Int64)
+ return m_value.as_i64 != 0;
if (type() == Type::UnsignedInt)
return m_value.as_uint != 0;
if (type() == Type::Rect)
@@ -118,10 +123,16 @@ public:
return is_valid();
}
- int as_int() const
+ int as_i32() const
{
- ASSERT(type() == Type::Int);
- return m_value.as_int;
+ ASSERT(type() == Type::Int32);
+ return m_value.as_i32;
+ }
+
+ int as_i64() const
+ {
+ ASSERT(type() == Type::Int64);
+ return m_value.as_i64;
}
unsigned as_uint() const
@@ -130,10 +141,13 @@ public:
return m_value.as_uint;
}
- int to_int() const
+ template<typename T>
+ T to_integer() const
{
- if (is_int())
- return as_int();
+ if (is_i32())
+ return as_i32();
+ if (is_i64())
+ return as_i64();
if (is_bool())
return as_bool() ? 1 : 0;
if (is_float())
@@ -152,6 +166,16 @@ public:
return 0;
}
+ i32 to_i32() const
+ {
+ return to_integer<i32>();
+ }
+
+ i64 to_i64() const
+ {
+ return to_integer<i64>();
+ }
+
float as_float() const
{
ASSERT(type() == Type::Float);
@@ -244,7 +268,8 @@ private:
GIconImpl* as_icon;
Font* as_font;
bool as_bool;
- int as_int;
+ i32 as_i32;
+ i64 as_i64;
unsigned as_uint;
float as_float;
RGBA32 as_color;