Browse Source

added basic sample setup for widgets

pull/2/head
Skycoder42 7 years ago
parent
commit
be56a15c4a
  1. 0
      doc/makedoc.sh
  2. 3
      examples/examples.pro
  3. 28
      examples/mvvmcore/SampleCore/SampleCore.pro
  4. 12
      examples/mvvmcore/SampleCore/samplecore_global.h
  5. 27
      examples/mvvmcore/SampleCore/samplecoreapp.cpp
  6. 19
      examples/mvvmcore/SampleCore/samplecoreapp.h
  7. 3
      examples/mvvmcore/mvvmcore.pro
  8. 36
      examples/mvvmwidgets/SampleWidgets/SampleWidgets.pro
  9. 9
      examples/mvvmwidgets/SampleWidgets/main.cpp
  10. 14
      examples/mvvmwidgets/SampleWidgets/mainwindow.cpp
  11. 22
      examples/mvvmwidgets/SampleWidgets/mainwindow.h
  12. 21
      examples/mvvmwidgets/SampleWidgets/mainwindow.ui
  13. 4
      examples/mvvmwidgets/mvvmwidgets.pro
  14. 76
      src/mvvmcore/coreapp.cpp
  15. 50
      src/mvvmcore/coreapp.h
  16. 22
      src/mvvmcore/coreapp_p.h
  17. 14
      src/mvvmcore/mvvmcore.pro
  18. 0
      src/mvvmcore/qtmvvmcore_global.h
  19. 43
      src/mvvmcore/viewmodel.cpp
  20. 44
      src/mvvmcore/viewmodel.h
  21. 19
      src/mvvmcore/viewmodel_p.h
  22. 2
      src/mvvmquick/mvvmquick.pro
  23. 12
      src/mvvmquick/qtmvvmquick_global.h
  24. 2
      src/mvvmwidgets/mvvmwidgets.pro
  25. 12
      src/mvvmwidgets/qt_mvvmwidgets_global.h
  26. 0
      src/mvvmwidgets/qtmvvmwidgets_global.h

0
doc/makedoc.sh

3
examples/examples.pro

@ -1,3 +1,4 @@
TEMPLATE = subdirs
SUBDIRS = mvvmcore
SUBDIRS = mvvmcore \
mvvmwidgets

28
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\''

12
examples/mvvmcore/SampleCore/samplecore_global.h

@ -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

27
examples/mvvmcore/SampleCore/samplecoreapp.cpp

@ -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;
}

19
examples/mvvmcore/SampleCore/samplecoreapp.h

@ -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

3
examples/mvvmcore/mvvmcore.pro

@ -1,2 +1,5 @@
TEMPLATE = subdirs
QT_FOR_CONFIG += core
SUBDIRS += \
SampleCore

36
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

9
examples/mvvmwidgets/SampleWidgets/main.cpp

@ -0,0 +1,9 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
return a.exec();
}

14
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;
}

22
examples/mvvmwidgets/SampleWidgets/mainwindow.h

@ -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

21
examples/mvvmwidgets/SampleWidgets/mainwindow.ui

@ -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>

4
examples/mvvmwidgets/mvvmwidgets.pro

@ -0,0 +1,4 @@
TEMPLATE = subdirs
SUBDIRS += \
SampleWidgets

76
src/mvvmcore/coreapp.cpp

@ -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()
{
}

50
src/mvvmcore/coreapp.h

@ -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

22
src/mvvmcore/coreapp_p.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

14
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 \

0
src/mvvmcore/qt_mvvmcore_global.h → src/mvvmcore/qtmvvmcore_global.h

43
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<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)
{}

44
src/mvvmcore/viewmodel.h

@ -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

19
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

2
src/mvvmquick/mvvmquick.pro

@ -3,7 +3,7 @@ TARGET = QtMvvmQuick
QT = core gui widgets mvvmcore
HEADERS += \
qt_mvvmquick_global.h
qtmvvmquick_global.h
SOURCES +=

12
src/mvvmquick/qtmvvmquick_global.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

2
src/mvvmwidgets/mvvmwidgets.pro

@ -3,7 +3,7 @@ TARGET = QtMvvmWidgets
QT = core gui widgets mvvmcore
HEADERS += \
qt_mvvmwidgets_global.h
qtmvvmwidgets_global.h
SOURCES +=

12
src/mvvmwidgets/qt_mvvmwidgets_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

0
src/mvvmquick/qt_mvvmquick_global.h → src/mvvmwidgets/qtmvvmwidgets_global.h

Loading…
Cancel
Save