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

A default concrete implementation of AbstractGridModel that stores items in a QVector. More...

#include <BasicGridModel.h++>

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

Public Member Functions

 BasicGridModel (int rows=0, int columns=0, QObject *parent=NULL)
 Constructs a new BasicGridModel with the given dimensions. More...
 
virtual ~BasicGridModel ()
 Destructor. More...
 
virtual QPoint positionOf (const T *item) const
 Returns the row and column position of the given item in the model. 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...
 
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

virtual void resizeData (int rows, int columns)
 Resizes the model. More...
 
virtual T * getAt (int row, int column) const
 Returns the item at the given row and column. More...
 
virtual T * takeAt (int row, int column)
 Removes and returns the item at the given row and column. More...
 
virtual void setAt (T *item, int row, int column)
 Sets the item at the given row and column. More...
 
virtual void removeAll ()
 Removes all items from the model. More...
 
virtual bool isEditable (const T &item) const
 Tests if a given item is editable. 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 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 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::BasicGridModel< T, IS, OS >

A default concrete implementation of AbstractGridModel that stores items in a QVector.

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

Constructor & Destructor Documentation

◆ BasicGridModel()

BasicGridModel ( int  rows = 0,
int  columns = 0,
QObject *  parent = NULL 
)

Constructs a new BasicGridModel with the given dimensions.

Parameters
rowsThe number of rows for the model.
columnsThe number of columns for the model.

◆ ~BasicGridModel()

virtual ~BasicGridModel ( )
virtual

Destructor.

Member Function Documentation

◆ clear()

void clear ( )
inherited

Removes all items from the model.

All items in the model are automatically deleted.

◆ columnCount()

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

Specified by QAbstractItemModel.

◆ columns()

int columns ( ) const
inherited

Returns the number of columns in the model.

◆ data()

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

Specified by QAbstractItemModel.

◆ dropMimeData()

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

Specified by QAbstractItemModel.

◆ dropOtherMimeData()

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

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
virtualinherited

Specified by QAbstractItemModel.

◆ getAt()

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

Returns the item at the given row and column.

Implements AbstractGridModel< T, IS, OS >.

◆ getColumnHeaderAlignment()

virtual Qt::AlignmentFlag getColumnHeaderAlignment ( ) const
protectedvirtualinherited

Returns the preferred column (horizontal) header label alignment.

◆ getColumnName()

virtual QString getColumnName ( int  column) const
virtualinherited

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
protectedvirtualinherited

Returns the icon for a given item, if any.

◆ getItemAt()

T* getItemAt ( int  row,
int  column 
) const
inherited

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
protectedvirtualinherited

Returns the preferred row (vertical) header label alignment.

◆ getRowName()

virtual QString getRowName ( int  row) const
virtualinherited

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
protectedvirtualinherited

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

◆ getValue()

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

Returns the display object for the given item.

◆ getValueAlignment()

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

Returns the preferred alignment of a given item.

◆ hasChildren()

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

Specified by QAbstractItemModel.

◆ headerData()

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

Specified by QAbstractItemModel.

◆ index()

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

Specified by QAbstractItemModel.

◆ isCellEmpty()

bool isCellEmpty ( int  row,
int  column 
) const
inherited

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
protectedvirtualinherited

Tests if a given item is checkable.

◆ isChecked()

virtual bool isChecked ( const T &  item) const
protectedvirtualinherited

Tests if a given item is currently checked.

◆ isDraggable()

virtual bool isDraggable ( const T &  item) const
protectedvirtualinherited

Tests if a given item can be dragged.

◆ isDroppable()

virtual bool isDroppable ( const T &  item) const
protectedvirtualinherited

Tests if a given item can be dropped onto.

◆ isEditable() [1/2]

bool isEditable ( ) const
inherited

Tests the editability of the model.

◆ isEditable() [2/2]

virtual bool isEditable ( const T &  item) const
protectedvirtualinherited

Tests if a given item is editable.

◆ isEmpty()

bool isEmpty ( ) const
inherited

Tests if the model is empty.

◆ isEmptyDroppable()

virtual bool isEmptyDroppable ( ) const
protectedvirtualinherited

Tests if an empty cell can be dropped onto.

◆ itemAdded()

virtual void itemAdded ( const T *  item)
protectedvirtualinherited

Called when an item has been added to the model.

The default implementation is a no-op.

◆ itemCount()

int itemCount ( ) const
inherited

Returns the number of items in the model.

◆ itemMimeType()

virtual QString itemMimeType ( ) const
protectedpure virtualinherited

Returns the model's native MIME-type.

◆ itemRemoved()

virtual void itemRemoved ( const T &  item)
protectedvirtualinherited

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)
protectedvirtualinherited

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
virtualinherited

Specified by QAbstractItemModel.

◆ mimeTypes()

virtual QStringList mimeTypes ( ) const
virtualinherited

Specified by QAbstractItemModel.

◆ otherMimeTypes()

virtual QStringList otherMimeTypes ( ) const
protectedvirtualinherited

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
virtualinherited

Specified by QAbstractItemModel.

◆ positionOf()

virtual QPoint positionOf ( const T *  item) const
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.

Implements AbstractGridModel< T, IS, OS >.

◆ readEpilog()

virtual void readEpilog ( IS &  stream)
protectedvirtualinherited

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)
protectedvirtualinherited

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)
protectedvirtualinherited

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 ( )
protectedvirtual

Removes all items from the model.

All cells become empty.

Implements AbstractGridModel< T, IS, OS >.

◆ removeItemAt()

void removeItemAt ( int  row,
int  column 
)
inherited

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

Parameters
rowThe row.
columnThe column.

◆ resize()

void resize ( int  rows,
int  columns 
)
inherited

Resizes the model.

Parameters
rowsThe new row count.
columnsThe new column count.

◆ resizeData()

virtual void resizeData ( int  rows,
int  columns 
)
protectedvirtual

Resizes the model.

Implements AbstractGridModel< T, IS, OS >.

◆ rowCount()

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

Specified by QAbstractItemModel.

◆ rows()

int rows ( ) const
inherited

Returns the number of rows in the model.

◆ setAt()

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

Sets the item at the given row and column.

Implements AbstractGridModel< T, IS, OS >.

◆ setChecked()

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

Sets the checked state of a checkable item.

◆ setData()

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

Specified by QAbstractItemModel.

◆ setEditable()

void setEditable ( bool  editable)
inherited

Sets the editability of the model.

◆ setItemAt()

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

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)
inherited

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 
)
protectedvirtualinherited

Sets the value of an edited item.

◆ takeAt()

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

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

Implements AbstractGridModel< T, IS, OS >.

◆ takeItemAt()

T* takeItemAt ( int  row,
int  column 
)
inherited

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)
inherited

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 
)
inherited

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
protectedvirtualinherited

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
protectedvirtualinherited

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
protectedvirtualinherited

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: