QIfAbstractFeatureListModel Class

The QIfAbstractFeatureListModel is the base class for QtInterfaceFramework Features which should act as a model. More...

Header: #include <QIfAbstractFeatureListModel>
qmake: QT += interfaceframework
In QML: AbstractFeatureListModel
Inherits: QAbstractListModel and QQmlParserStatus
Inherited By:

QIfPagingModel

Properties

Public Functions

QIfAbstractFeatureListModel(const QString &interfaceName, QObject *parent = nullptr)
bool asynchronousBackendLoading() const
bool backendUpdatesEnabled() const
QString configurationId() const
QIfAbstractFeature::DiscoveryMode discoveryMode() const
QIfAbstractFeature::DiscoveryResult discoveryResult() const
QIfAbstractFeature::Error error() const
QString errorMessage() const
bool isInitialized() const
bool isValid() const
QStringList preferredBackends() const
QIfServiceObject *serviceObject() const

Public Slots

void setAsynchronousBackendLoading(bool asynchronousBackendLoading)
void setBackendUpdatesEnabled(bool newBackendUpdatesEnabled)
void setConfigurationId(const QString &configurationId)
void setDiscoveryMode(QIfAbstractFeature::DiscoveryMode discoveryMode)
void setPreferredBackends(const QStringList &preferredBackends)
bool setServiceObject(QIfServiceObject *so)
QIfAbstractFeature::DiscoveryResult startAutoDiscovery()

Signals

void asynchronousBackendLoadingChanged(bool asynchronousBackendLoading)
void backendUpdatesEnabledChanged(bool backendUpdatesEnabled)
void configurationIdChanged(const QString &configurationId)
void discoveryModeChanged(QIfAbstractFeature::DiscoveryMode discoveryMode)
void discoveryResultChanged(QIfAbstractFeature::DiscoveryResult discoveryResult)
void errorChanged(QIfAbstractFeature::Error error, const QString &message)
void isInitializedChanged(bool isInitialized)
void isValidChanged(bool arg)
void preferredBackendsChanged(const QStringList &preferredBackends)
void serviceObjectChanged()

Protected Functions

virtual bool acceptServiceObject(QIfServiceObject *serviceObject)
virtual void clearServiceObject() = 0
virtual void connectToServiceObject(QIfServiceObject *serviceObject)
virtual void disconnectFromServiceObject(QIfServiceObject *serviceObject)
QString errorText() const
QString interfaceName() const
void setError(QIfAbstractFeature::Error error, const QString &message = QString())

Protected Slots

virtual void onErrorChanged(QIfAbstractFeature::Error error, const QString &message = QString())

Detailed Description

This base class is necessary to avoid virtual inheritance from QAbstractListModel and QIfAbstractFeature.

For more details on how a Feature works, see QIfAbstractFeature. For more information about models in QtInterfaceFramework, see Models.

Subclassing

Your QIfAbstractFeatureListModel subclass must provide implementations for all virtual functions from QIfAbstractFeature as well as the virtual functions from QAbstractListModel.

Property Documentation

[since 6.8] asynchronousBackendLoading : bool

This property holds whether backend loading is asynchronous.

By default, this property is false.

If set to true, the backend loading is asynchronous. This means that the feature will not wait for the backend to complete loading during auto discovery. Instead, the backend loads in the background and the feature will be updated once the backend is ready.

Note: This property defaults to true if the QIfAbstractFeatureListModel is created within an asynchronous QQmlIncubator (e.g. Loader).

This property was introduced in Qt 6.8.

Access functions:

bool asynchronousBackendLoading() const
void setAsynchronousBackendLoading(bool asynchronousBackendLoading)

Notifier signal:

void asynchronousBackendLoadingChanged(bool asynchronousBackendLoading)

[since 6.8] backendUpdatesEnabled : bool

This property holds whether backend updates are enabled

By default, this property is true.

setBackendUpdatesEnabled() is normally used to disable updates for a short period of time, for instance to skip expensive updates while the application is currently not visible on the screen.

This is especially useful when backend upates are triggered over an IPC and received by multiple applications. By disabling updates, the application can avoid unnecessary updates.

A change to this property will cause the connectToServiceObject() and disconnectFromServiceObject() functions to be called, depending on the new value.

