summaryrefslogtreecommitdiff
path: root/platform/qt/src/qquickmapboxglmapparameter.cpp
blob: bd5cfdd089b00f8ebcb12e2e8e9459885eca01d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "QQuickMapboxGLMapParameter"

#include <QByteArray>
#include <QMetaObject>
#include <QMetaProperty>
#include <QSignalMapper>


QQuickMapboxGLMapParameter::QQuickMapboxGLMapParameter(QObject *parent)
    : QObject(parent)
    , m_metaPropertyOffset(metaObject()->propertyCount())
{
}

void QQuickMapboxGLMapParameter::componentComplete()
{
    for (int i = m_metaPropertyOffset; i < metaObject()->propertyCount(); ++i) {
        QMetaProperty property = metaObject()->property(i);

        if (!property.hasNotifySignal()) {
            return;
        }

        auto mapper = new QSignalMapper(this);
        mapper->setMapping(this, i);

        const QByteArray signalName = '2' + property.notifySignal().methodSignature();
        QObject::connect(this, signalName, mapper, SLOT(map()));
        QObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(onPropertyUpdated(int)));
    }
    emit propertiesReady();
}

void QQuickMapboxGLMapParameter::onPropertyUpdated(int index)
{
    emit propertyUpdated(metaObject()->property(index).name());
}