Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 by Savoir-faire Linux |
| 3 | * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include <QObject> |
| 22 | |
| 23 | /* |
| 24 | * The main purpose of this class is to operate on qml objects, |
| 25 | * or provide api calls to qml objects that cannot be done directly in qml. |
| 26 | */ |
| 27 | class QmlAdapterBase : public QObject |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | public: |
| 31 | explicit QmlAdapterBase(QObject *parent = nullptr); |
| 32 | ~QmlAdapterBase(); |
| 33 | |
| 34 | /* |
| 35 | * This function should be called in the Component.onCompleted slot |
| 36 | * in the qml component that this adapter should attach to. |
| 37 | */ |
| 38 | Q_INVOKABLE void setQmlObject(QObject *obj); |
| 39 | |
| 40 | protected: |
| 41 | /* |
| 42 | *Once the qml object is set, custom actions can be done in this function. |
| 43 | */ |
| 44 | virtual void initQmlObject() = 0; |
| 45 | |
| 46 | /* |
| 47 | * Object pointer. |
| 48 | */ |
| 49 | QObject *qmlObj_; |
| 50 | }; |