src/script/api/qscriptclasspropertyiterator.cpp
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtScript module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "qscriptclasspropertyiterator.h"
       
    43 
       
    44 #include "qscriptstring.h"
       
    45 
       
    46 QT_BEGIN_NAMESPACE
       
    47 
       
    48 /*!
       
    49   \since 4.4
       
    50   \class QScriptClassPropertyIterator
       
    51 
       
    52   \brief The QScriptClassPropertyIterator class provides an iterator interface for custom Qt Script objects.
       
    53 
       
    54   \ingroup script
       
    55 
       
    56   This class is only relevant if you have subclassed QScriptClass and
       
    57   want to provide enumeration of your custom properties (e.g. when
       
    58   objects of your class are used with QScriptValueIterator, or with
       
    59   the for-in statement in scripts).
       
    60 
       
    61   The object() function returns the Qt Script object the iterator is
       
    62   traversing.
       
    63 
       
    64   toFront(), hasNext() and next() provide forward iteration.
       
    65 
       
    66   toBack(), hasPrevious() and previous() provide backward iteration.
       
    67 
       
    68   name(), id() and flags() return information about the last property
       
    69   that was jumped over using next() or previous().
       
    70 
       
    71   \sa QScriptClass::newIterator(), QScriptValueIterator
       
    72 */
       
    73 
       
    74 class QScriptClassPropertyIteratorPrivate
       
    75 {
       
    76     Q_DECLARE_PUBLIC(QScriptClassPropertyIterator)
       
    77 public:
       
    78     QScriptClassPropertyIteratorPrivate() {}
       
    79     virtual ~QScriptClassPropertyIteratorPrivate() {}
       
    80 
       
    81     QScriptValue object;
       
    82 
       
    83     QScriptClassPropertyIterator *q_ptr;
       
    84 };
       
    85 
       
    86 /*!
       
    87   Constructs an iterator for traversing \a object.
       
    88 
       
    89   Subclasses should ensure that the iterator is set to the front of the
       
    90   sequence of properties (before the first property).
       
    91 */
       
    92 QScriptClassPropertyIterator::QScriptClassPropertyIterator(const QScriptValue &object)
       
    93     : d_ptr(new QScriptClassPropertyIteratorPrivate)
       
    94 {
       
    95     d_ptr->q_ptr = this;
       
    96     d_ptr->object = object;
       
    97 }
       
    98 
       
    99 /*!
       
   100   \internal
       
   101 */
       
   102 QScriptClassPropertyIterator::QScriptClassPropertyIterator(const QScriptValue &object,
       
   103                                            QScriptClassPropertyIteratorPrivate &dd)
       
   104     : d_ptr(&dd)
       
   105 {
       
   106     d_ptr->q_ptr = this;
       
   107     d_ptr->object = object;
       
   108 }
       
   109 
       
   110 /*!
       
   111   Destroys the iterator.
       
   112 */
       
   113 QScriptClassPropertyIterator::~QScriptClassPropertyIterator()
       
   114 {
       
   115 }
       
   116 
       
   117 /*!
       
   118   Returns the Qt Script object this iterator is traversing.
       
   119 */
       
   120 QScriptValue QScriptClassPropertyIterator::object() const
       
   121 {
       
   122     Q_D(const QScriptClassPropertyIterator);
       
   123     return d->object;
       
   124 }
       
   125 
       
   126 /*!
       
   127   \fn bool QScriptClassPropertyIterator::hasNext() const
       
   128 
       
   129   Returns true if there is at least one item ahead of the iterator
       
   130   (i.e. the iterator is \e not at the back of the property sequence);
       
   131   otherwise returns false.
       
   132 
       
   133   \sa next(), hasPrevious()
       
   134 */
       
   135 
       
   136 /*!
       
   137   \fn void QScriptClassPropertyIterator::next()
       
   138 
       
   139   Advances the iterator by one position.
       
   140 
       
   141   Calling this function on an iterator located at the back of the
       
   142   container leads to undefined results.
       
   143 
       
   144   \sa hasNext(), previous(), name()
       
   145 */
       
   146 
       
   147 /*!
       
   148   \fn bool QScriptClassPropertyIterator::hasPrevious() const
       
   149 
       
   150   Returns true if there is at least one item behind the iterator
       
   151   (i.e. the iterator is \e not at the front of the property sequence);
       
   152   otherwise returns false.
       
   153 
       
   154   \sa previous(), hasNext()
       
   155 */
       
   156 
       
   157 /*!
       
   158   \fn void QScriptClassPropertyIterator::previous()
       
   159 
       
   160   Moves the iterator back by one position.
       
   161 
       
   162   Calling this function on an iterator located at the front of the
       
   163   container leads to undefined results.
       
   164 
       
   165   \sa hasPrevious(), next(), name()
       
   166 */
       
   167 
       
   168 /*!
       
   169   \fn void QScriptClassPropertyIterator::toFront()
       
   170 
       
   171   Moves the iterator to the front of the QScriptValue (before the
       
   172   first property).
       
   173 
       
   174   \sa toBack(), next()
       
   175 */
       
   176 
       
   177 /*!
       
   178   \fn void QScriptClassPropertyIterator::toBack()
       
   179 
       
   180   Moves the iterator to the back of the QScriptValue (after the
       
   181   last property).
       
   182 
       
   183   \sa toFront(), previous()
       
   184 */
       
   185 
       
   186 /*!
       
   187   \fn QScriptString QScriptClassPropertyIterator::name() const
       
   188 
       
   189   Returns the name of the last property that was jumped over using
       
   190   next() or previous().
       
   191 
       
   192   \sa id()
       
   193 */
       
   194 
       
   195 /*!
       
   196   \fn uint QScriptClassPropertyIterator::id() const
       
   197 
       
   198   Returns the id of the last property that was jumped over using
       
   199   next() or previous().
       
   200 
       
   201   The default implementation returns 0.
       
   202 
       
   203   \sa name()
       
   204 */
       
   205 uint QScriptClassPropertyIterator::id() const
       
   206 {
       
   207     return 0;
       
   208 }
       
   209 
       
   210 /*!
       
   211   Returns the flags of the last property that was jumped over using
       
   212   next() or previous().
       
   213 
       
   214   The default implementation calls the propertyFlags() function of
       
   215   object() with argument name().
       
   216 */
       
   217 QScriptValue::PropertyFlags QScriptClassPropertyIterator::flags() const
       
   218 {
       
   219     return object().propertyFlags(name());
       
   220 }
       
   221 
       
   222 QT_END_NAMESPACE