KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
EntityMetadata Class Reference

A typed, role-keyed data container for passing objects through model/view layers. More...

#include <entitymetadata.h>

Public Member Functions

 EntityMetadata ()
 Default constructor — creates an invalid (type 0) metadata object.
 
 EntityMetadata (int type)
 Construct metadata with only a type identifier.
 
 EntityMetadata (int type, const QVariant &data, KANOOP::ModelRole role=KANOOP::DataRole)
 Construct metadata with a type, data value, and optional role.
 
 EntityMetadata (int type, const QVariant &data, const QUuid &uuid, KANOOP::ModelRole role=KANOOP::DataRole)
 Construct metadata with a type, data value, UUID, and optional role.
 
bool operator== (const EntityMetadata &other) const
 Equality comparison by type and UUID.
 
int type () const
 Return the entity type integer.
 
QString typeString () const
 Return the human-readable name for this entity's type.
 
int iconId () const
 Return the icon ID associated with this entity's type.
 
QVariant data (int role=KANOOP::DataRole) const
 Return the data stored under the given role.
 
void setData (const QVariant &value, int role=KANOOP::DataRole)
 Store a value under the given role.
 
bool hasData (int role) const
 Test whether data has been stored for a given role.
 
QUuid uuid () const
 Return the UUID stored under KANOOP::UUidRole.
 
void setUuid (const QUuid &value)
 Store a UUID under KANOOP::UUidRole.
 
QVariant toVariant () const
 Wrap this object in a QVariant.
 
bool isValid () const
 Test whether this metadata has a non-zero type.
 

Static Public Member Functions

static EntityMetadata fromVariant (const QVariant &value)
 Unwrap an EntityMetadata from a QVariant.
 
static void registerMetadata (int type, const QString &name, int iconId=0)
 Register a name (and optional icon ID) for an entity type integer.
 
static void registerIcon (int type, int iconId)
 Associate an icon ID with an already-registered entity type.
 
static QString getTypeString (int type)
 Look up the registered name for an entity type integer.
 
static int getTypeFromString (const QString &value)
 Look up the entity type integer for a registered name string.
 
static QString getMimeTypeString (int type)
 Return a MIME type string for the given entity type.
 

Detailed Description

A typed, role-keyed data container for passing objects through model/view layers.

EntityMetadata wraps an integer entity type together with arbitrary role-keyed QVariant data and an optional UUID. Use registerMetadata() at startup to associate type integers with human-readable names and optional icon IDs.

Definition at line 37 of file entitymetadata.h.

Constructor & Destructor Documentation

◆ EntityMetadata() [1/4]

EntityMetadata::EntityMetadata ( )
inline

Default constructor — creates an invalid (type 0) metadata object.

Definition at line 41 of file entitymetadata.h.

◆ EntityMetadata() [2/4]

EntityMetadata::EntityMetadata ( int  type)

Construct metadata with only a type identifier.

Parameters
typeApplication-defined entity type integer

◆ EntityMetadata() [3/4]

EntityMetadata::EntityMetadata ( int  type,
const QVariant &  data,
KANOOP::ModelRole  role = KANOOP::DataRole 
)

Construct metadata with a type, data value, and optional role.

Parameters
typeApplication-defined entity type integer
dataPayload stored under the given role
roleModel role key (default KANOOP::DataRole)

◆ EntityMetadata() [4/4]

EntityMetadata::EntityMetadata ( int  type,
const QVariant &  data,
const QUuid &  uuid,
KANOOP::ModelRole  role = KANOOP::DataRole 
)

Construct metadata with a type, data value, UUID, and optional role.

Parameters
typeApplication-defined entity type integer
dataPayload stored under the given role
uuidUUID to associate with this entity
roleModel role key (default KANOOP::DataRole)

Member Function Documentation

◆ data()

QVariant EntityMetadata::data ( int  role = KANOOP::DataRole) const
inline

Return the data stored under the given role.

Parameters
roleModel role key (default KANOOP::DataRole)
Returns
Stored QVariant, or invalid QVariant if no data for role

