QListModelBase

Trait QListModelBase 

Source
pub trait QListModelBase: QListModel + QObjectHolder<ProxyRust = QListModelProxyRust> {
    // Provided methods
    fn set(&mut self, index: usize, value: Self::Item) -> bool { ... }
    fn push(&mut self, value: Self::Item) { ... }
    fn insert(&mut self, index: usize, value: Self::Item) { ... }
    fn pop(&mut self) -> Option<Self::Item> { ... }
    fn remove(&mut self, index: usize) -> Self::Item { ... }
    fn reset(&mut self) { ... }
}
Expand description

A data-change signaling extension of QListModel.

QListModelBase provides the signaling mutation API for list models. The methods defined in this trait wrap the corresponding *_unnotified methods from QListModel and automatically emit the required Qt model signals (such as beginInsertRows, endInsertRows, dataChanged, etc.). This allows the UI to react to changes in the underlying data.

This trait is automatically implemented by the [qobject] macro and should not be implemented manually.

§Usage

When modifying data that you made accessible with QListModel, you have to use the functions provided by this trait. Do not call the *_unnotified methods from QListModel directly unless you are manually handling Qt model notifications.

The correctness of this trait depends on implementors of QListModel ensuring that:

  • The *_unnotified methods perform the exact mutation corresponding to the emitted Qt signals.
  • No additional structural changes occur.

Violating this contract may result in undefined behavior in Qt views.

Provided Methods§

Source

fn set(&mut self, index: usize, value: Self::Item) -> bool

Sets the item at index and notifies any attached views about the change, if the operation is successful.

This method calls QListModel::set_unnotified.

Returns true if the value was successfully updated, or false if the operation failed (for example, if the index was out of bounds or validation failed).

Source

fn push(&mut self, value: Self::Item)

Appends value to the end of the model and notifies any attached views about the change.

This method calls QListModel::push_unnotified.

Source

fn insert(&mut self, index: usize, value: Self::Item)

Inserts value at index and notifies any attached views about the change.

This method calls QListModel::insert_unnotified.

Source

fn pop(&mut self) -> Option<Self::Item>

Removes and returns the last item in the model and notifies any attached views about the change.

This method calls QListModel::pop_unnotified.

Returns None if the model is empty. If the model is not empty, the function has to guarantee the success of the operation.

Source

fn remove(&mut self, index: usize) -> Self::Item

Removes and returns the item at index and notifies any attached views about the change.

This method calls QListModel::remove_unnotified.

Source

fn reset(&mut self)

Resets the entire model and notifies any attached views to resyncronize all data.

This method calls QListModel::reset_unnotified.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§