Accelerated Computation Engine
Classes | Public Types | Public Member Functions | List of all members
Ace::MetadataModel Class Reference

#include <ace_metadatamodel.h>

Inheritance diagram for Ace::MetadataModel:

Classes

class  Node
 

Public Types

enum  Roles { RawImageData = 10000 }
 

Public Member Functions

virtual QStringList mimeTypes () const override final
 
virtual Qt::DropActions supportedDropActions () const override final
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role) const override final
 
virtual QModelIndex index (int row, int column, const QModelIndex &parent) const override final
 
virtual QModelIndex parent (const QModelIndex &child) const override final
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const override final
 
virtual int rowCount (const QModelIndex &parent) const override final
 
virtual int columnCount (const QModelIndex &parent) const override final
 
virtual QMimeData * mimeData (const QModelIndexList &indexes) const override final
 
virtual QVariant data (const QModelIndex &index, int role) const override final
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role) override final
 
virtual bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override final
 
 MetadataModel (QObject *parent=nullptr)
 
bool isImage (const QModelIndex &index) const
 
bool isContainer (const QModelIndex &index) const
 
bool readOnly () const
 
EMetadata meta () const
 
bool insert (const QModelIndex &parent, EMetadata::Type type)
 
bool remove (const QModelIndex &index)
 
void setMeta (const EMetadata &newRoot)
 
void setReadOnly (bool state)
 

Detailed Description

This provides a Qt item model for a metadata structure. The root of the metadata structure must be an object type. This model is primarily used for the GUI dialog to edit the metadata of a data object. It can however be used as a general model for any purpose. The model can insert or remove a row, and drag and drop a single row that either copies or pastes the row. It consists of three columns. The first column is the name, the second is the type, and the last column is the value.

Member Enumeration Documentation

◆ Roles

This contains custom data roles for this model.

Enumerator
RawImageData 

This is for the data role of getting the byte array of a bytes metadata type. The normal display role for a bytes type will just return an "IMAGE" string.

Constructor & Destructor Documentation

◆ MetadataModel()

MetadataModel::MetadataModel ( QObject *  parent = nullptr)
explicit

This constructs a new metadata model with the given parent, if any.

Parameters
parentThe parent for this new model.

Member Function Documentation

◆ columnCount()

int MetadataModel::columnCount ( const QModelIndex &  parent) const
finaloverridevirtual

This implements the interface that returns the number of columns a given index contains. For this model the number of columns is always 3.

Parameters
parentThis is not used because the number of columns is static.
Returns
The number of columns which is always 3 for this model.

◆ data()

QVariant MetadataModel::data ( const QModelIndex &  index,
int  role 
) const
finaloverridevirtual

This implements the interface that returns data from the given index and role. This model only returns data based off the display role or custom raw image data role. This model returns a string suitable for a view with the display role. Only if the node of the given index is a bytes type then the byte array is returned with the raw image data role.

Parameters
indexThe index whose data is being requested.
roleThe role of the data being requested.
Returns
Data of given index and role.

◆ dropMimeData()

bool MetadataModel::dropMimeData ( const QMimeData *  data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
)
finaloverridevirtual

This implements the interface that handles the end of a drag and drop operation where the drop has occurred. This model only implements the copy and move actions.

Parameters
dataPointer to qt mime data object that was created when the drag was initiated.
actionThe drag and drop action being requested.
rowThe row where the drop occurred.
columnThe column where the drop occurred.
parentThe parent index where the drop occurred.
Returns
Returns true on success of the drag and drop action or false on failure.

◆ flags()

Qt::ItemFlags MetadataModel::flags ( const QModelIndex &  index) const
finaloverridevirtual

This implements the interface that returns the flags for a given index of this mode. The flags inform anyone what can and cannot be done to the given index.

Parameters
indexThe index whose flags are returned.
Returns
Flags for the given index.

◆ headerData()

QVariant MetadataModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role 
) const
finaloverridevirtual

This implements the interface that informs any view what the headers should be for columns and/or rows of the view. This returns the header data for the given section, orientation, and role. This model has no headers for the row and has headers for the first three columns denoting "key", "type", and "value".

Parameters
sectionThe section for the requested header data. This is the indent, starting at 0, for the given orientation of vertical or horizontal.
orientationThe orientation for the requested header data.
roleThe role for the requested header data.
Returns
The header data for the given section, orientation, and role.

