Qt 4.8
qdeclarativepackage.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "private/qdeclarativepackage_p.h"
43 
44 #include <private/qobject_p.h>
45 #include <private/qdeclarativeguard_p.h>
46 
48 
90 {
91 public:
93 
94  struct DataGuard : public QDeclarativeGuard<QObject>
95  {
99  // we assume priv will always be destroyed after objectDestroyed calls
100  list->removeOne(*this);
101  }
102  };
103 
106  QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data);
107  list->append(DataGuard(o, list));
108  }
110  QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data);
111  list->clear();
112  }
114  QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data);
115  return list->at(index);
116  }
118  QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data);
119  return list->count();
120  }
121 };
122 
124 
126 : QObject(parent)
127 {
128  attached.insert(parent, this);
129 }
130 
132 {
134 }
135 
137 {
138  return _name;
139 }
140 
142 {
143  _name = n;
144 }
145 
147  : QObject(*(new QDeclarativePackagePrivate), parent)
148 {
149 }
150 
152 {
154  for (int ii = 0; ii < d->dataList.count(); ++ii) {
155  QObject *obj = d->dataList.at(ii);
156  obj->setParent(this);
157  }
158 }
159 
161 {
167 }
168 
170 {
172  for (int ii = 0; ii < d->dataList.count(); ++ii) {
173  QObject *obj = d->dataList.at(ii);
174  QDeclarativePackageAttached *a = QDeclarativePackageAttached::attached.value(obj);
175  if (a && a->name() == name)
176  return true;
177  }
178  return false;
179 }
180 
182 {
184  if (name.isEmpty() && !d->dataList.isEmpty())
185  return d->dataList.at(0);
186 
187  for (int ii = 0; ii < d->dataList.count(); ++ii) {
188  QObject *obj = d->dataList.at(ii);
189  QDeclarativePackageAttached *a = QDeclarativePackageAttached::attached.value(obj);
190  if (a && a->name() == name)
191  return obj;
192  }
193 
194  if (name == QLatin1String("default") && !d->dataList.isEmpty())
195  return d->dataList.at(0);
196 
197  return 0;
198 }
199 
201 {
202  return new QDeclarativePackageAttached(o);
203 }
204 
205 
206 
double d
Definition: qnumeric_p.h:62
static QHash< QObject *, QDeclarativePackageAttached * > attached
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void data_clear(QDeclarativeListProperty< QObject > *prop)
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QDeclarativeListProperty< QObject > data()
QObject * part(const QString &=QString())
void clear()
Removes all items from the list.
Definition: qlist.h:764
QDeclarativePackage(QObject *parent=0)
static void data_append(QDeclarativeListProperty< QObject > *prop, QObject *o)
static QObject * data_at(QDeclarativeListProperty< QObject > *prop, int index)
DataGuard(QObject *obj, QList< DataGuard > *l)
void setName(const QString &n)
static QDeclarativePackageAttached * qmlAttachedProperties(QObject *)
This attached property holds the name of an item within a Package.
static int data_count(QDeclarativeListProperty< QObject > *prop)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QFactoryLoader * l
bool hasPart(const QString &)
quint16 index
QObject * parent
Definition: qobject.h:92
QDeclarativePackageAttached(QObject *parent)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62