Browse Source

add wasm support

master
Skycoder42 6 years ago
parent
commit
bdeef06f95
No known key found for this signature in database GPG Key ID: 8E01AD9EF0578D2B
  1. 3
      .travis.yml
  2. 2
      examples/mvvmdatasynccore/DataSyncSampleCore/samplecoreapp.cpp
  3. 3
      src/imports/mvvmquick/settingsentrymodel.cpp
  4. 4
      src/mvvmcore/coreapp.cpp
  5. 16
      src/mvvmcore/exception.h
  6. 2
      src/mvvmcore/ipresenter.cpp
  7. 9
      src/mvvmcore/ipresenter.h
  8. 3
      src/mvvmcore/mvvmcore.pro
  9. 6
      src/mvvmcore/serviceregistry.cpp
  10. 16
      src/mvvmcore/serviceregistry.h
  11. 2
      src/mvvmcore/settingsconfigloader.cpp
  12. 5
      src/mvvmcore/settingsconfigloader_p.h
  13. 4
      src/mvvmcore/settingssetup.h
  14. 9
      src/mvvmdatasynccore/datasyncsettingsaccessor.cpp
  15. 10
      src/mvvmquick/quickpresenter.cpp
  16. 12
      src/mvvmwidgets/widgetspresenter.cpp

3
.travis.yml

@ -23,6 +23,9 @@ matrix:
- PLATFORM=gcc_64 - PLATFORM=gcc_64
- BUILD_DOC=true - BUILD_DOC=true
- BUILD_EXAMPLES=true - BUILD_EXAMPLES=true
- os: linux
env:
- PLATFORM=emscripten
- os: linux - os: linux
env: env:
- PLATFORM=android_arm64_v8a - PLATFORM=android_arm64_v8a

2
examples/mvvmdatasynccore/DataSyncSampleCore/samplecoreapp.cpp

@ -29,7 +29,7 @@ int SampleCoreApp::startApp(const QStringList &arguments)
.create(); .create();
show<SampleViewModel>(); show<SampleViewModel>();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (QException &e) { } catch (std::exception &e) {
qCritical() << e.what(); qCritical() << e.what();
return EXIT_FAILURE; return EXIT_FAILURE;
} }

3
src/imports/mvvmquick/settingsentrymodel.cpp

