├── Button.qml ├── qml ├── Bar.qml ├── Button.qml ├── TableView.qml ├── Icon.qml ├── MainView.qml └── MenuView.qml ├── README.md ├── sources ├── views │ ├── table_view │ │ ├── i_table_view.h │ │ ├── qml_table_view.cpp │ │ └── qml_table_view.h │ ├── common │ │ ├── i_view.h │ │ ├── qquick_item_view.h │ │ ├── qquick_item_view.cpp │ │ ├── qml_item_view.h │ │ └── qml_item_view.cpp │ ├── main_view │ │ ├── i_main_view.h │ │ ├── qml_main_view.h │ │ └── qml_main_view.cpp │ └── menu_view │ │ ├── i_menu_view.h │ │ ├── qml_menu_view.h │ │ └── qml_menu_view.cpp ├── main_presenter │ ├── main_presenter.cpp │ └── main_presenter.h ├── presenters │ ├── table_presenter │ │ ├── table_presenter.cpp │ │ └── table_presenter.h │ ├── main_presenter │ │ ├── menu_presenter │ │ │ ├── menu_presenter.cpp │ │ │ └── menu_presenter.h │ │ ├── main_presenter.h │ │ └── main_presenter.cpp │ └── menu_presenter │ │ ├── menu_presenter.h │ │ └── menu_presenter.cpp ├── view_pools │ ├── qml_view_pool.h │ ├── i_view_pool.h │ └── qml_view_pool.cpp ├── domain │ └── menu_model.h └── main.cpp ├── resources.qrc ├── .gitignore ├── resources └── icons │ ├── menu.svg │ ├── add.svg │ └── quit.svg ├── qml-mvp-example.pro └── LICENSE /Button.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Rectangle { 4 | width: 100 5 | height: 62 6 | } 7 | -------------------------------------------------------------------------------- /qml/Bar.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Rectangle { 4 | id: bar 5 | color: "#4A535B" 6 | } 7 | -------------------------------------------------------------------------------- /qml/Button.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Rectangle { 4 | width: 100 5 | height: 62 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | qml-mvp-example 2 | =============== 3 | 4 | MVP pattern example with QML and Widget view 5 | -------------------------------------------------------------------------------- /qml/TableView.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Rectangle { 4 | width: 100 5 | height: 62 6 | } 7 | -------------------------------------------------------------------------------- /sources/views/table_view/i_table_view.h: -------------------------------------------------------------------------------- 1 | #ifndef I_TABLE_VIEW_H 2 | #define I_TABLE_VIEW_H 3 | 4 | #endif // I_TABLE_VIEW_H 5 | -------------------------------------------------------------------------------- /sources/views/table_view/qml_table_view.cpp: -------------------------------------------------------------------------------- 1 | #include "qml_table_view.h" 2 | 3 | QmlTableView::QmlTableView() 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /sources/main_presenter/main_presenter.cpp: -------------------------------------------------------------------------------- 1 | #include "main_presenter.h" 2 | 3 | MainPresenter::MainPresenter(QObject *parent) : 4 | QObject(parent) 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /sources/presenters/table_presenter/table_presenter.cpp: -------------------------------------------------------------------------------- 1 | #include "table_presenter.h" 2 | 3 | TablePresenter::TablePresenter(QObject *parent) : 4 | QObject(parent) 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /sources/presenters/main_presenter/menu_presenter/menu_presenter.cpp: -------------------------------------------------------------------------------- 1 | #include "menu_presenter.h" 2 | 3 | MenuPresenter::MenuPresenter(QObject *parent) : 4 | QObject(parent) 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /sources/views/table_view/qml_table_view.h: -------------------------------------------------------------------------------- 1 | #ifndef QML_TABLE_VIEW_H 2 | #define QML_TABLE_VIEW_H 3 | 4 | class QmlTableView : public ITableView 5 | { 6 | public: 7 | QmlTableView(); 8 | }; 9 | 10 | #endif // QML_TABLE_VIEW_H 11 | -------------------------------------------------------------------------------- /resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qml/MainView.qml 4 | qml/Bar.qml 5 | qml/MenuView.qml 6 | resources/icons/menu.svg 7 | qml/Icon.qml 8 | resources/icons/quit.svg 9 | 10 | 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | 3 | *.slo 4 | *.lo 5 | *.o 6 | *.a 7 | *.la 8 | *.lai 9 | *.so 10 | *.dll 11 | *.dylib 12 | 13 | # Qt-es 14 | 15 | /.qmake.cache 16 | /.qmake.stash 17 | *.pro.user 18 | *.pro.user.* 19 | *.moc 20 | moc_*.cpp 21 | qrc_*.cpp 22 | ui_*.h 23 | Makefile* 24 | *-build-* 25 | 26 | # QtCreator 27 | 28 | *.autosave 29 | -------------------------------------------------------------------------------- /sources/main_presenter/main_presenter.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_PRESENTER_H 2 | #define MAIN_PRESENTER_H 3 | 4 | #include 5 | 6 | class MainPresenter : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit MainPresenter(QObject *parent = 0); 11 | 12 | signals: 13 | 14 | public slots: 15 | 16 | }; 17 | 18 | #endif // MAIN_PRESENTER_H 19 | -------------------------------------------------------------------------------- /sources/view_pools/qml_view_pool.h: -------------------------------------------------------------------------------- 1 | #ifndef QML_VIEW_POOL_H 2 | #define QML_VIEW_POOL_H 3 | 4 | #include "i_view_pool.h" 5 | 6 | class QmlViewPool: public IViewPool 7 | { 8 | public: 9 | virtual IMainView* mainView(QObject* parent) override; 10 | virtual IMenuView* menuView(QObject* parent) override; 11 | }; 12 | 13 | #endif // QML_VIEW_POOL_H 14 | -------------------------------------------------------------------------------- /sources/views/common/i_view.h: -------------------------------------------------------------------------------- 1 | #ifndef I_VIEW_H 2 | #define I_VIEW_H 3 | 4 | #include 5 | 6 | class IView : public QObject 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | explicit IView(QObject* parent = nullptr): QObject(parent) {} 12 | 13 | virtual void show(QObject* parentVisualItem = nullptr) = 0; 14 | }; 15 | 16 | #endif // I_VIEW_H 17 | -------------------------------------------------------------------------------- /sources/presenters/table_presenter/table_presenter.h: -------------------------------------------------------------------------------- 1 | #ifndef TABLE_PRESENTER_H 2 | #define TABLE_PRESENTER_H 3 | 4 | #include 5 | 6 | class TablePresenter : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit TablePresenter(QObject *parent = 0); 11 | 12 | signals: 13 | 14 | public slots: 15 | 16 | }; 17 | 18 | #endif // TABLE_PRESENTER_H 19 | -------------------------------------------------------------------------------- /sources/presenters/main_presenter/menu_presenter/menu_presenter.h: -------------------------------------------------------------------------------- 1 | #ifndef MENU_PRESENTER_H 2 | #define MENU_PRESENTER_H 3 | 4 | #include 5 | 6 | class MenuPresenter : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit MenuPresenter(QObject *parent = 0); 11 | 12 | signals: 13 | 14 | public slots: 15 | 16 | }; 17 | 18 | #endif // MENU_PRESENTER_H 19 | -------------------------------------------------------------------------------- /sources/view_pools/i_view_pool.h: -------------------------------------------------------------------------------- 1 | #ifndef I_VIEW_POOL_H 2 | #define I_VIEW_POOL_H 3 | 4 | #include "../views/main_view/i_main_view.h" 5 | #include "../views/menu_view/i_menu_view.h" 6 | 7 | class IViewPool 8 | { 9 | public: 10 | virtual IMainView* mainView(QObject* parent) = 0; 11 | virtual IMenuView* menuView(QObject* parent) = 0; 12 | }; 13 | 14 | #endif // I_VIEW_POOL_H 15 | -------------------------------------------------------------------------------- /sources/view_pools/qml_view_pool.cpp: -------------------------------------------------------------------------------- 1 | #include "qml_view_pool.h" 2 | 3 | #include "../views/main_view/qml_main_view.h" 4 | #include "../views/menu_view/qml_menu_view.h" 5 | 6 | IMainView* QmlViewPool::mainView(QObject* parent) 7 | { 8 | return new QmlMainView(parent); 9 | } 10 | 11 | IMenuView* QmlViewPool::menuView(QObject* parent) 12 | { 13 | return new QmlMenuView(parent); 14 | } 15 | -------------------------------------------------------------------------------- /sources/domain/menu_model.h: -------------------------------------------------------------------------------- 1 | #ifndef MENU_MODEL_H 2 | #define MENU_MODEL_H 3 | 4 | #include 5 | 6 | class MenuModel 7 | { 8 | public: 9 | MenuModel(); 10 | ~MenuModel(); 11 | 12 | QStringList currentActions() const; 13 | void triggerAction(const QString& action); 14 | 15 | class MenuModelImpl; 16 | MenuModelImpl* d; 17 | }; 18 | 19 | #endif // MENU_MODEL_H 20 | -------------------------------------------------------------------------------- /sources/views/main_view/i_main_view.h: -------------------------------------------------------------------------------- 1 | #ifndef I_MAIN_VIEW_H 2 | #define I_MAIN_VIEW_H 3 | 4 | #include "../common/i_view.h" 5 | 6 | class IMainView : public IView 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | explicit IMainView(QObject* parent): IView(parent) {} 12 | 13 | virtual QObject* menuVisualItem() = 0; 14 | 15 | signals: 16 | void quit(); 17 | }; 18 | 19 | #endif // I_MAIN_VIEW_H 20 | -------------------------------------------------------------------------------- /sources/views/menu_view/i_menu_view.h: -------------------------------------------------------------------------------- 1 | #ifndef I_MENU_VIEW_H 2 | #define I_MENU_VIEW_H 3 | 4 | #include "../common/i_view.h" 5 | 6 | class IMenuView: public IView 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | explicit IMenuView(QObject* parent): IView(parent) {} 12 | 13 | virtual void setMenuModel(const QStringList& model) = 0; 14 | 15 | signals: 16 | void selected(QString value); 17 | }; 18 | 19 | #endif // I_MENU_VIEW_H 20 | -------------------------------------------------------------------------------- /sources/views/common/qquick_item_view.h: -------------------------------------------------------------------------------- 1 | #ifndef QQUICK_ITEM_VIEW_H 2 | #define QQUICK_ITEM_VIEW_H 3 | 4 | #include 5 | 6 | class QQuickItemView 7 | { 8 | public: 9 | QQuickItemView(); 10 | 11 | QQuickItem* visualItem(const QString& objectName = QString()); 12 | virtual void createVisualItem(QQuickItem* parentItem) = 0; 13 | 14 | protected: 15 | QQuickItem* m_item; 16 | }; 17 | 18 | #endif // QQUICK_ITEM_VIEW_H 19 | -------------------------------------------------------------------------------- /sources/views/common/qquick_item_view.cpp: -------------------------------------------------------------------------------- 1 | #include "qquick_item_view.h" 2 | 3 | QQuickItemView::QQuickItemView(): 4 | m_item(nullptr) 5 | {} 6 | 7 | QQuickItem* QQuickItemView::visualItem(const QString& objectName) 8 | { 9 | if (objectName.isNull()) 10 | { 11 | return m_item; 12 | } 13 | 14 | if (m_item) 15 | { 16 | return m_item->findChild(objectName); 17 | } 18 | 19 | return nullptr; 20 | } 21 | -------------------------------------------------------------------------------- /sources/views/common/qml_item_view.h: -------------------------------------------------------------------------------- 1 | #ifndef QML_ITEM_VIEW_H 2 | #define QML_ITEM_VIEW_H 3 | 4 | #include "qquick_item_view.h" 5 | 6 | class QmlItemView : public QQuickItemView 7 | { 8 | public: 9 | QmlItemView(); 10 | 11 | virtual void createVisualItem(QQuickItem* parentItem) override; 12 | 13 | QUrl source() const; 14 | void setSource(const QUrl& source); 15 | 16 | private: 17 | QUrl m_source; 18 | }; 19 | 20 | #endif // QML_ITEM_VIEW_H 21 | -------------------------------------------------------------------------------- /sources/views/menu_view/qml_menu_view.h: -------------------------------------------------------------------------------- 1 | #ifndef QML_MENU_VIEW_H 2 | #define QML_MENU_VIEW_H 3 | 4 | #include "i_menu_view.h" 5 | #include "../common/qml_item_view.h" 6 | 7 | class QmlMenuView: public IMenuView, public QmlItemView 8 | { 9 | Q_OBJECT 10 | 11 | public: 12 | explicit QmlMenuView(QObject* parent); 13 | 14 | virtual void show(QObject* parentVisualItem) override; 15 | virtual void setMenuModel(const QStringList& model) override; 16 | }; 17 | 18 | #endif // QML_MENU_VIEW_H 19 | -------------------------------------------------------------------------------- /sources/presenters/main_presenter/main_presenter.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_PRESENTER_H 2 | #define MAIN_PRESENTER_H 3 | 4 | #include "../../view_pools/i_view_pool.h" 5 | 6 | class MainPresenter: public QObject 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | MainPresenter(IViewPool* viewPool, QObject* parent = nullptr); 12 | ~MainPresenter(); 13 | 14 | void exec(); 15 | 16 | signals: 17 | void quit(); 18 | 19 | private: 20 | class MainPresenterImpl; 21 | MainPresenterImpl* d; 22 | }; 23 | 24 | #endif // MAIN_PRESENTER_H 25 | -------------------------------------------------------------------------------- /sources/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "view_pools/qml_view_pool.h" 4 | #include "presenters/main_presenter/main_presenter.h" 5 | 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | QGuiApplication app(argc, argv); 11 | 12 | QmlViewPool viewPool; 13 | 14 | MainPresenter mainPresenter(&viewPool); 15 | QObject::connect(&mainPresenter, &MainPresenter::quit, 16 | &app, &QGuiApplication::quit); 17 | 18 | mainPresenter.exec(); 19 | 20 | return app.exec(); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /qml/Icon.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Item { 4 | id: root 5 | width: 50 6 | height: 50 7 | 8 | property alias source: icon.source 9 | signal clicked 10 | 11 | Image { 12 | id: icon 13 | anchors.fill: parent 14 | anchors.margins: iconMouseArea.containsMouse ? 5 : 10; 15 | Behavior on anchors.margins { 16 | NumberAnimation { duration: 100 } 17 | } 18 | } 19 | 20 | MouseArea { 21 | id: iconMouseArea 22 | anchors.fill: root 23 | hoverEnabled: true 24 | onClicked: root.clicked() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sources/presenters/menu_presenter/menu_presenter.h: -------------------------------------------------------------------------------- 1 | #ifndef MENU_PRESENTER_H 2 | #define MENU_PRESENTER_H 3 | 4 | #include "../../view_pools/i_view_pool.h" 5 | 6 | class MenuPresenter: public QObject 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | MenuPresenter(IViewPool* viewPool, QObject* parent = nullptr); 12 | ~MenuPresenter(); 13 | 14 | void exec(QObject* parentVisualItem); 15 | 16 | private slots: 17 | void updateView(); 18 | void onSelected(const QString& value); 19 | 20 | private: 21 | class MenuPresenterImpl; 22 | MenuPresenterImpl* d; 23 | }; 24 | 25 | #endif // MENU_PRESENTER_H 26 | -------------------------------------------------------------------------------- /resources/icons/menu.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /sources/views/main_view/qml_main_view.h: -------------------------------------------------------------------------------- 1 | #ifndef QML_MAIN_VIEW_H 2 | #define QML_MAIN_VIEW_H 3 | 4 | #include "i_main_view.h" 5 | #include "../common/qquick_item_view.h" 6 | 7 | class QmlMainView : public IMainView, public QQuickItemView 8 | { 9 | Q_OBJECT 10 | 11 | public: 12 | explicit QmlMainView(QObject* parent); 13 | ~QmlMainView() override; 14 | 15 | virtual void show(QObject* parentVisualItem) override; 16 | virtual void createVisualItem(QQuickItem* parentItem) override; 17 | 18 | virtual QQuickItem* menuVisualItem() override; 19 | 20 | private: 21 | class QmlMainViewImpl; 22 | QmlMainViewImpl* const d; 23 | }; 24 | 25 | #endif // QML_MAIN_VIEW_H 26 | -------------------------------------------------------------------------------- /resources/icons/add.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /sources/views/menu_view/qml_menu_view.cpp: -------------------------------------------------------------------------------- 1 | #include "qml_menu_view.h" 2 | 3 | #include "../main_view/qml_main_view.h" 4 | 5 | namespace 6 | { 7 | const QUrl source = QUrl("qrc:///qml/MenuView.qml"); 8 | } 9 | 10 | QmlMenuView::QmlMenuView(QObject* parent): 11 | IMenuView(parent), 12 | QmlItemView() 13 | { 14 | this->setSource(::source); 15 | } 16 | 17 | void QmlMenuView::show(QObject* parentVisualItem) 18 | { 19 | this->createVisualItem(qobject_cast(parentVisualItem)); 20 | 21 | connect(m_item, SIGNAL(clicked(QString)), 22 | this, SIGNAL(selected(QString))); 23 | } 24 | 25 | void QmlMenuView::setMenuModel(const QStringList& model) 26 | { 27 | m_item->setProperty("model", model); 28 | } 29 | -------------------------------------------------------------------------------- /qml/MainView.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | 3 | Rectangle { 4 | id: root 5 | color: "#E0E2E4" 6 | width: 550 7 | height: 480 8 | 9 | Bar { 10 | id: bar 11 | height: 50 12 | anchors.top: parent.top 13 | anchors.left: parent.left 14 | anchors.right: parent.right 15 | 16 | Item { 17 | objectName: "menuPlaceholder" 18 | anchors.fill: parent 19 | } 20 | 21 | Icon { 22 | id: icon 23 | anchors.verticalCenter: parent.verticalCenter 24 | anchors.right: parent.right 25 | anchors.rightMargin: 10 26 | source: "qrc:///resources/icons/quit.svg"; 27 | onClicked: Qt.quit() 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sources/views/common/qml_item_view.cpp: -------------------------------------------------------------------------------- 1 | #include "qml_item_view.h" 2 | 3 | #include 4 | 5 | QmlItemView::QmlItemView(): 6 | QQuickItemView() 7 | {} 8 | 9 | void QmlItemView::createVisualItem(QQuickItem* parentItem) 10 | { 11 | QQmlComponent component(qmlEngine(parentItem), this->source()); 12 | m_item = qobject_cast(component.create()); 13 | m_item->setParentItem(parentItem); 14 | QQmlEngine::setObjectOwnership(m_item, QQmlEngine::JavaScriptOwnership); 15 | } 16 | 17 | QUrl QmlItemView::source() const 18 | { 19 | return m_source; 20 | } 21 | 22 | void QmlItemView::setSource(const QUrl& source) 23 | { 24 | m_source = source; 25 | 26 | if (m_item) 27 | { 28 | this->createVisualItem(qobject_cast(m_item->parent())); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /sources/presenters/main_presenter/main_presenter.cpp: -------------------------------------------------------------------------------- 1 | #include "main_presenter.h" 2 | 3 | #include "../menu_presenter/menu_presenter.h" 4 | 5 | class MainPresenter::MainPresenterImpl 6 | { 7 | public: 8 | IMainView* view = nullptr; 9 | MenuPresenter* menuPresenter = nullptr; 10 | }; 11 | 12 | 13 | MainPresenter::MainPresenter(IViewPool* viewPool, QObject* parent): 14 | QObject(parent), 15 | d(new MainPresenterImpl()) 16 | { 17 | d->view = viewPool->mainView(this); 18 | d->menuPresenter = new MenuPresenter(viewPool, this); 19 | 20 | connect(d->view, &IMainView::quit, this, &MainPresenter::quit); 21 | } 22 | 23 | MainPresenter::~MainPresenter() 24 | { 25 | delete d; 26 | } 27 | 28 | void MainPresenter::exec() 29 | { 30 | d->view->show(); 31 | d->menuPresenter->exec(d->view->menuVisualItem()); 32 | } 33 | -------------------------------------------------------------------------------- /qml/MenuView.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | 3 | Row { 4 | id: root 5 | anchors.fill: parent 6 | anchors.margins: 5 7 | spacing: 15 8 | 9 | signal clicked(string s) 10 | 11 | property alias model: repeater.model 12 | 13 | Repeater { 14 | id: repeater 15 | 16 | Text { 17 | id: text 18 | color: "#EFF0F1" 19 | text: modelData 20 | font.underline: textMouseArea.containsMouse 21 | font.pointSize: (textMouseArea.containsMouse && 22 | textMouseArea.pressed) ? 14 : 12 23 | anchors.verticalCenter: root.verticalCenter 24 | 25 | MouseArea { 26 | id: textMouseArea 27 | anchors.fill: parent 28 | hoverEnabled: true 29 | onClicked: root.clicked(modelData) 30 | } 31 | } 32 | } 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /sources/presenters/menu_presenter/menu_presenter.cpp: -------------------------------------------------------------------------------- 1 | #include "menu_presenter.h" 2 | 3 | #include "../../domain/menu_model.h" 4 | 5 | class MenuPresenter::MenuPresenterImpl 6 | { 7 | public: 8 | IMenuView* view = nullptr; 9 | MenuModel model; 10 | }; 11 | 12 | MenuPresenter::MenuPresenter(IViewPool* viewPool, QObject* parent): 13 | QObject(parent), 14 | d(new MenuPresenterImpl()) 15 | { 16 | d->view = viewPool->menuView(this); 17 | 18 | connect(d->view, SIGNAL(selected(QString)), this, SLOT(onSelected(QString))); 19 | } 20 | 21 | MenuPresenter::~MenuPresenter() 22 | { 23 | delete d; 24 | } 25 | 26 | void MenuPresenter::exec(QObject* parentVisualItem) 27 | { 28 | d->view->show(parentVisualItem); 29 | this->updateView(); 30 | } 31 | 32 | void MenuPresenter::updateView() 33 | { 34 | d->view->setMenuModel(d->model.currentActions()); 35 | } 36 | 37 | void MenuPresenter::onSelected(const QString& value) 38 | { 39 | d->model.triggerAction(value); 40 | this->updateView(); 41 | } 42 | -------------------------------------------------------------------------------- /qml-mvp-example.pro: -------------------------------------------------------------------------------- 1 | CONFIG += qt 2 | QT += qml quick widgets 3 | TEMPLATE = app 4 | TARGET = qml-mvp-example 5 | 6 | QMAKE_CXXFLAGS += -std=c++0x 7 | 8 | SOURCES += \ 9 | sources/main.cpp \ 10 | sources/presenters/main_presenter/main_presenter.cpp \ 11 | sources/presenters/menu_presenter/menu_presenter.cpp \ 12 | sources/view_pools/qml_view_pool.cpp \ 13 | sources/views/main_view/qml_main_view.cpp \ 14 | sources/views/menu_view/qml_menu_view.cpp \ 15 | sources/views/common/qquick_item_view.cpp \ 16 | sources/views/common/qml_item_view.cpp \ 17 | sources/domain/menu_model.cpp 18 | 19 | HEADERS += \ 20 | sources/presenters/main_presenter/main_presenter.h \ 21 | sources/presenters/menu_presenter/menu_presenter.h \ 22 | sources/views/main_view/i_main_view.h \ 23 | sources/view_pools/i_view_pool.h \ 24 | sources/view_pools/qml_view_pool.h \ 25 | sources/views/main_view/qml_main_view.h \ 26 | sources/views/menu_view/i_menu_view.h \ 27 | sources/views/menu_view/qml_menu_view.h \ 28 | sources/views/common/qquick_item_view.h \ 29 | sources/views/common/qml_item_view.h \ 30 | sources/domain/menu_model.h \ 31 | sources/views/common/i_view.h 32 | 33 | RESOURCES += \ 34 | resources.qrc 35 | -------------------------------------------------------------------------------- /sources/views/main_view/qml_main_view.cpp: -------------------------------------------------------------------------------- 1 | #include "qml_main_view.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace 8 | { 9 | const QUrl source = QUrl("qrc:///qml/MainView.qml"); 10 | const QString menuPlaceholder = "menuPlaceholder"; 11 | } 12 | 13 | class QmlMainView::QmlMainViewImpl 14 | { 15 | public: 16 | QQuickView window; 17 | }; 18 | 19 | QmlMainView::QmlMainView(QObject* parent): 20 | IMainView(parent), 21 | QQuickItemView(), 22 | d(new QmlMainViewImpl()) 23 | { 24 | d->window.setSource(::source); 25 | d->window.setResizeMode(QQuickView::SizeRootObjectToView); 26 | this->createVisualItem(nullptr); 27 | 28 | connect(d->window.rootContext(), &QQmlContext::destroyed, 29 | this, &IMainView::quit); 30 | connect(d->window.engine(), &QQmlEngine::quit, 31 | this, &IMainView::quit); 32 | } 33 | 34 | QmlMainView::~QmlMainView() 35 | { 36 | delete d; 37 | } 38 | 39 | void QmlMainView::show(QObject* parentVisualItem) 40 | { 41 | Q_UNUSED(parentVisualItem) 42 | 43 | d->window.show(); 44 | } 45 | 46 | void QmlMainView::createVisualItem(QQuickItem* parentItem) 47 | { 48 | Q_UNUSED(parentItem) 49 | m_item = d->window.rootObject(); 50 | } 51 | 52 | QQuickItem* QmlMainView::menuVisualItem() 53 | { 54 | return this->visualItem(::menuPlaceholder); 55 | } 56 | -------------------------------------------------------------------------------- /resources/icons/quit.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. --------------------------------------------------------------------------------