27 changed files with 549 additions and 5 deletions
@ -0,0 +1,19 @@ |
|||
TEMPLATE = lib |
|||
|
|||
QT = core gui mvvmcore mvvmdatasynccore |
|||
CONFIG += static |
|||
|
|||
TARGET = DataSyncSampleCore |
|||
|
|||
HEADERS += \ |
|||
samplecoreapp.h \ |
|||
sampleviewmodel.h \ |
|||
sampledata.h |
|||
|
|||
SOURCES += \ |
|||
samplecoreapp.cpp \ |
|||
sampleviewmodel.cpp \ |
|||
sampledata.cpp |
|||
|
|||
target.path = $$[QT_INSTALL_EXAMPLES]/mvvmdatasynccore/$$TARGET |
|||
INSTALLS += target |
@ -0,0 +1,36 @@ |
|||
#include "samplecoreapp.h" |
|||
#include "sampleviewmodel.h" |
|||
#include <QtCore/QDebug> |
|||
#include <QtCore/QLoggingCategory> |
|||
#include <QtMvvmCore/QtMvvmCoreVersion> |
|||
#include <QtDataSync/Setup> |
|||
|
|||
SampleCoreApp::SampleCoreApp(QObject *parent) : |
|||
CoreApp(parent) |
|||
{ |
|||
QCoreApplication::setApplicationName(QStringLiteral("QtMvvmDataSyncSample")); |
|||
QCoreApplication::setApplicationVersion(QStringLiteral(QTMVVMCORE_VERSION_STR)); |
|||
QCoreApplication::setOrganizationName(QStringLiteral("Skycoder42")); |
|||
} |
|||
|
|||
void SampleCoreApp::performRegistrations() |
|||
{ |
|||
qRegisterMetaType<SampleData>(); |
|||
QLoggingCategory::setFilterRules(QStringLiteral("qtmvvm.debug=true")); |
|||
} |
|||
|
|||
int SampleCoreApp::startApp(const QStringList &arguments) |
|||
{ |
|||
auto setup = QtDataSync::DefaultSetup; |
|||
if(arguments.size() > 1) |
|||
setup = arguments.value(1); |
|||
|
|||
try { |
|||
QtDataSync::Setup().create(setup); |
|||
show<SampleViewModel>(); |
|||
return EXIT_SUCCESS; |
|||
} catch (QException &e) { |
|||
qCritical() << e.what(); |
|||
return EXIT_FAILURE; |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
#ifndef SAMPLECOREAPP_H |
|||
#define SAMPLECOREAPP_H |
|||
|
|||
#include <QtMvvmCore/CoreApp> |
|||
|
|||
class SampleCoreApp : public QtMvvm::CoreApp |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
SampleCoreApp(QObject *parent = nullptr); |
|||
|
|||
protected: |
|||
void performRegistrations() override; |
|||
int startApp(const QStringList &arguments) override; |
|||
}; |
|||
|
|||
#undef coreApp |
|||
#define coreApp static_cast<SampleCoreApp*>(QtMvvm::CoreApp::instance()) |
|||
|
|||
#endif // SAMPLECOREAPP_H
|
@ -0,0 +1 @@ |
|||
#include "sampledata.h" |
@ -0,0 +1,18 @@ |
|||
#ifndef SAMPLEDATA_H |
|||
#define SAMPLEDATA_H |
|||
|
|||
#include <QtCore/QObject> |
|||
|
|||
class SampleData |
|||
{ |
|||
Q_GADGET |
|||
|
|||
Q_PROPERTY(QString key MEMBER key USER true) |
|||
|
|||
public: |
|||
QString key; |
|||
}; |
|||
|
|||
Q_DECLARE_METATYPE(SampleData) |
|||
|
|||
#endif // SAMPLEDATA_H
|
@ -0,0 +1,32 @@ |
|||
#include "sampleviewmodel.h" |
|||
#include <QtCore/QDebug> |
|||
#include <QtMvvmDataSyncCore/DataSyncViewModel> |
|||
|
|||
SampleViewModel::SampleViewModel(QObject *parent) : |
|||
ViewModel(parent), |
|||
_model(new QtDataSync::DataStoreModel(this)) |
|||
{ |
|||
_model->setTypeId<SampleData>(); |
|||
} |
|||
|
|||
QtDataSync::DataStoreModel *SampleViewModel::model() const |
|||
{ |
|||
return _model; |
|||
} |
|||
|
|||
void SampleViewModel::addData(const QString &key) |
|||
{ |
|||
_model->store()->save<SampleData>({key}); |
|||
} |
|||
|
|||
void SampleViewModel::removeAt(int index) |
|||
{ |
|||
auto mIndex = _model->index(index); |
|||
if(mIndex.isValid()) |
|||
_model->store()->remove<SampleData>(_model->object<SampleData>(mIndex).key); |
|||
} |
|||
|
|||
void SampleViewModel::showSyncInfo() |
|||
{ |
|||
show<QtMvvm::DataSyncViewModel>(); |
|||
} |
@ -0,0 +1,33 @@ |
|||
#ifndef SAMPLEVIEWMODEL_H |
|||
#define SAMPLEVIEWMODEL_H |
|||
|
|||
#include <QtCore/QStringListModel> |
|||
|
|||
#include <QtMvvmCore/ViewModel> |
|||
|
|||
#include <QtDataSync/DataStoreModel> |
|||
|
|||
#include "sampledata.h" |
|||
|
|||
class SampleViewModel : public QtMvvm::ViewModel |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
Q_PROPERTY(QtDataSync::DataStoreModel* model READ model CONSTANT) |
|||
|
|||
public: |
|||
Q_INVOKABLE explicit SampleViewModel(QObject *parent = nullptr); |
|||
|
|||
QtDataSync::DataStoreModel* model() const; |
|||
|
|||
public Q_SLOTS: |
|||
void addData(const QString &key); |
|||
void removeAt(int index); |
|||
|
|||
void showSyncInfo(); |
|||
|
|||
private: |
|||
QtDataSync::DataStoreModel *_model; |
|||
}; |
|||
|
|||
#endif // SAMPLEVIEWMODEL_H
|
@ -0,0 +1,5 @@ |
|||
TEMPLATE = subdirs |
|||
QT_FOR_CONFIG += core |
|||
|
|||
SUBDIRS += \ |
|||
DataSyncSampleCore |
@ -0,0 +1,43 @@ |
|||
TEMPLATE = app |
|||
|
|||
QT += core gui widgets mvvmwidgets mvvmdatasyncwidgets |
|||
|
|||
TARGET = DataSyncSampleWidgets |
|||
|
|||
HEADERS += \ |
|||
samplewindow.h |
|||
|
|||
SOURCES += \ |
|||
main.cpp \ |
|||
samplewindow.cpp |
|||
|
|||
FORMS += \ |
|||
samplewindow.ui |
|||
|
|||
target.path = $$[QT_INSTALL_EXAMPLES]/mvvmdatasyncwidgets/$$TARGET |
|||
INSTALLS += target |
|||
|
|||
#not found by linker? |
|||
linux:!android { |
|||
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\'' |
|||
|
|||
#link to core lib |
|||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../mvvmdatasynccore/DataSyncSampleCore/release/ -lDataSyncSampleCore |
|||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../mvvmdatasynccore/DataSyncSampleCore/debug/ -lDataSyncSampleCore |
|||
else:unix: LIBS += -L$$OUT_PWD/../../mvvmdatasynccore/DataSyncSampleCore/ -lDataSyncSampleCore |
|||
|
|||
INCLUDEPATH += $$PWD/../../mvvmdatasynccore/DataSyncSampleCore |
|||
DEPENDPATH += $$PWD/../../mvvmdatasynccore/DataSyncSampleCore |
|||
|
|||
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../mvvmdatasynccore/DataSyncSampleCore/release/libDataSyncSampleCore.a |
|||
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../mvvmdatasynccore/DataSyncSampleCore/debug/libDataSyncSampleCore.a |
|||
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../mvvmdatasynccore/DataSyncSampleCore/release/DataSyncSampleCore.lib |
|||
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../mvvmdatasynccore/DataSyncSampleCore/debug/DataSyncSampleCore.lib |
|||
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../../mvvmdatasynccore/DataSyncSampleCore/libDataSyncSampleCore.a |
@ -0,0 +1,18 @@ |
|||
#include <QtWidgets/QApplication> |
|||
#include <QtMvvmWidgets/WidgetsPresenter> |
|||
#include <samplecoreapp.h> |
|||
#include <QtMvvmDataSyncWidgets/qtmvvmdatasyncwidgets_global.h> |
|||
|
|||
#include "samplewindow.h" |
|||
|
|||
QTMVVM_REGISTER_CORE_APP(SampleCoreApp) |
|||
|
|||
int main(int argc, char *argv[]) |
|||
{ |
|||
QApplication a(argc, argv); |
|||
|
|||
QtMvvm::registerDataSyncWidgets(); |
|||
QtMvvm::WidgetsPresenter::registerView<SampleWindow>(); |
|||
|
|||
return a.exec(); |
|||
} |
@ -0,0 +1,29 @@ |
|||
#include "samplewindow.h" |
|||
#include "ui_samplewindow.h" |
|||
|
|||
SampleWindow::SampleWindow(QtMvvm::ViewModel *viewModel, QWidget *parent) : |
|||
QMainWindow(parent), |
|||
_viewModel(static_cast<SampleViewModel*>(viewModel)), |
|||
ui(new Ui::SampleWindow) |
|||
{ |
|||
ui->setupUi(this); |
|||
|
|||
ui->listView->setModel(_viewModel->model()); |
|||
connect(ui->syncButton, &QPushButton::clicked, |
|||
_viewModel, &SampleViewModel::showSyncInfo); |
|||
} |
|||
|
|||
SampleWindow::~SampleWindow() |
|||
{ |
|||
delete ui; |
|||
} |
|||
|
|||
void SampleWindow::on_addButton_clicked() |
|||
{ |
|||
_viewModel->addData(ui->keyEdit->text()); |
|||
} |
|||
|
|||
void SampleWindow::on_removeButton_clicked() |
|||
{ |
|||
_viewModel->removeAt(ui->listView->currentIndex().row()); |
|||
} |
@ -0,0 +1,28 @@ |
|||
#ifndef SAMPLEWINDOW_H |
|||
#define SAMPLEWINDOW_H |
|||
|
|||
#include <QtWidgets/QMainWindow> |
|||
#include <sampleviewmodel.h> |
|||
|
|||
namespace Ui { |
|||
class SampleWindow; |
|||
} |
|||
|
|||
class SampleWindow : public QMainWindow |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
Q_INVOKABLE explicit SampleWindow(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr); |
|||
~SampleWindow(); |
|||
|
|||
private Q_SLOTS: |
|||
void on_addButton_clicked(); |
|||
void on_removeButton_clicked(); |
|||
|
|||
private: |
|||
SampleViewModel *_viewModel; |
|||
Ui::SampleWindow *ui; |
|||
}; |
|||
|
|||
#endif // SAMPLEWINDOW_H
|
@ -0,0 +1,73 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<ui version="4.0"> |
|||
<class>SampleWindow</class> |
|||
<widget class="QMainWindow" name="SampleWindow"> |
|||
<property name="geometry"> |
|||
<rect> |
|||
<x>0</x> |
|||
<y>0</y> |
|||
<width>479</width> |
|||
<height>329</height> |
|||
</rect> |
|||
</property> |
|||
<property name="windowTitle"> |
|||
<string>SampleWindow</string> |
|||
</property> |
|||
<widget class="QWidget" name="centralWidget"> |
|||
<layout class="QVBoxLayout" name="verticalLayout"> |
|||
<item> |
|||
<widget class="QListView" name="listView"/> |
|||
</item> |
|||
<item> |
|||
<layout class="QHBoxLayout" name="horizontalLayout"> |
|||
<item> |
|||
<widget class="QLineEdit" name="keyEdit"> |
|||
<property name="placeholderText"> |
|||
<string>Key</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<widget class="QPushButton" name="addButton"> |
|||
<property name="text"> |
|||
<string>Add</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<widget class="Line" name="line"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Vertical</enum> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<widget class="QPushButton" name="removeButton"> |
|||
<property name="text"> |
|||
<string>Remove</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<widget class="Line" name="line_2"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Vertical</enum> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<widget class="QPushButton" name="syncButton"> |
|||
<property name="text"> |
|||
<string>Sync Status</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
</layout> |
|||
</item> |
|||
</layout> |
|||
</widget> |
|||
</widget> |
|||
<layoutdefault spacing="6" margin="11"/> |
|||
<resources/> |
|||
<connections/> |
|||
</ui> |
@ -0,0 +1,5 @@ |
|||
TEMPLATE = subdirs |
|||
QT_FOR_CONFIG += widgets |
|||
|
|||
SUBDIRS += \ |
|||
DataSyncSampleWidgets |
@ -0,0 +1,20 @@ |
|||
#include "datasyncwindow.h" |
|||
#include "datasyncwindow_p.h" |
|||
#include "ui_datasyncwindow.h" |
|||
using namespace QtMvvm; |
|||
|
|||
DataSyncWindow::DataSyncWindow(QtMvvm::ViewModel *viewModel, QWidget *parent) : |
|||
QWidget(parent, Qt::Window), |
|||
d(new DataSyncWindowPrivate(this, viewModel)) |
|||
{ |
|||
d->ui->setupUi(this); |
|||
} |
|||
|
|||
DataSyncWindow::~DataSyncWindow() {} |
|||
|
|||
// ------------- Private Implementation -------------
|
|||
|
|||
DataSyncWindowPrivate::DataSyncWindowPrivate(DataSyncWindow *q_ptr, ViewModel *viewModel) : |
|||
viewModel(static_cast<DataSyncViewModel*>(viewModel)), |
|||
ui(new Ui::DataSyncWindow()) |
|||
{} |
@ -0,0 +1,29 @@ |
|||
#ifndef QTMVVM_DATASYNCWINDOW_H |
|||
#define QTMVVM_DATASYNCWINDOW_H |
|||
|
|||
#include <QtCore/QScopedPointer> |
|||
|
|||
#include <QtWidgets/QWidget> |
|||
|
|||
#include <QtMvvmDataSyncCore/DataSyncViewModel> |
|||
|
|||
#include "QtMvvmDataSyncWidgets/qtmvvmdatasyncwidgets_global.h" |
|||
|
|||
namespace QtMvvm { |
|||
|
|||
class DataSyncWindowPrivate; |
|||
class Q_MVVMDATASYNCWIDGETS_EXPORT DataSyncWindow : public QWidget |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
Q_INVOKABLE explicit DataSyncWindow(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr); |
|||
~DataSyncWindow(); |
|||
|
|||
private: |
|||
QScopedPointer<DataSyncWindowPrivate> d; |
|||
}; |
|||
|
|||
} |
|||
|
|||
#endif // QTMVVM_DATASYNCWINDOW_H
|
@ -0,0 +1,21 @@ |
|||
<ui version="4.0"> |
|||
<author/> |
|||
<comment/> |
|||
<exportmacro/> |
|||
<class>DataSyncWindow</class> |
|||
<widget name="DataSyncWindow" class="QWidget"> |
|||
<property name="geometry"> |
|||
<rect> |
|||
<x>0</x> |
|||
<y>0</y> |
|||
<width>400</width> |
|||
<height>300</height> |
|||
</rect> |
|||
</property> |
|||
<property name="windowTitle"> |
|||
<string>Form</string> |
|||
</property> |
|||
</widget> |
|||
<pixmapfunction/> |
|||
<connections/> |
|||
</ui> |
@ -0,0 +1,24 @@ |
|||
#ifndef QTMVVM_DATASYNCWINDOW_P_H |
|||
#define QTMVVM_DATASYNCWINDOW_P_H |
|||
|
|||
#include "qtmvvmdatasyncwidgets_global.h" |
|||
#include "datasyncwindow.h" |
|||
|
|||
namespace Ui { |
|||
class DataSyncWindow; |
|||
} |
|||
|
|||
namespace QtMvvm { |
|||
|
|||
class DataSyncWindowPrivate |
|||
{ |
|||
public: |
|||
DataSyncWindowPrivate(DataSyncWindow *q_ptr, ViewModel *viewModel); |
|||
|
|||
DataSyncViewModel *viewModel; |
|||
QScopedPointer<Ui::DataSyncWindow> ui; |
|||
}; |
|||
|
|||
} |
|||
|
|||
#endif // QTMVVM_DATASYNCWINDOW_P_H
|
@ -0,0 +1,41 @@ |
|||
TARGET = QtMvvmDataSyncWidgets |
|||
|
|||
QT = core gui mvvmdatasynccore mvvmwidgets |
|||
|
|||
HEADERS += \ |
|||
qtmvvmdatasyncwidgets_global.h \ |
|||
datasyncwindow.h \ |
|||
datasyncwindow_p.h |
|||
|
|||
SOURCES += \ |
|||
datasyncwindow.cpp \ |
|||
qtmvvmdatasyncwidgets_global.cpp |
|||
|
|||
TRANSLATIONS += \ |
|||
translations/qtmvvmdatasyncwidgets_de.ts \ |
|||
translations/qtmvvmdatasyncwidgets_template.ts |
|||
|
|||
DISTFILES += $$TRANSLATIONS |
|||
|
|||
qpmx_ts_target.path = $$[QT_INSTALL_TRANSLATIONS] |
|||
qpmx_ts_target.depends += lrelease |
|||
|
|||
load(qt_module) |
|||
|
|||
win32 { |
|||
QMAKE_TARGET_PRODUCT = "$$TARGET" |
|||
QMAKE_TARGET_COMPANY = "Skycoder42" |
|||
QMAKE_TARGET_COPYRIGHT = "Felix Barz" |
|||
} else:mac { |
|||
QMAKE_TARGET_BUNDLE_PREFIX = "com.skycoder42." |
|||
} |
|||
|
|||
!ReleaseBuild:!DebugBuild:!system(qpmx -d $$shell_quote($$_PRO_FILE_PWD_) --qmake-run init $$QPMX_EXTRA_OPTIONS $$shell_quote($$QMAKE_QMAKE) $$shell_quote($$OUT_PWD)): error(qpmx initialization failed. Check the compilation log for details.) |
|||
else: include($$OUT_PWD/qpmx_generated.pri) |
|||
|
|||
qpmx_ts_target.files -= $$OUT_PWD/$$QPMX_WORKINGDIR/qtmvvmdatasyncwidgets_template.qm |
|||
qpmx_ts_target.files += translations/qtmvvmdatasyncwidgets_template.ts |
|||
|
|||
FORMS += \ |
|||
datasyncwindow.ui |
|||
|
@ -0,0 +1,14 @@ |
|||
{ |
|||
"dependencies": [], |
|||
"license": { |
|||
"file": "", |
|||
"name": "" |
|||
}, |
|||
"prcFile": "", |
|||
"priFile": "", |
|||
"priIncludes": [ |
|||
], |
|||
"publishers": { |
|||
}, |
|||
"source": false |
|||
} |
@ -0,0 +1,9 @@ |
|||
#include "qtmvvmdatasyncwidgets_global.h" |
|||
#include <QtMvvmWidgets/WidgetsPresenter> |
|||
|
|||
#include "datasyncwindow.h" |
|||
|
|||
void QtMvvm::registerDataSyncWidgets() |
|||
{ |
|||
QtMvvm::WidgetsPresenter::registerView<DataSyncWindow>(); |
|||
} |
@ -0,0 +1,18 @@ |
|||
#ifndef MVVMDATASYNCWIDGETS_GLOBAL_H |
|||
#define MVVMDATASYNCWIDGETS_GLOBAL_H |
|||
|
|||
#include <QtCore/qglobal.h> |
|||
|
|||
#if defined(QT_BUILD_MVVMDATASYNCWIDGETS_LIB) |
|||
# define Q_MVVMDATASYNCWIDGETS_EXPORT Q_DECL_EXPORT |
|||
#else |
|||
# define Q_MVVMDATASYNCWIDGETS_EXPORT Q_DECL_IMPORT |
|||
#endif |
|||
|
|||
namespace QtMvvm { |
|||
|
|||
Q_MVVMDATASYNCWIDGETS_EXPORT void registerDataSyncWidgets(); |
|||
|
|||
} |
|||
|
|||
#endif // MVVMDATASYNCWIDGETS_GLOBAL_H
|
Loading…
Reference in new issue