|
|
@ -16,14 +16,36 @@ QQmlMvvmBinding::QQmlMvvmBinding(QObject *parent) : |
|
|
|
this, &QQmlMvvmBinding::resetBinding); |
|
|
|
connect(this, &QQmlMvvmBinding::typeChanged, |
|
|
|
this, &QQmlMvvmBinding::resetBinding); |
|
|
|
|
|
|
|
connect(this, &QQmlMvvmBinding::viewChanged, |
|
|
|
this, &QQmlMvvmBinding::viewWasSet); |
|
|
|
connect(this, &QQmlMvvmBinding::viewModelChanged, |
|
|
|
this, &QQmlMvvmBinding::viewModelWasSet); |
|
|
|
} |
|
|
|
|
|
|
|
void QQmlMvvmBinding::classBegin() {} |
|
|
|
|
|
|
|
void QQmlMvvmBinding::componentComplete() |
|
|
|
{ |
|
|
|
if(!_view) |
|
|
|
// auto-detect parent item a view
|
|
|
|
if(!_viewSet) { |
|
|
|
_view = parent(); |
|
|
|
emit viewChanged(_view); |
|
|
|
} |
|
|
|
|
|
|
|
// auto-detect parent items viewmodel
|
|
|
|
if(_view && !_viewModelSet) { |
|
|
|
auto vmo = _view->metaObject(); |
|
|
|
auto vmPropIdx = vmo->indexOfProperty("viewModel"); |
|
|
|
if(vmPropIdx != -1) { |
|
|
|
auto vm = vmo->property(vmPropIdx).read(_view).value<QObject*>(); |
|
|
|
if(vm) { |
|
|
|
_viewModel = vm; |
|
|
|
emit viewModelChanged(_viewModel); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
_completed = true; |
|
|
|
resetBinding(); |
|
|
|
} |
|
|
@ -64,3 +86,13 @@ void QQmlMvvmBinding::resetBinding() |
|
|
|
_viewModelChangeSignal.isEmpty() ? nullptr : qUtf8Printable(_viewModelChangeSignal), |
|
|
|
_viewChangeSignal.isEmpty() ? nullptr : qUtf8Printable(_viewChangeSignal)); |
|
|
|
} |
|
|
|
|
|
|
|
void QQmlMvvmBinding::viewWasSet() |
|
|
|
{ |
|
|
|
_viewSet = true; |
|
|
|
} |
|
|
|
|
|
|
|
void QQmlMvvmBinding::viewModelWasSet() |
|
|
|
{ |
|
|
|
_viewModelSet = true; |
|
|
|
} |
|
|
|