testroles.cpp
1 #include "testroles.h" 2 #include <QtQml> 3 4 QVariant StaticRole::value() const 5 { 6 return m_value; 7 } 8 9 void StaticRole::setValue(const QVariant& value) 10 { 11 if (m_value == value) 12 return; 13 14 m_value = value; 15 Q_EMIT valueChanged(); 16 invalidate(); 17 } 18 19 QVariant StaticRole::data(const QModelIndex& sourceIndex, const qqsfpm::QQmlSortFilterProxyModel& proxyModel) 20 { 21 Q_UNUSED(sourceIndex) 22 Q_UNUSED(proxyModel) 23 return m_value; 24 } 25 26 QVariant SourceIndexRole::data(const QModelIndex& sourceIndex, const qqsfpm::QQmlSortFilterProxyModel& proxyModel) 27 { 28 Q_UNUSED(proxyModel) 29 return sourceIndex.row(); 30 } 31 32 QStringList MultiRole::names() 33 { 34 return {"role1", "role2"}; 35 } 36 37 QVariant MultiRole::data(const QModelIndex&, const qqsfpm::QQmlSortFilterProxyModel&, const QString& name) 38 { 39 return "data for " + name; 40 } 41 42 void registerTestRolesTypes() { 43 qmlRegisterType<StaticRole>("SortFilterProxyModel.Test", 0, 2, "StaticRole"); 44 qmlRegisterType<SourceIndexRole>("SortFilterProxyModel.Test", 0, 2, "SourceIndexRole"); 45 qmlRegisterType<MultiRole>("SortFilterProxyModel.Test", 0, 2, "MultiRole"); 46 } 47 48 Q_COREAPP_STARTUP_FUNCTION(registerTestRolesTypes)