From bdeef06f952ee68657c59f7f0a6f9650fbc6eaed Mon Sep 17 00:00:00 2001 From: Skycoder42 Date: Tue, 12 Feb 2019 23:22:07 +0100 Subject: [PATCH] add wasm support --- .travis.yml | 3 +++ .../DataSyncSampleCore/samplecoreapp.cpp | 2 +- src/imports/mvvmquick/settingsentrymodel.cpp | 3 +-- src/mvvmcore/coreapp.cpp | 4 ++-- src/mvvmcore/exception.h | 16 ++++++++++++++++ src/mvvmcore/ipresenter.cpp | 2 +- src/mvvmcore/ipresenter.h | 9 ++++----- src/mvvmcore/mvvmcore.pro | 3 ++- src/mvvmcore/serviceregistry.cpp | 6 +++--- src/mvvmcore/serviceregistry.h | 16 ++++++++-------- src/mvvmcore/settingsconfigloader.cpp | 2 +- src/mvvmcore/settingsconfigloader_p.h | 5 +++-- src/mvvmcore/settingssetup.h | 4 ++-- .../datasyncsettingsaccessor.cpp | 9 +++++---- src/mvvmquick/quickpresenter.cpp | 10 +++++----- src/mvvmwidgets/widgetspresenter.cpp | 12 +++++------- 16 files changed, 62 insertions(+), 44 deletions(-) create mode 100644 src/mvvmcore/exception.h diff --git a/.travis.yml b/.travis.yml index 2bcf80e..a4d4004 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,9 @@ matrix: - PLATFORM=gcc_64 - BUILD_DOC=true - BUILD_EXAMPLES=true + - os: linux + env: + - PLATFORM=emscripten - os: linux env: - PLATFORM=android_arm64_v8a diff --git a/examples/mvvmdatasynccore/DataSyncSampleCore/samplecoreapp.cpp b/examples/mvvmdatasynccore/DataSyncSampleCore/samplecoreapp.cpp index a5b8262..e55e904 100644 --- a/examples/mvvmdatasynccore/DataSyncSampleCore/samplecoreapp.cpp +++ b/examples/mvvmdatasynccore/DataSyncSampleCore/samplecoreapp.cpp @@ -29,7 +29,7 @@ int SampleCoreApp::startApp(const QStringList &arguments) .create(); show(); return EXIT_SUCCESS; - } catch (QException &e) { + } catch (std::exception &e) { qCritical() << e.what(); return EXIT_FAILURE; } diff --git a/src/imports/mvvmquick/settingsentrymodel.cpp b/src/imports/mvvmquick/settingsentrymodel.cpp index 3a95109..0640bf1 100644 --- a/src/imports/mvvmquick/settingsentrymodel.cpp +++ b/src/imports/mvvmquick/settingsentrymodel.cpp @@ -168,8 +168,7 @@ SettingsEntryModel::EntryInfo::EntryInfo(SettingsElements::Entry entry, QUrl del group(std::move(group)) { static const QRegularExpression nameRegex(QStringLiteral("&(?!&)"), - QRegularExpression::DontCaptureOption | - QRegularExpression::OptimizeOnFirstUsageOption); + QRegularExpression::DontCaptureOption); title.remove(nameRegex); this->group.entries.clear(); } diff --git a/src/mvvmcore/coreapp.cpp b/src/mvvmcore/coreapp.cpp index 3626202..2636e4a 100644 --- a/src/mvvmcore/coreapp.cpp +++ b/src/mvvmcore/coreapp.cpp @@ -251,7 +251,7 @@ void CoreAppPrivate::showDialog(const MessageConfig &config, MessageResult *resu try { presenter->showDialog(config, result); logDebug() << "Successfully presented dialog of type" << config.type(); - } catch(QException &e) { + } catch(QTMVVM_EXCEPTION_BASE &e) { logCritical() << "Failed to show dialog for type" << config.type() << ":" << config.subType() << "with error:" @@ -368,7 +368,7 @@ QPointer CoreAppPrivate::showViewModelWithReturn(const QMetaObject *m if(isSingle) singleInstances.insert(metaObject, vm); return vm; - } catch(QException &e) { + } catch(QTMVVM_EXCEPTION_BASE &e) { logCritical() << "Failed to present viewmodel of type" << metaObject->className() << "with error:" diff --git a/src/mvvmcore/exception.h b/src/mvvmcore/exception.h new file mode 100644 index 0000000..53b7c00 --- /dev/null +++ b/src/mvvmcore/exception.h @@ -0,0 +1,16 @@ +#ifndef QTMVVM_EXCEPTION_H +#define QTMVVM_EXCEPTION_H + +#include "QtMvvmCore/qtmvvmcore_global.h" + +#if !defined(QT_NO_EXCEPTIONS) && QT_CONFIG(future) +#include +#define QTMVVM_EXCEPTION_BASE QException +#define QTMVVM_EXCEPTION_OR override +#else +#include +#define QTMVVM_EXCEPTION_BASE std::exception +#define QTMVVM_EXCEPTION_OR +#endif + +#endif // QTMVVM_EXCEPTION_H diff --git a/src/mvvmcore/ipresenter.cpp b/src/mvvmcore/ipresenter.cpp index a2a6f1e..04a0f36 100644 --- a/src/mvvmcore/ipresenter.cpp +++ b/src/mvvmcore/ipresenter.cpp @@ -19,7 +19,7 @@ void PresenterException::raise() const throw (*this); } -QException *PresenterException::clone() const +QTMVVM_EXCEPTION_BASE *PresenterException::clone() const { return new PresenterException(this); } diff --git a/src/mvvmcore/ipresenter.h b/src/mvvmcore/ipresenter.h index 469bc5a..186bf15 100644 --- a/src/mvvmcore/ipresenter.h +++ b/src/mvvmcore/ipresenter.h @@ -1,16 +1,15 @@ #ifndef QTMVVM_IPRESENTER_H #define QTMVVM_IPRESENTER_H -#include - #include "QtMvvmCore/qtmvvmcore_global.h" #include "QtMvvmCore/viewmodel.h" #include "QtMvvmCore/message.h" +#include "QtMvvmCore/exception.h" namespace QtMvvm { //! An exception to be thrown from the presenter if presenting fails -class Q_MVVMCORE_EXPORT PresenterException : public QException +class Q_MVVMCORE_EXPORT PresenterException : public QTMVVM_EXCEPTION_BASE { public: //! Constructor with an error message @@ -20,9 +19,9 @@ public: const char *what() const noexcept override; //! @inherit{QException::raise} - void raise() const override; + virtual void raise() const QTMVVM_EXCEPTION_OR; //! @inherit{QException::clone} - QException *clone() const override; + virtual QTMVVM_EXCEPTION_BASE *clone() const QTMVVM_EXCEPTION_OR; protected: //! @private diff --git a/src/mvvmcore/mvvmcore.pro b/src/mvvmcore/mvvmcore.pro index be80844..eff5443 100644 --- a/src/mvvmcore/mvvmcore.pro +++ b/src/mvvmcore/mvvmcore.pro @@ -25,7 +25,8 @@ HEADERS += \ isettingsaccessor.h \ qsettingsaccessor.h \ settingsentry.h \ - settingsconfigloader_p.h + settingsconfigloader_p.h \ + exception.h SOURCES += \ viewmodel.cpp \ diff --git a/src/mvvmcore/serviceregistry.cpp b/src/mvvmcore/serviceregistry.cpp index 260a136..dc46d98 100644 --- a/src/mvvmcore/serviceregistry.cpp +++ b/src/mvvmcore/serviceregistry.cpp @@ -335,7 +335,7 @@ void ServiceExistsException::raise() const throw (*this); } -QException *ServiceExistsException::clone() const +QTMVVM_EXCEPTION_BASE *ServiceExistsException::clone() const { return new ServiceExistsException(this); } @@ -360,7 +360,7 @@ void ServiceConstructionException::raise() const throw (*this); } -QException *ServiceConstructionException::clone() const +QTMVVM_EXCEPTION_BASE *ServiceConstructionException::clone() const { return new ServiceConstructionException(this); } @@ -380,7 +380,7 @@ void ServiceDependencyException::raise() const throw (*this); } -QException *ServiceDependencyException::clone() const +QTMVVM_EXCEPTION_BASE *ServiceDependencyException::clone() const { return new ServiceDependencyException(this); } diff --git a/src/mvvmcore/serviceregistry.h b/src/mvvmcore/serviceregistry.h index 24a8f97..2e15a14 100644 --- a/src/mvvmcore/serviceregistry.h +++ b/src/mvvmcore/serviceregistry.h @@ -5,10 +5,10 @@ #include #include -#include #include "QtMvvmCore/qtmvvmcore_global.h" #include "QtMvvmCore/injection.h" +#include "QtMvvmCore/exception.h" namespace QtMvvm { @@ -108,7 +108,7 @@ private: }; //! Is thrown if a service is beeing registered that is already registered -class Q_MVVMCORE_EXPORT ServiceExistsException : public QException +class Q_MVVMCORE_EXPORT ServiceExistsException : public QTMVVM_EXCEPTION_BASE { public: //! @private @@ -118,9 +118,9 @@ public: const char *what() const noexcept override; //! @inherit{QException::raise} - void raise() const override; + virtual void raise() const QTMVVM_EXCEPTION_OR; //! @inherit{QException::clone} - QException *clone() const override; + virtual QTMVVM_EXCEPTION_BASE *clone() const QTMVVM_EXCEPTION_OR; protected: //! @private @@ -131,7 +131,7 @@ protected: }; //! Is thrown in case the construction of a service has failed -class Q_MVVMCORE_EXPORT ServiceConstructionException : public QException +class Q_MVVMCORE_EXPORT ServiceConstructionException : public QTMVVM_EXCEPTION_BASE { public: //! @private @@ -141,9 +141,9 @@ public: const char *what() const noexcept override; //! @inherit{QException::raise} - void raise() const override; + virtual void raise() const QTMVVM_EXCEPTION_OR; //! @inherit{QException::clone} - QException *clone() const override; + virtual QTMVVM_EXCEPTION_BASE *clone() const QTMVVM_EXCEPTION_OR; protected: //! @private @@ -161,7 +161,7 @@ public: ServiceDependencyException(const QByteArray &iid); void raise() const override; - QException *clone() const override; + QTMVVM_EXCEPTION_BASE *clone() const override; protected: //! @private diff --git a/src/mvvmcore/settingsconfigloader.cpp b/src/mvvmcore/settingsconfigloader.cpp index 524dac1..c146be5 100644 --- a/src/mvvmcore/settingsconfigloader.cpp +++ b/src/mvvmcore/settingsconfigloader.cpp @@ -226,7 +226,7 @@ void SettingsConfigException::raise() const throw *this; } -QException *SettingsConfigException::clone() const +QTMVVM_EXCEPTION_BASE *SettingsConfigException::clone() const { return new SettingsConfigException{_what}; } diff --git a/src/mvvmcore/settingsconfigloader_p.h b/src/mvvmcore/settingsconfigloader_p.h index e05079b..7fb5a26 100644 --- a/src/mvvmcore/settingsconfigloader_p.h +++ b/src/mvvmcore/settingsconfigloader_p.h @@ -6,6 +6,7 @@ #include "qtmvvmcore_global.h" #include "settingssetup.h" +#include "exception.h" #include @@ -57,8 +58,8 @@ public: const char *what() const noexcept override; - void raise() const override; - QException *clone() const override; + void raise() const QTMVVM_EXCEPTION_OR; + QTMVVM_EXCEPTION_BASE *clone() const QTMVVM_EXCEPTION_OR; private: const QByteArray _what; diff --git a/src/mvvmcore/settingssetup.h b/src/mvvmcore/settingssetup.h index b4d68ad..8677a8d 100644 --- a/src/mvvmcore/settingssetup.h +++ b/src/mvvmcore/settingssetup.h @@ -6,9 +6,9 @@ #include #include #include -#include #include "QtMvvmCore/qtmvvmcore_global.h" +#include "QtMvvmCore/exception.h" namespace QtMvvm { @@ -109,7 +109,7 @@ struct Setup } //! An exception throw in case loading a settings setup went wrong -class SettingsLoaderException : public QException {}; +class SettingsLoaderException : public QTMVVM_EXCEPTION_BASE {}; //! An interface for a generic settings setup loader class ISettingsSetupLoader diff --git a/src/mvvmdatasynccore/datasyncsettingsaccessor.cpp b/src/mvvmdatasynccore/datasyncsettingsaccessor.cpp index f829d0b..cb83a7a 100644 --- a/src/mvvmdatasynccore/datasyncsettingsaccessor.cpp +++ b/src/mvvmdatasynccore/datasyncsettingsaccessor.cpp @@ -1,6 +1,7 @@ #include "datasyncsettingsaccessor.h" #include "datasyncsettingsaccessor_p.h" #include +#include #undef logDebug #undef logInfo @@ -40,7 +41,7 @@ bool DataSyncSettingsAccessor::contains(const QString &key) const { try { return d->store->keys().contains(key); - } catch(QException &e) { + } catch (QTMVVM_EXCEPTION_BASE &e) { logCritical() << "Failed to check if entry" << key << "exists with error:" << e.what(); return false; @@ -54,7 +55,7 @@ QVariant DataSyncSettingsAccessor::load(const QString &key, const QVariant &defa } catch (QtDataSync::NoDataException &e) { Q_UNUSED(e) return defaultValue; - } catch (QException &e) { + } catch (QTMVVM_EXCEPTION_BASE &e) { logCritical() << "Failed to load entry" << key << "from datasync settings with error:" << e.what(); return defaultValue; @@ -65,7 +66,7 @@ void DataSyncSettingsAccessor::save(const QString &key, const QVariant &value) { try { d->store->save({key, value}); - } catch (QException &e) { + } catch (QTMVVM_EXCEPTION_BASE &e) { logCritical() << "Failed to save entry" << key << "to datasync settings with error:" << e.what(); } @@ -81,7 +82,7 @@ void DataSyncSettingsAccessor::remove(const QString &key) for(const auto &rmKey : rmKeys) d->store->remove(rmKey); d->store->remove(key); - } catch (QException &e) { + } catch (QTMVVM_EXCEPTION_BASE &e) { logCritical() << "Failed to remove entry" << key << "from datasync settings with error:" << e.what(); } diff --git a/src/mvvmquick/quickpresenter.cpp b/src/mvvmquick/quickpresenter.cpp index bb49e61..7105a69 100644 --- a/src/mvvmquick/quickpresenter.cpp +++ b/src/mvvmquick/quickpresenter.cpp @@ -7,21 +7,22 @@ #include #include +#include + #include #include #include -namespace { -void qtMvvmQuickInit() +static void qtMvvmQuickInit() { qmlRegisterType("de.skycoder42.QtMvvm.Quick.Private", 1, 0, "UrlValidator"); QtMvvm::ServiceRegistry::instance()->registerObject(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true); QtMvvm::ServiceRegistry::instance()->registerInterface(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true); } -void initResources() +static void initResources() { #ifdef QT_STATIC qtMvvmQuickInit(); @@ -29,7 +30,6 @@ void initResources() #endif } -} Q_COREAPP_STARTUP_FUNCTION(qtMvvmQuickInit) using namespace QtMvvm; @@ -223,7 +223,7 @@ QuickPresenter *QuickPresenterPrivate::currentPresenter() "Cannot register views if the current presenter does not extend QtMvvm::QuickPresenter"); #endif return static_cast(ServiceRegistry::instance()->service()); - } catch(QException &e) { + } catch (QTMVVM_EXCEPTION_BASE &e) { qFatal("%s", e.what()); } } diff --git a/src/mvvmwidgets/widgetspresenter.cpp b/src/mvvmwidgets/widgetspresenter.cpp index 492b029..46f57f2 100644 --- a/src/mvvmwidgets/widgetspresenter.cpp +++ b/src/mvvmwidgets/widgetspresenter.cpp @@ -22,28 +22,26 @@ #include #include +#include #include #include #include -namespace { - -void qtMvvmWidgetsInit() +static void qtMvvmWidgetsInit() { QtMvvm::ServiceRegistry::instance()->registerObject(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true); QtMvvm::ServiceRegistry::instance()->registerInterface(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true); } -void initResources() +static void initResources() { #ifdef QT_STATIC qtMvvmWidgetsInit(); - Q_INIT_RESOURCE(qtmvvmsettingswidgets_module); + Q_INIT_RESOURCE(qtmvvmwidgets_module); #endif } -} Q_COREAPP_STARTUP_FUNCTION(qtMvvmWidgetsInit) using namespace QtMvvm; @@ -508,7 +506,7 @@ WidgetsPresenter *WidgetsPresenterPrivate::currentPresenter() "Cannot register widgets if the current presenter does not extend QtMvvm::WidgetsPresenter"); #endif return static_cast(ServiceRegistry::instance()->service()); - } catch(QException &e) { + } catch (QTMVVM_EXCEPTION_BASE &e) { qFatal("%s", e.what()); } }