WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZMap.cpp
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2016 Bob Dinitto
4  *
5  * Filename: ZMap.cpp
6  * Created on: 2/1/2016
7  * Author: Bob Dinitto
8  *
9  * Zuble is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #include "ZMap.h"
26 #include <QtQml>
27 
28 namespace Zbl
29 {
30 
31 ZMap::ZMap(QObject *parent) :
32  QObject(parent)
33 {
34 }
35 
37 {
38  qmlRegisterType<ZMap>("org.zuble.qml", 1, 0, "ZMap");
39 }
40 
42 {
43  return m_map.size();
44 }
45 
46 bool ZMap::has(const QString& key)
47 {
48  return m_map.contains(key);
49 }
50 
51 QJSValue ZMap::get(const QString& key)
52 {
53  return m_map.value(key);
54 }
55 
56 void ZMap::set(const QString& key, QJSValue value)
57 {
58  m_map.insert(key, value);
59 }
60 
61 bool ZMap::remove(const QString& key)
62 {
63  return m_map.remove(key) ? true : false;
64 }
65 
66 QVariantList ZMap::keys()
67 {
68  QList<QString> k = m_map.keys();
69 
70  const int count = k.count();
71 
72  QVariantList vk;
73 
74  for(int i=0; i<count; i++)
75  {
76  qDebug() << "mapkey = " << k.at(i);
77 
78  vk.append(QVariant(k.at(i)));
79  }
80 
81  for(int i = 0; i<vk.count(); i++)
82  qDebug() << "variant key = " << vk.at(i);
83 
84  return vk;
85 }
86 
88 {
89  m_map.clear();
90 }
91 
92 
93 
94 
95 } // Zbl
void clear()
Remove all key/value pairs from the map.
Definition: ZMap.cpp:87
Q_INVOKABLE QJSValue get(const QString &key)
Returns the value associated with a specified key in the map.
Definition: ZMap.cpp:51
Definition: ZAndGate.cpp:6
void set(const QString &key, QJSValue value)
Sets the specified key in the map to the specified value.
Definition: ZMap.cpp:56
Q_INVOKABLE QVariantList keys()
Obtain the key names in the map.
Definition: ZMap.cpp:66
ZMap(QObject *parent=0)
Definition: ZMap.cpp:31
bool remove(const QString &key)
Removes the specified key from the map.
Definition: ZMap.cpp:61
Q_INVOKABLE bool has(const QString &key)
Returns true if the map contains the specified key.
Definition: ZMap.cpp:46
int getSize()
Definition: ZMap.cpp:41
zMap m_map
Definition: ZMap.h:125
static void registerType()
Register ZMailbox as a QML type.
Definition: ZMap.cpp:36