@ -168,8 +168,7 @@ SettingsEntryModel::EntryInfo::EntryInfo(SettingsElements::Entry entry, QUrl del
group(std::move(group)) group(std::move(group))
{ {
static const QRegularExpression nameRegex(QStringLiteral("&(?!&)"), static const QRegularExpression nameRegex(QStringLiteral("&(?!&)"),
QRegularExpression::DontCaptureOption | QRegularExpression::DontCaptureOption);
QRegularExpression::OptimizeOnFirstUsageOption);
title.remove(nameRegex); title.remove(nameRegex);
this->group.entries.clear(); this->group.entries.clear();
} }

4
src/mvvmcore/coreapp.cpp

@ -251,7 +251,7 @@ void CoreAppPrivate::showDialog(const MessageConfig &config, MessageResult *resu
try { try {
presenter->showDialog(config, result); presenter->showDialog(config, result);
logDebug() << "Successfully presented dialog of type" << config.type(); logDebug() << "Successfully presented dialog of type" << config.type();
} catch(QException &e) { } catch(QTMVVM_EXCEPTION_BASE &e) {
logCritical() << "Failed to show dialog for type" logCritical() << "Failed to show dialog for type"
<< config.type() << ":" << config.subType() << config.type() << ":" << config.subType()
<< "with error:" << "with error:"
@ -368,7 +368,7 @@ QPointer<ViewModel> CoreAppPrivate::showViewModelWithReturn(const QMetaObject *m
if(isSingle) if(isSingle)
singleInstances.insert(metaObject, vm); singleInstances.insert(metaObject, vm);
return vm; return vm;
} catch(QException &e) { } catch(QTMVVM_EXCEPTION_BASE &e) {
logCritical() << "Failed to present viewmodel of type" logCritical() << "Failed to present viewmodel of type"
<< metaObject->className() << metaObject->className()
<< "with error:" << "with error:"

16
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 <QtCore/QException>
#define QTMVVM_EXCEPTION_BASE QException
#define QTMVVM_EXCEPTION_OR override
#else
#include <exception>
#define QTMVVM_EXCEPTION_BASE std::exception
#define QTMVVM_EXCEPTION_OR
#endif
#endif // QTMVVM_EXCEPTION_H

2
src/mvvmcore/ipresenter.cpp

@ -19,7 +19,7 @@ void PresenterException::raise() const
throw (*this); throw (*this);
} }
QException *PresenterException::clone() const QTMVVM_EXCEPTION_BASE *PresenterException::clone() const
{ {
return new PresenterException(this); return new PresenterException(this);
} }

9
src/mvvmcore/ipresenter.h

@ -1,16 +1,15 @@
#ifndef QTMVVM_IPRESENTER_H #ifndef QTMVVM_IPRESENTER_H
#define QTMVVM_IPRESENTER_H #define QTMVVM_IPRESENTER_H
#include <QtCore/qexception.h>
#include "QtMvvmCore/qtmvvmcore_global.h" #include "QtMvvmCore/qtmvvmcore_global.h"
#include "QtMvvmCore/viewmodel.h" #include "QtMvvmCore/viewmodel.h"
#include "QtMvvmCore/message.h" #include "QtMvvmCore/message.h"
#include "QtMvvmCore/exception.h"
namespace QtMvvm { namespace QtMvvm {
//! An exception to be thrown from the presenter if presenting fails //! 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: public:
//! Constructor with an error message //! Constructor with an error message
@ -20,9 +19,9 @@ public:
const char *what() const noexcept override; const char *what() const noexcept override;
//! @inherit{QException::raise} //! @inherit{QException::raise}
void raise() const override; virtual void raise() const QTMVVM_EXCEPTION_OR;
//! @inherit{QException::clone} //! @inherit{QException::clone}
QException *clone() const override; virtual QTMVVM_EXCEPTION_BASE *clone() const QTMVVM_EXCEPTION_OR;
protected: protected:
//! @private //! @private

3
src/mvvmcore/mvvmcore.pro

@ -25,7 +25,8 @@ HEADERS += \
isettingsaccessor.h \ isettingsaccessor.h \
qsettingsaccessor.h \ qsettingsaccessor.h \
settingsentry.h \ settingsentry.h \
settingsconfigloader_p.h settingsconfigloader_p.h \
exception.h
SOURCES += \ SOURCES += \
viewmodel.cpp \ viewmodel.cpp \

6
src/mvvmcore/serviceregistry.cpp

@ -335,7 +335,7 @@ void ServiceExistsException::raise() const
throw (*this); throw (*this);
} }
QException *ServiceExistsException::clone() const QTMVVM_EXCEPTION_BASE *ServiceExistsException::clone() const
{ {
return new ServiceExistsException(this); return new ServiceExistsException(this);
} }
@ -360,7 +360,7 @@ void ServiceConstructionException::raise() const
throw (*this); throw (*this);
} }
QException *ServiceConstructionException::clone() const QTMVVM_EXCEPTION_BASE *ServiceConstructionException::clone() const
{ {
return new ServiceConstructionException(this); return new ServiceConstructionException(this);
} }
@ -380,7 +380,7 @@ void ServiceDependencyException::raise() const
throw (*this); throw (*this);
} }
QException *ServiceDependencyException::clone() const QTMVVM_EXCEPTION_BASE *ServiceDependencyException::clone() const
{ {
return new ServiceDependencyException(this); return new ServiceDependencyException(this);
} }

16
src/mvvmcore/serviceregistry.h

