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

A partial implementation of AbstractTableModel that stores its elements in a QVector. More...

#include <BasicTableModel.h++>

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

Public Member Functions

virtual ~BasicTableModel ()
 Destructor. More...
 
virtual int itemCount () const
 Returns the number of items in the model. More...
 
virtual int indexOf (const T *item) const
 Returns the row 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 removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
 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 *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 Specified by QAbstractItemModel. More...
 
void clear ()
 Removes all items from the model. More...
 
bool isEmpty () const
 Tests if the model is empty. More...
 
void addItem (T *item)
 Adds an item to the model. More...
 
void insertItemAt (T *item, int row)
 Inserts an item into the model at the given row position. More...
 
T * getItemAt (int row) const
 Returns the item in the specified row. More...
 
T * takeItemAt (int row)
 Removes and returns the item at the specified row. More...
 
void removeItem (T *item)
 Removes and deletes the specified item from the model. More...
 
void removeItemAt (int row)
 Removes and deletes the item at the specified row. More...
 
void updateItem (T *item)
 Notifies the model that the specified item in the model has changed in some way. More...
 
void updateItemAt (int row)
 Notifies the model that the item in the given row has changed in some way. More...
 
bool moveItemDownAt (int row)
 Moves the given row down one position in the model. More...
 
bool moveItemUpAt (int row)
 Moves the given row up one position in the model. More...
 
int indexOfItemEqualTo (const T &item) const
 
bool containsItemEqualTo (const T &item) const
 
virtual QString getRowName (int row) const
 Returns the name of the given row. More...
 
virtual QVariant getFieldValue (const T &item, int field) const =0
 Returns the value of the given field of an object. More...
 
virtual QVariant getFieldValueForRole (const T &item, int field, int role) const
 
virtual QVariant getFieldValueForRole (int field, int role) const
 
virtual QVariant getSortValue (const T &item, int field) const
 
virtual bool write (OS &stream) const
 
virtual bool read (IS &stream)
 
 Q_DECLARE_FLAGS (Options, Option)
 
void setEditable (bool editable)
 Sets the editability of the model. More...
 
bool isEditable () const
 Tests the editability of the model. More...
 
bool isSorted () const
 Tests if the model is a sorted model. More...
 
int fieldCount () const
 Returns the number of fields in the model. More...
 
const FieldgetField (int field) const
 Returns the specified field of the model. More...
 
QString getFieldName (int field) const
 Returns the name of the specified field. More...
 

Static Public Attributes

static const int DescriptionRole
 An item's description role. More...
 
static const int SortRole
 An item's sort role. More...
 

Protected Types

typedef AbstractTableModelBase::Option Option
 
typedef AbstractTableModelBase::Options Options
 

Protected Member Functions

 BasicTableModel (QFlags< Option > options=0, QObject *parent=NULL)
 
virtual T * getAt (int row) const
 Returns the item at the given row. More...
 
virtual T * takeAt (int row)
 Removes and returns the item at the given row. More...
 
virtual void insertAt (T *item, int row)
 Inserts an item at the given row, or at the end if the row is negative. More...
 
virtual void removeAll ()
 Removes all items from the model. 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 getRowHeaderAlignment () const
 Returns the preferred row (vertical) header label alignment. More...
 
virtual void setFieldValue (T *item, int field, const QVariant &value)
 Sets the value of an edited field. More...
 
virtual void setFieldChecked (T *item, int field, bool checked)
 Sets the checked state of a checkable field. More...
 
virtual bool isFieldEditable (const T &item, int field) const
 Tests if a field of a given item is editable. More...
 
virtual bool isFieldCheckable (const T &item, int field) const
 Tests if a field of a given item is checkable. More...
 
virtual bool isFieldChecked (const T &item, int field) const
 Tests if a field of 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 isRootDroppable () const
 Tests if new item(s) can be dropped onto a non-existent rows in the model. 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 int getSortIndex (const T &item) const
 Calculates the row at which a new item should be inserted in a presumably sorted 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
 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 bool 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 bool readEpilog (IS &stream)
 Reads any necessary epilog (e.g., an XML close-tag) when deserializing items that are being dropped into the model. More...
 
