summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
6ede3b0)
Handle nested property names in section.property.
Task-number: QTBUG-24569
Change-Id: I0ea6003313108b8232bcd3a3015a4dbbd0753cec
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
const_cast<VDMAbstractItemModelDataType *>(this)->release();
}
const_cast<VDMAbstractItemModelDataType *>(this)->release();
}
- QString stringValue(const QQuickVisualAdaptorModel &model, int index, const QString &role) const
+ QVariant value(const QQuickVisualAdaptorModel &model, int index, const QString &role) const
{
QHash<QByteArray, int>::const_iterator it = roleNames.find(role.toUtf8());
if (it != roleNames.end()) {
{
QHash<QByteArray, int>::const_iterator it = roleNames.find(role.toUtf8());
if (it != roleNames.end()) {
- return model.aim()->index(index, 0, model.rootIndex).data(*it).toString();
+ return model.aim()->index(index, 0, model.rootIndex).data(*it);
} else if (role == QLatin1String("hasModelChildren")) {
} else if (role == QLatin1String("hasModelChildren")) {
- return QVariant(model.aim()->hasChildren(model.aim()->index(index, 0, model.rootIndex))).toString();
+ return QVariant(model.aim()->hasChildren(model.aim()->index(index, 0, model.rootIndex)));
const_cast<VDMListModelInterfaceDataType *>(this)->release();
}
const_cast<VDMListModelInterfaceDataType *>(this)->release();
}
- QString stringValue(const QQuickVisualAdaptorModel &model, int index, const QString &role) const
+ QVariant value(const QQuickVisualAdaptorModel &model, int index, const QString &role) const
{
QHash<QByteArray, int>::const_iterator it = roleNames.find(role.toUtf8());
return it != roleNames.end() && model
{
QHash<QByteArray, int>::const_iterator it = roleNames.find(role.toUtf8());
return it != roleNames.end() && model
- ? model.lmi()->data(index, *it).toString()
- : QString();
+ ? model.lmi()->data(index, *it)
+ : QVariant();
}
QQuickVisualDataModelItem *createItem(
}
QQuickVisualDataModelItem *createItem(
return model.list.count();
}
return model.list.count();
}
- QString stringValue(const QQuickVisualAdaptorModel &model, int index, const QString &role) const
+ QVariant value(const QQuickVisualAdaptorModel &model, int index, const QString &role) const
{
return role == QLatin1String("modelData")
{
return role == QLatin1String("modelData")
- ? model.list.at(index).toString()
- : QString();
+ ? model.list.at(index)
+ : QVariant();
}
QQuickVisualDataModelItem *createItem(
}
QQuickVisualDataModelItem *createItem(
return model.list.count();
}
return model.list.count();
}
- QString stringValue(const QQuickVisualAdaptorModel &model, int index, const QString &role) const
+ QVariant value(const QQuickVisualAdaptorModel &model, int index, const QString &role) const
{
if (QObject *object = model.list.at(index).value<QObject *>())
{
if (QObject *object = model.list.at(index).value<QObject *>())
- return object->property(role.toUtf8()).toString();
- return QString();
+ return object->property(role.toUtf8());
+ return QVariant();
}
QQuickVisualDataModelItem *createItem(
}
QQuickVisualDataModelItem *createItem(
virtual int count(const QQuickVisualAdaptorModel &) const { return 0; }
virtual void cleanup(QQuickVisualAdaptorModel &, QQuickVisualDataModel * = 0) const {}
virtual int count(const QQuickVisualAdaptorModel &) const { return 0; }
virtual void cleanup(QQuickVisualAdaptorModel &, QQuickVisualDataModel * = 0) const {}
- virtual QString stringValue(const QQuickVisualAdaptorModel &, int, const QString &) const {
- return QString(); }
+ virtual QVariant value(const QQuickVisualAdaptorModel &, int, const QString &) const {
+ return QVariant(); }
virtual QQuickVisualDataModelItem *createItem(
QQuickVisualAdaptorModel &,
virtual QQuickVisualDataModelItem *createItem(
QQuickVisualAdaptorModel &,
inline const QListModelInterface *lmi() const { return static_cast<const QListModelInterface *>(object()); }
inline int count() const { return qMax(0, accessors->count(*this)); }
inline const QListModelInterface *lmi() const { return static_cast<const QListModelInterface *>(object()); }
inline int count() const { return qMax(0, accessors->count(*this)); }
- inline QString stringValue(int index, const QString &role) const {
- return accessors->stringValue(*this, index, role); }
+ inline QVariant value(int index, const QString &role) const {
+ return accessors->value(*this, index, role); }
inline QQuickVisualDataModelItem *createItem(QQuickVisualDataModelItemMetaType *metaType, QQmlEngine *engine, int index) {
return accessors->createItem(*this, metaType, engine, index); }
inline bool hasProxyObject() const {
inline QQuickVisualDataModelItem *createItem(QQuickVisualDataModelItemMetaType *metaType, QQmlEngine *engine, int index) {
return accessors->createItem(*this, metaType, engine, index); }
inline bool hasProxyObject() const {
{
Compositor::iterator it = m_compositor.find(group, index);
if (QQuickVisualAdaptorModel *model = it.list<QQuickVisualAdaptorModel>()) {
{
Compositor::iterator it = m_compositor.find(group, index);
if (QQuickVisualAdaptorModel *model = it.list<QQuickVisualAdaptorModel>()) {
- return model->stringValue(it.modelIndex(), name);
+ QString role = name;
+ int dot = name.indexOf(QLatin1Char('.'));
+ if (dot > 0)
+ role = name.left(dot);
+ QVariant value = model->value(it.modelIndex(), role);
+ while (dot > 0) {
+ QObject *obj = qvariant_cast<QObject*>(value);
+ if (!obj)
+ return QString();
+ int from = dot+1;
+ dot = name.indexOf(QLatin1Char('.'), from);
+ value = obj->property(name.mid(from, dot-from).toUtf8());
+ }
+ return value.toString();
Text { objectName: "section"; text: parent.ListView.section }
}
}
Text { objectName: "section"; text: parent.ListView.section }
}
}
+
+ function changeSectionProperty() {
+ section.property = "object.subName"
+ }
section.property: "name"
section.criteria: ViewSection.FullString
}
section.property: "name"
section.criteria: ViewSection.FullString
}
+class DataSubObject : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QString subName READ subName WRITE setSubName NOTIFY subNameChanged)
+
+public:
+ DataSubObject(QObject *parent=0) : QObject(parent) {}
+
+ QString subName() const { return m_subName; }
+ void setSubName(const QString &name) {
+ if (name != m_subName) {
+ m_subName = name;
+ emit subNameChanged();
+ }
+ }
+
+signals:
+ void subNameChanged();
+
+private:
+ QString m_subName;
+};
+
class DataObject : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
class DataObject : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
+ Q_PROPERTY(QObject *object READ object)
public:
DataObject(QObject *parent=0) : QObject(parent) {}
DataObject(const QString &name, const QString &color, QObject *parent=0)
public:
DataObject(QObject *parent=0) : QObject(parent) {}
DataObject(const QString &name, const QString &color, QObject *parent=0)
- : QObject(parent), m_name(name), m_color(color) { }
+ : QObject(parent), m_name(name), m_color(color), m_object(new DataSubObject(this)) { }
QString name() const { return m_name; }
QString name() const { return m_name; }
+ QObject *object() const { return m_object; }
+ void setSubName(const QString &sn) {
+ m_object->setSubName(sn);
+ }
+
signals:
void nameChanged();
void colorChanged();
signals:
void nameChanged();
void colorChanged();
private:
QString m_name;
QString m_color;
private:
QString m_name;
QString m_color;
+ DataSubObject *m_object;
};
class ItemRequester : public QObject
};
class ItemRequester : public QObject
dataList[0]->setProperty("name", QLatin1String("Changed"));
QCOMPARE(name->text(), QString("Changed"));
QCOMPARE(name->property("modelName").toString(), QString("Changed"));
dataList[0]->setProperty("name", QLatin1String("Changed"));
QCOMPARE(name->text(), QString("Changed"));
QCOMPARE(name->property("modelName").toString(), QString("Changed"));
+
+ // Test resolving nested section property
+ DataObject *obj = static_cast<DataObject*>(dataList[0]);
+ obj->setSubName("SubItem 1");
+
+ QMetaObject::invokeMethod(listview, "changeSectionProperty");
+ section = findItem<QQuickText>(contentItem, "section", 0);
+ QCOMPARE(section->text(), QString("SubItem 1"));
}
void tst_qquickvisualdatamodel::singleRole()
}
void tst_qquickvisualdatamodel::singleRole()