@ -5,10 +5,10 @@
#include <QtCore/qscopedpointer.h> #include <QtCore/qscopedpointer.h>
#include <QtCore/qvariant.h> #include <QtCore/qvariant.h>
#include <QtCore/qexception.h>
#include "QtMvvmCore/qtmvvmcore_global.h" #include "QtMvvmCore/qtmvvmcore_global.h"
#include "QtMvvmCore/injection.h" #include "QtMvvmCore/injection.h"
#include "QtMvvmCore/exception.h"
namespace QtMvvm { namespace QtMvvm {
@ -108,7 +108,7 @@ private:
}; };
//! Is thrown if a service is beeing registered that is already registered //! 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: public:
//! @private //! @private
@ -118,9 +118,9 @@ public:
const char *what() const noexcept override; const char *what() const noexcept override;
//! @inherit{QException::raise} //! @inherit{QException::raise}
void raise() const override; virtual void raise() const QTMVVM_EXCEPTION_OR;
//! @inherit{QException::clone} //! @inherit{QException::clone}
QException *clone() const override; virtual QTMVVM_EXCEPTION_BASE *clone() const QTMVVM_EXCEPTION_OR;
protected: protected:
//! @private //! @private
@ -131,7 +131,7 @@ protected:
}; };
//! Is thrown in case the construction of a service has failed //! 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: public:
//! @private //! @private
@ -141,9 +141,9 @@ public:
const char *what() const noexcept override; const char *what() const noexcept override;
//! @inherit{QException::raise} //! @inherit{QException::raise}
void raise() const override; virtual void raise() const QTMVVM_EXCEPTION_OR;
//! @inherit{QException::clone} //! @inherit{QException::clone}
QException *clone() const override; virtual QTMVVM_EXCEPTION_BASE *clone() const QTMVVM_EXCEPTION_OR;
protected: protected:
//! @private //! @private
@ -161,7 +161,7 @@ public:
ServiceDependencyException(const QByteArray &iid); ServiceDependencyException(const QByteArray &iid);
void raise() const override; void raise() const override;
QException *clone() const override; QTMVVM_EXCEPTION_BASE *clone() const override;
protected: protected:
//! @private //! @private

2
src/mvvmcore/settingsconfigloader.cpp

@ -226,7 +226,7 @@ void SettingsConfigException::raise() const
throw *this; throw *this;
} }
QException *SettingsConfigException::clone() const QTMVVM_EXCEPTION_BASE *SettingsConfigException::clone() const
{ {
return new SettingsConfigException{_what}; return new SettingsConfigException{_what};
} }

5
src/mvvmcore/settingsconfigloader_p.h

@ -6,6 +6,7 @@
#include "qtmvvmcore_global.h" #include "qtmvvmcore_global.h"
#include "settingssetup.h" #include "settingssetup.h"
#include "exception.h"
#include <settingsconfigimpl_p.h> #include <settingsconfigimpl_p.h>
@ -57,8 +58,8 @@ public:
const char *what() const noexcept override; const char *what() const noexcept override;
void raise() const override; void raise() const QTMVVM_EXCEPTION_OR;
QException *clone() const override; QTMVVM_EXCEPTION_BASE *clone() const QTMVVM_EXCEPTION_OR;
private: private:
const QByteArray _what; const QByteArray _what;

4
src/mvvmcore/settingssetup.h

@ -6,9 +6,9 @@
#include <QtCore/qurl.h> #include <QtCore/qurl.h>
#include <QtCore/qobject.h> #include <QtCore/qobject.h>
#include <QtCore/qfileselector.h> #include <QtCore/qfileselector.h>
#include <QtCore/qexception.h>
#include "QtMvvmCore/qtmvvmcore_global.h" #include "QtMvvmCore/qtmvvmcore_global.h"
#include "QtMvvmCore/exception.h"
namespace QtMvvm { namespace QtMvvm {
@ -109,7 +109,7 @@ struct Setup
} }
//! An exception throw in case loading a settings setup went wrong //! 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 //! An interface for a generic settings setup loader
class ISettingsSetupLoader class ISettingsSetupLoader

