| 1 |
/* This file is part of lomiri-action-api |
| 2 |
* Copyright 2013 Canonical Ltd. |
| 3 |
* |
| 4 |
* lomiri-action-api is free software: you can redistribute it and/or modify it |
| 5 |
* under the terms of the GNU Lesser General Public License version 3, |
| 6 |
* as published by the Free Software Foundation. |
| 7 |
* |
| 8 |
* lomiri-action-api is distributed in the hope that it will be useful, but |
| 9 |
* WITHOUT ANY WARRANTY; without even the implied warranties of |
| 10 |
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 11 |
* PURPOSE. See the GNU Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include "qml-context.h" |
| 18 |
|
| 19 |
using namespace lomiri::action; |
| 20 |
|
| 21 |
qml::ActionContext::ActionContext(QObject *parent) |
| 22 |
: lomiri::action::ActionContext(parent) |
| 23 |
{ |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
qml::ActionContext::~ActionContext() |
| 28 |
{ |
| 29 |
foreach(Action *action, actions()) { |
| 30 |
removeAction(action); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
QQmlListProperty<Action> |
| 35 |
qml::ActionContext::action_list() |
| 36 |
{ |
| 37 |
return QQmlListProperty<Action>(this, |
| 38 |
0, |
| 39 |
qml::ActionContext::append, |
| 40 |
qml::ActionContext::count, |
| 41 |
0, // at() |
| 42 |
qml::ActionContext::clear); |
| 43 |
} |
| 44 |
|
| 45 |
void |
| 46 |
qml::ActionContext::append(QQmlListProperty<Action> *list, |
| 47 |
Action *action) |
| 48 |
{ |
| 49 |
qml::ActionContext *ctx = qobject_cast<qml::ActionContext *>(list->object); |
| 50 |
if (ctx) { |
| 51 |
ctx->addAction(action); |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
Q_ASSERT(0); // should not be reached |
| 56 |
} |
| 57 |
|
| 58 |
void |
| 59 |
qml::ActionContext::clear(QQmlListProperty<Action> *list) |
| 60 |
{ |
| 61 |
qml::ActionContext *ctx = qobject_cast<qml::ActionContext *>(list->object); |
| 62 |
if (ctx) { |
| 63 |
foreach(Action *action, ctx->actions()) { |
| 64 |
ctx->removeAction(action); |
| 65 |
} |
| 66 |
return; |
| 67 |
} |
| 68 |
|
| 69 |
Q_ASSERT(0); // should not be reached |
| 70 |
} |
| 71 |
|
| 72 |
QQMLISTPROPERTY_INT |
| 73 |
qml::ActionContext::count(QQmlListProperty<Action> *list) |
| 74 |
{ |
| 75 |
qml::ActionContext *ctx = qobject_cast<qml::ActionContext *>(list->object); |
| 76 |
if (ctx) { |
| 77 |
return ctx->actions().count(); |
| 78 |
} |
| 79 |
|
| 80 |
Q_ASSERT(0); // should not be reached |
| 81 |
return 0; |
| 82 |
} |