diff --git a/examples/mvvmcore/SampleCore/samplecoreapp.cpp b/examples/mvvmcore/SampleCore/samplecoreapp.cpp index 818cda7..b10daff 100644 --- a/examples/mvvmcore/SampleCore/samplecoreapp.cpp +++ b/examples/mvvmcore/SampleCore/samplecoreapp.cpp @@ -2,6 +2,7 @@ #include "sampleviewmodel.h" #include "drawerviewmodel.h" +#include #include #include @@ -33,6 +34,8 @@ void SampleCoreApp::performRegistrations() Q_INIT_RESOURCE(sample_core); QtMvvm::registerInterfaceConverter(); + + QLoggingCategory::setFilterRules(QStringLiteral("qtmvvm.debug=true")); } int SampleCoreApp::startApp(const QStringList &arguments) diff --git a/src/imports/mvvmquick/ActionButton.qml b/src/imports/mvvmquick/ActionButton.qml index 9e7b26a..c56a10e 100644 --- a/src/imports/mvvmquick/ActionButton.qml +++ b/src/imports/mvvmquick/ActionButton.qml @@ -1,6 +1,7 @@ import QtQuick 2.10 import QtQuick.Controls 2.3 import QtQuick.Controls.Material 2.3 +import de.skycoder42.QtMvvm.Quick 1.0 ToolButton { id: _toolButton @@ -23,7 +24,7 @@ ToolButton { } onPressAndHold: { - //TODO QuickExtras.hapticLongPress(); + QuickPresenter.hapticLongPress(); _backToolTip.visible = true; } onCanceled: _backToolTip.visible = false diff --git a/src/imports/mvvmquick/plugins.qmltypes b/src/imports/mvvmquick/plugins.qmltypes index 2782bb0..be17471 100644 --- a/src/imports/mvvmquick/plugins.qmltypes +++ b/src/imports/mvvmquick/plugins.qmltypes @@ -88,6 +88,7 @@ Module { } Method { name: "toggleDrawer" } Method { name: "popView" } + Method { name: "hapticLongPress" } Method { name: "mimeTypeFilters" type: "QStringList" diff --git a/src/imports/mvvmquick/qqmlquickpresenter.cpp b/src/imports/mvvmquick/qqmlquickpresenter.cpp index 6739826..1c9c26d 100644 --- a/src/imports/mvvmquick/qqmlquickpresenter.cpp +++ b/src/imports/mvvmquick/qqmlquickpresenter.cpp @@ -8,6 +8,10 @@ #include +#ifdef Q_OS_ANDROID +#include +#endif + using namespace QtMvvm; QQmlQuickPresenter::QQmlQuickPresenter(QQmlEngine *engine) : @@ -74,6 +78,24 @@ void QQmlQuickPresenter::popView() QMetaObject::invokeMethod(_qmlPresenter, "closeAction"); } +void QQmlQuickPresenter::hapticLongPress() +{ +#ifdef Q_OS_ANDROID + QtAndroid::runOnAndroidThread([](){ + const auto content = QAndroidJniObject::getStaticField("android/R$id", "content"); + const auto LONG_PRESS = QAndroidJniObject::getStaticField("android/view/HapticFeedbackConstants", "LONG_PRESS"); + + auto activity = QtAndroid::androidActivity(); + auto view = activity.callObjectMethod("findViewById", + "(I)Landroid/view/View;", + content); + view.callMethod("performHapticFeedback", + "(I)Z", + LONG_PRESS); + }); +#endif +} + void QQmlQuickPresenter::present(ViewModel *viewModel, const QVariantHash ¶ms, const QUrl &viewUrl, QPointer parent) { auto component = _componentCache.object(viewUrl); diff --git a/src/imports/mvvmquick/qqmlquickpresenter.h b/src/imports/mvvmquick/qqmlquickpresenter.h index 8602685..d506dd7 100644 --- a/src/imports/mvvmquick/qqmlquickpresenter.h +++ b/src/imports/mvvmquick/qqmlquickpresenter.h @@ -44,6 +44,8 @@ public Q_SLOTS: void toggleDrawer(); void popView(); + void hapticLongPress(); + Q_SIGNALS: void qmlPresenterChanged(QObject* qmlPresenter); void viewLoadingChanged(bool viewLoading); diff --git a/src/mvvmcore/ipresenter.h b/src/mvvmcore/ipresenter.h index b184ecf..1456175 100644 --- a/src/mvvmcore/ipresenter.h +++ b/src/mvvmcore/ipresenter.h @@ -25,7 +25,7 @@ protected: const QByteArray _what; }; -class Q_MVVMCORE_EXPORT IPresenter //TODO use via service registry EVERYWHERE +class Q_MVVMCORE_EXPORT IPresenter { public: inline virtual ~IPresenter() = default; diff --git a/src/mvvmcore/qtmvvmcore_global.cpp b/src/mvvmcore/qtmvvmcore_global.cpp index a349450..6a7eb01 100644 --- a/src/mvvmcore/qtmvvmcore_global.cpp +++ b/src/mvvmcore/qtmvvmcore_global.cpp @@ -25,10 +25,6 @@ Q_COREAPP_STARTUP_FUNCTION(qtMvvmCoreStartup) namespace QtMvvm { -#ifdef QT_NO_DEBUG //TODO always info only Q_LOGGING_CATEGORY(mvvmLoggingCat, "qtmvvm", QtInfoMsg) -#else -Q_LOGGING_CATEGORY(mvvmLoggingCat, "qtmvvm", QtDebugMsg) -#endif } diff --git a/src/mvvmcore/serviceregistry.cpp b/src/mvvmcore/serviceregistry.cpp index c70dca4..c906067 100644 --- a/src/mvvmcore/serviceregistry.cpp +++ b/src/mvvmcore/serviceregistry.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include using namespace QtMvvm; @@ -135,8 +137,12 @@ ServiceRegistryPrivate::ServiceInfo::ServiceInfo(bool weak) : ServiceRegistryPrivate::ServiceInfo::~ServiceInfo() { - if(_instance) - QMetaObject::invokeMethod(_instance, "deleteLater"); //TODO doesnt work out of eventloop, maybe test first? + if(_instance) { + if(QCoreApplication::closingDown()) + delete _instance; + else + QMetaObject::invokeMethod(_instance, "deleteLater"); + } } bool ServiceRegistryPrivate::ServiceInfo::replaceable() const @@ -153,6 +159,8 @@ QObject *ServiceRegistryPrivate::ServiceInfo::instance(ServiceRegistryPrivate *d throw ServiceConstructionException("Failed to construct service of type " + iid + " with unknown error"); + if(_instance->thread() != qApp->thread()) + _instance->moveToThread(qApp->thread()); } return _instance; } diff --git a/src/mvvmwidgets/widgetspresenter.cpp b/src/mvvmwidgets/widgetspresenter.cpp index 730e4e8..348d0a9 100644 --- a/src/mvvmwidgets/widgetspresenter.cpp +++ b/src/mvvmwidgets/widgetspresenter.cpp @@ -304,7 +304,7 @@ void WidgetsPresenter::presentInputDialog(const MessageConfig &config, QPointer< if(text.isNull()) text = config.title(); else - dialog->setWindowTitle(config.title());//TODO as header better? + dialog->setWindowTitle(config.title()); if(!text.isNull()) { auto label = new QLabel(text, dialog); layout->addWidget(label);