9
src/mvvmdatasynccore/datasyncsettingsaccessor.cpp

@ -1,6 +1,7 @@
#include "datasyncsettingsaccessor.h" #include "datasyncsettingsaccessor.h"
#include "datasyncsettingsaccessor_p.h" #include "datasyncsettingsaccessor_p.h"
#include <QtCore/QRegularExpression> #include <QtCore/QRegularExpression>
#include <QtMvvmCore/exception.h>
#undef logDebug #undef logDebug
#undef logInfo #undef logInfo
@ -40,7 +41,7 @@ bool DataSyncSettingsAccessor::contains(const QString &key) const
{ {
try { try {
return d->store->keys().contains(key); return d->store->keys().contains(key);
} catch(QException &e) { } catch (QTMVVM_EXCEPTION_BASE &e) {
logCritical() << "Failed to check if entry" << key << "exists with error:" logCritical() << "Failed to check if entry" << key << "exists with error:"
<< e.what(); << e.what();
return false; return false;
@ -54,7 +55,7 @@ QVariant DataSyncSettingsAccessor::load(const QString &key, const QVariant &defa
} catch (QtDataSync::NoDataException &e) { } catch (QtDataSync::NoDataException &e) {
Q_UNUSED(e) Q_UNUSED(e)
return defaultValue; return defaultValue;
} catch (QException &e) { } catch (QTMVVM_EXCEPTION_BASE &e) {
logCritical() << "Failed to load entry" << key << "from datasync settings with error:" logCritical() << "Failed to load entry" << key << "from datasync settings with error:"
<< e.what(); << e.what();
return defaultValue; return defaultValue;
@ -65,7 +66,7 @@ void DataSyncSettingsAccessor::save(const QString &key, const QVariant &value)
{ {
try { try {
d->store->save({key, value}); d->store->save({key, value});
} catch (QException &e) { } catch (QTMVVM_EXCEPTION_BASE &e) {
logCritical() << "Failed to save entry" << key << "to datasync settings with error:" logCritical() << "Failed to save entry" << key << "to datasync settings with error:"
<< e.what(); << e.what();
} }
@ -81,7 +82,7 @@ void DataSyncSettingsAccessor::remove(const QString &key)
for(const auto &rmKey : rmKeys) for(const auto &rmKey : rmKeys)
d->store->remove(rmKey); d->store->remove(rmKey);
d->store->remove(key); d->store->remove(key);
} catch (QException &e) { } catch (QTMVVM_EXCEPTION_BASE &e) {
logCritical() << "Failed to remove entry" << key << "from datasync settings with error:" logCritical() << "Failed to remove entry" << key << "from datasync settings with error:"
<< e.what(); << e.what();
} }

10
src/mvvmquick/quickpresenter.cpp

@ -7,21 +7,22 @@
#include <QtCore/QDirIterator> #include <QtCore/QDirIterator>
#include <QtCore/QMetaMethod> #include <QtCore/QMetaMethod>
#include <QtMvvmCore/exception.h>
#include <QtQml/qqml.h> #include <QtQml/qqml.h>
#include <QtMvvmCore/private/qtmvvm_logging_p.h> #include <QtMvvmCore/private/qtmvvm_logging_p.h>
#include <qurlvalidator.h> #include <qurlvalidator.h>
namespace {
void qtMvvmQuickInit() static void qtMvvmQuickInit()
{ {
qmlRegisterType<QUrlValidator>("de.skycoder42.QtMvvm.Quick.Private", 1, 0, "UrlValidator"); qmlRegisterType<QUrlValidator>("de.skycoder42.QtMvvm.Quick.Private", 1, 0, "UrlValidator");
QtMvvm::ServiceRegistry::instance()->registerObject<QtMvvm::InputViewFactory>(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true); QtMvvm::ServiceRegistry::instance()->registerObject<QtMvvm::InputViewFactory>(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true);
QtMvvm::ServiceRegistry::instance()->registerInterface<QtMvvm::IPresenter, QtMvvm::QuickPresenter>(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true); QtMvvm::ServiceRegistry::instance()->registerInterface<QtMvvm::IPresenter, QtMvvm::QuickPresenter>(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true);
} }
void initResources() static void initResources()
{ {
#ifdef QT_STATIC #ifdef QT_STATIC
qtMvvmQuickInit(); qtMvvmQuickInit();
@ -29,7 +30,6 @@ void initResources()
#endif #endif
} }
}
Q_COREAPP_STARTUP_FUNCTION(qtMvvmQuickInit) Q_COREAPP_STARTUP_FUNCTION(qtMvvmQuickInit)
using namespace QtMvvm; using namespace QtMvvm;
@ -223,7 +223,7 @@ QuickPresenter *QuickPresenterPrivate::currentPresenter()
"Cannot register views if the current presenter does not extend QtMvvm::QuickPresenter"); "Cannot register views if the current presenter does not extend QtMvvm::QuickPresenter");
#endif #endif
return static_cast<QuickPresenter*>(ServiceRegistry::instance()->service<IPresenter>()); return static_cast<QuickPresenter*>(ServiceRegistry::instance()->service<IPresenter>());
} catch(QException &e) { } catch (QTMVVM_EXCEPTION_BASE &e) {
qFatal("%s", e.what()); qFatal("%s", e.what());
} }
} }

