MauiList

Search for usage in LXR

#include <mauilist.h>

Inheritance diagram for MauiList:

Properties

QML_ANONYMOUSint count
 
- Properties inherited from QObject
 objectName
 

Signals

void countChanged ()
 
void itemMoved (int index, int to)
 
void postItemAppended ()
 
void postItemRemoved ()
 
void postListChanged ()
 
void preItemAppended ()
 
void preItemAppendedAt (int index)
 
void preItemRemoved (int index)
 
void preItemsAppended (uint count)
 
void preListChanged ()
 
void updateModel (int index, QVector< int > roles)
 

Public Slots

QVariantMap get (const int &index) const
 

Public Member Functions

 MauiList (QObject *parent=nullptr)
 
virtual void classBegin () override
 
virtual void componentComplete () override
 
int getCount () const
 
FMH::MODEL getItem (const int &index) const
 
virtual const FMH::MODEL_LISTitems () const =0
 
virtual void modelHooked ()
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
QBindable< QStringbindableObjectName ()
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo () const const
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isQuickItemType () const const
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_GADGET_EXPORT (EXPORT_MACRO)
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_MOC_INCLUDE Q_MOC_INCLUDE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setObjectName (QAnyStringView name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool setProperty (const char *name, QVariant &&value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds interval, Qt::TimerType timerType)
 
QThreadthread () const const
 

Protected Member Functions

bool exists (const FMH::MODEL_KEY &key, const QString &value) const
 
int indexOf (const FMH::MODEL_KEY &key, const QString &value) const
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

MauiList class.

A helper class for easily setting up a list model to be feed into MauiModel::list, and to be used by the browsing views in Mauikit controls.

Warning
This method of setting up a data model is very limited by the lingo supported by the FMH::MODEL_KEY dictionary. So only consider using this class if your data model structure is based on only string text and can be represented by the FMH::MODEL_KEY dictionary entries.
See also
FMH::MODEL_KEY

This inherits from the QQmlParserStatus class, so t can be aware of its creation status in the QML engine. This is useful to lazy-loading parts when needed, as when the component presenting the data model is ready and loaded.

The list generated by sub-classing MauiList is meant to be used as the list for the MauiModel class, exposed to QML as the BaseModel type. The MauiModel supports features, such as filtering and sorting.

See also
MauiModel

Minimal Example

This is a simple example of a MauiList based data model.

First wee need to setup the MauiList data. In the example below the data is manually added. The data must be modeled using the FMH::MODEL_LIST, which is an array list of FMH::MODEL, which is a map of key pairs, where the key must be a FMH::MODEL_KEY enum type, and the value a string text.

#pragma once
#include <QObject>
#include <MauiKit4/Core/mauilist.h>
class PlantsList : public MauiList
{
Q_OBJECT
public:
PlantsList(QObject *parent = nullptr);
// QQmlParserStatus interface
void componentComplete();
// MauiList interface
const FMH::MODEL_LIST &items() const;
private:
//Here we have our own custom raw data and turn it into a FMH::MODEL_LIST
FMH::MODEL_LIST getData() const;
};
MauiList class.
Definition mauilist.h:180

In this example the data is only retrieved once the QML engine has completely loaded the component using the MauiList, for this we override the componentComplete() virtual method, and there we inform the MauiModel with the signals that the list data is ready.

#include "plantslist.h"
PlantsList::PlantsList(QObject *parent) : MauiList(parent)
{
}
void PlantsList::componentComplete()
{
Q_EMIT preListChanged();
m_list = getData();
Q_EMIT postListChanged();
Q_EMIT countChanged();
}
const FMH::MODEL_LIST &PlantsList::items() const
{
return m_list;
}
FMH::MODEL_LIST PlantsList::getData() const
{
data << FMH::MODEL {{FMH::MODEL_KEY::TITLE, QStringLiteral("Acanthaceae")}, {FMH::MODEL_KEY::CATEGORY, QStringLiteral("Acanthus")}};
data << FMH::MODEL {{FMH::MODEL_KEY::TITLE, QStringLiteral("Agavaceae")}, {FMH::MODEL_KEY::CATEGORY, QStringLiteral("Agave")}};
data << FMH::MODEL {{FMH::MODEL_KEY::TITLE, QStringLiteral("Bixaceae")}, {FMH::MODEL_KEY::CATEGORY, QStringLiteral("Annatto")}};
data << FMH::MODEL {{FMH::MODEL_KEY::TITLE, QStringLiteral("Asteraceae")}, {FMH::MODEL_KEY::CATEGORY, QStringLiteral("Aster")}};
data << FMH::MODEL {{FMH::MODEL_KEY::TITLE, QStringLiteral("Leguminaceae")}, {FMH::MODEL_KEY::CATEGORY, QStringLiteral("Bean")}};
return data;
}
QObject * parent() const const

Now we register our own custom PlanstList class to the QML engine as a type.

#include <MauiKit3/Core/mauiapp.h>
#include "plantslist.h"
int main(int argc, char *argv[])
{
...
qmlRegisterType<PlantsList>("org.maui.demo", 1, 0, "PlantsList"); //Here we register it.
engine.load(url);
return app.exec();
}

And finally, we can consume the data list by hooking it up to the MauiModel exposed type BaseModel.

import org.mauikit.controls as Maui
import org.maui.demo as Demo
Maui.ApplicationWindow
{
id: root
Maui.Page
{
id: _page
anchors.fill: parent
Maui.Controls.showCSD: true
headBar.forceCenterMiddleContent: true
Maui.ListBrowser
{
anchors.fill: parent
model: Maui.BaseModel
{
list: Demo.PlantsList
{
}
}
delegate: Maui.ListBrowserDelegate
{
width: ListView.view.width
label1.text: model.title
label2.text: model.category
}
}
}
}

You can find a more complete example at this link.

Definition at line 179 of file mauilist.h.

Property Documentation

◆ count

QML_ANONYMOUSint MauiList::count
read

The total amount of elements in the list.

Note
This needs to be setup manually, as in emitting the signal when new items are appended or removed, etc.

Definition at line 192 of file mauilist.h.

Constructor & Destructor Documentation

◆ MauiList()

MauiList::MauiList ( QObject * parent = nullptr)
explicit

Default constructor.

The usage of this class is meant to be via inheritance by sub-classing it.

Definition at line 22 of file mauilist.cpp.

Member Function Documentation

◆ classBegin()

virtual void MauiList::classBegin ( )
inlineoverridevirtual

See the Qt documentation on the QQmlParserStatus.

Implements QQmlParserStatus.

Definition at line 211 of file mauilist.h.

◆ componentComplete()

virtual void MauiList::componentComplete ( )
inlineoverridevirtual

See the Qt documentation on the QQmlParserStatus.

Implements QQmlParserStatus.

Definition at line 216 of file mauilist.h.

◆ countChanged

void MauiList::countChanged ( )
signal

This signal should be emitted by the implementation when the number of elements in the list data model varies.

For example when an item is removed or added.

◆ exists()

bool MauiList::exists ( const FMH::MODEL_KEY & key,
const QString & value ) const
protected

Whether an item with a given key-par value exists in the list.

Parameters
keythe FMH::MODEL_KEY to look for
valuethe value associated with the key to look for
Returns
an exact match exists or not

Definition at line 46 of file mauilist.cpp.

◆ get

QVariantMap MauiList::get ( const int & index) const
slot

Request to get an item in the list, the item is represented as a QVariantMap for easy consumption within the QML scope.

This function is exposed to be invoked from QML.

Parameters
indexthe position of the item to retrieve
Returns
The found item/map in the list at the index. If not item is found at the given index, then an empty map is returned.

Definition at line 32 of file mauilist.cpp.

◆ getCount()

int MauiList::getCount ( ) const

Definition at line 27 of file mauilist.cpp.

◆ getItem()

FMH::MODEL MauiList::getItem ( const int & index) const

Request to get an item in the list, the item is represented as a FMH::MODEL key pair value.

Parameters
indexthe position of the item to retrieve
Returns
The found item/map in the list at the index. If not item is found at the given index, then an empty map is returned.

Definition at line 37 of file mauilist.cpp.

◆ indexOf()

int MauiList::indexOf ( const FMH::MODEL_KEY & key,
const QString & value ) const
protected

The index number of an item in the list of a given key-par value.

Parameters
keythe FMH::MODEL_KEY to look for
valuethe value associated with the key to look for
Returns
the found index or -1 if not found

Definition at line 51 of file mauilist.cpp.

◆ itemMoved

void MauiList::itemMoved ( int index,
int to )
signal

This signal should be emitted by the implementation when an item has been moved from one index position to another.

Parameters
indexthe original index position of the item in the list data model
tothe new index destination of the item

◆ items()

virtual const FMH::MODEL_LIST & MauiList::items ( ) const
pure virtual

The modeled data represented by a FMH::MODEL_LIST.

Note
The data must be modeled using the FMH::MODEL_LIST, which is an array list of FMH::MODEL elements, which is a map of key pairs, where the key must be a FMH::MODEL_KEY enum type, and the value a string text.
Returns
The data model.

Implemented in FMList.

◆ modelHooked()

virtual void MauiList::modelHooked ( )
inlinevirtual

This function is called once the MauiList has been hooked to the MauiModel, using the MauiModel::list property.

Definition at line 221 of file mauilist.h.

◆ postItemAppended

void MauiList::postItemAppended ( )
signal

This signal should be emitted by the implementation after one or multiple new items have finished being added into the list data model.

◆ postItemRemoved

void MauiList::postItemRemoved ( )
signal

This signal should be emitted by the implementation after an item has been successfully removed from the list data model.

◆ postListChanged

void MauiList::postListChanged ( )
signal

This signal should be emitted by the implementation after the list data model is set and done.

◆ preItemAppended

void MauiList::preItemAppended ( )
signal

This signal should be emitted by the implementation before appending a new item to the list data model.

◆ preItemAppendedAt

void MauiList::preItemAppendedAt ( int index)
signal

This signal should be emitted by the implementation before a new item has been inserted at a given index to the list data model.

Parameters
indexthe position index where the new item was inserted at

◆ preItemRemoved

void MauiList::preItemRemoved ( int index)
signal

This signal should be emitted by the implementation before an item has been removed at the given index position.

Parameters
indexthe index position of the element that will be removed

◆ preItemsAppended

void MauiList::preItemsAppended ( uint count)
signal

This signal should be emitted by the implementation before appending a multiple new items to the list data model.

Parameters
countthe total amount of new items that will be added

◆ preListChanged

void MauiList::preListChanged ( )
signal

This signal should be emitted by the implementation before the list data model has been assigned or populated.

◆ updateModel

void MauiList::updateModel ( int index,
QVector< int > roles )
signal

This signal should be emitted by the implementation when changes have been done in the list data model.

Parameters
indexthe index position of the item that was modified in the list data model
rolesthe keys that were modified, the key values can be FMH::MODEL_KEY

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.