src/declarative/graphicsitems/qdeclarativerepeater.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
    60         delete model;
    60         delete model;
    61 }
    61 }
    62 
    62 
    63 /*!
    63 /*!
    64     \qmlclass Repeater QDeclarativeRepeater
    64     \qmlclass Repeater QDeclarativeRepeater
       
    65     \ingroup qml-utility-elements
    65     \since 4.7
    66     \since 4.7
    66     \inherits Item
    67     \inherits Item
    67 
    68 
    68     \brief The Repeater element allows you to repeat an Item-based component using a model.
    69     \brief The Repeater element allows you to repeat an Item-based component using a model.
    69 
    70 
   131     consider using other view elements like ListView (which only creates delegate items 
   132     consider using other view elements like ListView (which only creates delegate items 
   132     when they are scrolled into view) or use the \l {Dynamic Object Creation} methods to 
   133     when they are scrolled into view) or use the \l {Dynamic Object Creation} methods to 
   133     create items as they are required.
   134     create items as they are required.
   134 
   135 
   135     Also, note that Repeater is \l {Item}-based, and can only repeat \l {Item}-derived objects. 
   136     Also, note that Repeater is \l {Item}-based, and can only repeat \l {Item}-derived objects. 
   136     For example, it cannot be used to repeat QtObjects:
   137     For example, it cannot be used to repeat QObjects:
   137     \badcode
   138     \badcode
   138     Item {
   139     Item {
   139         //XXX does not work! Can't repeat QtObject as it doesn't derive from Item.
   140         //XXX does not work! Can't repeat QObject as it doesn't derive from Item.
   140         Repeater {
   141         Repeater {
   141             model: 10
   142             model: 10
   142             QtObject {}
   143             QObject {}
   143         }
   144         }
   144     }
   145     }
   145     \endcode
   146     \endcode
   146  */
   147  */
   147 
   148 
   148 /*!
       
   149     \internal
       
   150     \class QDeclarativeRepeater
       
   151  */
       
   152 
       
   153 /*!
       
   154     Create a new QDeclarativeRepeater instance.
       
   155  */
       
   156 QDeclarativeRepeater::QDeclarativeRepeater(QDeclarativeItem *parent)
   149 QDeclarativeRepeater::QDeclarativeRepeater(QDeclarativeItem *parent)
   157   : QDeclarativeItem(*(new QDeclarativeRepeaterPrivate), parent)
   150   : QDeclarativeItem(*(new QDeclarativeRepeaterPrivate), parent)
   158 {
   151 {
   159 }
   152 }
   160 
   153 
   161 /*!
       
   162     Destroy the repeater instance.  All items it instantiated are also
       
   163     destroyed.
       
   164  */
       
   165 QDeclarativeRepeater::~QDeclarativeRepeater()
   154 QDeclarativeRepeater::~QDeclarativeRepeater()
   166 {
   155 {
   167 }
   156 }
   168 
   157 
   169 /*!
   158 /*!
   243         /*
   232         /*
   244         connect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*)));
   233         connect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*)));
   245         connect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*)));
   234         connect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*)));
   246         */
   235         */
   247         regenerate();
   236         regenerate();
   248         emit countChanged();
   237     }
   249     }
   238     emit countChanged();
   250 }
   239 }
   251 
   240 
   252 /*!
   241 /*!
   253     \qmlproperty Component Repeater::delegate
   242     \qmlproperty Component Repeater::delegate
   254     \default
   243     \default
   298         return d->model->count();
   287         return d->model->count();
   299     return 0;
   288     return 0;
   300 }
   289 }
   301 
   290 
   302 
   291 
   303 /*!
       
   304     \internal
       
   305  */
       
   306 void QDeclarativeRepeater::componentComplete()
   292 void QDeclarativeRepeater::componentComplete()
   307 {
   293 {
   308     QDeclarativeItem::componentComplete();
   294     QDeclarativeItem::componentComplete();
   309     regenerate();
   295     regenerate();
   310 }
   296 }
   311 
   297 
   312 /*!
       
   313     \internal
       
   314  */
       
   315 QVariant QDeclarativeRepeater::itemChange(GraphicsItemChange change,
   298 QVariant QDeclarativeRepeater::itemChange(GraphicsItemChange change,
   316                                        const QVariant &value)
   299                                        const QVariant &value)
   317 {
   300 {
   318     QVariant rv = QDeclarativeItem::itemChange(change, value);
   301     QVariant rv = QDeclarativeItem::itemChange(change, value);
   319     if (change == ItemParentHasChanged) {
   302     if (change == ItemParentHasChanged) {
   332         }
   315         }
   333     }
   316     }
   334     d->deletables.clear();
   317     d->deletables.clear();
   335 }
   318 }
   336 
   319 
   337 /*!
       
   338     \internal
       
   339  */
       
   340 void QDeclarativeRepeater::regenerate()
   320 void QDeclarativeRepeater::regenerate()
   341 {
   321 {
   342     Q_D(QDeclarativeRepeater);
   322     Q_D(QDeclarativeRepeater);
   343     if (!isComponentComplete())
   323     if (!isComponentComplete())
   344         return;
   324         return;
   375             else
   355             else
   376                 item->stackBefore(this);
   356                 item->stackBefore(this);
   377             d->deletables.insert(modelIndex, item);
   357             d->deletables.insert(modelIndex, item);
   378         }
   358         }
   379     }
   359     }
       
   360     emit countChanged();
   380 }
   361 }
   381 
   362 
   382 void QDeclarativeRepeater::itemsRemoved(int index, int count)
   363 void QDeclarativeRepeater::itemsRemoved(int index, int count)
   383 {
   364 {
   384     Q_D(QDeclarativeRepeater);
   365     Q_D(QDeclarativeRepeater);
   389         if (item)
   370         if (item)
   390             d->model->release(item);
   371             d->model->release(item);
   391         else
   372         else
   392             break;
   373             break;
   393     }
   374     }
       
   375     emit countChanged();
   394 }
   376 }
   395 
   377 
   396 void QDeclarativeRepeater::itemsMoved(int from, int to, int count)
   378 void QDeclarativeRepeater::itemsMoved(int from, int to, int count)
   397 {
   379 {
   398     Q_D(QDeclarativeRepeater);
   380     Q_D(QDeclarativeRepeater);
   418 void QDeclarativeRepeater::modelReset()
   400 void QDeclarativeRepeater::modelReset()
   419 {
   401 {
   420     if (!isComponentComplete())
   402     if (!isComponentComplete())
   421         return;
   403         return;
   422     regenerate();
   404     regenerate();
       
   405     emit countChanged();
   423 }
   406 }
   424 
   407 
   425 QT_END_NAMESPACE
   408 QT_END_NAMESPACE