libfuoten 0.8.1
Qt based library to access the ownCloud/Nextcloud News App API
Loading...
Searching...
No Matches
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::AbstractStoragestorage
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

◆ sortOrder

Qt::SortOrder sortOrder
readwrite

The sorting order.

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

◆ storage

Fuoten::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
{
}
void folderDeleted(qint64 id)
Takes and processes data after a folder has been delted.
Definition abstractfoldermodel.cpp:277
void folderRenamed(qint64 id, const QString &newName)
Takes and processes data after a folder has been renamed.
Definition abstractfoldermodel.cpp:185
void load() override
Populates the mode with data from the local storage.
Definition abstractfoldermodel.cpp:119
void folderCreated(qint64 id, const QString &name)
Takes and processes data after a folder has been created.
Definition abstractfoldermodel.cpp:202
void folderMarkedRead(qint64 id, qint64 newestItem)
Takes and processes data after a folder has been marked as read.
Definition abstractfoldermodel.cpp:300
void handleStorageChanged(AbstractStorage *old) override
Connetcs the folder related signals of AbstractStorage to the model's slots.
Definition abstractfoldermodel.cpp:86
void foldersRequested(const QList< QPair< qint64, QString > > &updatedFolders, const QList< QPair< qint64, QString > > &newFolders, const Fuoten::IdList &deletedFolders)
Takes and processes data after folders have been requested.
Definition abstractfoldermodel.cpp:217
Abstract class to handle the storage of requested News App data.
Definition abstractstorage.h:72
void createdFolder(qint64 id, const QString &name)
Emit this after a new folder has been created.
void markedReadFolder(qint64 id, qint64 newestItem)
Emit this after a folder has been marked as read.
void requestedFolders(const QList< QPair< qint64, QString > > &updatedFolders, const QList< QPair< qint64, QString > > &newFolders, const Fuoten::IdList &deletedFolders)
Emit this after folders have been received and processed.
void deletedFolder(qint64 id)
Emit this after a folder has been deleted.
void readyChanged(bool ready)
Emitted whenever the ready property changes.
void renamedFolder(qint64 id, const QString &newName)
Emit this after a folder has been renamed.
Fuoten::AbstractStorage * storage
Pointer to a class derived from AbstractStorage.
Definition basemodel.h:60

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);
}
virtual QList< Folder * > getFolders(FuotenEnums::SortingRole sortingRole=FuotenEnums::Name, Qt::SortOrder sortOrder=Qt::AscendingOrder, const IdList &ids=IdList(), FuotenEnums::Type idType=FuotenEnums::Folder, int limit=0)=0
Returns a list of Folder objects from the local storage.
void setLoaded(bool loaded)
Set this to true if the model has initially loaded its data.
Definition basemodel.cpp:109
bool loaded
This property holds true if the model has initially loaded the data.
Definition basemodel.h:137
void setInOperation(bool nInOperation)
Sets the inOperation property.
Definition basemodel.cpp:55
@ Name
Definition fuoten.h:57

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