<liclass="level1"><ahref="#qtmvvm_readme_label_6">Usage</a><ul><liclass="level2"><ahref="#qtmvvm_readme_label_7">Add the custom wizard</a></li>
<liclass="level2"><ahref="#qtmvvm_readme_label_8">Create and initialize the QtMvvm Project</a></li>
<liclass="level2"><ahref="#qtmvvm_readme_label_9">Adding new ViewModels and Views</a><ul><liclass="level3"><ahref="#qtmvvm_readme_label_10">Create the ViewModel</a></li>
<liclass="level3"><ahref="#qtmvvm_readme_label_11">Create the View for QtWidgets</a></li>
<liclass="level3"><ahref="#qtmvvm_readme_label_12">Create the quick ui</a></li>
</ul>
</li>
</ul>
</li>
<liclass="level1"><ahref="#qtmvvm_readme_label_13">Understanding how QtMvvm works</a><ul><liclass="level2"><ahref="#qtmvvm_readme_label_14">A side note on presenters</a></li>
<divclass="textblock"><p>A mvvm oriented library for <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtcore/qtcore.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qt.html">Qt</a>, to create Projects for Widgets and Quick Controls 2 in parallel.</p>
<p>The main feature of <aclass="el"href="namespace_qt_mvvm.html"title="The primary namespace of the QtMvvm library. ">QtMvvm</a> is the seperation between ui and logic. With this library, you can create a core library, containing your application logic, as well as ui controllers (called "ViewModels"), and create multiple ui projects on top of it. This way you can for example provide both, a widgets and a qt quick based application, or create different uis for different devices, without having to code anything twice.</p>
<li>Widgets and <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtcore/qtcore.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qt.html">Qt</a> Quick Controls 2 are supported out of the box</li>
<p>The QtMvvmDatasync modules help you to integrate <ahref="https://github.com/Skycoder42/QtDataSync">QtDataSync</a> (An easy and reliable synchronization library) into your projects. It adds ViewModels and Views to:</p>
<ul>
<li>Monitor and control the connection and synchronization status</li>
<li>Manage your account and account devices</li>
<li>Easy file based import and exports, as well as a fronted for the local Network-Exchange</li>
<p>If you don't know the Mvvm pattern already, you can read up on the links below. It's basically a clever seperation of logic (the models), presentation logic (the viewmodels) and the actual GUI (the views) that is very useful when creating applications that need to support different uis for the same data.</p>
<li><aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtqml/qtqml.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qml-package.html">Package</a> Managers: The library is available via:<ul>
<li><b>IMPORTANT:</b> Due to limitations of homebrew, you must run <code>source /usr/local/opt/qtmvvm/bashrc.sh</code> before you can use the module. Some goes for the <code>qtdatasync</code> dependency.</li>
<li>Simply add my repository to your <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtcore/qtcore.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qt.html">Qt</a> MaintenanceTool (Image-based How-To here: <ahref="https://github.com/Skycoder42/QtModules/blob/master/README.md#add-my-repositories-to-qt-maintenancetool">Add custom repository</a>):<oltype="a">
<li>Start the MaintenanceTool from the commandline using <code>/path/to/MaintenanceTool --addTempRepository <url></code> with one of the following urls (GUI-Method is currently broken, see <ahref="https://bugreports.qt.io/browse/QTIFW-1156">QTIFW-1156</a>) - This must be done <em>every time</em> you start the tool:<ul>
<li>A new entry appears under all supported <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtcore/qtcore.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qt.html">Qt</a> Versions (e.g. <code><aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtcore/qtcore.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qt.html">Qt</a>><aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtcore/qtcore.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qt.html">Qt</a> 5.11 > Skycoder42 <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtcore/qtcore.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qt.html">Qt</a> modules</code>)</li>
<li>You can install either all of my modules, or select the one you need: <code><aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtcore/qtcore.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qt.html">Qt</a> Mvvm</code></li>
<li>Continue the setup and thats it! you can now use the module for all of your installed Kits for that <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtcore/qtcore.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qt.html">Qt</a> Version</li>
<li>Download the compiled modules from the release page. <b>Note:</b> You will have to add the correct ones yourself and may need to adjust some paths to fit your installation! In addition to that, you will have to download the modules this one depends on as well. See Section "Requirements" below.</li>
<li>Build it yourself! <b>Note:</b> This requires all build an runtime dependencies to be available (See Section "Requirements" below). If you don't have/need cmake, you can ignore the related warnings. To automatically build and install to your <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtcore/qtcore.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qt.html">Qt</a> installation, run:<ul>
<p>The library only has a few dependencies. The main modules only depends on qtbase and qtquick respectively. However, the Datasync extensions need <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtdatasync/qtdatasync.tags:https://skycoder42.github.io/QtDataSync/"href="https://skycoder42.github.io/QtDataSync/namespace_qt_data_sync.html">QtDataSync</a> of course.</p>
<li>Please note that you need the <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtdatasync/qtdatasync.tags:https://skycoder42.github.io/QtDataSync/"href="https://skycoder42.github.io/QtDataSync/namespace_qt_data_sync.html">QtDataSync</a> for building the datasync modules, but if you don't have it, the build wont fail. The datasync modules will simply be skipped.</li>
<li><b>QtMvvmDataSyncCore:</b> The core part of the <aclass="el"href="namespace_qt_mvvm.html"title="The primary namespace of the QtMvvm library. ">QtMvvm</a> DataSync extension (requires <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtdatasync/qtdatasync.tags:https://skycoder42.github.io/QtDataSync/"href="https://skycoder42.github.io/QtDataSync/namespace_qt_data_sync.html">QtDataSync</a>)</li>
<li><b>QtMvvmDataSyncWidgets:</b> The frontend extensions of <aclass="el"href="namespace_qt_mvvm.html"title="The primary namespace of the QtMvvm library. ">QtMvvm</a> DataSync for QtWidgets (requires <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtdatasync/qtdatasync.tags:https://skycoder42.github.io/QtDataSync/"href="https://skycoder42.github.io/QtDataSync/namespace_qt_data_sync.html">QtDataSync</a>)</li>
<li><b>QtMvvmDataSyncQuick:</b> The frontend extensions of <aclass="el"href="namespace_qt_mvvm.html"title="The primary namespace of the QtMvvm library. ">QtMvvm</a> DataSync for QtQuick Controls 2 (requires <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtdatasync/qtdatasync.tags:https://skycoder42.github.io/QtDataSync/"href="https://skycoder42.github.io/QtDataSync/namespace_qt_data_sync.html">QtDataSync</a>)</li>
<p>The following chapters will explain how to create a <aclass="el"href="namespace_qt_mvvm.html"title="The primary namespace of the QtMvvm library. ">QtMvvm</a> Project and how to correctly implement applications with it. A Mvvm Project always consists of one core project, with the application logic, and one or more gui projects with the View implementations. In the following section it is explained how to use <aclass="el"href="namespace_qt_mvvm.html"title="The primary namespace of the QtMvvm library. ">QtMvvm</a> without going into the depths. For more details you can check the sample projects. If you want to go deeper on how the Framework works and what detailed steps are needed, check out the <ahref="https://skycoder42.github.io/QtMvvm/">Documentation</a> of the following classes:</p>
<ul>
<li>CoreApp</li>
<li>ViewModel</li>
<li>ServiceRegistry</li>
<li>IPresenter</li>
</ul>
<p>The easiest way to create a <aclass="el"href="namespace_qt_mvvm.html"title="The primary namespace of the QtMvvm library. ">QtMvvm</a> Project is to use the provided project template. If you did not install via a package manager or the repository, follow the steps below to add the wizard.</p>
<p>If you did install the module as module you can skip this part. To create a new <aclass="el"href="namespace_qt_mvvm.html"title="The primary namespace of the QtMvvm library. ">QtMvvm</a> project, you can use a custom wizard for QtCreator. You will have to add it to your computer once. To do this, you will have to copy the contents of the [<code>ProjectTemplate</code>](ProjectTemplate) folder to a location known by QtCreator (Pro Tip: Use <ahref="https://kinolien.github.io/gitzip/">Kinolien's Gitzip</a> to download that directory only). The locations can be found here: <ahref="https://doc.qt.io/qtcreator/creator-project-wizards.html#locating-wizards">Locating Wizards</a>. If you are, for example, working on linux, create a new folder called <code><aclass="el"href="namespace_qt_mvvm.html"title="The primary namespace of the QtMvvm library. ">QtMvvm</a></code> inside of <code>$HOME/.config/QtProject/qtcreator/templates/wizards</code> and copy the contents there. After restarting QtCreator, the project template should appear in the <code>Applications</code> section of the new-dialog as <code><aclass="el"href="namespace_qt_mvvm.html"title="The primary namespace of the QtMvvm library. ">QtMvvm</a> Application Project</code>.</p>
<p>Follow the setup to create the project. You can select the GUI-frontends you want to use, as well as additional features. After that you get a basic project skeleton with a simple CoreApp and a ViewModel, as well as the corresponding views.</p>
<p>For more Details on these classes, check the <ahref="https://skycoder42.github.io/QtMvvm/">Documentation</a>.</p>
<li>Add a new c++ class to your core project. Let it inherit from <code><aclass="el"href="class_qt_mvvm_1_1_view_model.html"title="The base class for all viewmodels. ">QtMvvm::ViewModel</a></code></li>
<li>Make shure the Constructor has the following signature: <code>Q_INVOKABLE MyClass(QObject *parent);</code></li>
<li>See <ahref="examples/mvvmcore/SampleCore/sampleviewmodel.h"><code>examples/mvvmcore/SampleCore/sampleviewmodel.h</code></a> for an example ViewModel</li>
<li>Create a new widget class in your widgets gui project.</li>
<li>In order to use it as widget for a viewmodel, you should name it accordingly: If your viewmodel is named <code>MyCustomViewModel</code>, the widgets name must start with <code>MyCustom</code> as well (e.g. <code>MyCustomWindow</code>, <code>MyCustomDialog</code>, <code>MyCustomView</code>, etc.)</li>
<li>Modify the constructor to look like this: <code>Q_INVOKABLE MyCustomWindow(<aclass="el"href="class_qt_mvvm_1_1_view_model.html"title="The base class for all viewmodels. ">QtMvvm::ViewModel</a> *viewModel, <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtautoupdater/qtautoupdater.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/class_q_widget.html">QWidget</a> *parent = nullptr);</code></li>
<li>As final step, you need to register the widget. This can be done by adding the line <code>WidgetPresenter::registerView<MyCustomWindow>();</code> to your <code>main.cpp</code>, before calling <code><aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtwidgets/qtwidgets.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qapplication.html#exec">QApplication::exec</a></code></li>
<li>See <ahref="examples/mvvmwidgets/SampleWidgets/sampleview.h"><code>examples/mvvmwidgets/SampleWidgets/sampleview.h</code></a> for an example widget</li>
<li><em>Optional:</em> Register the viewmodel for qml. This way autocomplete will work. Add the line <code>qmlRegisterUncreatableType<MyCustomViewModel>("com.example.mvvmexample", 1, 0, "MyCustomViewModel", "ViewModels cannot be created!");</code> to your main cpp before creating the engine.</li>
<li>Create a new qml file inside of the folder <code>:/qml/views</code> (This is required to automatically find the view).</li>
<li>In order to use it as view for a viewmodel, you should name it accordingly: If your viewmodel is named <code>MyCustomViewModel</code>, the views name must start with <code>MyCustom</code> as well (e.g. <code>MyCustomView</code>, <code>MyCustomActivity</code>, etc.)</li>
<li>Add the following imports to the qml file: <divclass="fragment"><divclass="line"><spanclass="keyword">import</span><aclass="code"href="namespace_qt_quick.html">QtQuick</a> 2.10</div><divclass="line">import <aclass="code"href="namespace_qt_quick.html">QtQuick</a>.Controls 2.3</div><divclass="line">import <aclass="codeRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtrestclient/qtrestclient.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/namespacede_1_1skycoder42_1_1_qt_rest_client.html">de</a>.<aclass="codeRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtrestclient/qtrestclient.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/namespacede_1_1skycoder42_1_1_qt_rest_client.html">skycoder42</a>.<aclass="code"href="namespacede_1_1skycoder42_1_1_qt_mvvm.html">QtMvvm</a>.<aclass="code"href="namespacede_1_1skycoder42_1_1_qt_mvvm_1_1_core.html">Core</a> 1.1</div><divclass="line">import <aclass="codeRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtrestclient/qtrestclient.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/namespacede_1_1skycoder42_1_1_qt_rest_client.html">de</a>.<aclass="codeRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtrestclient/qtrestclient.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/namespacede_1_1skycoder42_1_1_qt_rest_client.html">skycoder42</a>.<aclass="code"href="namespacede_1_1skycoder42_1_1_qt_mvvm.html">QtMvvm</a>.<aclass="code"href="namespacede_1_1skycoder42_1_1_qt_mvvm_1_1_quick.html">Quick</a> 1.1</div><divclass="line">import com.example.mvvmexample 1.0 <spanclass="comment">//adjust to the module defined in your main.cpp</span></div></div><!-- fragment --></li>
<li>Add a property named viewmodel to the root element: <code>property MyCustomViewModel viewmodel: null</code> (If you did not register the viewmodel, use <code>var</code> instead of <code>MyCustomViewModel</code> as property type)</li>
<li>Add a presenter progress element to the root element. This way lazy loading views will show a progress: <code>PresenterProgress {}</code></li>
<li>See <ahref="examples/mvvmquick/SampleQuick/SampleView.qml"><code>examples/mvvmquick/SampleQuick/SampleView.qml</code></a> for an example view</li>
<p>The general idea is the following: You create viewmodels in your core project, which represent uis. They typically contain all the properties relevant for the ui, methods (slots) that can be called (e.g. on a button click) and signals to inform the ui about changes and other events. Thus, you can use the as ui "placeholders". Of course, They only contain the ui logic, not the actual uis.</p>
<p>The CoreApp is what's reponsible for managing those viewmodels. Showing a viewmodel, as well as messages (alert dialogs) are all controlled by the coreapp. The coreapp uses a so called presenters to create the actual uis. The presenters are located in the ui projects and they are the most complicated part. Their main task is to find ui implementations for viewmodel (called views), and manage the life cycle as well as the presentation of those real views. The presenters are where the decision is made, how a specific view should be shown.</p>
<p>The views are whatever you need to create actual uis. This depends on the presenter used, since the presenter selects the views. Each ui type has their own way to create those views, but they all have in commmon that the views themselves do not control the application. When a viewmodel gets shown, a new view is created and the viewmodel passed to it. Once the views was closed, the view and the viewmodel get deleted again. Views and ViewModels are temporary and should only use the viewmodel to interact with other parts of the application.</p>
<p>To create a presenter, the <code><aclass="el"href="class_qt_mvvm_1_1_i_presenter.html"title="The interface for a GUI view presenter. ">QtMvvm::IPresenter</a></code> must be implemented and provided via the <code>ServiceRegistry</code>. Presenters can become quite complicated, but they are the thing you need to modify if you want to present views in a different way from the ones supported. Currently, the presenters can do the following:</p>
<ul>
<li>Widgets Presenter<ul>
<li>Present viewmodels as widgets (or windows, dialogs, depending on type and parent)</li>
<li>Parent-Aware: If your viewmodel has a parent and shows a ui, the childs ui will be a child of the parents ui as well</li>
<li>Automatically detect QDockWidgets and place them as dock inside a parents <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtwidgets/qtwidgets.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qmainwindow.html">QMainWindow</a></li>
<li>Automatically detect QMdiSubWindows and place them in a parents <aclass="elRef"target="_blank"doxygen="/home/sky/Qt/Docs/Qt-5.11.1/qtwidgets/qtwidgets.tags:https://doc.qt.io/qt-5/"href="https://doc.qt.io/qt-5/qmdiarea.html">QMdiArea</a></li>
<li>Allows windows to implement <code>IPresentingWidget</code>. This way a window can handle the presentation of it's children without modifying the presenter</li>
<li>Allows to register custom input widgets for input dialogs (and other parts, like the settings. See <code>InputWidgetFactory</code>)</li>
</ul>
</li>
<li>Quick Presenter<ul>
<li>Consists of a c++ part and a qml part</li>
<li>The c++ part is responsible for finding views for controls and creating them, but <b>not</b> for the actual presentation. This is done by the qml presenter<ul>
<li>Allows to register custom input views for input dialogs (and other parts, like the settings. See <code>InputViewFactory</code>)</li>
</ul>
</li>
<li>The qml presenter can be any qml type. It must provide the correct methods (as seen in <code>QtMvvmApp</code>) and register itself with <code>Component.onCompleted: QuickPresenter.qmlPresenter = self</code><ul>
<li>The <code>QtMvvmApp</code> qml types automatically register themselves as presenter and perform the presentations</li>
<li>Supports Items as new fullscreen pages inside a stack view, as drawer or as tabs</li>