Changeset View
Changeset View
Standalone View
Standalone View
src/delegaterecycler.cpp
Show First 20 Lines • Show All 208 Lines • ▼ Show 20 Line(s) | 207 | if (parentCtx) { | |||
---|---|---|---|---|---|
209 | break; | 209 | break; | ||
210 | } else { | 210 | } else { | ||
211 | candidate = candidate->parentItem(); | 211 | candidate = candidate->parentItem(); | ||
212 | } | 212 | } | ||
213 | } | 213 | } | ||
214 | 214 | | |||
215 | Q_ASSERT(ctx); | 215 | Q_ASSERT(ctx); | ||
216 | 216 | | |||
217 | if (QQmlEngine *eng = qmlEngine(this)) { | 217 | QObject *contextObjectToSet = nullptr; | ||
218 | //share context object in order to never lose track of global i18n() | 218 | { | ||
219 | ctx->setContextObject(eng->rootContext()->contextObject()); | 219 | // Find the first parent that has a context object with a valid translationDomain property, i.e. is a KLocalizedContext | ||
220 | QQmlContext *auxCtx = ctx; | ||||
221 | while (auxCtx != nullptr) { | ||||
222 | QObject *auxCtxObj = auxCtx->contextObject(); | ||||
223 | if (auxCtxObj && auxCtxObj->property("translationDomain").isValid()) { | ||||
224 | contextObjectToSet = auxCtxObj; | ||||
225 | break; | ||||
226 | } | ||||
227 | auxCtx = auxCtx->parentContext(); | ||||
228 | } | ||||
229 | } | ||||
230 | if (contextObjectToSet) { | ||||
231 | ctx->setContextObject(contextObjectToSet); | ||||
220 | } | 232 | } | ||
221 | 233 | | |||
222 | QObject *modelObj = m_propertiesTracker->property("trackedModel").value<QObject *>(); | 234 | QObject *modelObj = m_propertiesTracker->property("trackedModel").value<QObject *>(); | ||
223 | if (modelObj) { | 235 | if (modelObj) { | ||
224 | const QMetaObject *metaObj = modelObj->metaObject(); | 236 | const QMetaObject *metaObj = modelObj->metaObject(); | ||
225 | for (int i = metaObj->propertyOffset(); i < metaObj->propertyCount(); ++i) { | 237 | for (int i = metaObj->propertyOffset(); i < metaObj->propertyCount(); ++i) { | ||
226 | ctx->setContextProperty(QString::fromUtf8(metaObj->property(i).name()), metaObj->property(i).read(modelObj)); | 238 | ctx->setContextProperty(QString::fromUtf8(metaObj->property(i).name()), metaObj->property(i).read(modelObj)); | ||
227 | } | 239 | } | ||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |