Skycoder42
7 years ago
26 changed files with 475 additions and 19 deletions
@ -1,3 +1,4 @@ |
|||
TEMPLATE = subdirs |
|||
|
|||
SUBDIRS = mvvmcore |
|||
SUBDIRS = mvvmcore \ |
|||
mvvmwidgets |
|||
|
@ -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\'' |
@ -0,0 +1,12 @@ |
|||
#ifndef SAMPLECORE_GLOBAL_H |
|||
#define SAMPLECORE_GLOBAL_H |
|||
|
|||
#include <QtCore/qglobal.h> |
|||
|
|||
#if defined(SAMPLECORE_LIBRARY) |
|||
# define SAMPLECORESHARED_EXPORT Q_DECL_EXPORT |
|||
#else |
|||
# define SAMPLECORESHARED_EXPORT Q_DECL_IMPORT |
|||
#endif |
|||
|
|||
#endif // SAMPLECORE_GLOBAL_H
|
@ -0,0 +1,27 @@ |
|||
#include "samplecoreapp.h" |
|||
|
|||
#include <QtCore/QCommandLineParser> |
|||
|
|||
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; |
|||
} |
@ -0,0 +1,19 @@ |
|||
#ifndef SAMPLECOREAPP_H |
|||
#define SAMPLECOREAPP_H |
|||
|
|||
#include <QtMvvmCore/CoreApp> |
|||
|
|||
#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
|
@ -1,2 +1,5 @@ |
|||
TEMPLATE = subdirs |
|||
QT_FOR_CONFIG += core |
|||
|
|||
SUBDIRS += \ |
|||
SampleCore |
|||
|
@ -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 |
@ -0,0 +1,9 @@ |
|||
#include "mainwindow.h" |
|||
#include <QApplication> |
|||
|
|||
int main(int argc, char *argv[]) |
|||
{ |
|||
QApplication a(argc, argv); |
|||
|
|||
return a.exec(); |
|||
} |
@ -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; |
|||
} |
@ -0,0 +1,22 @@ |
|||
#ifndef MAINWINDOW_H |
|||
#define MAINWINDOW_H |
|||
|
|||
#include <QMainWindow> |
|||
|
|||
namespace Ui { |
|||
class MainWindow; |
|||
} |
|||
|
|||
class MainWindow : public QMainWindow |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
explicit MainWindow(QWidget *parent = 0); |
|||
~MainWindow(); |
|||
|
|||
private: |
|||
Ui::MainWindow *ui; |
|||
}; |
|||
|
|||
#endif // MAINWINDOW_H
|
@ -0,0 +1,21 @@ |
|||
<ui version="4.0"> |
|||
<class>MainWindow</class> |
|||
<widget class="QMainWindow" name="MainWindow" > |
|||
<property name="geometry" > |
|||
<rect> |
|||
<x>0</x> |
|||
<y>0</y> |
|||
<width>800</width> |
|||
<height>480</height> |
|||
</rect> |
|||
</property> |
|||
<property name="windowTitle" > |
|||
<string>MainWindow</string> |
|||
</property> |
|||
<widget class="QWidget" name="centralWidget" /> |
|||
</widget> |
|||
<layoutDefault spacing="6" margin="11" /> |
|||
<pixmapfunction></pixmapfunction> |
|||
<resources/> |
|||
<connections/> |
|||
</ui> |
@ -0,0 +1,4 @@ |
|||
TEMPLATE = subdirs |
|||
|
|||
SUBDIRS += \ |
|||
SampleWidgets |
@ -0,0 +1,76 @@ |
|||
#include "coreapp.h" |
|||
#include "coreapp_p.h" |
|||
|
|||
#include <QtCore/QCommandLineParser> |
|||
|
|||
#include <QtGui/QGuiApplication> |
|||
|
|||
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<CoreApp> CoreAppPrivate::instance = nullptr; |
|||
|
|||
CoreAppPrivate::CoreAppPrivate() |
|||
{ |
|||
|
|||
} |
@ -0,0 +1,50 @@ |
|||
#ifndef QTMVVM_COREAPP_H |
|||
#define QTMVVM_COREAPP_H |
|||
|
|||
#include <QtCore/qobject.h> |
|||
#include <QtCore/qscopedpointer.h> |
|||
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<CoreAppPrivate> 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
|
@ -0,0 +1,22 @@ |
|||
#ifndef QTMVVM_COREAPP_P_H |
|||
#define QTMVVM_COREAPP_P_H |
|||
|
|||
#include <QtCore/QPointer> |
|||
|
|||
#include "qtmvvmcore_global.h" |
|||
#include "coreapp.h" |
|||
|
|||
namespace QtMvvm { |
|||
|
|||
class CoreAppPrivate |
|||
{ |
|||
public: |
|||
CoreAppPrivate(); |
|||
|
|||
static bool bootEnabled; |
|||
static QPointer<CoreApp> instance; |
|||
}; |
|||
|
|||
} |
|||
|
|||
#endif // QTMVVM_COREAPP_P_H
|
@ -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<ViewModel*>(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) |
|||
{} |
@ -0,0 +1,44 @@ |
|||
#ifndef QTMVVM_VIEWMODEL_H |
|||
#define QTMVVM_VIEWMODEL_H |
|||
|
|||
#include <QtCore/qobject.h> |
|||
#include <QtCore/qscopedpointer.h> |
|||
|
|||
#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<ViewModelPrivate> d; |
|||
}; |
|||
|
|||
} |
|||
|
|||
#endif // QTMVVM_VIEWMODEL_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
|
@ -0,0 +1,12 @@ |
|||
#ifndef QTMVVMQUICK_GLOBAL_H |
|||
#define QTMVVMQUICK_GLOBAL_H |
|||
|
|||
#include <QtCore/qglobal.h> |
|||
|
|||
#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
|
@ -1,12 +0,0 @@ |
|||
#ifndef QTMVVMWIDGETS_GLOBAL_H |
|||
#define QTMVVMWIDGETS_GLOBAL_H |
|||
|
|||
#include <QtCore/qglobal.h> |
|||
|
|||
#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
|
Loading…
Reference in new issue