diff options
author | Matthew Vogt <matthew.vogt@nokia.com> | 2012-01-31 16:52:36 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-03 00:39:18 +0100 |
commit | 01dc7e2ea476e0e6dcdce2e72979bbc858f4057d (patch) | |
tree | d8796f7695bbf8ad42abf47cd84c1b5e000ef795 /src/qtquick1/graphicsitems/qdeclarativerepeater.cpp | |
parent | 5e07b57b818326da47a46d384415041fa4cea0ba (diff) |
Remove QtQuick1 elements from qtdeclarative
QtQuick1 is now contained in a separate repository.
Task-number: QTBUG-23737
Change-Id: I09eae67af5693a22b896b916f816f73ccc3a89b1
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/qtquick1/graphicsitems/qdeclarativerepeater.cpp')
-rw-r--r-- | src/qtquick1/graphicsitems/qdeclarativerepeater.cpp | 450 |
1 files changed, 0 insertions, 450 deletions
diff --git a/src/qtquick1/graphicsitems/qdeclarativerepeater.cpp b/src/qtquick1/graphicsitems/qdeclarativerepeater.cpp deleted file mode 100644 index 7e92d579e9..0000000000 --- a/src/qtquick1/graphicsitems/qdeclarativerepeater.cpp +++ /dev/null @@ -1,450 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "QtQuick1/private/qdeclarativerepeater_p.h" -#include "QtQuick1/private/qdeclarativerepeater_p_p.h" - -#include "QtQuick1/private/qdeclarativevisualitemmodel_p.h" -#include <QtDeclarative/private/qdeclarativeglobal_p.h> -#include <QtQuick1/private/qdeclarativelistaccessor_p.h> - -QT_BEGIN_NAMESPACE - - -QDeclarative1RepeaterPrivate::QDeclarative1RepeaterPrivate() -: model(0), ownModel(false) -{ -} - -QDeclarative1RepeaterPrivate::~QDeclarative1RepeaterPrivate() -{ - if (ownModel) - delete model; -} - -/*! - \qmlclass Repeater QDeclarative1Repeater - \inqmlmodule QtQuick 1 - \ingroup qml-utility-elements - \since QtQuick 1.0 - \inherits Item - - \brief The Repeater element allows you to repeat an Item-based component using a model. - - The Repeater element is used to create a large number of - similar items. Like other view elements, a Repeater has a \l model and a \l delegate: - for each entry in the model, the delegate is instantiated - in a context seeded with data from the model. A Repeater item is usually - enclosed in a positioner element such as \l Row or \l Column to visually - position the multiple delegate items created by the Repeater. - - The following Repeater creates three instances of a \l Rectangle item within - a \l Row: - - \snippet doc/src/snippets/qtquick1/repeaters/repeater.qml import - \codeline - \snippet doc/src/snippets/qtquick1/repeaters/repeater.qml simple - - \image repeater-simple.png - - A Repeater's \l model can be any of the supported \l {qmlmodels}{data models}. - Additionally, like delegates for other views, a Repeater delegate can access - its index within the repeater, as well as the model data relevant to the - delegate. See the \l delegate property documentation for details. - - Items instantiated by the Repeater are inserted, in order, as - children of the Repeater's parent. The insertion starts immediately after - the repeater's position in its parent stacking list. This allows - a Repeater to be used inside a layout. For example, the following Repeater's - items are stacked between a red rectangle and a blue rectangle: - - \snippet doc/src/snippets/qtquick1/repeaters/repeater.qml layout - - \image repeater.png - - - \note A Repeater item owns all items it instantiates. Removing or dynamically destroying - an item created by a Repeater results in unpredictable behavior. - - - \section2 Considerations when using Repeater - - The Repeater element creates all of its delegate items when the repeater is first - created. This can be inefficient if there are a large number of delegate items and - not all of the items are required to be visible at the same time. If this is the case, - consider using other view elements like ListView (which only creates delegate items - when they are scrolled into view) or use the \l {Dynamic Object Creation} methods to - create items as they are required. - - Also, note that Repeater is \l {Item}-based, and can only repeat \l {Item}-derived objects. - For example, it cannot be used to repeat QtObjects: - \badcode - Item { - //XXX does not work! Can't repeat QtObject as it doesn't derive from Item. - Repeater { - model: 10 - QtObject {} - } - } - \endcode - */ - -/*! - \qmlsignal QtQuick1::Repeater::onItemAdded(int index, Item item) - \since Quick 1.1 - - This handler is called when an item is added to the repeater. The \a index - parameter holds the index at which the item has been inserted within the - repeater, and the \a item parameter holds the \l Item that has been added. -*/ - -/*! - \qmlsignal QtQuick1::Repeater::onItemRemoved(int index, Item item) - \since Quick 1.1 - - This handler is called when an item is removed from the repeater. The \a index - parameter holds the index at which the item was removed from the repeater, - and the \a item parameter holds the \l Item that was removed. - - Do not keep a reference to \a item if it was created by this repeater, as - in these cases it will be deleted shortly after the handler is called. -*/ - -QDeclarative1Repeater::QDeclarative1Repeater(QDeclarativeItem *parent) - : QDeclarativeItem(*(new QDeclarative1RepeaterPrivate), parent) -{ -} - -QDeclarative1Repeater::~QDeclarative1Repeater() -{ -} - -/*! - \qmlproperty any QtQuick1::Repeater::model - - The model providing data for the repeater. - - This property can be set to any of the supported \l {qmlmodels}{data models}: - - \list - \o A number that indicates the number of delegates to be created by the repeater - \o A model (e.g. a ListModel item, or a QAbstractItemModel subclass) - \o A string list - \o An object list - \endlist - - The type of model affects the properties that are exposed to the \l delegate. - - \sa {qmlmodels}{Data Models} -*/ -QVariant QDeclarative1Repeater::model() const -{ - Q_D(const QDeclarative1Repeater); - return d->dataSource; -} - -void QDeclarative1Repeater::setModel(const QVariant &model) -{ - Q_D(QDeclarative1Repeater); - if (d->dataSource == model) - return; - - clear(); - if (d->model) { - disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); - disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); - disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); - disconnect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); - /* - disconnect(d->model, SIGNAL(createdItem(int,QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); - disconnect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); - */ - } - d->dataSource = model; - QObject *object = qvariant_cast<QObject*>(model); - QDeclarative1VisualModel *vim = 0; - if (object && (vim = qobject_cast<QDeclarative1VisualModel *>(object))) { - if (d->ownModel) { - delete d->model; - d->ownModel = false; - } - d->model = vim; - } else { - if (!d->ownModel) { - d->model = new QDeclarative1VisualDataModel(qmlContext(this), this); - d->ownModel = true; - } - if (QDeclarative1VisualDataModel *dataModel = qobject_cast<QDeclarative1VisualDataModel*>(d->model)) - dataModel->setModel(model); - } - if (d->model) { - connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); - connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); - connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); - connect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); - /* - connect(d->model, SIGNAL(createdItem(int,QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); - connect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); - */ - regenerate(); - } - emit modelChanged(); - emit countChanged(); -} - -/*! - \qmlproperty Component QtQuick1::Repeater::delegate - \default - - The delegate provides a template defining each item instantiated by the repeater. - - Delegates are exposed to a read-only \c index property that indicates the index - of the delegate within the repeater. For example, the following \l Text delegate - displays the index of each repeated item: - - \table - \row - \o \snippet doc/src/snippets/qtquick1/repeaters/repeater.qml index - \o \image repeater-index.png - \endtable - - If the \l model is a \l{QStringList-based model}{string list} or - \l{QObjectList-based model}{object list}, the delegate is also exposed to - a read-only \c modelData property that holds the string or object data. For - example: - - \table - \row - \o \snippet doc/src/snippets/qtquick1/repeaters/repeater.qml modeldata - \o \image repeater-modeldata.png - \endtable - - If the \l model is a model object (such as a \l ListModel) the delegate - can access all model roles as named properties, in the same way that delegates - do for view classes like ListView. - - \sa {QML Data Models} - */ -QDeclarativeComponent *QDeclarative1Repeater::delegate() const -{ - Q_D(const QDeclarative1Repeater); - if (d->model) { - if (QDeclarative1VisualDataModel *dataModel = qobject_cast<QDeclarative1VisualDataModel*>(d->model)) - return dataModel->delegate(); - } - - return 0; -} - -void QDeclarative1Repeater::setDelegate(QDeclarativeComponent *delegate) -{ - Q_D(QDeclarative1Repeater); - if (QDeclarative1VisualDataModel *dataModel = qobject_cast<QDeclarative1VisualDataModel*>(d->model)) - if (delegate == dataModel->delegate()) - return; - - if (!d->ownModel) { - d->model = new QDeclarative1VisualDataModel(qmlContext(this)); - d->ownModel = true; - } - if (QDeclarative1VisualDataModel *dataModel = qobject_cast<QDeclarative1VisualDataModel*>(d->model)) { - dataModel->setDelegate(delegate); - regenerate(); - emit delegateChanged(); - } -} - -/*! - \qmlproperty int QtQuick1::Repeater::count - - This property holds the number of items in the repeater. -*/ -int QDeclarative1Repeater::count() const -{ - Q_D(const QDeclarative1Repeater); - if (d->model) - return d->model->count(); - return 0; -} - -/*! - \qmlmethod Item QtQuick1::Repeater::itemAt(index) - \since Quick 1.1 - - Returns the \l Item that has been created at the given \a index, or \c null - if no item exists at \a index. -*/ -QDeclarativeItem *QDeclarative1Repeater::itemAt(int index) const -{ - Q_D(const QDeclarative1Repeater); - if (index >= 0 && index < d->deletables.count()) - return d->deletables[index]; - return 0; - -} - -void QDeclarative1Repeater::componentComplete() -{ - QDeclarativeItem::componentComplete(); - regenerate(); -} - -QVariant QDeclarative1Repeater::itemChange(GraphicsItemChange change, - const QVariant &value) -{ - QVariant rv = QDeclarativeItem::itemChange(change, value); - if (change == ItemParentHasChanged) { - regenerate(); - } - - return rv; -} - -void QDeclarative1Repeater::clear() -{ - Q_D(QDeclarative1Repeater); - bool complete = isComponentComplete(); - - if (d->model) { - while (d->deletables.count() > 0) { - QDeclarativeItem *item = d->deletables.takeLast(); - if (complete) - emit itemRemoved(d->deletables.count()-1, item); - d->model->release(item); - } - } - d->deletables.clear(); -} - -void QDeclarative1Repeater::regenerate() -{ - Q_D(QDeclarative1Repeater); - if (!isComponentComplete()) - return; - - clear(); - - if (!d->model || !d->model->count() || !d->model->isValid() || !parentItem() || !isComponentComplete()) - return; - - for (int ii = 0; ii < count(); ++ii) { - QDeclarativeItem *item = d->model->item(ii); - if (item) { - QDeclarative_setParent_noEvent(item, parentItem()); - item->setParentItem(parentItem()); - item->stackBefore(this); - d->deletables << item; - emit itemAdded(ii, item); - } - } -} - -void QDeclarative1Repeater::itemsInserted(int index, int count) -{ - Q_D(QDeclarative1Repeater); - if (!isComponentComplete()) - return; - for (int i = 0; i < count; ++i) { - int modelIndex = index + i; - QDeclarativeItem *item = d->model->item(modelIndex); - if (item) { - QDeclarative_setParent_noEvent(item, parentItem()); - item->setParentItem(parentItem()); - if (modelIndex < d->deletables.count()) - item->stackBefore(d->deletables.at(modelIndex)); - else - item->stackBefore(this); - d->deletables.insert(modelIndex, item); - emit itemAdded(modelIndex, item); - } - } - emit countChanged(); -} - -void QDeclarative1Repeater::itemsRemoved(int index, int count) -{ - Q_D(QDeclarative1Repeater); - if (!isComponentComplete() || count <= 0) - return; - while (count--) { - QDeclarativeItem *item = d->deletables.takeAt(index); - emit itemRemoved(index, item); - if (item) - d->model->release(item); - else - break; - } - emit countChanged(); -} - -void QDeclarative1Repeater::itemsMoved(int from, int to, int count) -{ - Q_D(QDeclarative1Repeater); - if (!isComponentComplete() || count <= 0) - return; - if (from + count > d->deletables.count()) { - regenerate(); - return; - } - QList<QDeclarativeItem*> removed; - int removedCount = count; - while (removedCount--) - removed << d->deletables.takeAt(from); - for (int i = 0; i < count; ++i) - d->deletables.insert(to + i, removed.at(i)); - d->deletables.last()->stackBefore(this); - for (int i = d->model->count()-1; i > 0; --i) { - QDeclarativeItem *item = d->deletables.at(i-1); - item->stackBefore(d->deletables.at(i)); - } -} - -void QDeclarative1Repeater::modelReset() -{ - if (!isComponentComplete()) - return; - regenerate(); - emit countChanged(); -} - - - -QT_END_NAMESPACE |