libfuoten 0.8.2
Qt based library to access the Nextcloud News App API.
Loading...
Searching...
No Matches
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.
bool inOperation
 Returns true while the model is loading data.
int limit
 Limits the result to the specified number of objects.
bool loaded
 This property holds true if the model has initially loaded the data.
qint64 parentId
 Sets the parent database ID to load feeds/items for.
Fuoten::FuotenEnums::SortingRole sortingRole
 The role/value used to sort the result.
Qt::SortOrder sortOrder
 The sorting order.
Fuoten::AbstractStoragestorage
 Pointer to a class derived from AbstractStorage.
bool unreadOnly
 If true, only unread articles, feeds or folders are returned.

Public Member Functions

 BaseModel (QObject *parent=nullptr)
 Constructs a new BaseModel object.
 ~BaseModel () override
 Deconstructs the BaseModel object.
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.
virtual QModelIndex findByID (qint64 id) const
 Returns the model index of the item identified by database ID.
virtual QHash< qint64, QModelIndexfindByIDs (const IdList &ids) const
 Returns a hash-table containing IDs and their model index fount in the model.
bool inOperation () const
 Returns true while the model is loading data.
int limit () const
 Getter function for the limit property.
bool loaded () const
 Getter function for the loaded property. *.
qint64 parentId () const
 Returns the currently set parent ID.
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.
void setLimit (int nLimit)
 Setter function for the limit property. Emits the limitChanged() signal if nLimit is not equal to the stored value.
void setParentId (qint64 nParentId)
 Set the parent ID.
void setSortingRole (FuotenEnums::SortingRole nSortingRole)
 Setter function for the sortingRole property. Emits the sortingRoleChanged() signal if nSortingRole is not equal to the stored value.
void setSortOrder (Qt::SortOrder nSortOrder)
 Setter function for the sortOrder property. Emits the sortOrderChanged() signal if nSortOrder is not equal to the stored value.
void setStorage (AbstractStorage *nStorage)
 Sets the pointer to the local storage handler.
void setUnreadOnly (bool nUnreadOnly)
 Setter function for the unreadOnly property. Emits the unreadOnlyChanged() signal if nUnreadOnly is not equal to the stored value.
FuotenEnums::SortingRole sortingRole () const
 Getter function for the sortingRole property.
Qt::SortOrder sortOrder () const
 Getter function for the sortOrder property.
AbstractStoragestorage () const
 Returns the pointer to the currently set local storage.
bool unreadOnly () const
 Getter function for the unreadOnly property.

Public Slots

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

Signals

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

Protected Member Functions

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

Detailed Description

Abstract base class for all data models.

Property Documentation

◆ doubleParentId

double Fuoten::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 Fuoten::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 Fuoten::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 Fuoten::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 Fuoten::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

Fuoten::FuotenEnums::SortingRole Fuoten::BaseModel::sortingRole
readwrite

◆ sortOrder

Qt::SortOrder Fuoten::BaseModel::sortOrder
readwrite

◆ storage

Fuoten::AbstractStorage * Fuoten::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 Fuoten::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 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
{
}
void folderMarkedRead(qint64 id, qint64 newestItem)
Takes and processes data after a folder has been marked as read.
Definition abstractfoldermodel.cpp:286
void folderCreated(qint64 id, const QString &name)
Takes and processes data after a folder has been created.
Definition abstractfoldermodel.cpp:188
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:203
void load() override
Populates the mode with data from the local storage.
Definition abstractfoldermodel.cpp:105
void folderDeleted(qint64 id)
Takes and processes data after a folder has been delted.
Definition abstractfoldermodel.cpp:263
void folderRenamed(qint64 id, const QString &newName)
Takes and processes data after a folder has been renamed.
Definition abstractfoldermodel.cpp:171
void handleStorageChanged(AbstractStorage *old) override
Connetcs the folder related signals of AbstractStorage to the model's slots.
Definition abstractfoldermodel.cpp:72
Abstract class to handle the storage of requested News App data.
Definition abstractstorage.h:59
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.
Definition moc_abstractstorage.cpp:710
void createdFolder(qint64 id, const QString &name)
Emit this after a new folder has been created.
Definition moc_abstractstorage.cpp:717
void deletedFolder(qint64 id)
Emit this after a folder has been deleted.
Definition moc_abstractstorage.cpp:731
void renamedFolder(qint64 id, const QString &newName)
Emit this after a folder has been renamed.
Definition moc_abstractstorage.cpp:724
void markedReadFolder(qint64 id, qint64 newestItem)
Emit this after a folder has been marked as read.
Definition moc_abstractstorage.cpp:738
void readyChanged(bool ready)
Emitted whenever the ready property changes.
Definition moc_abstractstorage.cpp:752
Fuoten::AbstractStorage * storage
Pointer to a class derived from AbstractStorage.
Definition basemodel.h:47
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)

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

◆ inOperation()

bool 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 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);
}
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 setInOperation(bool nInOperation)
Sets the inOperation property.
Definition basemodel.cpp:42
void setLoaded(bool loaded)
Set this to true if the model has initially loaded its data.
Definition basemodel.cpp:96
bool loaded
This property holds true if the model has initially loaded the data.
Definition basemodel.h:124
@ Name
Definition fuoten.h:44
void beginInsertRows(const QModelIndex &parent, int first, int last)
int count(const T &value) const const
bool isEmpty() const const
AscendingOrder

◆ loaded()

bool 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 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 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 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 * 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 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:
  • Fuoten/Models/basemodel.h
  • build/Fuoten/FuotenQt5_autogen/include/moc_basemodel.cpp
  • Fuoten/Models/basemodel.cpp