Definition at line 95 of file entitymetadata.h.

◆ fromVariant()

static EntityMetadata EntityMetadata::fromVariant ( const QVariant &  value)
inlinestatic

Unwrap an EntityMetadata from a QVariant.

Parameters
valueVariant previously created by toVariant()
Returns
Extracted EntityMetadata

Definition at line 134 of file entitymetadata.h.

◆ getMimeTypeString()

static QString EntityMetadata::getMimeTypeString ( int  type)
inlinestatic

Return a MIME type string for the given entity type.

Parameters
typeEntity type integer
Returns
MIME type string of the form "application-epcpower/<name>"

Definition at line 176 of file entitymetadata.h.

◆ getTypeFromString()

static int EntityMetadata::getTypeFromString ( const QString &  value)
static

Look up the entity type integer for a registered name string.

Parameters
valueRegistered name string
Returns
Matching type integer, or 0 if not found

◆ getTypeString()

static QString EntityMetadata::getTypeString ( int  type)
static

Look up the registered name for an entity type integer.

Parameters
typeEntity type integer
Returns
Registered name string, or empty string if not found

◆ hasData()

bool EntityMetadata::hasData ( int  role) const
inline

Test whether data has been stored for a given role.

Parameters
roleModel role key to check
Returns
true if data exists for role

Definition at line 109 of file entitymetadata.h.

◆ iconId()

int EntityMetadata::iconId ( ) const
inline

Return the icon ID associated with this entity's type.

Returns
Icon ID, or 0 if none was registered

Definition at line 88 of file entitymetadata.h.

◆ isValid()

bool EntityMetadata::isValid ( ) const
inline

Test whether this metadata has a non-zero type.

Returns
true if type != 0

Definition at line 140 of file entitymetadata.h.

◆ operator==()

bool EntityMetadata::operator== ( const EntityMetadata other) const

Equality comparison by type and UUID.

Parameters
otherEntityMetadata to compare.
Returns
True if type and UUID match.

◆ registerIcon()

static void EntityMetadata::registerIcon ( int  type,
int  iconId 
)
static

Associate an icon ID with an already-registered entity type.

Parameters
typeRegistered entity type integer
iconIdIcon identifier to associate

◆ registerMetadata()

static void EntityMetadata::registerMetadata ( int  type,
const QString &  name,
int  iconId = 0 
)
static

Register a name (and optional icon ID) for an entity type integer.

Parameters
typeApplication-defined entity type integer
nameHuman-readable name for this type
iconIdOptional icon identifier to associate with this type

◆ setData()

void EntityMetadata::setData ( const QVariant &  value,
int  role = KANOOP::DataRole 
)
inline

Store a value under the given role.

Parameters
valueValue to store
roleModel role key (default KANOOP::DataRole)

Definition at line 102 of file entitymetadata.h.

◆ setUuid()

void EntityMetadata::setUuid ( const QUuid &  value)
inline

Store a UUID under KANOOP::UUidRole.

Parameters
valueUUID to associate with this entity

Definition at line 121 of file entitymetadata.h.

References KANOOP::UUidRole.

◆ toVariant()

QVariant EntityMetadata::toVariant ( ) const
inline

Wrap this object in a QVariant.

Returns
QVariant containing a copy of this EntityMetadata

Definition at line 127 of file entitymetadata.h.

◆ type()

int EntityMetadata::type ( ) const
inline

Return the entity type integer.

Returns
Type value as registered with registerMetadata()

Definition at line 76 of file entitymetadata.h.

◆ typeString()

QString EntityMetadata::typeString ( ) const

Return the human-readable name for this entity's type.

Returns
Registered type name string, or empty string if unknown

◆ uuid()

QUuid EntityMetadata::uuid ( ) const
inline

Return the UUID stored under KANOOP::UUidRole.

Returns
Stored UUID, or null UUID if not set

Definition at line 115 of file entitymetadata.h.

References KANOOP::UUidRole.


The documentation for this class was generated from the following file: