|
|
@ -38,6 +38,9 @@ void CoreApp::disableAutoBoot() |
|
|
|
void CoreApp::registerApp() |
|
|
|
{ |
|
|
|
//register metatypes
|
|
|
|
qRegisterMetaType<const QMetaObject*>("const QMetaObject*"); |
|
|
|
|
|
|
|
//setup
|
|
|
|
setParent(qApp); |
|
|
|
CoreAppPrivate::instance = this; |
|
|
|
performRegistrations(); |
|
|
@ -45,6 +48,11 @@ void CoreApp::registerApp() |
|
|
|
QMetaObject::invokeMethod(this, "bootApp", Qt::QueuedConnection); |
|
|
|
} |
|
|
|
|
|
|
|
IPresenter *CoreApp::presenter() const |
|
|
|
{ |
|
|
|
return d->presenter.data(); |
|
|
|
} |
|
|
|
|
|
|
|
void CoreApp::bootApp() |
|
|
|
{ |
|
|
|
if(!d->presenter) |
|
|
@ -81,6 +89,28 @@ bool CoreApp::autoParse(QCommandLineParser &parser, const QStringList &arguments |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void CoreApp::show(const char *viewModelName, const QVariantHash ¶ms) const |
|
|
|
{ |
|
|
|
auto metaId = QMetaType::type(viewModelName); |
|
|
|
auto metaObject = QMetaType::metaObjectForType(metaId); |
|
|
|
if(!metaObject) { |
|
|
|
throw PresenterException(QByteArrayLiteral("Given name (") + |
|
|
|
viewModelName + |
|
|
|
QByteArrayLiteral(") does not name a type with meta data")); |
|
|
|
} |
|
|
|
show(metaObject, params); |
|
|
|
} |
|
|
|
|
|
|
|
void CoreApp::show(const QMetaObject *viewMetaObject, const QVariantHash ¶ms) const |
|
|
|
{ |
|
|
|
if(!viewMetaObject->inherits(&ViewModel::staticMetaObject)) { |
|
|
|
throw PresenterException(QByteArrayLiteral("Given type (") + |
|
|
|
viewMetaObject->className() + |
|
|
|
QByteArrayLiteral(") is not a class that extends QtMvvm::ViewModel")); |
|
|
|
} |
|
|
|
ViewModel::showImp(viewMetaObject, params, nullptr); |
|
|
|
} |
|
|
|
|
|
|
|
// ------------- Private Implementation -------------
|
|
|
|
|
|
|
|
bool CoreAppPrivate::bootEnabled = true; |
|
|
@ -96,6 +126,20 @@ QScopedPointer<CoreAppPrivate> &CoreAppPrivate::dInstance() |
|
|
|
} |
|
|
|
|
|
|
|
void CoreAppPrivate::showViewModel(const QMetaObject *metaObject, const QVariantHash ¶ms, QPointer<ViewModel> parent, quint32 requestCode) |
|
|
|
{ |
|
|
|
QMetaObject::invokeMethod(this, "showViewModelPrivate", Qt::QueuedConnection, |
|
|
|
Q_ARG(const QMetaObject*, metaObject), |
|
|
|
Q_ARG(const QVariantHash&, params), |
|
|
|
Q_ARG(QPointer<ViewModel>, parent), |
|
|
|
Q_ARG(quint32, requestCode)); |
|
|
|
} |
|
|
|
|
|
|
|
IPresenter *CoreAppPrivate::currentPresenter() const |
|
|
|
{ |
|
|
|
return presenter.data(); |
|
|
|
} |
|
|
|
|
|
|
|
void CoreAppPrivate::showViewModelPrivate(const QMetaObject *metaObject, const QVariantHash ¶ms, QPointer<ViewModel> parent, quint32 requestCode) |
|
|
|
{ |
|
|
|
if(presenter) { |
|
|
|
QPointer<ViewModel> vm; |
|
|
@ -106,9 +150,13 @@ void CoreAppPrivate::showViewModel(const QMetaObject *metaObject, const QVariant |
|
|
|
throw ServiceConstructionException("Invalid types - not at QtMvvm::ViewModel"); |
|
|
|
presenter->present(vm, params, parent); |
|
|
|
if(requestCode != 0) { |
|
|
|
QObject::connect(vm, &ViewModel::resultReady, |
|
|
|
parent, &ViewModel::onResult, |
|
|
|
Qt::UniqueConnection); |
|
|
|
QObject::connect(vm, &ViewModel::resultReady, parent, [vm, requestCode, parent](const QVariant &r){ |
|
|
|
vm->disconnect(parent); |
|
|
|
parent->onResult(requestCode, r); |
|
|
|
}); |
|
|
|
QObject::connect(vm, &ViewModel::destroyed, parent, [vm, requestCode, parent](){ |
|
|
|
parent->onResult(requestCode, QVariant()); |
|
|
|
}); |
|
|
|
} |
|
|
|
} catch(QException &e) { |
|
|
|
logCritical() << "Failed to present viewmodel of type" |
|
|
@ -124,8 +172,3 @@ void CoreAppPrivate::showViewModel(const QMetaObject *metaObject, const QVariant |
|
|
|
<< "- no presenter was set"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
IPresenter *CoreAppPrivate::currentPresenter() const |
|
|
|
{ |
|
|
|
return presenter.data(); |
|
|
|
} |
|
|
|