Quark  0.1
AbstractGridModel< T, IS, OS > Class Template Referenceabstract

An abstract base class for grid data models, i.e., models in which every cell contains the same type of object. More...

#include <AbstractGridModel.h++>

Inheritance diagram for AbstractGridModel< T, IS, OS >:

Public Member Functions

virtual ~AbstractGridModel ()
 Destructor. More...
 
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 Specified by QAbstractItemModel. More...
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const
 Specified by QAbstractItemModel. More...
 
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 Specified by QAbstractItemModel. More...
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 Specified by QAbstractItemModel. More...
 
virtual bool hasChildren (const QModelIndex &parent=QModelIndex()) const
 Specified by QAbstractItemModel. More...
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 Specified by QAbstractItemModel. More...
 
virtual QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Specified by QAbstractItemModel. More...
 
virtual QModelIndex parent (const QModelIndex &index) const
 Specified by QAbstractItemModel. More...
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const
 Specified by QAbstractItemModel. More...
 
virtual QStringList mimeTypes () const
 Specified by QAbstractItemModel. More...
 
virtual QMimeData * mimeData (const QModelIndexList &indexes) const
 Specified by QAbstractItemModel. More...
 
virtual bool dropMimeData (const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 Specified by QAbstractItemModel. More...
 
void resize (int rows, int columns)
 Resizes the model. More...
 
int rows () const
 Returns the number of rows in the model. More...
 
int columns () const
 Returns the number of columns in the model. More...
 
int itemCount () const
 Returns the number of items in the model. More...
 
void clear ()
 Removes all items from the model. More...
 
bool isEmpty () const
 Tests if the model is empty. More...
 
bool setItems (QList< T *> items)
 Populates the model with items from a QList. More...
 
void setItemAt (T *item, int row, int column)
 Sets an item at the specified row and column. More...
 
T * getItemAt (int row, int column) const
 Returns the item at the specified row and column. More...
 
T * takeItemAt (int row, int column)
 Removes and returns the item at the specified row and column. More...
 
void removeItemAt (int row, int column)
 Removes and deletes the item at the specified row and column. More...
 
void updateItem (T *item)
 Notifies the model that the given item has changed in some way. More...
 
void updateItemAt (int row, int column)
 Notifies the model that the item at the given position has changed in some way. More...
 
virtual QPoint positionOf (const T *item) const =0
 Returns the row and column position of the given item in the model. More...
 
bool isCellEmpty (int row, int column) const
 Tests if the given cell of the model is empty. More...
 
void setEditable (bool editable)
 Sets the editability of the model. More...
 
bool isEditable () const
 Tests the editability of the model. More...
 
virtual QVariant getValue (const T &item) const =0
 Returns the display object for the given item. More...
 
virtual QString getRowName (int row) const
 Returns the name of the given row. More...
 
virtual QString getColumnName (int column) const
 Returns the name of the given column. More...
 

Protected Member Functions

 AbstractGridModel (QObject *parent=NULL)
 Constructor. More...
 
virtual QIcon getIcon (const T &item) const
 Returns the icon for a given item, if any. More...
 
virtual QSize getSize (const T &item) const
 Returns the preferred display size of a given item, if any. More...
 
virtual Qt::AlignmentFlag getValueAlignment (const T &item) const
 Returns the preferred alignment of a given item. More...
 
virtual Qt::AlignmentFlag getRowHeaderAlignment () const
 Returns the preferred row (vertical) header label alignment. More...
 
virtual Qt::AlignmentFlag getColumnHeaderAlignment () const
 Returns the preferred column (horizontal) header label alignment. More...
 
virtual void setValue (T *item, const QVariant &value)
 Sets the value of an edited item. More...
 
virtual void setChecked (T *item, bool checked)
 Sets the checked state of a checkable item. More...
 
virtual bool isEditable (const T &item) const
 Tests if a given item is editable. More...
 
virtual bool isCheckable (const T &item) const
 Tests if a given item is checkable. More...
 
virtual bool isChecked (const T &item) const
 Tests if a given item is currently checked. More...
 
virtual bool isDraggable (const T &item) const
 Tests if a given item can be dragged. More...
 
virtual bool isDroppable (const T &item) const
 Tests if a given item can be dropped onto. More...
 
virtual bool isEmptyDroppable () const
 Tests if an empty cell can be dropped onto. More...
 
virtual void itemAdded (const T *item)
 Called when an item has been added to the model. More...
 
virtual void itemUpdated (const T &item)
 Called when an item has been updated in the model. More...
 
virtual void itemRemoved (const T &item)
 Called when an item is about to be removed from the model. More...
 
virtual T * getAt (int row, int column) const =0
 Returns the item at the given row and column. More...
 
virtual T * takeAt (int row, int column)=0
 Removes and returns the item at the given row and column. More...
 
virtual void setAt (T *item, int row, int column)=0
 Sets the item at the given row and column. More...
 
virtual void removeAll ()=0
 Removes all items from the model. More...
 
virtual void resizeData (int rows, int columns)=0
 Resizes the model. More...
 
virtual bool dropOtherMimeData (const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 Handles the dropping of MIME data with a MIME-type that is supported by (but not native to) this model. More...
 
virtual QStringList otherMimeTypes () const
 Returns a list of additional MIME-types that can be dropped onto the model. More...
 
virtual QString itemMimeType () const =0
 Returns the model's native MIME-type. More...
 
virtual void writeProlog (OS &stream) const
 Writes any necessary prolog (e.g., an XML open-tag) when serializing items to be dragged out of the model. More...
 
virtual void writeItem (const T &item, OS &stream) const
 Serializes an item that is being dragged out of the model. More...
 
virtual void writeEpilog (OS &stream) const
 Writes any necessary epilog (e.g., an XML close-tag) when serializing items to be dragged out of the model. More...
 
virtual void readProlog (IS &stream)
 Reads any necessary prolog (e.g., an XML open-tag) when deserializing items that are being dropped into the model. More...
 
virtual T * readItem (IS &stream)
 Deserializes an item that is being dropped into the model. More...
 
virtual void readEpilog (IS &stream)
 Reads any necessary epilog (e.g., an XML close-tag) when deserializing items that are being dropped into the model. More...
 

Detailed Description

template<class T, class IS = QDataStream, class OS = QDataStream>
class quark::gui::AbstractGridModel< T, IS, OS >

An abstract base class for grid data models, i.e., models in which every cell contains the same type of object.

This class does not specify the data structure for storing the model's contents; see BasicGridModel for a default implementation that stores items in a QVector.

If the model supports drag and/or drop, data streams of the specified type will be instantiated to serialize/deserialize the dragged objects.

Template Parameters
TThe type of the objects contained in this model.
ISA class for deserializing objects of type T.
OSA class for serializing objects of type T.
Author
Mark Lindner

Constructor & Destructor Documentation

◆ ~AbstractGridModel()

virtual ~AbstractGridModel ( )
virtual

Destructor.

All items in the model are automatically deleted.

◆ AbstractGridModel()

AbstractGridModel ( QObject *  parent = NULL)
protected

Constructor.

Member Function Documentation

◆ clear()

void clear ( )

Removes all items from the model.

All items in the model are automatically deleted.

◆ columnCount()

virtual int columnCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Specified by QAbstractItemModel.

◆ columns()

int columns ( ) const

Returns the number of columns in the model.

◆ data()

virtual QVariant data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
virtual

Specified by QAbstractItemModel.

◆ dropMimeData()

virtual bool dropMimeData ( const QMimeData *  mimeData,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
)
virtual

Specified by QAbstractItemModel.

◆ dropOtherMimeData()

virtual bool dropOtherMimeData ( const QMimeData *  mimeData,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
)
protectedvirtual

Handles the dropping of MIME data with a MIME-type that is supported by (but not native to) this model.

The default implementation is a no-op that returns false.

Parameters
mimeDataThe MIME data.
actionThe drop action.
rowThe row onto which the data is being dropped.
columnThe column onto which the data is being dropped.
parentThe parent index.
Returns
true if the drop was handled successfully, false otherwise.

◆ flags()

virtual Qt::ItemFlags flags ( const QModelIndex &  index) const
virtual

Specified by QAbstractItemModel.

◆ getAt()

virtual T* getAt ( int  row,
int  column 
) const
protectedpure virtual

Returns the item at the given row and column.

Implemented in BasicGridModel< T, IS, OS >.

◆ getColumnHeaderAlignment()

virtual Qt::AlignmentFlag getColumnHeaderAlignment ( ) const
protectedvirtual

Returns the preferred column (horizontal) header label alignment.

◆ getColumnName()

virtual QString getColumnName ( int  column) const
virtual

Returns the name of the given column.

This name will be used for the corresponding label in a view's horizontal header.

Parameters
columnThe column.
Returns
The name, or a null string if the column has no name.

◆ getIcon()

virtual QIcon getIcon ( const T &  item) const
protectedvirtual

Returns the icon for a given item, if any.

◆ getItemAt()

T* getItemAt ( int  row,
int  column 
) const

Returns the item at the specified row and column.

Parameters
rowThe row.
columnThe column.
Returns
The item at the given position, or NULL if there is no item at that position.

◆ getRowHeaderAlignment()

virtual Qt::AlignmentFlag getRowHeaderAlignment ( ) const
protectedvirtual

Returns the preferred row (vertical) header label alignment.

◆ getRowName()

virtual QString getRowName ( int  row) const
virtual

Returns the name of the given row.

This name will be used for the corresponding label in a view's vertical header.

Parameters
rowThe row.
Returns
The name, or a null string if the row has no name.

◆ getSize()

virtual QSize getSize ( const T &  item) const
protectedvirtual

Returns the preferred display size of a given item, if any.

◆ getValue()

virtual QVariant getValue ( const T &  item) const
pure virtual

Returns the display object for the given item.

◆ getValueAlignment()

virtual Qt::AlignmentFlag getValueAlignment ( const T &  item) const
protectedvirtual

Returns the preferred alignment of a given item.

◆ hasChildren()

virtual bool hasChildren ( const QModelIndex &  parent = QModelIndex()) const
virtual

Specified by QAbstractItemModel.

◆ headerData()

virtual QVariant headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Specified by QAbstractItemModel.

◆ index()

virtual QModelIndex index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
virtual

Specified by QAbstractItemModel.

◆ isCellEmpty()

bool isCellEmpty ( int  row,
int  column 
) const

Tests if the given cell of the model is empty.

Parameters
rowThe row.
columnThe column.
Returns
true if no item is stored at the given position, false otherwise.

◆ isCheckable()

virtual bool isCheckable ( const T &  item) const
protectedvirtual

Tests if a given item is checkable.

◆ isChecked()

virtual bool isChecked ( const T &  item) const
protectedvirtual

Tests if a given item is currently checked.

◆ isDraggable()

virtual bool isDraggable ( const T &  item) const
protectedvirtual

Tests if a given item can be dragged.

◆ isDroppable()

virtual bool isDroppable ( const T &  item) const
protectedvirtual

Tests if a given item can be dropped onto.

◆ isEditable() [1/2]

bool isEditable ( ) const

Tests the editability of the model.

◆ isEditable() [2/2]

virtual bool isEditable ( const T &  item) const
protectedvirtual

Tests if a given item is editable.

◆ isEmpty()

bool isEmpty ( ) const

Tests if the model is empty.

◆ isEmptyDroppable()

virtual bool isEmptyDroppable ( ) const
protectedvirtual

Tests if an empty cell can be dropped onto.

◆ itemAdded()

virtual void itemAdded ( const T *  item)
protectedvirtual

Called when an item has been added to the model.

The default implementation is a no-op.

◆ itemCount()

int itemCount ( ) const

Returns the number of items in the model.

◆ itemMimeType()

virtual QString itemMimeType ( ) const
protectedpure virtual

Returns the model's native MIME-type.

◆ itemRemoved()

virtual void itemRemoved ( const T &  item)
protectedvirtual

Called when an item is about to be removed from the model.

The default implementation is a no-op.

◆ itemUpdated()

virtual void itemUpdated ( const T &  item)
protectedvirtual

Called when an item has been updated in the model.

The default implementation is a no-op.

◆ mimeData()

virtual QMimeData* mimeData ( const QModelIndexList &  indexes) const
virtual

Specified by QAbstractItemModel.

◆ mimeTypes()

virtual QStringList mimeTypes ( ) const
virtual

Specified by QAbstractItemModel.

◆ otherMimeTypes()

virtual QStringList otherMimeTypes ( ) const
protectedvirtual

Returns a list of additional MIME-types that can be dropped onto the model.

The default implementation returns an empty list.

◆ parent()

virtual QModelIndex parent ( const QModelIndex &  index) const
virtual

Specified by QAbstractItemModel.

◆ positionOf()

virtual QPoint positionOf ( const T *  item) const
pure virtual

Returns the row and column position of the given item in the model.

Parameters
itemThe item.
Returns
The position of the item. If the item is not actually in the model, the x and y components of the position will be -1.

Implemented in BasicGridModel< T, IS, OS >.

◆ readEpilog()

virtual void readEpilog ( IS &  stream)
protectedvirtual

Reads any necessary epilog (e.g., an XML close-tag) when deserializing items that are being dropped into the model.

This method is called at the end of a drop operation. The default implementation is a no-op.

Parameters
streamThe stream from which items are being deserialized.

◆ readItem()

virtual T* readItem ( IS &  stream)
protectedvirtual

Deserializes an item that is being dropped into the model.

This method is called once for each item that is being dropped during a drop operation. The default implementation is a no-op.

Parameters
streamThe stream from which items are being deserialized.
Returns
item The deserialized item.

◆ readProlog()

virtual void readProlog ( IS &  stream)
protectedvirtual

Reads any necessary prolog (e.g., an XML open-tag) when deserializing items that are being dropped into the model.

This method is called at the beginning of a drop operation. The default implementation is a no-op.

Parameters
streamThe stream from which items are being deserialized.

◆ removeAll()

virtual void removeAll ( )
protectedpure virtual

Removes all items from the model.

All cells become empty.

Implemented in BasicGridModel< T, IS, OS >.

◆ removeItemAt()

void removeItemAt ( int  row,
int  column 
)

Removes and deletes the item at the specified row and column.

Parameters
rowThe row.
columnThe column.

◆ resize()

void resize ( int  rows,
int  columns 
)

Resizes the model.

Parameters
rowsThe new row count.
columnsThe new column count.

◆ resizeData()

virtual void resizeData ( int  rows,
int  columns 
)
protectedpure virtual

Resizes the model.

Implemented in BasicGridModel< T, IS, OS >.

◆ rowCount()

virtual int rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Specified by QAbstractItemModel.

◆ rows()

int rows ( ) const

Returns the number of rows in the model.

◆ setAt()

virtual void setAt ( T *  item,
int  row,
int  column 
)
protectedpure virtual

Sets the item at the given row and column.

Implemented in BasicGridModel< T, IS, OS >.

◆ setChecked()

virtual void setChecked ( T *  item,
bool  checked 
)
protectedvirtual

Sets the checked state of a checkable item.

◆ setData()

virtual bool setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Specified by QAbstractItemModel.

◆ setEditable()

void setEditable ( bool  editable)

Sets the editability of the model.

◆ setItemAt()

void setItemAt ( T *  item,
int  row,
int  column 
)

Sets an item at the specified row and column.

Any old item at the given position is deleted.

Parameters
itemThe item. The model takes ownership of the object.
rowThe row at which to place the item.
columnThe column at which to place the item.

◆ setItems()

bool setItems ( QList< T *>  items)

Populates the model with items from a QList.

The model is filled row by row, starting with the first row.

Parameters
itemsThe items.
Returns
true on success, or false if the model is too small to accommodate the items.

◆ setValue()

virtual void setValue ( T *  item,
const QVariant &  value 
)
protectedvirtual

Sets the value of an edited item.

◆ takeAt()

virtual T* takeAt ( int  row,
int  column 
)
protectedpure virtual

Removes and returns the item at the given row and column.

Implemented in BasicGridModel< T, IS, OS >.

◆ takeItemAt()

T* takeItemAt ( int  row,
int  column 
)

Removes and returns the item at the specified row and column.

The model relinquishes ownership of the returned item, so it must eventually be deleted by the caller.

Parameters
rowThe row.
columnThe column.
Returns
The item at the given position, or NULL if there is no item at that position.

◆ updateItem()

void updateItem ( T *  item)

Notifies the model that the given item has changed in some way.

The model will invoke the appropriate signal(s) to notify any attached views that the corresponding cell needs to be redrawn.

Parameters
itemThe item that changed. If this item is not actually in the model, the call will be a no-op.

◆ updateItemAt()

void updateItemAt ( int  row,
int  column 
)

Notifies the model that the item at the given position has changed in some way.

The model will invoke the appropriate signal(s) to notify any attached views that the corresponding cell needs to be redrawn.

Parameters
rowThe row of the item that changed.
columnThe column of the item that changed.

◆ writeEpilog()

virtual void writeEpilog ( OS &  stream) const
protectedvirtual

Writes any necessary epilog (e.g., an XML close-tag) when serializing items to be dragged out of the model.

This method is called at the end of a drag operation. The default implementation is a no-op.

Parameters
streamThe stream to which items are being serialized.

◆ writeItem()

virtual void writeItem ( const T &  item,
OS &  stream 
) const
protectedvirtual

Serializes an item that is being dragged out of the model.

This method is called once for each item that is being dragged during a drag operation. The default implementation is a no-op.

Parameters
itemThe item to serialize.
streamThe stream to which items are being serialized.

◆ writeProlog()

virtual void writeProlog ( OS &  stream) const
protectedvirtual

Writes any necessary prolog (e.g., an XML open-tag) when serializing items to be dragged out of the model.

This method is called at the beginning of a drag operation. The default implementation is a no-op.

Parameters
streamThe stream to which items are being serialized.

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