◆ index()

QModelIndex MetadataModel::index ( int  row,
int  column,
const QModelIndex &  parent 
) const
finaloverridevirtual

This implements the interface that creates a new index from the given row, column, and parent index.

Parameters
rowRow for the requested index.
columnColumn for the requested index.
parentParent index for the requested index.
Returns
Index for the given row, column, and parent index.

◆ insert()

bool MetadataModel::insert ( const QModelIndex &  parent,
EMetadata::Type  type 
)

Inserts a new empty node with the given metadata type into the given parent. If the parent is a map type a new key is generated else if the parent is an array type the new node is prepended to the array.

Parameters
parent
type
Returns
Returns true on success else returns false.

◆ isContainer()

bool MetadataModel::isContainer ( const QModelIndex &  index) const

Tests if the given index is a container type, either an array or object type.

Parameters
indexThe given index to test if it is a container type.
Returns
Returns true if the given index is a container type else returns false.

◆ isImage()

bool MetadataModel::isImage ( const QModelIndex &  index) const

Tests if the given index is a bytes type which stores the data of an image.

Parameters
indexThe given index to test if it is an image.
Returns
Returns true if the given index is an image else returns false.

◆ meta()

EMetadata MetadataModel::meta ( ) const

Returns this model's data tree in the form of metadata objects. The root metadata object returned is an object type that is the root of the tree for the model.

Returns
Root metadata object of this model's data tree.

◆ mimeData()

QMimeData * MetadataModel::mimeData ( const QModelIndexList &  indexes) const
finaloverridevirtual

This implements the interface that creates a new qt mime data object when a drag and drop action is initiated. This model creates a custom mime data type just for this model which consists of a node pointer that will be copied or moved. This model does not support multiple indexes being drag and dropped at once so only the first index in the list of indexes will ever be used.

Parameters
indexesList of indexes that is being requested for drag and drop action. This model only uses the first index in the list.
Returns
Pointer to new qt mime data object.

◆ mimeTypes()

QStringList MetadataModel::mimeTypes ( ) const
finaloverridevirtual

This implements the interface that informs Qt what mime types this model supports for drag and drop support.

Returns
List of mime types this model supports for drag and drop.

◆ parent()

QModelIndex MetadataModel::parent ( const QModelIndex &  child) const
finaloverridevirtual

This implements the interface that returns the parent index of the given index for this model.

Parameters
childThe child index of the parent index to be found.
Returns
Parent index of the given index.

◆ readOnly()

bool MetadataModel::readOnly ( ) const

Returns the read only state of this model.

Returns
True if this model is read only or false otherwise.

◆ remove()

bool MetadataModel::remove ( const QModelIndex &  index)

Removes the given index from this model.

Parameters
indexThe given index that is deleted.
Returns
Returns true on success or false on failure.

◆ rowCount()

int MetadataModel::rowCount ( const QModelIndex &  parent) const
finaloverridevirtual

This implements the interface that returns the number of rows a given index contains. This number resolves to the number of nodes contained in the node of the given index. If the node is not a container 0 is returned.

Parameters
parentThe index whose number of rows are returned.
Returns
The number of rows for the given index.

◆ setData()

bool MetadataModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role 
)
finaloverridevirtual

This implements the interface that sets the data of a given index with the given role. The only role this model implements is the edit role. All other roles are ignored and false is returned.

Parameters
indexThe index whose data will be changed.
valueThe new value for the given index's data.
roleThe role of the data being set.
Returns
Returns true if the data of the given index was successfully changed, else returns false.

◆ setMeta()

void MetadataModel::setMeta ( const EMetadata newRoot)

This sets its model's data to the given metadata value. Any data stored within the model is removed and overwritten. The metadata object given must be an object type or this will throw an exception.

Parameters
newRootThe given metadata root object that will be copied into this model's data.

◆ setReadOnly()

void MetadataModel::setReadOnly ( bool  state)

Set the read only state of this model.

Parameters
stateNew boolean value for this model's read only state.

◆ supportedDropActions()

Qt::DropActions MetadataModel::supportedDropActions ( ) const
finaloverridevirtual

This implements the interface that informs Qt what drag and drop actions this model supports. The drag and drop actions this model supports is moving and copying.

Returns
Supported drag and drop actions for this model.

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