summaryrefslogtreecommitdiffstats
path: root/src/charts/barchart/qbarmodelmapper.cpp
diff options
context:
space:
mode:
authorMaurice Kalinowski <maurice.kalinowski@qt.io>2018-11-08 10:28:52 +0100
committerMaurice Kalinowski <maurice.kalinowski@qt.io>2018-12-21 14:18:16 +0000
commiteb852ca7e5800577762663bc72b1f9d009cf7e51 (patch)
tree26960355e5870bf7f85910e1f0f1ac150a7044eb /src/charts/barchart/qbarmodelmapper.cpp
parentb36af85eac67c2e92b35849b34d913ee0290cd2b (diff)
Fix access to bar sets instantiated inside the module
The QBarModelMapper allocates QBarSet instances during initialization. While this works for pure C++ applications, on the QML side these need to be of type DeclarativeBarSet to be accessible, but also expose additional properties. The C++ module is not aware of QML, also the QBarModelMapper cannot expose a dynamic allocator without breaking binary compatibility. Hence, the approach is to create a custom allocator function and export it from the C++ module. In case a declarative chart is created, the allocator is replaced with the QML one. Fixes: QTBUG-71013 Change-Id: I1864d637df37f8cd38d28fdba75da0c5608a612c Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Diffstat (limited to 'src/charts/barchart/qbarmodelmapper.cpp')
-rw-r--r--src/charts/barchart/qbarmodelmapper.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/charts/barchart/qbarmodelmapper.cpp b/src/charts/barchart/qbarmodelmapper.cpp
index 966d719f..6a7e18d7 100644
--- a/src/charts/barchart/qbarmodelmapper.cpp
+++ b/src/charts/barchart/qbarmodelmapper.cpp
@@ -540,6 +540,13 @@ void QBarModelMapperPrivate::barValueChanged(int index)
initializeBarFromModel();
}
+QBarSet *qt_allocate_bar_set_cpp(const QString &label)
+{
+ return new QBarSet(label);
+}
+
+QT_CHARTS_EXPORT QBarSet *(*qt_allocate_bar_set)(const QString &label) = &qt_allocate_bar_set_cpp;
+
void QBarModelMapperPrivate::initializeBarFromModel()
{
if (m_model == 0 || m_series == 0)
@@ -556,7 +563,7 @@ void QBarModelMapperPrivate::initializeBarFromModel()
QModelIndex barIndex = barModelIndex(i, posInBar);
// check if there is such model index
if (barIndex.isValid()) {
- QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString());
+ QBarSet *barSet = qt_allocate_bar_set(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString());
while (barIndex.isValid()) {
barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
posInBar++;