diff --git a/doc/makedoc.sh b/doc/makedoc.sh old mode 100644 new mode 100755 diff --git a/examples/examples.pro b/examples/examples.pro index e656575..949c824 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,3 +1,4 @@ TEMPLATE = subdirs -SUBDIRS = mvvmcore +SUBDIRS = mvvmcore \ + mvvmwidgets diff --git a/examples/mvvmcore/SampleCore/SampleCore.pro b/examples/mvvmcore/SampleCore/SampleCore.pro new file mode 100644 index 0000000..9eae342 --- /dev/null +++ b/examples/mvvmcore/SampleCore/SampleCore.pro @@ -0,0 +1,28 @@ +TEMPLATE = lib + +QT = core gui mvvmcore + +TARGET = SampleCore + +DEFINES += SAMPLECORE_LIBRARY + +HEADERS += \ + samplecore_global.h \ + samplecoreapp.h + +SOURCES += \ + samplecoreapp.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/mvvmcore/$$TARGET +INSTALLS += target + +#not found by linker? +unix:!mac { + LIBS += -L$$OUT_PWD/../../../lib #required to make this the first place to search + LIBS += -L$$[QT_INSTALL_LIBS] -licudata + LIBS += -L$$[QT_INSTALL_LIBS] -licui18n + LIBS += -L$$[QT_INSTALL_LIBS] -licuuc +} + +#add lib dir to rpath +mac: QMAKE_LFLAGS += '-Wl,-rpath,\'$$OUT_PWD/../../../lib\'' diff --git a/examples/mvvmcore/SampleCore/samplecore_global.h b/examples/mvvmcore/SampleCore/samplecore_global.h new file mode 100644 index 0000000..ba5ca4d --- /dev/null +++ b/examples/mvvmcore/SampleCore/samplecore_global.h @@ -0,0 +1,12 @@ +#ifndef SAMPLECORE_GLOBAL_H +#define SAMPLECORE_GLOBAL_H + +#include + +#if defined(SAMPLECORE_LIBRARY) +# define SAMPLECORESHARED_EXPORT Q_DECL_EXPORT +#else +# define SAMPLECORESHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // SAMPLECORE_GLOBAL_H diff --git a/examples/mvvmcore/SampleCore/samplecoreapp.cpp b/examples/mvvmcore/SampleCore/samplecoreapp.cpp new file mode 100644 index 0000000..288cbd7 --- /dev/null +++ b/examples/mvvmcore/SampleCore/samplecoreapp.cpp @@ -0,0 +1,27 @@ +#include "samplecoreapp.h" + +#include + +QTMVVM_REGISTER_CORE_APP(SampleCoreApp) + +SampleCoreApp::SampleCoreApp(QObject *parent) : + CoreApp(parent) +{} + +int SampleCoreApp::startApp(const QStringList &arguments) +{ + QCommandLineParser parser; + parser.addVersionOption(); + parser.addHelpOption(); + + parser.addOption({ + {QStringLiteral("n"), QStringLiteral("nothing")}, + QStringLiteral("Pointless action") + }); + + if(!autoParse(parser, arguments)) + return EXIT_SUCCESS; + + //TODO implement app code + return EXIT_FAILURE; +} diff --git a/examples/mvvmcore/SampleCore/samplecoreapp.h b/examples/mvvmcore/SampleCore/samplecoreapp.h new file mode 100644 index 0000000..857c25b --- /dev/null +++ b/examples/mvvmcore/SampleCore/samplecoreapp.h @@ -0,0 +1,19 @@ +#ifndef SAMPLECOREAPP_H +#define SAMPLECOREAPP_H + +#include + +#include "samplecore_global.h" + +class SAMPLECORESHARED_EXPORT SampleCoreApp : public QtMvvm::CoreApp +{ + Q_OBJECT + +public: + SampleCoreApp(QObject *parent = nullptr); + +protected: + int startApp(const QStringList &arguments) override; +}; + +#endif // SAMPLECOREAPP_H diff --git a/examples/mvvmcore/mvvmcore.pro b/examples/mvvmcore/mvvmcore.pro index 517b870..0f57e24 100644 --- a/examples/mvvmcore/mvvmcore.pro +++ b/examples/mvvmcore/mvvmcore.pro @@ -1,2 +1,5 @@ TEMPLATE = subdirs QT_FOR_CONFIG += core + +SUBDIRS += \ + SampleCore diff --git a/examples/mvvmwidgets/SampleWidgets/SampleWidgets.pro b/examples/mvvmwidgets/SampleWidgets/SampleWidgets.pro new file mode 100644 index 0000000..d6401c4 --- /dev/null +++ b/examples/mvvmwidgets/SampleWidgets/SampleWidgets.pro @@ -0,0 +1,36 @@ +TEMPLATE = app + +QT += core gui widgets mvvmwidgets + +TARGET = SampleWidgets + +HEADERS += \ + mainwindow.h + +SOURCES += \ + main.cpp \ + mainwindow.cpp + +FORMS += \ + mainwindow.ui + +target.path = $$[QT_INSTALL_EXAMPLES]/mvvmwidgets/$$TARGET +INSTALLS += target + +#not found by linker? +unix:!mac { + LIBS += -L$$OUT_PWD/../../../lib #required to make this the first place to search + LIBS += -L$$[QT_INSTALL_LIBS] -licudata + LIBS += -L$$[QT_INSTALL_LIBS] -licui18n + LIBS += -L$$[QT_INSTALL_LIBS] -licuuc +} + +#add lib dir to rpath +mac: QMAKE_LFLAGS += '-Wl,-rpath,\'$$OUT_PWD/../../../lib\'' + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../mvvmcore/SampleCore/release/ -lSampleCore +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../mvvmcore/SampleCore/debug/ -lSampleCore +else:unix: LIBS += -L$$OUT_PWD/../../mvvmcore/SampleCore/ -lSampleCore + +INCLUDEPATH += $$PWD/../../mvvmcore/SampleCore +DEPENDPATH += $$PWD/../../mvvmcore/SampleCore diff --git a/examples/mvvmwidgets/SampleWidgets/main.cpp b/examples/mvvmwidgets/SampleWidgets/main.cpp new file mode 100644 index 0000000..ee2cd6f --- /dev/null +++ b/examples/mvvmwidgets/SampleWidgets/main.cpp @@ -0,0 +1,9 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + return a.exec(); +} diff --git a/examples/mvvmwidgets/SampleWidgets/mainwindow.cpp b/examples/mvvmwidgets/SampleWidgets/mainwindow.cpp new file mode 100644 index 0000000..3137cb1 --- /dev/null +++ b/examples/mvvmwidgets/SampleWidgets/mainwindow.cpp @@ -0,0 +1,14 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + delete ui; +} diff --git a/examples/mvvmwidgets/SampleWidgets/mainwindow.h b/examples/mvvmwidgets/SampleWidgets/mainwindow.h new file mode 100644 index 0000000..8c7efd7 --- /dev/null +++ b/examples/mvvmwidgets/SampleWidgets/mainwindow.h @@ -0,0 +1,22 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/examples/mvvmwidgets/SampleWidgets/mainwindow.ui b/examples/mvvmwidgets/SampleWidgets/mainwindow.ui new file mode 100644 index 0000000..7ebf873 --- /dev/null +++ b/examples/mvvmwidgets/SampleWidgets/mainwindow.ui @@ -0,0 +1,21 @@ + + MainWindow + + + + 0 + 0 + 800 + 480 + + + + MainWindow + + + + + + + + diff --git a/examples/mvvmwidgets/mvvmwidgets.pro b/examples/mvvmwidgets/mvvmwidgets.pro new file mode 100644 index 0000000..ec249f6 --- /dev/null +++ b/examples/mvvmwidgets/mvvmwidgets.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + SampleWidgets diff --git a/src/mvvmcore/coreapp.cpp b/src/mvvmcore/coreapp.cpp new file mode 100644 index 0000000..1d62aac --- /dev/null +++ b/src/mvvmcore/coreapp.cpp @@ -0,0 +1,76 @@ +#include "coreapp.h" +#include "coreapp_p.h" + +#include + +#include + +using namespace QtMvvm; + +CoreApp::CoreApp(QObject *parent) : + QObject(parent), + d(new CoreAppPrivate()) +{} + +CoreApp::~CoreApp() {} + +CoreApp *CoreApp::instance() +{ + return CoreAppPrivate::instance; +} + +void CoreApp::disableAutoBoot() +{ + CoreAppPrivate::bootEnabled = false; +} + +void CoreApp::registerApp() +{ + //register metatypes + setParent(qApp); + CoreAppPrivate::instance = this; + if(CoreAppPrivate::bootEnabled) + QMetaObject::invokeMethod(this, "bootApp", Qt::QueuedConnection); +} + +void CoreApp::bootApp() +{ + auto res = startApp(QCoreApplication::arguments()); + if(res == EXIT_SUCCESS) { + connect(qApp, &QCoreApplication::aboutToQuit, + this, &CoreApp::closeApp); + } else + qApp->exit(res); +} + +void CoreApp::closeApp() {} + +bool CoreApp::autoParse(QCommandLineParser &parser, const QStringList &arguments) +{ + if(parser.parse(arguments)) { + if(parser.isSet(QStringLiteral("help"))) { + Q_UNIMPLEMENTED(); + return false; + } else if(parser.isSet(QStringLiteral("version"))) { + auto text = QGuiApplication::applicationDisplayName() + + QLatin1Char(' ') + + QCoreApplication::applicationVersion(); + Q_UNIMPLEMENTED(); + return false; + } else + return true; + } else { + Q_UNIMPLEMENTED(); + return false; + } +} + +// ------------- Private Implementation ------------- + +bool CoreAppPrivate::bootEnabled = true; +QPointer CoreAppPrivate::instance = nullptr; + +CoreAppPrivate::CoreAppPrivate() +{ + +} diff --git a/src/mvvmcore/coreapp.h b/src/mvvmcore/coreapp.h new file mode 100644 index 0000000..ac6b52e --- /dev/null +++ b/src/mvvmcore/coreapp.h @@ -0,0 +1,50 @@ +#ifndef QTMVVM_COREAPP_H +#define QTMVVM_COREAPP_H + +#include +#include +class QCommandLineParser; + +#include "QtMvvmCore/qtmvvmcore_global.h" + +namespace QtMvvm { + +class CoreAppPrivate; +class Q_MVVMCORE_EXPORT CoreApp : public QObject +{ + Q_OBJECT + +public: + explicit CoreApp(QObject *parent = nullptr); + ~CoreApp(); + + static CoreApp *instance(); + static void disableAutoBoot(); + + void registerApp(); + +public Q_SLOTS: + void bootApp(); + +protected: + virtual int startApp(const QStringList &arguments) = 0; + virtual void closeApp(); + + bool autoParse(QCommandLineParser &parser, const QStringList &arguments); + +private: + QScopedPointer d; +}; + +} + +#define QTMVVM_REGISTER_CORE_APP(T) \ + static void _setup_ ## T ## _hook() { \ + auto app = new T(nullptr); \ + app->registerApp(); \ + } \ + Q_COREAPP_STARTUP_FUNCTION(_setup_ ## T ## _hook) + +#define coreApp CoreApp::instance() + +#endif // QTMVVM_COREAPP_H diff --git a/src/mvvmcore/coreapp_p.h b/src/mvvmcore/coreapp_p.h new file mode 100644 index 0000000..0854965 --- /dev/null +++ b/src/mvvmcore/coreapp_p.h @@ -0,0 +1,22 @@ +#ifndef QTMVVM_COREAPP_P_H +#define QTMVVM_COREAPP_P_H + +#include + +#include "qtmvvmcore_global.h" +#include "coreapp.h" + +namespace QtMvvm { + +class CoreAppPrivate +{ +public: + CoreAppPrivate(); + + static bool bootEnabled; + static QPointer instance; +}; + +} + +#endif // QTMVVM_COREAPP_P_H diff --git a/src/mvvmcore/mvvmcore.pro b/src/mvvmcore/mvvmcore.pro index 84a843d..08d841a 100644 --- a/src/mvvmcore/mvvmcore.pro +++ b/src/mvvmcore/mvvmcore.pro @@ -1,11 +1,17 @@ TARGET = QtMvvmCore -QT = core +QT = core gui HEADERS += \ - qt_mvvmcore_global.h - -SOURCES += + viewmodel.h \ + qtmvvmcore_global.h \ + viewmodel_p.h \ + coreapp.h \ + coreapp_p.h + +SOURCES += \ + viewmodel.cpp \ + coreapp.cpp TRANSLATIONS += \ translations/qtmvvmcore_de.ts \ diff --git a/src/mvvmcore/qt_mvvmcore_global.h b/src/mvvmcore/qtmvvmcore_global.h similarity index 100% rename from src/mvvmcore/qt_mvvmcore_global.h rename to src/mvvmcore/qtmvvmcore_global.h diff --git a/src/mvvmcore/viewmodel.cpp b/src/mvvmcore/viewmodel.cpp new file mode 100644 index 0000000..cd4bcbf --- /dev/null +++ b/src/mvvmcore/viewmodel.cpp @@ -0,0 +1,43 @@ +#include "viewmodel.h" +#include "viewmodel_p.h" +using namespace QtMvvm; + +ViewModel::ViewModel(QObject *parent) : + QObject(parent), + d(new ViewModelPrivate()) +{} + +ViewModel::~ViewModel() {} + +ViewModel *ViewModel::parentViewModel() const +{ + return qobject_cast(parent()); +} + +bool ViewModel::deleteOnClose() const +{ + return d->deleteOnClose; +} + +void ViewModel::setDeleteOnClose(bool deleteOnClose) +{ + if (d->deleteOnClose == deleteOnClose) + return; + + d->deleteOnClose = deleteOnClose; + emit deleteOnCloseChanged(deleteOnClose, {}); +} + +void ViewModel::onInit() {} + +void ViewModel::onDestroy() {} + +void ViewModel::onShow() {} + +void ViewModel::onClose() {} + +// ------------- Private Implementation ------------- + +ViewModelPrivate::ViewModelPrivate() : + deleteOnClose(true) +{} diff --git a/src/mvvmcore/viewmodel.h b/src/mvvmcore/viewmodel.h new file mode 100644 index 0000000..80814ed --- /dev/null +++ b/src/mvvmcore/viewmodel.h @@ -0,0 +1,44 @@ +#ifndef QTMVVM_VIEWMODEL_H +#define QTMVVM_VIEWMODEL_H + +#include +#include + +#include "QtMvvmCore/qtmvvmcore_global.h" + +namespace QtMvvm { + +class ViewModelPrivate; +class Q_MVVMCORE_EXPORT ViewModel : public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool deleteOnClose READ deleteOnClose WRITE setDeleteOnClose NOTIFY deleteOnCloseChanged) + +public: + explicit ViewModel(QObject *parent = nullptr); + ~ViewModel(); + + virtual ViewModel *parentViewModel() const; + + bool deleteOnClose() const; + +public Q_SLOTS: + void setDeleteOnClose(bool deleteOnClose); + +Q_SIGNALS: + void deleteOnCloseChanged(bool deleteOnClose, QPrivateSignal); + +protected: + virtual void onInit(); + virtual void onDestroy(); + virtual void onShow(); + virtual void onClose(); + +private: + QScopedPointer d; +}; + +} + +#endif // QTMVVM_VIEWMODEL_H diff --git a/src/mvvmcore/viewmodel_p.h b/src/mvvmcore/viewmodel_p.h new file mode 100644 index 0000000..943eb6c --- /dev/null +++ b/src/mvvmcore/viewmodel_p.h @@ -0,0 +1,19 @@ +#ifndef QTMVVM_VIEWMODEL_P_H +#define QTMVVM_VIEWMODEL_P_H + +#include "qtmvvmcore_global.h" +#include "viewmodel.h" + +namespace QtMvvm { + +class ViewModelPrivate +{ +public: + ViewModelPrivate(); + + bool deleteOnClose; +}; + +} + +#endif // QTMVVM_VIEWMODEL_P_H diff --git a/src/mvvmquick/mvvmquick.pro b/src/mvvmquick/mvvmquick.pro index 56d88c6..cf6b92f 100644 --- a/src/mvvmquick/mvvmquick.pro +++ b/src/mvvmquick/mvvmquick.pro @@ -3,7 +3,7 @@ TARGET = QtMvvmQuick QT = core gui widgets mvvmcore HEADERS += \ - qt_mvvmquick_global.h + qtmvvmquick_global.h SOURCES += diff --git a/src/mvvmquick/qtmvvmquick_global.h b/src/mvvmquick/qtmvvmquick_global.h new file mode 100644 index 0000000..09f6de6 --- /dev/null +++ b/src/mvvmquick/qtmvvmquick_global.h @@ -0,0 +1,12 @@ +#ifndef QTMVVMQUICK_GLOBAL_H +#define QTMVVMQUICK_GLOBAL_H + +#include + +#if defined(QT_BUILD_MVVM_LIB) +# define Q_MVVMQUICK_EXPORT Q_DECL_EXPORT +#else +# define Q_MVVMQUICK_EXPORT Q_DECL_IMPORT +#endif + +#endif // QTMVVMQUICK_GLOBAL_H diff --git a/src/mvvmwidgets/mvvmwidgets.pro b/src/mvvmwidgets/mvvmwidgets.pro index f74f368..8d7fd21 100644 --- a/src/mvvmwidgets/mvvmwidgets.pro +++ b/src/mvvmwidgets/mvvmwidgets.pro @@ -3,7 +3,7 @@ TARGET = QtMvvmWidgets QT = core gui widgets mvvmcore HEADERS += \ - qt_mvvmwidgets_global.h + qtmvvmwidgets_global.h SOURCES += diff --git a/src/mvvmwidgets/qt_mvvmwidgets_global.h b/src/mvvmwidgets/qt_mvvmwidgets_global.h deleted file mode 100644 index 0938a3c..0000000 --- a/src/mvvmwidgets/qt_mvvmwidgets_global.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef QTMVVMWIDGETS_GLOBAL_H -#define QTMVVMWIDGETS_GLOBAL_H - -#include - -#if defined(QT_BUILD_MVVM_LIB) -# define Q_MVVMWIDGETS_EXPORT Q_DECL_EXPORT -#else -# define Q_MVVMWIDGETS_EXPORT Q_DECL_IMPORT -#endif - -#endif // QTMVVMWIDGETS_GLOBAL_H diff --git a/src/mvvmquick/qt_mvvmquick_global.h b/src/mvvmwidgets/qtmvvmwidgets_global.h similarity index 100% rename from src/mvvmquick/qt_mvvmquick_global.h rename to src/mvvmwidgets/qtmvvmwidgets_global.h