Skycoder42
7 years ago
25 changed files with 205 additions and 323 deletions
@ -1,6 +1,6 @@ |
|||
import QtQuick 2.8 |
|||
import de.skycoder42.qtmvvm.quick 1.0 |
|||
|
|||
App { |
|||
import QtQuick 2.10 |
|||
import de.skycoder42.QtMvvm.Quick 1.0 |
|||
|
|||
QtMvvmApp { |
|||
title: qsTr("%{ProjectName}") |
|||
} |
|||
|
@ -1,44 +0,0 @@ |
|||
#include "%{ControlHdrName}" |
|||
@if '%{UseSettings}' |
|||
#include <settingscontrol.h> |
|||
@endif |
|||
|
|||
%{ControlCn}::%{ControlCn}(QObject *parent) : |
|||
Control(parent), |
|||
_text(QStringLiteral("hello world")) |
|||
{} |
|||
|
|||
QString %{ControlCn}::text() const |
|||
{ |
|||
return _text; |
|||
} |
|||
|
|||
@if '%{UseSettings}' |
|||
void %{ControlCn}::showSettings() |
|||
{ |
|||
auto settings = new SettingsControl(this); |
|||
settings->setDeleteOnClose(true); |
|||
settings->show(); |
|||
} |
|||
|
|||
@endif |
|||
void %{ControlCn}::setText(QString text) |
|||
{ |
|||
if (_text == text) |
|||
return; |
|||
|
|||
_text = text; |
|||
emit textChanged(_text); |
|||
} |
|||
|
|||
void %{ControlCn}::onShow() |
|||
{ |
|||
qDebug("%{ControlName} gui is now visible"); |
|||
//logic to execute when the gui is shown
|
|||
} |
|||
|
|||
void %{ControlCn}::onClose() |
|||
{ |
|||
qDebug("%{ControlName} gui is now closed"); |
|||
//logic to execute when the gui was closed
|
|||
} |
@ -1,34 +0,0 @@ |
|||
#ifndef %{ControlGuard} |
|||
#define %{ControlGuard} |
|||
|
|||
#include <control.h> |
|||
|
|||
class %{ControlCn} : public Control |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) |
|||
|
|||
public: |
|||
explicit %{ControlCn}(QObject *parent = nullptr); |
|||
|
|||
void onShow() override; |
|||
void onClose() override; |
|||
|
|||
QString text() const; |
|||
|
|||
public slots: |
|||
@if '%{UseSettings}' |
|||
void showSettings(); |
|||
|
|||
@endif |
|||
void setText(QString text); |
|||
|
|||
signals: |
|||
void textChanged(QString text); |
|||
|
|||
private: |
|||
QString _text; |
|||
}; |
|||
|
|||
#endif // %{ControlGuard}
|
Before Width: | Height: | Size: 831 B |
@ -1,27 +0,0 @@ |
|||
{ |
|||
"dependencies": [ |
|||
@if '%{UseSettings}' |
|||
{ |
|||
"package": "de.skycoder42.qtmvvm.settings.core", |
|||
"provider": "qpm", |
|||
"version": "1.1.2" |
|||
}, |
|||
@endif |
|||
{ |
|||
"package": "de.skycoder42.qtmvvm.core", |
|||
"provider": "qpm", |
|||
"version": "1.1.1" |
|||
} |
|||
], |
|||
"license": { |
|||
"file": "", |
|||
"name": "" |
|||
}, |
|||
"prcFile": "", |
|||
"priFile": "", |
|||
"priIncludes": [ |
|||
], |
|||
"publishers": { |
|||
}, |
|||
"source": false |
|||
} |
@ -1,28 +0,0 @@ |
|||
{ |
|||
"dependencies": [ |
|||
@if '%{UseSettings}' |
|||
{ |
|||
"package": "de.skycoder42.qtmvvm.settings.quick", |
|||
"provider": "qpm", |
|||
"version": "1.1.2" |
|||
}, |
|||
@endif |
|||
{ |
|||
"package": "de.skycoder42.qtmvvm.quick", |
|||
"provider": "qpm", |
|||
"version": "1.1.2" |
|||
} |
|||
], |
|||
"license": { |
|||
"file": "", |
|||
"name": "" |
|||
}, |
|||
"prcFile": "", |
|||
"priFile": "", |
|||
"priIncludes": [ |
|||
"../%{CoreName}" |
|||
], |
|||
"publishers": { |
|||
}, |
|||
"source": false |
|||
} |
@ -1,28 +0,0 @@ |
|||
{ |
|||
"dependencies": [ |
|||
@if '%{UseSettings}' |
|||
{ |
|||
"package": "de.skycoder42.qtmvvm.settings.widgets", |
|||
"provider": "qpm", |
|||
"version": "1.1.3" |
|||
}, |
|||
@endif |
|||
{ |
|||
"package": "de.skycoder42.qtmvvm.widgets", |
|||
"provider": "qpm", |
|||
"version": "1.1.2" |
|||
} |
|||
], |
|||
"license": { |
|||
"file": "", |
|||
"name": "" |
|||
}, |
|||
"prcFile": "", |
|||
"priFile": "", |
|||
"priIncludes": [ |
|||
"../%{CoreName}" |
|||
], |
|||
"publishers": { |
|||
}, |
|||
"source": false |
|||
} |
@ -1,8 +1,8 @@ |
|||
<RCC> |
|||
<qresource prefix="/qml"> |
|||
<qresource prefix="/"> |
|||
<file>App.qml</file> |
|||
</qresource> |
|||
<qresource prefix="/qml/views"> |
|||
<qresource prefix="/qtmvvm/views"> |
|||
<file>%{QuickQmlName}</file> |
|||
</qresource> |
|||
</RCC> |
|||
|
@ -1,18 +1,21 @@ |
|||
#include <QGuiApplication> |
|||
#include <QQmlApplicationEngine> |
|||
#include <quickpresenter.h> |
|||
#include <QtGui/QGuiApplication> |
|||
#include <QtQml/QQmlApplicationEngine> |
|||
#include <%{AppHdrName}> |
|||
|
|||
REGISTER_CORE_APP(%{AppCn}) |
|||
QTMVVM_REGISTER_CORE_APP(%{AppCn}) |
|||
|
|||
int main(int argc, char *argv[]) |
|||
{ |
|||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); |
|||
// If you want to support file dialogs on platforms other then android, use a QApplication instead (and add QT += widgets to the pro file)
|
|||
QGuiApplication app(argc, argv); |
|||
|
|||
qmlRegisterUncreatableType<%{ControlCn}>("com.example.%{ProjectLowerName}", 1, 0, "%{ControlCn}", "Controls cannot be created!"); |
|||
|
|||
QuickPresenter::createAppEngine(QUrl(QLatin1String("qrc:/qml/App.qml"))); |
|||
qmlRegisterUncreatableType<%{VmCn}>("com.example.%{ProjectLowerName}", 1, 0, "%{VmCn}", "ViewModels cannot be created!"); |
|||
|
|||
QQmlApplicationEngine engine; |
|||
engine.load(QUrl(QStringLiteral("qrc:/App.qml"))); |
|||
if (engine.rootObjects().isEmpty()) |
|||
return -1; |
|||
|
|||
return app.exec(); |
|||
} |
|||
|
@ -0,0 +1,31 @@ |
|||
#include "%{VmHdrName}" |
|||
@if '%{UseSettings}' |
|||
|
|||
#include <QtMvvmCore/SettingsViewModel> |
|||
@endif |
|||
|
|||
%{VmCn}::%{VmCn}(QObject *parent) : |
|||
ViewModel(parent), |
|||
_text(QStringLiteral("hello world")) |
|||
{} |
|||
|
|||
QString %{VmCn}::text() const |
|||
{ |
|||
return _text; |
|||
} |
|||
|
|||
@if '%{UseSettings}' |
|||
void %{VmCn}::showSettings() |
|||
{ |
|||
show<QtMvvm::SettingsViewModel>(); |
|||
} |
|||
|
|||
@endif |
|||
void %{VmCn}::setText(const QString &text) |
|||
{ |
|||
if (_text == text) |
|||
return; |
|||
|
|||
_text = text; |
|||
emit textChanged(_text); |
|||
} |
@ -0,0 +1,31 @@ |
|||
#ifndef %{VmGuard} |
|||
#define %{VmGuard} |
|||
|
|||
#include <QtMvvmCore/ViewModel> |
|||
|
|||
class %{VmCn} : public QtMvvm::ViewModel |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) |
|||
|
|||
public: |
|||
Q_INVOKABLE explicit %{VmCn}(QObject *parent = nullptr); |
|||
|
|||
QString text() const; |
|||
|
|||
public Q_SLOTS: |
|||
@if '%{UseSettings}' |
|||
void showSettings(); |
|||
|
|||
@endif |
|||
void setText(const QString &text); |
|||
|
|||
Q_SIGNALS: |
|||
void textChanged(const QString &text); |
|||
|
|||
private: |
|||
QString _text; |
|||
}; |
|||
|
|||
#endif // %{VmGuard}
|
@ -1,25 +1,19 @@ |
|||
#include <QApplication> |
|||
#include <widgetpresenter.h> |
|||
#include <QtWidgets/QApplication> |
|||
#include <QtMvvmWidgets/WidgetsPresenter> |
|||
#include <%{AppHdrName}> |
|||
|
|||
@if '%{UseSettings}' |
|||
#include <settingsdialog.h> |
|||
@endif |
|||
#include "%{WindowHdrName}" |
|||
|
|||
//register the core app to be used
|
|||
REGISTER_CORE_APP(%{AppCn}) |
|||
// Register the core app
|
|||
QTMVVM_REGISTER_CORE_APP(%{AppCn}) |
|||
|
|||
int main(int argc, char *argv[]) |
|||
{ |
|||
QApplication a(argc, argv); |
|||
|
|||
// automatically sets "WidgetPresenter" as presenter and registers the %{WindowName} class as a widget
|
|||
// the control this widget belongs to is detected automatically via naming conventions
|
|||
WidgetPresenter::registerWidget<%{WindowCn}>(); |
|||
@if '%{UseSettings}' |
|||
WidgetPresenter::registerWidget<SettingsDialog>(); |
|||
@endif |
|||
// Automatically sets "WidgetPresenter" as presenter and registers the %{WindowName} class as a widget
|
|||
// The viewmodel this widget belongs to is detected automatically via naming conventions
|
|||
QtMvvm::WidgetsPresenter::registerView<%{WindowCn}>(); |
|||
|
|||
return a.exec(); |
|||
} |
|||
|
@ -1,24 +1,28 @@ |
|||
#include "%{WindowHdrName}" |
|||
#include "ui_%{WindowHdrName}" |
|||
#include <qtmvvmbinding.h> |
|||
|
|||
%{WindowCn}::%{WindowCn}(Control *mControl, QWidget *parent) : |
|||
#include <QtMvvmCore/Binding> |
|||
|
|||
%{WindowCn}::%{WindowCn}(QtMvvm::ViewModel *viewModel, QWidget *parent) : |
|||
QMainWindow(parent), |
|||
control(static_cast<%{ControlCn}*>(mControl)), |
|||
ui(new Ui::%{WindowCn}) |
|||
_viewModel(static_cast<%{VmCn}*>(viewModel)), |
|||
_ui(new Ui::%{WindowCn}) |
|||
{ |
|||
ui->setupUi(this); |
|||
_ui->setupUi(this); |
|||
@if '%{UseSettings}' |
|||
|
|||
connect(ui->actionSettings, &QAction::triggered, |
|||
control, &%{ControlCn}::showSettings); |
|||
connect(_ui->actionSettings, &QAction::triggered, |
|||
_viewModel, &%{VmCn}::showSettings); |
|||
@endif |
|||
|
|||
QtMvvmBinding::bind(control, "text", ui->lineEdit, "text"); |
|||
QtMvvmBinding::bind(control, "text", ui->label, "text", QtMvvmBinding::OneWayFromControl); |
|||
QtMvvm::bind(_viewModel, "text", |
|||
_ui->lineEdit, "text"); |
|||
QtMvvm::bind(_viewModel, "text", |
|||
_ui->label, "text", |
|||
QtMvvm::Binding::OneWayToView); |
|||
} |
|||
|
|||
%{WindowCn}::~%{WindowCn}() |
|||
{ |
|||
delete ui; |
|||
delete _ui; |
|||
} |
|||
|
Loading…
Reference in new issue