This property was introduced in Qt 6.8.

Access functions:

bool backendUpdatesEnabled() const
void setBackendUpdatesEnabled(bool newBackendUpdatesEnabled)

Notifier signal:

void backendUpdatesEnabledChanged(bool backendUpdatesEnabled)

[since 6.5] configurationId : QString

Holds the id to determine which configuration this feature belongs to.

Once the id has been set, it is possible to change certain values using the QIfConfiguration API.

Note: Values set in the matching QIfConfiguration can override the initial values set during the component creation.

This property was introduced in Qt 6.5.

Access functions:

QString configurationId() const
void setConfigurationId(const QString &configurationId)

Notifier signal:

void configurationIdChanged(const QString &configurationId)

See also QIfConfiguration.

discoveryMode : QIfAbstractFeature::DiscoveryMode

Holds the mode that is used for the autoDiscovery

Note: If you change this property after the Feature is instantiated you need to call startAutoDiscovery() to search for a new Service Object

Access functions:

QIfAbstractFeature::DiscoveryMode discoveryMode() const
void setDiscoveryMode(QIfAbstractFeature::DiscoveryMode discoveryMode)

Notifier signal:

void discoveryModeChanged(QIfAbstractFeature::DiscoveryMode discoveryMode)

[read-only] discoveryResult : const QIfAbstractFeature::DiscoveryResult

This property holds the result of the last autoDiscovery attempt

Access functions:

QIfAbstractFeature::DiscoveryResult discoveryResult() const

Notifier signal:

void discoveryResultChanged(QIfAbstractFeature::DiscoveryResult discoveryResult)

See also startAutoDiscovery().

[read-only] error : const QString

Last error message of the feature. Empty if no error.

Access functions:

QString errorMessage() const

Notifier signal:

void errorChanged(QIfAbstractFeature::Error error, const QString &message)

[read-only] isInitialized : const bool

Indicates whether the feature has been initialized with all the values from the backend.

The property is true once the backend sends the QIfFeatureInterface::initializationDone signal to indicate that all values have now been initialized with values from the backend.

Access functions:

bool isInitialized() const

Notifier signal:

void isInitializedChanged(bool isInitialized)

See also isValid and QIfFeatureInterface::initializationDone.

[read-only] isValid : const bool

Indicates whether the feature is ready to use.

The property is true if the feature is ready to be used, otherwise false. Not being ready usually indicates that no suitable service object could be found, or that automatic discovery has not been triggered.

The backend still might not have sent all properties yet and is not fully initialized. Use isInitialized instead to know when the feature holds all correct values.

Access functions:

bool isValid() const

Notifier signal:

void isValidChanged(bool arg)

See also QIfServiceObject, discoveryMode, and isInitialized.

[since 6.5] preferredBackends : QStringList

Holds a list of wildcards to load the preferred backend during auto discovery.

The auto discovery mechanism will automatically search for backends which provide a matching interface for this feature implementation. See startAutoDiscovery() for more information.

In case multiple backends implement the same interface, the list of wildcards can be used to determine the correct one to load.

The wildcards are applied in order to the found backends. If the wildcard matches some backends those backends will be loaded, otherwise the next wildcard is used.

For example: Given an AbstractFeature with two backends, backend_mqtt.so and backend_qtro.so, the property can be set to "*_mqtt*" to always select the backend_mqtt.so backend when available.

This property was introduced in Qt 6.5.

Access functions:

QStringList preferredBackends() const
void setPreferredBackends(const QStringList &preferredBackends)

Notifier signal:

void preferredBackendsChanged(const QStringList &preferredBackends)

serviceObject : QIfServiceObject*

Sets the service object for the feature.

As features only expose the front API facing the developer, a service object implementing the actual function is required. This is usually retrieved through the auto discovery mechanism.

The setter for this property returns false if the Service Object is already set to exactly this instance or the Service Object doesn't get accepted by the feature.

Access functions:

QIfServiceObject *serviceObject() const
bool setServiceObject(QIfServiceObject *so)

Notifier signal:

void serviceObjectChanged()

See also discoveryMode.

Member Function Documentation

[explicit] QIfAbstractFeatureListModel::QIfAbstractFeatureListModel(const QString &interfaceName, QObject *parent = nullptr)

