diff --git a/Libraries/LibGUI/Forward.h b/Libraries/LibGUI/Forward.h index 209760d0e1..5c39ae4a3f 100644 --- a/Libraries/LibGUI/Forward.h +++ b/Libraries/LibGUI/Forward.h @@ -92,6 +92,7 @@ class Widget; class Window; class WindowServerConnection; +enum class ModelRole; enum class SortOrder; } diff --git a/Libraries/LibGUI/ModelIndex.cpp b/Libraries/LibGUI/ModelIndex.cpp index 78c396a767..1c31d3f3bf 100644 --- a/Libraries/LibGUI/ModelIndex.cpp +++ b/Libraries/LibGUI/ModelIndex.cpp @@ -25,10 +25,20 @@ */ #include -#include +#include +#include namespace GUI { +Variant ModelIndex::data(ModelRole role) const +{ + if (!is_valid()) + return {}; + + ASSERT(model()); + return model()->data(*this, role); +} + const LogStream& operator<<(const LogStream& stream, const ModelIndex& value) { if (value.internal_data()) diff --git a/Libraries/LibGUI/ModelIndex.h b/Libraries/LibGUI/ModelIndex.h index 7bdb647ec4..cdac89c85e 100644 --- a/Libraries/LibGUI/ModelIndex.h +++ b/Libraries/LibGUI/ModelIndex.h @@ -28,6 +28,7 @@ #include #include +#include namespace GUI { @@ -35,7 +36,7 @@ class ModelIndex { friend class Model; public: - ModelIndex() {} + ModelIndex() { } bool is_valid() const { return m_row != -1 && m_column != -1; } int row() const { return m_row; } @@ -57,6 +58,8 @@ public: const Model* model() const { return m_model; } + Variant data(ModelRole = ModelRole::Display) const; + private: ModelIndex(const Model& model, int row, int column, void* internal_data) : m_model(&model)