25 changed files with 205 additions and 323 deletions
			
			
		@ -1,6 +1,6 @@ | 
				
			|||||
import QtQuick 2.8 | 
					import QtQuick 2.10 | 
				
			||||
import de.skycoder42.qtmvvm.quick 1.0 | 
					import de.skycoder42.QtMvvm.Quick 1.0 | 
				
			||||
 | 
					 | 
				
			||||
App { | 
					 | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					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> | 
					<RCC> | 
				
			||||
    <qresource prefix="/qml"> | 
					    <qresource prefix="/"> | 
				
			||||
        <file>App.qml</file> | 
					        <file>App.qml</file> | 
				
			||||
    </qresource> | 
					    </qresource> | 
				
			||||
    <qresource prefix="/qml/views"> | 
						<qresource prefix="/qtmvvm/views"> | 
				
			||||
        <file>%{QuickQmlName}</file> | 
					        <file>%{QuickQmlName}</file> | 
				
			||||
    </qresource> | 
					    </qresource> | 
				
			||||
</RCC> | 
					</RCC> | 
				
			||||
 | 
				
			|||||
@ -1,18 +1,21 @@ | 
				
			|||||
#include <QGuiApplication> | 
					#include <QtGui/QGuiApplication> | 
				
			||||
#include <QQmlApplicationEngine> | 
					#include <QtQml/QQmlApplicationEngine> | 
				
			||||
#include <quickpresenter.h> | 
					 | 
				
			||||
#include <%{AppHdrName}> | 
					#include <%{AppHdrName}> | 
				
			||||
 | 
					
 | 
				
			||||
REGISTER_CORE_APP(%{AppCn}) | 
					QTMVVM_REGISTER_CORE_APP(%{AppCn}) | 
				
			||||
 | 
					
 | 
				
			||||
int main(int argc, char *argv[]) | 
					int main(int argc, char *argv[]) | 
				
			||||
{ | 
					{ | 
				
			||||
	QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | 
						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); | 
						QGuiApplication app(argc, argv); | 
				
			||||
 | 
					
 | 
				
			||||
	qmlRegisterUncreatableType<%{ControlCn}>("com.example.%{ProjectLowerName}", 1, 0, "%{ControlCn}", "Controls cannot be created!"); | 
						qmlRegisterUncreatableType<%{VmCn}>("com.example.%{ProjectLowerName}", 1, 0, "%{VmCn}", "ViewModels cannot be created!"); | 
				
			||||
	 | 
						 | 
				
			||||
	QuickPresenter::createAppEngine(QUrl(QLatin1String("qrc:/qml/App.qml"))); | 
						QQmlApplicationEngine engine; | 
				
			||||
 | 
						engine.load(QUrl(QStringLiteral("qrc:/App.qml"))); | 
				
			||||
 | 
						if (engine.rootObjects().isEmpty()) | 
				
			||||
 | 
							return -1; | 
				
			||||
 | 
					
 | 
				
			||||
	return app.exec(); | 
						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 <QtWidgets/QApplication> | 
				
			||||
#include <widgetpresenter.h> | 
					#include <QtMvvmWidgets/WidgetsPresenter> | 
				
			||||
#include <%{AppHdrName}> | 
					#include <%{AppHdrName}> | 
				
			||||
 | 
					
 | 
				
			||||
@if '%{UseSettings}' | 
					 | 
				
			||||
#include <settingsdialog.h> | 
					 | 
				
			||||
@endif | 
					 | 
				
			||||
#include "%{WindowHdrName}" | 
					#include "%{WindowHdrName}" | 
				
			||||
 | 
					
 | 
				
			||||
//register the core app to be used
 | 
					// Register the core app
 | 
				
			||||
REGISTER_CORE_APP(%{AppCn}) | 
					QTMVVM_REGISTER_CORE_APP(%{AppCn}) | 
				
			||||
 | 
					
 | 
				
			||||
int main(int argc, char *argv[]) | 
					int main(int argc, char *argv[]) | 
				
			||||
{ | 
					{ | 
				
			||||
	QApplication a(argc, argv); | 
						QApplication a(argc, argv); | 
				
			||||
 | 
					
 | 
				
			||||
	// automatically sets "WidgetPresenter" as presenter and registers the %{WindowName} class as a widget
 | 
						// 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
 | 
						// The viewmodel this widget belongs to is detected automatically via naming conventions
 | 
				
			||||
	WidgetPresenter::registerWidget<%{WindowCn}>(); | 
						QtMvvm::WidgetsPresenter::registerView<%{WindowCn}>(); | 
				
			||||
@if '%{UseSettings}' | 
					 | 
				
			||||
	WidgetPresenter::registerWidget<SettingsDialog>(); | 
					 | 
				
			||||
@endif | 
					 | 
				
			||||
 | 
					
 | 
				
			||||
	return a.exec(); | 
						return a.exec(); | 
				
			||||
} | 
					} | 
				
			||||
 | 
				
			|||||
@ -1,24 +1,28 @@ | 
				
			|||||
#include "%{WindowHdrName}" | 
					#include "%{WindowHdrName}" | 
				
			||||
#include "ui_%{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), | 
						QMainWindow(parent), | 
				
			||||
	control(static_cast<%{ControlCn}*>(mControl)), | 
						_viewModel(static_cast<%{VmCn}*>(viewModel)), | 
				
			||||
	ui(new Ui::%{WindowCn}) | 
						_ui(new Ui::%{WindowCn}) | 
				
			||||
{ | 
					{ | 
				
			||||
	ui->setupUi(this); | 
						_ui->setupUi(this); | 
				
			||||
@if '%{UseSettings}' | 
					@if '%{UseSettings}' | 
				
			||||
 | 
					
 | 
				
			||||
	connect(ui->actionSettings, &QAction::triggered, | 
						connect(_ui->actionSettings, &QAction::triggered, | 
				
			||||
			control, &%{ControlCn}::showSettings); | 
								_viewModel, &%{VmCn}::showSettings); | 
				
			||||
@endif | 
					@endif | 
				
			||||
 | 
					
 | 
				
			||||
	QtMvvmBinding::bind(control, "text", ui->lineEdit, "text"); | 
						QtMvvm::bind(_viewModel, "text", | 
				
			||||
	QtMvvmBinding::bind(control, "text", ui->label, "text", QtMvvmBinding::OneWayFromControl); | 
									 _ui->lineEdit, "text"); | 
				
			||||
 | 
						QtMvvm::bind(_viewModel, "text", | 
				
			||||
 | 
									 _ui->label, "text", | 
				
			||||
 | 
									 QtMvvm::Binding::OneWayToView); | 
				
			||||
} | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
%{WindowCn}::~%{WindowCn}() | 
					%{WindowCn}::~%{WindowCn}() | 
				
			||||
{ | 
					{ | 
				
			||||
	delete ui; | 
						delete _ui; | 
				
			||||
} | 
					} | 
				
			||||
 | 
				
			|||||
					Loading…
					
					
				
		Reference in new issue