libfuoten  0.8.1
Qt based library to access the ownCloud/Nextcloud News App API
Properties | Public Member Functions | Public Slots | Signals | Protected Member Functions | List of all members
BaseModel Class Referenceabstract

#include <Fuoten/Models/BaseModel>

Inheritance diagram for BaseModel:
AbstractArticleModel AbstractFeedModel AbstractFolderModel ArticleListModel FeedListModel FolderListModel

Properties

double doubleParentId
 
bool inOperation
 
int limit
 
bool loaded
 
qint64 parentId
 
Fuoten::FuotenEnums::SortingRole sortingRole
 
Qt::SortOrder sortOrder
 
Fuoten::AbstractStorage storage
 
bool unreadOnly
 

Public Member Functions

 BaseModel (QObject *parent=nullptr)
 
 ~BaseModel () override
 
double doubleParentId () const
 
virtual QModelIndex findByID (qint64 id) const
 
virtual QHash< qint64, QModelIndex > findByIDs (const IdList &ids) const
 
bool inOperation () const
 
int limit () const
 
bool loaded () const
 
qint64 parentId () const
 
void setDoubleParentId (double nDoubleParentId)
 
void setLimit (int nLimit)
 
void setParentId (qint64 nParentId)
 
void setSortingRole (FuotenEnums::SortingRole nSortingRole)
 
void setSortOrder (Qt::SortOrder nSortOrder)
 
void setStorage (AbstractStorage *nStorage)
 
void setUnreadOnly (bool nUnreadOnly)
 
FuotenEnums::SortingRole sortingRole () const
 
Qt::SortOrder sortOrder () const
 
AbstractStoragestorage () const
 
bool unreadOnly () const
 

Public Slots

virtual void load ()=0
 
virtual void reload ()
 

Signals

void doubleParentIdChanged (double doubleParentId)
 
void inOperationChanged (bool inOperation)
 
void limitChanged (int limit)
 
void loadedChanged (bool loaded)
 
void parentIdChanged (qint64 parentId)
 
void sortingRoleChanged (FuotenEnums::SortingRole sortingRole)
 
void sortOrderChanged (Qt::SortOrder sortOrder)
 
void storageChanged (Fuoten::AbstractStorage *storage)
 
void unreadOnlyChanged (bool unreadOnly)
 

Protected Member Functions

virtual void clear ()=0
 
virtual void handleStorageChanged (AbstractStorage *old)
 
void setInOperation (bool nInOperation)
 
void setLoaded (bool loaded)
 

Detailed Description

Abstract base class for all data models.

Property Documentation

◆ doubleParentId

double 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 inOperation
readwrite

Returns true while the model is loading data.

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

◆ limit

int 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 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 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 sortingRole
readwrite

◆ sortOrder

Qt::SortOrder sortOrder
readwrite

The sorting order.

Access functions:
Qt::SortOrdersortOrder() const
voidsetSortOrder(Qt::SortOrder nSortOrder)
Notifier signal:
voidsortOrderChanged(Qt::SortOrder sortOrder)

◆ storage

AbstractStorage * storage
readwrite

Pointer to a class derived from AbstractStorage.

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

◆ unreadOnly

bool 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 ( QObject *  parent = nullptr)
explicit

Constructs a new BaseModel object.

◆ ~BaseModel()

~BaseModel ( )
override

Deconstructs the BaseModel object.

Member Function Documentation

◆ clear()

virtual void clear ( )
protectedpure virtual

Clears the model and removes all model data.

Implemented in AbstractArticleModel, AbstractFeedModel, and AbstractFolderModel.

◆ doubleParentId()

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.

See also
doubleParentId

◆ doubleParentIdChanged

void doubleParentIdChanged ( double  doubleParentId)
signal

This signal is emitted if the parent ID changes.

See also
doubleParentId

◆ findByID()

QModelIndex 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 AbstractArticleModel, AbstractFeedModel, and AbstractFolderModel.

◆ findByIDs()

QHash< qint64, QModelIndex > 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 AbstractArticleModel, and AbstractFeedModel.

◆ handleStorageChanged()

void 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 AbstractArticleModel, AbstractFeedModel, and AbstractFolderModel.

◆ inOperation()

bool inOperation ( ) const

Returns true while the model is loading data.

See also
inOperation

◆ inOperationChanged

void inOperationChanged ( bool  inOperation)
signal

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

See also
inOperatoin

◆ limit()

int limit ( ) const

Getter function for the limit property.

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

◆ limitChanged

void limitChanged ( int  limit)
signal

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

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

◆ load

virtual void 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);
const QList<Folder*> fs = storage()->getFolders(FuotenEnums::Name, Qt::AscendingOrder);
if (!fs.isEmpty()) {
beginInsertRows(QModelIndex(), 0, fs.count() - 1);
d->folders = fs;
endInsertRows();
}
setLoaded(true);
}

◆ loaded()

bool loaded ( ) const

Getter function for the loaded property. *.

See also
setLoaded(), loadedChanged()

◆ loadedChanged

void loadedChanged ( bool  loaded)
signal

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

See also
loaded(), setLoaded()

◆ parentId()

qint64 parentId ( ) const

Returns the currently set parent ID.

See also
parentId

◆ parentIdChanged

void parentIdChanged ( qint64  parentId)
signal

This signal is emitted if the parent ID changes.

See also
parentId

◆ reload

void reload ( )
virtualslot

Reloads the complete model.

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

◆ setDoubleParentId()

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.

See also
doubleParentId

◆ setInOperation()

void setInOperation ( bool  nInOperation)
protected

Sets the inOperation property.

See also
inOperation

◆ setLimit()

void 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 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 setParentId ( qint64  nParentId)

Set the parent ID.

See also
parentId

◆ setSortingRole()

void 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 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 setStorage ( AbstractStorage nStorage)

Sets the pointer to the local storage handler.

See also
storage

◆ setUnreadOnly()

void 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 sortingRole ( ) const

◆ sortingRoleChanged

void 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 sortOrder ( ) const

Getter function for the sortOrder property.

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

◆ sortOrderChanged

void sortOrderChanged ( Qt::SortOrder  sortOrder)
signal

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

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

◆ storage()

AbstractStorage* storage ( ) const

Returns the pointer to the currently set local storage.

See also
storage

◆ storageChanged

void storageChanged ( Fuoten::AbstractStorage storage)
signal

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

See also
storage

◆ unreadOnly()

bool unreadOnly ( ) const

Getter function for the unreadOnly property.

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

◆ unreadOnlyChanged

void unreadOnlyChanged ( bool  unreadOnly)
signal

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

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