Constructs a QIfAbstractFeatureListModel.

The parent argument is passed on to the QAbstractListModel base class.

The interfaceName argument is used to locate suitable service objects.

[virtual protected] bool QIfAbstractFeatureListModel::acceptServiceObject(QIfServiceObject *serviceObject)

This method is expected to be implemented by any class subclassing QIfAbstractFeature.

The method should return true if the given serviceObject is accepted and can be used, otherwise false.

If the object is accepted, connectToServiceObject is called to actually connect to the service object.

The default implementation accepts the serviceObject if it implements the interface returned by interfaceName();

See also connectToServiceObject(), disconnectFromServiceObject(), and clearServiceObject().

[pure virtual protected] void QIfAbstractFeatureListModel::clearServiceObject()

This method is expected to be implemented by any class subclassing QIfAbstractFeatureListModel.

Called when no service object is available. The implementation is expected to set all properties to safe defaults and forget all links to the previous service object.

Note: You must emit the corresponding change signals for these properties, so that the feature is informed about the state change. This makes it possible for the implemented class to connect to a new service object afterwards.

There is no need to disconnect from the service object. If it still exists, it is guaranteed that disconnectFromServiceObject is called first.

See also acceptServiceObject(), connectToServiceObject(), and disconnectFromServiceObject().

[virtual protected] void QIfAbstractFeatureListModel::connectToServiceObject(QIfServiceObject *serviceObject)

This method is expected to be implemented by any class subclassing QIfAbstractFeature.

The implementation should connect to the serviceObject, and set up all properties to reflect the state of the service object.

There is no previous service object connected, as this function call is always preceded by a call to disconnectFromServiceObject or clearServiceObject.

It is safe to assume that the serviceObject, has always been accepted through the acceptServiceObject method prior to being passed to this method.

The default implementation connects to the signals offered by QIfFeatureInterface and calls QIfFeatureInterface::initialize() afterwards.

When reimplementing please keep in mind to connect all signals before calling this function. e.g.

/code void SimpleFeature::connectToServiceObject(QIfServiceObject *serviceObject) { SimpleFeatureBackendInterface *backend = backend(serviceObject); if (!backend) return;

// connect your signals connect(backend, &SimpleFeatureBackendInterface::propertyChanged, this, &SimpleFeature::onPropertyChanged);

// connects the base signals and call initialize() QIfAbstractFeature::connectToServiceObject(serviceObject);

// Additional initialization functions can be added here } /endcode

See also acceptServiceObject(), disconnectFromServiceObject(), and clearServiceObject().

[virtual protected] void QIfAbstractFeatureListModel::disconnectFromServiceObject(QIfServiceObject *serviceObject)

This method is expected to be implemented by any class subclassing QIfAbstractFeature.

The implementation should disconnect all connections to the serviceObject.

There is no need to reset internal variables to safe defaults. A call to this function is always followed by a call to connectToServiceObject or clearServiceObject.

The default implementation disconnects all signals from the serviceObject to this instance.

See also acceptServiceObject(), connectToServiceObject(), and clearServiceObject().

QIfAbstractFeature::Error QIfAbstractFeatureListModel::error() const

Returns the last error code.

See also setError() and QIfAbstractFeature::Error.

[protected] QString QIfAbstractFeatureListModel::errorText() const

Returns the current error code converted from QIfAbstractFeature::Error to QString

See also error.

[protected] QString QIfAbstractFeatureListModel::interfaceName() const

Returns the interface name this Feature expect to be available from the Service Object and this Feature is implementing.

See also acceptServiceObject.

[virtual protected slot] void QIfAbstractFeatureListModel::onErrorChanged(QIfAbstractFeature::Error error, const QString &message = QString())

Updates error and message from the backend.

This slot can be used when implementing a new Feature to report generic errors.

[protected] void QIfAbstractFeatureListModel::setError(QIfAbstractFeature::Error error, const QString &message = QString())

Sets error with the message.

Emits errorChanged() signal.

See also error() and QIfAbstractFeature::Error.

[slot] QIfAbstractFeature::DiscoveryResult QIfAbstractFeatureListModel::startAutoDiscovery()

Performs an automatic discovery attempt.

See QIfAbstractFeature::startAutoDiscovery() for more information

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.