- Qt 6.12
- Qt Graphs
- QML Types
- QtGraphs
- BarModelMapper
- Qt Graphs | Commercial or GPLv3

# BarModelMapper QML Type

Model mapper for bar series. More...

Import Statement: | `import QtGraphs`
In C++: | QBarModelMapper

- List of all members, including inherited members
- BarModelMapper is part of Qt Graphs QML Types for 2D.

## Properties

- count : qsizetype
- first : qsizetype
- firstBarSetSection : qsizetype
- lastBarSetSection : qsizetype
- model : model
- orientation : orientation
- series : BarSeries

## Signals

- countChanged()
- firstBarSetSectionChanged()
- firstChanged()
- lastBarSetSectionChanged()
- modelChanged()
- orientationChanged()
- orientationChanged()
- seriesChanged()

## Detailed Description

The BarModelMapper type enables using a data model derived from the QAbstractItemModel class as a data source for a graph. A model mapper is used to create a connection between a data model and QBarSeries. You need to implement the data model and expose it to QML.

Both model and bar series properties can be used to manipulate the data. The model mapper keeps the bar series and the data model in sync.

The model mapper ensures that all the bar sets in the bar series have equal sizes. Therefore, adding or removing a value from a bar set causes the same change to be made in all the bar sets in the bar series.

The following QML code snippet creates a bar series with three bar sets (assuming the model has at least four columns). Each bar set contains data starting from row 1. The name of a bar set is defined by the column header.

     BarSeries {
         BarModelMapper {
             model: myCustomModel // QAbstractItemModel derived implementation
             firstBarSetColumn: 1
             lastBarSetColumn: 3
             firstRow: 1
             orientation: Qt.Vertical
         }
     }

## Property Documentation

### count : qsizetype

The number of rows or columns of the model that are mapped as the data for the bar series. The default value is `-1` which is also the minimum. The count is limited by the number of model's rows/columns.

See also orientation.

### first : qsizetype

The row or column of the model that contains the first values of the bar sets in the bar series. The default value is 0.

See also orientation.

### firstBarSetSection : qsizetype

The section of the model that is used as the data source for the first bar set. The default value is -1 (invalid mapping).

See also orientation.

### lastBarSetSection : qsizetype

The section of the model that is used as the data source for the last bar set. The default value is -1 (invalid mapping).

See also orientation.

### model : model

The data model that is used by the mapper. You need to implement the model and expose it to QML.

Note: The model has to support adding and removing rows or columns and modifying the data in the cells.

### orientation : orientation

Tells the modelmapper how to map data from a model. If `Qt.Vertical` is used, each of the model's columns defines a bar set, and the model's rows define the categories. When the orientation is set to `Qt.Horizontal`, each of the model's rows defines a bar set, and the model's columns define categories.

### series : BarSeries

The bar series that is used by the mapper. All the data in the series is discarded when it is set to the mapper. When the new series is specified, the old series is disconnected, but it preserves its data.

## Signal Documentation

### countChanged()

This signal is emitted when the number of rows or columns changes.

Note: The corresponding handler is `onCountChanged`.

### firstBarSetSectionChanged()

This signal is emitted when the first bar set section changes.

Note: The corresponding handler is `onFirstBarSetSectionChanged`.

### firstChanged()

This signal is emitted when the first row or column changes.

Note: The corresponding handler is `onFirstChanged`.

### lastBarSetSectionChanged()

This signal is emitted when the last bar set section changes.

Note: The corresponding handler is `onLastBarSetSectionChanged`.

### modelChanged()

This signal is emitted when the model that the mapper is connected to changes.

Note: The corresponding handler is `onModelChanged`.

### orientationChanged()

This signal is emitted when the orientation changes.

Note: The corresponding handler is `onOrientationChanged`.

### orientationChanged()

This signal is emitted when the orientation changes.

Note: The corresponding handler is `onOrientationChanged`.

### seriesChanged()

This signal is emitted when the bar series that the mapper is connected to changes.

Note: The corresponding handler is `onSeriesChanged`.