FieldaddField (const QString &name)
 Adds a new field to the model. More...
 

Detailed Description

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

A partial implementation of AbstractTableModel that stores its elements in a QVector.

Author
Mark Lindner

Member Typedef Documentation

◆ Option

◆ Options

typedef AbstractTableModelBase::Options Options
protected

Constructor & Destructor Documentation

◆ ~BasicTableModel()

virtual ~BasicTableModel ( )
virtual

Destructor.

◆ BasicTableModel()

BasicTableModel ( QFlags< Option options = 0,
QObject *  parent = NULL 
)
protected

Member Function Documentation

◆ addField()

Field& addField ( const QString &  name)
protectedinherited

Adds a new field to the model.

Parameters
nameThe name of the field. This will be used as the header label for the corresponding column.
Returns
Field A field object representing this field; the appearance of the items in the corresponding column can be customized by setting properties of this object.

◆ addItem()

void addItem ( T *  item)
inherited

Adds an item to the model.

If the model is sorted, the item is inserted at the appropriate sort position; otherwise, it is added at the end.

Parameters
itemThe item. The model takes ownership of the object.

◆ 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.

◆ containsItemEqualTo()

bool containsItemEqualTo ( const T &  item) const
inherited

◆ data()

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

Specified by QAbstractItemModel.

◆ dropMimeData()

virtual bool dropMimeData ( const QMimeData *  data,
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.

◆ fieldCount()

int fieldCount ( ) const
inherited

Returns the number of fields in the model.

◆ flags()

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

Specified by QAbstractItemModel.

◆ getAt()

virtual T* getAt ( int  row) const
protectedvirtual

Returns the item at the given row.

Implements AbstractTableModel< T, IS, OS >.

◆ getField()

const Field& getField ( int  field) const
inherited

Returns the specified field of the model.

◆ getFieldName()

QString getFieldName ( int  field) const
inherited

Returns the name of the specified field.

◆ getFieldValue()

virtual QVariant getFieldValue ( const T &  item,
int  field 
) const
pure virtualinherited

Returns the value of the given field of an object.

This is the display value for the corresponding column of the model.

Parameters
itemThe item.
fieldThe field number.
Returns
The value of the field.

Implemented in RecentFileTableModel, SearchPathModel, and StringListModel.

◆ getFieldValueForRole() [1/2]

virtual QVariant getFieldValueForRole ( const T &  item,
int  field,
int  role 
) const
virtualinherited

◆ getFieldValueForRole() [2/2]

virtual QVariant getFieldValueForRole ( int  field,
int  role 
) const
virtualinherited

◆ getIcon()

virtual QIcon getIcon ( const T &  item) const
protectedvirtualinherited

Returns the icon for a given item, if any.

Reimplemented in SearchPathModel.

◆ getItemAt()

T* getItemAt ( int  row) const
inherited

Returns the item in the specified row.

Parameters
rowThe row.
Returns
The item, or NULL if the row is invalid.

◆ 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.

◆ getSortIndex()

virtual int getSortIndex ( const T &  item) const
protectedvirtualinherited

Calculates the row at which a new item should be inserted in a presumably sorted model.

The default implementation does a binary search to find the position.

◆ getSortValue()

virtual QVariant getSortValue ( const T &  item,
int  field 
) const
virtualinherited

◆ 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.

◆ indexOf()

virtual int indexOf ( const T *  item) const
virtual

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

Parameters
itemThe item.
Returns
The row of the item. If the item is not actually in the model, returns -1.

Implements AbstractTableModel< T, IS, OS >.

◆ indexOfItemEqualTo()

int indexOfItemEqualTo ( const T &  item) const
inherited

◆ insertAt()

virtual void insertAt ( T *  item,
int  row 
)
protectedvirtual

Inserts an item at the given row, or at the end if the row is negative.

Implements AbstractTableModel< T, IS, OS >.

◆ insertItemAt()

void insertItemAt ( T *  item,
int  row 
)
inherited

Inserts an item into the model at the given row position.

Parameters
itemThe item. The model takes ownership of the object.
rowThe row at which to insert the item. If negative, inserts the item after the last row.

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

bool isEditable ( ) const
inlineinherited

Tests the editability of the model.

◆ isEmpty()

bool isEmpty ( ) const
inherited

Tests if the model is empty.

◆ isFieldCheckable()

virtual bool isFieldCheckable ( const T &  item,
int  field 
) const
protectedvirtualinherited

Tests if a field of a given item is checkable.

Parameters
itemThe item.
fieldThe field number.
Returns
true if the field is checkable for this item, false otherwise.

◆ isFieldChecked()

virtual bool isFieldChecked ( const T &  item,
int  field 
) const
protectedvirtualinherited

Tests if a field of a given item is currently checked.

◆ isFieldEditable()

virtual bool isFieldEditable ( const T &  item,
int  field 
) const
protectedvirtualinherited

Tests if a field of a given item is editable.

Parameters
itemThe item.
fieldThe field number.
Returns
true if the field is editable for this item, false otherwise.

◆ isRootDroppable()

virtual bool isRootDroppable ( ) const
protectedvirtualinherited

Tests if new item(s) can be dropped onto a non-existent rows in the model.

◆ isSorted()

bool isSorted ( ) const
inherited

Tests if the model is a sorted model.

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

virtual int itemCount ( ) const
virtual

Returns the number of items in the model.

Implements AbstractTableModel< T, IS, OS >.

◆ itemMimeType()

virtual QString itemMimeType ( ) const
protectedvirtualinherited

Returns the model's native MIME-type.

Reimplemented in RecentFileTableModel.

◆ 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.

◆ moveItemDownAt()

bool moveItemDownAt ( int  row)
inherited

Moves the given row down one position in the model.

Parameters
rowThe row to move. If the row is the last row, the call will be a no-op.

◆ moveItemUpAt()

bool moveItemUpAt ( int  row)
inherited

Moves the given row up one position in the model.

Parameters
rowThe row to move. If the row is the first row, the call will be a no-op.

◆ 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.

◆ Q_DECLARE_FLAGS()

Q_DECLARE_FLAGS ( Options  ,
Option   
)
inherited

◆ read()

virtual bool read ( IS &  stream)
virtualinherited

◆ readEpilog()

virtual bool 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.

Reimplemented in RecentFileTableModel.

◆ readProlog()

virtual bool 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 rows are removed.

Implements AbstractTableModel< T, IS, OS >.

◆ removeItem()

void removeItem ( T *  item)
inherited

Removes and deletes the specified item from the model.

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

◆ removeItemAt()

void removeItemAt ( int  row)
inherited

Removes and deletes the item at the specified row.

Parameters
rowThe row.

◆ removeRows()

virtual bool removeRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
virtualinherited

Specified by QAbstractItemModel.

◆ rowCount()

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

Specified by QAbstractItemModel.

◆ setData()

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

Specified by QAbstractItemModel.

◆ setEditable()

void setEditable ( bool  editable)
inlineinherited

Sets the editability of the model.

◆ setFieldChecked()

virtual void setFieldChecked ( T *  item,
int  field,
bool  checked 
)
protectedvirtualinherited

Sets the checked state of a checkable field.

◆ setFieldValue()

virtual void setFieldValue ( T *  item,
int  field,
const QVariant &  value 
)
protectedvirtualinherited

Sets the value of an edited field.

◆ takeAt()

virtual T* takeAt ( int  row)
protectedvirtual

Removes and returns the item at the given row.

Implements AbstractTableModel< T, IS, OS >.

◆ takeItemAt()

T* takeItemAt ( int  row)
inherited

Removes and returns the item at the specified row.

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

Parameters
rowThe row.
Returns
The item in the given row, or NULL if there is no item in that row.

◆ updateItem()

void updateItem ( T *  item)
inherited

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

The model will invoke the appropriate signal(s) to notify any attached views that the corresponding cells need 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)
inherited

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

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

Parameters
rowThe row of the item that changed.

◆ write()

virtual bool write ( OS &  stream) const
virtualinherited

◆ 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.

Member Data Documentation

◆ DescriptionRole

const int DescriptionRole
staticinherited

An item's description role.

◆ SortRole

const int SortRole
staticinherited

An item's sort role.


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