mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:07: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 Window;
|
||||||
class WindowServerConnection;
|
class WindowServerConnection;
|
||||||
|
|
||||||
|
enum class ModelRole;
|
||||||
enum class SortOrder;
|
enum class SortOrder;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibGUI/ModelIndex.h>
|
#include <LibGUI/Model.h>
|
||||||
|
#include <LibGUI/Variant.h>
|
||||||
|
|
||||||
namespace GUI {
|
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)
|
const LogStream& operator<<(const LogStream& stream, const ModelIndex& value)
|
||||||
{
|
{
|
||||||
if (value.internal_data())
|
if (value.internal_data())
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include <AK/Traits.h>
|
#include <AK/Traits.h>
|
||||||
#include <LibGUI/Forward.h>
|
#include <LibGUI/Forward.h>
|
||||||
|
#include <LibGUI/ModelRole.h>
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ class ModelIndex {
|
||||||
friend class Model;
|
friend class Model;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModelIndex() {}
|
ModelIndex() { }
|
||||||
|
|
||||||
bool is_valid() const { return m_row != -1 && m_column != -1; }
|
bool is_valid() const { return m_row != -1 && m_column != -1; }
|
||||||
int row() const { return m_row; }
|
int row() const { return m_row; }
|
||||||
|
@ -57,6 +58,8 @@ public:
|
||||||
|
|
||||||
const Model* model() const { return m_model; }
|
const Model* model() const { return m_model; }
|
||||||
|
|
||||||
|
Variant data(ModelRole = ModelRole::Display) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ModelIndex(const Model& model, int row, int column, void* internal_data)
|
ModelIndex(const Model& model, int row, int column, void* internal_data)
|
||||||
: m_model(&model)
|
: m_model(&model)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue