libfuoten  0.8.2
Qt based library to access the Nextcloud News App API.
Properties | Public Member Functions | Public Slots | Signals | Protected Member Functions | List of all members
Fuoten::BaseModel Class Referenceabstract

Abstract base class for all data models. More...

#include <Fuoten/Models/BaseModel>

Inheritance diagram for Fuoten::BaseModel:
QAbstractItemModel QObject Fuoten::AbstractArticleModel Fuoten::AbstractFeedModel Fuoten::AbstractFolderModel Fuoten::ArticleListModel Fuoten::FeedListModel Fuoten::FolderListModel

Properties

double doubleParentId
 Stores the parent ID as double to make it accesseable from QML. More...
 
bool inOperation
 Returns true while the model is loading data. More...
 
int limit
 Limits the result to the specified number of objects. More...
 
bool loaded
 This property holds true if the model has initially loaded the data. More...
 
qint64 parentId
 Sets the parent database ID to load feeds/items for. More...
 
Fuoten::FuotenEnums::SortingRole sortingRole
 The role/value used to sort the result. More...
 
Qt::SortOrder sortOrder
 The sorting order. More...
 
Fuoten::AbstractStorage storage
 Pointer to a class derived from AbstractStorage. More...
 
bool unreadOnly
 If true, only unread articles, feeds or folders are returned. More...
 

Public Member Functions

 BaseModel (QObject *parent=nullptr)
 Constructs a new BaseModel object. More...
 
 ~BaseModel () override
 Deconstructs the BaseModel object. More...
 
double doubleParentId () const
 Returns the currently set parent ID as double. This function is for use in QML, that does not support 64bit integers. It performs a static cast from the saved qint64 parent ID to double. More...
 
virtual QModelIndex findByID (qint64 id) const
 Returns the model index of the item identified by database ID. More...
 
virtual QHash< qint64, QModelIndexfindByIDs (const IdList &ids) const
 Returns a hash-table containing IDs and their model index fount in the model. More...
 
bool inOperation () const
 Returns true while the model is loading data. More...
 
int limit () const
 Getter function for the limit property. More...
 
bool loaded () const
 Getter function for the loaded property. *. More...
 
qint64 parentId () const
 Returns the currently set parent ID. More...
 
void setDoubleParentId (double nDoubleParentId)
 Sets the parent ID via a double. This function is for use in QML, that does not support 64bit integers. It performs a static cast from the double to a qint64 to save it. More...
 
void setLimit (int nLimit)
 Setter function for the limit property. Emits the limitChanged() signal if nLimit is not equal to the stored value. More...
 
void setParentId (qint64 nParentId)
 Set the parent ID. More...
 
void setSortingRole (FuotenEnums::SortingRole nSortingRole)
 Setter function for the sortingRole property. Emits the sortingRoleChanged() signal if nSortingRole is not equal to the stored value. More...
 
void setSortOrder (Qt::SortOrder nSortOrder)
 Setter function for the sortOrder property. Emits the sortOrderChanged() signal if nSortOrder is not equal to the stored value. More...
 
void setStorage (AbstractStorage *nStorage)
 Sets the pointer to the local storage handler. More...
 
void setUnreadOnly (bool nUnreadOnly)
 Setter function for the unreadOnly property. Emits the unreadOnlyChanged() signal if nUnreadOnly is not equal to the stored value. More...
 
FuotenEnums::SortingRole sortingRole () const
 Getter function for the sortingRole property. More...
 
Qt::SortOrder sortOrder () const
 Getter function for the sortOrder property. More...
 
AbstractStoragestorage () const
 Returns the pointer to the currently set local storage. More...
 
bool unreadOnly () const
 Getter function for the unreadOnly property. More...
 

Public Slots

virtual void load ()=0
 Loads the model data. More...
 
virtual void reload ()
 Reloads the complete model. More...
 

Signals

void doubleParentIdChanged (double doubleParentId)
 This signal is emitted if the parent ID changes. More...
 
void inOperationChanged (bool inOperation)
 This signal is emitted if the operational state of the model changes. More...
 
void limitChanged (int limit)
 This is emitted if the value of the limit property changes. More...
 
void loadedChanged (bool loaded)
 This is emitted if the value of the loaded property changes. More...
 
void parentIdChanged (qint64 parentId)
 This signal is emitted if the parent ID changes. More...
 
void sortingRoleChanged (FuotenEnums::SortingRole sortingRole)
 This is emitted if the value of the sortingRole property changes. More...
 
void sortOrderChanged (Qt::SortOrder sortOrder)
 This is emitted if the value of the sortOrder property changes. More...
 
void storageChanged (Fuoten::AbstractStorage *storage)
 This signal is emitted if the poiner to the local storage changes. More...
 
void unreadOnlyChanged (bool unreadOnly)
 This is emitted if the value of the unreadOnly property changes. More...
 

Protected Member Functions

virtual void clear ()=0
 Clears the model and removes all model data. More...
 
virtual void handleStorageChanged (AbstractStorage *old)
 Will be called by setStorage() whenever the storage changes. More...
 
void setInOperation (bool nInOperation)
 Sets the inOperation property. More...
 
void setLoaded (bool loaded)
 Set this to true if the model has initially loaded its data. More...
 

Detailed Description

Abstract base class for all data models.

Property Documentation

◆ doubleParentId

double BaseModel::doubleParentId
readwrite

Stores the parent ID as double to make it accesseable from QML.

This uses the same data as parentId, but converts it between double and qint64. This is a convenience property for use in QML that does not support 64bit integers. As JavaScript and JSON are storing number values according to IEEE 754, there might happen an overflow, if setting values greater than the limit of qint64. Under normal circumstances we simply assume, that there will hardly be greater database IDs than what fits in qint64.

Access functions:
doubledoubleParentId() const
voidsetDoubleParentId(double nDoubleParentId)
Notifier signal:
voiddoubleParentIdChanged(double doubleParentId)

◆ inOperation

bool BaseModel::inOperation
readwrite

Returns true while the model is loading data.

Access functions:
boolinOperation() const
Notifier signal:
voidinOperationChanged(bool inOperation)
See also
setInOperation()

◆ limit

int BaseModel::limit
readwrite

Limits the result to the specified number of objects.

Access functions:
intlimit() const
voidsetLimit(int nLimit)
Notifier signal:
voidlimitChanged(int limit)

◆ loaded

bool BaseModel::loaded
read

This property holds true if the model has initially loaded the data.

While it is true, load() will return immediately without loading data. Use reload() instead. When creating a derived class, you should use setLoaded() after your model has initially loaded the data.

Access functions:
void setLoaded(bool loaded) bool loaded() const
Notifier signal:
void loadedChanged(bool loaded)

◆ parentId

qint64 BaseModel::parentId
readwrite

Sets the parent database ID to load feeds/items for.

If used on a model presenting feeds, this defines the folder, the feed belongs to. If used on a model presenting items, this defines the feed the items belong to.

Access functions:
qint64parentId() const
voidsetParentId(qint64 nParentId)
Notifier signal:
voidparentIdChanged(qint64 parentId)

◆ sortingRole

FuotenEnums::SortingRole BaseModel::sortingRole
readwrite

◆ sortOrder

Qt::SortOrder BaseModel::sortOrder
readwrite

◆ storage

AbstractStorage * BaseModel::storage
readwrite

Pointer to a class derived from AbstractStorage.

Access functions:
AbstractStorage*storage() const
voidsetStorage(AbstractStorage *nStorage)
Notifier signal:
voidstorageChanged(AbstractStorage *storage)

◆ unreadOnly

bool BaseModel::unreadOnly
readwrite

If true, only unread articles, feeds or folders are returned.

Access functions:
boolunreadOnly() const
voidsetUnreadOnly(bool nUnreadOnly)
Notifier signal:
voidunreadOnlyChanged(bool unreadOnly)

Constructor & Destructor Documentation

◆ BaseModel()

BaseModel::BaseModel ( QObject parent = nullptr)
explicit

Constructs a new BaseModel object.

◆ ~BaseModel()

BaseModel::~BaseModel ( )
override

Deconstructs the BaseModel object.

Member Function Documentation

◆ clear()

virtual void Fuoten::BaseModel::clear ( )
protectedpure virtual

Clears the model and removes all model data.

Implemented in Fuoten::AbstractArticleModel, Fuoten::AbstractFeedModel, and Fuoten::AbstractFolderModel.

◆ doubleParentId()

double Fuoten::BaseModel::doubleParentId ( ) const

Returns the currently set parent ID as double. This function is for use in QML, that does not support 64bit integers. It performs a static cast from the saved qint64 parent ID to double.

See also
doubleParentId

◆ doubleParentIdChanged

void Fuoten::BaseModel::doubleParentIdChanged ( double  doubleParentId)
signal

This signal is emitted if the parent ID changes.

See also
doubleParentId

◆ findByID()

QModelIndex BaseModel::findByID ( qint64  id) const
virtual

Returns the model index of the item identified by database ID.

The default implementation returns an invalid QModelIndex. Reimplement this function in a subclass.

Reimplemented in Fuoten::AbstractArticleModel, Fuoten::AbstractFeedModel, and Fuoten::AbstractFolderModel.

◆ findByIDs()

QHash< qint64, QModelIndex > BaseModel::findByIDs ( const IdList ids) const
virtual

Returns a hash-table containing IDs and their model index fount in the model.

The default implementation return an empty QHash<qint64, QModelIndex>. Reimplement this function in a subclass.

Reimplemented in Fuoten::AbstractArticleModel, and Fuoten::AbstractFeedModel.

◆ handleStorageChanged()

void BaseModel::handleStorageChanged ( AbstractStorage old)
protectedvirtual

Will be called by setStorage() whenever the storage changes.

The default implementation does nothing. You should use this to connect signals from the AbstractStorage to slots in the model implementation that updates the model data after the local data has been changed.

Example implementation

Reimplemented in Fuoten::AbstractArticleModel, Fuoten::AbstractFeedModel, and Fuoten::AbstractFolderModel.

◆ inOperation()

bool Fuoten::BaseModel::inOperation ( ) const

Returns true while the model is loading data.

See also
inOperation

◆ inOperationChanged

void Fuoten::BaseModel::inOperationChanged ( bool  inOperation)
signal

This signal is emitted if the operational state of the model changes.

See also
inOperatoin

◆ limit()

int Fuoten::BaseModel::limit ( ) const

Getter function for the limit property.

See also
BaseModel::setLimit(), BaseModel::limitChanged()

◆ limitChanged

void Fuoten::BaseModel::limitChanged ( int  limit)
signal

This is emitted if the value of the limit property changes.

See also
BaseModel::limit(), BaseModel::setLimit()

◆ load

virtual void Fuoten::BaseModel::load ( )
pure virtualslot

Loads the model data.

Reimplement this in a subclass. Do only load the data, if loaded() returns false and set setLoaded() to true after the data has been loaded. All later changes, after the model has loaded the initial data, should be done by signals and slots without reloading the full model.

Additionally you could use the inOperation property in this function to indicate, that the model is loading its data.

Example implementation
{
if (!storage()) {
return;
}
if (!storage()->ready() || loaded()) {
return;
}
Q_D(AbstractFolderModel);
if (!fs.isEmpty()) {
d->folders = fs;
}
setLoaded(true);
}

◆ loaded()

bool Fuoten::BaseModel::loaded ( ) const

Getter function for the loaded property. *.

See also
setLoaded(), loadedChanged()

◆ loadedChanged

void Fuoten::BaseModel::loadedChanged ( bool  loaded)
signal

This is emitted if the value of the loaded property changes.

See also
loaded(), setLoaded()

◆ parentId()

qint64 Fuoten::BaseModel::parentId ( ) const

Returns the currently set parent ID.

See also
parentId

◆ parentIdChanged

void Fuoten::BaseModel::parentIdChanged ( qint64  parentId)
signal

This signal is emitted if the parent ID changes.

See also
parentId

◆ reload

void BaseModel::reload ( )
virtualslot

Reloads the complete model.

Will call clear(), will than set loaded to false and will then call load().

◆ setDoubleParentId()

void BaseModel::setDoubleParentId ( double  nDoubleParentId)

Sets the parent ID via a double. This function is for use in QML, that does not support 64bit integers. It performs a static cast from the double to a qint64 to save it.

See also
doubleParentId

◆ setInOperation()

void BaseModel::setInOperation ( bool  nInOperation)
protected

Sets the inOperation property.

See also
inOperation

◆ setLimit()

void BaseModel::setLimit ( int  nLimit)

Setter function for the limit property. Emits the limitChanged() signal if nLimit is not equal to the stored value.

See also
BaseModel::limit(), BaseModel::limitChanged()

◆ setLoaded()

void BaseModel::setLoaded ( bool  loaded)
protected

Set this to true if the model has initially loaded its data.

In the reimplementation of a BaseModel this should be set in the implementation of the load() function, after the initial data has been loaded.

See also
BaseModel::loaded

◆ setParentId()

void BaseModel::setParentId ( qint64  nParentId)

Set the parent ID.

See also
parentId

◆ setSortingRole()

void BaseModel::setSortingRole ( FuotenEnums::SortingRole  nSortingRole)

Setter function for the sortingRole property. Emits the sortingRoleChanged() signal if nSortingRole is not equal to the stored value.

See also
BaseModel::sortingRole(), BaseModel::sortingRoleChanged()

◆ setSortOrder()

void BaseModel::setSortOrder ( Qt::SortOrder  nSortOrder)

Setter function for the sortOrder property. Emits the sortOrderChanged() signal if nSortOrder is not equal to the stored value.

See also
BaseModel::sortOrder(), BaseModel::sortOrderChanged()

◆ setStorage()

void BaseModel::setStorage ( AbstractStorage nStorage)

Sets the pointer to the local storage handler.

See also
storage

◆ setUnreadOnly()

void BaseModel::setUnreadOnly ( bool  nUnreadOnly)

Setter function for the unreadOnly property. Emits the unreadOnlyChanged() signal if nUnreadOnly is not equal to the stored value.

See also
BaseModel::unreadOnly(), BaseModel::unreadOnlyChanged()

◆ sortingRole()

FuotenEnums::SortingRole Fuoten::BaseModel::sortingRole ( ) const

◆ sortingRoleChanged

void Fuoten::BaseModel::sortingRoleChanged ( FuotenEnums::SortingRole  sortingRole)
signal

This is emitted if the value of the sortingRole property changes.

See also
BaseModel::sortingRole(), BaseModel::setSortingRole()

◆ sortOrder()

Qt::SortOrder Fuoten::BaseModel::sortOrder ( ) const

Getter function for the sortOrder property.

See also
BaseModel::setSortOrder(), BaseModel::sortOrderChanged()

◆ sortOrderChanged

void Fuoten::BaseModel::sortOrderChanged ( Qt::SortOrder  sortOrder)
signal

This is emitted if the value of the sortOrder property changes.

See also
BaseModel::sortOrder(), BaseModel::setSortOrder()

◆ storage()

AbstractStorage* Fuoten::BaseModel::storage ( ) const

Returns the pointer to the currently set local storage.

See also
storage

◆ storageChanged

void Fuoten::BaseModel::storageChanged ( Fuoten::AbstractStorage storage)
signal

This signal is emitted if the poiner to the local storage changes.

See also
storage

◆ unreadOnly()

bool Fuoten::BaseModel::unreadOnly ( ) const

Getter function for the unreadOnly property.

See also
BaseModel::setUnreadOnly(), BaseModel::unreadOnlyChanged()

◆ unreadOnlyChanged

void Fuoten::BaseModel::unreadOnlyChanged ( bool  unreadOnly)
signal

This is emitted if the value of the unreadOnly property changes.

See also
BaseModel::unreadOnly(), BaseModel::setUnreadOnly()

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