12
src/mvvmwidgets/widgetspresenter.cpp

@ -22,28 +22,26 @@
#include <QtWidgets/QColorDialog> #include <QtWidgets/QColorDialog>
#include <QtMvvmCore/CoreApp> #include <QtMvvmCore/CoreApp>
#include <QtMvvmCore/exception.h>
#include <QtMvvmCore/private/qtmvvm_logging_p.h> #include <QtMvvmCore/private/qtmvvm_logging_p.h>
#include <dialogmaster.h> #include <dialogmaster.h>
#include <qurlvalidator.h> #include <qurlvalidator.h>
namespace { static void qtMvvmWidgetsInit()
void qtMvvmWidgetsInit()
{ {
QtMvvm::ServiceRegistry::instance()->registerObject<QtMvvm::InputWidgetFactory>(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true); QtMvvm::ServiceRegistry::instance()->registerObject<QtMvvm::InputWidgetFactory>(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true);
QtMvvm::ServiceRegistry::instance()->registerInterface<QtMvvm::IPresenter, QtMvvm::WidgetsPresenter>(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true); QtMvvm::ServiceRegistry::instance()->registerInterface<QtMvvm::IPresenter, QtMvvm::WidgetsPresenter>(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true);
} }
void initResources() static void initResources()
{ {
#ifdef QT_STATIC #ifdef QT_STATIC
qtMvvmWidgetsInit(); qtMvvmWidgetsInit();
Q_INIT_RESOURCE(qtmvvmsettingswidgets_module); Q_INIT_RESOURCE(qtmvvmwidgets_module);
#endif #endif
} }
}
Q_COREAPP_STARTUP_FUNCTION(qtMvvmWidgetsInit) Q_COREAPP_STARTUP_FUNCTION(qtMvvmWidgetsInit)
using namespace QtMvvm; using namespace QtMvvm;
@ -508,7 +506,7 @@ WidgetsPresenter *WidgetsPresenterPrivate::currentPresenter()
"Cannot register widgets if the current presenter does not extend QtMvvm::WidgetsPresenter"); "Cannot register widgets if the current presenter does not extend QtMvvm::WidgetsPresenter");
#endif #endif
return static_cast<WidgetsPresenter*>(ServiceRegistry::instance()->service<IPresenter>()); return static_cast<WidgetsPresenter*>(ServiceRegistry::instance()->service<IPresenter>());
} catch(QException &e) { } catch (QTMVVM_EXCEPTION_BASE &e) {
qFatal("%s", e.what()); qFatal("%s", e.what());
} }
} }

Loading…
Cancel
Save