mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:37:35 +00:00
LibGUI: Add ModelIndex::data(ModelRole)
This is a convenience API that makes accessing model data easier.
This commit is contained in:
parent
a1e381a0f8
commit
f882424869
3 changed files with 16 additions and 2 deletions
|
@ -92,6 +92,7 @@ class Widget;
|
|||
class Window;
|
||||
class WindowServerConnection;
|
||||
|
||||
enum class ModelRole;
|
||||
enum class SortOrder;
|
||||
|
||||
}
|
||||
|
|
|
@ -25,10 +25,20 @@
|
|||
*/
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibGUI/ModelIndex.h>
|
||||
#include <LibGUI/Model.h>
|
||||
#include <LibGUI/Variant.h>
|
||||
|
||||
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())
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <AK/Traits.h>
|
||||
#include <LibGUI/Forward.h>
|
||||
#include <LibGUI/ModelRole.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue