Quark
0.1
|
A data model for storing a list of RecentFile objects, representing files that were "recently opened" by an application. More...
#include <RecentFileTableModel.h++>
Public Slots | |
void | addFile (const QString &path) |
Adds a new file to the model. More... | |
void | load () |
Loads the model from the settings. More... | |
void | save () |
Saves the model to the settings. More... | |
Public Member Functions | |
RecentFileTableModel (const QString &settingName, int maxItems=10, QObject *parent=NULL) | |
Constructs a new RecentFileTableModel with the given attributes. More... | |
virtual | ~RecentFileTableModel () |
void | setShowFullPath (bool showFullPath) |
Specifies whether the items will be visually represented by the full paths of the files. More... | |
bool | showFullPath () const |
Tests whether the model shows full paths. More... | |
virtual int | itemCount () const |
Returns the number of items in the model. More... | |
virtual int | indexOf (const RecentFile *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 (RecentFile *item) |
Adds an item to the model. More... | |
void | insertItemAt (RecentFile *item, int row) |
Inserts an item into the model at the given row position. More... | |
RecentFile * | getItemAt (int row) const |
Returns the item in the specified row. More... | |
RecentFile * | takeItemAt (int row) |
Removes and returns the item at the specified row. More... | |
void | removeItem (RecentFile *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 (RecentFile *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 RecentFile &item) const |
bool | containsItemEqualTo (const RecentFile &item) const |
virtual QString | getRowName (int row) const |
Returns the name of the given row. More... | |
virtual QVariant | getFieldValueForRole (const RecentFile &item, int field, int role) const |
virtual QVariant | getFieldValueForRole (int field, int role) const |
virtual QVariant | getSortValue (const RecentFile &item, int field) const |
virtual bool | write (QDataStream &stream) const |
virtual bool | read (QDataStream &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 Field & | getField (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 | |
virtual QVariant | getFieldValue (const RecentFile &item, int field) const |
Returns the value of the given field of an object. More... | |
virtual QString | itemMimeType () const |
Returns the model's native MIME-type. More... | |
virtual void | writeItem (const RecentFile &item, QDataStream &stream) |
virtual RecentFile * | readItem (QDataStream &stream) |
Deserializes an item that is being dropped into the model. More... | |
virtual RecentFile * | getAt (int row) const |
Returns the item at the given row. More... | |
virtual RecentFile * | takeAt (int row) |
Removes and returns the item at the given row. More... | |
virtual void | insertAt (RecentFile *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 RecentFile &item) const |
Returns the icon for a given item, if any. More... | |
virtual QSize | getSize (const RecentFile &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 (RecentFile *item, int field, const QVariant &value) |
Sets the value of an edited field. More... | |
virtual void | setFieldChecked (RecentFile *item, int field, bool checked) |
Sets the checked state of a checkable field. More... | |
virtual bool | isFieldEditable (const RecentFile &item, int field) const |
Tests if a field of a given item is editable. More... | |
virtual bool | isFieldCheckable (const RecentFile &item, int field) const |
Tests if a field of a given item is checkable. More... | |
virtual bool | isFieldChecked (const RecentFile &item, int field) const |
Tests if a field of a given item is currently checked. More... | |
virtual bool | isDraggable (const RecentFile &item) const |
Tests if a given item can be dragged. More... | |
virtual bool | isDroppable (const RecentFile &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 RecentFile *item) |
Called when an item has been added to the model. More... | |
virtual void | itemUpdated (const RecentFile &item) |
Called when an item has been updated in the model. More... | |
virtual void | itemRemoved (const RecentFile &item) |
Called when an item is about to be removed from the model. More... | |
virtual int | getSortIndex (const RecentFile &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 void | writeProlog (QDataStream &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 RecentFile &item, QDataStream &stream) const |
Serializes an item that is being dragged out of the model. More... | |
virtual void | writeEpilog (QDataStream &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 (QDataStream &stream) |
Reads any necessary prolog (e.g., an XML open-tag) when deserializing items that are being dropped into the model. More... | |
virtual bool | readEpilog (QDataStream &stream) |
Reads any necessary epilog (e.g., an XML close-tag) when deserializing items that are being dropped into the model. More... | |
Field & | addField (const QString &name) |
Adds a new field to the model. More... | |
A data model for storing a list of RecentFile objects, representing files that were "recently opened" by an application.
The model provides methods for reading the list from and writing it to an application setting. Typically the model would be used in conjunction with a RecentFileTableModelMenuAdapter to create a submenu of the application's File menu containing menu items for all of the recently opened files.
|
protectedinherited |
|
protectedinherited |
RecentFileTableModel | ( | const QString & | settingName, |
int | maxItems = 10 , |
||
QObject * | parent = NULL |
||
) |
Constructs a new RecentFileTableModel with the given attributes.
settingName | The name of the setting in which the list will be persisted. |
maxItems | The maximum size of the list. Once the maximum is reached, when a new item is added to the model, the least recently added item will be removed automatically. |
parent | The parent object. |
|
virtual |
|
protectedinherited |
Adds a new field to the model.
name | The name of the field. This will be used as the header label for the corresponding column. |
|
slot |
Adds a new file to the model.
path | The path of the new file. If the path already exists in the model, it is moved to the top position. |
|
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.
item | The item. The model takes ownership of the object. |
|
inherited |
Removes all items from the model.
All items in the model are automatically deleted.
|
virtualinherited |
Specified by QAbstractItemModel.
|
inherited |
|
virtualinherited |
Specified by QAbstractItemModel.
|
virtualinherited |
Specified by QAbstractItemModel.
|
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
.
mimeData | The MIME data. |
action | The drop action. |
row | The row onto which the data is being dropped. |
column | The column onto which the data is being dropped. |
parent | The parent index. |
true
if the drop was handled successfully, false
otherwise.
|
inherited |
Returns the number of fields in the model.
|
virtualinherited |
Specified by QAbstractItemModel.
|
protectedvirtualinherited |
Returns the item at the given row.
Implements AbstractTableModel< RecentFile, QDataStream, QDataStream >.
|
inherited |
Returns the specified field of the model.
|
inherited |
Returns the name of the specified field.
|
protectedvirtual |
Returns the value of the given field of an object.
This is the display value for the corresponding column of the model.
item | The item. |
field | The field number. |
Implements AbstractTableModel< RecentFile, QDataStream, QDataStream >.
|
virtualinherited |
|
virtualinherited |
|
protectedvirtualinherited |
Returns the icon for a given item, if any.
|
inherited |
Returns the item in the specified row.
row | The row. |
NULL
if the row is invalid.
|
protectedvirtualinherited |
Returns the preferred row (vertical) header label alignment.
|
virtualinherited |
Returns the name of the given row.
This name will be used for the corresponding label in a view's vertical header.
row | The row. |
|
protectedvirtualinherited |
Returns the preferred display size of a given item, if any.
|
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.
|
virtualinherited |
|
virtualinherited |
Specified by QAbstractItemModel.
|
virtualinherited |
Specified by QAbstractItemModel.
|
virtualinherited |
Specified by QAbstractItemModel.
|
virtualinherited |
Returns the row position of the given item in the model.
item | The item. |
Implements AbstractTableModel< RecentFile, QDataStream, QDataStream >.
|
inherited |
|
protectedvirtualinherited |
Inserts an item at the given row, or at the end if the row is negative.
Implements AbstractTableModel< RecentFile, QDataStream, QDataStream >.
|
inherited |
Inserts an item into the model at the given row position.
item | The item. The model takes ownership of the object. |
row | The row at which to insert the item. If negative, inserts the item after the last row. |
|
protectedvirtualinherited |
Tests if a given item can be dragged.
|
protectedvirtualinherited |
Tests if a given item can be dropped onto.
|
inlineinherited |
Tests the editability of the model.
|
inherited |
Tests if the model is empty.
|
protectedvirtualinherited |
Tests if a field of a given item is checkable.
item | The item. |
field | The field number. |
true
if the field is checkable for this item, false
otherwise.
|
protectedvirtualinherited |
Tests if a field of a given item is currently checked.
|
protectedvirtualinherited |
Tests if a field of a given item is editable.
item | The item. |
field | The field number. |
true
if the field is editable for this item, false
otherwise.
|
protectedvirtualinherited |
Tests if new item(s) can be dropped onto a non-existent rows in the model.
|
inherited |
Tests if the model is a sorted model.
|
protectedvirtualinherited |
Called when an item has been added to the model.
The default implementation is a no-op.
|
virtualinherited |
Returns the number of items in the model.
Implements AbstractTableModel< RecentFile, QDataStream, QDataStream >.
|
protectedvirtual |
Returns the model's native MIME-type.
Reimplemented from AbstractTableModel< RecentFile, QDataStream, QDataStream >.
|
protectedvirtualinherited |
Called when an item is about to be removed from the model.
The default implementation is a no-op.
|
protectedvirtualinherited |
Called when an item has been updated in the model.
The default implementation is a no-op.
|
slot |
Loads the model from the settings.
|
virtualinherited |
Specified by QAbstractItemModel.
|
virtualinherited |
Specified by QAbstractItemModel.
|
inherited |
Moves the given row down one position in the model.
row | The row to move. If the row is the last row, the call will be a no-op. |
|
inherited |
Moves the given row up one position in the model.
row | The row to move. If the row is the first row, the call will be a no-op. |
|
protectedvirtualinherited |
Returns a list of additional MIME-types that can be dropped onto the model.
The default implementation returns an empty list.
|
virtualinherited |
Specified by QAbstractItemModel.
|
inherited |
|
virtualinherited |
|
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.
stream | The stream from which items are being deserialized. |
|
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.
stream | The stream from which items are being deserialized. |
Reimplemented from AbstractTableModel< RecentFile, QDataStream, QDataStream >.
|
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.
stream | The stream from which items are being deserialized. |
|
protectedvirtualinherited |
Removes all items from the model.
All rows are removed.
Implements AbstractTableModel< RecentFile, QDataStream, QDataStream >.
|
inherited |
Removes and deletes the specified item from the model.
item | The item to remove. If this item is not actually in the model, the call will be a no-op. |
|
inherited |
Removes and deletes the item at the specified row.
row | The row. |
|
virtualinherited |
Specified by QAbstractItemModel.
|
virtualinherited |
Specified by QAbstractItemModel.
|
slot |
Saves the model to the settings.
|
virtualinherited |
Specified by QAbstractItemModel.
|
inlineinherited |
Sets the editability of the model.
|
protectedvirtualinherited |
Sets the checked state of a checkable field.
|
protectedvirtualinherited |
Sets the value of an edited field.
|
inline |
Specifies whether the items will be visually represented by the full paths of the files.
By default, only the filenames are shown.
|
inline |
Tests whether the model shows full paths.
|
protectedvirtualinherited |
Removes and returns the item at the given row.
Implements AbstractTableModel< RecentFile, QDataStream, QDataStream >.
|
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.
row | The row. |
NULL
if there is no item in that row.
|
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.
item | The item that changed. If this item is not actually in the model, the call will be a no-op. |
|
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.
row | The row of the item that changed. |
|
virtualinherited |
|
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.
stream | The stream to which items are being serialized. |
|
protectedvirtual |
|
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.
item | The item to serialize. |
stream | The stream to which items are being serialized. |
|
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.
stream | The stream to which items are being serialized. |
|
staticinherited |
An item's description role.
|
staticinherited |
An item's sort role.