diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-08-24 01:12:59 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-08-24 01:12:59 (GMT) |
commit | 27f6749f80dffe3876e615997279f7dc13d02de7 (patch) | |
tree | 7de89ebf480a35f58b3f3756b2f8e9c2988cb4af /src | |
parent | 25aa10e773db72a66aa18dbd297bd24ad810e241 (diff) | |
parent | a33615e18719730a9f50fbd1221a7067c51abfd5 (diff) | |
download | Qt-27f6749f80dffe3876e615997279f7dc13d02de7.zip Qt-27f6749f80dffe3876e615997279f7dc13d02de7.tar.gz Qt-27f6749f80dffe3876e615997279f7dc13d02de7.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src')
123 files changed, 3891 insertions, 2721 deletions
diff --git a/src/3rdparty/webkit/JavaScriptCore/JavaScriptCore.pri b/src/3rdparty/webkit/JavaScriptCore/JavaScriptCore.pri index b43602e..d65095d 100644 --- a/src/3rdparty/webkit/JavaScriptCore/JavaScriptCore.pri +++ b/src/3rdparty/webkit/JavaScriptCore/JavaScriptCore.pri @@ -128,7 +128,7 @@ SOURCES += \ yarr/RegexJIT.cpp \ interpreter/RegisterFile.cpp -win32-*: SOURCES += jit/ExecutableAllocatorWin.cpp +win32-*|wince*: SOURCES += jit/ExecutableAllocatorWin.cpp else: SOURCES += jit/ExecutableAllocatorPosix.cpp # AllInOneFile.cpp helps gcc analize and optimize code diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp index fc11815..696a95a 100644 --- a/src/corelib/animation/qvariantanimation.cpp +++ b/src/corelib/animation/qvariantanimation.cpp @@ -137,7 +137,6 @@ QT_BEGIN_NAMESPACE \sa currentValue */ - static bool animationValueLessThan(const QVariantAnimation::KeyValue &p1, const QVariantAnimation::KeyValue &p2) { return p1.first < p2.first; @@ -178,11 +177,8 @@ template<> Q_INLINE_TEMPLATE QLineF _q_interpolate(const QLineF &f, const QLineF return QLineF( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress)); } -QVariantAnimationPrivate::QVariantAnimationPrivate() : duration(250), interpolator(&defaultInterpolator), - changedSignalMask(1 << QVariantAnimation::staticMetaObject.indexOfSignal("valueChanged(QVariant)")) -{ - //we keep the mask so that we emit valueChanged only when needed (for performance reasons) -} +QVariantAnimationPrivate::QVariantAnimationPrivate() : duration(250), interpolator(&defaultInterpolator) +{ } void QVariantAnimationPrivate::convertValues(int t) { @@ -278,7 +274,12 @@ void QVariantAnimationPrivate::setCurrentValueForProgress(const qreal progress) localProgress); qSwap(currentValue, ret); q->updateCurrentValue(currentValue); - if ((connectedSignals[0] & changedSignalMask) && currentValue != ret) { + static QBasicAtomicInt changedSignalIndex = Q_BASIC_ATOMIC_INITIALIZER(0); + if (!changedSignalIndex) { + //we keep the mask so that we emit valueChanged only when needed (for performance reasons) + changedSignalIndex.testAndSetRelaxed(0, signalIndex("valueChanged(QVariant)")); + } + if (isSignalConnected(changedSignalIndex) && currentValue != ret) { //the value has changed emit q->valueChanged(currentValue); } diff --git a/src/corelib/animation/qvariantanimation_p.h b/src/corelib/animation/qvariantanimation_p.h index ef57a4c..ce625f1 100644 --- a/src/corelib/animation/qvariantanimation_p.h +++ b/src/corelib/animation/qvariantanimation_p.h @@ -93,8 +93,6 @@ public: QVariantAnimation::Interpolator interpolator; - const quint32 changedSignalMask; - void setCurrentValueForProgress(const qreal progress); void recalculateCurrentInterval(bool force=false); void setValueAt(qreal, const QVariant &); diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index b150e22..52c507d 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -696,6 +696,7 @@ static void setup() (void)new QJisCodec; (void)new QSjisCodec; (void)new QEucKrCodec; + (void)new QCP949Codec; (void)new QBig5Codec; (void)new QBig5hkscsCodec; # endif // QT_NO_ICONV && !QT_BOOTSTRAPPED diff --git a/src/corelib/concurrent/qtconcurrentmap.cpp b/src/corelib/concurrent/qtconcurrentmap.cpp index 3fd044d..243921a 100644 --- a/src/corelib/concurrent/qtconcurrentmap.cpp +++ b/src/corelib/concurrent/qtconcurrentmap.cpp @@ -1,4 +1,4 @@ - /**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Nokia Corporation (qt-info@nokia.com) diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index f42a2ff..20e7845 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -487,7 +487,7 @@ QT_END_NAMESPACE extern const char qt_core_interpreter[] __attribute__((section(".interp"))) = ELF_INTERPRETER; -extern "C" +extern "C" void qt_core_boilerplate(); void qt_core_boilerplate() { printf("This is the QtCore library version " QT_VERSION_STR "\n" diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index ca178ce..fd1e367 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -2445,7 +2445,7 @@ QDebug operator<<(QDebug debug, QDir::Filters filters) return debug; } -QDebug operator<<(QDebug debug, QDir::SortFlags sorting) +static QDebug operator<<(QDebug debug, QDir::SortFlags sorting) { if (sorting == QDir::NoSort) { debug << "QDir::SortFlags(NoSort)"; diff --git a/src/corelib/kernel/qabstracteventdispatcher_p.h b/src/corelib/kernel/qabstracteventdispatcher_p.h index 86c9d79..dc69265 100644 --- a/src/corelib/kernel/qabstracteventdispatcher_p.h +++ b/src/corelib/kernel/qabstracteventdispatcher_p.h @@ -58,6 +58,8 @@ QT_BEGIN_NAMESPACE +Q_CORE_EXPORT uint qGlobalPostedEventsCount(); + class Q_CORE_EXPORT QAbstractEventDispatcherPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QAbstractEventDispatcher) diff --git a/src/corelib/kernel/qabstractitemmodel.cpp b/src/corelib/kernel/qabstractitemmodel.cpp index d6d1bcf..17af60d 100644 --- a/src/corelib/kernel/qabstractitemmodel.cpp +++ b/src/corelib/kernel/qabstractitemmodel.cpp @@ -251,8 +251,9 @@ QPersistentModelIndex::operator const QModelIndex&() const Returns true if this persistent model index refers to the same location as the \a other model index; otherwise returns false. - Note that all values in the persistent model index are used when comparing - with another model index. + + All values in the persistent model index are used when comparing with + another model index. */ bool QPersistentModelIndex::operator==(const QModelIndex &other) const @@ -335,10 +336,10 @@ qint64 QPersistentModelIndex::internalId() const } /*! - Returns the parent QModelIndex for this persistent index, or - QModelIndex() if it has no parent. + Returns the parent QModelIndex for this persistent index, or an invalid + QModelIndex if it has no parent. - \sa child() sibling() model() + \sa child() sibling() model() */ QModelIndex QPersistentModelIndex::parent() const { @@ -348,10 +349,10 @@ QModelIndex QPersistentModelIndex::parent() const } /*! - Returns the sibling at \a row and \a column or an invalid - QModelIndex if there is no sibling at this position. + Returns the sibling at \a row and \a column or an invalid QModelIndex if + there is no sibling at this position. - \sa parent() child() + \sa parent() child() */ QModelIndex QPersistentModelIndex::sibling(int row, int column) const @@ -362,10 +363,10 @@ QModelIndex QPersistentModelIndex::sibling(int row, int column) const } /*! - Returns the child of the model index that is stored in the given - \a row and \a column. + Returns the child of the model index that is stored in the given \a row + and \a column. - \sa parent() sibling() + \sa parent() sibling() */ QModelIndex QPersistentModelIndex::child(int row, int column) const @@ -376,9 +377,10 @@ QModelIndex QPersistentModelIndex::child(int row, int column) const } /*! - Returns the data for the given \a role for the item referred to by the index. + Returns the data for the given \a role for the item referred to by the + index. - \sa Qt::ItemDataRole, QAbstractItemModel::setData() + \sa Qt::ItemDataRole, QAbstractItemModel::setData() */ QVariant QPersistentModelIndex::data(int role) const { @@ -388,9 +390,9 @@ QVariant QPersistentModelIndex::data(int role) const } /*! - \since 4.2 + \since 4.2 - Returns the flags for the item referred to by the index. + Returns the flags for the item referred to by the index. */ Qt::ItemFlags QPersistentModelIndex::flags() const { @@ -400,7 +402,7 @@ Qt::ItemFlags QPersistentModelIndex::flags() const } /*! - Returns the model that the index belongs to. + Returns the model that the index belongs to. */ const QAbstractItemModel *QPersistentModelIndex::model() const { @@ -414,7 +416,9 @@ const QAbstractItemModel *QPersistentModelIndex::model() const Returns true if this persistent model index is valid; otherwise returns false. - A valid index belongs to a model, and has non-negative row and column numbers. + + A valid index belongs to a model, and has non-negative row and column + numbers. \sa model(), row(), column() */ @@ -760,44 +764,42 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, selection models to locate an item in the model. New QModelIndex objects are created by the model using the - QAbstractItemModel::createIndex() function. An \e invalid model index - can be constructed with the QModelIndex constructor. Invalid indexes are - often used as parent indexes when referring to top-level items in a model. + QAbstractItemModel::createIndex() function. An \e invalid model index can + be constructed with the QModelIndex constructor. Invalid indexes are often + used as parent indexes when referring to top-level items in a model. Model indexes refer to items in models, and contain all the information required to specify their locations in those models. Each index is located - in a given row and column, and may have a parent index; use row(), column(), - and parent() to obtain this information. Each top-level item in a model is - represented by a model index that does not have a parent index - in this - case, parent() will return an invalid model index, equivalent to an index - constructed with the zero argument form of the QModelIndex() constructor. + in a given row and column, and may have a parent index; use row(), + column(), and parent() to obtain this information. Each top-level item in a + model is represented by a model index that does not have a parent index - + in this case, parent() will return an invalid model index, equivalent to an + index constructed with the zero argument form of the QModelIndex() + constructor. To obtain a model index that refers to an existing item in a model, call - QAbstractItemModel::index() with the required row and column - values, and the model index of the parent. When referring to - top-level items in a model, supply QModelIndex() as the parent index. + QAbstractItemModel::index() with the required row and column values, and + the model index of the parent. When referring to top-level items in a + model, supply QModelIndex() as the parent index. The model() function returns the model that the index references as a - QAbstractItemModel. - The child() function is used to examine the items held beneath the index - in the model. - The sibling() function allows you to traverse items in the model on the - same level as the index. + QAbstractItemModel. The child() function is used to examine items held + under the index in the model. The sibling() function allows you to traverse + items in the model on the same level as the index. \note Model indexes should be used immediately and then discarded. You should not rely on indexes to remain valid after calling model functions that change the structure of the model or delete items. If you need to keep a model index over time use a QPersistentModelIndex. - \sa \link model-view-programming.html Model/View Programming\endlink QPersistentModelIndex QAbstractItemModel + \sa {Model/View Programming}, QPersistentModelIndex, QAbstractItemModel */ /*! \fn QModelIndex::QModelIndex() - Creates a new empty model index. - This type of model index is used to indicate - that the position in the model is invalid. + Creates a new empty model index. This type of model index is used to + indicate that the position in the model is invalid. \sa isValid() QAbstractItemModel */ @@ -860,7 +862,9 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, \fn bool QModelIndex::isValid() const Returns true if this model index is valid; otherwise returns false. - A valid index belongs to a model, and has non-negative row and column numbers. + + A valid index belongs to a model, and has non-negative row and column + numbers. \sa model(), row(), column() */ @@ -871,33 +875,34 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, Returns a pointer to the model containing the item that this index refers to. - You receive a const pointer to the model because calls to - non-const functions of the model might invalidate the model index - - and possibly crash your application. + A const pointer to the model is returned because calls to non-const + functions of the model might invalidate the model index and possibly + crash your application. */ /*! \fn QModelIndex QModelIndex::sibling(int row, int column) const - Returns the sibling at \a row and \a column or an invalid - QModelIndex if there is no sibling at this position. + Returns the sibling at \a row and \a column. If there is no sibling at this + position, an invalid QModelIndex is returned. - \sa parent() child() + \sa parent(), child() */ /*! \fn QModelIndex QModelIndex::child(int row, int column) const - Returns the child of the model index that is stored in the given - \a row and \a column. + Returns the child of the model index that is stored in the given \a row and + \a column. - \sa parent() sibling() + \sa parent(), sibling() */ /*! \fn QVariant QModelIndex::data(int role) const - Returns the data for the given \a role for the item referred to by the index. + Returns the data for the given \a role for the item referred to by the + index. */ /*! @@ -910,28 +915,29 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, /*! \fn bool QModelIndex::operator==(const QModelIndex &other) const - Returns true if this model index refers to the same location as - the \a other model index; otherwise returns false. - Note that all values in the model index are used when comparing - with another model index. + Returns true if this model index refers to the same location as the + \a other model index; otherwise returns false. + + All values in the model index are used when comparing with another model + index. */ /*! \fn bool QModelIndex::operator!=(const QModelIndex &other) const - Returns true if this model index does not refer to the same - location as the \a other model index; otherwise returns false. + Returns true if this model index does not refer to the same location as + the \a other model index; otherwise returns false. */ /*! - \fn QModelIndex QModelIndex::parent() const + \fn QModelIndex QModelIndex::parent() const - Returns the parent of the model index, or QModelIndex() if it has no - parent. + Returns the parent of the model index, or QModelIndex() if it has no + parent. - \sa child() sibling() model() + \sa child(), sibling(), model() */ /*! @@ -960,7 +966,7 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, simple table of rows and columns. Each item has a unique index specified by a QModelIndex. - \img modelindex-no-parent.png + \image modelindex-no-parent.png Every item of data that can be accessed via a model has an associated model index. You can obtain this model index using the index() function. Each @@ -1078,9 +1084,8 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, \sa {Model Classes}, {Model Subclassing Reference}, QModelIndex, QAbstractItemView, {Using Drag and Drop with Item Views}, - {Simple DOM Model Example}, - {Simple Tree Model Example}, {Editable Tree Model Example}, - {Fetch More Example} + {Simple DOM Model Example}, {Simple Tree Model Example}, + {Editable Tree Model Example}, {Fetch More Example} */ /*! @@ -1089,8 +1094,9 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, Returns the index of the item in the model specified by the given \a row, \a column and \a parent index. - When reimplementing this function in a subclass, call createIndex() to generate - model indexes that other components can use to refer to items in your model. + When reimplementing this function in a subclass, call createIndex() to + generate model indexes that other components can use to refer to items in + your model. \sa createIndex() */ @@ -1099,8 +1105,9 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, \fn bool QAbstractItemModel::insertColumn(int column, const QModelIndex &parent) Inserts a single column before the given \a column in the child items of - the \a parent specified. Returns true if the column is inserted; otherwise - returns false. + the \a parent specified. + + Returns true if the column is inserted; otherwise returns false. \sa insertColumns() insertRow() removeColumn() */ @@ -1109,8 +1116,9 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, \fn bool QAbstractItemModel::insertRow(int row, const QModelIndex &parent) Inserts a single row before the given \a row in the child items of the - \a parent specified. Returns true if the row is inserted; otherwise - returns false. + \a parent specified. + + Returns true if the row is inserted; otherwise returns false. \sa insertRows() insertColumn() removeRow() */ @@ -1123,17 +1131,18 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, /*! \fn QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const = 0 - Returns the parent of the model item with the given \a index, or QModelIndex() - if it has no parent. + Returns the parent of the model item with the given \a index. If the model + has no parent, an invalid QModelIndex is returned. A common convention used in models that expose tree data structures is that - only items in the first column have children. For that case, when reimplementing - this function in a subclass the column of the returned QModelIndex would be 0. + only items in the first column have children. For that case, when + reimplementing this function in a subclass the column of the returned + QModelIndex would be 0. - \note When reimplementing this function in a subclass, be careful to avoid + When reimplementing this function in a subclass, be careful to avoid calling QModelIndex member functions, such as QModelIndex::parent(), since - indexes belonging to your model will simply call your implementation, leading - to infinite recursion. + indexes belonging to your model will simply call your implementation, + leading to infinite recursion. \sa createIndex() */ @@ -1141,7 +1150,9 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, /*! \fn bool QAbstractItemModel::removeColumn(int column, const QModelIndex &parent) - Removes the given \a column from the child items of the \a parent specified. + Removes the given \a column from the child items of the \a parent + specified. + Returns true if the column is removed; otherwise returns false. \sa removeColumns(), removeRow(), insertColumn() @@ -1151,10 +1162,11 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, \fn bool QAbstractItemModel::removeRow(int row, const QModelIndex &parent) Removes the given \a row from the child items of the \a parent specified. + Returns true if the row is removed; otherwise returns false. - The removeRow() is a convenience function that calls removeRows(). - The QAbstractItemModel implementation of removeRows does nothing. + This is a convenience function that calls removeRows(). The + QAbstractItemModel implementation of removeRows() does nothing. \sa removeRows(), removeColumn(), insertRow() */ @@ -1166,13 +1178,12 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, indicates whether the horizontal or vertical header has changed. The sections in the header from the \a first to the \a last need to be updated. - Note that this signal must be emitted explicitly when - reimplementing the setHeaderData() function. + When reimplementing the setHeaderData() function, this signal must be + emitted explicitly. - If you are changing the number of columns or rows you don't need - to emit this signal, but use the begin/end functions (see the - section on subclassing in the QAbstractItemModel class description - for details). + If you are changing the number of columns or rows you do not need to emit + this signal, but use the begin/end functions (refer to the section on + subclassing in the QAbstractItemModel class description for details). \sa headerData(), setHeaderData(), dataChanged() */ @@ -1182,8 +1193,8 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, \since 4.2 This signal is emitted just before the layout of a model is changed. - Components connected to this signal use it to adapt to changes - in the model's layout. + Components connected to this signal use it to adapt to changes in the + model's layout. Subclasses should update any persistent model indexes after emitting layoutAboutToBeChanged(). @@ -1195,19 +1206,20 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, \fn void QAbstractItemModel::layoutChanged() This signal is emitted whenever the layout of items exposed by the model - has changed; for example, when the model has been sorted. When this signal is - received by a view, it should update the layout of items to reflect this + has changed; for example, when the model has been sorted. When this signal + is received by a view, it should update the layout of items to reflect this change. - When subclassing QAbstractItemModel or QAbstractProxyModel, ensure that - you emit layoutAboutToBeChanged() before changing the order of items or + When subclassing QAbstractItemModel or QAbstractProxyModel, ensure that you + emit layoutAboutToBeChanged() before changing the order of items or altering the structure of the data you expose to views, and emit layoutChanged() after changing the layout. - Subclasses should update any persistent model indexes before - emitting layoutChanged(). + Subclasses should update any persistent model indexes before emitting + layoutChanged(). - \sa layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), reset(), changePersistentIndex() + \sa layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), reset(), + changePersistentIndex() */ /*! @@ -1237,12 +1249,12 @@ QAbstractItemModel::~QAbstractItemModel() /*! \fn QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const - Returns the sibling at \a row and \a column for the item at \a index, or - an invalid QModelIndex if there is no sibling at that location. + Returns the sibling at \a row and \a column for the item at \a index, or an + invalid QModelIndex if there is no sibling at that location. sibling() is just a convenience function that finds the item's parent, and - uses it to retrieve the index of the child item in the specified \a row - and \a column. + uses it to retrieve the index of the child item in the specified \a row and + \a column. \sa index(), QModelIndex::row(), QModelIndex::column() */ @@ -1251,11 +1263,11 @@ QAbstractItemModel::~QAbstractItemModel() /*! \fn int QAbstractItemModel::rowCount(const QModelIndex &parent) const - Returns the number of rows under the given \a parent. When the parent - is valid it means that rowCount is returning the number of children of parent. + Returns the number of rows under the given \a parent. When the parent is + valid it means that rowCount is returning the number of children of parent. - \bold{Tip:} When implementing a table based model, rowCount() should return 0 when - the parent is valid. + \note When implementing a table based model, rowCount() should return 0 + when the parent is valid. \sa columnCount() */ @@ -1265,13 +1277,14 @@ QAbstractItemModel::~QAbstractItemModel() Returns the number of columns for the children of the given \a parent. - In most subclasses, the number of columns is independent of the - \a parent. For example: + In most subclasses, the number of columns is independent of the \a parent. + + For example: \snippet examples/itemviews/simpledommodel/dommodel.cpp 2 - \bold{Tip:} When implementing a table based model, columnCount() should return 0 when - the parent is valid. + \note When implementing a table based model, columnCount() should return 0 + when the parent is valid. \sa rowCount() */ @@ -1298,8 +1311,8 @@ QAbstractItemModel::~QAbstractItemModel() model. The new items are those between \a start and \a end inclusive, under the given \a parent item. - \bold{Note:} Components connected to this signal use it to adapt to changes - in the model's dimensions. It can only be emitted by the QAbstractItemModel + \note Components connected to this signal use it to adapt to changes in the + model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code. \sa insertRows(), beginInsertRows() @@ -1308,11 +1321,11 @@ QAbstractItemModel::~QAbstractItemModel() /*! \fn void QAbstractItemModel::rowsAboutToBeInserted(const QModelIndex &parent, int start, int end) - This signal is emitted just before rows are inserted into the - model. The new items will be positioned between \a start and \a end - inclusive, under the given \a parent item. + This signal is emitted just before rows are inserted into the model. The + new items will be positioned between \a start and \a end inclusive, under + the given \a parent item. - \bold{Note:} Components connected to this signal use it to adapt to changes + \note Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code. @@ -1322,11 +1335,11 @@ QAbstractItemModel::~QAbstractItemModel() /*! \fn void QAbstractItemModel::rowsRemoved(const QModelIndex &parent, int start, int end) - This signal is emitted after rows have been removed from the - model. The removed items are those between \a start and \a end - inclusive, under the given \a parent item. + This signal is emitted after rows have been removed from the model. The + removed items are those between \a start and \a end inclusive, under the + given \a parent item. - \bold{Note:} Components connected to this signal use it to adapt to changes + \note Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code. @@ -1336,11 +1349,11 @@ QAbstractItemModel::~QAbstractItemModel() /*! \fn void QAbstractItemModel::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) - This signal is emitted just before rows are removed from the - model. The items that will be removed are those between \a start and \a end - inclusive, under the given \a parent item. + This signal is emitted just before rows are removed from the model. The + items that will be removed are those between \a start and \a end inclusive, + under the given \a parent item. - \bold{Note:} Components connected to this signal use it to adapt to changes + \note Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code. @@ -1350,12 +1363,12 @@ QAbstractItemModel::~QAbstractItemModel() /*! \fn void QAbstractItemModel::columnsInserted(const QModelIndex &parent, int start, int end) - This signal is emitted after columns have been inserted into the - model. The new items are those between \a start and \a end - inclusive, under the given \a parent item. + This signal is emitted after columns have been inserted into the model. The + new items are those between \a start and \a end inclusive, under the given + \a parent item. - \bold{Note:} Components connected to this signal use it to adapt to changes - in the model's dimensions. It can only be emitted by the QAbstractItemModel + \note Components connected to this signal use it to adapt to changes in the + model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code. \sa insertColumns(), beginInsertColumns() @@ -1364,12 +1377,12 @@ QAbstractItemModel::~QAbstractItemModel() /*! \fn void QAbstractItemModel::columnsAboutToBeInserted(const QModelIndex &parent, int start, int end) - This signal is emitted just before columns are inserted into the - model. The new items will be positioned between \a start and \a end - inclusive, under the given \a parent item. + This signal is emitted just before columns are inserted into the model. The + new items will be positioned between \a start and \a end inclusive, under + the given \a parent item. - \bold{Note:} Components connected to this signal use it to adapt to changes - in the model's dimensions. It can only be emitted by the QAbstractItemModel + \note Components connected to this signal use it to adapt to changes in the + model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code. \sa insertColumns(), beginInsertColumns() @@ -1378,12 +1391,12 @@ QAbstractItemModel::~QAbstractItemModel() /*! \fn void QAbstractItemModel::columnsRemoved(const QModelIndex &parent, int start, int end) - This signal is emitted after columns have been removed from the - model. The removed items are those between \a start and \a end - inclusive, under the given \a parent item. + This signal is emitted after columns have been removed from the model. + The removed items are those between \a start and \a end inclusive, + under the given \a parent item. - \bold{Note:} Components connected to this signal use it to adapt to changes - in the model's dimensions. It can only be emitted by the QAbstractItemModel + \note Components connected to this signal use it to adapt to changes in + the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code. \sa removeColumns(), beginRemoveColumns() @@ -1392,20 +1405,20 @@ QAbstractItemModel::~QAbstractItemModel() /*! \fn void QAbstractItemModel::columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end) - This signal is emitted just before columns are removed - from the model. The items to be removed are those between \a start and - \a end inclusive, under the given \a parent item. + This signal is emitted just before columns are removed from the model. The + items to be removed are those between \a start and \a end inclusive, under + the given \a parent item. - \bold{Note:} Components connected to this signal use it to adapt to changes - in the model's dimensions. It can only be emitted by the QAbstractItemModel + \note Components connected to this signal use it to adapt to changes in the + model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code. \sa removeColumns(), beginRemoveColumns() */ /*! - Returns true if the model returns a valid QModelIndex for \a row and - \a column with \a parent, otherwise returns false. + Returns true if the model returns a valid QModelIndex for \a row and + \a column with \a parent, otherwise returns false. */ bool QAbstractItemModel::hasIndex(int row, int column, const QModelIndex &parent) const { @@ -1416,10 +1429,11 @@ bool QAbstractItemModel::hasIndex(int row, int column, const QModelIndex &parent /*! - Returns true if \a parent has any children; otherwise returns false. - Use rowCount() on the parent to find out the number of children. + Returns true if \a parent has any children; otherwise returns false. - \sa parent() index() + Use rowCount() on the parent to find out the number of children. + + \sa parent() index() */ bool QAbstractItemModel::hasChildren(const QModelIndex &parent) const { @@ -1428,11 +1442,11 @@ bool QAbstractItemModel::hasChildren(const QModelIndex &parent) const /*! - Returns a map with values for all predefined roles in the model - for the item at the given \a index. + Returns a map with values for all predefined roles in the model for the + item at the given \a index. - Reimplemented this function if you want to extend the default behavior - of this function to include custom roles in the map. + Reimplement this function if you want to extend the default behavior of + this function to include custom roles in the map. \sa Qt::ItemDataRole, data() */ @@ -1449,14 +1463,14 @@ QMap<int, QVariant> QAbstractItemModel::itemData(const QModelIndex &index) const /*! Sets the \a role data for the item at \a index to \a value. + Returns true if successful; otherwise returns false. - The dataChanged() signal should be emitted if the data was successfully set. + The dataChanged() signal should be emitted if the data was successfully + set. - The base class implementation returns false. This function and - data() must be reimplemented for editable models. Note that the - dataChanged() signal must be emitted explicitly when - reimplementing this function. + The base class implementation returns false. This function and data() must + be reimplemented for editable models. \sa Qt::ItemDataRole, data(), itemData() */ @@ -1475,15 +1489,16 @@ bool QAbstractItemModel::setData(const QModelIndex &index, const QVariant &value by the \a index. \note If you do not have a value to return, return an \bold invalid - QVariant() instead of returning 0. + QVariant instead of returning 0. \sa Qt::ItemDataRole, setData(), headerData() */ /*! Sets the role data for the item at \a index to the associated value in - \a roles, for every Qt::ItemDataRole. Returns true if successful; otherwise - returns false. + \a roles, for every Qt::ItemDataRole. + + Returns true if successful; otherwise returns false. Roles that are not in \a roles will not be modified. @@ -1498,8 +1513,8 @@ bool QAbstractItemModel::setItemData(const QModelIndex &index, const QMap<int, Q } /*! - Returns a list of MIME types that can be used to describe a list of - model indexes. + Returns a list of MIME types that can be used to describe a list of model + indexes. \sa mimeData() */ @@ -1511,12 +1526,12 @@ QStringList QAbstractItemModel::mimeTypes() const } /*! - Returns an object that contains serialized items of data corresponding to the - list of \a indexes specified. The formats used to describe the encoded data - is obtained from the mimeTypes() function. + Returns an object that contains serialized items of data corresponding to + the list of \a indexes specified. The formats used to describe the encoded + data is obtained from the mimeTypes() function. - If the list of indexes is empty, or there are no supported MIME types, - 0 is returned rather than a serialized empty list. + If the list of indexes is empty, or there are no supported MIME types, 0 is + returned rather than a serialized empty list. \sa mimeTypes(), dropMimeData() */ @@ -1538,22 +1553,23 @@ QMimeData *QAbstractItemModel::mimeData(const QModelIndexList &indexes) const /*! Handles the \a data supplied by a drag and drop operation that ended with - the given \a action. Returns true if the data and action can be handled - by the model; otherwise returns false. + the given \a action. - Although the specified \a row, \a column and \a parent indicate the location of - an item in the model where the operation ended, it is the responsibility of the - view to provide a suitable location for where the data should be inserted. + Returns true if the data and action can be handled by the model; otherwise + returns false. - For instance, a drop action on an item in a QTreeView can result in new items - either being inserted as children of the item specified by \a row, \a column, - and \a parent, or as siblings of the item. + Although the specified \a row, \a column and \a parent indicate the + location of an item in the model where the operation ended, it is the + responsibility of the view to provide a suitable location for where the + data should be inserted. - When row and column are -1 it means that it is up to the model to decide - where to place the data. This can occur in a tree when data is dropped - on a parent. Models will usually append the data to the parent in this case. + For instance, a drop action on an item in a QTreeView can result in new + items either being inserted as children of the item specified by \a row, + \a column, and \a parent, or as siblings of the item. - Returns true if the dropping was successful otherwise false. + When row and column are -1 it means that it is up to the model to decide + where to place the data. This can occur in a tree when data is dropped on + a parent. Models will usually append the data to the parent in this case. \sa supportedDropActions(), {Using Drag and Drop with Item Views} */ @@ -1583,17 +1599,17 @@ bool QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction acti } /*! - \since 4.2 + \since 4.2 - Returns the drop actions supported by this model. + Returns the drop actions supported by this model. - The default implementation returns Qt::CopyAction. Reimplement this - function if you wish to support additional actions. Note that you - must also reimplement the dropMimeData() function to handle the - additional operations. + The default implementation returns Qt::CopyAction. Reimplement this + function if you wish to support additional actions. You must also + reimplement the dropMimeData() function to handle the additional + operations. - \sa dropMimeData(), Qt::DropActions, {Using Drag and Drop with Item - Views} + \sa dropMimeData(), Qt::DropActions, {Using Drag and Drop with Item + Views} */ Qt::DropActions QAbstractItemModel::supportedDropActions() const { @@ -1601,15 +1617,15 @@ Qt::DropActions QAbstractItemModel::supportedDropActions() const } /*! - Returns the actions supported by the data in this model. + Returns the actions supported by the data in this model. - The default implementation returns supportedDropActions() unless - specific values have been set with setSupportedDragActions(). + The default implementation returns supportedDropActions() unless specific + values have been set with setSupportedDragActions(). - supportedDragActions() is used by QAbstractItemView::startDrag() as - the default values when a drag occurs. + supportedDragActions() is used by QAbstractItemView::startDrag() as the + default values when a drag occurs. - \sa Qt::DropActions, {Using Drag and Drop with Item Views} + \sa Qt::DropActions, {Using Drag and Drop with Item Views} */ Qt::DropActions QAbstractItemModel::supportedDragActions() const { @@ -1634,25 +1650,28 @@ void QAbstractItemModel::setSupportedDragActions(Qt::DropActions actions) } /*! - On models that support this, inserts \a count rows into the model before the - given \a row. The items in the new row will be children of the item - represented by the \a parent model index. + On models that support this, inserts \a count rows into the model before + the given \a row. Items in the new row will be children of the item + represented by the \a parent model index. - If \a row is 0, the rows are prepended to any existing rows in the parent. - If \a row is rowCount(), the rows are appended to any existing rows in the - parent. - If \a parent has no children, a single column with \a count rows is inserted. + If \a row is 0, the rows are prepended to any existing rows in the parent. - Returns true if the rows were successfully inserted; otherwise returns - false. + If \a row is rowCount(), the rows are appended to any existing rows in the + parent. - The base class implementation does nothing and returns false. + If \a parent has no children, a single column with \a count rows is + inserted. - If you implement your own model, you can reimplement this function - if you want to support insertions. Alternatively, you can provide - you own API for altering the data. + Returns true if the rows were successfully inserted; otherwise returns + false. + + The base class implementation does nothing and returns false. - \sa insertColumns(), removeRows(), beginInsertRows(), endInsertRows() + If you implement your own model, you can reimplement this function if you + want to support insertions. Alternatively, you can provide your own API for + altering the data. + + \sa insertColumns(), removeRows(), beginInsertRows(), endInsertRows() */ bool QAbstractItemModel::insertRows(int, int, const QModelIndex &) { @@ -1660,25 +1679,28 @@ bool QAbstractItemModel::insertRows(int, int, const QModelIndex &) } /*! - On models that support this, inserts \a count new columns into the model - before the given \a column. The items in each new column will be children - of the item represented by the \a parent model index. + On models that support this, inserts \a count new columns into the model + before the given \a column. The items in each new column will be children + of the item represented by the \a parent model index. + + If \a column is 0, the columns are prepended to any existing columns. + + If \a column is columnCount(), the columns are appended to any existing + columns. - If \a column is 0, the columns are prepended to any existing columns. - If \a column is columnCount(), the columns are appended to any existing - columns. - If \a parent has no children, a single row with \a count columns is inserted. + If \a parent has no children, a single row with \a count columns is + inserted. - Returns true if the columns were successfully inserted; otherwise returns - false. + Returns true if the columns were successfully inserted; otherwise returns + false. - The base class implementation does nothing and returns false. + The base class implementation does nothing and returns false. - If you implement your own model, you can reimplement this function - if you want to support insertions. Alternatively, you can provide - you own API for altering the data. + If you implement your own model, you can reimplement this function if you + want to support insertions. Alternatively, you can provide your own API for + altering the data. - \sa insertRows(), removeColumns(), beginInsertColumns(), endInsertColumns() + \sa insertRows(), removeColumns(), beginInsertColumns(), endInsertColumns() */ bool QAbstractItemModel::insertColumns(int, int, const QModelIndex &) { @@ -1687,16 +1709,19 @@ bool QAbstractItemModel::insertColumns(int, int, const QModelIndex &) /*! On models that support this, removes \a count rows starting with the given - \a row under parent \a parent from the model. Returns true if the rows - were successfully removed; otherwise returns false. + \a row under parent \a parent from the model. + + Returns true if the rows were successfully removed; otherwise returns + false. The base class implementation does nothing and returns false. - If you implement your own model, you can reimplement this function - if you want to support removing. Alternatively, you can provide - you own API for altering the data. + If you implement your own model, you can reimplement this function if you + want to support removing. Alternatively, you can provide your own API for + altering the data. - \sa removeRow(), removeColumns(), insertColumns(), beginRemoveRows(), endRemoveRows() + \sa removeRow(), removeColumns(), insertColumns(), beginRemoveRows(), + endRemoveRows() */ bool QAbstractItemModel::removeRows(int, int, const QModelIndex &) { @@ -1705,16 +1730,19 @@ bool QAbstractItemModel::removeRows(int, int, const QModelIndex &) /*! On models that support this, removes \a count columns starting with the - given \a column under parent \a parent from the model. Returns true if the - columns were successfully removed; otherwise returns false. + given \a column under parent \a parent from the model. + + Returns true if the columns were successfully removed; otherwise returns + false. The base class implementation does nothing and returns false. - If you implement your own model, you can reimplement this function - if you want to support removing. Alternatively, you can provide - you own API for altering the data. + If you implement your own model, you can reimplement this function if you + want to support removing. Alternatively, you can provide your own API for + altering the data. - \sa removeColumn(), removeRows(), insertColumns(), beginRemoveColumns(), endRemoveColumns() + \sa removeColumn(), removeRows(), insertColumns(), beginRemoveColumns(), + endRemoveColumns() */ bool QAbstractItemModel::removeColumns(int, int, const QModelIndex &) { @@ -1737,9 +1765,9 @@ void QAbstractItemModel::fetchMore(const QModelIndex &) } /*! - Returns true if there is more data available for \a parent; otherwise returns - false. - + Returns true if there is more data available for \a parent; otherwise + returns false. + The default implementation always returns false. If canFetchMore() returns true, QAbstractItemView will call fetchMore(). @@ -1756,9 +1784,9 @@ bool QAbstractItemModel::canFetchMore(const QModelIndex &) const /*! Returns the item flags for the given \a index. - The base class implementation returns a combination of flags that - enables the item (\c ItemIsEnabled) and allows it to be - selected (\c ItemIsSelectable). + The base class implementation returns a combination of flags that enables + the item (\c ItemIsEnabled) and allows it to be selected + (\c ItemIsSelectable). \sa Qt::ItemFlags */ @@ -1784,12 +1812,13 @@ void QAbstractItemModel::sort(int column, Qt::SortOrder order) } /*! - Returns a model index for the buddy of the item represented by \a index. - When the user wants to edit an item, the view will call this function to - check whether another item in the model should be edited instead, and - construct a delegate using the model index returned by the buddy item. + Returns a model index for the buddy of the item represented by \a index. + When the user wants to edit an item, the view will call this function to + check whether another item in the model should be edited instead. Then, the + view will construct a delegate using the model index returned by the buddy + item. - In the default implementation each item is its own buddy. + The default implementation of this function has each item as its own buddy. */ QModelIndex QAbstractItemModel::buddy(const QModelIndex &index) const { @@ -1797,23 +1826,23 @@ QModelIndex QAbstractItemModel::buddy(const QModelIndex &index) const } /*! - Returns a list of indexes for the items in the column of the \a - start index where the data stored under the given \a role matches - the specified \a value. The way the search is performed is defined - by the \a flags given. The list that is returned may be empty. + Returns a list of indexes for the items in the column of the \a start index + where data stored under the given \a role matches the specified \a value. + The way the search is performed is defined by the \a flags given. The list + that is returned may be empty. - The search starts from the \a start index, and continues until the - number of matching data items equals \a hits, the search reaches - the last row, or the search reaches \a start again, depending on - whether \c MatchWrap is specified in \a flags. If you want to search - for all matching items, use \a hits = -1. + The search begins from the \a start index, and continues until the number + of matching data items equals \a hits, the search reaches the last row, or + the search reaches \a start again - depending on whether \c MatchWrap is + specified in \a flags. If you want to search for all matching items, use + \a hits = -1. By default, this function will perform a wrapping, string-based comparison on all items, searching for items that begin with the search term specified by \a value. - - \note The default implementation of this function only searches columns, - This function can be reimplemented to include other search behavior. + + \note The default implementation of this function only searches columns. + Reimplement this function to include a different search behavior. */ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, const QVariant &value, int hits, @@ -1888,7 +1917,7 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, /*! Returns the row and column span of the item represented by \a index. - Note: span is not used currently, but will be in the future. + \note Currently, span is not used. */ QSize QAbstractItemModel::span(const QModelIndex &) const @@ -1897,16 +1926,16 @@ QSize QAbstractItemModel::span(const QModelIndex &) const } /*! - \since 4.6 - - Sets the model's role names to \a roleNames. + \since 4.6 - This function is provided to allow mapping of role identifiers to - role property names in Declarative UI. This function must be called - before the model is used. Modifying the role names after the model - has been set may result in undefined behaviour. + Sets the model's role names to \a roleNames. - \sa roleNames() + This function allows mapping of role identifiers to role property names in + Declarative UI. This function must be called before the model is used. + Modifying the role names after the model has been set may result in + undefined behaviour. + + \sa roleNames() */ void QAbstractItemModel::setRoleNames(const QHash<int,QByteArray> &roleNames) { @@ -1915,11 +1944,11 @@ void QAbstractItemModel::setRoleNames(const QHash<int,QByteArray> &roleNames) } /*! - \since 4.6 + \since 4.6 - Returns the model's role names. + Returns the model's role names. - \sa setRoleNames() + \sa setRoleNames() */ const QHash<int,QByteArray> &QAbstractItemModel::roleNames() const { @@ -1928,10 +1957,12 @@ const QHash<int,QByteArray> &QAbstractItemModel::roleNames() const } /*! - Called to let the model know that it should submit whatever it has cached - to the permanent storage. Typically used for row editing. + Lets the model know that it should submit cached information to permanent + storage. This function is typically used for row editing. + + Returns true if there is no error; otherwise returns false. - Returns false on error, otherwise true. + \sa revert() */ bool QAbstractItemModel::submit() @@ -1940,8 +1971,10 @@ bool QAbstractItemModel::submit() } /*! - Called to let the model know that it should discard whatever it has cached. - Typically used for row editing. + Lets the model know that it should discard cached information. This + function is typically used for row editing. + + \sa submit() */ void QAbstractItemModel::revert() @@ -1950,14 +1983,14 @@ void QAbstractItemModel::revert() } /*! - Returns the data for the given \a role and \a section in the header - with the specified \a orientation. + Returns the data for the given \a role and \a section in the header with + the specified \a orientation. - For horizontal headers, the section number corresponds to the column - number of items shown beneath it. For vertical headers, the section - number typically to the row number of items shown alongside it. + For horizontal headers, the section number corresponds to the column + number. Similarly, for vertical headers, the section number corresponds to + the row number. - \sa Qt::ItemDataRole, setHeaderData(), QHeaderView + \sa Qt::ItemDataRole, setHeaderData(), QHeaderView */ QVariant QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -1969,14 +2002,15 @@ QVariant QAbstractItemModel::headerData(int section, Qt::Orientation orientation } /*! - Sets the data for the given \a role and \a section in the header with - the specified \a orientation to the \a value supplied. - Returns true if the header's data was updated; otherwise returns false. + Sets the data for the given \a role and \a section in the header with the + specified \a orientation to the \a value supplied. + + Returns true if the header's data was updated; otherwise returns false. - Note that the headerDataChanged() signal must be emitted explicitly - when reimplementing this function. + When reimplementing this function, the headerDataChanged() signal must be + emitted explicitly. - \sa Qt::ItemDataRole, headerData() + \sa Qt::ItemDataRole, headerData() */ bool QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation, @@ -1992,11 +2026,12 @@ bool QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation, /*! \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, void *ptr) const - Creates a model index for the given \a row and \a column with the internal pointer \a ptr. + Creates a model index for the given \a row and \a column with the internal + pointer \a ptr. - Note that when you are using a QSortFilterProxyModel its indexes have their own - internal pointer. It is not advisable to access the internal pointer in the index - outside of the model. Use the data() function instead. + When using a QSortFilterProxyModel, its indexes have their own internal + pointer. It is not advisable to access this internal pointer outside of the + model. Use the data() function instead. This function provides a consistent interface that model subclasses must use to create model indexes. @@ -2006,7 +2041,8 @@ bool QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation, \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, int id) const \obsolete - Use QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) instead. + Use QModelIndex + QAbstractItemModel::createIndex(int row, int column, quint32 id) instead. */ /*! @@ -2017,6 +2053,7 @@ bool QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation, This function provides a consistent interface that model subclasses must use to create model indexes. + \sa QModelIndex::internalId() */ @@ -2120,34 +2157,41 @@ bool QAbstractItemModel::decodeData(int row, int column, const QModelIndex &pare /*! Begins a row insertion operation. - When reimplementing insertRows() in a subclass, you must call this - function \e before inserting data into the model's underlying data - store. + When reimplementing insertRows() in a subclass, you must call this function + \e before inserting data into the model's underlying data store. - The \a parent index corresponds to the parent into which the new - rows are inserted; \a first and \a last are the row numbers that the - new rows will have after they have been inserted. + The \a parent index corresponds to the parent into which the new rows are + inserted; \a first and \a last are the row numbers that the new rows will + have after they have been inserted. \table 80% - \row \o \inlineimage modelview-begin-insert-rows.png Inserting rows - \o Specify the first and last row numbers for the span of rows - you want to insert into an item in a model. - - For example, as shown in the diagram, we insert three rows before - row 2, so \a first is 2 and \a last is 4: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 0 - This inserts the three new rows as rows 2, 3, and 4. \row - \o \inlineimage modelview-begin-append-rows.png Appending rows - \o To append rows, insert them after the last row. - - For example, as shown in the diagram, we append two rows to a - collection of 4 existing rows (ending in row 3), so \a first is 4 - and \a last is 5: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 1 - This appends the two new rows as rows 4 and 5. + \o \inlineimage modelview-begin-insert-rows.png Inserting rows + \o Specify the first and last row numbers for the span of rows you + want to insert into an item in a model. + + For example, as shown in the diagram, we insert three rows before + row 2, so \a first is 2 and \a last is 4: + + \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 0 + + This inserts the three new rows as rows 2, 3, and 4. + \row + \o \inlineimage modelview-begin-append-rows.png Appending rows + \o To append rows, insert them after the last row. + + For example, as shown in the diagram, we append two rows to a + collection of 4 existing rows (ending in row 3), so \a first is 4 + and \a last is 5: + + \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 1 + + This appends the two new rows as rows 4 and 5. \endtable + \note This function emits the rowsAboutToBeInserted() signal which + connected views (or proxies) must handle before the data is inserted. + Otherwise, the views may end up in an invalid state. \sa endInsertRows() */ void QAbstractItemModel::beginInsertRows(const QModelIndex &parent, int first, int last) @@ -2163,9 +2207,8 @@ void QAbstractItemModel::beginInsertRows(const QModelIndex &parent, int first, i /*! Ends a row insertion operation. - When reimplementing insertRows() in a subclass, you must call this - function \e after inserting data into the model's underlying data - store. + When reimplementing insertRows() in a subclass, you must call this function + \e after inserting data into the model's underlying data store. \sa beginInsertRows() */ @@ -2181,23 +2224,28 @@ void QAbstractItemModel::endInsertRows() Begins a row removal operation. When reimplementing removeRows() in a subclass, you must call this - function \e before removing data from the model's underlying data - store. + function \e before removing data from the model's underlying data store. - The \a parent index corresponds to the parent from which the new - rows are removed; \a first and \a last are the row numbers of the - rows to be removed. + The \a parent index corresponds to the parent from which the new rows are + removed; \a first and \a last are the row numbers of the rows to be + removed. \table 80% - \row \o \inlineimage modelview-begin-remove-rows.png Removing rows - \o Specify the first and last row numbers for the span of rows - you want to remove from an item in a model. + \row + \o \inlineimage modelview-begin-remove-rows.png Removing rows + \o Specify the first and last row numbers for the span of rows you + want to remove from an item in a model. + + For example, as shown in the diagram, we remove the two rows from + row 2 to row 3, so \a first is 2 and \a last is 3: - For example, as shown in the diagram, we remove the two rows from - row 2 to row 3, so \a first is 2 and \a last is 3: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 2 + \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 2 \endtable + \note This function emits the rowsAboutToBeRemoved() signal which connected + views (or proxies) must handle before the data is removed. Otherwise, the + views may end up in an invalid state. + \sa endRemoveRows() */ void QAbstractItemModel::beginRemoveRows(const QModelIndex &parent, int first, int last) @@ -2213,9 +2261,8 @@ void QAbstractItemModel::beginRemoveRows(const QModelIndex &parent, int first, i /*! Ends a row removal operation. - When reimplementing removeRows() in a subclass, you must call this - function \e after removing data from the model's underlying data - store. + When reimplementing removeRows() in a subclass, you must call this function + \e after removing data from the model's underlying data store. \sa beginRemoveRows() */ @@ -2231,33 +2278,41 @@ void QAbstractItemModel::endRemoveRows() Begins a column insertion operation. When reimplementing insertColumns() in a subclass, you must call this - function \e before inserting data into the model's underlying data - store. + function \e before inserting data into the model's underlying data store. - The \a parent index corresponds to the parent into which the new - columns are inserted; \a first and \a last are the column numbers of - the new columns will have after they have been inserted. + The \a parent index corresponds to the parent into which the new columns + are inserted; \a first and \a last are the column numbers of the new + columns will have after they have been inserted. \table 80% - \row \o \inlineimage modelview-begin-insert-columns.png Inserting columns - \o Specify the first and last column numbers for the span of columns - you want to insert into an item in a model. - - For example, as shown in the diagram, we insert three columns before - column 4, so \a first is 4 and \a last is 6: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 3 - This inserts the three new columns as columns 4, 5, and 6. \row - \o \inlineimage modelview-begin-append-columns.png Appending columns - \o To append columns, insert them after the last column. - - For example, as shown in the diagram, we append three columns to a - collection of six existing columns (ending in column 5), so \a first - is 6 and \a last is 8: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 4 - This appends the two new columns as columns 6, 7, and 8. + \o \inlineimage modelview-begin-insert-columns.png Inserting columns + \o Specify the first and last column numbers for the span of columns + you want to insert into an item in a model. + + For example, as shown in the diagram, we insert three columns + before column 4, so \a first is 4 and \a last is 6: + + \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 3 + + This inserts the three new columns as columns 4, 5, and 6. + \row + \o \inlineimage modelview-begin-append-columns.png Appending columns + \o To append columns, insert them after the last column. + + For example, as shown in the diagram, we append three columns to a + collection of six existing columns (ending in column 5), so + \a first is 6 and \a last is 8: + + \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 4 + + This appends the two new columns as columns 6, 7, and 8. \endtable + \note This function emits the columnsAboutToBeInserted() signal which + connected views (or proxies) must handle before the data is inserted. + Otherwise, the views may end up in an invalid state. + \sa endInsertColumns() */ void QAbstractItemModel::beginInsertColumns(const QModelIndex &parent, int first, int last) @@ -2291,23 +2346,28 @@ void QAbstractItemModel::endInsertColumns() Begins a column removal operation. When reimplementing removeColumns() in a subclass, you must call this - function \e before removing data from the model's underlying data - store. + function \e before removing data from the model's underlying data store. - The \a parent index corresponds to the parent from which the new - columns are removed; \a first and \a last are the column numbers of - the first and last columns to be removed. + The \a parent index corresponds to the parent from which the new columns + are removed; \a first and \a last are the column numbers of the first and + last columns to be removed. \table 80% - \row \o \inlineimage modelview-begin-remove-columns.png Removing columns - \o Specify the first and last column numbers for the span of columns - you want to remove from an item in a model. + \row + \o \inlineimage modelview-begin-remove-columns.png Removing columns + \o Specify the first and last column numbers for the span of columns + you want to remove from an item in a model. + + For example, as shown in the diagram, we remove the three columns + from column 4 to column 6, so \a first is 4 and \a last is 6: - For example, as shown in the diagram, we remove the three columns - from column 4 to column 6, so \a first is 4 and \a last is 6: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 5 + \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 5 \endtable + \note This function emits the columnsAboutToBeRemoved() signal which + connected views (or proxies) must handle before the data is removed. + Otherwise, the views may end up in an invalid state. + \sa endRemoveColumns() */ void QAbstractItemModel::beginRemoveColumns(const QModelIndex &parent, int first, int last) @@ -2324,8 +2384,7 @@ void QAbstractItemModel::beginRemoveColumns(const QModelIndex &parent, int first Ends a column removal operation. When reimplementing removeColumns() in a subclass, you must call this - function \e after removing data from the model's underlying data - store. + function \e after removing data from the model's underlying data store. \sa beginRemoveColumns() */ @@ -2340,11 +2399,11 @@ void QAbstractItemModel::endRemoveColumns() /*! Resets the model to its original state in any attached views. - \note The view to which the model is attached to will be reset as well. + The view to which the model is attached to will be reset as well. When a model is reset it means that any previous data reported from the - model is now invalid and has to be queried for again. This also means - that the current item and any selected items will become invalid. + model is now invalid and has to be queried for again. This also means that + the current item and any selected items will become invalid. When a model radically changes its data it can sometimes be easier to just call this function rather than emit dataChanged() to inform other @@ -2361,13 +2420,13 @@ void QAbstractItemModel::reset() } /*! - Changes the QPersistentModelIndex that is equal to the given \a from - model index to the given \a to model index. + Changes the QPersistentModelIndex that is equal to the given \a from model + index to the given \a to model index. - If no persistent model index equal to the given \a from model index was - found, nothing is changed. + If no persistent model index equal to the given \a from model index was + found, nothing is changed. - \sa persistentIndexList(), changePersistentIndexList() + \sa persistentIndexList(), changePersistentIndexList() */ void QAbstractItemModel::changePersistentIndex(const QModelIndex &from, const QModelIndex &to) { @@ -2388,15 +2447,15 @@ void QAbstractItemModel::changePersistentIndex(const QModelIndex &from, const QM } /*! - \since 4.1 + \since 4.1 - Changes the QPersistentModelIndexes that is equal to the indexes in the given \a from - model index list to the given \a to model index list. + Changes the QPersistentModelIndexes that is equal to the indexes in the + given \a from model index list to the given \a to model index list. - If no persistent model indexes equal to the indexes in the given \a from model index list - was found, nothing is changed. + If no persistent model indexes equal to the indexes in the given \a from + model index list was found, nothing is changed. - \sa persistentIndexList(), changePersistentIndex() + \sa persistentIndexList(), changePersistentIndex() */ void QAbstractItemModel::changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to) @@ -2429,9 +2488,9 @@ void QAbstractItemModel::changePersistentIndexList(const QModelIndexList &from, } /*! - \since 4.2 + \since 4.2 - Returns the list of indexes stored as persistent indexes in the model. + Returns the list of indexes stored as persistent indexes in the model. */ QModelIndexList QAbstractItemModel::persistentIndexList() const { @@ -2458,10 +2517,10 @@ QModelIndexList QAbstractItemModel::persistentIndexList() const but must be subclassed. Since the model provides a more specialized interface than - QAbstractItemModel, it is not suitable for use with tree views, although - it can be used to provide data to a QListView. If you need to represent - a simple list of items, and only need a model to contain a single column - of data, subclassing the QAbstractListModel may be more appropriate. + QAbstractItemModel, it is not suitable for use with tree views, although it + can be used to provide data to a QListView. If you need to represent a + simple list of items, and only need a model to contain a single column of + data, subclassing the QAbstractListModel may be more appropriate. The rowCount() and columnCount() functions return the dimensions of the table. To retrieve a model index corresponding to an item in the model, use @@ -2469,9 +2528,6 @@ QModelIndexList QAbstractItemModel::persistentIndexList() const \section1 Subclassing - \bold{Note:} Some general guidelines for subclassing models are - available in the \l{Model Subclassing Reference}. - When subclassing QAbstractTableModel, you must implement rowCount(), columnCount(), and data(). Default implementations of the index() and parent() functions are provided by QAbstractTableModel. @@ -2502,9 +2558,13 @@ QModelIndexList QAbstractItemModel::persistentIndexList() const call endRemoveColumns() \e{immediately afterwards}. \endlist - \sa {Model Classes}, {Model Subclassing Reference}, QAbstractItemModel, - QAbstractListModel, - {Pixelator Example} + \note Some general guidelines for subclassing models are available in the + \l{Model Subclassing Reference}. + + \note + + \sa {Model Classes}, QAbstractItemModel, QAbstractListModel, + {Pixelator Example} */ /*! @@ -2602,9 +2662,6 @@ bool QAbstractTableModel::hasChildren(const QModelIndex &parent) const \section1 Subclassing - \bold{Note:} Some general guidelines for subclassing models are - available in the \l{Model Subclassing Reference}. - When subclassing QAbstractListModel, you must provide implementations of the rowCount() and data() functions. Well behaved models also provide a headerData() implementation. @@ -2631,6 +2688,9 @@ bool QAbstractTableModel::hasChildren(const QModelIndex &parent) const call endRemoveRows() \e{immediately afterwards}. \endlist + \note Some general guidelines for subclassing models are available in the + \l{Model Subclassing Reference}. + \sa {Model Classes}, {Model Subclassing Reference}, QAbstractItemView, QAbstractTableModel, {Item Views Puzzle Example} */ diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 522f0dc..847938f 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -140,63 +140,6 @@ QT_BEGIN_NAMESPACE \value Public */ -// do not touch without touching the moc as well -enum PropertyFlags { - Invalid = 0x00000000, - Readable = 0x00000001, - Writable = 0x00000002, - Resettable = 0x00000004, - EnumOrFlag = 0x00000008, - StdCppSet = 0x00000100, -// Override = 0x00000200, - Constant = 0x00000400, - Final = 0x00000800, - Designable = 0x00001000, - ResolveDesignable = 0x00002000, - Scriptable = 0x00004000, - ResolveScriptable = 0x00008000, - Stored = 0x00010000, - ResolveStored = 0x00020000, - Editable = 0x00040000, - ResolveEditable = 0x00080000, - User = 0x00100000, - ResolveUser = 0x00200000, - Notify = 0x00400000 -}; - -enum MethodFlags { - AccessPrivate = 0x00, - AccessProtected = 0x01, - AccessPublic = 0x02, - AccessMask = 0x03, //mask - - MethodMethod = 0x00, - MethodSignal = 0x04, - MethodSlot = 0x08, - MethodConstructor = 0x0c, - MethodTypeMask = 0x0c, - - MethodCompatibility = 0x10, - MethodCloned = 0x20, - MethodScriptable = 0x40 -}; - -enum MetaObjectFlags { - DynamicMetaObject = 0x01 -}; - -struct QMetaObjectPrivate -{ - int revision; - int className; - int classInfoCount, classInfoData; - int methodCount, methodData; - int propertyCount, propertyData; - int enumeratorCount, enumeratorData; - int constructorCount, constructorData; - int flags; -}; - static inline const QMetaObjectPrivate *priv(const uint* data) { return reinterpret_cast<const QMetaObjectPrivate*>(data); } @@ -599,29 +542,46 @@ int QMetaObject::indexOfMethod(const char *method) const */ int QMetaObject::indexOfSignal(const char *signal) const { - int i = -1; const QMetaObject *m = this; - while (m && i < 0) { + int i = QMetaObjectPrivate::indexOfSignalRelative(&m, signal); + if (i >= 0) + i += m->methodOffset(); + return i; +} + +/*! \internal + Same as QMetaObject::indexOfSignal, but the result is the local offset to the base object. + + \a baseObject will be adjusted to the enclosing QMetaObject, or 0 if the signal is not found +*/ +int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject, const char *signal) +{ + int i = -1; + while (*baseObject) { + const QMetaObject *const m = *baseObject; for (i = priv(m->d.data)->methodCount-1; i >= 0; --i) if ((m->d.data[priv(m->d.data)->methodData + 5*i + 4] & MethodTypeMask) == MethodSignal && strcmp(signal, m->d.stringdata - + m->d.data[priv(m->d.data)->methodData + 5*i]) == 0) { - i += m->methodOffset(); + + m->d.data[priv(m->d.data)->methodData + 5*i]) == 0) { break; } - m = m->d.superdata; + if (i >= 0) + break; + *baseObject = m->d.superdata; } #ifndef QT_NO_DEBUG + const QMetaObject *m = *baseObject; if (i >= 0 && m && m->d.superdata) { int conflict = m->d.superdata->indexOfMethod(signal); if (conflict >= 0) qWarning("QMetaObject::indexOfSignal:%s: Conflict with %s::%s", - m->d.stringdata, m->d.superdata->d.stringdata, signal); + m->d.stringdata, m->d.superdata->d.stringdata, signal); } #endif return i; } + /*! Finds \a slot and returns its index; otherwise returns -1. @@ -2669,4 +2629,20 @@ const char* QMetaClassInfo::value() const and \a data. */ +/*! \internal + If the local_method_index is a cloned method, return the index of the original. + + Example: if the index of "destroyed()" is passed, the index of "destroyed(QObject*)" is returned + */ +int QMetaObjectPrivate::originalClone(const QMetaObject *mobj, int local_method_index) +{ + int handle = get(mobj)->methodData + 5 * local_method_index; + while (mobj->d.data[handle + 4] & MethodCloned) { + Q_ASSERT(local_method_index > 0); + handle -= 5; + local_method_index--; + } + return local_method_index; +} + QT_END_NAMESPACE diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h index 66ed55c..d843deb 100644 --- a/src/corelib/kernel/qmetaobject_p.h +++ b/src/corelib/kernel/qmetaobject_p.h @@ -54,9 +54,82 @@ // #include <QtCore/qglobal.h> +#include <QtCore/qobjectdefs.h> QT_BEGIN_NAMESPACE +enum PropertyFlags { + Invalid = 0x00000000, + Readable = 0x00000001, + Writable = 0x00000002, + Resettable = 0x00000004, + EnumOrFlag = 0x00000008, + StdCppSet = 0x00000100, +// Override = 0x00000200, + Constant = 0x00000400, + Final = 0x00000800, + Designable = 0x00001000, + ResolveDesignable = 0x00002000, + Scriptable = 0x00004000, + ResolveScriptable = 0x00008000, + Stored = 0x00010000, + ResolveStored = 0x00020000, + Editable = 0x00040000, + ResolveEditable = 0x00080000, + User = 0x00100000, + ResolveUser = 0x00200000, + Notify = 0x00400000 +}; + +enum MethodFlags { + AccessPrivate = 0x00, + AccessProtected = 0x01, + AccessPublic = 0x02, + AccessMask = 0x03, //mask + + MethodMethod = 0x00, + MethodSignal = 0x04, + MethodSlot = 0x08, + MethodConstructor = 0x0c, + MethodTypeMask = 0x0c, + + MethodCompatibility = 0x10, + MethodCloned = 0x20, + MethodScriptable = 0x40 +}; + +enum MetaObjectFlags { + DynamicMetaObject = 0x01 +}; + + +struct QMetaObjectPrivate +{ + int revision; + int className; + int classInfoCount, classInfoData; + int methodCount, methodData; + int propertyCount, propertyData; + int enumeratorCount, enumeratorData; + int constructorCount, constructorData; //since revision 2 + int flags; //since revision 3 + int signalCount; //since revision 4 + + static inline const QMetaObjectPrivate *get(const QMetaObject *metaobject) + { return reinterpret_cast<const QMetaObjectPrivate*>(metaobject->d.data); } + + static int indexOfSignalRelative(const QMetaObject **baseObject, const char* name); + static int originalClone(const QMetaObject *obj, int local_method_index); + + //defined in qobject.cpp + static bool connect(const QObject *sender, int signal_index, + const QObject *receiver, int method_index, + int type = 0, int *types = 0); + static bool disconnect(const QObject *sender, int signal_index, + const QObject *receiver, int method_index); + +}; + #ifndef UTILS_H // mirrored in moc's utils.h static inline bool is_ident_char(char s) @@ -202,6 +275,7 @@ static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixSc return result; } + QT_END_NAMESPACE #endif diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 0e75867..e874c90 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -41,6 +41,7 @@ #include "qobject.h" #include "qobject_p.h" +#include "qmetaobject_p.h" #include "qabstracteventdispatcher.h" #include "qcoreapplication.h" @@ -221,12 +222,42 @@ void QObjectPrivate::removePendingChildInsertedEvents(QObject *child) #endif +/*!\internal + For a given metaobject, compute the signal offset, and the method offset (including signals) +*/ +static void computeOffsets(const QMetaObject *metaobject, int *signalOffset, int *methodOffset) +{ + *signalOffset = *methodOffset = 0; + const QMetaObject *m = metaobject->d.superdata; + while (m) { + const QMetaObjectPrivate *d = QMetaObjectPrivate::get(m); + *methodOffset += d->methodCount; + *signalOffset += (d->revision >= 4) ? d->signalCount : d->methodCount; + /*Before Qt 4.6 (revision 4), the signalCount information was not generated by moc. + so for compatibility we consider all the method as slot for old moc output*/ + m = m->d.superdata; + } +} + +/*! \internal + This vector contains the all connections from an object. + + Each object may have one vector containing the lists of connections for a given signal. + The index in the vector correspond to the signal index. + The signal index is the one returned by QObjectPrivate::signalIndex (not QMetaObject::indexOfSignal). + Negative index means connections to all signals. + + This vector is protected by the object mutex (signalSlotMutexes()) + + Each Connection is also part of a 'senders' linked list. The mutex of the receiver must be locked when touching + the pointers of this linked list. +*/ class QObjectConnectionListVector : public QVector<QObjectPrivate::ConnectionList> { public: - bool orphaned; - bool dirty; - int inUse; + bool orphaned; //the QObject owner of this vector has been destroyed while the vector was inUse + bool dirty; //some Connection have been disconnected (their receiver is 0) but not removed from the list yet + int inUse; //number of functions that are currently accessing this object or its connections QObjectPrivate::ConnectionList allsignals; QObjectConnectionListVector() @@ -251,7 +282,7 @@ public: bool QObjectPrivate::isSender(const QObject *receiver, const char *signal) const { Q_Q(const QObject); - int signal_index = q->metaObject()->indexOfSignal(signal); + int signal_index = signalIndex(signal); if (signal_index < 0) return false; QMutexLocker locker(signalSlotLock(q)); @@ -275,7 +306,7 @@ QObjectList QObjectPrivate::receiverList(const char *signal) const { Q_Q(const QObject); QObjectList returnValue; - int signal_index = q->metaObject()->indexOfSignal(signal); + int signal_index = signalIndex(signal); if (signal_index < 0) return returnValue; QMutexLocker locker(signalSlotLock(q)); @@ -2417,6 +2448,7 @@ QObject *QObject::sender() const int QObject::receivers(const char *signal) const { + Q_D(const QObject); int receivers = 0; if (signal) { QByteArray signal_name = QMetaObject::normalizedSignature(signal); @@ -2426,8 +2458,7 @@ int QObject::receivers(const char *signal) const return 0; #endif signal++; // skip code - const QMetaObject *smeta = this->metaObject(); - int signal_index = smeta->indexOfSignal(signal); + int signal_index = d->signalIndex(signal); if (signal_index < 0) { #ifndef QT_NO_DEBUG err_method_notfound(this, signal-1, "receivers"); @@ -2551,19 +2582,26 @@ bool QObject::connect(const QObject *sender, const char *signal, const QMetaObject *smeta = sender->metaObject(); const char *signal_arg = signal; ++signal; //skip code - int signal_index = smeta->indexOfSignal(signal); + int signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal); if (signal_index < 0) { // check for normalized signatures tmp_signal_name = QMetaObject::normalizedSignature(signal - 1); signal = tmp_signal_name.constData() + 1; - signal_index = smeta->indexOfSignal(signal); + smeta = sender->metaObject(); + signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal); + if (signal_index < 0) { err_method_notfound(sender, signal_arg, "connect"); err_info_about_objects("connect", sender, receiver); return false; } } + signal_index = QMetaObjectPrivate::originalClone(smeta, signal_index); + int signalOffset, methodOffset; + computeOffsets(smeta, &signalOffset, &methodOffset); + int signal_absolute_index = signal_index + methodOffset; + signal_index += signalOffset; QByteArray tmp_method_name; int membcode = extract_code(method); @@ -2612,12 +2650,12 @@ bool QObject::connect(const QObject *sender, const char *signal, int *types = 0; if ((type == Qt::QueuedConnection || type == Qt::BlockingQueuedConnection) - && !(types = queuedConnectionTypes(smeta->method(signal_index).parameterTypes()))) + && !(types = queuedConnectionTypes(smeta->method(signal_absolute_index).parameterTypes()))) return false; #ifndef QT_NO_DEBUG { - QMetaMethod smethod = smeta->method(signal_index); + QMetaMethod smethod = smeta->method(signal_absolute_index); QMetaMethod rmethod = rmeta->method(method_index); if (warnCompat) { if(smethod.attributes() & QMetaMethod::Compatibility) { @@ -2630,7 +2668,7 @@ bool QObject::connect(const QObject *sender, const char *signal, } } #endif - if (!QMetaObject::connect(sender, signal_index, receiver, method_index, type, types)) + if (!QMetaObjectPrivate::connect(sender, signal_index, receiver, method_index, type, types)) return false; const_cast<QObject*>(sender)->connectNotify(signal - 1); return true; @@ -2761,14 +2799,18 @@ bool QObject::disconnect(const QObject *sender, const char *signal, do { int signal_index = -1; if (signal) { - signal_index = smeta->indexOfSignal(signal); - if (signal_index < smeta->methodOffset()) - continue; + signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal); + if (signal_index < 0) + break; + signal_index = QMetaObjectPrivate::originalClone(smeta, signal_index); + int signalOffset, methodOffset; + computeOffsets(smeta, &signalOffset, &methodOffset); + signal_index += signalOffset; signal_found = true; } if (!method) { - res |= QMetaObject::disconnect(sender, signal_index, receiver, -1); + res |= QMetaObjectPrivate::disconnect(sender, signal_index, receiver, -1); } else { const QMetaObject *rmeta = receiver->metaObject(); do { @@ -2778,7 +2820,7 @@ bool QObject::disconnect(const QObject *sender, const char *signal, rmeta = rmeta->superClass(); if (method_index < 0) break; - res |= QMetaObject::disconnect(sender, signal_index, receiver, method_index); + res |= QMetaObjectPrivate::disconnect(sender, signal_index, receiver, method_index); method_found = true; } while ((rmeta = rmeta->superClass())); } @@ -2869,16 +2911,31 @@ void QObject::disconnectNotify(const char *) } /*!\internal + \a types is a 0-terminated vector of meta types for queued + connections. - \a types is a 0-terminated vector of meta types for queued - connections. - - if \a signal_index is -1, then we effectively connect *all* signals - from the sender to the receiver's slot -*/ + if \a signal_index is -1, then we effectively connect *all* signals + from the sender to the receiver's slot + */ bool QMetaObject::connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type, int *types) { + const QMetaObject *mo = sender->metaObject(); + while (mo && mo->methodOffset() > signal_index) + mo = mo->superClass(); + int signalOffset, methodOffset; + computeOffsets(mo, &signalOffset, &methodOffset); + signal_index = QMetaObjectPrivate::originalClone(mo, signal_index - methodOffset) + signalOffset; + return QMetaObjectPrivate::connect(sender, signal_index, + receiver, method_index, type, types); +} + +/*! \internal + Same as the QMetaObject::connect, but \a signal_index must be the result of QObjectPrivate::signalIndex + */ +bool QMetaObjectPrivate::connect(const QObject *sender, int signal_index, + const QObject *receiver, int method_index, int type, int *types) +{ QObject *s = const_cast<QObject *>(sender); QObject *r = const_cast<QObject *>(receiver); @@ -2886,7 +2943,7 @@ bool QMetaObject::connect(const QObject *sender, int signal_index, signalSlotLock(receiver)); if (type & Qt::UniqueConnection) { - QObjectConnectionListVector *connectionLists = s->d_func()->connectionLists; + QObjectConnectionListVector *connectionLists = QObjectPrivate::get(s)->connectionLists; if (connectionLists && connectionLists->count() > signal_index) { const QObjectPrivate::Connection *c2 = (*connectionLists)[signal_index].first; @@ -2907,25 +2964,25 @@ bool QMetaObject::connect(const QObject *sender, int signal_index, c->connectionType = type; c->argumentTypes = types; c->nextConnectionList = 0; - c->prev = &r->d_func()->senders; + c->prev = &(QObjectPrivate::get(r)->senders); c->next = *c->prev; *c->prev = c; if (c->next) c->next->prev = &c->next; - s->d_func()->addConnection(signal_index, c); + QObjectPrivate::get(s)->addConnection(signal_index, c); + QObjectPrivate *const sender_d = QObjectPrivate::get(s); if (signal_index < 0) { - for (uint i = 0; i < (sizeof sender->d_func()->connectedSignals - / sizeof sender->d_func()->connectedSignals[0] ); ++i) - sender->d_func()->connectedSignals[i] = ~0u; - } else if (signal_index < (int)sizeof sender->d_func()->connectedSignals * 8) { - uint n = (signal_index / (8 * sizeof sender->d_func()->connectedSignals[0])); - sender->d_func()->connectedSignals[n] |= (1 << (signal_index - n * 8 - * sizeof sender->d_func()->connectedSignals[0])); + for (uint i = 0; i < (sizeof sender_d->connectedSignals + / sizeof sender_d->connectedSignals[0] ); ++i) + sender_d->connectedSignals[i] = ~0u; + } else if (signal_index < (int)sizeof sender_d->connectedSignals * 8) { + uint n = (signal_index / (8 * sizeof sender_d->connectedSignals[0])); + sender_d->connectedSignals[n] |= (1 << (signal_index - n * 8 + * sizeof sender_d->connectedSignals[0])); } - return true; } @@ -2935,6 +2992,22 @@ bool QMetaObject::connect(const QObject *sender, int signal_index, bool QMetaObject::disconnect(const QObject *sender, int signal_index, const QObject *receiver, int method_index) { + const QMetaObject *mo = sender->metaObject(); + while (mo && mo->methodOffset() > signal_index) + mo = mo->superClass(); + int signalOffset, methodOffset; + computeOffsets(mo, &signalOffset, &methodOffset); + signal_index = QMetaObjectPrivate::originalClone(mo, signal_index - methodOffset) + signalOffset; + return QMetaObjectPrivate::disconnect(sender, signal_index, + receiver, method_index); +} + +/*! \internal + Same as the QMetaObject::disconnect, but \a signal_index must be the result of QObjectPrivate::signalIndex + */ +bool QMetaObjectPrivate::disconnect(const QObject *sender, int signal_index, + const QObject *receiver, int method_index) +{ if (!sender) return false; @@ -2945,7 +3018,7 @@ bool QMetaObject::disconnect(const QObject *sender, int signal_index, QMutex *receiverMutex = receiver ? signalSlotLock(receiver) : 0; QOrderedMutexLocker locker(senderMutex, receiverMutex); - QObjectConnectionListVector *connectionLists = s->d_func()->connectionLists; + QObjectConnectionListVector *connectionLists = QObjectPrivate::get(s)->connectionLists; if (!connectionLists) return false; @@ -3056,23 +3129,26 @@ void QMetaObject::connectSlotsByName(QObject *o) int len = objName.length(); if (!len || qstrncmp(slot + 3, objName.data(), len) || slot[len+3] != '_') continue; - const QMetaObject *smo = co->metaObject(); - int sigIndex = smo->indexOfMethod(slot + len + 4); + int sigIndex = co->d_func()->signalIndex(slot + len + 4); if (sigIndex < 0) { // search for compatible signals + const QMetaObject *smo = co->metaObject(); int slotlen = qstrlen(slot + len + 4) - 1; for (int k = 0; k < co->metaObject()->methodCount(); ++k) { - if (smo->method(k).methodType() != QMetaMethod::Signal) + QMetaMethod method = smo->method(k); + if (method.methodType() != QMetaMethod::Signal) continue; - if (!qstrncmp(smo->method(k).signature(), slot + len + 4, slotlen)) { - sigIndex = k; + if (!qstrncmp(method.signature(), slot + len + 4, slotlen)) { + int signalOffset, methodOffset; + computeOffsets(method.enclosingMetaObject(), &signalOffset, &methodOffset); + sigIndex = k + - methodOffset + signalOffset; break; } } } if (sigIndex < 0) continue; - if (QMetaObject::connect(co, sigIndex, o, i)) { + if (QMetaObjectPrivate::connect(co, sigIndex, o, i)) { foundIt = true; break; } @@ -3142,15 +3218,43 @@ static void blocking_activate(QObject *sender, int signal, QObjectPrivate::Conne } /*!\internal + \obsolete. + Used to be called from QMetaObject::activate(QObject *, QMetaObject *, int, int, void **) before Qt 4.6 */ void QMetaObject::activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv) { + Q_UNUSED(to_signal_index); + activate(sender, from_signal_index, argv); +} + +/*!\internal + */ +void QMetaObject::activate(QObject *sender, const QMetaObject *m, int local_signal_index, + void **argv) +{ + int signalOffset; + int methodOffset; + computeOffsets(m, &signalOffset, &methodOffset); + + int signal_index = signalOffset + local_signal_index; + if (signal_index < (int)sizeof(sender->d_func()->connectedSignals) * 8 + && !qt_signal_spy_callback_set.signal_begin_callback + && !qt_signal_spy_callback_set.signal_end_callback) { + uint n = (signal_index / (8 * sizeof sender->d_func()->connectedSignals[0])); + uint m = 1 << (signal_index - n * 8 * sizeof sender->d_func()->connectedSignals[0]); + if ((sender->d_func()->connectedSignals[n] & m) == 0) + // nothing connected to these signals, and no spy + return; + } + if (sender->d_func()->blockSig) return; + int signal_absolute_index = methodOffset + local_signal_index; + void *empty_argv[] = { 0 }; if (qt_signal_spy_callback_set.signal_begin_callback != 0) { - qt_signal_spy_callback_set.signal_begin_callback(sender, from_signal_index, + qt_signal_spy_callback_set.signal_begin_callback(sender, signal_absolute_index, argv ? argv : empty_argv); } @@ -3160,26 +3264,20 @@ void QMetaObject::activate(QObject *sender, int from_signal_index, int to_signal QObjectConnectionListVector *connectionLists = sender->d_func()->connectionLists; if (!connectionLists) { if (qt_signal_spy_callback_set.signal_end_callback != 0) - qt_signal_spy_callback_set.signal_end_callback(sender, from_signal_index); + qt_signal_spy_callback_set.signal_end_callback(sender, signal_absolute_index); return; } ++connectionLists->inUse; + if (signal_index >= connectionLists->count()) { + signal_index = -2; //for "all signals"; + } - // emit signals in the following order: from_signal_index <= signals <= to_signal_index, signal < 0 - for (int signal = from_signal_index; - (signal >= from_signal_index && signal <= to_signal_index) || (signal == -2); - (signal == to_signal_index ? signal = -2 : ++signal)) - { - if (signal >= connectionLists->count()) { - signal = to_signal_index; - continue; - } - - QObjectPrivate::Connection *c = connectionLists->at(signal).first; + do { + QObjectPrivate::Connection *c = connectionLists->at(signal_index).first; if (!c) continue; // We need to check against last here to ensure that signals added // during the signal emission are not emitted in this emission. - QObjectPrivate::Connection *last = connectionLists->at(signal).last; + QObjectPrivate::Connection *last = connectionLists->at(signal_index).last; do { if (!c->receiver) @@ -3193,17 +3291,17 @@ void QMetaObject::activate(QObject *sender, int from_signal_index, int to_signal && (currentThreadData != sender->d_func()->threadData || receiver->d_func()->threadData != sender->d_func()->threadData)) || (c->connectionType == Qt::QueuedConnection)) { - queued_activate(sender, signal, c, argv); + queued_activate(sender, signal_absolute_index, c, argv); continue; } else if (c->connectionType == Qt::BlockingQueuedConnection) { - blocking_activate(sender, signal, c, argv); + blocking_activate(sender, signal_absolute_index, c, argv); continue; } const int method = c->method; QObjectPrivate::Sender currentSender; currentSender.sender = sender; - currentSender.signal = signal < 0 ? from_signal_index : signal; + currentSender.signal = signal_absolute_index; currentSender.ref = 1; QObjectPrivate::Sender *previousSender = 0; if (currentThreadData == receiver->d_func()->threadData) @@ -3247,7 +3345,7 @@ void QMetaObject::activate(QObject *sender, int from_signal_index, int to_signal if (connectionLists->orphaned) break; - } + } while (signal_index >= 0 && (signal_index = -1)); //start over for -1 (all signal) --connectionLists->inUse; Q_ASSERT(connectionLists->inUse >= 0); @@ -3261,82 +3359,50 @@ void QMetaObject::activate(QObject *sender, int from_signal_index, int to_signal locker.unlock(); if (qt_signal_spy_callback_set.signal_end_callback != 0) - qt_signal_spy_callback_set.signal_end_callback(sender, from_signal_index); -} + qt_signal_spy_callback_set.signal_end_callback(sender, signal_absolute_index); +} /*!\internal - */ + Obsolete. (signal_index comes from indexOfMethod()) +*/ void QMetaObject::activate(QObject *sender, int signal_index, void **argv) { - if (signal_index < (int)sizeof(sender->d_func()->connectedSignals) * 8 - && !qt_signal_spy_callback_set.signal_begin_callback - && !qt_signal_spy_callback_set.signal_end_callback) { - uint n = (signal_index / (8 * sizeof sender->d_func()->connectedSignals[0])); - uint m = 1 << (signal_index - n * 8 * sizeof sender->d_func()->connectedSignals[0]); - if ((sender->d_func()->connectedSignals[n] & m) == 0) - // nothing connected to these signals, and no spy - return; - } - activate(sender, signal_index, signal_index, argv); -} - -/*!\internal - */ -void QMetaObject::activate(QObject *sender, const QMetaObject *m, int local_signal_index, - void **argv) -{ - int signal_index = m->methodOffset() + local_signal_index; - if (signal_index < (int)sizeof(sender->d_func()->connectedSignals) * 8 - && !qt_signal_spy_callback_set.signal_begin_callback - && !qt_signal_spy_callback_set.signal_end_callback) { - uint n = (signal_index / (8 * sizeof sender->d_func()->connectedSignals[0])); - uint m = 1 << (signal_index - n * 8 * sizeof sender->d_func()->connectedSignals[0]); - if ((sender->d_func()->connectedSignals[n] & m) == 0) - // nothing connected to these signals, and no spy - return; - } - activate(sender, signal_index, signal_index, argv); + const QMetaObject *mo = sender->metaObject(); + while (mo && mo->methodOffset() > signal_index) + mo = mo->superClass(); + activate(sender, mo, signal_index - mo->methodOffset(), argv); } /*!\internal + Obsolete, called by moc generated code before Qt 4.6 for cloned signals + But since Qt 4.6, all clones are connected to their original */ void QMetaObject::activate(QObject *sender, const QMetaObject *m, int from_local_signal_index, int to_local_signal_index, void **argv) { - Q_ASSERT(from_local_signal_index <= to_local_signal_index); - int offset = m->methodOffset(); - int from_signal_index = offset + from_local_signal_index; - int to_signal_index = offset + to_local_signal_index; + Q_UNUSED(to_local_signal_index); + Q_ASSERT(from_local_signal_index == QMetaObjectPrivate::originalClone(m, to_local_signal_index)); + activate(sender, m, from_local_signal_index, argv); +} - if (to_signal_index < (int)sizeof(sender->d_func()->connectedSignals) * 8 - && !qt_signal_spy_callback_set.signal_begin_callback - && !qt_signal_spy_callback_set.signal_end_callback) { +/*! \internal + Returns the signal index used in the internal connectionLists vector. - uint n = (from_signal_index / (8 * sizeof sender->d_func()->connectedSignals[0])); - uint m = 1 << (from_signal_index - n * 8 * sizeof sender->d_func()->connectedSignals[0]); - uint nt = (to_signal_index / (8 * sizeof sender->d_func()->connectedSignals[0])); - uint mt = 1 << (to_signal_index - n * 8 * sizeof sender->d_func()->connectedSignals[0]); - bool connected = false; - quint32 *connectedSignals = sender->d_func()->connectedSignals; - for (uint i = 0; !connected && i < (sizeof sender->d_func()->connectedSignals - / sizeof sender->d_func()->connectedSignals[0]); ++i) { - uint mask = 0; - if (i > n) - mask = ~0u; - else if (i == n) - mask = ~(m -1); - if (i > nt) - mask = 0; - else if (i == nt) - mask &= (mt << 1) - 1; - connected = connectedSignals[i] & mask; - } - if (!connected) - // nothing connected to these signals, and no spy - return; - } - activate(sender, from_signal_index, to_signal_index, argv); + It is different from QMetaObject::indexOfSignal(): indexOfSignal is the same as indexOfMethod + while QObjectPrivate::signalIndex is smaller because it doesn't give index to slots. +*/ +int QObjectPrivate::signalIndex(const char *signalName) const +{ + Q_Q(const QObject); + const QMetaObject *base = q->metaObject(); + int relative_index = QMetaObjectPrivate::indexOfSignalRelative(&base, signalName); + if (relative_index < 0) + return relative_index; + relative_index = QMetaObjectPrivate::originalClone(base, relative_index); + int signalOffset, methodOffset; + computeOffsets(base, &signalOffset, &methodOffset); + return relative_index + signalOffset; } /*! \internal @@ -3344,14 +3410,16 @@ void QMetaObject::activate(QObject *sender, const QMetaObject *m, Returns true if the signal with index \a signal_index from object \a sender is connected. Signals with indices above a certain range are always considered connected (see connectedSignals in QObjectPrivate). If a signal spy is installed, all signals are considered connected. + + \a signal_index must be the index returned by QObjectPrivate::signalIndex; */ -bool QMetaObject::isConnected(QObject *sender, int signal_index) { - if (signal_index < (int)sizeof(sender->d_func()->connectedSignals) * 8 +bool QObjectPrivate::isSignalConnected(int signal_index) const { + if (signal_index < (int)sizeof(connectedSignals) * 8 && !qt_signal_spy_callback_set.signal_begin_callback && !qt_signal_spy_callback_set.signal_end_callback) { - uint n = (signal_index / (8 * sizeof sender->d_func()->connectedSignals[0])); - uint m = 1 << (signal_index - n * 8 * sizeof sender->d_func()->connectedSignals[0]); - if ((sender->d_func()->connectedSignals[n] & m) == 0) + uint n = (signal_index / (8 * sizeof connectedSignals[0])); + uint m = 1 << (signal_index - n * 8 * sizeof connectedSignals[0]); + if ((connectedSignals[n] & m) == 0) // nothing connected to these signals, and no spy return false; } @@ -3557,8 +3625,21 @@ void QObject::dumpObjectInfo() qDebug(" SIGNALS OUT"); if (d->connectionLists) { + int offset = 0; + int offsetToNextMetaObject = 0; for (int signal_index = 0; signal_index < d->connectionLists->count(); ++signal_index) { - const QMetaMethod signal = metaObject()->method(signal_index); + if (signal_index >= offsetToNextMetaObject) { + const QMetaObject *mo = metaObject(); + int signalOffset, methodOffset; + computeOffsets(mo, &signalOffset, &methodOffset); + while (mo && signalOffset > signal_index) { + mo = mo->superClass(); + offsetToNextMetaObject = signalOffset; + computeOffsets(mo, &signalOffset, &methodOffset); + } + offset = offset - signalOffset + methodOffset; + } + const QMetaMethod signal = metaObject()->method(signal_index + offset); qDebug(" signal: %s", signal.signature()); // receivers diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index 49d8b63..9721ef8 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -169,6 +169,9 @@ public: return o->d_func(); } + int signalIndex(const char *signalName) const; + bool isSignalConnected(int signalIdx) const; + public: QString objectName; ExtraData *extraData; // extra data set by the user diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h index befd596..421617a 100644 --- a/src/corelib/kernel/qobjectdefs.h +++ b/src/corelib/kernel/qobjectdefs.h @@ -330,12 +330,10 @@ struct Q_CORE_EXPORT QMetaObject static void connectSlotsByName(QObject *o); // internal index-based signal activation - static void activate(QObject *sender, int signal_index, void **argv); - static void activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv); + static void activate(QObject *sender, int signal_index, void **argv); //obsolete + static void activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv); //obsolete static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv); - static void activate(QObject *sender, const QMetaObject *, int from_local_signal_index, int to_local_signal_index, void **argv); - - static bool isConnected(QObject *sender, int signal_index); + static void activate(QObject *sender, const QMetaObject *, int from_local_signal_index, int to_local_signal_index, void **argv); //obsolete // internal guarded pointers static void addGuard(QObject **ptr); diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 54d6073..533ccd7 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -2467,7 +2467,7 @@ double QVariant::toDouble(bool *ok) const */ float QVariant::toFloat(bool *ok) const { - return qNumVariantToHelper<float>(d, handler, ok, d.data.d); + return qNumVariantToHelper<float>(d, handler, ok, d.data.f); } /*! @@ -2484,7 +2484,7 @@ float QVariant::toFloat(bool *ok) const */ qreal QVariant::toReal(bool *ok) const { - return qNumVariantToHelper<qreal>(d, handler, ok, d.data.d); + return qNumVariantToHelper<qreal>(d, handler, ok, d.data.real); } /*! diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 79bd5b8..d6a704e 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -358,6 +358,7 @@ class Q_CORE_EXPORT QVariant bool b; double d; float f; + qreal real; qlonglong ll; qulonglong ull; QObject *o; diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index 993c43b..c36899d 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -57,6 +57,7 @@ // to a pointer of the input type #include <QtCore/qglobal.h> +#include <QtCore/qvariant.h> QT_BEGIN_NAMESPACE @@ -145,6 +146,8 @@ inline void v_clear(QVariant::Private *d, T* = 0) } +Q_CORE_EXPORT const QVariant::Handler *qcoreVariantHandler(); + QT_END_NAMESPACE #endif // QVARIANT_P_H diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index 2853b1a..defa7af 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -217,6 +217,8 @@ public: static const Handler *handler; }; +Q_CORE_EXPORT const QStateMachinePrivate::Handler *qcoreStateMachineHandler(); + QT_END_NAMESPACE #endif diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 635c799..e952ea2 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -310,6 +310,7 @@ public: // stl compatibility typedef const char & const_reference; typedef char & reference; + typedef char value_type; void push_back(char c); void push_back(const char *c); void push_back(const QByteArray &a); diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index bebf141..a3053bb 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -832,7 +832,7 @@ struct QRegExpEngineKey } }; -bool operator==(const QRegExpEngineKey &key1, const QRegExpEngineKey &key2) +static bool operator==(const QRegExpEngineKey &key1, const QRegExpEngineKey &key2) { return key1.pattern == key2.pattern && key1.patternSyntax == key2.patternSyntax && key1.cs == key2.cs; diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp index a311b99..4cd8965 100644 --- a/src/corelib/xml/qxmlstream.cpp +++ b/src/corelib/xml/qxmlstream.cpp @@ -313,8 +313,8 @@ QXmlStreamEntityResolver *QXmlStreamReader::entityResolver() const error handling described. The \l{QXmlStream Bookmarks Example} illustrates how to use the - recursive descent technique with a subclassed stream reader to read - an XML bookmark file (XBEL). + recursive descent technique to read an XML bookmark file (XBEL) with + a stream reader. \section1 Namespaces @@ -2943,7 +2943,7 @@ QStringRef QXmlStreamReader::documentEncoding() const encodings can be enforced using setCodec(). The \l{QXmlStream Bookmarks Example} illustrates how to use a - subclassed stream writer to write an XML bookmark file (XBEL) that + stream writer to write an XML bookmark file (XBEL) that was previously read in by a QXmlStreamReader. */ diff --git a/src/dbus/qdbusmessage.cpp b/src/dbus/qdbusmessage.cpp index a676a01..851eaf0 100644 --- a/src/dbus/qdbusmessage.cpp +++ b/src/dbus/qdbusmessage.cpp @@ -707,7 +707,7 @@ QDBusMessage::MessageType QDBusMessage::type() const \sa QDBusConnection::send() */ #ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug dbg, QDBusMessage::MessageType t) +static QDebug operator<<(QDebug dbg, QDBusMessage::MessageType t) { switch (t) { diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index c9ceddc..da290b7 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -2,48 +2,69 @@ QML API Review ============== The QML API is being reviewed from 17 to 28 August 2009. This -file documents the changes. +file documents the changes. Note that the changes are incremental, +so a rename A->B for example may be follow by another subseqent +rename B->C, if later reviews override earlier reviews. API Changes =========== +Renamed Elements: +LineEdit -> TextInput +VerticalLayout -> VerticalPositioner +HorizontalLayout -> HorizontalPositioner +GridLayout -> GridPositioner +Rect -> Rectangle +FocusRealm -> FocusScope +FontFamily -> FontLoader +Palette -> SystemPalette +Bind -> Binding +SetProperties -> PropertyChanges +RunScript -> StateChangeScript +SetAnchors -> AnchorChanges +SetPropertyAction -> PropertyAction +RunScriptAction -> ScriptAction +ParentChangeAction -> ParentAction + Renamed properties: -MouseRegion: xmin -> minimumX -MouseRegion: xmax -> maximumX -MouseRegion: ymin -> minimumY -MouseRegion: ymin -> maximumY +MouseRegion: xmin -> minimumX +MouseRegion: xmax -> maximumX +MouseRegion: ymin -> minimumY +MouseRegion: ymin -> maximumY +Text elements: hAlign -> horizontalAlignment +Text elements: vAlign -> verticalAlignment +State: operations -> changes +Transition: operations -> animations +Transition: fromState -> from +Transition: toState -> to +Follow: followValue -> value Additions: MouseRegion: add "acceptedButtons" property MouseRegion: add "hoverEnabled" property +MouseRegion: add "pressedButtons" property +Timer: add start() and stop() slots + +Deletions: +VerticalPositioner: lost "margins" property +HorizontalPositioner: lost "margins" property +GridPositioner: lost "margins" property Other Changes: Drag: axis becomes an enum with values "XAxis", "YAxis", "XandYAxis" +Image: scaleGrid property removed. New item called BorderImage instead. +KeyActions: changed to a Keys attached property on any item. Pending Changes =============== Renamed elements: -RunScriptAction -> ScriptAction -ParentChangeAction -> ParentAction -Bind -> Binding -Palette -> SystemPalette -SetProperties -> PropertyChanges -RunScript -> StateChangeScript -SetAnchors -> AnchorChanges Renamed properties: -Follow: followValue -> value -State: operations -> changes -Transition: fromState -> from -Trnasition: toState -> to -Transition: operations -> animations Removed Properties: PropertyAction::property PropertyAction::target (if possible) Additions: -MouseRegion: add "pressedButtons" property Connection: add "slot" property -Timer: add start() and stop() slots diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 83b4eb5..d78e096 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -88,7 +88,7 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) it allows a different scale for the x and y axes, and allows the scale to be relative to an arbitrary point. - The following example scales the X axis of the Rect, relative to its interior point 25, 25: + The following example scales the X axis of the Rectangle, relative to its interior point 25, 25: \qml Rectangle { width: 100; height: 100 @@ -121,7 +121,7 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) \qmlclass Rotation \brief A Rotation object provides a way to rotate an Item around a point using an axis in 3D space. - The following example rotates a Rect around its interior point 25, 25: + The following example rotates a Rectangle around its interior point 25, 25: \qml Rectangle { width: 100; height: 100 diff --git a/src/declarative/fx/qfxmouseregion.cpp b/src/declarative/fx/qfxmouseregion.cpp index 6c71a9b..d3c776f 100644 --- a/src/declarative/fx/qfxmouseregion.cpp +++ b/src/declarative/fx/qfxmouseregion.cpp @@ -260,8 +260,19 @@ QFxMouseRegion::~QFxMouseRegion() /*! \qmlproperty real MouseRegion::mouseX \qmlproperty real MouseRegion::mouseY + These properties hold the coordinates of the mouse. - The coordinates of the mouse while pressed. The coordinates are relative to the item that was pressed. + If the hoverEnabled property is false then these properties will only be valid + while a button is pressed, and will remain valid as long as the button is held + even if the mouse is moved outside the region. + + If hoverEnabled is true then these properties will be valid: + \list + \i when no button is pressed, but the mouse is within the MouseRegion (containsMouse is true). + \i if a button is pressed and held, even if it has since moved out of the region. + \endlist + + The coordinates are relative to the MouseRegion. */ qreal QFxMouseRegion::mouseX() const { @@ -293,6 +304,38 @@ void QFxMouseRegion::setEnabled(bool a) emit enabledChanged(); } } +/*! + \qmlproperty MouseButtons MouseRegion::pressedButtons + This property holds the mouse buttons currently pressed. + + It contains a bitwise combination of: + \list + \o Qt.LeftButton + \o Qt.RightButton + \o Qt.MidButton + \endlist + + The code below displays "right" when the right mouse buttons is pressed: + \code + Text { + text: mr.pressedButtons & Qt.RightButton ? "right" : "" + horizontalAlignment: "AlignHCenter" + verticalAlignment: "AlignVCenter" + MouseRegion { + id: mr + acceptedButtons: Qt.LeftButton | Qt.RightButton + anchors.fill: parent + } + } + \endcode + + \sa acceptedButtons +*/ +Qt::MouseButtons QFxMouseRegion::pressedButtons() const +{ + Q_D(const QFxMouseRegion); + return d->lastButtons; +} void QFxMouseRegion::mousePressEvent(QGraphicsSceneMouseEvent *event) { @@ -389,9 +432,9 @@ void QFxMouseRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void QFxMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { Q_D(QFxMouseRegion); - if (!d->absorb) + if (!d->absorb) { QFxItem::mouseReleaseEvent(event); - else { + } else { d->saveEvent(event); setPressed(false); // If we don't accept hover, we need to reset containsMouse. @@ -403,9 +446,9 @@ void QFxMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void QFxMouseRegion::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { Q_D(QFxMouseRegion); - if (!d->absorb) + if (!d->absorb) { QFxItem::mouseDoubleClickEvent(event); - else { + } else { QFxItem::mouseDoubleClickEvent(event); if (event->isAccepted()) { // Only deliver the event if we have accepted the press. @@ -421,8 +464,19 @@ void QFxMouseRegion::hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_D(QFxMouseRegion); if (!d->absorb) QFxItem::hoverEnterEvent(event); - else { + else setHovered(true); +} + +void QFxMouseRegion::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_D(QFxMouseRegion); + if (!d->absorb) { + QFxItem::hoverEnterEvent(event); + } else { + d->lastPos = event->pos(); + QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, d->lastButtons, d->lastModifiers, false, d->longPress); + emit positionChanged(&me); } } @@ -431,9 +485,8 @@ void QFxMouseRegion::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_D(QFxMouseRegion); if (!d->absorb) QFxItem::hoverLeaveEvent(event); - else { + else setHovered(false); - } } bool QFxMouseRegion::sceneEvent(QEvent *event) @@ -467,7 +520,7 @@ void QFxMouseRegion::timerEvent(QTimerEvent *event) } /*! - \qmlproperty bool hoverEnabled + \qmlproperty bool MouseRegion::hoverEnabled This property holds whether hover events are handled. By default, mouse events are only handled in response to a button event, or when a button is diff --git a/src/declarative/fx/qfxmouseregion.h b/src/declarative/fx/qfxmouseregion.h index ae54ff6..7fb34b5 100644 --- a/src/declarative/fx/qfxmouseregion.h +++ b/src/declarative/fx/qfxmouseregion.h @@ -104,6 +104,7 @@ class Q_DECLARATIVE_EXPORT QFxMouseRegion : public QFxItem Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged) Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged) Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) Q_PROPERTY(bool hoverEnabled READ acceptHoverEvents WRITE setAcceptHoverEvents) Q_PROPERTY(QFxDrag *drag READ drag) //### add flicking to QFxDrag or add a QFxFlick ??? @@ -121,6 +122,8 @@ public: bool hovered() const; bool pressed() const; + Qt::MouseButtons pressedButtons() const; + Qt::MouseButtons acceptedButtons() const; void setAcceptedButtons(Qt::MouseButtons buttons); @@ -150,6 +153,7 @@ protected: void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverMoveEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); bool sceneEvent(QEvent *); void timerEvent(QTimerEvent *event); diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp index dcaaa54..69768b3 100644 --- a/src/declarative/fx/qfxtext.cpp +++ b/src/declarative/fx/qfxtext.cpp @@ -62,7 +62,7 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Text,QFxText) It can display both plain and rich text. For example: \qml - Text { text: "Hello World!"; font.family: "Helvetica"; font.size: 24; color: "red" } + Text { text: "Hello World!"; font.family: "Helvetica"; font.pointSize: 24; color: "red" } Text { text: "<b>Hello</b> <i>World!</i>" } \endqml @@ -90,7 +90,7 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Text,QFxText) It can display both plain and rich text. For example: \qml - Text { text: "Hello World!"; font.family: "Helvetica"; font.size: 24; color: "red" } + Text { text: "Hello World!"; font.family: "Helvetica"; font.pointSize: 24; color: "red" } Text { text: "<b>Hello</b> <i>World!</i>" } \endqml @@ -126,11 +126,11 @@ QFxText::~QFxText() \qmlproperty string Text::font.family \qmlproperty bool Text::font.bold \qmlproperty bool Text::font.italic - \qmlproperty real Text::font.size + \qmlproperty bool Text::font.underline + \qmlproperty real Text::font.pointSize + \qmlproperty int Text::font.pixelSize Set the Text's font attributes. - - \note \c font.size sets the font's point size (not pixel size). */ QFont QFxText::font() const { @@ -230,10 +230,10 @@ QColor QFxText::color() const \qml HorizontalPositioner { - Text { font.size: 24; text: "Normal" } - Text { font.size: 24; text: "Raised"; style: "Raised"; styleColor: "#AAAAAA" } - Text { font.size: 24; text: "Outline"; style: "Outline"; styleColor: "red" } - Text { font.size: 24; text: "Sunken"; style: "Sunken"; styleColor: "#AAAAAA" } + Text { font.pointSize: 24; text: "Normal" } + Text { font.pointSize: 24; text: "Raised"; style: "Raised"; styleColor: "#AAAAAA" } + Text { font.pointSize: 24; text: "Outline"; style: "Outline"; styleColor: "red" } + Text { font.pointSize: 24; text: "Sunken"; style: "Sunken"; styleColor: "#AAAAAA" } } \endqml @@ -365,16 +365,16 @@ void QFxText::setWrap(bool w) \qml VerticalPositioner { TextEdit { - font.size: 24 + font.pointSize: 24 text: "<b>Hello</b> <i>World!</i>" } TextEdit { - font.size: 24 + font.pointSize: 24 textFormat: "RichText" text: "<b>Hello</b> <i>World!</i>" } TextEdit { - font.size: 24 + font.pointSize: 24 textFormat: "PlainText" text: "<b>Hello</b> <i>World!</i>" } diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index f7f5f0a..eaceeeb 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -67,7 +67,7 @@ TextEdit { text: "<b>Hello</b> <i>World!</i>" focus: true font.family: "Helvetica" - font.size: 20 + font.pointSize: 20 color: "blue" width: 240 } @@ -124,9 +124,14 @@ QString QFxTextEdit::text() const } /*! - \qmlproperty font TextEdit::font - - Set the TextEdit's font attributes. \c font.size sets the font's point size. + \qmlproperty string TextEdit::font.family + \qmlproperty bool TextEdit::font.bold + \qmlproperty bool TextEdit::font.italic + \qmlproperty bool TextEdit::font.underline + \qmlproperty real TextEdit::font.pointSize + \qmlproperty int TextEdit::font.pixelSize + + Set the TextEdit's font attributes. */ /*! @@ -169,16 +174,16 @@ void QFxTextEdit::setText(const QString &text) \qml VerticalPositioner { TextEdit { - font.size: 24 + font.pointSize: 24 text: "<b>Hello</b> <i>World!</i>" } TextEdit { - font.size: 24 + font.pointSize: 24 textFormat: "RichText" text: "<b>Hello</b> <i>World!</i>" } TextEdit { - font.size: 24 + font.pointSize: 24 textFormat: "PlainText" text: "<b>Hello</b> <i>World!</i>" } diff --git a/src/declarative/fx/qfxtextinput.cpp b/src/declarative/fx/qfxtextinput.cpp index 164739f..b9b33ab 100644 --- a/src/declarative/fx/qfxtextinput.cpp +++ b/src/declarative/fx/qfxtextinput.cpp @@ -99,9 +99,14 @@ void QFxTextInput::setText(const QString &s) } /*! - \qmlproperty font TextInput::font - - Set the TextInput's font attributes. \c font.size sets the font's point size. + \qmlproperty string TextInput::font.family + \qmlproperty bool TextInput::font.bold + \qmlproperty bool TextInput::font.italic + \qmlproperty bool TextInput::font.underline + \qmlproperty real TextInput::font.pointSize + \qmlproperty int TextInput::font.pixelSize + + Set the TextInput's font attributes. */ QFont QFxTextInput::font() const { diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp index 45d20f4..39851ff 100644 --- a/src/declarative/qml/qmlbinding.cpp +++ b/src/declarative/qml/qmlbinding.cpp @@ -49,6 +49,7 @@ #include <QtCore/qdebug.h> #include <private/qmlcontext_p.h> #include <private/qmldeclarativedata_p.h> +#include <private/qmlstringconverters_p.h> Q_DECLARE_METATYPE(QList<QObject *>); @@ -129,6 +130,11 @@ void QmlBinding::update() (value.type() == QVariant::String || value.type() == QVariant::ByteArray) && !value.isNull()) value.setValue(context()->resolvedUrl(QUrl(value.toString()))); + if (d->property.propertyType() == QVariant::Vector3D && + value.type() == QVariant::String) { + value = qVariantFromValue(QmlStringConverters::vector3DFromString(value.toString())); + } + d->property.write(value); } diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index e04c876..1771cb4 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -297,6 +297,13 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, if (!v->value.isBoolean()) COMPILE_EXCEPTION(v, "Invalid property assignment: boolean expected"); } break; + case QVariant::Vector3D: + { + bool ok; + QVector3D point = QmlStringConverters::vector3DFromString(string, &ok); + if (!ok) COMPILE_EXCEPTION(v, "Invalid property assignment: 3D vector expected"); + } + break; default: { int t = prop.type(); @@ -487,6 +494,18 @@ void QmlCompiler::genLiteralAssignment(const QMetaProperty &prop, instr.storeBool.value = b; } break; + case QVariant::Vector3D: + { + bool ok; + QVector3D vector = + QmlStringConverters::vector3DFromString(string, &ok); + float data[] = { vector.x(), vector.y(), vector.z() }; + int index = output->indexForFloat(data, 3); + instr.type = QmlInstruction::StoreVector3D; + instr.storeRealPair.propertyIndex = prop.propertyIndex(); + instr.storeRealPair.valueIndex = index; + } + break; default: { int t = prop.type(); @@ -550,6 +569,7 @@ bool QmlCompiler::compile(QmlEngine *engine, for (int ii = 0; ii < unit->types.count(); ++ii) { QmlCompositeTypeData::TypeReference &tref = unit->types[ii]; QmlCompiledData::TypeReference ref; + QmlScriptParser::TypeReference *parserRef = unit->data.referencedTypes().at(ii); if (tref.type) ref.type = tref.type; else if (tref.unit) { @@ -559,7 +579,13 @@ bool QmlCompiler::compile(QmlEngine *engine, QmlError error; error.setUrl(output->url); error.setDescription(QLatin1String("Unable to create type ") + - unit->data.types().at(ii)); + parserRef->name); + if (!parserRef->refObjects.isEmpty()) { + QmlParser::Object *parserObject = parserRef->refObjects.first(); + error.setLine(parserObject->location.start.line); + error.setColumn(parserObject->location.start.column); + } + exceptions << error; exceptions << ref.component->errors(); reset(out); @@ -568,7 +594,7 @@ bool QmlCompiler::compile(QmlEngine *engine, ref.ref = tref.unit; ref.ref->addref(); } - ref.className = unit->data.types().at(ii).toLatin1(); + ref.className = parserRef->name.toLatin1(); out->types << ref; } @@ -1449,7 +1475,7 @@ bool QmlCompiler::buildAttachedProperty(QmlParser::Property *prop, // Build "grouped" properties. In this example: // Text { -// font.size: 12 +// font.pointSize: 12 // font.family: "Helvetica" // } // font is a nested property. size and family are not. diff --git a/src/declarative/qml/qmlcompositetypedata_p.h b/src/declarative/qml/qmlcompositetypedata_p.h index 3469fea..54933c4 100644 --- a/src/declarative/qml/qmlcompositetypedata_p.h +++ b/src/declarative/qml/qmlcompositetypedata_p.h @@ -91,7 +91,7 @@ struct QmlCompositeTypeData : public QmlRefCount // occurs QmlCompiledData *toCompiledComponent(QmlEngine *); - struct TypeReference + struct TypeReference { TypeReference(); diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index 97391e6..0fb6c86 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -311,21 +311,23 @@ void QmlCompositeTypeManager::checkComplete(QmlCompositeTypeData *unit) void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) { - QStringList typeNames = unit->data.types(); + QList<QmlScriptParser::TypeReference*> types = unit->data.referencedTypes(); int waiting = 0; - for (int ii = 0; ii < typeNames.count(); ++ii) { - QByteArray type = typeNames.at(ii).toLatin1(); + for (int ii = 0; ii < types.count(); ++ii) { + QmlScriptParser::TypeReference *parserRef = types.at(ii); + QByteArray typeName = parserRef->name.toLatin1(); QmlCompositeTypeData::TypeReference ref; - if (type == QByteArray("Property") || - type == QByteArray("Signal")) { + + if (typeName == QByteArray("Property") || + typeName == QByteArray("Signal")) { unit->types << ref; continue; } QUrl url; - if (!QmlEnginePrivate::get(engine)->resolveType(unit->imports, type, &ref.type, &url)) { + if (!QmlEnginePrivate::get(engine)->resolveType(unit->imports, typeName, &ref.type, &url)) { // XXX could produce error message here. } @@ -353,7 +355,12 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) { QmlError error; error.setUrl(unit->imports.baseUrl()); - error.setDescription(tr("Type %1 unavailable").arg(QLatin1String(type))); + error.setDescription(tr("Type %1 unavailable").arg(QLatin1String(typeName))); + if (!parserRef->refObjects.isEmpty()) { + QmlParser::Object *obj = parserRef->refObjects.first(); + error.setLine(obj->location.start.line); + error.setColumn(obj->location.start.column); + } unit->errors << error; } if (urlUnit->errorType != QmlCompositeTypeData::AccessError) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 84c9553..351bd8a 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -71,6 +71,7 @@ #include <QtCore/qthread.h> #include <QtCore/qcoreapplication.h> #include <QtCore/qdir.h> +#include <QtGui/qvector3d.h> #include <qmlcomponent.h> #include "private/qmlcomponentjs_p.h" #include "private/qmlmetaproperty_p.h" @@ -158,6 +159,8 @@ void QmlEnginePrivate::init() scriptEngine.newFunction(QmlEnginePrivate::createQmlObject, 1)); scriptEngine.globalObject().setProperty(QLatin1String("createComponent"), scriptEngine.newFunction(QmlEnginePrivate::createComponent, 1)); + scriptEngine.globalObject().setProperty(QLatin1String("vector"), + scriptEngine.newFunction(QmlEnginePrivate::vector, 1)); if (QCoreApplication::instance()->thread() == q->thread() && QmlEngineDebugServer::isDebuggingEnabled()) { @@ -692,6 +695,42 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi return engine->nullValue(); } +/*! + This function is intended for use inside QML only. In C++ just create a + QVector3D as usual. + + This function takes three numeric components and combines them into a + QMLJS string that can be used with any property that takes a + QVector3D argument. The following QML code: + + \code + transform: Rotation { + id: Rotation + origin.x: Container.width / 2; + axis: vector(0, 1, 1) + } + \endcode + + is equivalent to: + + \code + transform: Rotation { + id: Rotation + origin.x: Container.width / 2; + axis.x: 0; axis.y: 1; axis.z: 0 + } + \endcode +*/ +QScriptValue QmlEnginePrivate::vector(QScriptContext *ctxt, QScriptEngine *engine) +{ + if(ctxt->argumentCount() < 3) + return engine->nullValue(); + qsreal x = ctxt->argument(0).toNumber(); + qsreal y = ctxt->argument(1).toNumber(); + qsreal z = ctxt->argument(2).toNumber(); + return engine->newVariant(qVariantFromValue(QVector3D(x, y, z))); +} + QmlScriptClass::QmlScriptClass(QmlEngine *bindengine) : QScriptClass(QmlEnginePrivate::getScriptEngine(bindengine)), engine(bindengine) diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index aaf679f..4142872 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -204,6 +204,7 @@ public: static QScriptValue qmlScriptObject(QObject*, QmlEngine*); static QScriptValue createComponent(QScriptContext*, QScriptEngine*); static QScriptValue createQmlObject(QScriptContext*, QScriptEngine*); + static QScriptValue vector(QScriptContext*, QScriptEngine*); static QScriptEngine *getScriptEngine(QmlEngine *e) { return &e->d_func()->scriptEngine; } static QmlEnginePrivate *get(QmlEngine *e) { return e->d_func(); } diff --git a/src/declarative/qml/qmlinstruction.cpp b/src/declarative/qml/qmlinstruction.cpp index fd912ac..02e4883 100644 --- a/src/declarative/qml/qmlinstruction.cpp +++ b/src/declarative/qml/qmlinstruction.cpp @@ -119,6 +119,9 @@ void QmlCompiledData::dump(QmlInstruction *instr, int idx) case QmlInstruction::StoreRectF: qWarning() << idx << "\t" << line << "\t" << "STORE_RECTF\t\t" << instr->storeRect.propertyIndex << "\t" << instr->storeRect.valueIndex; break; + case QmlInstruction::StoreVector3D: + qWarning() << idx << "\t" << line << "\t" << "STORE_VECTOR3D\t\t" << instr->storeVector3D.propertyIndex << "\t" << instr->storeVector3D.valueIndex; + break; case QmlInstruction::StoreVariant: qWarning() << idx << "\t" << line << "\t" << "STORE_VARIANT\t\t" << instr->storeString.propertyIndex << "\t" << instr->storeString.value << "\t\t" << primitives.at(instr->storeString.value); break; diff --git a/src/declarative/qml/qmlinstruction_p.h b/src/declarative/qml/qmlinstruction_p.h index 7f3498f..0f2995a 100644 --- a/src/declarative/qml/qmlinstruction_p.h +++ b/src/declarative/qml/qmlinstruction_p.h @@ -111,6 +111,7 @@ public: StoreSizeF, /* storeRealPair */ StoreRect, /* storeRect */ StoreRectF, /* storeRect */ + StoreVector3D, /* storeVector3D */ StoreVariant, /* storeString */ StoreObject, /* storeObject */ StoreVariantObject, /* storeObject */ @@ -263,6 +264,10 @@ public: } storeRect; struct { int propertyIndex; + int valueIndex; + } storeVector3D; + struct { + int propertyIndex; } storeObject; struct { int propertyIndex; diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp index 091bd1b..ab64079 100644 --- a/src/declarative/qml/qmlmetatype.cpp +++ b/src/declarative/qml/qmlmetatype.cpp @@ -75,6 +75,7 @@ # include <qpoint.h> # include <qrect.h> # include <qline.h> +# include <qvector3d.h> #endif #define NS(x) QT_PREPEND_NAMESPACE(x) @@ -1028,6 +1029,9 @@ bool QmlMetaType::copy(int type, void *data, const void *copy) case QMetaType::QPointF: *static_cast<NS(QPointF) *>(data) = *static_cast<const NS(QPointF)*>(copy); return true; + case QMetaType::QVector3D: + *static_cast<NS(QVector3D) *>(data) = *static_cast<const NS(QVector3D)*>(copy); + return true; #endif #ifndef QT_NO_REGEXP case QMetaType::QRegExp: @@ -1155,6 +1159,9 @@ bool QmlMetaType::copy(int type, void *data, const void *copy) case QMetaType::QPointF: *static_cast<NS(QPointF) *>(data) = NS(QPointF)(); return true; + case QMetaType::QVector3D: + *static_cast<NS(QVector3D) *>(data) = NS(QVector3D)(); + return true; #endif #ifndef QT_NO_REGEXP case QMetaType::QRegExp: diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index 2f82f0d..187f640 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -288,10 +288,13 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, QString resolvableObjectType = objectType; if (lastTypeDot >= 0) resolvableObjectType.replace(QLatin1Char('.'),QLatin1Char('/')); - const int typeId = _parser->findOrCreateTypeId(resolvableObjectType); + + QmlScriptParser::TypeReference *typeRef = _parser->findOrCreateType(resolvableObjectType); Object *obj = new Object; - obj->type = typeId; + obj->type = typeRef->id; + + typeRef->refObjects.append(obj); // XXX this doesn't do anything (_scope never builds up) _scope.append(resolvableObjectType); @@ -802,9 +805,9 @@ bool QmlScriptParser::parse(const QByteArray &qmldata, const QUrl &url) return _errors.isEmpty(); } -QStringList QmlScriptParser::types() const +QList<QmlScriptParser::TypeReference*> QmlScriptParser::referencedTypes() const { - return _typeNames; + return _refTypes; } Object *QmlScriptParser::tree() const @@ -828,7 +831,8 @@ void QmlScriptParser::clear() root->release(); root = 0; } - _typeNames.clear(); + qDeleteAll(_refTypes); + _refTypes.clear(); _errors.clear(); if (data) { @@ -837,16 +841,22 @@ void QmlScriptParser::clear() } } -int QmlScriptParser::findOrCreateTypeId(const QString &name) +QmlScriptParser::TypeReference *QmlScriptParser::findOrCreateType(const QString &name) { - int index = _typeNames.indexOf(name); - - if (index == -1) { - index = _typeNames.size(); - _typeNames.append(name); + TypeReference *type = 0; + int i = 0; + for (; i < _refTypes.size(); ++i) { + if (_refTypes.at(i)->name == name) { + type = _refTypes.at(i); + break; + } + } + if (!type) { + type = new TypeReference(i, name); + _refTypes.append(type); } - return index; + return type; } void QmlScriptParser::setTree(Object *tree) diff --git a/src/declarative/qml/qmlscriptparser_p.h b/src/declarative/qml/qmlscriptparser_p.h index 355ff75..d489610 100644 --- a/src/declarative/qml/qmlscriptparser_p.h +++ b/src/declarative/qml/qmlscriptparser_p.h @@ -84,12 +84,24 @@ public: QmlParser::LocationSpan location; }; + class TypeReference + { + public: + TypeReference(int typeId, const QString &typeName) : id(typeId), name(typeName) {} + + int id; + // type as it has been referenced in Qml + QString name; + // objects in parse tree referencing the type + QList<QmlParser::Object*> refObjects; + }; + QmlScriptParser(); ~QmlScriptParser(); bool parse(const QByteArray &data, const QUrl &url = QUrl()); - QStringList types() const; + QList<TypeReference*> referencedTypes() const; QmlParser::Object *tree() const; QList<Import> imports() const; @@ -99,7 +111,7 @@ public: QList<QmlError> errors() const; // ### private: - int findOrCreateTypeId(const QString &name); + TypeReference *findOrCreateType(const QString &name); void setTree(QmlParser::Object *tree); void setScriptFile(const QString &filename) {_scriptFile = filename; } @@ -110,7 +122,7 @@ public: QmlParser::Object *root; QList<Import> _imports; - QStringList _typeNames; + QList<TypeReference*> _refTypes; QString _scriptFile; QmlScriptParserJsASTData *data; }; diff --git a/src/declarative/qml/qmlstringconverters.cpp b/src/declarative/qml/qmlstringconverters.cpp index c1f4b8c..34025c5 100644 --- a/src/declarative/qml/qmlstringconverters.cpp +++ b/src/declarative/qml/qmlstringconverters.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include <QtGui/qcolor.h> +#include <QtGui/qvector3d.h> #include <QtCore/qpoint.h> #include <QtCore/qrect.h> #include <QtCore/qsize.h> @@ -94,6 +95,8 @@ QVariant QmlStringConverters::variantFromString(const QString &s) if (ok) return QVariant(sz); bool b = boolFromString(s, &ok); if (ok) return QVariant(b); + QVector3D v = vector3DFromString(s, &ok); + if (ok) return qVariantFromValue(v); return QVariant(s); } @@ -209,4 +212,30 @@ bool QmlStringConverters::boolFromString(const QString &str, bool *ok) return true; } +//expects input of "x,y,z" +QVector3D QmlStringConverters::vector3DFromString(const QString &s, bool *ok) +{ + if (s.count(QLatin1Char(',')) != 2) { + if (ok) + *ok = false; + return QVector3D(); + } + + bool xGood, yGood, zGood; + int index = s.indexOf(QLatin1Char(',')); + int index2 = s.indexOf(QLatin1Char(','), index+1); + qreal xCoord = s.left(index).toDouble(&xGood); + qreal yCoord = s.mid(index+1, index2-index-1).toDouble(&yGood); + qreal zCoord = s.mid(index2+1).toDouble(&zGood); + if (!xGood || !yGood || !zGood) { + if (ok) + *ok = false; + return QVector3D(); + } + + if (ok) + *ok = true; + return QVector3D(xCoord, yCoord, zCoord); +} + QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlstringconverters_p.h b/src/declarative/qml/qmlstringconverters_p.h index 52426a7..ab7448c 100644 --- a/src/declarative/qml/qmlstringconverters_p.h +++ b/src/declarative/qml/qmlstringconverters_p.h @@ -60,6 +60,7 @@ class QSizeF; class QRectF; class QString; class QByteArray; +class QVector3D; QT_BEGIN_NAMESPACE @@ -72,6 +73,7 @@ namespace QmlStringConverters QSizeF Q_DECLARATIVE_EXPORT sizeFFromString(const QString &, bool *ok = 0); QRectF Q_DECLARATIVE_EXPORT rectFFromString(const QString &, bool *ok = 0); bool Q_DECLARATIVE_EXPORT boolFromString(const QString &, bool *ok = 0); + QVector3D Q_DECLARATIVE_EXPORT vector3DFromString(const QString &, bool *ok = 0); }; QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index 79b1d89..7455eb4 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -439,6 +439,19 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledData } break; + case QmlInstruction::StoreVector3D: + { + QObject *target = stack.top(); + void *a[1]; + QVector3D p(floatData.at(instr.storeVector3D.valueIndex), + floatData.at(instr.storeVector3D.valueIndex+1), + floatData.at(instr.storeVector3D.valueIndex+2)); + a[0] = (void *)&p; + QMetaObject::metacall(target, QMetaObject::WriteProperty, + instr.storeVector3D.propertyIndex, a); + } + break; + case QmlInstruction::StoreObject: { QObject *assignObj = stack.pop(); diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 7faddee..720a045 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -422,7 +422,7 @@ void QmlAbstractAnimation::setGroup(QmlAnimationGroup *g) } /*! - \qmlproperty Object SetPropertyAction::target + \qmlproperty Object PropertyAction::target This property holds an explicit target object to animate. The exact effect of the \c target property depends on how the animation @@ -459,7 +459,7 @@ void QmlAbstractAnimation::setTarget(QObject *o) } /*! - \qmlproperty string SetPropertyAction::property + \qmlproperty string PropertyAction::property This property holds an explicit property to animated. The exact effect of the \c property property depends on how the animation @@ -762,46 +762,46 @@ void QmlColorAnimation::setTo(const QColor &t) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ColorAnimation,QmlColorAnimation) /*! - \qmlclass RunScriptAction QmlRunScriptAction + \qmlclass ScriptAction QmlScriptAction \inherits Animation - \brief The RunScripAction allows scripts to be run during an animation. + \brief The ScriptAction allows scripts to be run during an animation. */ /*! \internal - \class QmlRunScriptAction + \class QmlScriptAction */ -QmlRunScriptAction::QmlRunScriptAction(QObject *parent) - :QmlAbstractAnimation(*(new QmlRunScriptActionPrivate), parent) +QmlScriptAction::QmlScriptAction(QObject *parent) + :QmlAbstractAnimation(*(new QmlScriptActionPrivate), parent) { - Q_D(QmlRunScriptAction); + Q_D(QmlScriptAction); d->init(); } -QmlRunScriptAction::~QmlRunScriptAction() +QmlScriptAction::~QmlScriptAction() { } -void QmlRunScriptActionPrivate::init() +void QmlScriptActionPrivate::init() { - Q_Q(QmlRunScriptAction); + Q_Q(QmlScriptAction); rsa = new QActionAnimation(&proxy); QFx_setParent_noEvent(rsa, q); } /*! - \qmlproperty QString RunScriptAction::script + \qmlproperty QString ScriptAction::script This property holds the script to run. */ -QString QmlRunScriptAction::script() const +QString QmlScriptAction::script() const { - Q_D(const QmlRunScriptAction); + Q_D(const QmlScriptAction); return d->script; } -void QmlRunScriptAction::setScript(const QString &script) +void QmlScriptAction::setScript(const QString &script) { - Q_D(QmlRunScriptAction); + Q_D(QmlScriptAction); if (script == d->script) return; d->script = script; @@ -809,27 +809,27 @@ void QmlRunScriptAction::setScript(const QString &script) } /*! - \qmlproperty QString RunScriptAction::runScriptName - This property holds the the name of the RunScript to run. + \qmlproperty QString ScriptAction::runScriptName + This property holds the the name of the StateChangeScript to run. - This property is only valid when RunScriptAction is used as part of a transition. + This property is only valid when ScriptAction is used as part of a transition. If both script and runScriptName are set, runScriptName will be used. */ -QString QmlRunScriptAction::runScriptName() const +QString QmlScriptAction::runScriptName() const { - Q_D(const QmlRunScriptAction); + Q_D(const QmlScriptAction); return d->script; } -void QmlRunScriptAction::setRunScriptName(const QString &name) +void QmlScriptAction::setRunScriptName(const QString &name) { - Q_D(QmlRunScriptAction); + Q_D(QmlScriptAction); d->name = name; } -void QmlRunScriptActionPrivate::execute() +void QmlScriptActionPrivate::execute() { - Q_Q(QmlRunScriptAction); + Q_Q(QmlScriptAction); QString scriptStr = runScriptScript.isEmpty() ? script : runScriptScript; if (!scriptStr.isEmpty()) { @@ -839,11 +839,11 @@ void QmlRunScriptActionPrivate::execute() } } -void QmlRunScriptAction::transition(QmlStateActions &actions, +void QmlScriptAction::transition(QmlStateActions &actions, QmlMetaProperties &modified, TransitionDirection direction) { - Q_D(QmlRunScriptAction); + Q_D(QmlScriptAction); Q_UNUSED(modified); Q_UNUSED(direction); @@ -851,77 +851,77 @@ void QmlRunScriptAction::transition(QmlStateActions &actions, for (int ii = 0; ii < actions.count(); ++ii) { Action &action = actions[ii]; - if (action.event && action.event->typeName() == QLatin1String("RunScript") - && static_cast<QmlRunScript*>(action.event)->name() == d->name) { + if (action.event && action.event->typeName() == QLatin1String("StateChangeScript") + && static_cast<QmlStateChangeScript*>(action.event)->name() == d->name) { //### how should we handle reverse direction? - d->runScriptScript = static_cast<QmlRunScript*>(action.event)->script(); + d->runScriptScript = static_cast<QmlStateChangeScript*>(action.event)->script(); action.actionDone = true; break; //assumes names are unique } } } -QAbstractAnimation *QmlRunScriptAction::qtAnimation() +QAbstractAnimation *QmlScriptAction::qtAnimation() { - Q_D(QmlRunScriptAction); + Q_D(QmlScriptAction); return d->rsa; } -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,RunScriptAction,QmlRunScriptAction) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ScriptAction,QmlScriptAction) /*! - \qmlclass SetPropertyAction QmlSetPropertyAction + \qmlclass PropertyAction QmlPropertyAction \inherits Animation - \brief The SetPropertyAction allows immediate property changes during animation. + \brief The PropertyAction allows immediate property changes during animation. Explicitly set \c theimage.smooth=true during a transition: \code - SetPropertyAction { target: theimage; property: "smooth"; value: true } + PropertyAction { target: theimage; property: "smooth"; value: true } \endcode Set \c thewebview.url to the value set for the destination state: \code - SetPropertyAction { target: thewebview; property: "url" } + PropertyAction { target: thewebview; property: "url" } \endcode - The SetPropertyAction is immediate - + The PropertyAction is immediate - the target property is not animated to the selected value in any way. */ /*! \internal - \class QmlSetPropertyAction + \class QmlPropertyAction */ -QmlSetPropertyAction::QmlSetPropertyAction(QObject *parent) -: QmlAbstractAnimation(*(new QmlSetPropertyActionPrivate), parent) +QmlPropertyAction::QmlPropertyAction(QObject *parent) +: QmlAbstractAnimation(*(new QmlPropertyActionPrivate), parent) { - Q_D(QmlSetPropertyAction); + Q_D(QmlPropertyAction); d->init(); } -QmlSetPropertyAction::~QmlSetPropertyAction() +QmlPropertyAction::~QmlPropertyAction() { } -void QmlSetPropertyActionPrivate::init() +void QmlPropertyActionPrivate::init() { - Q_Q(QmlSetPropertyAction); + Q_Q(QmlPropertyAction); spa = new QActionAnimation; QFx_setParent_noEvent(spa, q); } /*! - \qmlproperty string SetPropertyAction::properties + \qmlproperty string PropertyAction::properties This property holds the properties to be immediately set, comma-separated. */ -QString QmlSetPropertyAction::properties() const +QString QmlPropertyAction::properties() const { - Q_D(const QmlSetPropertyAction); + Q_D(const QmlPropertyAction); return d->properties; } -void QmlSetPropertyAction::setProperties(const QString &p) +void QmlPropertyAction::setProperties(const QString &p) { - Q_D(QmlSetPropertyAction); + Q_D(QmlPropertyAction); if (d->properties == p) return; d->properties = p; @@ -929,61 +929,61 @@ void QmlSetPropertyAction::setProperties(const QString &p) } /*! - \qmlproperty list<Item> SetPropertyAction::targets + \qmlproperty list<Item> PropertyAction::targets This property holds the items selected to be affected by this animation (all if not set). \sa exclude */ -QList<QObject *> *QmlSetPropertyAction::targets() +QList<QObject *> *QmlPropertyAction::targets() { - Q_D(QmlSetPropertyAction); + Q_D(QmlPropertyAction); return &d->targets; } /*! - \qmlproperty list<Item> SetPropertyAction::exclude + \qmlproperty list<Item> PropertyAction::exclude This property holds the items not to be affected by this animation. \sa targets */ -QList<QObject *> *QmlSetPropertyAction::exclude() +QList<QObject *> *QmlPropertyAction::exclude() { - Q_D(QmlSetPropertyAction); + Q_D(QmlPropertyAction); return &d->exclude; } /*! - \qmlproperty any SetPropertyAction::value + \qmlproperty any PropertyAction::value This property holds the value to be set on the property. If not set, then the value defined for the end state of the transition. */ -QVariant QmlSetPropertyAction::value() const +QVariant QmlPropertyAction::value() const { - Q_D(const QmlSetPropertyAction); + Q_D(const QmlPropertyAction); return d->value; } -void QmlSetPropertyAction::setValue(const QVariant &v) +void QmlPropertyAction::setValue(const QVariant &v) { - Q_D(QmlSetPropertyAction); + Q_D(QmlPropertyAction); if (d->value.isNull || d->value != v) { d->value = v; emit valueChanged(v); } } -void QmlSetPropertyActionPrivate::doAction() +void QmlPropertyActionPrivate::doAction() { property.write(value); } -QAbstractAnimation *QmlSetPropertyAction::qtAnimation() +QAbstractAnimation *QmlPropertyAction::qtAnimation() { - Q_D(QmlSetPropertyAction); + Q_D(QmlPropertyAction); return d->spa; } -void QmlSetPropertyAction::prepare(QmlMetaProperty &p) +void QmlPropertyAction::prepare(QmlMetaProperty &p) { - Q_D(QmlSetPropertyAction); + Q_D(QmlPropertyAction); if (d->userProperty.isNull) d->property = p; @@ -993,11 +993,11 @@ void QmlSetPropertyAction::prepare(QmlMetaProperty &p) d->spa->setAnimAction(&d->proxy, QAbstractAnimation::KeepWhenStopped); } -void QmlSetPropertyAction::transition(QmlStateActions &actions, +void QmlPropertyAction::transition(QmlStateActions &actions, QmlMetaProperties &modified, TransitionDirection direction) { - Q_D(QmlSetPropertyAction); + Q_D(QmlPropertyAction); Q_UNUSED(direction); struct QmlSetPropertyAnimationAction : public QAbstractAnimationAction @@ -1072,59 +1072,59 @@ void QmlSetPropertyAction::transition(QmlStateActions &actions, } } -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,SetPropertyAction,QmlSetPropertyAction) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PropertyAction,QmlPropertyAction) /*! - \qmlclass ParentChangeAction QmlParentChangeAction + \qmlclass ParentAction QmlParentAction \inherits Animation - \brief The ParentChangeAction allows parent changes during transitions. + \brief The ParentAction allows parent changes during transitions. - The ParentChangeAction is immediate - it is not animated in any way. + The ParentAction is immediate - it is not animated in any way. */ -QmlParentChangeAction::QmlParentChangeAction(QObject *parent) -: QmlAbstractAnimation(*(new QmlParentChangeActionPrivate), parent) +QmlParentAction::QmlParentAction(QObject *parent) +: QmlAbstractAnimation(*(new QmlParentActionPrivate), parent) { - Q_D(QmlParentChangeAction); + Q_D(QmlParentAction); d->init(); } -QmlParentChangeAction::~QmlParentChangeAction() +QmlParentAction::~QmlParentAction() { } -void QmlParentChangeActionPrivate::init() +void QmlParentActionPrivate::init() { - Q_Q(QmlParentChangeAction); + Q_Q(QmlParentAction); cpa = new QActionAnimation; QFx_setParent_noEvent(cpa, q); } -QFxItem *QmlParentChangeAction::object() const +QFxItem *QmlParentAction::object() const { - Q_D(const QmlParentChangeAction); + Q_D(const QmlParentAction); return d->pcTarget; } -void QmlParentChangeAction::setObject(QFxItem *target) +void QmlParentAction::setObject(QFxItem *target) { - Q_D(QmlParentChangeAction); + Q_D(QmlParentAction); d->pcTarget = target; } -QFxItem *QmlParentChangeAction::parent() const +QFxItem *QmlParentAction::parent() const { - Q_D(const QmlParentChangeAction); + Q_D(const QmlParentAction); return d->pcParent; } -void QmlParentChangeAction::setParent(QFxItem *parent) +void QmlParentAction::setParent(QFxItem *parent) { - Q_D(QmlParentChangeAction); + Q_D(QmlParentAction); d->pcParent = parent; } -void QmlParentChangeActionPrivate::doAction() +void QmlParentActionPrivate::doAction() { QmlParentChange pc; pc.setObject(pcTarget); @@ -1132,24 +1132,24 @@ void QmlParentChangeActionPrivate::doAction() pc.execute(); } -QAbstractAnimation *QmlParentChangeAction::qtAnimation() +QAbstractAnimation *QmlParentAction::qtAnimation() { - Q_D(QmlParentChangeAction); + Q_D(QmlParentAction); return d->cpa; } -void QmlParentChangeAction::transition(QmlStateActions &actions, +void QmlParentAction::transition(QmlStateActions &actions, QmlMetaProperties &modified, TransitionDirection direction) { - Q_D(QmlParentChangeAction); + Q_D(QmlParentAction); Q_UNUSED(modified); Q_UNUSED(direction); - struct QmlParentChangeActionData : public QAbstractAnimationAction + struct QmlParentActionData : public QAbstractAnimationAction { - QmlParentChangeActionData(): pc(0) {} - ~QmlParentChangeActionData() { delete pc; } + QmlParentActionData(): pc(0) {} + ~QmlParentActionData() { delete pc; } QmlStateActions actions; bool reverse; @@ -1166,7 +1166,7 @@ void QmlParentChangeAction::transition(QmlStateActions &actions, } }; - QmlParentChangeActionData *data = new QmlParentChangeActionData; + QmlParentActionData *data = new QmlParentActionData; for (int ii = 0; ii < actions.count(); ++ii) { Action &action = actions[ii]; @@ -1197,7 +1197,7 @@ void QmlParentChangeAction::transition(QmlStateActions &actions, } } -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParentChangeAction,QmlParentChangeAction) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParentAction,QmlParentAction) /*! \qmlclass NumberAnimation QmlNumberAnimation @@ -1462,6 +1462,10 @@ void QmlPropertyAnimationPrivate::convertVariant(QVariant &variant, int type) variant.setValue(QmlStringConverters::colorFromString(variant.toString())); break; } + case QVariant::Vector3D: { + variant.setValue(QmlStringConverters::vector3DFromString(variant.toString())); + break; + } default: if ((uint)type >= QVariant::UserType) { QmlMetaType::StringConverter converter = QmlMetaType::customStringConverter(type); diff --git a/src/declarative/util/qmlanimation.h b/src/declarative/util/qmlanimation.h index 602bf37..f5180a5 100644 --- a/src/declarative/util/qmlanimation.h +++ b/src/declarative/util/qmlanimation.h @@ -157,18 +157,18 @@ protected: virtual QAbstractAnimation *qtAnimation(); }; -class QmlRunScriptActionPrivate; -class QmlRunScriptAction : public QmlAbstractAnimation +class QmlScriptActionPrivate; +class QmlScriptAction : public QmlAbstractAnimation { Q_OBJECT - Q_DECLARE_PRIVATE(QmlRunScriptAction) + Q_DECLARE_PRIVATE(QmlScriptAction) Q_PROPERTY(QString script READ script WRITE setScript NOTIFY scriptChanged) Q_PROPERTY(QString runScriptName READ runScriptName WRITE setRunScriptName) public: - QmlRunScriptAction(QObject *parent=0); - virtual ~QmlRunScriptAction(); + QmlScriptAction(QObject *parent=0); + virtual ~QmlScriptAction(); QString script() const; void setScript(const QString &); @@ -186,11 +186,11 @@ protected: virtual QAbstractAnimation *qtAnimation(); }; -class QmlSetPropertyActionPrivate; -class QmlSetPropertyAction : public QmlAbstractAnimation +class QmlPropertyActionPrivate; +class QmlPropertyAction : public QmlAbstractAnimation { Q_OBJECT - Q_DECLARE_PRIVATE(QmlSetPropertyAction) + Q_DECLARE_PRIVATE(QmlPropertyAction) Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) @@ -200,8 +200,8 @@ class QmlSetPropertyAction : public QmlAbstractAnimation Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) public: - QmlSetPropertyAction(QObject *parent=0); - virtual ~QmlSetPropertyAction(); + QmlPropertyAction(QObject *parent=0); + virtual ~QmlPropertyAction(); QString properties() const; void setProperties(const QString &); @@ -225,18 +225,18 @@ protected: }; class QFxItem; -class QmlParentChangeActionPrivate; -class QmlParentChangeAction : public QmlAbstractAnimation +class QmlParentActionPrivate; +class QmlParentAction : public QmlAbstractAnimation { Q_OBJECT - Q_DECLARE_PRIVATE(QmlParentChangeAction) + Q_DECLARE_PRIVATE(QmlParentAction) Q_PROPERTY(QFxItem *target READ object WRITE setObject) Q_PROPERTY(QFxItem *parent READ parent WRITE setParent) public: - QmlParentChangeAction(QObject *parent=0); - virtual ~QmlParentChangeAction(); + QmlParentAction(QObject *parent=0); + virtual ~QmlParentAction(); QFxItem *object() const; void setObject(QFxItem *); @@ -395,9 +395,9 @@ QT_END_NAMESPACE QML_DECLARE_TYPE(QmlAbstractAnimation) QML_DECLARE_TYPE(QmlPauseAnimation) -QML_DECLARE_TYPE(QmlRunScriptAction) -QML_DECLARE_TYPE(QmlSetPropertyAction) -QML_DECLARE_TYPE(QmlParentChangeAction) +QML_DECLARE_TYPE(QmlScriptAction) +QML_DECLARE_TYPE(QmlPropertyAction) +QML_DECLARE_TYPE(QmlParentAction) QML_DECLARE_TYPE(QmlPropertyAnimation) QML_DECLARE_TYPE(QmlColorAnimation) QML_DECLARE_TYPE(QmlNumberAnimation) diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index fb4dae0..4f6edb7 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -220,11 +220,11 @@ public: QPauseAnimation *pa; }; -class QmlRunScriptActionPrivate : public QmlAbstractAnimationPrivate +class QmlScriptActionPrivate : public QmlAbstractAnimationPrivate { - Q_DECLARE_PUBLIC(QmlRunScriptAction) + Q_DECLARE_PUBLIC(QmlScriptAction) public: - QmlRunScriptActionPrivate() + QmlScriptActionPrivate() : QmlAbstractAnimationPrivate(), proxy(this), rsa(0) {} void init(); @@ -235,16 +235,16 @@ public: void execute(); - QAnimationActionProxy<QmlRunScriptActionPrivate, - &QmlRunScriptActionPrivate::execute> proxy; + QAnimationActionProxy<QmlScriptActionPrivate, + &QmlScriptActionPrivate::execute> proxy; QActionAnimation *rsa; }; -class QmlSetPropertyActionPrivate : public QmlAbstractAnimationPrivate +class QmlPropertyActionPrivate : public QmlAbstractAnimationPrivate { - Q_DECLARE_PUBLIC(QmlSetPropertyAction) + Q_DECLARE_PUBLIC(QmlPropertyAction) public: - QmlSetPropertyActionPrivate() + QmlPropertyActionPrivate() : QmlAbstractAnimationPrivate(), proxy(this), spa(0) {} void init(); @@ -257,16 +257,16 @@ public: void doAction(); - QAnimationActionProxy<QmlSetPropertyActionPrivate, - &QmlSetPropertyActionPrivate::doAction> proxy; + QAnimationActionProxy<QmlPropertyActionPrivate, + &QmlPropertyActionPrivate::doAction> proxy; QActionAnimation *spa; }; -class QmlParentChangeActionPrivate : public QmlAbstractAnimationPrivate +class QmlParentActionPrivate : public QmlAbstractAnimationPrivate { - Q_DECLARE_PUBLIC(QmlParentChangeAction) + Q_DECLARE_PUBLIC(QmlParentAction) public: - QmlParentChangeActionPrivate() + QmlParentActionPrivate() : QmlAbstractAnimationPrivate(), pcTarget(0), pcParent(0) {} void init(); diff --git a/src/declarative/util/qmlbind.cpp b/src/declarative/util/qmlbind.cpp index f3b5fa4..d18ef47 100644 --- a/src/declarative/util/qmlbind.cpp +++ b/src/declarative/util/qmlbind.cpp @@ -63,27 +63,27 @@ public: QmlNullableValue<QVariant> value; }; -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Bind,QmlBind) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Binding,QmlBind) /*! - \qmlclass Bind QmlBind - \brief The Bind element allows arbitrary property bindings to be created. + \qmlclass Binding QmlBind + \brief The Binding element allows arbitrary property bindings to be created. Sometimes it is necessary to bind to a property of an object that wasn't directly instantiated by QML - generally a property of a class exported - to QML by C++. In these cases, regular property binding doesn't work. Bind + to QML by C++. In these cases, regular property binding doesn't work. Binding allows you to bind any value to any property. For example, imagine a C++ application that maps an "app.enteredText" - property into QML. You could use Bind to update the enteredText property + property into QML. You could use Binding to update the enteredText property like this. \code TextEdit { id: myTextField; text: "Please type here..." } - Bind { target: app; property: "enteredText"; value: myTextField.text /> + Binding { target: app; property: "enteredText"; value: myTextField.text } \endcode Whenever the text in the TextEdit is updated, the C++ property will be updated also. - If the bind target or bind property is changed, the bound value is + If the binding target or binding property is changed, the bound value is immediately pushed onto the new target. \sa {qmlforcpp}{Qt Declarative Markup Language For C++ Programmers} @@ -123,7 +123,7 @@ void QmlBind::setWhen(bool v) } /*! - \qmlproperty Object Bind::target + \qmlproperty Object Binding::target The object to be updated. */ @@ -141,7 +141,7 @@ void QmlBind::setObject(QObject *obj) } /*! - \qmlproperty string Bind::property + \qmlproperty string Binding::property The property to be updated. */ @@ -159,7 +159,7 @@ void QmlBind::setProperty(const QString &p) } /*! - \qmlproperty any Bind::value + \qmlproperty any Binding::value The value to be set on the target object and property. This can be a constant (which isn't very useful), or a bound expression. diff --git a/src/declarative/util/qmlconnection.cpp b/src/declarative/util/qmlconnection.cpp index 83804a5..6dca2d1 100644 --- a/src/declarative/util/qmlconnection.cpp +++ b/src/declarative/util/qmlconnection.cpp @@ -114,8 +114,6 @@ Connection { \class QmlConnection \brief The QmlConnection class describes generalized connections to signals. - QmlSetProperties is a mechanism for connecting a script to be run when - some object sends a signal. */ QmlConnection::QmlConnection(QObject *parent) : QObject(*(new QmlConnectionPrivate), parent) diff --git a/src/declarative/util/qmlfollow.cpp b/src/declarative/util/qmlfollow.cpp index c48684b..eec2480 100644 --- a/src/declarative/util/qmlfollow.cpp +++ b/src/declarative/util/qmlfollow.cpp @@ -410,7 +410,7 @@ void QmlFollow::setMass(qreal mass) } /*! - \qmlproperty qreal Follow::followValue + \qmlproperty qreal Follow::value The current value. */ diff --git a/src/declarative/util/qmlfollow.h b/src/declarative/util/qmlfollow.h index 5c1093e..07b2f49 100644 --- a/src/declarative/util/qmlfollow.h +++ b/src/declarative/util/qmlfollow.h @@ -66,7 +66,7 @@ class Q_DECLARATIVE_EXPORT QmlFollow : public QmlPropertyValueSource, Q_PROPERTY(qreal epsilon READ epsilon WRITE setEpsilon) Q_PROPERTY(qreal modulus READ modulus WRITE setModulus) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) - Q_PROPERTY(qreal followValue READ value NOTIFY valueChanged) + Q_PROPERTY(qreal value READ value NOTIFY valueChanged) Q_PROPERTY(qreal modulus READ modulus WRITE setModulus NOTIFY modulusChanged) Q_PROPERTY(qreal mass READ mass WRITE setMass NOTIFY massChanged) Q_PROPERTY(bool inSync READ inSync NOTIFY syncChanged) diff --git a/src/declarative/util/qmlsetproperties.cpp b/src/declarative/util/qmlpropertychanges.cpp index e7be329..bece267 100644 --- a/src/declarative/util/qmlsetproperties.cpp +++ b/src/declarative/util/qmlpropertychanges.cpp @@ -41,7 +41,7 @@ #include "private/qobject_p.h" #include "qmlopenmetaobject.h" -#include "qmlsetproperties.h" +#include "qmlpropertychanges.h" #include <QtCore/qdebug.h> #include <QtDeclarative/qmlinfo.h> #include <private/qmlcustomparser_p.h> @@ -53,14 +53,14 @@ QT_BEGIN_NAMESPACE /*! - \qmlclass SetProperties QmlSetProperties - \brief The SetProperties element describes new property values for a state. + \qmlclass PropertyChanges QmlPropertyChanges + \brief The PropertyChanges element describes new property values for a state. - SetProperties changes the properties of an item. It allows you to specify the property + PropertyChanges changes the properties of an item. It allows you to specify the property names and values similar to how you normally would specify them for the actual item: \code - SetProperties { + PropertyChanges { target: myRect x: 52 y: 300 @@ -71,20 +71,20 @@ QT_BEGIN_NAMESPACE /*! \internal - \class QmlSetProperties - \brief The QmlSetProperties class describes new property values for a state. + \class QmlPropertyChanges + \brief The QmlPropertyChanges class describes new property values for a state. */ /*! - \qmlproperty Object SetProperties::target + \qmlproperty Object PropertyChanges::target This property holds the object that the properties to change belong to */ -class QmlSetPropertiesPrivate : public QObjectPrivate +class QmlPropertyChangesPrivate : public QObjectPrivate { - Q_DECLARE_PUBLIC(QmlSetProperties) + Q_DECLARE_PUBLIC(QmlPropertyChanges) public: - QmlSetPropertiesPrivate() : object(0), decoded(true), restore(true), + QmlPropertyChangesPrivate() : object(0), decoded(true), restore(true), isExplicit(false) {} QObject *object; @@ -101,7 +101,7 @@ public: QmlMetaProperty property(const QByteArray &); }; -class QmlSetPropertiesParser : public QmlCustomParser +class QmlPropertyChangesParser : public QmlCustomParser { public: void compileList(QList<QPair<QByteArray, QVariant> > &list, const QByteArray &pre, const QmlCustomParserProperty &prop); @@ -111,7 +111,7 @@ public: }; void -QmlSetPropertiesParser::compileList(QList<QPair<QByteArray, QVariant> > &list, +QmlPropertyChangesParser::compileList(QList<QPair<QByteArray, QVariant> > &list, const QByteArray &pre, const QmlCustomParserProperty &prop) { @@ -137,7 +137,7 @@ QmlSetPropertiesParser::compileList(QList<QPair<QByteArray, QVariant> > &list, } QByteArray -QmlSetPropertiesParser::compile(const QList<QmlCustomParserProperty> &props, +QmlPropertyChangesParser::compile(const QList<QmlCustomParserProperty> &props, bool *ok) { *ok = true; @@ -176,9 +176,9 @@ QmlSetPropertiesParser::compile(const QList<QmlCustomParserProperty> &props, return rv; } -void QmlSetPropertiesPrivate::decode() +void QmlPropertyChangesPrivate::decode() { - Q_Q(QmlSetProperties); + Q_Q(QmlPropertyChanges); if (decoded) return; @@ -207,55 +207,55 @@ void QmlSetPropertiesPrivate::decode() data.clear(); } -void QmlSetPropertiesParser::setCustomData(QObject *object, +void QmlPropertyChangesParser::setCustomData(QObject *object, const QByteArray &data) { - QmlSetPropertiesPrivate *p = - static_cast<QmlSetPropertiesPrivate *>(QObjectPrivate::get(object)); + QmlPropertyChangesPrivate *p = + static_cast<QmlPropertyChangesPrivate *>(QObjectPrivate::get(object)); p->data = data; p->decoded = false; } -QmlSetProperties::QmlSetProperties() -: QmlStateOperation(*(new QmlSetPropertiesPrivate)) +QmlPropertyChanges::QmlPropertyChanges() +: QmlStateOperation(*(new QmlPropertyChangesPrivate)) { } -QmlSetProperties::~QmlSetProperties() +QmlPropertyChanges::~QmlPropertyChanges() { - Q_D(QmlSetProperties); + Q_D(QmlPropertyChanges); for(int ii = 0; ii < d->expressions.count(); ++ii) delete d->expressions.at(ii).second; } -QObject *QmlSetProperties::object() const +QObject *QmlPropertyChanges::object() const { - Q_D(const QmlSetProperties); + Q_D(const QmlPropertyChanges); return d->object; } -void QmlSetProperties::setObject(QObject *o) +void QmlPropertyChanges::setObject(QObject *o) { - Q_D(QmlSetProperties); + Q_D(QmlPropertyChanges); d->object = o; } -bool QmlSetProperties::restoreEntryValues() const +bool QmlPropertyChanges::restoreEntryValues() const { - Q_D(const QmlSetProperties); + Q_D(const QmlPropertyChanges); return d->restore; } -void QmlSetProperties::setRestoreEntryValues(bool v) +void QmlPropertyChanges::setRestoreEntryValues(bool v) { - Q_D(QmlSetProperties); + Q_D(QmlPropertyChanges); d->restore = v; } QmlMetaProperty -QmlSetPropertiesPrivate::property(const QByteArray &property) +QmlPropertyChangesPrivate::property(const QByteArray &property) { - Q_Q(QmlSetProperties); + Q_Q(QmlPropertyChanges); QmlMetaProperty prop = QmlMetaProperty::createProperty(object, QString::fromLatin1(property)); if (!prop.isValid()) { qmlInfo(q) << "Cannot assign to non-existant property" << property; @@ -267,9 +267,9 @@ QmlSetPropertiesPrivate::property(const QByteArray &property) return prop; } -QmlSetProperties::ActionList QmlSetProperties::actions() +QmlPropertyChanges::ActionList QmlPropertyChanges::actions() { - Q_D(QmlSetProperties); + Q_D(QmlPropertyChanges); d->decode(); @@ -322,18 +322,18 @@ QmlSetProperties::ActionList QmlSetProperties::actions() return list; } -bool QmlSetProperties::isExplicit() const +bool QmlPropertyChanges::isExplicit() const { - Q_D(const QmlSetProperties); + Q_D(const QmlPropertyChanges); return d->isExplicit; } -void QmlSetProperties::setIsExplicit(bool e) +void QmlPropertyChanges::setIsExplicit(bool e) { - Q_D(QmlSetProperties); + Q_D(QmlPropertyChanges); d->isExplicit = e; } -QML_DEFINE_CUSTOM_TYPE(Qt, 4,6, (QT_VERSION&0x00ff00)>>8, SetProperties, QmlSetProperties, QmlSetPropertiesParser) +QML_DEFINE_CUSTOM_TYPE(Qt, 4,6, (QT_VERSION&0x00ff00)>>8, PropertyChanges, QmlPropertyChanges, QmlPropertyChangesParser) QT_END_NAMESPACE diff --git a/src/declarative/util/qmlsetproperties.h b/src/declarative/util/qmlpropertychanges.h index 3632816..8d338f1 100644 --- a/src/declarative/util/qmlsetproperties.h +++ b/src/declarative/util/qmlpropertychanges.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QMLSETPROPERTIES_H -#define QMLSETPROPERTIES_H +#ifndef QMLPROPERTYCHANGES_H +#define QMLPROPERTYCHANGES_H #include <QtDeclarative/qmlstateoperations.h> @@ -50,18 +50,18 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QmlSetPropertiesPrivate; -class Q_DECLARATIVE_EXPORT QmlSetProperties : public QmlStateOperation +class QmlPropertyChangesPrivate; +class Q_DECLARATIVE_EXPORT QmlPropertyChanges : public QmlStateOperation { Q_OBJECT - Q_DECLARE_PRIVATE(QmlSetProperties) + Q_DECLARE_PRIVATE(QmlPropertyChanges) Q_PROPERTY(QObject *target READ object WRITE setObject) Q_PROPERTY(bool restoreEntryValues READ restoreEntryValues WRITE setRestoreEntryValues) Q_PROPERTY(bool explicit READ isExplicit WRITE setIsExplicit); public: - QmlSetProperties(); - ~QmlSetProperties(); + QmlPropertyChanges(); + ~QmlPropertyChanges(); QObject *object() const; void setObject(QObject *); @@ -77,8 +77,8 @@ public: QT_END_NAMESPACE -QML_DECLARE_TYPE(QmlSetProperties) +QML_DECLARE_TYPE(QmlPropertyChanges) QT_END_HEADER -#endif // QMLSETPROPERTIES_H +#endif // QMLPROPERTYCHANGES_H diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index ce94aa8..e7149d5 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -227,7 +227,7 @@ void QmlState::setExtends(const QString &extends) } /*! - \qmlproperty list<StateOperation> State::operations + \qmlproperty list<Change> State::changes This property holds the changes to apply for this state \default @@ -235,7 +235,7 @@ void QmlState::setExtends(const QString &extends) extends another state, then the changes are applied against the state being extended. */ -QmlList<QmlStateOperation *> *QmlState::operations() +QmlList<QmlStateOperation *> *QmlState::changes() { Q_D(QmlState); return &d->operations; diff --git a/src/declarative/util/qmlstate.h b/src/declarative/util/qmlstate.h index 1b35295..d15bd4a 100644 --- a/src/declarative/util/qmlstate.h +++ b/src/declarative/util/qmlstate.h @@ -100,6 +100,7 @@ public: virtual bool override(ActionEvent*other); }; +//### rename to QmlStateChange? class QmlStateGroup; class Q_DECLARATIVE_EXPORT QmlStateOperation : public QObject { @@ -126,8 +127,8 @@ class Q_DECLARATIVE_EXPORT QmlState : public QObject Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QmlBinding *when READ when WRITE setWhen) Q_PROPERTY(QString extends READ extends WRITE setExtends) - Q_PROPERTY(QmlList<QmlStateOperation *>* operations READ operations) - Q_CLASSINFO("DefaultProperty", "operations") + Q_PROPERTY(QmlList<QmlStateOperation *>* changes READ changes) + Q_CLASSINFO("DefaultProperty", "changes") public: QmlState(QObject *parent=0); @@ -145,7 +146,7 @@ public: QString extends() const; void setExtends(const QString &); - QmlList<QmlStateOperation *> *operations(); + QmlList<QmlStateOperation *> *changes(); QmlState &operator<<(QmlStateOperation *); void apply(QmlStateGroup *, QmlTransition *, QmlState *revert); diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index 056912f..b17b80b 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -213,60 +213,60 @@ bool QmlParentChange::override(ActionEvent*other) return false; } -class QmlRunScriptPrivate : public QObjectPrivate +class QmlStateChangeScriptPrivate : public QObjectPrivate { public: - QmlRunScriptPrivate() {} + QmlStateChangeScriptPrivate() {} QString script; QString name; }; /*! - \qmlclass RunScript QmlRunScript - \brief The RunScript element allows you to run a script in a state. + \qmlclass StateChangeScript QmlStateChangeScript + \brief The StateChangeScript element allows you to run a script in a state. */ -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,RunScript,QmlRunScript) -QmlRunScript::QmlRunScript(QObject *parent) -: QmlStateOperation(*(new QmlRunScriptPrivate), parent) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,StateChangeScript,QmlStateChangeScript) +QmlStateChangeScript::QmlStateChangeScript(QObject *parent) +: QmlStateOperation(*(new QmlStateChangeScriptPrivate), parent) { } -QmlRunScript::~QmlRunScript() +QmlStateChangeScript::~QmlStateChangeScript() { } /*! - \qmlproperty string RunScript::script + \qmlproperty string StateChangeScript::script This property holds the script to run when the state is current. */ -QString QmlRunScript::script() const +QString QmlStateChangeScript::script() const { - Q_D(const QmlRunScript); + Q_D(const QmlStateChangeScript); return d->script; } -void QmlRunScript::setScript(const QString &s) +void QmlStateChangeScript::setScript(const QString &s) { - Q_D(QmlRunScript); + Q_D(QmlStateChangeScript); d->script = s; } -QString QmlRunScript::name() const +QString QmlStateChangeScript::name() const { - Q_D(const QmlRunScript); + Q_D(const QmlStateChangeScript); return d->name; } -void QmlRunScript::setName(const QString &n) +void QmlStateChangeScript::setName(const QString &n) { - Q_D(QmlRunScript); + Q_D(QmlStateChangeScript); d->name = n; } -void QmlRunScript::execute() +void QmlStateChangeScript::execute() { - Q_D(QmlRunScript); + Q_D(QmlStateChangeScript); if (!d->script.isEmpty()) { QmlExpression expr(qmlContext(this), d->script, this); expr.setTrackChange(false); @@ -274,7 +274,7 @@ void QmlRunScript::execute() } } -QmlRunScript::ActionList QmlRunScript::actions() +QmlStateChangeScript::ActionList QmlStateChangeScript::actions() { ActionList rv; Action a; @@ -284,16 +284,16 @@ QmlRunScript::ActionList QmlRunScript::actions() } /*! - \qmlclass SetAnchors - \brief The SetAnchors element allows you to change anchors in a state. + \qmlclass AnchorChanges + \brief The AnchorChanges element allows you to change anchors in a state. */ -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,SetAnchors,QmlSetAnchors) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,AnchorChanges,QmlAnchorChanges) -class QmlSetAnchorsPrivate : public QObjectPrivate +class QmlAnchorChangesPrivate : public QObjectPrivate { public: - QmlSetAnchorsPrivate() : target(0) {} + QmlAnchorChangesPrivate() : target(0) {} QString name; QFxItem *target; @@ -313,98 +313,98 @@ public: qreal origHeight; }; -QmlSetAnchors::QmlSetAnchors(QObject *parent) - : QmlStateOperation(*(new QmlSetAnchorsPrivate), parent) +QmlAnchorChanges::QmlAnchorChanges(QObject *parent) + : QmlStateOperation(*(new QmlAnchorChangesPrivate), parent) { } -QmlSetAnchors::~QmlSetAnchors() +QmlAnchorChanges::~QmlAnchorChanges() { } -QmlSetAnchors::ActionList QmlSetAnchors::actions() +QmlAnchorChanges::ActionList QmlAnchorChanges::actions() { Action a; a.event = this; return ActionList() << a; } -QFxItem *QmlSetAnchors::object() const +QFxItem *QmlAnchorChanges::object() const { - Q_D(const QmlSetAnchors); + Q_D(const QmlAnchorChanges); return d->target; } -void QmlSetAnchors::setObject(QFxItem *target) +void QmlAnchorChanges::setObject(QFxItem *target) { - Q_D(QmlSetAnchors); + Q_D(QmlAnchorChanges); d->target = target; } -QString QmlSetAnchors::reset() const +QString QmlAnchorChanges::reset() const { - Q_D(const QmlSetAnchors); + Q_D(const QmlAnchorChanges); return d->resetString; } -void QmlSetAnchors::setReset(const QString &reset) +void QmlAnchorChanges::setReset(const QString &reset) { - Q_D(QmlSetAnchors); + Q_D(QmlAnchorChanges); d->resetString = reset; d->resetList = d->resetString.split(QLatin1Char(',')); } -QFxAnchorLine QmlSetAnchors::left() const +QFxAnchorLine QmlAnchorChanges::left() const { - Q_D(const QmlSetAnchors); + Q_D(const QmlAnchorChanges); return d->left; } -void QmlSetAnchors::setLeft(const QFxAnchorLine &edge) +void QmlAnchorChanges::setLeft(const QFxAnchorLine &edge) { - Q_D(QmlSetAnchors); + Q_D(QmlAnchorChanges); d->left = edge; } -QFxAnchorLine QmlSetAnchors::right() const +QFxAnchorLine QmlAnchorChanges::right() const { - Q_D(const QmlSetAnchors); + Q_D(const QmlAnchorChanges); return d->right; } -void QmlSetAnchors::setRight(const QFxAnchorLine &edge) +void QmlAnchorChanges::setRight(const QFxAnchorLine &edge) { - Q_D(QmlSetAnchors); + Q_D(QmlAnchorChanges); d->right = edge; } -QFxAnchorLine QmlSetAnchors::top() const +QFxAnchorLine QmlAnchorChanges::top() const { - Q_D(const QmlSetAnchors); + Q_D(const QmlAnchorChanges); return d->top; } -void QmlSetAnchors::setTop(const QFxAnchorLine &edge) +void QmlAnchorChanges::setTop(const QFxAnchorLine &edge) { - Q_D(QmlSetAnchors); + Q_D(QmlAnchorChanges); d->top = edge; } -QFxAnchorLine QmlSetAnchors::bottom() const +QFxAnchorLine QmlAnchorChanges::bottom() const { - Q_D(const QmlSetAnchors); + Q_D(const QmlAnchorChanges); return d->bottom; } -void QmlSetAnchors::setBottom(const QFxAnchorLine &edge) +void QmlAnchorChanges::setBottom(const QFxAnchorLine &edge) { - Q_D(QmlSetAnchors); + Q_D(QmlAnchorChanges); d->bottom = edge; } -void QmlSetAnchors::execute() +void QmlAnchorChanges::execute() { - Q_D(QmlSetAnchors); + Q_D(QmlAnchorChanges); if (!d->target) return; @@ -419,14 +419,14 @@ void QmlSetAnchors::execute() d->target->anchors()->setBottom(d->bottom); } -bool QmlSetAnchors::isReversable() +bool QmlAnchorChanges::isReversable() { return true; } -void QmlSetAnchors::reverse() +void QmlAnchorChanges::reverse() { - Q_D(QmlSetAnchors); + Q_D(QmlAnchorChanges); if (!d->target) return; @@ -442,14 +442,14 @@ void QmlSetAnchors::reverse() } -QString QmlSetAnchors::typeName() const +QString QmlAnchorChanges::typeName() const { - return QLatin1String("SetAnchors"); + return QLatin1String("AnchorChanges"); } -QList<Action> QmlSetAnchors::extraActions() +QList<Action> QmlAnchorChanges::extraActions() { - Q_D(QmlSetAnchors); + Q_D(QmlAnchorChanges); QList<Action> extra; //### try to be smarter about which ones we add. @@ -477,14 +477,14 @@ QList<Action> QmlSetAnchors::extraActions() return extra; } -bool QmlSetAnchors::changesBindings() +bool QmlAnchorChanges::changesBindings() { return true; } -void QmlSetAnchors::clearForwardBindings() +void QmlAnchorChanges::clearForwardBindings() { - Q_D(QmlSetAnchors); + Q_D(QmlAnchorChanges); d->origLeft = d->target->anchors()->left(); d->origRight = d->target->anchors()->right(); d->origTop = d->target->anchors()->top(); @@ -505,9 +505,9 @@ void QmlSetAnchors::clearForwardBindings() d->target->anchors()->resetBottom(); } -void QmlSetAnchors::clearReverseBindings() +void QmlAnchorChanges::clearReverseBindings() { - Q_D(QmlSetAnchors); + Q_D(QmlAnchorChanges); d->origX = d->target->x(); d->origY = d->target->y(); d->origWidth = d->target->width(); diff --git a/src/declarative/util/qmlstateoperations.h b/src/declarative/util/qmlstateoperations.h index 4bd17a0..3018b44 100644 --- a/src/declarative/util/qmlstateoperations.h +++ b/src/declarative/util/qmlstateoperations.h @@ -79,18 +79,18 @@ public: virtual bool override(ActionEvent*other); }; -class QmlRunScriptPrivate; -class Q_DECLARATIVE_EXPORT QmlRunScript : public QmlStateOperation, public ActionEvent +class QmlStateChangeScriptPrivate; +class Q_DECLARATIVE_EXPORT QmlStateChangeScript : public QmlStateOperation, public ActionEvent { Q_OBJECT - Q_DECLARE_PRIVATE(QmlRunScript) + Q_DECLARE_PRIVATE(QmlStateChangeScript) Q_PROPERTY(QString script READ script WRITE setScript) Q_PROPERTY(QString name READ name WRITE setName) public: - QmlRunScript(QObject *parent=0); - ~QmlRunScript(); + QmlStateChangeScript(QObject *parent=0); + ~QmlStateChangeScript(); virtual ActionList actions(); @@ -103,11 +103,11 @@ public: virtual void execute(); }; -class QmlSetAnchorsPrivate; -class Q_DECLARATIVE_EXPORT QmlSetAnchors : public QmlStateOperation, public ActionEvent +class QmlAnchorChangesPrivate; +class Q_DECLARATIVE_EXPORT QmlAnchorChanges : public QmlStateOperation, public ActionEvent { Q_OBJECT - Q_DECLARE_PRIVATE(QmlSetAnchors) + Q_DECLARE_PRIVATE(QmlAnchorChanges) Q_PROPERTY(QFxItem *target READ object WRITE setObject) Q_PROPERTY(QString reset READ reset WRITE setReset) @@ -117,8 +117,8 @@ class Q_DECLARATIVE_EXPORT QmlSetAnchors : public QmlStateOperation, public Acti Q_PROPERTY(QFxAnchorLine bottom READ bottom WRITE setBottom) public: - QmlSetAnchors(QObject *parent=0); - ~QmlSetAnchors(); + QmlAnchorChanges(QObject *parent=0); + ~QmlAnchorChanges(); virtual ActionList actions(); @@ -153,8 +153,8 @@ public: QT_END_NAMESPACE QML_DECLARE_TYPE(QmlParentChange) -QML_DECLARE_TYPE(QmlRunScript) -QML_DECLARE_TYPE(QmlSetAnchors) +QML_DECLARE_TYPE(QmlStateChangeScript) +QML_DECLARE_TYPE(QmlAnchorChanges) QT_END_HEADER diff --git a/src/declarative/util/qmlpalette.cpp b/src/declarative/util/qmlsystempalette.cpp index d86f98f..88278c3 100644 --- a/src/declarative/util/qmlpalette.cpp +++ b/src/declarative/util/qmlsystempalette.cpp @@ -40,29 +40,29 @@ ****************************************************************************/ #include "private/qobject_p.h" -#include "qmlpalette.h" +#include "qmlsystempalette.h" #include <QApplication> QT_BEGIN_NAMESPACE -class QmlPalettePrivate : public QObjectPrivate +class QmlSystemPalettePrivate : public QObjectPrivate { public: QPalette palette; QPalette::ColorGroup group; }; -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Palette,QmlPalette) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,SystemPalette,QmlSystemPalette) /*! - \qmlclass Palette QmlPalette + \qmlclass SystemPalette QmlSystemPalette \ingroup group_utility - \brief The Palette item gives access to the Qt palettes. + \brief The SystemPalette item gives access to the Qt palettes. \sa QPalette Example: - \code - Palette { id: MyPalette; colorGroup: Qt.Active } + \qml + SystemPalette { id: MyPalette; colorGroup: Qt.Active } Rectangle { width: 640; height: 480 @@ -72,227 +72,227 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Palette,QmlPalette) text: "Hello!"; color: MyPalette.windowText } } - \endcode + \endqml */ -QmlPalette::QmlPalette(QObject *parent) - : QObject(*(new QmlPalettePrivate), parent) +QmlSystemPalette::QmlSystemPalette(QObject *parent) + : QObject(*(new QmlSystemPalettePrivate), parent) { - Q_D(QmlPalette); + Q_D(QmlSystemPalette); d->palette = qApp->palette(); d->group = QPalette::Active; qApp->installEventFilter(this); } -QmlPalette::~QmlPalette() +QmlSystemPalette::~QmlSystemPalette() { } /*! - \qmlproperty color Palette::window + \qmlproperty color SystemPalette::window The window (general background) color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::window() const +QColor QmlSystemPalette::window() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::Window); } /*! - \qmlproperty color Palette::windowText + \qmlproperty color SystemPalette::windowText The window text (general foreground) color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::windowText() const +QColor QmlSystemPalette::windowText() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::WindowText); } /*! - \qmlproperty color Palette::base + \qmlproperty color SystemPalette::base The base color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::base() const +QColor QmlSystemPalette::base() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::Base); } /*! - \qmlproperty color Palette::text + \qmlproperty color SystemPalette::text The text color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::text() const +QColor QmlSystemPalette::text() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::Text); } /*! - \qmlproperty color Palette::alternateBase + \qmlproperty color SystemPalette::alternateBase The alternate base color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::alternateBase() const +QColor QmlSystemPalette::alternateBase() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::AlternateBase); } /*! - \qmlproperty color Palette::button + \qmlproperty color SystemPalette::button The button color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::button() const +QColor QmlSystemPalette::button() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::Button); } /*! - \qmlproperty color Palette::buttonText + \qmlproperty color SystemPalette::buttonText The button text foreground color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::buttonText() const +QColor QmlSystemPalette::buttonText() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::ButtonText); } /*! - \qmlproperty color Palette::light + \qmlproperty color SystemPalette::light The light color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::light() const +QColor QmlSystemPalette::light() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::Light); } /*! - \qmlproperty color Palette::midlight + \qmlproperty color SystemPalette::midlight The midlight color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::midlight() const +QColor QmlSystemPalette::midlight() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::Midlight); } /*! - \qmlproperty color Palette::dark + \qmlproperty color SystemPalette::dark The dark color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::dark() const +QColor QmlSystemPalette::dark() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::Dark); } /*! - \qmlproperty color Palette::mid + \qmlproperty color SystemPalette::mid The mid color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::mid() const +QColor QmlSystemPalette::mid() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::Mid); } /*! - \qmlproperty color Palette::shadow + \qmlproperty color SystemPalette::shadow The shadow color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::shadow() const +QColor QmlSystemPalette::shadow() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::Shadow); } /*! - \qmlproperty color Palette::highlight + \qmlproperty color SystemPalette::highlight The highlight color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::highlight() const +QColor QmlSystemPalette::highlight() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::Highlight); } /*! - \qmlproperty color Palette::highlightedText + \qmlproperty color SystemPalette::highlightedText The highlighted text color of the current color group. \sa QPalette::ColorRole */ -QColor QmlPalette::highlightedText() const +QColor QmlSystemPalette::highlightedText() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->palette.color(d->group, QPalette::HighlightedText); } /*! - \qmlproperty color Palette::lighter + \qmlproperty color SystemPalette::lighter */ -QColor QmlPalette::lighter(const QColor& color) const +QColor QmlSystemPalette::lighter(const QColor& color) const { return color.lighter(); } /*! - \qmlproperty color Palette::darker + \qmlproperty color SystemPalette::darker */ -QColor QmlPalette::darker(const QColor& color) const +QColor QmlSystemPalette::darker(const QColor& color) const { return color.darker(); } /*! - \qmlproperty QPalette::ColorGroup Palette::colorGroup + \qmlproperty QPalette::ColorGroup SystemPalette::colorGroup The color group of the palette. It can be Active, Inactive or Disabled. Active is the default. \sa QPalette::ColorGroup */ -QPalette::ColorGroup QmlPalette::colorGroup() const +QPalette::ColorGroup QmlSystemPalette::colorGroup() const { - Q_D(const QmlPalette); + Q_D(const QmlSystemPalette); return d->group; } -void QmlPalette::setColorGroup(QPalette::ColorGroup colorGroup) +void QmlSystemPalette::setColorGroup(QPalette::ColorGroup colorGroup) { - Q_D(QmlPalette); + Q_D(QmlSystemPalette); d->group = colorGroup; emit paletteChanged(); } -bool QmlPalette::eventFilter(QObject *watched, QEvent *event) +bool QmlSystemPalette::eventFilter(QObject *watched, QEvent *event) { if (watched == qApp) { if (event->type() == QEvent::ApplicationPaletteChange) { @@ -303,9 +303,9 @@ bool QmlPalette::eventFilter(QObject *watched, QEvent *event) return QObject::eventFilter(watched, event); } -bool QmlPalette::event(QEvent *event) +bool QmlSystemPalette::event(QEvent *event) { - Q_D(QmlPalette); + Q_D(QmlSystemPalette); if (event->type() == QEvent::ApplicationPaletteChange) { d->palette = qApp->palette(); emit paletteChanged(); diff --git a/src/declarative/util/qmlpalette.h b/src/declarative/util/qmlsystempalette.h index e381814..6558c7e 100644 --- a/src/declarative/util/qmlpalette.h +++ b/src/declarative/util/qmlsystempalette.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QMLPALETTE_H -#define QMLPALETTE_H +#ifndef QMLSYSTEMPALETTE_H +#define QMLSYSTEMPALETTE_H #include <QtCore/qobject.h> #include <QtDeclarative/qml.h> @@ -52,11 +52,11 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QmlPalettePrivate; -class Q_DECLARATIVE_EXPORT QmlPalette : public QObject +class QmlSystemPalettePrivate; +class Q_DECLARATIVE_EXPORT QmlSystemPalette : public QObject { Q_OBJECT - Q_DECLARE_PRIVATE(QmlPalette) + Q_DECLARE_PRIVATE(QmlSystemPalette) Q_PROPERTY(QPalette::ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY paletteChanged) Q_PROPERTY(QColor window READ window NOTIFY paletteChanged) @@ -75,8 +75,8 @@ class Q_DECLARATIVE_EXPORT QmlPalette : public QObject Q_PROPERTY(QColor highlightedText READ highlightedText NOTIFY paletteChanged) public: - QmlPalette(QObject *parent=0); - ~QmlPalette(); + QmlSystemPalette(QObject *parent=0); + ~QmlSystemPalette(); QColor window() const; QColor windowText() const; @@ -115,8 +115,8 @@ private: QT_END_NAMESPACE -QML_DECLARE_TYPE(QmlPalette) +QML_DECLARE_TYPE(QmlSystemPalette) QT_END_HEADER -#endif // QMLPALETTE_H +#endif // QMLSYSTEMPALETTE_H diff --git a/src/declarative/util/qmltimer.cpp b/src/declarative/util/qmltimer.cpp index 2d3a343..b95d6ad 100644 --- a/src/declarative/util/qmltimer.cpp +++ b/src/declarative/util/qmltimer.cpp @@ -188,6 +188,32 @@ void QmlTimer::setTriggeredOnStart(bool triggeredOnStart) } } +/*! + \qmlmethod Timer::start() + \brief Starts the timer. + + If the timer is already running, calling this method has no effect. The + \c running property will be true following a call to \c start(). +*/ +void QmlTimer::start() +{ + Q_D(QmlTimer); + d->pause.start(); +} + +/*! + \qmlmethod Timer::stop() + \brief stops the timer. + + If the timer is not running, calling this method has no effect. The + \c running property will be false following a call to \c stop(). +*/ +void QmlTimer::stop() +{ + Q_D(QmlTimer); + d->pause.stop(); +} + void QmlTimer::update() { Q_D(QmlTimer); diff --git a/src/declarative/util/qmltimer.h b/src/declarative/util/qmltimer.h index d376834..22478cb 100644 --- a/src/declarative/util/qmltimer.h +++ b/src/declarative/util/qmltimer.h @@ -83,6 +83,10 @@ protected: void classBegin(); void componentComplete(); +public Q_SLOTS: + void start(); + void stop(); + Q_SIGNALS: void triggered(); void runningChanged(); diff --git a/src/declarative/util/qmltransition.cpp b/src/declarative/util/qmltransition.cpp index fd22f6b..66275d9 100644 --- a/src/declarative/util/qmltransition.cpp +++ b/src/declarative/util/qmltransition.cpp @@ -183,17 +183,17 @@ void QmlTransition::prepare(QmlStateOperation::ActionList &actions, } /*! - \qmlproperty string Transition::fromState - \qmlproperty string Transition::toState + \qmlproperty string Transition::from + \qmlproperty string Transition::to These properties are selectors indicating which state changes should trigger the transition. - fromState is used in conjunction with toState to determine when a transition should - be applied. By default fromState and toState are both "*" (any state). In the following example, + from is used in conjunction with to to determine when a transition should + be applied. By default from and to are both "*" (any state). In the following example, the transition is applied when changing from state1 to state2. \code Transition { - fromState: "state1" - toState: "state2" + from: "state1" + to: "state2" ... } \endcode @@ -241,15 +241,16 @@ void QmlTransition::setToState(const QString &t) } /*! - \qmlproperty list<Animation> Transition::operations + \qmlproperty list<Animation> Transition::animations + \default This property holds a list of the animations to be run for this transition. - The top-level animations in operations are run in parallel. - To run them sequentially, you can create a single SequentialAnimation - which contains all the animations, and assign that to operations. + The top-level animations are run in parallel. To run them sequentially, + you can create a single SequentialAnimation which contains all the animations, + and assign that to animations the animations property. \default */ -QmlList<QmlAbstractAnimation *>* QmlTransition::operations() +QmlList<QmlAbstractAnimation *>* QmlTransition::animations() { Q_D(QmlTransition); return &d->operations; diff --git a/src/declarative/util/qmltransition.h b/src/declarative/util/qmltransition.h index 8ccb0ec..b09341d 100644 --- a/src/declarative/util/qmltransition.h +++ b/src/declarative/util/qmltransition.h @@ -61,11 +61,11 @@ class Q_DECLARATIVE_EXPORT QmlTransition : public QObject Q_OBJECT Q_DECLARE_PRIVATE(QmlTransition) - Q_PROPERTY(QString fromState READ fromState WRITE setFromState) - Q_PROPERTY(QString toState READ toState WRITE setToState) + Q_PROPERTY(QString from READ fromState WRITE setFromState) + Q_PROPERTY(QString to READ toState WRITE setToState) Q_PROPERTY(bool reversible READ reversible WRITE setReversible) - Q_PROPERTY(QmlList<QmlAbstractAnimation *>* operations READ operations) - Q_CLASSINFO("DefaultProperty", "operations") + Q_PROPERTY(QmlList<QmlAbstractAnimation *>* animations READ animations) + Q_CLASSINFO("DefaultProperty", "animations") public: QmlTransition(QObject *parent=0); @@ -80,7 +80,7 @@ public: bool reversible() const; void setReversible(bool); - QmlList<QmlAbstractAnimation *>* operations(); + QmlList<QmlAbstractAnimation *>* animations(); void prepare(QmlStateOperation::ActionList &actions, QList<QmlMetaProperty> &after, diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index 9374f00..f1b599f 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -6,12 +6,12 @@ SOURCES += \ util/qmlpackage.cpp \ util/qmlscript.cpp \ util/qmlanimation.cpp \ - util/qmlpalette.cpp \ + util/qmlsystempalette.cpp \ util/qmlfollow.cpp \ util/qmlstate.cpp\ util/qmltransitionmanager.cpp \ util/qmlstateoperations.cpp \ - util/qmlsetproperties.cpp \ + util/qmlpropertychanges.cpp \ util/qmlstategroup.cpp \ util/qmltransition.cpp \ util/qmllistmodel.cpp\ @@ -31,11 +31,11 @@ HEADERS += \ util/qmlscript.h \ util/qmlanimation.h \ util/qmlanimation_p.h \ - util/qmlpalette.h \ + util/qmlsystempalette.h \ util/qmlfollow.h \ util/qmlstate.h\ util/qmlstateoperations.h \ - util/qmlsetproperties.h \ + util/qmlpropertychanges.h \ util/qmlstate_p.h\ util/qmltransitionmanager_p.h \ util/qmlstategroup.h \ diff --git a/src/gui/dialogs/qfileinfogatherer_p.h b/src/gui/dialogs/qfileinfogatherer_p.h index cb980d2..bab4a29 100644 --- a/src/gui/dialogs/qfileinfogatherer_p.h +++ b/src/gui/dialogs/qfileinfogatherer_p.h @@ -184,7 +184,7 @@ private: QMutex mutex; QWaitCondition condition; - bool abort; + volatile bool abort; QStack<QString> path; QStack<QStringList> files; diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 675fc0d..1d52182 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -1010,7 +1010,7 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent) } // Resolve depth. - resolveDepth(parent ? parent->d_ptr->depth : -1); + invalidateDepthRecursively(); dirtySceneTransform = 1; // Restore the sub focus chain. @@ -4401,14 +4401,42 @@ bool QGraphicsItemPrivate::discardUpdateRequest(bool ignoreClipping, bool ignore /*! \internal +*/ +int QGraphicsItemPrivate::depth() const +{ + if (itemDepth == -1) + const_cast<QGraphicsItemPrivate *>(this)->resolveDepth(); + + return itemDepth; +} - Resolves the stacking depth of this object and all its children. +/*! + \internal */ -void QGraphicsItemPrivate::resolveDepth(int parentDepth) +void QGraphicsItemPrivate::invalidateDepthRecursively() { - depth = parentDepth + 1; + if (itemDepth == -1) + return; + + itemDepth = -1; for (int i = 0; i < children.size(); ++i) - children.at(i)->d_ptr->resolveDepth(depth); + children.at(i)->d_ptr->invalidateDepthRecursively(); +} + +/*! + \internal + + Resolves the stacking depth of this object and all its ancestors. +*/ +void QGraphicsItemPrivate::resolveDepth() +{ + if (!parent) + itemDepth = 0; + else { + if (parent->d_ptr->itemDepth == -1) + parent->d_ptr->resolveDepth(); + itemDepth = parent->d_ptr->itemDepth + 1; + } } /*! @@ -5578,8 +5606,8 @@ QGraphicsItem *QGraphicsItem::commonAncestorItem(const QGraphicsItem *other) con return const_cast<QGraphicsItem *>(this); const QGraphicsItem *thisw = this; const QGraphicsItem *otherw = other; - int thisDepth = d_ptr->depth; - int otherDepth = other->d_ptr->depth; + int thisDepth = d_ptr->depth(); + int otherDepth = other->d_ptr->depth(); while (thisDepth > otherDepth) { thisw = thisw->d_ptr->parent; --thisDepth; @@ -6589,7 +6617,7 @@ void QGraphicsItem::prepareGeometryChange() // if someone is connected to the changed signal or the scene has no views. // Note that this has to be done *after* markDirty to ensure that // _q_processDirtyItems is called before _q_emitUpdated. - if ((scenePrivate->connectedSignals[0] & scenePrivate->changedSignalMask) + if (scenePrivate->isSignalConnected(scenePrivate->changedSignalIndex) || scenePrivate->views.isEmpty()) { if (d_ptr->hasTranslateOnlySceneTransform()) { d_ptr->scene->update(boundingRect().translated(d_ptr->sceneTransform.dx(), diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index 43d690f..a41cab5 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -123,7 +123,7 @@ public: transformData(0), index(-1), siblingIndex(-1), - depth(0), + itemDepth(-1), focusProxy(0), subFocusItem(0), imHints(Qt::ImhNone), @@ -209,7 +209,9 @@ public: void setEnabledHelper(bool newEnabled, bool explicitly, bool update = true); bool discardUpdateRequest(bool ignoreClipping = false, bool ignoreVisibleBit = false, bool ignoreDirtyBit = false, bool ignoreOpacity = false) const; - void resolveDepth(int parentDepth); + int depth() const; + void invalidateDepthRecursively(); + void resolveDepth(); void addChild(QGraphicsItem *child); void removeChild(QGraphicsItem *child); void setParentItemHelper(QGraphicsItem *parent); @@ -419,7 +421,7 @@ public: QTransform sceneTransform; int index; int siblingIndex; - int depth; + int itemDepth; // Lazily calculated when calling depth(). QGraphicsItem *focusProxy; QList<QGraphicsItem **> focusProxyRefs; QGraphicsItem *subFocusItem; @@ -500,16 +502,17 @@ struct QGraphicsItemPrivate::TransformData return transform * *postmultiplyTransform; } - QTransform x(transform); + QMatrix4x4 x(transform); for (int i = 0; i < graphicsTransforms.size(); ++i) graphicsTransforms.at(i)->applyTo(&x); x.translate(xOrigin, yOrigin); - x.rotate(rotation, Qt::ZAxis); - x.scale(scale, scale); + x.rotate(rotation, 0, 0, 1); + x.scale(scale); x.translate(-xOrigin, -yOrigin); + QTransform t = x.toTransform(); // project the 3D matrix back to 2D. if (postmultiplyTransform) - x *= *postmultiplyTransform; - return x; + t *= *postmultiplyTransform; + return t; } }; diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 3f13a86..7fa565d 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -265,12 +265,13 @@ static void _q_hoverFromMouseEvent(QGraphicsSceneHoverEvent *hover, const QGraph hover->setAccepted(mouseEvent->isAccepted()); } +int QGraphicsScenePrivate::changedSignalIndex; + /*! \internal */ QGraphicsScenePrivate::QGraphicsScenePrivate() - : changedSignalMask(0), - indexMethod(QGraphicsScene::BspTreeIndex), + : indexMethod(QGraphicsScene::BspTreeIndex), index(0), lastItemCount(0), hasSceneRect(false), @@ -311,7 +312,9 @@ void QGraphicsScenePrivate::init() index = new QGraphicsSceneBspTreeIndex(q); // Keep this index so we can check for connected slots later on. - changedSignalMask = (1 << q->metaObject()->indexOfSignal("changed(QList<QRectF>)")); + if (!changedSignalIndex) { + changedSignalIndex = signalIndex("changed(QList<QRectF>)"); + } qApp->d_func()->scene_list.append(q); q->update(); } @@ -343,7 +346,7 @@ void QGraphicsScenePrivate::_q_emitUpdated() // the optimization that items send updates directly to the views, but it // needs to happen in order to keep compatibility with the behavior from // Qt 4.4 and backward. - if (connectedSignals[0] & changedSignalMask) { + if (isSignalConnected(changedSignalIndex)) { for (int i = 0; i < views.size(); ++i) { QGraphicsView *view = views.at(i); if (!view->d_func()->connectedToScene) { @@ -2894,7 +2897,7 @@ void QGraphicsScene::update(const QRectF &rect) // Check if anyone's connected; if not, we can send updates directly to // the views. Otherwise or if there are no views, use old behavior. - bool directUpdates = !(d->connectedSignals[0] & d->changedSignalMask) && !d->views.isEmpty(); + bool directUpdates = !(d->isSignalConnected(d->changedSignalIndex)) && !d->views.isEmpty(); if (rect.isNull()) { d->updateAll = true; d->updatedRects.clear(); @@ -4473,7 +4476,7 @@ void QGraphicsScenePrivate::markDirty(QGraphicsItem *item, const QRectF &rect, b if (removingItemFromScene) { // Note that this function can be called from the item's destructor, so // do NOT call any virtual functions on it within this block. - if ((connectedSignals[0] & changedSignalMask) || views.isEmpty()) { + if (isSignalConnected(changedSignalIndex) || views.isEmpty()) { // This block of code is kept for compatibility. Since 4.5, by default // QGraphicsView does not connect the signal and we use the below // method of delivering updates. @@ -4619,7 +4622,7 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool // Process item. if (item->d_ptr->dirty || item->d_ptr->paintedViewBoundingRectsNeedRepaint) { - const bool useCompatUpdate = views.isEmpty() || (connectedSignals[0] & changedSignalMask); + const bool useCompatUpdate = views.isEmpty() || isSignalConnected(changedSignalIndex); const QRectF itemBoundingRect = adjustedItemBoundingRect(item); if (useCompatUpdate && !itemIsUntransformable && qFuzzyIsNull(item->boundingRegionGranularity())) { diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h index 685f534..f1ddb5a 100644 --- a/src/gui/graphicsview/qgraphicsscene_p.h +++ b/src/gui/graphicsview/qgraphicsscene_p.h @@ -87,7 +87,7 @@ public: static QGraphicsScenePrivate *get(QGraphicsScene *q); - quint32 changedSignalMask; + static int changedSignalIndex; QGraphicsScene::ItemIndexMethod indexMethod; QGraphicsSceneIndex *index; diff --git a/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp b/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp index d68183c..a80cdca 100644 --- a/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp +++ b/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp @@ -419,8 +419,8 @@ bool QGraphicsSceneBspTreeIndexPrivate::closestItemFirst_withoutCache(const QGra // Find common ancestor, and each item's ancestor closest to the common // ancestor. - int item1Depth = d1->depth; - int item2Depth = d2->depth; + int item1Depth = d1->depth(); + int item2Depth = d2->depth(); const QGraphicsItem *p = item1; const QGraphicsItem *t1 = item1; while (item1Depth > item2Depth && (p = p->d_ptr->parent)) { diff --git a/src/gui/graphicsview/qgraphicstransform.cpp b/src/gui/graphicsview/qgraphicstransform.cpp index 86f5b08..585e0f9 100644 --- a/src/gui/graphicsview/qgraphicstransform.cpp +++ b/src/gui/graphicsview/qgraphicstransform.cpp @@ -63,10 +63,17 @@ independent transformation. The resulting operation is then combined into a single transform which is applied to QGraphicsItem. + Transformations are computed in true 3D space using QMatrix4x4. + When the transformation is applied to a QGraphicsItem, it will be + projected back to a 2D QTransform. When multiple QGraphicsTransform + objects are applied to a QGraphicsItem, all of the transformations + are computed in true 3D space, with the projection back to 2D + only occurring after the last QGraphicsTransform is applied. + If you want to create your own configurable transformation, you can create a subclass of QGraphicsTransform (or any or the existing subclasses), and reimplement the pure virtual applyTo() function, which takes a pointer to a - QTransform. Each operation you would like to apply should be exposed as + QMatrix4x4. Each operation you would like to apply should be exposed as properties (e.g., customTransform->setVerticalShear(2.5)). Inside you reimplementation of applyTo(), you can modify the provided transform respectively. @@ -136,28 +143,13 @@ QGraphicsTransform::QGraphicsTransform(QGraphicsTransformPrivate &p, QObject *pa } /*! - Applies this transformation to an identity transform, and returns the - resulting transform. - - This is equivalent to passing an identity transform to applyTo(). - - \sa applyTo() -*/ -QTransform QGraphicsTransform::transform() const -{ - QTransform t; - applyTo(&t); - return t; -} - -/*! - \fn void QGraphicsTransform::applyTo(QTransform *transform) const + \fn void QGraphicsTransform::applyTo(QMatrix4x4 *matrix) const This pure virtual method has to be reimplemented in derived classes. - It applies this transformation to \a transform. + It applies this transformation to \a matrix. - \sa QGraphicsItem::transform() + \sa QGraphicsItem::transform(), QMatrix4x4::toTransform() */ /*! @@ -189,11 +181,12 @@ void QGraphicsTransform::update() relative to the parent as the rest of the item grows). By default the origin is QPointF(0, 0). - The two parameters xScale and yScale describe the scale factors to apply in - horizontal and vertical direction. They can take on any value, including 0 - (to collapse the item to a point) or negativate value. A negative xScale - value will mirror the item horizontally. A negative yScale value will flip - the item vertically. + The parameters xScale, yScale, and zScale describe the scale factors to + apply in horizontal, vertical, and depth directions. They can take on any + value, including 0 (to collapse the item to a point) or negative value. + A negative xScale value will mirror the item horizontally. A negative yScale + value will flip the item vertically. A negative zScale will flip the + item end for end. \sa QGraphicsTransform, QGraphicsItem::setScale(), QTransform::scale() */ @@ -202,10 +195,11 @@ class QGraphicsScalePrivate : public QGraphicsTransformPrivate { public: QGraphicsScalePrivate() - : xScale(1), yScale(1) {} - QPointF origin; + : xScale(1), yScale(1), zScale(1) {} + QVector3D origin; qreal xScale; qreal yScale; + qreal zScale; }; /*! @@ -225,21 +219,23 @@ QGraphicsScale::~QGraphicsScale() /*! \property QGraphicsScale::origin - \brief The QGraphicsScene class provides the origin of the scale. + \brief the origin of the scale in 3D space. All scaling will be done relative to this point (i.e., this point will stay fixed, relative to the parent, when the item is scaled). - \sa xScale, yScale + \sa xScale, yScale, zScale */ -QPointF QGraphicsScale::origin() const +QVector3D QGraphicsScale::origin() const { Q_D(const QGraphicsScale); return d->origin; } -void QGraphicsScale::setOrigin(const QPointF &point) +void QGraphicsScale::setOrigin(const QVector3D &point) { Q_D(QGraphicsScale); + if (d->origin == point) + return; d->origin = point; update(); emit originChanged(); @@ -254,7 +250,7 @@ void QGraphicsScale::setOrigin(const QPointF &point) provide a negative value, the item will be mirrored horizontally around its origin. - \sa yScale, origin + \sa yScale, zScale, origin */ qreal QGraphicsScale::xScale() const { @@ -280,7 +276,7 @@ void QGraphicsScale::setXScale(qreal scale) provide a negative value, the item will be flipped vertically around its origin. - \sa xScale, origin + \sa xScale, zScale, origin */ qreal QGraphicsScale::yScale() const { @@ -298,14 +294,40 @@ void QGraphicsScale::setYScale(qreal scale) } /*! + \property QGraphicsScale::zScale + \brief the depth scale factor. + + The scale factor can be any real number; the default value is 1.0. If you + set the factor to 0.0, the item will be collapsed to a single point. If you + provide a negative value, the item will be flipped end for end around its + origin. + + \sa xScale, yScale, origin +*/ +qreal QGraphicsScale::zScale() const +{ + Q_D(const QGraphicsScale); + return d->zScale; +} +void QGraphicsScale::setZScale(qreal scale) +{ + Q_D(QGraphicsScale); + if (d->zScale == scale) + return; + d->zScale = scale; + update(); + emit scaleChanged(); +} + +/*! \reimp */ -void QGraphicsScale::applyTo(QTransform *transform) const +void QGraphicsScale::applyTo(QMatrix4x4 *matrix) const { Q_D(const QGraphicsScale); - transform->translate(d->origin.x(), d->origin.y()); - transform->scale(d->xScale, d->yScale); - transform->translate(-d->origin.x(), -d->origin.y()); + matrix->translate(d->origin); + matrix->scale(d->xScale, d->yScale, d->zScale); + matrix->translate(-d->origin); } /*! @@ -319,10 +341,11 @@ void QGraphicsScale::applyTo(QTransform *transform) const /*! \fn QGraphicsScale::scaleChanged() - This signal is emitted whenever the xScale or yScale of the object - changes. + This signal is emitted whenever the xScale, yScale, or zScale + of the object changes. \sa QGraphicsScale::xScale, QGraphicsScale::yScale + \sa QGraphicsScale::zScale */ /*! @@ -359,20 +382,14 @@ void QGraphicsScale::applyTo(QTransform *transform) const \sa QGraphicsTransform, QGraphicsItem::setRotation(), QTransform::rotate() */ -#define VECTOR_FOR_AXIS_X QVector3D(1, 0, 0) -#define VECTOR_FOR_AXIS_Y QVector3D(0, 1, 0) -#define VECTOR_FOR_AXIS_Z QVector3D(0, 0, 1) - - class QGraphicsRotationPrivate : public QGraphicsTransformPrivate { public: QGraphicsRotationPrivate() - : angle(0), axis(VECTOR_FOR_AXIS_Z), simpleAxis(Qt::ZAxis) {} - QPointF origin; + : angle(0), axis(0, 0, 1) {} + QVector3D origin; qreal angle; QVector3D axis; - int simpleAxis; }; /*! @@ -392,21 +409,23 @@ QGraphicsRotation::~QGraphicsRotation() /*! \property QGraphicsRotation::origin - \brief the origin of the rotation. + \brief the origin of the rotation in 3D space. All rotations will be done relative to this point (i.e., this point will stay fixed, relative to the parent, when the item is rotated). \sa angle */ -QPointF QGraphicsRotation::origin() const +QVector3D QGraphicsRotation::origin() const { Q_D(const QGraphicsRotation); return d->origin; } -void QGraphicsRotation::setOrigin(const QPointF &point) +void QGraphicsRotation::setOrigin(const QVector3D &point) { Q_D(QGraphicsRotation); + if (d->origin == point) + return; d->origin = point; update(); emit originChanged(); @@ -448,11 +467,11 @@ void QGraphicsRotation::setAngle(qreal angle) */ /*! - \fn void QGraphicsRotation::angleChanged() + \fn void QGraphicsRotation::angleChanged() - This signal is emitted whenever the angle has changed. + This signal is emitted whenever the angle has changed. - \sa QGraphicsRotation::angle + \sa QGraphicsRotation::angle */ /*! @@ -475,18 +494,9 @@ QVector3D QGraphicsRotation::axis() const void QGraphicsRotation::setAxis(const QVector3D &axis) { Q_D(QGraphicsRotation); - if (d->axis == axis) + if (d->axis == axis) return; - d->axis = axis; - if (axis == VECTOR_FOR_AXIS_X) { - d->simpleAxis = Qt::XAxis; - } else if (axis == VECTOR_FOR_AXIS_Y) { - d->simpleAxis = Qt::YAxis; - } else if (axis == VECTOR_FOR_AXIS_Z) { - d->simpleAxis = Qt::ZAxis; - } else { - d->simpleAxis = -1; // no predefined axis - } + d->axis = axis; update(); emit axisChanged(); } @@ -495,90 +505,58 @@ void QGraphicsRotation::setAxis(const QVector3D &axis) \fn void QGraphicsRotation::setAxis(Qt::Axis axis) Convenience function to set the axis to \a axis. -*/ + Note: the Qt::YAxis rotation for QTransform is inverted from the + correct mathematical rotation in 3D space. The QGraphicsRotation + class implements a correct mathematical rotation. The following + two sequences of code will perform the same transformation: + + \code + QTransform t; + t.rotate(45, Qt::YAxis); + + QGraphicsRotation r; + r.setAxis(Qt::YAxis); + r.setAngle(-45); + \endcode +*/ void QGraphicsRotation::setAxis(Qt::Axis axis) { switch (axis) { case Qt::XAxis: - setAxis(VECTOR_FOR_AXIS_X); + setAxis(QVector3D(1, 0, 0)); break; case Qt::YAxis: - setAxis(VECTOR_FOR_AXIS_Y); + setAxis(QVector3D(0, 1, 0)); break; case Qt::ZAxis: - setAxis(VECTOR_FOR_AXIS_Z); + setAxis(QVector3D(0, 0, 1)); break; } } - -const qreal deg2rad = qreal(0.017453292519943295769); // pi/180 -static const qreal inv_dist_to_plane = 1. / 1024.; - /*! \reimp */ -void QGraphicsRotation::applyTo(QTransform *t) const +void QGraphicsRotation::applyTo(QMatrix4x4 *matrix) const { Q_D(const QGraphicsRotation); - qreal a = d->angle; - - if (a == 0.) - return; - - if (d->simpleAxis != -1) { - //that's an optimization for simple axis - t->translate(d->origin.x(), d->origin.y()); - t->rotate(a, Qt::Axis(d->simpleAxis)); - t->translate(-d->origin.x(), -d->origin.y()); - return; - } - - qreal x = d->axis.x(); - qreal y = d->axis.y(); - qreal z = d->axis.z(); - - if (x == 0. && y == 0 && z == 0) + if (d->angle == 0. || d->axis.isNull()) return; - qreal c, s; - if (a == 90. || a == -270.) { - s = 1.; - c = 0.; - } else if (a == 270. || a == -90.) { - s = -1.; - c = 0.; - } else if (a == 180.) { - s = 0.; - c = -1.; - } else { - qreal b = deg2rad*a; - s = qSin(b); - c = qCos(b); - } - - qreal len = x * x + y * y + z * z; - if (len != 1.) { - len = 1. / qSqrt(len); - x *= len; - y *= len; - z *= len; - } - - t->translate(d->origin.x(), d->origin.y()); - *t = QTransform(x*x*(1-c)+c, x*y*(1-c)+z*s, x*z*(1-c)-y*s*inv_dist_to_plane, - y*x*(1-c)-z*s, y*y*(1-c)+c, y*z*(1-c)-x*s*inv_dist_to_plane, - 0, 0, 1) * *t; - t->translate(-d->origin.x(), -d->origin.y()); + matrix->translate(d->origin); + matrix->rotate(d->angle, d->axis.x(), d->axis.y(), d->axis.z()); + matrix->translate(-d->origin); } /*! \fn void QGraphicsRotation::axisChanged() This signal is emitted whenever the axis of the object changes. + + \sa QGraphicsRotation::axis */ #include "moc_qgraphicstransform.cpp" diff --git a/src/gui/graphicsview/qgraphicstransform.h b/src/gui/graphicsview/qgraphicstransform.h index 8ccc258..d6d5b79 100644 --- a/src/gui/graphicsview/qgraphicstransform.h +++ b/src/gui/graphicsview/qgraphicstransform.h @@ -43,8 +43,9 @@ #define QGRAPHICSTRANSFORM_H #include <QtCore/QObject> -#include <QtGui/QTransform> #include <QtGui/QVector3D> +#include <QtGui/QTransform> +#include <QtGui/QMatrix4x4> QT_BEGIN_HEADER @@ -62,8 +63,7 @@ public: QGraphicsTransform(QObject *parent = 0); ~QGraphicsTransform(); - QTransform transform() const; - virtual void applyTo(QTransform *transform) const = 0; + virtual void applyTo(QMatrix4x4 *matrix) const = 0; protected Q_SLOTS: void update(); @@ -83,15 +83,16 @@ class Q_GUI_EXPORT QGraphicsScale : public QGraphicsTransform { Q_OBJECT - Q_PROPERTY(QPointF origin READ origin WRITE setOrigin NOTIFY originChanged) + Q_PROPERTY(QVector3D origin READ origin WRITE setOrigin NOTIFY originChanged) Q_PROPERTY(qreal xScale READ xScale WRITE setXScale NOTIFY scaleChanged) Q_PROPERTY(qreal yScale READ yScale WRITE setYScale NOTIFY scaleChanged) + Q_PROPERTY(qreal zScale READ zScale WRITE setZScale NOTIFY scaleChanged) public: QGraphicsScale(QObject *parent = 0); ~QGraphicsScale(); - QPointF origin() const; - void setOrigin(const QPointF &point); + QVector3D origin() const; + void setOrigin(const QVector3D &point); qreal xScale() const; void setXScale(qreal); @@ -99,7 +100,10 @@ public: qreal yScale() const; void setYScale(qreal); - void applyTo(QTransform *transform) const; + qreal zScale() const; + void setZScale(qreal); + + void applyTo(QMatrix4x4 *matrix) const; Q_SIGNALS: void originChanged(); @@ -115,15 +119,15 @@ class Q_GUI_EXPORT QGraphicsRotation : public QGraphicsTransform { Q_OBJECT - Q_PROPERTY(QPointF origin READ origin WRITE setOrigin NOTIFY originChanged) + Q_PROPERTY(QVector3D origin READ origin WRITE setOrigin NOTIFY originChanged) Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged) Q_PROPERTY(QVector3D axis READ axis WRITE setAxis NOTIFY axisChanged) public: QGraphicsRotation(QObject *parent = 0); ~QGraphicsRotation(); - QPointF origin() const; - void setOrigin(const QPointF &point); + QVector3D origin() const; + void setOrigin(const QVector3D &point); qreal angle() const; void setAngle(qreal); @@ -132,7 +136,7 @@ public: void setAxis(const QVector3D &axis); void setAxis(Qt::Axis axis); - void applyTo(QTransform *transform) const; + void applyTo(QMatrix4x4 *matrix) const; Q_SIGNALS: void originChanged(); diff --git a/src/gui/image/qbmphandler.cpp b/src/gui/image/qbmphandler.cpp index ccf8457..19701b4 100644 --- a/src/gui/image/qbmphandler.cpp +++ b/src/gui/image/qbmphandler.cpp @@ -81,14 +81,14 @@ static void swapPixel01(QImage *image) // 1-bpp: swap 0 and 1 pixels const int BMP_FILEHDR_SIZE = 14; // size of BMP_FILEHDR data -QDataStream &operator>>(QDataStream &s, BMP_FILEHDR &bf) +static QDataStream &operator>>(QDataStream &s, BMP_FILEHDR &bf) { // read file header s.readRawData(bf.bfType, 2); s >> bf.bfSize >> bf.bfReserved1 >> bf.bfReserved2 >> bf.bfOffBits; return s; } -QDataStream &operator<<(QDataStream &s, const BMP_FILEHDR &bf) +static QDataStream &operator<<(QDataStream &s, const BMP_FILEHDR &bf) { // write file header s.writeRawData(bf.bfType, 2); s << bf.bfSize << bf.bfReserved1 << bf.bfReserved2 << bf.bfOffBits; @@ -106,7 +106,7 @@ const int BMP_RLE4 = 2; // run-length encoded, 4 const int BMP_BITFIELDS = 3; // RGB values encoded in data as bit-fields -QDataStream &operator>>(QDataStream &s, BMP_INFOHDR &bi) +static QDataStream &operator>>(QDataStream &s, BMP_INFOHDR &bi) { s >> bi.biSize; if (bi.biSize == BMP_WIN || bi.biSize == BMP_OS2) { @@ -128,7 +128,7 @@ QDataStream &operator>>(QDataStream &s, BMP_INFOHDR &bi) return s; } -QDataStream &operator<<(QDataStream &s, const BMP_INFOHDR &bi) +static QDataStream &operator<<(QDataStream &s, const BMP_INFOHDR &bi) { s << bi.biSize; s << bi.biWidth << bi.biHeight; diff --git a/src/gui/image/qiconloader_p.h b/src/gui/image/qiconloader_p.h index b2944ef..5d5c211 100644 --- a/src/gui/image/qiconloader_p.h +++ b/src/gui/image/qiconloader_p.h @@ -85,6 +85,7 @@ struct QIconDirInfo class QIconLoaderEngineEntry { public: + virtual ~QIconLoaderEngineEntry() {} virtual QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) = 0; diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 9eb71b7..d79a378 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -3378,11 +3378,7 @@ QPoint QAbstractItemView::dirtyRegionOffset() const */ void QAbstractItemView::startAutoScroll() { - Q_D(QAbstractItemView); - // ### it would be nice to make this into a style hint one day - int scrollInterval = (verticalScrollMode() == QAbstractItemView::ScrollPerItem) ? 150 : 50; - d->autoScrollTimer.start(scrollInterval, this); - d->autoScrollCount = 0; + d_func()->startAutoScroll(); } /*! @@ -3390,9 +3386,7 @@ void QAbstractItemView::startAutoScroll() */ void QAbstractItemView::stopAutoScroll() { - Q_D(QAbstractItemView); - d->autoScrollTimer.stop(); - d->autoScrollCount = 0; + d_func()->stopAutoScroll(); } /*! diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h index 2ba027d..e7991d2 100644 --- a/src/gui/itemviews/qabstractitemview_p.h +++ b/src/gui/itemviews/qabstractitemview_p.h @@ -126,6 +126,15 @@ public: void doDelayedItemsLayout(int delay = 0); void interruptDelayedItemsLayout() const; + void startAutoScroll() + { // ### it would be nice to make this into a style hint one day + int scrollInterval = (verticalScrollMode == QAbstractItemView::ScrollPerItem) ? 150 : 50; + autoScrollTimer.start(scrollInterval, q_func()); + autoScrollCount = 0; + } + void stopAutoScroll() { autoScrollTimer.stop(); autoScrollCount = 0;} + + bool dropOn(QDropEvent *event, int *row, int *col, QModelIndex *index); bool droppingOnItself(QDropEvent *event, const QModelIndex &index); diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp index e9e365f..3e9db3b 100644 --- a/src/gui/itemviews/qlistview.cpp +++ b/src/gui/itemviews/qlistview.cpp @@ -1,4 +1,4 @@ -/*************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Nokia Corporation (qt-info@nokia.com) @@ -458,15 +458,13 @@ QSize QListView::gridSize() const void QListView::setViewMode(ViewMode mode) { Q_D(QListView); - if (d->viewMode == mode) + if (d->commonListView && d->viewMode == mode) return; d->viewMode = mode; + delete d->commonListView; if (mode == ListMode) { - delete d->dynamicListView; - d->dynamicListView = 0; - if (!d->staticListView) - d->staticListView = new QStaticListViewBase(this, d); + d->commonListView = new QListModeViewBase(this, d); if (!(d->modeProperties & QListViewPrivate::Wrap)) d->setWrapping(false); if (!(d->modeProperties & QListViewPrivate::Spacing)) @@ -482,10 +480,7 @@ void QListView::setViewMode(ViewMode mode) if (!(d->modeProperties & QListViewPrivate::SelectionRectVisible)) d->showElasticBand = false; } else { - delete d->staticListView; - d->staticListView = 0; - if (!d->dynamicListView) - d->dynamicListView = new QDynamicListViewBase(this, d); + d->commonListView = new QIconModeViewBase(this, d); if (!(d->modeProperties & QListViewPrivate::Wrap)) d->setWrapping(true); if (!(d->modeProperties & QListViewPrivate::Spacing)) @@ -549,24 +544,12 @@ void QListView::setRowHidden(int row, bool hide) { Q_D(QListView); const bool hidden = d->isHidden(row); - if (d->viewMode == ListMode) { - if (hide && !hidden) - d->hiddenRows.append(d->model->index(row, 0)); - else if (!hide && hidden) - d->hiddenRows.remove(d->hiddenRows.indexOf(d->model->index(row, 0))); - d->doDelayedItemsLayout(); - } else { - if (hide && !hidden) { - d->dynamicListView->removeItem(row); - d->hiddenRows.append(d->model->index(row, 0)); - } else if (!hide && hidden) { - d->hiddenRows.remove(d->hiddenRows.indexOf(d->model->index(row, 0))); - d->dynamicListView->insertItem(row); - } - if (d->resizeMode == Adjust) - d->doDelayedItemsLayout(); - d->viewport->update(); - } + if (hide && !hidden) + d->commonListView->appendHiddenRow(row); + else if (!hide && hidden) + d->commonListView->removeHiddenRow(row); + d->doDelayedItemsLayout(); + d->viewport->update(); } /*! @@ -575,7 +558,7 @@ void QListView::setRowHidden(int row, bool hide) QRect QListView::visualRect(const QModelIndex &index) const { Q_D(const QListView); - return d->mapToViewport(rectForIndex(index), d->viewMode == QListView::ListMode); + return d->mapToViewport(rectForIndex(index)); } /*! @@ -612,69 +595,17 @@ int QListViewPrivate::horizontalScrollToValue(const QModelIndex &index, const QR const bool rightOf = q->isRightToLeft() ? rect.right() > area.right() : (rect.right() > area.right()) && (rect.left() > area.left()); - int horizontalValue = hbar->value(); - - // ScrollPerItem - if (q->horizontalScrollMode() == QAbstractItemView::ScrollPerItem && viewMode == QListView::ListMode) { - const QListViewItem item = indexToListViewItem(index); - const QRect rect = q->visualRect(index); - horizontalValue = staticListView->horizontalPerItemValue(itemIndex(item), - horizontalValue, area.width(), - leftOf, rightOf, isWrapping(), hint, rect.width()); - } else { // ScrollPerPixel - if (q->isRightToLeft()) { - if (hint == QListView::PositionAtCenter) { - horizontalValue += ((area.width() - rect.width()) / 2) - rect.left(); - } else { - if (leftOf) - horizontalValue -= rect.left(); - else if (rightOf) - horizontalValue += qMin(rect.left(), area.width() - rect.right()); - } - } else { - if (hint == QListView::PositionAtCenter) { - horizontalValue += rect.left() - ((area.width()- rect.width()) / 2); - } else { - if (leftOf) - horizontalValue += rect.left(); - else if (rightOf) - horizontalValue += qMin(rect.left(), rect.right() - area.width()); - } - } - } - return horizontalValue; + return commonListView->horizontalScrollToValue(q->visualIndex(index), hint, leftOf, rightOf, area, rect); } int QListViewPrivate::verticalScrollToValue(const QModelIndex &index, const QRect &rect, QListView::ScrollHint hint) const { Q_Q(const QListView); - const QRect area = viewport->rect(); const bool above = (hint == QListView::EnsureVisible && rect.top() < area.top()); const bool below = (hint == QListView::EnsureVisible && rect.bottom() > area.bottom()); - - int verticalValue = vbar->value(); - - // ScrollPerItem - if (verticalScrollMode == QAbstractItemView::ScrollPerItem && viewMode == QListView::ListMode) { - const QListViewItem item = indexToListViewItem(index); - const QRect rect = q->visualRect(index); - verticalValue = staticListView->verticalPerItemValue(itemIndex(item), - verticalValue, area.height(), - above, below, isWrapping(), hint, rect.height()); - - } else { // ScrollPerPixel - QRect adjusted = rect.adjusted(-spacing(), -spacing(), spacing(), spacing()); - if (hint == QListView::PositionAtTop || above) - verticalValue += adjusted.top(); - else if (hint == QListView::PositionAtBottom || below) - verticalValue += qMin(adjusted.top(), adjusted.bottom() - area.height() + 1); - else if (hint == QListView::PositionAtCenter) - verticalValue += adjusted.top() - ((area.height() - adjusted.height()) / 2); - } - - return verticalValue; + return commonListView->verticalScrollToValue(q->visualIndex(index), hint, above, below, area, rect); } void QListViewPrivate::selectAll(QItemSelectionModel::SelectionFlags command) @@ -766,23 +697,12 @@ void QListView::setRootIndex(const QModelIndex &index) Scroll the view contents by \a dx and \a dy. */ + void QListView::scrollContentsBy(int dx, int dy) { Q_D(QListView); - d->delayedAutoScroll.stop(); // auto scroll was canceled by the user scrolling - - if (d->viewMode == ListMode) - d->staticListView->scrollContentsBy(dx, dy); - else if (state() == DragSelectingState) - d->scrollElasticBandBy(isRightToLeft() ? -dx : dx, dy); - - d->scrollContentsBy(isRightToLeft() ? -dx : dx, dy); - - // update the dragged items - if (d->viewMode == IconMode) // ### move to dynamic class - if (!d->dynamicListView->draggedItems.isEmpty()) - d->viewport->update(d->dynamicListView->draggedItemsRect().translated(dx, dy)); + d->commonListView->scrollContentsBy(dx, dy, d->state == QListView::DragSelectingState); } /*! @@ -811,9 +731,7 @@ QSize QListView::contentsSize() const */ void QListView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { - Q_D(QListView); - if (d->viewMode == IconMode) - d->dynamicListView->dataChanged(topLeft, bottomRight); + d_func()->commonListView->dataChanged(topLeft, bottomRight); QAbstractItemView::dataChanged(topLeft, bottomRight); } @@ -864,7 +782,7 @@ void QListView::mouseMoveEvent(QMouseEvent *e) && d->selectionMode != NoSelection) { QRect rect(d->pressedPosition, e->pos() + QPoint(horizontalOffset(), verticalOffset())); rect = rect.normalized(); - d->viewport->update(d->mapToViewport(rect.united(d->elasticBand), d->viewMode == QListView::ListMode)); + d->viewport->update(d->mapToViewport(rect.united(d->elasticBand))); d->elasticBand = rect; } } @@ -878,7 +796,7 @@ void QListView::mouseReleaseEvent(QMouseEvent *e) QAbstractItemView::mouseReleaseEvent(e); // #### move this implementation into a dynamic class if (d->showElasticBand && d->elasticBand.isValid()) { - d->viewport->update(d->mapToViewport(d->elasticBand, d->viewMode == QListView::ListMode)); + d->viewport->update(d->mapToViewport(d->elasticBand)); d->elasticBand = QRect(); } } @@ -935,69 +853,27 @@ void QListView::resizeEvent(QResizeEvent *e) */ void QListView::dragMoveEvent(QDragMoveEvent *e) { - // ### move implementation to dynamic - Q_D(QListView); - if (e->source() == this && d->viewMode == IconMode) { - // the ignore by default - e->ignore(); - if (d->canDecode(e)) { - // get old dragged items rect - QRect itemsRect = d->dynamicListView->itemsRect(d->dynamicListView->draggedItems); - d->viewport->update(itemsRect.translated(d->dynamicListView->draggedItemsDelta())); - // update position - d->dynamicListView->draggedItemsPos = e->pos(); - // get new items rect - d->viewport->update(itemsRect.translated(d->dynamicListView->draggedItemsDelta())); - // set the item under the cursor to current - QModelIndex index; - if (d->movement == Snap) { - QRect rect(d->dynamicListView->snapToGrid(e->pos() + d->offset()), d->gridSize()); - const QVector<QModelIndex> intersectVector = d->intersectingSet(rect); - index = intersectVector.count() > 0 - ? intersectVector.last() : QModelIndex(); - } else { - index = indexAt(e->pos()); - } - // check if we allow drops here - if (e->source() == this && d->dynamicListView->draggedItems.contains(index)) - e->accept(); // allow changing item position - else if (d->model->flags(index) & Qt::ItemIsDropEnabled) - e->accept(); // allow dropping on dropenabled items - else if (!index.isValid()) - e->accept(); // allow dropping in empty areas - } - // do autoscrolling - if (d->shouldAutoScroll(e->pos())) - startAutoScroll(); - } else { // not internal + if (!d_func()->commonListView->filterDragMoveEvent(e)) QAbstractItemView::dragMoveEvent(e); - } } + /*! \reimp */ void QListView::dragLeaveEvent(QDragLeaveEvent *e) { - // ### move implementation to dynamic - Q_D(QListView); - if (d->viewMode == IconMode) { - d->viewport->update(d->dynamicListView->draggedItemsRect()); // erase the area - d->dynamicListView->draggedItemsPos = QPoint(-1, -1); // don't draw the dragged items - } - QAbstractItemView::dragLeaveEvent(e); + if (!d_func()->commonListView->filterDragLeaveEvent(e)) + QAbstractItemView::dragLeaveEvent(e); } /*! \reimp */ -void QListView::dropEvent(QDropEvent *event) +void QListView::dropEvent(QDropEvent *e) { - Q_D(QListView); - if (event->source() == this && d->viewMode == IconMode) - internalDrop(event); // ### move to dynamic - else - QAbstractItemView::dropEvent(event); + if (!d_func()->commonListView->filterDropEvent(e)) + QAbstractItemView::dropEvent(e); } /*! @@ -1005,10 +881,7 @@ void QListView::dropEvent(QDropEvent *event) */ void QListView::startDrag(Qt::DropActions supportedActions) { - Q_D(QListView); - if (d->viewMode == IconMode) // ### move to dynamic - internalDrag(supportedActions); - else + if (!d_func()->commonListView->filterStartDrag(supportedActions)) QAbstractItemView::startDrag(supportedActions); } @@ -1020,41 +893,8 @@ void QListView::startDrag(Qt::DropActions supportedActions) */ void QListView::internalDrop(QDropEvent *event) { - Q_D(QListView); - if (d->viewMode == QListView::ListMode) - return; - - // ### move to dynamic class - QPoint offset(horizontalOffset(), verticalOffset()); - QPoint end = event->pos() + offset; - QPoint start = d->pressedPosition; - QPoint delta = (d->movement == Snap ? - d->dynamicListView->snapToGrid(end) - - d->dynamicListView->snapToGrid(start) : end - start); - QSize contents = d->contentsSize(); - QList<QModelIndex> indexes = d->selectionModel->selectedIndexes(); - for (int i = 0; i < indexes.count(); ++i) { - QModelIndex index = indexes.at(i); - QRect rect = rectForIndex(index); - d->viewport->update(d->mapToViewport(rect, d->viewMode == QListView::ListMode)); - QPoint dest = rect.topLeft() + delta; - if (isRightToLeft()) - dest.setX(d->flipX(dest.x()) - rect.width()); - d->dynamicListView->moveItem(index.row(), dest); - update(index); - } - stopAutoScroll(); - d->dynamicListView->draggedItems.clear(); - emit indexesMoved(indexes); - event->accept(); // we have handled the event - // if the size has not grown, we need to check if it has shrinked - if (d->dynamicListView - && (d->contentsSize().width() <= contents.width() - || d->contentsSize().height() <= contents.height())) { - d->dynamicListView->updateContentsSize(); - } - if (d->contentsSize() != contents) - updateGeometries(); + // ### Qt5: remove that function + Q_UNUSED(event); } /*! @@ -1065,31 +905,8 @@ void QListView::internalDrop(QDropEvent *event) */ void QListView::internalDrag(Qt::DropActions supportedActions) { - Q_D(QListView); - if (d->viewMode == QListView::ListMode) - return; - - // #### move to dynamic class - - // This function does the same thing as in QAbstractItemView::startDrag(), - // plus adding viewitems to the draggedItems list. - // We need these items to draw the drag items - QModelIndexList indexes = d->selectionModel->selectedIndexes(); - if (indexes.count() > 0 ) { - if (d->viewport->acceptDrops()) { - QModelIndexList::ConstIterator it = indexes.constBegin(); - for (; it != indexes.constEnd(); ++it) - if (d->model->flags(*it) & Qt::ItemIsDragEnabled - && (*it).column() == d->column) - d->dynamicListView->draggedItems.push_back(*it); - } - QDrag *drag = new QDrag(this); - drag->setMimeData(d->model->mimeData(indexes)); - Qt::DropAction action = drag->exec(supportedActions, Qt::CopyAction); - d->dynamicListView->draggedItems.clear(); - if (action == Qt::MoveAction) - d->clearOrRemove(); - } + // ### Qt5: remove that function + Q_UNUSED(supportedActions); } #endif // QT_NO_DRAGANDDROP @@ -1117,6 +934,7 @@ QStyleOptionViewItem QListView::viewOptions() const return option; } + /*! \reimp */ @@ -1213,18 +1031,7 @@ void QListView::paintEvent(QPaintEvent *e) } #ifndef QT_NO_DRAGANDDROP - // #### move this implementation into a dynamic class - if (d->viewMode == IconMode) - if (!d->dynamicListView->draggedItems.isEmpty() - && d->viewport->rect().contains(d->dynamicListView->draggedItemsPos)) { - QPoint delta = d->dynamicListView->draggedItemsDelta(); - painter.translate(delta.x(), delta.y()); - d->dynamicListView->drawItems(&painter, d->dynamicListView->draggedItems); - } - // FIXME: Until the we can provide a proper drop indicator - // in IconMode, it makes no sense to show it - if (d->viewMode == ListMode) - d->paintDropIndicator(&painter); + d->commonListView->paintDragDrop(&painter); #endif #ifndef QT_NO_RUBBERBAND @@ -1263,31 +1070,7 @@ QModelIndex QListView::indexAt(const QPoint &p) const */ int QListView::horizontalOffset() const { - Q_D(const QListView); - // ### split into static and dynamic - if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem && d->viewMode == ListMode) { - if (d->isWrapping()) { - if (d->flow == TopToBottom && !d->staticListView->segmentPositions.isEmpty()) { - const int max = d->staticListView->segmentPositions.count() - 1; - int currentValue = qBound(0, horizontalScrollBar()->value(), max); - int position = d->staticListView->segmentPositions.at(currentValue); - int maximumValue = qBound(0, horizontalScrollBar()->maximum(), max); - int maximum = d->staticListView->segmentPositions.at(maximumValue); - return (isRightToLeft() ? maximum - position : position); - } - //return 0; - } else { - if (d->flow == LeftToRight && !d->staticListView->flowPositions.isEmpty()) { - int position = d->staticListView->flowPositions.at(horizontalScrollBar()->value()); - int maximum = d->staticListView->flowPositions.at(horizontalScrollBar()->maximum()); - return (isRightToLeft() ? maximum - position : position); - } - //return 0; - } - } - return (isRightToLeft() - ? horizontalScrollBar()->maximum() - horizontalScrollBar()->value() - : horizontalScrollBar()->value()); + return d_func()->commonListView->horizontalOffset(); } /*! @@ -1295,30 +1078,7 @@ int QListView::horizontalOffset() const */ int QListView::verticalOffset() const { - // ## split into static and dynamic - Q_D(const QListView); - if (verticalScrollMode() == QAbstractItemView::ScrollPerItem && d->viewMode == ListMode) { - if (d->isWrapping()) { - if (d->flow == LeftToRight && !d->staticListView->segmentPositions.isEmpty()) { - int value = verticalScrollBar()->value(); - if (value >= d->staticListView->segmentPositions.count()) { - //qWarning("QListView: Vertical scroll bar is out of bounds"); - return 0; - } - return d->staticListView->segmentPositions.at(value); - } - } else { - if (d->flow == TopToBottom && !d->staticListView->flowPositions.isEmpty()) { - int value = verticalScrollBar()->value(); - if (value > d->staticListView->flowPositions.count()) { - //qWarning("QListView: Vertical scroll bar is out of bounds"); - return 0; - } - return d->staticListView->flowPositions.at(value) - d->spacing(); - } - } - } - return verticalScrollBar()->value(); + return d_func()->commonListView->verticalOffset(); } /*! @@ -1444,15 +1204,7 @@ QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie */ QRect QListView::rectForIndex(const QModelIndex &index) const { - Q_D(const QListView); - if (!d->isIndexValid(index) - || index.parent() != d->root - || index.column() != d->column - || isIndexHidden(index)) - return QRect(); - d->executePostedLayout(); - QListViewItem item = d->indexToListViewItem(index); - return d->viewItemRect(item); + return d_func()->rectForIndex(index); } /*! @@ -1460,8 +1212,8 @@ QRect QListView::rectForIndex(const QModelIndex &index) const Sets the contents position of the item at \a index in the model to the given \a position. - If the list view's movement mode is Static, this function will have no - effect. + If the list view's movement mode is Static or its view mode is ListView, + this function will have no effect. */ void QListView::setPositionForIndex(const QPoint &position, const QModelIndex &index) { @@ -1473,15 +1225,7 @@ void QListView::setPositionForIndex(const QPoint &position, const QModelIndex &i return; d->executePostedLayout(); - if (index.row() >= d->dynamicListView->items.count()) - return; - const QSize oldContents = d->contentsSize(); - update(index); // update old position - d->dynamicListView->moveItem(index.row(), position); - update(index); // update new position - - if (d->contentsSize() != oldContents) - updateGeometries(); // update the scroll bars + d->commonListView->setPositionForIndex(position, index); } /*! @@ -1717,99 +1461,8 @@ void QListView::updateGeometries() QModelIndex index = d->model->index(0, d->column, d->root); QStyleOptionViewItemV4 option = d->viewOptionsV4(); QSize step = d->itemSize(option, index); - - QSize csize = d->contentsSize(); - QSize vsize = d->viewport->size(); - QSize max = maximumViewportSize(); - if (max.width() >= d->contentsSize().width() && max.height() >= d->contentsSize().height()) - vsize = max; - - // ### reorder the logic - - // ### split into static and dynamic - - const bool vertical = verticalScrollMode() == QAbstractItemView::ScrollPerItem; - const bool horizontal = horizontalScrollMode() == QAbstractItemView::ScrollPerItem; - - if (d->flow == TopToBottom) { - if (horizontal && d->isWrapping() && d->viewMode == ListMode) { - const QVector<int> segmentPositions = d->staticListView->segmentPositions; - const int steps = segmentPositions.count() - 1; - if (steps > 0) { - int pageSteps = d->staticListView->perItemScrollingPageSteps(vsize.width(), - csize.width(), - isWrapping()); - horizontalScrollBar()->setSingleStep(1); - horizontalScrollBar()->setPageStep(pageSteps); - horizontalScrollBar()->setRange(0, steps - pageSteps); - } else { - horizontalScrollBar()->setRange(0, 0); - } - } else { - horizontalScrollBar()->setSingleStep(step.width() + d->spacing()); - horizontalScrollBar()->setPageStep(vsize.width()); - horizontalScrollBar()->setRange(0, d->contentsSize().width() - vsize.width()); - } - if (vertical && !d->isWrapping() && d->viewMode == ListMode) { - const QVector<int> flowPositions = d->staticListView->flowPositions; - const int steps = flowPositions.count() - 1; - if (steps > 0) { - int pageSteps = d->staticListView->perItemScrollingPageSteps(vsize.height(), - csize.height(), - isWrapping()); - verticalScrollBar()->setSingleStep(1); - verticalScrollBar()->setPageStep(pageSteps); - verticalScrollBar()->setRange(0, steps - pageSteps); - } else { - verticalScrollBar()->setRange(0, 0); - } - // } else if (vertical && d->isWrapping() && d->movement == Static) { - // ### wrapped scrolling in flow direction - } else { - verticalScrollBar()->setSingleStep(step.height() + d->spacing()); - verticalScrollBar()->setPageStep(vsize.height()); - verticalScrollBar()->setRange(0, d->contentsSize().height() - vsize.height()); - } - } else { // LeftToRight - if (horizontal && !d->isWrapping() && d->viewMode == ListMode) { - const QVector<int> flowPositions = d->staticListView->flowPositions; - int steps = flowPositions.count() - 1; - if (steps > 0) { - int pageSteps = d->staticListView->perItemScrollingPageSteps(vsize.width(), - csize.width(), - isWrapping()); - horizontalScrollBar()->setSingleStep(1); - horizontalScrollBar()->setPageStep(pageSteps); - horizontalScrollBar()->setRange(0, steps - pageSteps); - } else { - horizontalScrollBar()->setRange(0, 0); - } - // } else if (horizontal && d->isWrapping() && d->movement == Static) { - // ### wrapped scrolling in flow direction - } else { - horizontalScrollBar()->setSingleStep(step.width() + d->spacing()); - horizontalScrollBar()->setPageStep(vsize.width()); - horizontalScrollBar()->setRange(0, d->contentsSize().width() - vsize.width()); - } - if (vertical && d->isWrapping() && d->viewMode == ListMode) { - const QVector<int> segmentPositions = d->staticListView->segmentPositions; - int steps = segmentPositions.count() - 1; - if (steps > 0) { - int pageSteps = d->staticListView->perItemScrollingPageSteps(vsize.height(), - csize.height(), - isWrapping()); - verticalScrollBar()->setSingleStep(1); - verticalScrollBar()->setPageStep(pageSteps); - verticalScrollBar()->setRange(0, steps - pageSteps); - } else { - verticalScrollBar()->setRange(0, 0); - } - } else { - verticalScrollBar()->setSingleStep(step.height() + d->spacing()); - verticalScrollBar()->setPageStep(vsize.height()); - verticalScrollBar()->setRange(0, d->contentsSize().height() - vsize.height()); - } - } + d->commonListView->updateHorizontalScrollBar(step); + d->commonListView->updateVerticalScrollBar(step); } QAbstractItemView::updateGeometries(); @@ -1958,14 +1611,14 @@ bool QListView::event(QEvent *e) QListViewPrivate::QListViewPrivate() : QAbstractItemViewPrivate(), - dynamicListView(0), + commonListView(0), wrap(false), space(0), flow(QListView::TopToBottom), movement(QListView::Static), resizeMode(QListView::Fixed), layoutMode(QListView::SinglePass), - viewMode(QListView::IconMode), //this will ensure the first initialization to ListView + viewMode(QListView::ListMode), modeProperties(0), column(0), uniformItemSizes(false), @@ -1976,21 +1629,14 @@ QListViewPrivate::QListViewPrivate() QListViewPrivate::~QListViewPrivate() { - if (viewMode == QListView::ListMode) - delete staticListView; - else - delete dynamicListView; + delete commonListView; } void QListViewPrivate::clear() { - // ### split into dynamic and static // initialization of data structs cachedItemSize = QSize(); - if (viewMode == QListView::ListMode) - staticListView->clear(); - else - dynamicListView->clear(); + commonListView->clear(); } void QListViewPrivate::prepareItemsLayout() @@ -1999,7 +1645,7 @@ void QListViewPrivate::prepareItemsLayout() clear(); //take the size as if there were scrollbar in order to prevent scrollbar to blink - layoutBounds = QRect(QPoint(0,0), q->maximumViewportSize()); + layoutBounds = QRect(QPoint(), q->maximumViewportSize()); int frameAroundContents = 0; if (q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents)) @@ -2017,15 +1663,8 @@ void QListViewPrivate::prepareItemsLayout() layoutBounds.adjust(0, 0, -verticalMargin, -horizontalMargin); - int rowCount = model->rowCount(root); - int colCount = model->columnCount(root); - if (colCount <= 0) - rowCount = 0; // no contents - if (viewMode == QListView::ListMode) { - staticListView->flowPositions.resize(rowCount); - } else { - dynamicListView->tree.create(qMax(rowCount - hiddenRows.count(), 0)); - } + int rowCount = model->columnCount(root) <= 0 ? 0 : model->rowCount(root); + commonListView->setRowCount(rowCount); } /*! @@ -2033,7 +1672,6 @@ void QListViewPrivate::prepareItemsLayout() */ bool QListViewPrivate::doItemsLayout(int delta) { - // ### split into static and dynamic int max = model->rowCount(root) - 1; int first = batchStartRow(); int last = qMin(first + delta - 1, max); @@ -2057,9 +1695,7 @@ bool QListViewPrivate::doItemsLayout(int delta) info.flow = flow; info.max = max; - if (viewMode == QListView::ListMode) - return staticListView->doBatchedItemLayout(info, max); - return dynamicListView->doBatchedItemLayout(info, max); + return commonListView->doBatchedItemLayout(info, max); } QListViewItem QListViewPrivate::indexToListViewItem(const QModelIndex &index) const @@ -2067,29 +1703,16 @@ QListViewItem QListViewPrivate::indexToListViewItem(const QModelIndex &index) co if (!index.isValid() || isHidden(index.row())) return QListViewItem(); - if (viewMode == QListView::ListMode) - return staticListView->indexToListViewItem(index); - return dynamicListView->indexToListViewItem(index); + return commonListView->indexToListViewItem(index); } - -int QListViewPrivate::itemIndex(const QListViewItem &item) const -{ - if (viewMode == QListView::ListMode) - return staticListView->itemIndex(item); - return dynamicListView->itemIndex(item); -} - -QRect QListViewPrivate::mapToViewport(const QRect &rect, bool greedy) const +QRect QListViewPrivate::mapToViewport(const QRect &rect, bool extend) const { Q_Q(const QListView); if (!rect.isValid()) return rect; - QRect result = rect; - if (greedy) - result = staticListView->mapToViewport(rect); - + QRect result = extend ? commonListView->mapToViewport(rect) : rect; int dx = -q->horizontalOffset(); int dy = -q->verticalOffset(); result.adjust(dx, dy, dx, dy); @@ -2177,46 +1800,217 @@ QItemSelection QListViewPrivate::selection(const QRect &rect) const } /* - * Static ListView Implementation + * Common ListView Implementation */ -int QStaticListViewBase::verticalPerItemValue(int itemIndex, int verticalValue, int areaHeight, - bool above, bool below, bool wrap, - QListView::ScrollHint hint, int itemHeight) const +void QCommonListViewBase::appendHiddenRow(int row) +{ + dd->hiddenRows.append(dd->model->index(row, 0)); +} + +void QCommonListViewBase::removeHiddenRow(int row) { - int value = qBound(0, verticalValue, flowPositions.count() - 1); - if (above) - return perItemScrollToValue(itemIndex, value, areaHeight, QListView::PositionAtTop, - Qt::Vertical,wrap, itemHeight); - else if (below) - return perItemScrollToValue(itemIndex, value, areaHeight, QListView::PositionAtBottom, - Qt::Vertical, wrap, itemHeight); - else if (hint != QListView::EnsureVisible) - return perItemScrollToValue(itemIndex, value, areaHeight, hint, Qt::Vertical, wrap, itemHeight); - return value; + dd->hiddenRows.remove(dd->hiddenRows.indexOf(dd->model->index(row, 0))); } -int QStaticListViewBase::horizontalPerItemValue(int itemIndex, int horizontalValue, int areaWidth, - bool leftOf, bool rightOf, bool wrap, - QListView::ScrollHint hint, int itemWidth) const +void QCommonListViewBase::updateHorizontalScrollBar(const QSize &step) { - int value = qBound(0, horizontalValue, flowPositions.count() - 1); + horizontalScrollBar()->setSingleStep(step.width() + spacing()); + horizontalScrollBar()->setPageStep(viewport()->width()); + horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width()); +} + +void QCommonListViewBase::updateVerticalScrollBar(const QSize &step) +{ + verticalScrollBar()->setSingleStep(step.height() + spacing()); + verticalScrollBar()->setPageStep(viewport()->height()); + verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height()); +} + +void QCommonListViewBase::scrollContentsBy(int dx, int dy, bool /*scrollElasticBand*/) +{ + dd->scrollContentsBy(isRightToLeft() ? -dx : dx, dy); +} + +int QCommonListViewBase::verticalScrollToValue(int /*index*/, QListView::ScrollHint hint, + bool above, bool below, const QRect &area, const QRect &rect) const +{ + int verticalValue = verticalScrollBar()->value(); + QRect adjusted = rect.adjusted(-spacing(), -spacing(), spacing(), spacing()); + if (hint == QListView::PositionAtTop || above) + verticalValue += adjusted.top(); + else if (hint == QListView::PositionAtBottom || below) + verticalValue += qMin(adjusted.top(), adjusted.bottom() - area.height() + 1); + else if (hint == QListView::PositionAtCenter) + verticalValue += adjusted.top() - ((area.height() - adjusted.height()) / 2); + return verticalValue; +} + +int QCommonListViewBase::horizontalOffset() const +{ + return (isRightToLeft() ? horizontalScrollBar()->maximum() - horizontalScrollBar()->value() : horizontalScrollBar()->value()); +} + +int QCommonListViewBase::horizontalScrollToValue(const int /*index*/, QListView::ScrollHint hint, + bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const +{ + int horizontalValue = horizontalScrollBar()->value(); + if (isRightToLeft()) { + if (hint == QListView::PositionAtCenter) { + horizontalValue += ((area.width() - rect.width()) / 2) - rect.left(); + } else { + if (leftOf) + horizontalValue -= rect.left(); + else if (rightOf) + horizontalValue += qMin(rect.left(), area.width() - rect.right()); + } + } else { + if (hint == QListView::PositionAtCenter) { + horizontalValue += rect.left() - ((area.width()- rect.width()) / 2); + } else { + if (leftOf) + horizontalValue += rect.left(); + else if (rightOf) + horizontalValue += qMin(rect.left(), rect.right() - area.width()); + } + } + return horizontalValue; +} + +/* + * ListMode ListView Implementation +*/ + +#ifndef QT_NO_DRAGANDDROP +void QListModeViewBase::paintDragDrop(QPainter *painter) +{ + // FIXME: Until the we can provide a proper drop indicator + // in IconMode, it makes no sense to show it + dd->paintDropIndicator(painter); +} +#endif //QT_NO_DRAGANDDROP + +void QListModeViewBase::updateVerticalScrollBar(const QSize &step) +{ + if (verticalScrollMode() == QAbstractItemView::ScrollPerItem + && ((flow() == QListView::TopToBottom && !isWrapping()) + || (flow() == QListView::LeftToRight && isWrapping()))) { + const int steps = (flow() == QListView::TopToBottom ? flowPositions : segmentPositions).count() - 1; + if (steps > 0) { + const int pageSteps = perItemScrollingPageSteps(viewport()->height(), contentsSize.height(), isWrapping()); + verticalScrollBar()->setSingleStep(1); + verticalScrollBar()->setPageStep(pageSteps); + verticalScrollBar()->setRange(0, steps - pageSteps); + } else { + verticalScrollBar()->setRange(0, 0); + } + // } else if (vertical && d->isWrapping() && d->movement == Static) { + // ### wrapped scrolling in flow direction + } else { + QCommonListViewBase::updateVerticalScrollBar(step); + } +} + +void QListModeViewBase::updateHorizontalScrollBar(const QSize &step) +{ + if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem + && ((flow() == QListView::TopToBottom && isWrapping()) + || (flow() == QListView::LeftToRight && !isWrapping()))) { + int steps = (flow() == QListView::TopToBottom ? segmentPositions : flowPositions).count() - 1; + if (steps > 0) { + const int pageSteps = perItemScrollingPageSteps(viewport()->width(), contentsSize.width(), isWrapping()); + horizontalScrollBar()->setSingleStep(1); + horizontalScrollBar()->setPageStep(pageSteps); + horizontalScrollBar()->setRange(0, steps - pageSteps); + } else { + horizontalScrollBar()->setRange(0, 0); + } + } else { + QCommonListViewBase::updateHorizontalScrollBar(step); + } +} + +int QListModeViewBase::verticalScrollToValue(int index, QListView::ScrollHint hint, + bool above, bool below, const QRect &area, const QRect &rect) const +{ + if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) { + int value = qBound(0, verticalScrollBar()->value(), flowPositions.count() - 1); + if (above) + hint = QListView::PositionAtTop; + else if (below) + hint = QListView::PositionAtBottom; + if (hint == QListView::EnsureVisible) + return value; + + return perItemScrollToValue(index, value, area.height(), hint, Qt::Vertical, isWrapping(), rect.height()); + } + + return QCommonListViewBase::verticalScrollToValue(index, hint, above, below, area, rect); +} + +int QListModeViewBase::horizontalOffset() const +{ + if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) { + if (isWrapping()) { + if (flow() == QListView::TopToBottom && !segmentPositions.isEmpty()) { + const int max = segmentPositions.count() - 1; + int currentValue = qBound(0, horizontalScrollBar()->value(), max); + int position = segmentPositions.at(currentValue); + int maximumValue = qBound(0, horizontalScrollBar()->maximum(), max); + int maximum = segmentPositions.at(maximumValue); + return (isRightToLeft() ? maximum - position : position); + } + } else if (flow() == QListView::LeftToRight && !flowPositions.isEmpty()) { + int position = flowPositions.at(horizontalScrollBar()->value()); + int maximum = flowPositions.at(horizontalScrollBar()->maximum()); + return (isRightToLeft() ? maximum - position : position); + } + } + return QCommonListViewBase::horizontalOffset(); +} + +int QListModeViewBase::verticalOffset() const +{ + if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) { + if (isWrapping()) { + if (flow() == QListView::LeftToRight && !segmentPositions.isEmpty()) { + int value = verticalScrollBar()->value(); + if (value >= segmentPositions.count()) + return 0; + return segmentPositions.at(value); + } + } else if (flow() == QListView::TopToBottom && !flowPositions.isEmpty()) { + int value = verticalScrollBar()->value(); + if (value > flowPositions.count()) + return 0; + return flowPositions.at(value) - spacing(); + } + } + return QCommonListViewBase::verticalOffset(); +} + +int QListModeViewBase::horizontalScrollToValue(int index, QListView::ScrollHint hint, + bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const +{ + if (horizontalScrollMode() != QAbstractItemView::ScrollPerItem) + return QCommonListViewBase::horizontalScrollToValue(index, hint, leftOf, rightOf, area, rect); + + int value = qBound(0, horizontalScrollBar()->value(), flowPositions.count() - 1); if (leftOf) - return perItemScrollToValue(itemIndex, value, areaWidth, QListView::PositionAtTop, - Qt::Horizontal, wrap, itemWidth); + hint = QListView::PositionAtTop; else if (rightOf) - return perItemScrollToValue(itemIndex, value, areaWidth, QListView::PositionAtBottom, - Qt::Horizontal, wrap, itemWidth); - else if (hint != QListView::EnsureVisible) - return perItemScrollToValue(itemIndex, value, areaWidth, hint, Qt::Horizontal, wrap, itemWidth); - return value; + hint = QListView::PositionAtBottom; + if (hint == QListView::EnsureVisible) + return value; + + return perItemScrollToValue(index, value, area.width(), hint, Qt::Horizontal, isWrapping(), rect.width()); } -void QStaticListViewBase::scrollContentsBy(int &dx, int &dy) +void QListModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand) { // ### reorder this logic - const int verticalValue = verticalScrollBarValue(); - const int horizontalValue = horizontalScrollBarValue(); + const int verticalValue = verticalScrollBar()->value(); + const int horizontalValue = horizontalScrollBar()->value(); const bool vertical = (verticalScrollMode() == QAbstractItemView::ScrollPerItem); const bool horizontal = (horizontalScrollMode() == QAbstractItemView::ScrollPerItem); @@ -2255,9 +2049,10 @@ void QStaticListViewBase::scrollContentsBy(int &dx, int &dy) dx = previousCoordinate - currentCoordinate; } } + QCommonListViewBase::scrollContentsBy(dx, dy, scrollElasticBand); } -bool QStaticListViewBase::doBatchedItemLayout(const QListViewLayoutInfo &info, int max) +bool QListModeViewBase::doBatchedItemLayout(const QListViewLayoutInfo &info, int max) { doStaticLayout(info); if (batchStartRow > max) { // stop items layout @@ -2269,7 +2064,7 @@ bool QStaticListViewBase::doBatchedItemLayout(const QListViewLayoutInfo &info, i return false; // not done } -QListViewItem QStaticListViewBase::indexToListViewItem(const QModelIndex &index) const +QListViewItem QListModeViewBase::indexToListViewItem(const QModelIndex &index) const { if (flowPositions.isEmpty() || segmentPositions.isEmpty() @@ -2305,7 +2100,7 @@ QListViewItem QStaticListViewBase::indexToListViewItem(const QModelIndex &index) return QListViewItem(QRect(pos, size), index.row()); } -QPoint QStaticListViewBase::initStaticLayout(const QListViewLayoutInfo &info) +QPoint QListModeViewBase::initStaticLayout(const QListViewLayoutInfo &info) { int x, y; if (info.first == 0) { @@ -2340,7 +2135,7 @@ QPoint QStaticListViewBase::initStaticLayout(const QListViewLayoutInfo &info) /*! \internal */ -void QStaticListViewBase::doStaticLayout(const QListViewLayoutInfo &info) +void QListModeViewBase::doStaticLayout(const QListViewLayoutInfo &info) { const bool useItemSize = !info.grid.isValid(); const QPoint topLeft = initStaticLayout(info); @@ -2443,7 +2238,7 @@ void QStaticListViewBase::doStaticLayout(const QListViewLayoutInfo &info) Finds the set of items intersecting with \a area. In this function, itemsize is counted from topleft to the start of the next item. */ -QVector<QModelIndex> QStaticListViewBase::intersectingStaticSet(const QRect &area) const +QVector<QModelIndex> QListModeViewBase::intersectingSet(const QRect &area) const { QVector<QModelIndex> ret; int segStartPosition; @@ -2480,19 +2275,14 @@ QVector<QModelIndex> QStaticListViewBase::intersectingStaticSet(const QRect &are ret += index; #if 0 // for debugging else - qWarning("intersectingStaticSet: row %d was invalid", row); + qWarning("intersectingSet: row %d was invalid", row); #endif } } return ret; } -int QStaticListViewBase::itemIndex(const QListViewItem &item) const -{ - return item.indexHint; -} - -QRect QStaticListViewBase::mapToViewport(const QRect &rect) const +QRect QListModeViewBase::mapToViewport(const QRect &rect) const { if (isWrapping()) return rect; @@ -2510,7 +2300,7 @@ QRect QStaticListViewBase::mapToViewport(const QRect &rect) const return result; } -int QStaticListViewBase::perItemScrollingPageSteps(int length, int bounds, bool wrap) const +int QListModeViewBase::perItemScrollingPageSteps(int length, int bounds, bool wrap) const { const QVector<int> positions = (wrap ? segmentPositions : flowPositions); if (positions.isEmpty() || bounds <= length) @@ -2538,7 +2328,7 @@ int QStaticListViewBase::perItemScrollingPageSteps(int length, int bounds, bool return qMax(pageSteps, 1); } -int QStaticListViewBase::perItemScrollToValue(int index, int scrollValue, int viewportSize, +int QListModeViewBase::perItemScrollToValue(int index, int scrollValue, int viewportSize, QAbstractItemView::ScrollHint hint, Qt::Orientation orientation, bool wrap, int itemExtent) const { @@ -2598,7 +2388,7 @@ int QStaticListViewBase::perItemScrollToValue(int index, int scrollValue, int vi return scrollValue; } -void QStaticListViewBase::clear() +void QListModeViewBase::clear() { flowPositions.clear(); segmentPositions.clear(); @@ -2610,10 +2400,175 @@ void QStaticListViewBase::clear() } /* - * Dynamic ListView Implementation + * IconMode ListView Implementation */ -void QDynamicListViewBase::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) +void QIconModeViewBase::setPositionForIndex(const QPoint &position, const QModelIndex &index) +{ + if (index.row() >= items.count()) + return; + const QSize oldContents = contentsSize; + qq->update(index); // update old position + moveItem(index.row(), position); + qq->update(index); // update new position + + if (contentsSize != oldContents) + dd->viewUpdateGeometries(); // update the scroll bars +} + +void QIconModeViewBase::appendHiddenRow(int row) +{ + if (row >= 0 && row < items.count()) //remove item + tree.removeLeaf(items.at(row).rect(), row); + QCommonListViewBase::appendHiddenRow(row); +} + +void QIconModeViewBase::removeHiddenRow(int row) +{ + QCommonListViewBase::appendHiddenRow(row); + if (row >= 0 && row < items.count()) //insert item + tree.insertLeaf(items.at(row).rect(), row); +} + +#ifndef QT_NO_DRAGANDDROP +void QIconModeViewBase::paintDragDrop(QPainter *painter) +{ + if (!draggedItems.isEmpty() && viewport()->rect().contains(draggedItemsPos)) { + //we need to draw the items that arre dragged + painter->translate(draggedItemsDelta()); + QStyleOptionViewItemV4 option = viewOptions(); + option.state &= ~QStyle::State_MouseOver; + QVector<QModelIndex>::const_iterator it = draggedItems.begin(); + QListViewItem item = indexToListViewItem(*it); + for (; it != draggedItems.end(); ++it) { + item = indexToListViewItem(*it); + option.rect = viewItemRect(item); + delegate(*it)->paint(painter, option, *it); + } + } +} + +bool QIconModeViewBase::filterStartDrag(Qt::DropActions supportedActions) +{ + // This function does the same thing as in QAbstractItemView::startDrag(), + // plus adding viewitems to the draggedItems list. + // We need these items to draw the drag items + QModelIndexList indexes = dd->selectionModel->selectedIndexes(); + if (indexes.count() > 0 ) { + if (viewport()->acceptDrops()) { + QModelIndexList::ConstIterator it = indexes.constBegin(); + for (; it != indexes.constEnd(); ++it) + if (dd->model->flags(*it) & Qt::ItemIsDragEnabled + && (*it).column() == dd->column) + draggedItems.push_back(*it); + } + QDrag *drag = new QDrag(qq); + drag->setMimeData(dd->model->mimeData(indexes)); + Qt::DropAction action = drag->exec(supportedActions, Qt::CopyAction); + draggedItems.clear(); + if (action == Qt::MoveAction) + dd->clearOrRemove(); + } + return true; +} + +bool QIconModeViewBase::filterDropEvent(QDropEvent *e) +{ + if (e->source() != qq) + return false; + + const QSize contents = contentsSize; + QPoint offset(horizontalOffset(), verticalOffset()); + QPoint end = e->pos() + offset; + QPoint start = dd->pressedPosition; + QPoint delta = (dd->movement == QListView::Snap ? snapToGrid(end) - snapToGrid(start) : end - start); + QList<QModelIndex> indexes = dd->selectionModel->selectedIndexes(); + for (int i = 0; i < indexes.count(); ++i) { + QModelIndex index = indexes.at(i); + QRect rect = dd->rectForIndex(index); + viewport()->update(mapToViewport(rect)); + QPoint dest = rect.topLeft() + delta; + if (qq->isRightToLeft()) + dest.setX(dd->flipX(dest.x()) - rect.width()); + moveItem(index.row(), dest); + qq->update(index); + } + dd->stopAutoScroll(); + draggedItems.clear(); + dd->emitIndexesMoved(indexes); + e->accept(); // we have handled the event + // if the size has not grown, we need to check if it has shrinked + if (contentsSize != contents) { + if ((contentsSize.width() <= contents.width() + || contentsSize.height() <= contents.height())) { + updateContentsSize(); + } + dd->viewUpdateGeometries(); + } + return true; +} + +bool QIconModeViewBase::filterDragLeaveEvent(QDragLeaveEvent *e) +{ + viewport()->update(draggedItemsRect()); // erase the area + draggedItemsPos = QPoint(-1, -1); // don't draw the dragged items + return QCommonListViewBase::filterDragLeaveEvent(e); +} + +bool QIconModeViewBase::filterDragMoveEvent(QDragMoveEvent *e) +{ + if (e->source() != qq || !dd->canDecode(e)) + return false; + + // ignore by default + e->ignore(); + // get old dragged items rect + QRect itemsRect = this->itemsRect(draggedItems); + viewport()->update(itemsRect.translated(draggedItemsDelta())); + // update position + draggedItemsPos = e->pos(); + // get new items rect + viewport()->update(itemsRect.translated(draggedItemsDelta())); + // set the item under the cursor to current + QModelIndex index; + if (movement() == QListView::Snap) { + QRect rect(snapToGrid(e->pos() + offset()), gridSize()); + const QVector<QModelIndex> intersectVector = intersectingSet(rect); + index = intersectVector.count() > 0 ? intersectVector.last() : QModelIndex(); + } else { + index = qq->indexAt(e->pos()); + } + // check if we allow drops here + if (draggedItems.contains(index)) + e->accept(); // allow changing item position + else if (dd->model->flags(index) & Qt::ItemIsDropEnabled) + e->accept(); // allow dropping on dropenabled items + else if (!index.isValid()) + e->accept(); // allow dropping in empty areas + + // the event was treated. do autoscrolling + if (dd->shouldAutoScroll(e->pos())) + dd->startAutoScroll(); + return true; +} +#endif // QT_NO_DRAGANDDROP + +void QIconModeViewBase::setRowCount(int rowCount) +{ + tree.create(qMax(rowCount - hiddenCount(), 0)); +} + +void QIconModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand) +{ + if (scrollElasticBand) + dd->scrollElasticBandBy(isRightToLeft() ? -dx : dx, dy); + + QCommonListViewBase::scrollContentsBy(dx, dy, scrollElasticBand); + if (!draggedItems.isEmpty()) + viewport()->update(draggedItemsRect().translated(dx, dy)); +} + +void QIconModeViewBase::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { if (column() >= topLeft.column() && column() <= bottomRight.column()) { QStyleOptionViewItemV4 option = viewOptions(); @@ -2623,23 +2578,29 @@ void QDynamicListViewBase::dataChanged(const QModelIndex &topLeft, const QModelI } } -bool QDynamicListViewBase::doBatchedItemLayout(const QListViewLayoutInfo &info, int max) +bool QIconModeViewBase::doBatchedItemLayout(const QListViewLayoutInfo &info, int max) { if (info.last >= items.count()) { - createItems(info.last + 1); + //first we create the items + QStyleOptionViewItemV4 option = viewOptions(); + for (int row = items.count(); row <= info.last; ++row) { + QSize size = itemSize(option, modelIndex(row)); + QListViewItem item(QRect(0, 0, size.width(), size.height()), row); // default pos + items.append(item); + } doDynamicLayout(info); } return (batchStartRow > max); // done } -QListViewItem QDynamicListViewBase::indexToListViewItem(const QModelIndex &index) const +QListViewItem QIconModeViewBase::indexToListViewItem(const QModelIndex &index) const { if (index.isValid() && index.row() < items.count()) return items.at(index.row()); return QListViewItem(); } -void QDynamicListViewBase::initBspTree(const QSize &contents) +void QIconModeViewBase::initBspTree(const QSize &contents) { // remove all items from the tree int leafCount = tree.leafCount(); @@ -2656,7 +2617,7 @@ void QDynamicListViewBase::initBspTree(const QSize &contents) tree.init(QRect(0, 0, contents.width(), contents.height()), type); } -QPoint QDynamicListViewBase::initDynamicLayout(const QListViewLayoutInfo &info) +QPoint QIconModeViewBase::initDynamicLayout(const QListViewLayoutInfo &info) { int x, y; if (info.first == 0) { @@ -2678,7 +2639,7 @@ QPoint QDynamicListViewBase::initDynamicLayout(const QListViewLayoutInfo &info) /*! \internal */ -void QDynamicListViewBase::doDynamicLayout(const QListViewLayoutInfo &info) +void QIconModeViewBase::doDynamicLayout(const QListViewLayoutInfo &info) { const bool useItemSize = !info.grid.isValid(); const QPoint topLeft = initDynamicLayout(info); @@ -2712,7 +2673,7 @@ void QDynamicListViewBase::doDynamicLayout(const QListViewLayoutInfo &info) if (moved.count() != items.count()) moved.resize(items.count()); - QRect rect(QPoint(0, 0), topLeft); + QRect rect(QPoint(), topLeft); QListViewItem *item = 0; for (int row = info.first; row <= info.last; ++row) { item = &items[row]; @@ -2805,43 +2766,18 @@ void QDynamicListViewBase::doDynamicLayout(const QListViewLayoutInfo &info) viewport()->update(); } -QVector<QModelIndex> QDynamicListViewBase::intersectingDynamicSet(const QRect &area) const +QVector<QModelIndex> QIconModeViewBase::intersectingSet(const QRect &area) const { - QDynamicListViewBase *that = const_cast<QDynamicListViewBase*>(this); + QIconModeViewBase *that = const_cast<QIconModeViewBase*>(this); QBspTree::Data data(static_cast<void*>(that)); QVector<QModelIndex> res; that->interSectingVector = &res; - that->tree.climbTree(area, &QDynamicListViewBase::addLeaf, data); + that->tree.climbTree(area, &QIconModeViewBase::addLeaf, data); that->interSectingVector = 0; return res; } -void QDynamicListViewBase::createItems(int to) -{ - int count = items.count(); - QSize size; - QStyleOptionViewItemV4 option = viewOptions(); - for (int row = count; row < to; ++row) { - size = itemSize(option, modelIndex(row)); - QListViewItem item(QRect(0, 0, size.width(), size.height()), row); // default pos - items.append(item); - } -} - -void QDynamicListViewBase::drawItems(QPainter *painter, const QVector<QModelIndex> &indexes) const -{ - QStyleOptionViewItemV4 option = viewOptions(); - option.state &= ~QStyle::State_MouseOver; - QVector<QModelIndex>::const_iterator it = indexes.begin(); - QListViewItem item = indexToListViewItem(*it); - for (; it != indexes.end(); ++it) { - item = indexToListViewItem(*it); - option.rect = viewItemRect(item); - delegate(*it)->paint(painter, option, *it); - } -} - -QRect QDynamicListViewBase::itemsRect(const QVector<QModelIndex> &indexes) const +QRect QIconModeViewBase::itemsRect(const QVector<QModelIndex> &indexes) const { QVector<QModelIndex>::const_iterator it = indexes.begin(); QListViewItem item = indexToListViewItem(*it); @@ -2853,7 +2789,7 @@ QRect QDynamicListViewBase::itemsRect(const QVector<QModelIndex> &indexes) const return rect; } -int QDynamicListViewBase::itemIndex(const QListViewItem &item) const +int QIconModeViewBase::itemIndex(const QListViewItem &item) const { if (!item.isValid()) return -1; @@ -2889,11 +2825,11 @@ int QDynamicListViewBase::itemIndex(const QListViewItem &item) const return -1; } -void QDynamicListViewBase::addLeaf(QVector<int> &leaf, const QRect &area, +void QIconModeViewBase::addLeaf(QVector<int> &leaf, const QRect &area, uint visited, QBspTree::Data data) { QListViewItem *vi; - QDynamicListViewBase *_this = static_cast<QDynamicListViewBase *>(data.ptr); + QIconModeViewBase *_this = static_cast<QIconModeViewBase *>(data.ptr); for (int i = 0; i < leaf.count(); ++i) { int idx = leaf.at(i); if (idx < 0 || idx >= _this->items.count()) @@ -2909,19 +2845,7 @@ void QDynamicListViewBase::addLeaf(QVector<int> &leaf, const QRect &area, } } -void QDynamicListViewBase::insertItem(int index) -{ - if (index >= 0 && index < items.count()) - tree.insertLeaf(items.at(index).rect(), index); -} - -void QDynamicListViewBase::removeItem(int index) -{ - if (index >= 0 && index < items.count()) - tree.removeLeaf(items.at(index).rect(), index); -} - -void QDynamicListViewBase::moveItem(int index, const QPoint &dest) +void QIconModeViewBase::moveItem(int index, const QPoint &dest) { // does not impact on the bintree itself or the contents rect QListViewItem *item = &items[index]; @@ -2941,14 +2865,14 @@ void QDynamicListViewBase::moveItem(int index, const QPoint &dest) moved.setBit(index, true); } -QPoint QDynamicListViewBase::snapToGrid(const QPoint &pos) const +QPoint QIconModeViewBase::snapToGrid(const QPoint &pos) const { int x = pos.x() - (pos.x() % gridSize().width()); int y = pos.y() - (pos.y() % gridSize().height()); return QPoint(x, y); } -QPoint QDynamicListViewBase::draggedItemsDelta() const +QPoint QIconModeViewBase::draggedItemsDelta() const { if (movement() == QListView::Snap) { QPoint snapdelta = QPoint((offset().x() % gridSize().width()), @@ -2958,7 +2882,7 @@ QPoint QDynamicListViewBase::draggedItemsDelta() const return draggedItemsPos - pressedPosition(); } -QRect QDynamicListViewBase::draggedItemsRect() const +QRect QIconModeViewBase::draggedItemsRect() const { QRect rect = itemsRect(draggedItems); rect.translate(draggedItemsDelta()); @@ -2977,7 +2901,7 @@ void QListViewPrivate::scrollElasticBandBy(int dx, int dy) elasticBand.moveTop(elasticBand.top() - dy); } -void QDynamicListViewBase::clear() +void QIconModeViewBase::clear() { tree.destroy(); items.clear(); @@ -2986,7 +2910,7 @@ void QDynamicListViewBase::clear() batchSavedDeltaSeg = 0; } -void QDynamicListViewBase::updateContentsSize() +void QIconModeViewBase::updateContentsSize() { QRect bounding; for (int i = 0; i < items.count(); ++i) @@ -3039,7 +2963,7 @@ int QListView::visualIndex(const QModelIndex &index) const Q_D(const QListView); d->executePostedLayout(); QListViewItem itm = d->indexToListViewItem(index); - return d->itemIndex(itm); + return d->commonListView->itemIndex(itm); } QT_END_NAMESPACE diff --git a/src/gui/itemviews/qlistview_p.h b/src/gui/itemviews/qlistview_p.h index 6c8d324..db9eb59 100644 --- a/src/gui/itemviews/qlistview_p.h +++ b/src/gui/itemviews/qlistview_p.h @@ -67,8 +67,8 @@ QT_BEGIN_NAMESPACE class QListViewItem { friend class QListViewPrivate; - friend class QStaticListViewBase; - friend class QDynamicListViewBase; + friend class QListModeViewBase; + friend class QIconModeViewBase; public: inline QListViewItem() : x(-1), y(-1), w(0), h(0), indexHint(-1), visited(0xffff) {} @@ -120,8 +120,42 @@ class QListViewPrivate; class QCommonListViewBase { public: - inline QCommonListViewBase(QListView *q, QListViewPrivate *d) : dd(d), qq(q) {} - + inline QCommonListViewBase(QListView *q, QListViewPrivate *d) : dd(d), qq(q), batchStartRow(0), batchSavedDeltaSeg(0) {} + virtual ~QCommonListViewBase() {} + + //common interface + virtual int itemIndex(const QListViewItem &item) const = 0; + virtual QListViewItem indexToListViewItem(const QModelIndex &index) const = 0; + virtual bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max) = 0; + virtual void clear() = 0; + virtual void setRowCount(int) = 0; + virtual QVector<QModelIndex> intersectingSet(const QRect &area) const = 0; + + virtual int horizontalScrollToValue(int index, QListView::ScrollHint hint, + bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const; + virtual int verticalScrollToValue(int index, QListView::ScrollHint hint, + bool above, bool below, const QRect &area, const QRect &rect) const; + virtual void scrollContentsBy(int dx, int dy, bool scrollElasticBand); + virtual QRect mapToViewport(const QRect &rect) const {return rect;} + virtual int horizontalOffset() const; + virtual int verticalOffset() const { return verticalScrollBar()->value(); } + virtual void updateHorizontalScrollBar(const QSize &step); + virtual void updateVerticalScrollBar(const QSize &step); + virtual void dataChanged(const QModelIndex &, const QModelIndex &) { } + virtual void appendHiddenRow(int row); + virtual void removeHiddenRow(int row); + virtual void setPositionForIndex(const QPoint &, const QModelIndex &) { } + +#ifndef QT_NO_DRAGANDDROP + virtual void paintDragDrop(QPainter *painter) = 0; + virtual bool filterDragMoveEvent(QDragMoveEvent *) { return false; } + virtual bool filterDragLeaveEvent(QDragLeaveEvent *) { return false; } + virtual bool filterDropEvent(QDropEvent *) { return false; } + virtual bool filterStartDrag(Qt::DropActions) { return false; } +#endif + + + //other inline members inline int spacing() const; inline bool isWrapping() const; inline QSize gridSize() const; @@ -133,8 +167,8 @@ public: inline bool uniformItemSizes() const; inline int column() const; - inline int verticalScrollBarValue() const; - inline int horizontalScrollBarValue() const; + inline QScrollBar *verticalScrollBar() const; + inline QScrollBar *horizontalScrollBar() const; inline QListView::ScrollMode verticalScrollMode() const; inline QListView::ScrollMode horizontalScrollMode() const; @@ -157,110 +191,107 @@ public: QListViewPrivate *dd; QListView *qq; + QSize contentsSize; + int batchStartRow; + int batchSavedDeltaSeg; }; -// ### rename to QListModeViewBase -class QStaticListViewBase : public QCommonListViewBase +class QListModeViewBase : public QCommonListViewBase { - friend class QListViewPrivate; public: - QStaticListViewBase(QListView *q, QListViewPrivate *d) : QCommonListViewBase(q, d), - batchStartRow(0), batchSavedDeltaSeg(0), batchSavedPosition(0) {} + QListModeViewBase(QListView *q, QListViewPrivate *d) : QCommonListViewBase(q, d) {} QVector<int> flowPositions; QVector<int> segmentPositions; QVector<int> segmentStartRows; QVector<int> segmentExtents; - QSize contentsSize; - // used when laying out in batches - int batchStartRow; - int batchSavedDeltaSeg; int batchSavedPosition; + //reimplementations + int itemIndex(const QListViewItem &item) const { return item.indexHint; } + QListViewItem indexToListViewItem(const QModelIndex &index) const; bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max); + void clear(); + void setRowCount(int rowCount) { flowPositions.resize(rowCount); } + QVector<QModelIndex> intersectingSet(const QRect &area) const; + + int horizontalScrollToValue(int index, QListView::ScrollHint hint, + bool leftOf, bool rightOf,const QRect &area, const QRect &rect) const; + int verticalScrollToValue(int index, QListView::ScrollHint hint, + bool above, bool below, const QRect &area, const QRect &rect) const; + void scrollContentsBy(int dx, int dy, bool scrollElasticBand); + QRect mapToViewport(const QRect &rect) const; + int horizontalOffset() const; + int verticalOffset() const; + void updateHorizontalScrollBar(const QSize &step); + void updateVerticalScrollBar(const QSize &step); + +#ifndef QT_NO_DRAGANDDROP + void paintDragDrop(QPainter *painter); +#endif +private: QPoint initStaticLayout(const QListViewLayoutInfo &info); void doStaticLayout(const QListViewLayoutInfo &info); - QVector<QModelIndex> intersectingStaticSet(const QRect &area) const; - - int itemIndex(const QListViewItem &item) const; - - int perItemScrollingPageSteps(int length, int bounds, bool wrap) const; - int perItemScrollToValue(int index, int value, int height, QAbstractItemView::ScrollHint hint, Qt::Orientation orientation, bool wrap, int extent) const; - - QRect mapToViewport(const QRect &rect) const; - - QListViewItem indexToListViewItem(const QModelIndex &index) const; - - void scrollContentsBy(int &dx, int &dy); - - int verticalPerItemValue(int itemIndex, int verticalValue, int areaHeight, - bool above, bool below, bool wrap, QListView::ScrollHint hint, int itemHeight) const; - int horizontalPerItemValue(int itemIndex, int horizontalValue, int areaWidth, - bool leftOf, bool rightOf, bool wrap, QListView::ScrollHint hint, int itemWidth) const; - - void clear(); + int perItemScrollingPageSteps(int length, int bounds, bool wrap) const; }; -// ### rename to QIconModeViewBase -class QDynamicListViewBase : public QCommonListViewBase +class QIconModeViewBase : public QCommonListViewBase { - friend class QListViewPrivate; public: - QDynamicListViewBase(QListView *q, QListViewPrivate *d) : QCommonListViewBase(q, d), - batchStartRow(0), batchSavedDeltaSeg(0), interSectingVector(0) {} + QIconModeViewBase(QListView *q, QListViewPrivate *d) : QCommonListViewBase(q, d), interSectingVector(0) {} QBspTree tree; QVector<QListViewItem> items; QBitArray moved; - QSize contentsSize; - QVector<QModelIndex> draggedItems; // indices to the tree.itemVector mutable QPoint draggedItemsPos; // used when laying out in batches - int batchStartRow; - int batchSavedDeltaSeg; - QVector<QModelIndex> *interSectingVector; //used from within intersectingDynamicSet + QVector<QModelIndex> *interSectingVector; //used from within intersectingSet - void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); + //reimplementations + int itemIndex(const QListViewItem &item) const; + QListViewItem indexToListViewItem(const QModelIndex &index) const; bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max); + void clear(); + void setRowCount(int rowCount); + QVector<QModelIndex> intersectingSet(const QRect &area) const; + + void scrollContentsBy(int dx, int dy, bool scrollElasticBand); + void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); + void appendHiddenRow(int row); + void removeHiddenRow(int row); + void setPositionForIndex(const QPoint &position, const QModelIndex &index); + +#ifndef QT_NO_DRAGANDDROP + void paintDragDrop(QPainter *painter); + bool filterDragMoveEvent(QDragMoveEvent *); + bool filterDragLeaveEvent(QDragLeaveEvent *); + bool filterDropEvent(QDropEvent *e); + bool filterStartDrag(Qt::DropActions); +#endif +private: void initBspTree(const QSize &contents); QPoint initDynamicLayout(const QListViewLayoutInfo &info); void doDynamicLayout(const QListViewLayoutInfo &info); - QVector<QModelIndex> intersectingDynamicSet(const QRect &area) const; - static void addLeaf(QVector<int> &leaf, const QRect &area, uint visited, QBspTree::Data data); - - void insertItem(int index); - void removeItem(int index); - void moveItem(int index, const QPoint &dest); - - int itemIndex(const QListViewItem &item) const; - - void createItems(int to); - void drawItems(QPainter *painter, const QVector<QModelIndex> &indexes) const; QRect itemsRect(const QVector<QModelIndex> &indexes) const; - - QPoint draggedItemsDelta() const; QRect draggedItemsRect() const; - QPoint snapToGrid(const QPoint &pos) const; - - void scrollElasticBandBy(int dx, int dy); - - QListViewItem indexToListViewItem(const QModelIndex &index) const; - - void clear(); void updateContentsSize(); + QPoint draggedItemsDelta() const; + void drawItems(QPainter *painter, const QVector<QModelIndex> &indexes) const; + void moveItem(int index, const QPoint &dest); + }; class QListViewPrivate: public QAbstractItemViewPrivate @@ -278,23 +309,13 @@ public: inline QVector<QModelIndex> intersectingSet(const QRect &area, bool doLayout = true) const { if (doLayout) executePostedLayout(); QRect a = (q_func()->isRightToLeft() ? flipX(area.normalized()) : area.normalized()); - return (viewMode == QListView::ListMode) ? staticListView->intersectingStaticSet(a) - : dynamicListView->intersectingDynamicSet(a); + return commonListView->intersectingSet(a); } - // ### FIXME: - inline void resetBatchStartRow() - { if (viewMode == QListView::ListMode) staticListView->batchStartRow = 0; - else dynamicListView->batchStartRow = 0; } - inline int batchStartRow() const - { return (viewMode == QListView::ListMode - ? staticListView->batchStartRow : dynamicListView->batchStartRow); } - inline QSize contentsSize() const - { return (viewMode == QListView::ListMode - ? staticListView->contentsSize : dynamicListView->contentsSize); } - inline void setContentsSize(int w, int h) - { if (viewMode == QListView::ListMode) staticListView->contentsSize = QSize(w, h); - else dynamicListView->contentsSize = QSize(w, h); } + inline void resetBatchStartRow() { commonListView->batchStartRow = 0; } + inline int batchStartRow() const { return commonListView->batchStartRow; } + inline QSize contentsSize() const { return commonListView->contentsSize; } + inline void setContentsSize(int w, int h) { commonListView->contentsSize = QSize(w, h); } inline int flipX(int x) const { return qMax(viewport->width(), contentsSize().width()) - x; } @@ -305,12 +326,22 @@ public: inline QRect viewItemRect(const QListViewItem &item) const { if (q_func()->isRightToLeft()) return flipX(item.rect()); return item.rect(); } - int itemIndex(const QListViewItem &item) const; QListViewItem indexToListViewItem(const QModelIndex &index) const; inline QModelIndex listViewItemToIndex(const QListViewItem &item) const - { return model->index(itemIndex(item), column, root); } + { return model->index(commonListView->itemIndex(item), column, root); } + + QRect rectForIndex(const QModelIndex &index) const + { + if (!isIndexValid(index) || index.parent() != root || index.column() != column || isHidden(index.row())) + return QRect(); + executePostedLayout(); + return viewItemRect(indexToListViewItem(index)); + } + + void viewUpdateGeometries() { q_func()->updateGeometries(); } - QRect mapToViewport(const QRect &rect, bool greedy = false) const; + + QRect mapToViewport(const QRect &rect, bool extend = true) const; QModelIndex closestIndex(const QRect &target, const QVector<QModelIndex> &candidates) const; QSize itemSize(const QStyleOptionViewItem &option, const QModelIndex &index) const; @@ -351,10 +382,10 @@ public: QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const; - union { - QDynamicListViewBase *dynamicListView; - QStaticListViewBase *staticListView; - }; + void emitIndexesMoved(const QModelIndexList &indexes) { emit q_func()->indexesMoved(indexes); } + + + QCommonListViewBase *commonListView; // ### FIXME: see if we can move the members into the dynamic/static classes @@ -412,8 +443,8 @@ inline QPoint QCommonListViewBase::pressedPosition() const { return dd->pressedP inline bool QCommonListViewBase::uniformItemSizes() const { return dd->uniformItemSizes; } inline int QCommonListViewBase::column() const { return dd->column; } -inline int QCommonListViewBase::verticalScrollBarValue() const { return qq->verticalScrollBar()->value(); } -inline int QCommonListViewBase::horizontalScrollBarValue() const { return qq->horizontalScrollBar()->value(); } +inline QScrollBar *QCommonListViewBase::verticalScrollBar() const { return qq->verticalScrollBar(); } +inline QScrollBar *QCommonListViewBase::horizontalScrollBar() const { return qq->horizontalScrollBar(); } inline QListView::ScrollMode QCommonListViewBase::verticalScrollMode() const { return qq->verticalScrollMode(); } inline QListView::ScrollMode QCommonListViewBase::horizontalScrollMode() const { return qq->horizontalScrollMode(); } diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 574d845..ccf6ac9 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -101,6 +101,10 @@ extern bool qt_wince_is_pocket_pc(); //qguifunctions_wince.cpp #include "qdatetime.h" +#ifdef QT_MAC_USE_COCOA +#include <private/qt_cocoa_helpers_mac_p.h> +#endif + //#define ALIEN_DEBUG static void initResources() @@ -3477,6 +3481,15 @@ void QApplication::changeOverrideCursor(const QCursor &cursor) if (qApp->d_func()->cursor_list.isEmpty()) return; qApp->d_func()->cursor_list.removeFirst(); +#ifdef QT_MAC_USE_COCOA + // We use native NSCursor stacks in Cocoa. The currentCursor is the + // top of this stack. So to avoid flickering of cursor, we have to + // change the cusor instead of pop-ing the existing OverrideCursor + // and pushing the new one. + qApp->d_func()->cursor_list.prepend(cursor); + qt_cocoaChangeOverrideCursor(cursor); + return; +#endif setOverrideCursor(cursor); } #endif diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp index d942519..0d07a02 100644 --- a/src/gui/kernel/qapplication_x11.cpp +++ b/src/gui/kernel/qapplication_x11.cpp @@ -4572,6 +4572,7 @@ bool QETWidget::translateXinputEvent(const XEvent *ev, QTabletDeviceData *tablet int deviceType = QTabletEvent::NoDevice; int pointerType = QTabletEvent::UnknownPointer; XEvent mouseMotionEvent; + XEvent dummy; const XDeviceMotionEvent *motion = 0; XDeviceButtonEvent *button = 0; const XProximityNotifyEvent *proximity = 0; @@ -4589,7 +4590,6 @@ bool QETWidget::translateXinputEvent(const XEvent *ev, QTabletDeviceData *tablet // Do event compression. Skip over tablet+mouse move events if there are newer ones. qt_tablet_motion_data tabletMotionData; tabletMotionData.tabletMotionType = tablet->xinput_motion; - XEvent dummy; while (true) { // Find first mouse event since we expect them in pairs inside Qt tabletMotionData.error =false; diff --git a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm index 572df70..172d07b 100644 --- a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm +++ b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm @@ -197,11 +197,19 @@ static void cleanupCocoaApplicationDelegate() } } - // Prevent Cocoa from terminating the application, since this simply - // exits the program whithout allowing QApplication::exec() to return. - // The call to QApplication::quit() above will instead quit the - // application from the Qt side. - return NSTerminateCancel; + if (qtPrivate->threadData->eventLoops.size() == 0) { + // INVARIANT: No event loop is executing. This probably + // means that Qt is used as a plugin, or as a part of a native + // Cocoa application. In any case it should be fine to + // terminate now: + return NSTerminateNow; + } else { + // Prevent Cocoa from terminating the application, since this simply + // exits the program whithout allowing QApplication::exec() to return. + // The call to QApplication::quit() above will instead quit the + // application from the Qt side. + return NSTerminateCancel; + } } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index 7ac0d89..5a0209d 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -667,7 +667,15 @@ extern "C" { - (void)mouseMoved:(NSEvent *)theEvent { - qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); + // We always enable mouse tracking for all QCocoaView-s. In cases where we have + // child views, we will receive mouseMoved for both parent & the child (if + // mouse is over the child). We need to ignore the parent mouseMoved in such + // cases. + NSPoint windowPoint = [theEvent locationInWindow]; + NSView *candidateView = [[[self window] contentView] hitTest:windowPoint]; + if (candidateView && candidateView == self) { + qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); + } } - (void)mouseDown:(NSEvent *)theEvent diff --git a/src/gui/kernel/qdnd_x11.cpp b/src/gui/kernel/qdnd_x11.cpp index a4042c1..8f92fea 100644 --- a/src/gui/kernel/qdnd_x11.cpp +++ b/src/gui/kernel/qdnd_x11.cpp @@ -1073,12 +1073,14 @@ void qt_xdnd_send_leave() if (!qt_xdnd_current_target) return; + QDragManager *manager = QDragManager::self(); + XClientMessageEvent leave; leave.type = ClientMessage; leave.window = qt_xdnd_current_target; leave.format = 32; leave.message_type = ATOM(XdndLeave); - leave.data.l[0] = qt_xdnd_dragsource_xid; + leave.data.l[0] = manager->dragPrivate()->source->effectiveWinId(); leave.data.l[1] = 0; // flags leave.data.l[2] = 0; // x, y leave.data.l[3] = 0; // w, h @@ -1094,8 +1096,8 @@ void qt_xdnd_send_leave() else XSendEvent(X11->display, qt_xdnd_current_proxy_target, False, NoEventMask, (XEvent*)&leave); + // reset the drag manager state - QDragManager *manager = QDragManager::self(); manager->willDrop = false; if (global_accepted_action != Qt::IgnoreAction) manager->emitActionChanged(Qt::IgnoreAction); diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 7365820..3e1d12d 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3538,38 +3538,108 @@ QMenubarUpdatedEvent::QMenubarUpdatedEvent(QMenuBar * const menuBar) \since 4.6 \ingroup events - Touch events occur when pressing, releasing, or moving one or more - touch points on a touch device (such as a touch-screen or - track-pad). To receive touch events, widgets have to have the - Qt::WA_AcceptTouchEvents attribute set and graphics items need to have - the \l{QGraphicsItem::setAcceptTouchEvents()}{acceptTouchEvents} - attribute set to true. - - All touch events are of type QEvent::TouchBegin, - QEvent::TouchUpdate, or QEvent::TouchEnd. The touchPoints() - function returns a list of all touch points contained in the event. - Information about each touch point can be retrieved using the - QTouchEvent::TouchPoint class. The Qt::TouchPointState enum - describes the different states that a touch point may have. - - Similar to QMouseEvent, Qt automatically grabs each touch point on - the first press inside a widget; the widget will receive all - updates for the touch point until it is released. Note that it is - possible for a widget to receive events for multiple touch points, - and that multiple widgets may be receiving touch events at the same - time. - - A touch event contains a special accept flag that indicates - whether the receiver wants the event. By default, the event is - accepted. You should call ignore() if the touch event is not handled by - your widget. A QEvent::TouchBegin event is propagated up the parent widget - chain until a widget accepts it with accept(), or an event filter - consumes it. If the QEvent::TouchBegin event is neither accepted nor consumed, - then mouse events are simulated from the state of the first touch - point. - - Reimplement QWidget::event() for widgets and QGraphicsItem::sceneEvent() - for items in a graphics view to receive touch events. + \section1 Enabling Touch Events + + Touch events occur when pressing, releasing, or moving one or more touch points on a touch + device (such as a touch-screen or track-pad). To receive touch events, widgets have to have the + Qt::WA_AcceptTouchEvents attribute set and graphics items need to have the + \l{QGraphicsItem::setAcceptTouchEvents()}{acceptTouchEvents} attribute set to true. + + Note: when using QAbstractScrollArea based widgets, you should enabled the + Qt::WA_AcceptTouchEvents attribute on the scroll area's + \l{QAbstractScrollArea::viewport()}{viewport}. + + \section1 Event Delivery and Propagation + + All touch events are of type QEvent::TouchBegin, QEvent::TouchUpdate, or QEvent::TouchEnd. + Reimplement QWidget::event() or QAbstractScrollArea::viewportEvent() for widgets and + QGraphicsItem::sceneEvent() for items in a graphics view to receive touch events. By default, + QWidget::event() translates the first non-primary touch point in a QTouchEvent into a + QMouseEvent. This makes it possible to enable touch events on existing widgets that do not + normally handle QTouchEvent. See below for information on some special considerations needed + when doing this. + + QEvent::TouchBegin is the first touch event sent to a widget. The QEvent::TouchBegin event + contains a special accept flag that indicates whether the receiver wants the event. By default, + the event is accepted. You should call ignore() if the touch event is not handled by your + widget. The QEvent::TouchBegin event is propagated up the parent widget chain until a widget + accepts it with accept(), or an event filter consumes it. For QGraphicsItems, the + QEvent::TouchBegin event is propagated to items under the mouse (similar to mouse event + propagation for QGraphicsItems). + + The QEvent::TouchUpdate and QEvent::TouchEnd events are sent to the widget or item that + accepted the QEvent::TouchBegin event. If the QEvent::TouchBegin event is not accepted and not + filtered by an event filter, then no further touch events are sent until the next + QEvent::TouchBegin. + + The touchPoints() function returns a list of all touch points contained in the event. + Information about each touch point can be retrieved using the QTouchEvent::TouchPoint class. + The Qt::TouchPointState enum describes the different states that a touch point may have. + + Similar to QMouseEvent, Qt automatically grabs each touch point on the first press inside a + widget; the widget will receive all updates for the touch point until it is released. Note that + it is possible for a widget to receive events for multiple touch points, and that multiple + widgets may be receiving touch events at the same time. + + \section1 Touch Point Grouping + + As mentioned above, it is possible that several widgets can be receiving QTouchEvents at the + same time. However, Qt makes sure to never send duplicate QEvent::TouchBegin events to the same + widget, which could theoretically happen during propagation if, for example, the user touched 2 + separate widgets in a QGroupBox and both widgets ignored the QEvent::TouchBegin event. + + To avoid this, Qt will group new touch points together using the following rules: + + \list + + \i When the first touch point is detected, the destination widget is determined firstly by the + location on screen first and secondly by the propagation rules. + + \i When additional touch points are detected, Qt first looks to see if there are any active + touch points on any ancestor or descendent of the widget under the new touch point. If there + are, the new touch point is grouped with the first, and the new touch point will be sent in a + single QTouchEvent to the widget that handled the first touch point. (The widget under the new + touch point will not receive an event). + + \endlist + + This makes it possible for sibling widgets to handle touch events independently while making + sure that the sequence of QTouchEvents is always correct. + + \section1 Mouse Events and the Primary Touch Point + + QTouchEvent delivery is independent from that of QMouseEvent. On some windowing systems, mouse + events are also sent for the \l{QTouchEvent::TouchPoint::isPrimary()}{primary touch point}. + This means it is possible for your widget to receive both QTouchEvent and QMouseEvent for the + same user interaction point. You can use the QTouchEvent::TouchPoint::isPrimary() function to + identify the primary touch point. + + Note that on some systems, it is possible to receive touch events without a primary touch + point. All this means is that there will be no mouse event generated for the touch points in + the QTouchEvent. + + \section1 Caveats + + \list + + \i As mentioned above, enabling touch events means multiple widgets can be receiving touch + events simultaneously. Combined with the default QWidget::event() handling for QTouchEvents, + this gives you great flexibility in designing multi-touch user interfaces. Be aware of the + implications. For example, is is possible that the user is moving a QSlider with one finger and + pressing a QPushButton with another. The signals are emitted from these widgets will be + interleaved. + + \i Recursion into the event loop using one of the exec() methods (e.g. QDialog::exec() or + QMenu::exec()) in a QTouchEvent event handler is not supported. Since there are multiple event + recipients, unexpected recursion may cause problems, including but not limited to lost events + and unexpected infinite recursion. + + \i QTouchEvents are not affected by a \l{QWidget::grabMouse()}{mouse grab} or an + \l{QApplication::activePopupWidget()}{active popup widget}. The behavior of QTouchEvents is + undefined when opening a popup or grabbing the mouse while there are multiple active touch + points. + + \endlist \sa QTouchEvent::TouchPoint, Qt::TouchPointState, Qt::WA_AcceptTouchEvents, QGraphicsItem::acceptTouchEvents() @@ -3648,6 +3718,11 @@ QTouchEvent::~QTouchEvent() Returns the list of touch points contained in the touch event. */ +/*! \fn QTouchEvent::DeviceType QTouchEvent::deviceType() const + + Returns the touch device Type, which is of type \l {QTouchEvent::DeviceType} {DeviceType}. +*/ + /*! \fn void QTouchEvent::setWidget(QWidget *widget) \internal @@ -3669,6 +3744,14 @@ QTouchEvent::~QTouchEvent() Sets the list of touch points for this event. */ +/*! \fn void QTouchEvent::setDeviceType(DeviceType deviceType) + + \internal + + Sets the device type to \a deviceType, which is of type \l {QTouchEvent::DeviceType} + {DeviceType}. +*/ + /*! \class QTouchEvent::TouchPoint \brief The QTouchEvent::TouchPoint class provides information about a touch point in a QTouchEvent. \since 4.6 @@ -4080,15 +4163,4 @@ QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::T return *this; } -/*! \fn QTouchEvent::DeviceType QTouchEvent::deviceType() const - Returns the touch device Type, which is of type - \l {QTouchEvent::DeviceType} {DeviceType}. - */ - -/*! \fn void QTouchEvent::setDeviceType(DeviceType deviceType) - Sets the device type to \a deviceType, which is of type - \l {QTouchEvent::DeviceType} {DeviceType}. - */ - - QT_END_NAMESPACE diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp index c965bac..0027deb 100644 --- a/src/gui/kernel/qshortcutmap.cpp +++ b/src/gui/kernel/qshortcutmap.cpp @@ -99,11 +99,11 @@ struct QShortcutEntry QObject *owner; }; -#ifndef QT_NO_DEBUG_STREAM +#if 0 //ndef QT_NO_DEBUG_STREAM /*! \internal QDebug operator<< for easy debug output of the shortcut entries. */ -QDebug &operator<<(QDebug &dbg, const QShortcutEntry *se) { +static QDebug &operator<<(QDebug &dbg, const QShortcutEntry *se) { if (!se) return dbg << "QShortcutEntry(0x0)"; dbg.nospace() diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index 47f3146..10689ba 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -172,8 +172,6 @@ bool QPanGesture::eventFilter(QObject *receiver, QEvent *event) bool QPanGesture::filterEvent(QEvent *event) { Q_D(QPanGesture); - if (!event->spontaneous()) - return false; const QTouchEvent *ev = static_cast<const QTouchEvent*>(event); if (event->type() == QEvent::TouchBegin) { QTouchEvent::TouchPoint p = ev->touchPoints().at(0); @@ -329,10 +327,11 @@ bool QPinchGesture::event(QEvent *event) bool QPinchGesture::eventFilter(QObject *receiver, QEvent *event) { -#ifdef Q_WS_WIN +#if defined(Q_WS_WIN) || defined(Q_WS_MAC) Q_D(QPinchGesture); if (receiver->isWidgetType() && event->type() == QEvent::NativeGesture) { QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event); +#if defined(Q_WS_WIN) QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); QApplicationPrivate::WidgetStandardGesturesMap::iterator it; it = qAppPriv->widgetGestures.find(static_cast<QWidget*>(receiver)); @@ -340,7 +339,9 @@ bool QPinchGesture::eventFilter(QObject *receiver, QEvent *event) return false; if (this != it.value().pinch) return false; +#endif Qt::GestureState nextState = Qt::NoGesture; + switch(ev->gestureType) { case QNativeGestureEvent::GestureBegin: // next we might receive the first gesture update event, so we @@ -349,15 +350,22 @@ bool QPinchGesture::eventFilter(QObject *receiver, QEvent *event) d->scaleFactor = d->lastScaleFactor = 1; d->rotationAngle = d->lastRotationAngle = 0; d->startCenterPoint = d->centerPoint = d->lastCenterPoint = QPoint(); +#if defined(Q_WS_WIN) d->initialDistance = 0; +#endif return false; case QNativeGestureEvent::Rotate: d->lastRotationAngle = d->rotationAngle; +#if defined(Q_WS_WIN) d->rotationAngle = -1 * GID_ROTATE_ANGLE_FROM_ARGUMENT(ev->argument); +#elif defined(Q_WS_MAC) + d->rotationAngle = ev->percentage; +#endif nextState = Qt::GestureUpdated; event->accept(); break; case QNativeGestureEvent::Zoom: +#if defined(Q_WS_WIN) if (d->initialDistance != 0) { d->lastScaleFactor = d->scaleFactor; int distance = int(qint64(ev->argument)); @@ -365,6 +373,10 @@ bool QPinchGesture::eventFilter(QObject *receiver, QEvent *event) } else { d->initialDistance = int(qint64(ev->argument)); } +#elif defined(Q_WS_MAC) + d->lastScaleFactor = d->scaleFactor; + d->scaleFactor = ev->percentage; +#endif nextState = Qt::GestureUpdated; event->accept(); break; diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm index 7596802..a9b8970 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac.mm +++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm @@ -1238,4 +1238,12 @@ void qt_mac_menu_collapseSeparators(void */*NSMenu **/ theMenu, bool collapse) } } +#ifdef QT_MAC_USE_COCOA +void qt_cocoaChangeOverrideCursor(const QCursor &cursor) +{ + QMacCocoaAutoReleasePool pool; + [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(cursor)) set]; +} +#endif + QT_END_NAMESPACE diff --git a/src/gui/kernel/qt_cocoa_helpers_mac_p.h b/src/gui/kernel/qt_cocoa_helpers_mac_p.h index 24d7096..932abef 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac_p.h +++ b/src/gui/kernel/qt_cocoa_helpers_mac_p.h @@ -133,6 +133,7 @@ bool qt_mac_checkForNativeSizeGrip(const QWidget *widget); void qt_dispatchTabletProximityEvent(void * /*NSEvent * */ tabletEvent); #ifdef QT_MAC_USE_COCOA bool qt_dispatchKeyEventWithCocoa(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent); +void qt_cocoaChangeOverrideCursor(const QCursor &cursor); #endif void qt_mac_menu_collapseSeparators(void * /*NSMenu */ menu, bool collapse); bool qt_dispatchKeyEvent(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent); diff --git a/src/gui/kernel/qt_mac.cpp b/src/gui/kernel/qt_mac.cpp index 642aa5c..bef3449 100644 --- a/src/gui/kernel/qt_mac.cpp +++ b/src/gui/kernel/qt_mac.cpp @@ -1,11 +1,11 @@ /**************************************************************************** - ** - ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Nokia Corporation (qt-info@nokia.com) - ** - ** This file is part of the QtGui module of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:LGPL$ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions @@ -36,11 +36,8 @@ ** If you are unsure which license is appropriate for your use, please ** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ - ** - ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - ** - ****************************************************************************/ +** +****************************************************************************/ #include <private/qt_mac_p.h> #include <private/qpixmap_mac_p.h> diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 999faeb..71571e4 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -1055,7 +1055,7 @@ OSStatus QWidgetPrivate::qt_window_event(EventHandlerCallRef er, EventRef event, handled_event = false; break; } - qNGEvent.gestureType = QNativeGestureEvent::Zoom; + qNGEvent.gestureType = QNativeGestureEvent::Rotate; qNGEvent.percentage = float(amount); break; } case kEventGestureSwipe: { diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp index 77ab590..ea334b6 100644 --- a/src/gui/kernel/qwidget_win.cpp +++ b/src/gui/kernel/qwidget_win.cpp @@ -2060,8 +2060,6 @@ void QWidgetPrivate::winSetupGestures() Q_Q(QWidget); if (!q) return; - q->setAttribute(Qt::WA_DontCreateNativeAncestors); - q->setAttribute(Qt::WA_NativeWindow); if (!q->isVisible()) return; QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index 8fc439b..ed0802b 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -1438,18 +1438,59 @@ QMatrix QMatrix4x4::toAffine() const qreal(m[3][0]), qreal(m[3][1])); } +static const qreal inv_dist_to_plane = 1. / 1024.; + /*! Returns the conventional Qt 2D transformation matrix that - corresponds to this matrix. It is assumed that this matrix - only contains 2D transformation elements. + corresponds to this matrix. + + If \a distanceToPlane is non-zero, it indicates a projection + factor to use to adjust for the z co-ordinate. The default + value of 1024 corresponds to the projection factor used + by QTransform::rotate() for the x and y axes. + + If \a distToPlane is zero, then the returned QTransform + is formed by simply dropping the third row and third column + of the QMatrix4x4. This is suitable for implementing + orthographic projections where the z co-ordinate should + be dropped rather than projected. \sa toAffine() */ -QTransform QMatrix4x4::toTransform() const +QTransform QMatrix4x4::toTransform(qreal distanceToPlane) const { - return QTransform(qreal(m[0][0]), qreal(m[0][1]), qreal(m[0][3]), - qreal(m[1][0]), qreal(m[1][1]), qreal(m[1][3]), - qreal(m[3][0]), qreal(m[3][1]), qreal(m[3][3])); + if (distanceToPlane == 1024.0f) { + // Optimize the common case with constants. + return QTransform(qreal(m[0][0]), qreal(m[0][1]), + qreal(m[0][3]) - qreal(m[0][2]) * + inv_dist_to_plane, + qreal(m[1][0]), qreal(m[1][1]), + qreal(m[1][3]) - qreal(m[1][2]) * + inv_dist_to_plane, + qreal(m[3][0]), qreal(m[3][1]), + qreal(m[3][3]) - qreal(m[3][2]) * + inv_dist_to_plane); + } else if (distanceToPlane != 0.0f) { + // The following projection matrix is pre-multiplied with "matrix": + // | 1 0 0 0 | + // | 0 1 0 0 | + // | 0 0 1 0 | + // | 0 0 d 1 | + // where d = -1 / distanceToPlane. After projection, row 3 and + // column 3 are dropped to form the final QTransform. + qreal d = 1.0f / distanceToPlane; + return QTransform(qreal(m[0][0]), qreal(m[0][1]), + qreal(m[0][3]) - qreal(m[0][2]) * d, + qreal(m[1][0]), qreal(m[1][1]), + qreal(m[1][3]) - qreal(m[1][2]) * d, + qreal(m[3][0]), qreal(m[3][1]), + qreal(m[3][3]) - qreal(m[3][2]) * d); + } else { + // Orthographic projection: drop row 3 and column 3. + return QTransform(qreal(m[0][0]), qreal(m[0][1]), qreal(m[0][3]), + qreal(m[1][0]), qreal(m[1][1]), qreal(m[1][3]), + qreal(m[3][0]), qreal(m[3][1]), qreal(m[3][3])); + } } /*! diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h index b02608d..04a4216 100644 --- a/src/gui/math3d/qmatrix4x4.h +++ b/src/gui/math3d/qmatrix4x4.h @@ -158,7 +158,7 @@ public: void toValueArray(qreal *values) const; QMatrix toAffine() const; - QTransform toTransform() const; + QTransform toTransform(qreal distanceToPlane = 1024.0f) const; QPoint map(const QPoint& point) const; QPointF map(const QPointF& point) const; diff --git a/src/gui/styles/gtksymbols.cpp b/src/gui/styles/gtksymbols.cpp index 51f40e3..6a5ea49 100644 --- a/src/gui/styles/gtksymbols.cpp +++ b/src/gui/styles/gtksymbols.cpp @@ -642,7 +642,7 @@ GtkStyle* QGtk::gtkStyle(const QString &path) return 0; } -static void update_toolbar_style(GtkWidget *gtkToolBar, GParamSpec *pspec, gpointer user_data) +static void update_toolbar_style(GtkWidget *gtkToolBar, GParamSpec *, gpointer) { GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS; g_object_get(gtkToolBar, "toolbar-style", &toolbar_style, NULL); diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index 533ef46..e7aeed0 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -63,10 +63,10 @@ QT_BEGIN_NAMESPACE // The VxWorks DIAB compiler crashes when initializing the anonymouse union with { a7 } #if !defined(Q_CC_DIAB) # define QT_INIT_TEXTUNDOCOMMAND(c, a1, a2, a3, a4, a5, a6, a7, a8) \ - QTextUndoCommand c = { a1, a2, a3, a4, a5, a6, { a7 }, a8 } + QTextUndoCommand c = { a1, a2, 0, 0, a3, a4, a5, a6, { a7 }, a8 } #else # define QT_INIT_TEXTUNDOCOMMAND(c, a1, a2, a3, a4, a5, a6, a7, a8) \ - QTextUndoCommand c = { a1, a2, a3, a4, a5, a6 }; c.blockFormat = a7; c.revision = a8 + QTextUndoCommand c = { a1, a2, 0, 0, a3, a4, a5, a6 }; c.blockFormat = a7; c.revision = a8 #endif /* @@ -961,14 +961,18 @@ int QTextDocumentPrivate::undoRedo(bool undo) B->revision = c.revision; } - if (undo) { - if (undoState == 0 || !undoStack[undoState-1].block) - break; - } else { + if (!undo) ++undoState; - if (undoState == undoStack.size() || !undoStack[undoState-1].block) - break; - } + + bool inBlock = ( + undoState > 0 + && undoState < undoStack.size() + && undoStack[undoState].block_part + && undoStack[undoState-1].block_part + && !undoStack[undoState-1].block_end + ); + if (!inBlock) + break; } undoEnabled = true; int editPos = -1; @@ -993,7 +997,8 @@ void QTextDocumentPrivate::appendUndoItem(QAbstractUndoItem *item) QTextUndoCommand c; c.command = QTextUndoCommand::Custom; - c.block = editBlock != 0; + c.block_part = editBlock != 0; + c.block_end = 0; c.operation = QTextUndoCommand::MoveCursor; c.format = 0; c.strPos = 0; @@ -1014,9 +1019,10 @@ void QTextDocumentPrivate::appendUndoItem(const QTextUndoCommand &c) if (!undoStack.isEmpty() && modified) { QTextUndoCommand &last = undoStack[undoState - 1]; - if ( (last.block && c.block) // part of the same block => can merge - || (!c.block && !last.block // two single undo items => can merge - && (undoState < 2 || !undoStack[undoState-2].block))) { + + if ( (last.block_part && c.block_part && !last.block_end) // part of the same block => can merge + || (!c.block_part && !last.block_part)) { // two single undo items => can merge + if (last.tryMerge(c)) return; } @@ -1028,7 +1034,7 @@ void QTextDocumentPrivate::appendUndoItem(const QTextUndoCommand &c) emitUndoAvailable(true); emitRedoAvailable(false); - if (!c.block) + if (!c.block_part) emit document()->undoCommandAdded(); } @@ -1094,7 +1100,7 @@ void QTextDocumentPrivate::joinPreviousEditBlock() beginEditBlock(); if (undoEnabled && undoState) - undoStack[undoState - 1].block = true; + undoStack[undoState - 1].block_end = false; } void QTextDocumentPrivate::endEditBlock() @@ -1103,10 +1109,10 @@ void QTextDocumentPrivate::endEditBlock() return; if (undoEnabled && undoState > 0) { - const bool wasBlocking = undoStack[undoState - 1].block; - undoStack[undoState - 1].block = false; - if (wasBlocking) + if (undoStack[undoState - 1].block_part) { + undoStack[undoState - 1].block_end = true; emit document()->undoCommandAdded(); + } } finishEdit(); diff --git a/src/gui/text/qtextdocument_p.h b/src/gui/text/qtextdocument_p.h index 55aa17e..363309c 100644 --- a/src/gui/text/qtextdocument_p.h +++ b/src/gui/text/qtextdocument_p.h @@ -139,7 +139,9 @@ public: MoveCursor = 1 }; quint16 command; - quint8 block; ///< All undo commands that have this set to true are combined with the preceding command on undo/redo. + uint block_part : 1; // all commands that are part of an undo block (including the first and the last one) have this set to 1 + uint block_end : 1; // the last command in an undo block has this set to 1. + uint block_padding : 6; // padding since block used to be a quint8 quint8 operation; int format; quint32 strPos; diff --git a/src/gui/widgets/qdatetimeedit.cpp b/src/gui/widgets/qdatetimeedit.cpp index 0fca0b7..7eb9eb5 100644 --- a/src/gui/widgets/qdatetimeedit.cpp +++ b/src/gui/widgets/qdatetimeedit.cpp @@ -1,4 +1,4 @@ -/****************************************************************************) +/**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Nokia Corporation (qt-info@nokia.com) diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp index b88cd9ae..56cc828 100644 --- a/src/gui/widgets/qlineedit.cpp +++ b/src/gui/widgets/qlineedit.cpp @@ -1388,6 +1388,7 @@ bool QLineEdit::event(QEvent * e) if (QApplication::keypadNavigationEnabled()) { if (e->type() == QEvent::EnterEditFocus) { end(false); + d->setCursorVisible(true); int cft = QApplication::cursorFlashTime(); d->control->setCursorBlinkPeriod(cft/2); } else if (e->type() == QEvent::LeaveEditFocus) { @@ -1396,7 +1397,6 @@ bool QLineEdit::event(QEvent * e) if (d->control->hasAcceptableInput() || d->control->fixup()) emit editingFinished(); } - return true; } #endif return QWidget::event(e); diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index e19961f..ebf01d4 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -1027,6 +1027,8 @@ void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget Restores the state of \a dockwidget if it is created after the call to restoreState(). Returns true if the state was restored; otherwise returns false. + + \sa restoreState(), saveState() */ bool QMainWindow::restoreDockWidget(QDockWidget *dockwidget) @@ -1158,6 +1160,11 @@ Qt::DockWidgetArea QMainWindow::dockWidgetArea(QDockWidget *dockwidget) const To restore the saved state, pass the return value and \a version number to restoreState(). + To save the geometry when the window closes, you can + implement a close event like this: + + \snippet doc/src/snippets/code/src_gui_widgets_qmainwindow.cpp 0 + \sa restoreState(), QWidget::saveGeometry(), QWidget::restoreGeometry() */ QByteArray QMainWindow::saveState(int version) const @@ -1177,7 +1184,13 @@ QByteArray QMainWindow::saveState(int version) const unchanged, and this function returns \c false; otherwise, the state is restored, and this function returns \c true. - \sa saveState(), QWidget::saveGeometry(), QWidget::restoreGeometry() + To restore geometry saved using QSettings, you can use code like + this: + + \snippet doc/src/snippets/code/src_gui_widgets_qmainwindow.cpp 1 + + \sa saveState(), QWidget::saveGeometry(), + QWidget::restoreGeometry(), restoreDockWidget() */ bool QMainWindow::restoreState(const QByteArray &state, int version) { diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index bf2d58a..397e0b5 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -65,19 +65,37 @@ QT_BEGIN_NAMESPACE -const int QHttpNetworkConnectionPrivate::channelCount = 6; +const int QHttpNetworkConnectionPrivate::defaultChannelCount = 6; + +// the maximum amount of requests that might be pipelined into a socket +// from what was suggested, 3 seems to be OK +const int QHttpNetworkConnectionPrivate::defaultPipelineLength = 3; + QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(const QString &hostName, quint16 port, bool encrypt) : hostName(hostName), port(port), encrypt(encrypt), + channelCount(defaultChannelCount), pendingAuthSignal(false), pendingProxyAuthSignal(false) #ifndef QT_NO_NETWORKPROXY , networkProxy(QNetworkProxy::NoProxy) #endif +{ + channels = new QHttpNetworkConnectionChannel[channelCount]; +} +QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(quint16 channelCount, const QString &hostName, quint16 port, bool encrypt) +: hostName(hostName), port(port), encrypt(encrypt), + channelCount(channelCount), + pendingAuthSignal(false), pendingProxyAuthSignal(false) +#ifndef QT_NO_NETWORKPROXY + , networkProxy(QNetworkProxy::NoProxy) +#endif { channels = new QHttpNetworkConnectionChannel[channelCount]; } + + QHttpNetworkConnectionPrivate::~QHttpNetworkConnectionPrivate() { for (int i = 0; i < channelCount; ++i) { @@ -139,17 +157,6 @@ qint64 QHttpNetworkConnectionPrivate::uncompressedBytesAvailableNextBlock(const return reply.d_func()->responseData.sizeNextBlock(); } -qint64 QHttpNetworkConnectionPrivate::compressedBytesAvailable(const QHttpNetworkReply &reply) const -{ - return reply.d_func()->compressedData.size(); -} - -void QHttpNetworkConnectionPrivate::eraseData(QHttpNetworkReply *reply) -{ - reply->d_func()->compressedData.clear(); - reply->d_func()->responseData.clear(); -} - void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair) { QHttpNetworkRequest &request = messagePair.first; @@ -223,231 +230,8 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair) reply->d_func()->requestIsPrepared = true; } -bool QHttpNetworkConnectionPrivate::ensureConnection(QAbstractSocket *socket) -{ - // make sure that this socket is in a connected state, if not initiate - // connection to the host. - if (socket->state() != QAbstractSocket::ConnectedState) { - // connect to the host if not already connected. - int index = indexOf(socket); - // resend this request after we receive the disconnected signal - if (socket->state() == QAbstractSocket::ClosingState) { - channels[index].resendCurrent = true; - return false; - } - channels[index].state = QHttpNetworkConnectionChannel::ConnectingState; - channels[index].pendingEncrypt = encrypt; - - // This workaround is needed since we use QAuthenticator for NTLM authentication. The "phase == Done" - // is the usual criteria for emitting authentication signals. The "phase" is set to "Done" when the - // last header for Authorization is generated by the QAuthenticator. Basic & Digest logic does not - // check the "phase" for generating the Authorization header. NTLM authentication is a two stage - // process & needs the "phase". To make sure the QAuthenticator uses the current username/password - // the phase is reset to Start. - QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(channels[index].authenticator); - if (priv && priv->phase == QAuthenticatorPrivate::Done) - priv->phase = QAuthenticatorPrivate::Start; - priv = QAuthenticatorPrivate::getPrivate(channels[index].proxyAuthenticator); - if (priv && priv->phase == QAuthenticatorPrivate::Done) - priv->phase = QAuthenticatorPrivate::Start; - - QString connectHost = hostName; - qint16 connectPort = port; - -#ifndef QT_NO_NETWORKPROXY - // HTTPS always use transparent proxy. - if (networkProxy.type() != QNetworkProxy::NoProxy && !encrypt) { - connectHost = networkProxy.hostName(); - connectPort = networkProxy.port(); - } -#endif - if (encrypt) { -#ifndef QT_NO_OPENSSL - QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket); - sslSocket->connectToHostEncrypted(connectHost, connectPort); - if (channels[index].ignoreAllSslErrors) - sslSocket->ignoreSslErrors(); - sslSocket->ignoreSslErrors(channels[index].ignoreSslErrorsList); -#else - emitReplyError(socket, channels[index].reply, QNetworkReply::ProtocolUnknownError); -#endif - } else { - socket->connectToHost(connectHost, connectPort); - } - return false; - } - return true; -} - -bool QHttpNetworkConnectionPrivate::sendRequest(QAbstractSocket *socket) -{ - Q_Q(QHttpNetworkConnection); - int i = indexOf(socket); - switch (channels[i].state) { - case QHttpNetworkConnectionChannel::IdleState: { // write the header - if (!ensureConnection(socket)) { - // wait for the connection (and encryption) to be done - // sendRequest will be called again from either - // _q_connected or _q_encrypted - return false; - } - channels[i].written = 0; // excluding the header - channels[i].bytesTotal = 0; - if (channels[i].reply) { - channels[i].reply->d_func()->clear(); - channels[i].reply->d_func()->connection = q; - channels[i].reply->d_func()->autoDecompress = channels[i].request.d->autoDecompress; - } - channels[i].state = QHttpNetworkConnectionChannel::WritingState; - channels[i].pendingEncrypt = false; - // if the url contains authentication parameters, use the new ones - // both channels will use the new authentication parameters - if (!channels[i].request.url().userInfo().isEmpty()) { - QUrl url = channels[i].request.url(); - QAuthenticator &auth = channels[i].authenticator; - if (url.userName() != auth.user() - || (!url.password().isEmpty() && url.password() != auth.password())) { - auth.setUser(url.userName()); - auth.setPassword(url.password()); - copyCredentials(i, &auth, false); - } - // clear the userinfo, since we use the same request for resending - // userinfo in url can conflict with the one in the authenticator - url.setUserInfo(QString()); - channels[i].request.setUrl(url); - } - createAuthorization(socket, channels[i].request); -#ifndef QT_NO_NETWORKPROXY - QByteArray header = QHttpNetworkRequestPrivate::header(channels[i].request, - (networkProxy.type() != QNetworkProxy::NoProxy)); -#else - QByteArray header = QHttpNetworkRequestPrivate::header(channels[i].request, - false); -#endif - socket->write(header); - QNonContiguousByteDevice* uploadByteDevice = channels[i].request.uploadByteDevice(); - if (uploadByteDevice) { - // connect the signals so this function gets called again - QObject::connect(uploadByteDevice, SIGNAL(readyRead()), &channels[i], SLOT(_q_uploadDataReadyRead())); - - channels[i].bytesTotal = channels[i].request.contentLength(); - } else { - socket->flush(); // ### Remove this when pipelining is implemented. We want less TCP packets! - channels[i].state = QHttpNetworkConnectionChannel::WaitingState; - break; - } - // write the initial chunk together with the headers - // fall through - } - case QHttpNetworkConnectionChannel::WritingState: - { - // write the data - QNonContiguousByteDevice* uploadByteDevice = channels[i].request.uploadByteDevice(); - if (!uploadByteDevice || channels[i].bytesTotal == channels[i].written) { - if (uploadByteDevice) - emit channels[i].reply->dataSendProgress(channels[i].written, channels[i].bytesTotal); - channels[i].state = QHttpNetworkConnectionChannel::WaitingState; // now wait for response - sendRequest(socket); - break; - } - - // only feed the QTcpSocket buffer when there is less than 32 kB in it - const qint64 socketBufferFill = 32*1024; - const qint64 socketWriteMaxSize = 16*1024; - - -#ifndef QT_NO_OPENSSL - QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket); - // if it is really an ssl socket, check more than just bytesToWrite() - while ((socket->bytesToWrite() + (sslSocket ? sslSocket->encryptedBytesToWrite() : 0)) - <= socketBufferFill && channels[i].bytesTotal != channels[i].written) -#else - while (socket->bytesToWrite() <= socketBufferFill - && channels[i].bytesTotal != channels[i].written) -#endif - { - // get pointer to upload data - qint64 currentReadSize; - qint64 desiredReadSize = qMin(socketWriteMaxSize, channels[i].bytesTotal - channels[i].written); - const char *readPointer = uploadByteDevice->readPointer(desiredReadSize, currentReadSize); - - if (currentReadSize == -1) { - // premature eof happened - emitReplyError(socket, channels[i].reply, QNetworkReply::UnknownNetworkError); - return false; - break; - } else if (readPointer == 0 || currentReadSize == 0) { - // nothing to read currently, break the loop - break; - } else { - qint64 currentWriteSize = socket->write(readPointer, currentReadSize); - if (currentWriteSize == -1 || currentWriteSize != currentReadSize) { - // socket broke down - emitReplyError(socket, channels[i].reply, QNetworkReply::UnknownNetworkError); - return false; - } else { - channels[i].written += currentWriteSize; - uploadByteDevice->advanceReadPointer(currentWriteSize); - - emit channels[i].reply->dataSendProgress(channels[i].written, channels[i].bytesTotal); - - if (channels[i].written == channels[i].bytesTotal) { - // make sure this function is called once again - channels[i].state = QHttpNetworkConnectionChannel::WaitingState; - sendRequest(socket); - break; - } - } - } - } - break; - } - - case QHttpNetworkConnectionChannel::WaitingState: - { - QNonContiguousByteDevice* uploadByteDevice = channels[i].request.uploadByteDevice(); - if (uploadByteDevice) { - QObject::disconnect(uploadByteDevice, SIGNAL(readyRead()), &channels[i], SLOT(_q_uploadDataReadyRead())); - } - // ensure we try to receive a reply in all cases, even if _q_readyRead_ hat not been called - // this is needed if the sends an reply before we have finished sending the request. In that - // case receiveReply had been called before but ignored the server reply - receiveReply(socket, channels[i].reply); - break; - } - case QHttpNetworkConnectionChannel::ReadingState: - case QHttpNetworkConnectionChannel::Wait4AuthState: - // ignore _q_bytesWritten in these states - // fall through - default: - break; - } - return true; -} - -bool QHttpNetworkConnectionPrivate::shouldEmitSignals(QHttpNetworkReply *reply) -{ - // for 401 & 407 don't emit the data signals. Content along with these - // responses are send only if the authentication fails. - return (reply && reply->d_func()->statusCode != 401 && reply->d_func()->statusCode != 407); -} - -bool QHttpNetworkConnectionPrivate::expectContent(QHttpNetworkReply *reply) -{ - // check whether we can expect content after the headers (rfc 2616, sec4.4) - if (!reply) - return false; - if ((reply->d_func()->statusCode >= 100 && reply->d_func()->statusCode < 200) - || reply->d_func()->statusCode == 204 || reply->d_func()->statusCode == 304) - return false; - if (reply->d_func()->request.operation() == QHttpNetworkRequest::Head) - return !shouldEmitSignals(reply); - if (reply->d_func()->contentLength() == 0) - return false; - return true; -} void QHttpNetworkConnectionPrivate::emitReplyError(QAbstractSocket *socket, QHttpNetworkReply *reply, @@ -460,271 +244,13 @@ void QHttpNetworkConnectionPrivate::emitReplyError(QAbstractSocket *socket, emit reply->finishedWithError(errorCode, reply->d_func()->errorString); int i = indexOf(socket); // remove the corrupt data if any - eraseData(channels[i].reply); - closeChannel(i); + reply->d_func()->eraseData(); + channels[i].close(); // send the next request QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); } } -#ifndef QT_NO_COMPRESS -bool QHttpNetworkConnectionPrivate::expand(QAbstractSocket *socket, QHttpNetworkReply *reply, bool dataComplete) -{ - Q_ASSERT(socket); - Q_ASSERT(reply); - - qint64 total = compressedBytesAvailable(*reply); - if (total >= CHUNK || dataComplete) { - int i = indexOf(socket); - // uncompress the data - QByteArray content, inflated; - content = reply->d_func()->compressedData; - reply->d_func()->compressedData.clear(); - - int ret = Z_OK; - if (content.size()) - ret = reply->d_func()->gunzipBodyPartially(content, inflated); - int retCheck = (dataComplete) ? Z_STREAM_END : Z_OK; - if (ret >= retCheck) { - if (inflated.size()) { - reply->d_func()->totalProgress += inflated.size(); - reply->d_func()->appendUncompressedReplyData(inflated); - if (shouldEmitSignals(reply)) { - // important: At the point of this readyRead(), inflated must be cleared, - // else implicit sharing will trigger memcpy when the user is reading data! - emit reply->readyRead(); - // make sure that the reply is valid - if (channels[i].reply != reply) - return true; - emit reply->dataReadProgress(reply->d_func()->totalProgress, 0); - // make sure that the reply is valid - if (channels[i].reply != reply) - return true; - - } - } - } else { - emitReplyError(socket, reply, QNetworkReply::ProtocolFailure); - return false; - } - } - return true; -} -#endif - -void QHttpNetworkConnectionPrivate::receiveReply(QAbstractSocket *socket, QHttpNetworkReply *reply) -{ - Q_ASSERT(socket); - - Q_Q(QHttpNetworkConnection); - qint64 bytes = 0; - QAbstractSocket::SocketState state = socket->state(); - int i = indexOf(socket); - - // connection might be closed to signal the end of data - if (state == QAbstractSocket::UnconnectedState) { - if (!socket->bytesAvailable()) { - if (reply && reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) { - reply->d_func()->state = QHttpNetworkReplyPrivate::AllDoneState; - channels[i].state = QHttpNetworkConnectionChannel::IdleState; - allDone(socket, reply); - } else { - // try to reconnect/resend before sending an error. - if (channels[i].reconnectAttempts-- > 0) { - resendCurrentRequest(socket); - } else if (reply) { - reply->d_func()->errorString = errorDetail(QNetworkReply::RemoteHostClosedError, socket); - emit reply->finishedWithError(QNetworkReply::RemoteHostClosedError, reply->d_func()->errorString); - QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); - } - } - } - } - - // read loop for the response - while (socket->bytesAvailable()) { - QHttpNetworkReplyPrivate::ReplyState state = reply ? reply->d_func()->state : QHttpNetworkReplyPrivate::AllDoneState; - switch (state) { - case QHttpNetworkReplyPrivate::NothingDoneState: - case QHttpNetworkReplyPrivate::ReadingStatusState: { - qint64 statusBytes = reply->d_func()->readStatus(socket); - if (statusBytes == -1) { - // error reading the status, close the socket and emit error - socket->close(); - reply->d_func()->errorString = errorDetail(QNetworkReply::ProtocolFailure, socket); - emit reply->finishedWithError(QNetworkReply::ProtocolFailure, reply->d_func()->errorString); - QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); - break; - } - bytes += statusBytes; - channels[i].lastStatus = reply->d_func()->statusCode; - break; - } - case QHttpNetworkReplyPrivate::ReadingHeaderState: - bytes += reply->d_func()->readHeader(socket); - if (reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) { - if (reply->d_func()->isGzipped() && reply->d_func()->autoDecompress) { - // remove the Content-Length from header - reply->d_func()->removeAutoDecompressHeader(); - } else { - reply->d_func()->autoDecompress = false; - } - if (reply && reply->d_func()->statusCode == 100) { - reply->d_func()->state = QHttpNetworkReplyPrivate::ReadingStatusState; - break; // ignore - } - if (shouldEmitSignals(reply)) - emit reply->headerChanged(); - if (!expectContent(reply)) { - reply->d_func()->state = QHttpNetworkReplyPrivate::AllDoneState; - channels[i].state = QHttpNetworkConnectionChannel::IdleState; - allDone(socket, reply); - return; - } - } - break; - case QHttpNetworkReplyPrivate::ReadingDataState: { - if (!reply->d_func()->isChunked() && !reply->d_func()->autoDecompress - && reply->d_func()->bodyLength > 0) { - // bulk files like images should fulfill these properties and - // we can therefore save on memory copying - bytes = reply->d_func()->readBodyFast(socket, &reply->d_func()->responseData); - reply->d_func()->totalProgress += bytes; - if (shouldEmitSignals(reply)) { - emit reply->readyRead(); - // make sure that the reply is valid - if (channels[i].reply != reply) - return; - emit reply->dataReadProgress(reply->d_func()->totalProgress, reply->d_func()->bodyLength); - // make sure that the reply is valid - if (channels[i].reply != reply) - return; - } - } - else - { - // use the traditional slower reading (for compressed encoding, chunked encoding, - // no content-length etc) - QByteDataBuffer byteDatas; - bytes = reply->d_func()->readBody(socket, &byteDatas); - if (bytes) { - if (reply->d_func()->autoDecompress) - reply->d_func()->appendCompressedReplyData(byteDatas); - else - reply->d_func()->appendUncompressedReplyData(byteDatas); - - if (!reply->d_func()->autoDecompress) { - reply->d_func()->totalProgress += bytes; - if (shouldEmitSignals(reply)) { - // important: At the point of this readyRead(), the byteDatas list must be empty, - // else implicit sharing will trigger memcpy when the user is reading data! - emit reply->readyRead(); - // make sure that the reply is valid - if (channels[i].reply != reply) - return; - emit reply->dataReadProgress(reply->d_func()->totalProgress, reply->d_func()->bodyLength); - // make sure that the reply is valid - if (channels[i].reply != reply) - return; - } - } -#ifndef QT_NO_COMPRESS - else if (!expand(socket, reply, false)) { // expand a chunk if possible - return; // ### expand failed - } -#endif - } - } - if (reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) - break; - // everything done, fall through - } - case QHttpNetworkReplyPrivate::AllDoneState: - channels[i].state = QHttpNetworkConnectionChannel::IdleState; - allDone(socket, reply); - break; - default: - break; - } - } -} - -void QHttpNetworkConnectionPrivate::allDone(QAbstractSocket *socket, QHttpNetworkReply *reply) -{ -#ifndef QT_NO_COMPRESS - // expand the whole data. - if (expectContent(reply) && reply->d_func()->autoDecompress && !reply->d_func()->streamEnd) - expand(socket, reply, true); // ### if expand returns false, its an error -#endif - // while handling 401 & 407, we might reset the status code, so save this. - bool emitFinished = shouldEmitSignals(reply); - handleStatus(socket, reply); - // ### at this point there should be no more data on the socket - // close if server requested - int i = indexOf(socket); - if (reply->d_func()->connectionCloseEnabled()) - closeChannel(i); - // queue the finished signal, this is required since we might send new requests from - // slot connected to it. The socket will not fire readyRead signal, if we are already - // in the slot connected to readyRead - if (emitFinished) - QMetaObject::invokeMethod(reply, "finished", Qt::QueuedConnection); - // reset the reconnection attempts after we receive a complete reply. - // in case of failures, each channel will attempt two reconnects before emitting error. - channels[i].reconnectAttempts = 2; -} - -void QHttpNetworkConnectionPrivate::handleStatus(QAbstractSocket *socket, QHttpNetworkReply *reply) -{ - Q_ASSERT(socket); - Q_ASSERT(reply); - - Q_Q(QHttpNetworkConnection); - - int statusCode = reply->statusCode(); - bool resend = false; - - switch (statusCode) { - case 401: - case 407: - if (handleAuthenticateChallenge(socket, reply, (statusCode == 407), resend)) { - if (resend) { - int i = indexOf(socket); - - QNonContiguousByteDevice* uploadByteDevice = channels[i].request.uploadByteDevice(); - if (uploadByteDevice) { - if (uploadByteDevice->reset()) { - channels[i].written = 0; - } else { - emitReplyError(socket, reply, QNetworkReply::ContentReSendError); - break; - } - } - - eraseData(reply); - - // also use async _q_startNextRequest so we dont break with closed - // proxy or server connections.. - channels[i].resendCurrent = true; - QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); - } - } else { - int i = indexOf(socket); - emit channels[i].reply->headerChanged(); - emit channels[i].reply->readyRead(); - QNetworkReply::NetworkError errorCode = (statusCode == 407) - ? QNetworkReply::ProxyAuthenticationRequiredError - : QNetworkReply::AuthenticationRequiredError; - reply->d_func()->errorString = errorDetail(errorCode, socket); - emit q->error(errorCode, reply->d_func()->errorString); - emit channels[i].reply->finished(); - } - break; - default: - QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); - } -} - void QHttpNetworkConnectionPrivate::copyCredentials(int fromChannel, QAuthenticator *auth, bool isProxy) { Q_ASSERT(auth); @@ -747,6 +273,7 @@ void QHttpNetworkConnectionPrivate::copyCredentials(int fromChannel, QAuthentica } +// handles the authentication for one channel and eventually re-starts the other channels bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket *socket, QHttpNetworkReply *reply, bool isProxy, bool &resend) { @@ -786,8 +313,8 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket if (priv->phase == QAuthenticatorPrivate::Done) { if ((isProxy && pendingProxyAuthSignal) ||(!isProxy && pendingAuthSignal)) { // drop the request - eraseData(channels[i].reply); - closeChannel(i); + reply->d_func()->eraseData(); + channels[i].close(); channels[i].lastStatus = 0; channels[i].state = QHttpNetworkConnectionChannel::Wait4AuthState; return false; @@ -892,7 +419,24 @@ QHttpNetworkReply* QHttpNetworkConnectionPrivate::queueRequest(const QHttpNetwor return reply; } -void QHttpNetworkConnectionPrivate::unqueueAndSendRequest(QAbstractSocket *socket) +void QHttpNetworkConnectionPrivate::requeueRequest(const HttpMessagePair &pair) +{ + Q_Q(QHttpNetworkConnection); + + QHttpNetworkRequest request = pair.first; + switch (request.priority()) { + case QHttpNetworkRequest::HighPriority: + highPriorityQueue.prepend(pair); + break; + case QHttpNetworkRequest::NormalPriority: + case QHttpNetworkRequest::LowPriority: + lowPriorityQueue.prepend(pair); + break; + } + QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); +} + +void QHttpNetworkConnectionPrivate::dequeueAndSendRequest(QAbstractSocket *socket) { Q_ASSERT(socket); @@ -906,8 +450,9 @@ void QHttpNetworkConnectionPrivate::unqueueAndSendRequest(QAbstractSocket *socke channels[i].request = messagePair.first; channels[i].reply = messagePair.second; - sendRequest(socket); + // remove before sendRequest! else we might pipeline the same request again highPriorityQueue.removeAt(j); + channels[i].sendRequest(); return; } } @@ -919,28 +464,113 @@ void QHttpNetworkConnectionPrivate::unqueueAndSendRequest(QAbstractSocket *socke prepareRequest(messagePair); channels[i].request = messagePair.first; channels[i].reply = messagePair.second; - sendRequest(socket); + // remove before sendRequest! else we might pipeline the same request again lowPriorityQueue.removeAt(j); + channels[i].sendRequest(); return; } } } -void QHttpNetworkConnectionPrivate::closeChannel(int channel) +// this is called from _q_startNextRequest and when a request has been sent down a socket from the channel +void QHttpNetworkConnectionPrivate::fillPipeline(QAbstractSocket *socket) { - channels[channel].close(); + // return fast if there is nothing to pipeline + if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty()) + return; + + int i = indexOf(socket); + + bool highPriorityQueueProcessingDone = false; + bool lowPriorityQueueProcessingDone = false; + + while (!highPriorityQueueProcessingDone && !lowPriorityQueueProcessingDone) { + // this loop runs once per request we intend to pipeline in. + + if (channels[i].pipeliningSupported != QHttpNetworkConnectionChannel::PipeliningProbablySupported) + return; + + // the current request that is in must already support pipelining + if (!channels[i].request.isPipeliningAllowed()) + return; + + // the current request must be a idempotent (right now we only check GET) + if (channels[i].request.operation() != QHttpNetworkRequest::Get) + return; + + // check if socket is connected + if (socket->state() != QAbstractSocket::ConnectedState) + return; + + // check for resendCurrent + if (channels[i].resendCurrent) + return; + + // we do not like authentication stuff + // ### make sure to be OK with this in later releases + if (!channels[i].authenticator.isNull() || !channels[i].authenticator.user().isEmpty()) + return; + if (!channels[i].proxyAuthenticator.isNull() || !channels[i].proxyAuthenticator.user().isEmpty()) + return; + + // check for pipeline length + if (channels[i].alreadyPipelinedRequests.length() >= defaultPipelineLength) + return; + + // must be in ReadingState or WaitingState + if (! (channels[i].state == QHttpNetworkConnectionChannel::WaitingState + || channels[i].state == QHttpNetworkConnectionChannel::ReadingState)) + return; + + highPriorityQueueProcessingDone = fillPipeline(highPriorityQueue, channels[i]); + // not finished with highPriorityQueue? then loop again + if (!highPriorityQueueProcessingDone) + continue; + // highPriorityQueue was processed, now deal with the lowPriorityQueue + lowPriorityQueueProcessingDone = fillPipeline(lowPriorityQueue, channels[i]); + } } -void QHttpNetworkConnectionPrivate::resendCurrentRequest(QAbstractSocket *socket) +// returns true when the processing of a queue has been done +bool QHttpNetworkConnectionPrivate::fillPipeline(QList<HttpMessagePair> &queue, QHttpNetworkConnectionChannel &channel) { - Q_Q(QHttpNetworkConnection); - Q_ASSERT(socket); - int i = indexOf(socket); - closeChannel(i); - channels[i].resendCurrent = true; - QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); + if (queue.isEmpty()) + return true; + + for (int i = 0; i < queue.length(); i++) { + HttpMessagePair messagePair = queue.at(i); + const QHttpNetworkRequest &request = messagePair.first; + + // we currently do not support pipelining if HTTP authentication is used + if (!request.url().userInfo().isEmpty()) + continue; + + // take only GET requests + if (request.operation() != QHttpNetworkRequest::Get) + continue; + + if (!request.isPipeliningAllowed()) + continue; + + // remove it from the queue + queue.takeAt(i); + // we modify the queue we iterate over here, but since we return from the function + // afterwards this is fine. + + // actually send it + if (!messagePair.second->d_func()->requestIsPrepared) + prepareRequest(messagePair); + channel.pipelineInto(messagePair); + + // return false because we processed something and need to process again + return false; + } + + // return true, the queue has been processed and not changed + return true; } + QString QHttpNetworkConnectionPrivate::errorDetail(QNetworkReply::NetworkError errorCode, QAbstractSocket* socket) { Q_ASSERT(socket); @@ -992,7 +622,7 @@ void QHttpNetworkConnectionPrivate::removeReply(QHttpNetworkReply *reply) if (channels[i].reply == reply) { channels[i].reply = 0; if (reply->d_func()->connectionCloseEnabled()) - closeChannel(i); + channels[i].close(); QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); return; } @@ -1031,7 +661,7 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest() channels[i].resendCurrent = false; channels[i].state = QHttpNetworkConnectionChannel::IdleState; if (channels[i].reply) - sendRequest(channels[i].socket); + channels[i].sendRequest(); } } QAbstractSocket *socket = 0; @@ -1043,20 +673,33 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest() break; } } - if (!socket) - return; // this will be called after finishing current request. - unqueueAndSendRequest(socket); + + // this socket is free, + if (socket) + dequeueAndSendRequest(socket); + + // try to push more into all sockets + // ### FIXME we should move this to the beginning of the function + // as soon as QtWebkit is properly using the pipelining + // (e.g. not for XMLHttpRequest or the first page load) + // ### FIXME we should also divide the requests more even + // on the connected sockets + //tryToFillPipeline(socket); + // return fast if there is nothing to pipeline + if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty()) + return; + for (int j = 0; j < channelCount; j++) + fillPipeline(channels[j].socket); } void QHttpNetworkConnectionPrivate::_q_restartAuthPendingRequests() { // send the request using the idle socket for (int i = 0 ; i < channelCount; ++i) { - QAbstractSocket *socket = channels[i].socket; if (channels[i].state == QHttpNetworkConnectionChannel::Wait4AuthState) { channels[i].state = QHttpNetworkConnectionChannel::IdleState; if (channels[i].reply) - sendRequest(socket); + channels[i].sendRequest(); } } } @@ -1069,6 +712,13 @@ QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 d->init(); } +QHttpNetworkConnection::QHttpNetworkConnection(quint16 connectionCount, const QString &hostName, quint16 port, bool encrypt, QObject *parent) + : QObject(*(new QHttpNetworkConnectionPrivate(connectionCount, hostName, port, encrypt)), parent) +{ + Q_D(QHttpNetworkConnection); + d->init(); +} + QHttpNetworkConnection::~QHttpNetworkConnection() { } @@ -1215,6 +865,19 @@ void QHttpNetworkConnection::ignoreSslErrors(const QList<QSslError> &errors, int #endif //QT_NO_OPENSSL +#ifndef QT_NO_NETWORKPROXY +// only called from QHttpNetworkConnectionChannel::_q_proxyAuthenticationRequired, not +// from QHttpNetworkConnectionChannel::handleAuthenticationChallenge +// e.g. it is for SOCKS proxies which require authentication. +void QHttpNetworkConnectionPrivate::emitProxyAuthenticationRequired(const QHttpNetworkConnectionChannel *chan, const QNetworkProxy &proxy, QAuthenticator* auth) +{ + Q_Q(QHttpNetworkConnection); + emit q->proxyAuthenticationRequired(proxy, auth, q); + int i = indexOf(chan->socket); + copyCredentials(i, auth, true); +} +#endif + QT_END_NAMESPACE diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 99dda2a..af764ed 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -89,6 +89,7 @@ class Q_AUTOTEST_EXPORT QHttpNetworkConnection : public QObject public: QHttpNetworkConnection(const QString &hostName, quint16 port = 80, bool encrypt = false, QObject *parent = 0); + QHttpNetworkConnection(quint16 channelCount, const QString &hostName, quint16 port = 80, bool encrypt = false, QObject *parent = 0); ~QHttpNetworkConnection(); //The hostname to which this is connected to. @@ -153,7 +154,11 @@ class QHttpNetworkConnectionPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QHttpNetworkConnection) public: + static const int defaultChannelCount; + static const int defaultPipelineLength; + QHttpNetworkConnectionPrivate(const QString &hostName, quint16 port, bool encrypt); + QHttpNetworkConnectionPrivate(quint16 channelCount, const QString &hostName, quint16 port, bool encrypt); ~QHttpNetworkConnectionPrivate(); void init(); @@ -166,12 +171,13 @@ public: bool isSocketReading(QAbstractSocket *socket) const; QHttpNetworkReply *queueRequest(const QHttpNetworkRequest &request); - void unqueueAndSendRequest(QAbstractSocket *socket); + void requeueRequest(const HttpMessagePair &pair); // e.g. after pipeline broke + void dequeueAndSendRequest(QAbstractSocket *socket); void prepareRequest(HttpMessagePair &request); - bool sendRequest(QAbstractSocket *socket); - void receiveReply(QAbstractSocket *socket, QHttpNetworkReply *reply); - void resendCurrentRequest(QAbstractSocket *socket); - void closeChannel(int channel); + + void fillPipeline(QAbstractSocket *socket); + bool fillPipeline(QList<HttpMessagePair> &queue, QHttpNetworkConnectionChannel &channel); + void copyCredentials(int fromChannel, QAuthenticator *auth, bool isProxy); // private slots @@ -179,9 +185,9 @@ public: void _q_restartAuthPendingRequests(); // send the currently blocked request void createAuthorization(QAbstractSocket *socket, QHttpNetworkRequest &request); - bool ensureConnection(QAbstractSocket *socket); + QString errorDetail(QNetworkReply::NetworkError errorCode, QAbstractSocket *socket); - void eraseData(QHttpNetworkReply *reply); + #ifndef QT_NO_COMPRESS bool expand(QAbstractSocket *socket, QHttpNetworkReply *reply, bool dataComplete); #endif @@ -191,7 +197,7 @@ public: quint16 port; bool encrypt; - static const int channelCount; + const int channelCount; QHttpNetworkConnectionChannel *channels; // parallel connections to the server bool pendingAuthSignal; // there is an incomplete authentication signal @@ -199,14 +205,11 @@ public: qint64 uncompressedBytesAvailable(const QHttpNetworkReply &reply) const; qint64 uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const; - qint64 compressedBytesAvailable(const QHttpNetworkReply &reply) const; + void emitReplyError(QAbstractSocket *socket, QHttpNetworkReply *reply, QNetworkReply::NetworkError errorCode); bool handleAuthenticateChallenge(QAbstractSocket *socket, QHttpNetworkReply *reply, bool isProxy, bool &resend); - void allDone(QAbstractSocket *socket, QHttpNetworkReply *reply); - void handleStatus(QAbstractSocket *socket, QHttpNetworkReply *reply); - inline bool shouldEmitSignals(QHttpNetworkReply *reply); - inline bool expectContent(QHttpNetworkReply *reply); + #ifndef QT_NO_OPENSSL QSslConfiguration sslConfiguration(const QHttpNetworkReply &reply) const; @@ -214,6 +217,7 @@ public: #ifndef QT_NO_NETWORKPROXY QNetworkProxy networkProxy; + void emitProxyAuthenticationRequired(const QHttpNetworkConnectionChannel *chan, const QNetworkProxy &proxy, QAuthenticator* auth); #endif //The request queues diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 5ffab76..9d78c55 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -41,6 +41,7 @@ #include "qhttpnetworkconnection_p.h" #include "qhttpnetworkconnectionchannel_p.h" +#include "private/qnoncontiguousbytedevice_p.h" #include <qpair.h> #include <qdebug.h> @@ -113,61 +114,646 @@ void QHttpNetworkConnectionChannel::close() } +bool QHttpNetworkConnectionChannel::sendRequest() +{ + switch (state) { + case QHttpNetworkConnectionChannel::IdleState: { // write the header + if (!ensureConnection()) { + // wait for the connection (and encryption) to be done + // sendRequest will be called again from either + // _q_connected or _q_encrypted + return false; + } + written = 0; // excluding the header + bytesTotal = 0; + if (reply) { + reply->d_func()->clear(); + reply->d_func()->connection = connection; + reply->d_func()->autoDecompress = request.d->autoDecompress; + reply->d_func()->pipeliningUsed = false; + } + state = QHttpNetworkConnectionChannel::WritingState; + pendingEncrypt = false; + // if the url contains authentication parameters, use the new ones + // both channels will use the new authentication parameters + if (!request.url().userInfo().isEmpty()) { + QUrl url = request.url(); + QAuthenticator &auth = authenticator; + if (url.userName() != auth.user() + || (!url.password().isEmpty() && url.password() != auth.password())) { + auth.setUser(url.userName()); + auth.setPassword(url.password()); + connection->d_func()->copyCredentials(connection->d_func()->indexOf(socket), &auth, false); + } + // clear the userinfo, since we use the same request for resending + // userinfo in url can conflict with the one in the authenticator + url.setUserInfo(QString()); + request.setUrl(url); + } + connection->d_func()->createAuthorization(socket, request); +#ifndef QT_NO_NETWORKPROXY + QByteArray header = QHttpNetworkRequestPrivate::header(request, + (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy)); +#else + QByteArray header = QHttpNetworkRequestPrivate::header(request, false); +#endif + socket->write(header); + QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice(); + if (uploadByteDevice) { + // connect the signals so this function gets called again + QObject::connect(uploadByteDevice, SIGNAL(readyRead()),this, SLOT(_q_uploadDataReadyRead())); + + bytesTotal = request.contentLength(); + } else { + state = QHttpNetworkConnectionChannel::WaitingState; + sendRequest(); + break; + } + // write the initial chunk together with the headers + // fall through + } + case QHttpNetworkConnectionChannel::WritingState: + { + // write the data + QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice(); + if (!uploadByteDevice || bytesTotal == written) { + if (uploadByteDevice) + emit reply->dataSendProgress(written, bytesTotal); + state = QHttpNetworkConnectionChannel::WaitingState; // now wait for response + sendRequest(); + break; + } + + // only feed the QTcpSocket buffer when there is less than 32 kB in it + const qint64 socketBufferFill = 32*1024; + const qint64 socketWriteMaxSize = 16*1024; + + +#ifndef QT_NO_OPENSSL + QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket); + // if it is really an ssl socket, check more than just bytesToWrite() + while ((socket->bytesToWrite() + (sslSocket ? sslSocket->encryptedBytesToWrite() : 0)) + <= socketBufferFill && bytesTotal != written) +#else + while (socket->bytesToWrite() <= socketBufferFill + && bytesTotal != written) +#endif + { + // get pointer to upload data + qint64 currentReadSize; + qint64 desiredReadSize = qMin(socketWriteMaxSize, bytesTotal - written); + const char *readPointer = uploadByteDevice->readPointer(desiredReadSize, currentReadSize); + + if (currentReadSize == -1) { + // premature eof happened + connection->d_func()->emitReplyError(socket, reply, QNetworkReply::UnknownNetworkError); + return false; + break; + } else if (readPointer == 0 || currentReadSize == 0) { + // nothing to read currently, break the loop + break; + } else { + qint64 currentWriteSize = socket->write(readPointer, currentReadSize); + if (currentWriteSize == -1 || currentWriteSize != currentReadSize) { + // socket broke down + connection->d_func()->emitReplyError(socket, reply, QNetworkReply::UnknownNetworkError); + return false; + } else { + written += currentWriteSize; + uploadByteDevice->advanceReadPointer(currentWriteSize); + + emit reply->dataSendProgress(written, bytesTotal); + + if (written == bytesTotal) { + // make sure this function is called once again + state = QHttpNetworkConnectionChannel::WaitingState; + sendRequest(); + break; + } + } + } + } + break; + } + + case QHttpNetworkConnectionChannel::WaitingState: + { + QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice(); + if (uploadByteDevice) { + QObject::disconnect(uploadByteDevice, SIGNAL(readyRead()), this, SLOT(_q_uploadDataReadyRead())); + } + + // HTTP pipelining + connection->d_func()->fillPipeline(socket); + socket->flush(); + + // ensure we try to receive a reply in all cases, even if _q_readyRead_ hat not been called + // this is needed if the sends an reply before we have finished sending the request. In that + // case receiveReply had been called before but ignored the server reply + receiveReply(); + break; + } + case QHttpNetworkConnectionChannel::ReadingState: + case QHttpNetworkConnectionChannel::Wait4AuthState: + // ignore _q_bytesWritten in these states + // fall through + default: + break; + } + return true; +} + + +void QHttpNetworkConnectionChannel::receiveReply() +{ + Q_ASSERT(socket); + + qint64 bytes = 0; + QAbstractSocket::SocketState socketState = socket->state(); + + // connection might be closed to signal the end of data + if (socketState == QAbstractSocket::UnconnectedState) { + if (!socket->bytesAvailable()) { + if (reply && reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) { + reply->d_func()->state = QHttpNetworkReplyPrivate::AllDoneState; + this->state = QHttpNetworkConnectionChannel::IdleState; + allDone(); + } else { + // try to reconnect/resend before sending an error. + if (reconnectAttempts-- > 0) { + closeAndResendCurrentRequest(); + } else if (reply) { + reply->d_func()->errorString = connection->d_func()->errorDetail(QNetworkReply::RemoteHostClosedError, socket); + emit reply->finishedWithError(QNetworkReply::RemoteHostClosedError, reply->d_func()->errorString); + QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); + } + } + } + } + + // read loop for the response + while (socket->bytesAvailable()) { + QHttpNetworkReplyPrivate::ReplyState state = reply ? reply->d_func()->state : QHttpNetworkReplyPrivate::AllDoneState; + switch (state) { + case QHttpNetworkReplyPrivate::NothingDoneState: + case QHttpNetworkReplyPrivate::ReadingStatusState: { + eatWhitespace(); + qint64 statusBytes = reply->d_func()->readStatus(socket); + if (statusBytes == -1 && reconnectAttempts <= 0) { + // too many errors reading/receiving/parsing the status, close the socket and emit error + close(); + reply->d_func()->errorString = connection->d_func()->errorDetail(QNetworkReply::ProtocolFailure, socket); + emit reply->finishedWithError(QNetworkReply::ProtocolFailure, reply->d_func()->errorString); + QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); + break; + } else if (statusBytes == -1) { + reconnectAttempts--; + reply->d_func()->clear(); + closeAndResendCurrentRequest(); + break; + } + bytes += statusBytes; + lastStatus = reply->d_func()->statusCode; + break; + } + case QHttpNetworkReplyPrivate::ReadingHeaderState: + bytes += reply->d_func()->readHeader(socket); + if (reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) { + if (reply->d_func()->isGzipped() && reply->d_func()->autoDecompress) { + // remove the Content-Length from header + reply->d_func()->removeAutoDecompressHeader(); + } else { + reply->d_func()->autoDecompress = false; + } + if (reply && reply->d_func()->statusCode == 100) { + reply->d_func()->state = QHttpNetworkReplyPrivate::ReadingStatusState; + break; // ignore + } + if (reply->d_func()->shouldEmitSignals()) + emit reply->headerChanged(); + if (!reply->d_func()->expectContent()) { + reply->d_func()->state = QHttpNetworkReplyPrivate::AllDoneState; + this->state = QHttpNetworkConnectionChannel::IdleState; + allDone(); + return; + } + } + break; + case QHttpNetworkReplyPrivate::ReadingDataState: { + if (!reply->d_func()->isChunked() && !reply->d_func()->autoDecompress + && reply->d_func()->bodyLength > 0) { + // bulk files like images should fulfill these properties and + // we can therefore save on memory copying + bytes = reply->d_func()->readBodyFast(socket, &reply->d_func()->responseData); + reply->d_func()->totalProgress += bytes; + if (reply->d_func()->shouldEmitSignals()) { + QPointer<QHttpNetworkReply> replyPointer = reply; + emit reply->readyRead(); + // make sure that the reply is valid + if (replyPointer.isNull()) + return; + emit reply->dataReadProgress(reply->d_func()->totalProgress, reply->d_func()->bodyLength); + // make sure that the reply is valid + if (replyPointer.isNull()) + return; + } + } + else + { + // use the traditional slower reading (for compressed encoding, chunked encoding, + // no content-length etc) + QByteDataBuffer byteDatas; + bytes = reply->d_func()->readBody(socket, &byteDatas); + if (bytes) { + if (reply->d_func()->autoDecompress) + reply->d_func()->appendCompressedReplyData(byteDatas); + else + reply->d_func()->appendUncompressedReplyData(byteDatas); + + if (!reply->d_func()->autoDecompress) { + reply->d_func()->totalProgress += bytes; + if (reply->d_func()->shouldEmitSignals()) { + QPointer<QHttpNetworkReply> replyPointer = reply; + // important: At the point of this readyRead(), the byteDatas list must be empty, + // else implicit sharing will trigger memcpy when the user is reading data! + emit reply->readyRead(); + // make sure that the reply is valid + if (replyPointer.isNull()) + return; + emit reply->dataReadProgress(reply->d_func()->totalProgress, reply->d_func()->bodyLength); + // make sure that the reply is valid + if (replyPointer.isNull()) + return; + } + } +#ifndef QT_NO_COMPRESS + else if (!expand(false)) { // expand a chunk if possible + return; // ### expand failed + } +#endif + } + } + if (reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) + break; + // everything done, fall through + } + case QHttpNetworkReplyPrivate::AllDoneState: + this->state = QHttpNetworkConnectionChannel::IdleState; + allDone(); + break; + default: + break; + } + } +} + +bool QHttpNetworkConnectionChannel::ensureConnection() +{ + // make sure that this socket is in a connected state, if not initiate + // connection to the host. + if (socket->state() != QAbstractSocket::ConnectedState) { + // connect to the host if not already connected. + // resend this request after we receive the disconnected signal + if (socket->state() == QAbstractSocket::ClosingState) { + resendCurrent = true; + return false; + } + state = QHttpNetworkConnectionChannel::ConnectingState; + pendingEncrypt = connection->d_func()->encrypt; + + // reset state + pipeliningSupported = PipeliningSupportUnknown; + + // This workaround is needed since we use QAuthenticator for NTLM authentication. The "phase == Done" + // is the usual criteria for emitting authentication signals. The "phase" is set to "Done" when the + // last header for Authorization is generated by the QAuthenticator. Basic & Digest logic does not + // check the "phase" for generating the Authorization header. NTLM authentication is a two stage + // process & needs the "phase". To make sure the QAuthenticator uses the current username/password + // the phase is reset to Start. + QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(authenticator); + if (priv && priv->phase == QAuthenticatorPrivate::Done) + priv->phase = QAuthenticatorPrivate::Start; + priv = QAuthenticatorPrivate::getPrivate(proxyAuthenticator); + if (priv && priv->phase == QAuthenticatorPrivate::Done) + priv->phase = QAuthenticatorPrivate::Start; + + QString connectHost = connection->d_func()->hostName; + qint16 connectPort = connection->d_func()->port; + +#ifndef QT_NO_NETWORKPROXY + // HTTPS always use transparent proxy. + if (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy && !connection->d_func()->encrypt) { + connectHost = connection->d_func()->networkProxy.hostName(); + connectPort = connection->d_func()->networkProxy.port(); + } +#endif + if (connection->d_func()->encrypt) { +#ifndef QT_NO_OPENSSL + QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket); + sslSocket->connectToHostEncrypted(connectHost, connectPort); + if (ignoreAllSslErrors) + sslSocket->ignoreSslErrors(); + sslSocket->ignoreSslErrors(ignoreSslErrorsList); +#else + connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ProtocolUnknownError); +#endif + } else { + socket->connectToHost(connectHost, connectPort); + } + return false; + } + return true; +} + + +#ifndef QT_NO_COMPRESS +bool QHttpNetworkConnectionChannel::expand(bool dataComplete) +{ + Q_ASSERT(socket); + Q_ASSERT(reply); + + qint64 total = reply->d_func()->compressedData.size(); + if (total >= CHUNK || dataComplete) { + // uncompress the data + QByteArray content, inflated; + content = reply->d_func()->compressedData; + reply->d_func()->compressedData.clear(); + + int ret = Z_OK; + if (content.size()) + ret = reply->d_func()->gunzipBodyPartially(content, inflated); + int retCheck = (dataComplete) ? Z_STREAM_END : Z_OK; + if (ret >= retCheck) { + if (inflated.size()) { + reply->d_func()->totalProgress += inflated.size(); + reply->d_func()->appendUncompressedReplyData(inflated); + if (reply->d_func()->shouldEmitSignals()) { + QPointer<QHttpNetworkReply> replyPointer = reply; + // important: At the point of this readyRead(), inflated must be cleared, + // else implicit sharing will trigger memcpy when the user is reading data! + emit reply->readyRead(); + // make sure that the reply is valid + if (replyPointer.isNull()) + return true; + emit reply->dataReadProgress(reply->d_func()->totalProgress, 0); + // make sure that the reply is valid + if (replyPointer.isNull()) + return true; + + } + } + } else { + connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ProtocolFailure); + return false; + } + } + return true; +} +#endif + + +void QHttpNetworkConnectionChannel::allDone() +{ +#ifndef QT_NO_COMPRESS + // expand the whole data. + if (reply->d_func()->expectContent() && reply->d_func()->autoDecompress && !reply->d_func()->streamEnd) + expand(true); // ### if expand returns false, its an error +#endif + // while handling 401 & 407, we might reset the status code, so save this. + bool emitFinished = reply->d_func()->shouldEmitSignals(); + handleStatus(); + // ### at this point there should be no more data on the socket + // close if server requested + if (reply->d_func()->connectionCloseEnabled()) + close(); + // queue the finished signal, this is required since we might send new requests from + // slot connected to it. The socket will not fire readyRead signal, if we are already + // in the slot connected to readyRead + if (emitFinished) + QMetaObject::invokeMethod(reply, "finished", Qt::QueuedConnection); + // reset the reconnection attempts after we receive a complete reply. + // in case of failures, each channel will attempt two reconnects before emitting error. + reconnectAttempts = 2; + + detectPipeliningSupport(); + + // move next from pipeline to current request + if (!alreadyPipelinedRequests.isEmpty()) { + if (resendCurrent || reply->d_func()->connectionCloseEnabled() || socket->state() != QAbstractSocket::ConnectedState) { + // move the pipelined ones back to the main queue + requeueCurrentlyPipelinedRequests(); + } else { + // there were requests pipelined in and we can continue + HttpMessagePair messagePair = alreadyPipelinedRequests.takeFirst(); + + request = messagePair.first; + reply = messagePair.second; + state = QHttpNetworkConnectionChannel::ReadingState; + resendCurrent = false; + + written = 0; // message body, excluding the header, irrelevant here + bytesTotal = 0; // message body total, excluding the header, irrelevant here + + // pipeline even more + connection->d_func()->fillPipeline(socket); + + // continue reading + receiveReply(); + } + } else if (alreadyPipelinedRequests.isEmpty() && socket->bytesAvailable() > 0) { + eatWhitespace(); + // this is weird. we had nothing pipelined but still bytes available. better close it. + if (socket->bytesAvailable() > 0) + close(); + QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); + } else if (alreadyPipelinedRequests.isEmpty()) { + QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); + } +} + +void QHttpNetworkConnectionChannel::detectPipeliningSupport() +{ + // detect HTTP Pipelining support + QByteArray serverHeaderField = reply->headerField("Server"); + if ( + // check for broken servers in server reply header + // this is adapted from http://mxr.mozilla.org/firefox/ident?i=SupportsPipelining + (!serverHeaderField.contains("Microsoft-IIS/4.")) + && (!serverHeaderField.contains("Microsoft-IIS/5.")) + && (!serverHeaderField.contains("Netscape-Enterprise/3.")) + // check for HTTP/1.1 + && (reply->d_func()->majorVersion == 1 && reply->d_func()->minorVersion == 1) + // check for not having connection close + && (!reply->d_func()->connectionCloseEnabled()) + // check if it is still connected + && (socket->state() == QAbstractSocket::ConnectedState) + ) { + pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningProbablySupported; + } else { + pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningSupportUnknown; + } +} + +// called when the connection broke and we need to queue some pipelined requests again +void QHttpNetworkConnectionChannel::requeueCurrentlyPipelinedRequests() +{ + for (int i = 0; i < alreadyPipelinedRequests.length(); i++) + connection->d_func()->requeueRequest(alreadyPipelinedRequests.at(i)); + alreadyPipelinedRequests.clear(); + + close(); + QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); +} + +void QHttpNetworkConnectionChannel::eatWhitespace() +{ + char c; + while (socket->bytesAvailable()) { + if (socket->peek(&c, 1) != 1) + return; + + // read all whitespace and line endings + if (c == 11 || c == '\n' || c == '\r' || c == ' ' || c == 31) { + socket->read(&c, 1); + continue; + } else { + break; + } + } +} + +void QHttpNetworkConnectionChannel::handleStatus() +{ + Q_ASSERT(socket); + Q_ASSERT(reply); + + int statusCode = reply->statusCode(); + bool resend = false; + + switch (statusCode) { + case 401: // auth required + case 407: // proxy auth required + if (connection->d_func()->handleAuthenticateChallenge(socket, reply, (statusCode == 407), resend)) { + if (resend) { + QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice(); + if (uploadByteDevice) { + if (uploadByteDevice->reset()) { + written = 0; + } else { + connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ContentReSendError); + break; + } + } + + reply->d_func()->eraseData(); + + if (alreadyPipelinedRequests.isEmpty()) { + // this does a re-send without closing the connection + resendCurrent = true; + QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); + } else { + // we had requests pipelined.. better close the connection in closeAndResendCurrentRequest + closeAndResendCurrentRequest(); + QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); + } + } + } else { + emit reply->headerChanged(); + emit reply->readyRead(); + QNetworkReply::NetworkError errorCode = (statusCode == 407) + ? QNetworkReply::ProxyAuthenticationRequiredError + : QNetworkReply::AuthenticationRequiredError; + reply->d_func()->errorString = connection->d_func()->errorDetail(errorCode, socket); + emit connection->error(errorCode, reply->d_func()->errorString); + emit reply->finished(); + } + break; + default: + QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); + } +} + +void QHttpNetworkConnectionChannel::pipelineInto(HttpMessagePair &pair) +{ + // this is only called for simple GET + + QHttpNetworkRequest &request = pair.first; + QHttpNetworkReply *reply = pair.second; + if (reply) { + reply->d_func()->clear(); + reply->d_func()->connection = connection; + reply->d_func()->autoDecompress = request.d->autoDecompress; + reply->d_func()->pipeliningUsed = true; + } + +#ifndef QT_NO_NETWORKPROXY + QByteArray header = QHttpNetworkRequestPrivate::header(request, + (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy)); +#else + QByteArray header = QHttpNetworkRequestPrivate::header(request, false); +#endif + socket->write(header); + + alreadyPipelinedRequests.append(pair); +} + +void QHttpNetworkConnectionChannel::closeAndResendCurrentRequest() +{ + requeueCurrentlyPipelinedRequests(); + close(); + resendCurrent = true; + QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); +} + //private slots void QHttpNetworkConnectionChannel::_q_readyRead() { - if (!socket) - return; // ### error if (connection->d_func()->isSocketWaiting(socket) || connection->d_func()->isSocketReading(socket)) { state = QHttpNetworkConnectionChannel::ReadingState; if (reply) - connection->d_func()->receiveReply(socket, reply); + receiveReply(); } - // ### error } void QHttpNetworkConnectionChannel::_q_bytesWritten(qint64 bytes) { Q_UNUSED(bytes); - if (!socket) - return; // ### error // bytes have been written to the socket. write even more of them :) if (connection->d_func()->isSocketWriting(socket)) - connection->d_func()->sendRequest(socket); + sendRequest(); // otherwise we do nothing } void QHttpNetworkConnectionChannel::_q_disconnected() { - if (!socket) - return; // ### error // read the available data before closing if (connection->d_func()->isSocketWaiting(socket) || connection->d_func()->isSocketReading(socket)) { state = QHttpNetworkConnectionChannel::ReadingState; if (reply) - connection->d_func()->receiveReply(socket, reply); + receiveReply(); } else if (state == QHttpNetworkConnectionChannel::IdleState && resendCurrent) { // re-sending request because the socket was in ClosingState QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); } state = QHttpNetworkConnectionChannel::IdleState; + + requeueCurrentlyPipelinedRequests(); } void QHttpNetworkConnectionChannel::_q_connected() { - if (!socket) - return; // ### error - // improve performance since we get the request sent by the kernel ASAP socket->setSocketOption(QAbstractSocket::LowDelayOption, 1); + pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningSupportUnknown; + // ### FIXME: if the server closes the connection unexpectedly, we shouldn't send the same broken request again! //channels[i].reconnectAttempts = 2; if (!pendingEncrypt) { state = QHttpNetworkConnectionChannel::IdleState; if (reply) - connection->d_func()->sendRequest(socket); + sendRequest(); else close(); } @@ -193,7 +779,7 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket // while "Reading" the _q_disconnected() will handle this. if (state != QHttpNetworkConnectionChannel::IdleState && state != QHttpNetworkConnectionChannel::ReadingState) { if (reconnectAttempts-- > 0) { - connection->d_func()->resendCurrentRequest(socket); + closeAndResendCurrentRequest(); return; } else { send2Reply = true; @@ -206,7 +792,7 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket case QAbstractSocket::SocketTimeoutError: // try to reconnect/resend before sending an error. if (state == QHttpNetworkConnectionChannel::WritingState && (reconnectAttempts-- > 0)) { - connection->d_func()->resendCurrentRequest(socket); + closeAndResendCurrentRequest(); return; } send2Reply = true; @@ -244,13 +830,13 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket #ifndef QT_NO_NETWORKPROXY void QHttpNetworkConnectionChannel::_q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator* auth) { - emit connection->proxyAuthenticationRequired(proxy, auth, connection); + connection->d_func()->emitProxyAuthenticationRequired(this, proxy, auth); } #endif void QHttpNetworkConnectionChannel::_q_uploadDataReadyRead() { - connection->d_func()->sendRequest(socket); + sendRequest(); } #ifndef QT_NO_OPENSSL @@ -259,7 +845,7 @@ void QHttpNetworkConnectionChannel::_q_encrypted() if (!socket) return; // ### error state = QHttpNetworkConnectionChannel::IdleState; - connection->d_func()->sendRequest(socket); + sendRequest(); } void QHttpNetworkConnectionChannel::_q_sslErrors(const QList<QSslError> &errors) diff --git a/src/network/access/qhttpnetworkconnectionchannel_p.h b/src/network/access/qhttpnetworkconnectionchannel_p.h index f937669..220b72c 100644 --- a/src/network/access/qhttpnetworkconnectionchannel_p.h +++ b/src/network/access/qhttpnetworkconnectionchannel_p.h @@ -82,10 +82,14 @@ class QHttpNetworkReply; class QByteArray; class QHttpNetworkConnection; +#ifndef HttpMessagePair +typedef QPair<QHttpNetworkRequest, QHttpNetworkReply*> HttpMessagePair; +#endif + class QHttpNetworkConnectionChannel : public QObject { Q_OBJECT public: - enum ChannelState { + enum ChannelState { IdleState = 0, // ready to send request ConnectingState = 1, // connecting to host WritingState = 2, // writing the data @@ -112,12 +116,24 @@ public: bool ignoreAllSslErrors; QList<QSslError> ignoreSslErrorsList; #endif + + // HTTP pipelining -> http://en.wikipedia.org/wiki/Http_pipelining + enum PipeliningSupport { + PipeliningSupportUnknown, // default for a new connection + PipeliningProbablySupported, // after having received a server response that indicates support + PipeliningNotSupported // currently not used + }; + PipeliningSupport pipeliningSupported; + QList<HttpMessagePair> alreadyPipelinedRequests; + + QHttpNetworkConnectionChannel() : socket(0), state(IdleState), reply(0), written(0), bytesTotal(0), resendCurrent(false), lastStatus(0), pendingEncrypt(false), reconnectAttempts(2), authMehtod(QAuthenticatorPrivate::None), proxyAuthMehtod(QAuthenticatorPrivate::None) #ifndef QT_NO_OPENSSL , ignoreAllSslErrors(false) #endif + , pipeliningSupported(PipeliningSupportUnknown) , connection(0) {} @@ -127,6 +143,23 @@ public: void init(); void close(); + bool sendRequest(); + void receiveReply(); + + bool ensureConnection(); + + bool expand(bool dataComplete); + void allDone(); // reply header + body have been read + void handleStatus(); // called from allDone() + + void pipelineInto(HttpMessagePair &pair); + void requeueCurrentlyPipelinedRequests(); + void detectPipeliningSupport(); + + void closeAndResendCurrentRequest(); + + void eatWhitespace(); + protected slots: void _q_bytesWritten(qint64 bytes); // proceed sending void _q_readyRead(); // pending data to read diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index c31c59c..4a315e4 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -187,6 +187,10 @@ bool QHttpNetworkReply::isFinished() const return d_func()->state == QHttpNetworkReplyPrivate::AllDoneState; } +bool QHttpNetworkReply::isPipeliningUsed() const +{ + return d_func()->pipeliningUsed; +} QHttpNetworkReplyPrivate::QHttpNetworkReplyPrivate(const QUrl &newUrl) @@ -195,6 +199,7 @@ QHttpNetworkReplyPrivate::QHttpNetworkReplyPrivate(const QUrl &newUrl) chunkedTransferEncoding(0), currentChunkSize(0), currentChunkRead(0), connection(0), initInflate(false), autoDecompress(false), responseData(), requestIsPrepared(false) + ,pipeliningUsed(false) { } @@ -418,20 +423,26 @@ qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket) } bool ok = parseStatus(fragment); state = ReadingHeaderState; - fragment.clear(); // next fragment - - if (!ok) + fragment.clear(); + if (!ok) { return -1; + } break; } else { c = 0; - bytes += socket->read(&c, 1); + int haveRead = socket->read(&c, 1); + if (haveRead == -1) + return -1; + bytes += haveRead; fragment.append(c); } // is this a valid reply? if (fragment.length() >= 5 && !fragment.startsWith("HTTP/")) + { + fragment.clear(); return -1; + } } @@ -568,7 +579,6 @@ qint64 QHttpNetworkReplyPrivate::readBodyFast(QAbstractSocket *socket, QByteData if (contentRead + haveRead == bodyLength) { state = AllDoneState; - socket->readAll(); // Read the rest to clean (CRLF) ### will break pipelining } contentRead += haveRead; @@ -588,8 +598,6 @@ qint64 QHttpNetworkReplyPrivate::readBody(QAbstractSocket *socket, QByteDataBuff } else { bytes += readReplyBodyRaw(socket, out, socket->bytesAvailable()); } - if (state == AllDoneState) - socket->readAll(); // Read the rest to clean (CRLF) ### will break pipelining contentRead += bytes; return bytes; } @@ -717,6 +725,33 @@ void QHttpNetworkReplyPrivate::appendCompressedReplyData(QByteDataBuffer &data) } +bool QHttpNetworkReplyPrivate::shouldEmitSignals() +{ + // for 401 & 407 don't emit the data signals. Content along with these + // responses are send only if the authentication fails. + return (statusCode != 401 && statusCode != 407); +} + +bool QHttpNetworkReplyPrivate::expectContent() +{ + // check whether we can expect content after the headers (rfc 2616, sec4.4) + if ((statusCode >= 100 && statusCode < 200) + || statusCode == 204 || statusCode == 304) + return false; + if (request.operation() == QHttpNetworkRequest::Head) + return !shouldEmitSignals(); + if (contentLength() == 0) + return false; + return true; +} + +void QHttpNetworkReplyPrivate::eraseData() +{ + compressedData.clear(); + responseData.clear(); +} + + // SSL support below #ifndef QT_NO_OPENSSL diff --git a/src/network/access/qhttpnetworkreply_p.h b/src/network/access/qhttpnetworkreply_p.h index 5aee067..8d4d724 100644 --- a/src/network/access/qhttpnetworkreply_p.h +++ b/src/network/access/qhttpnetworkreply_p.h @@ -128,6 +128,8 @@ public: bool isFinished() const; + bool isPipeliningUsed() const; + #ifndef QT_NO_OPENSSL QSslConfiguration sslConfiguration() const; void setSslConfiguration(const QSslConfiguration &config); @@ -177,6 +179,10 @@ public: void appendUncompressedReplyData(QByteDataBuffer &data); void appendCompressedReplyData(QByteDataBuffer &data); + bool shouldEmitSignals(); + bool expectContent(); + void eraseData(); + qint64 bytesAvailable() const; bool isChunked(); bool connectionCloseEnabled(); @@ -219,6 +225,8 @@ public: QByteDataBuffer responseData; // uncompressed body QByteArray compressedData; // compressed body (temporary) bool requestIsPrepared; + + bool pipeliningUsed; }; diff --git a/src/network/access/qhttpnetworkrequest.cpp b/src/network/access/qhttpnetworkrequest.cpp index 693e1f4..8b2c4e9 100644 --- a/src/network/access/qhttpnetworkrequest.cpp +++ b/src/network/access/qhttpnetworkrequest.cpp @@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(QHttpNetworkRequest::Operation op, QHttpNetworkRequest::Priority pri, const QUrl &newUrl) : QHttpNetworkHeaderPrivate(newUrl), operation(op), priority(pri), uploadByteDevice(0), - autoDecompress(false) + autoDecompress(false), pipeliningAllowed(false) { } @@ -60,6 +60,7 @@ QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(const QHttpNetworkRequest priority = other.priority; uploadByteDevice = other.uploadByteDevice; autoDecompress = other.autoDecompress; + pipeliningAllowed = other.pipeliningAllowed; } QHttpNetworkRequestPrivate::~QHttpNetworkRequestPrivate() @@ -239,6 +240,16 @@ void QHttpNetworkRequest::setPriority(Priority priority) d->priority = priority; } +bool QHttpNetworkRequest::isPipeliningAllowed() const +{ + return d->pipeliningAllowed; +} + +void QHttpNetworkRequest::setPipeliningAllowed(bool b) +{ + d->pipeliningAllowed = b; +} + void QHttpNetworkRequest::setUploadByteDevice(QNonContiguousByteDevice *bd) { d->uploadByteDevice = bd; diff --git a/src/network/access/qhttpnetworkrequest_p.h b/src/network/access/qhttpnetworkrequest_p.h index ffacb14..2468be9 100644 --- a/src/network/access/qhttpnetworkrequest_p.h +++ b/src/network/access/qhttpnetworkrequest_p.h @@ -106,6 +106,9 @@ public: Priority priority() const; void setPriority(Priority priority); + bool isPipeliningAllowed() const; + void setPipeliningAllowed(bool b); + void setUploadByteDevice(QNonContiguousByteDevice *bd); QNonContiguousByteDevice* uploadByteDevice() const; @@ -113,6 +116,7 @@ private: QSharedDataPointer<QHttpNetworkRequestPrivate> d; friend class QHttpNetworkRequestPrivate; friend class QHttpNetworkConnectionPrivate; + friend class QHttpNetworkConnectionChannel; }; class QHttpNetworkRequestPrivate : public QHttpNetworkHeaderPrivate @@ -132,6 +136,7 @@ public: QHttpNetworkRequest::Priority priority; mutable QNonContiguousByteDevice* uploadByteDevice; bool autoDecompress; + bool pipeliningAllowed; }; diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index 479990a..3532de8 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -516,6 +516,9 @@ void QNetworkAccessHttpBackend::postRequest() return; // no need to send the request! :) } + if (request().attribute(QNetworkRequest::HttpPipeliningAllowedAttribute).toBool() == true) + httpRequest.setPipeliningAllowed(true); + httpReply = http->sendRequest(httpRequest); httpReply->setParent(this); #ifndef QT_NO_OPENSSL @@ -713,6 +716,8 @@ void QNetworkAccessHttpBackend::checkForRedirect(const int statusCode) void QNetworkAccessHttpBackend::replyHeaderChanged() { + setAttribute(QNetworkRequest::HttpPipeliningWasUsedAttribute, httpReply->isPipeliningUsed()); + // reconstruct the HTTP header QList<QPair<QByteArray, QByteArray> > headerMap = httpReply->header(); QList<QPair<QByteArray, QByteArray> >::ConstIterator it = headerMap.constBegin(), diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index ce5f6c7..839bf31 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -804,7 +804,13 @@ void QNetworkAccessManagerPrivate::proxyAuthenticationRequired(QNetworkAccessBac QAuthenticator *authenticator) { Q_Q(QNetworkAccessManager); - + // ### FIXME Tracking of successful authentications + // This code is a bit broken right now for SOCKS authentication + // first request: proxyAuthenticationRequired gets emitted, credentials gets saved + // second request: (proxy != backend->reply->lastProxyAuthentication) does not evaluate to true, + // proxyAuthenticationRequired gets emitted again + // possible solution: some tracking inside the authenticator + // or a new function proxyAuthenticationSucceeded(true|false) if (proxy != backend->reply->lastProxyAuthentication) { QNetworkAuthenticationCredential *cred = fetchCachedCredentials(proxy); if (cred) { diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index 721f8c4..c6cbddd 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -167,6 +167,16 @@ QT_BEGIN_NAMESPACE When using this flag with sequential upload data, the ContentLengthHeader header must be set. + \value HttpPipeliningAllowedAttribute + Requests only, type: QVariant::Bool (default: false) + Indicates whether the QNetworkAccessManager code is + allowed to use HTTP pipelining with this request. + + \value HttpPipeliningWasUsedAttribute + Replies only, type: QVariant::Bool + Indicates whether the HTTP pipelining was used for receiving + this reply. + \value User Special type. Additional information can be passed in QVariants with types ranging from User to UserMax. The default diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h index aaeed48..2c26038 100644 --- a/src/network/access/qnetworkrequest.h +++ b/src/network/access/qnetworkrequest.h @@ -76,6 +76,8 @@ public: CacheSaveControlAttribute, SourceIsFromCacheAttribute, DoNotBufferUploadDataAttribute, + HttpPipeliningAllowedAttribute, + HttpPipeliningWasUsedAttribute, User = 1000, UserMax = 32767 diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index ee1369d..77b2a7e 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -162,16 +162,13 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver, QWindowsSockInit bust; // makes sure WSAStartup was callled #endif - // Support for IDNA - QString lookup = QString::fromLatin1(QUrl::toAce(name)); - QHostInfoResult *result = new QHostInfoResult; result->autoDelete = false; QObject::connect(result, SIGNAL(resultsReady(QHostInfo)), receiver, member); int id = result->lookupId = theIdCounter.fetchAndAddRelaxed(1); - if (lookup.isEmpty()) { + if (name.isEmpty()) { QHostInfo info(id); info.setError(QHostInfo::HostNotFound); info.setErrorString(QObject::tr("No host name given")); @@ -182,7 +179,7 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver, } QHostInfoAgent *agent = theAgent(); - agent->addHostName(lookup, result); + agent->addHostName(name, result); #if !defined QT_NO_THREAD if (!agent->isRunning()) @@ -226,13 +223,7 @@ QHostInfo QHostInfo::fromName(const QString &name) qDebug("QHostInfo::fromName(\"%s\")",name.toLatin1().constData()); #endif - if (!name.isEmpty()) - return QHostInfoAgent::fromName(QLatin1String(QUrl::toAce(name))); - - QHostInfo retval; - retval.d->err = HostNotFound; - retval.d->errorStr = QObject::tr("No host name given"); - return retval; + return QHostInfoAgent::fromName(name); } /*! diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp index 4a23399..e3d51e7 100644 --- a/src/network/kernel/qhostinfo_unix.cpp +++ b/src/network/kernel/qhostinfo_unix.cpp @@ -124,7 +124,6 @@ static void resolveLibrary() QHostInfo QHostInfoAgent::fromName(const QString &hostName) { QHostInfo results; - results.setHostName(hostName); #if defined(QHOSTINFO_DEBUG) qDebug("QHostInfoAgent::fromName(%s) looking up...", @@ -194,6 +193,22 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) #endif } + // IDN support + QByteArray aceHostname; + if (results.hostName().isEmpty()) { + // it's a hostname resolution + aceHostname = QUrl::toAce(hostName); + results.setHostName(hostName); + if (aceHostname.isEmpty()) { + results.setError(QHostInfo::HostNotFound); + results.setErrorString(hostName.isEmpty() ? QObject::tr("No host name given") : QObject::tr("Invalid hostname")); + return results; + } + } else { + // it's an IP reverse resolution + aceHostname = results.hostName().toLatin1(); + } + #if !defined (QT_NO_GETADDRINFO) // Call getaddrinfo, and place all IPv4 addresses at the start and // the IPv6 addresses at the end of the address list in results. @@ -205,12 +220,12 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) hints.ai_flags = Q_ADDRCONFIG; #endif - int result = getaddrinfo(hostName.toLatin1().constData(), 0, &hints, &res); + int result = getaddrinfo(aceHostname.constData(), 0, &hints, &res); # ifdef Q_ADDRCONFIG if (result == EAI_BADFLAGS) { // if the lookup failed with AI_ADDRCONFIG set, try again without it hints.ai_flags = 0; - result = getaddrinfo(hostName.toLatin1().constData(), 0, &hints, &res); + result = getaddrinfo(aceHostname.constData(), 0, &hints, &res); } # endif @@ -264,7 +279,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) // use one QHostInfoAgent, but if more agents are introduced, locking // must be provided. QMutexLocker locker(::getHostByNameMutex()); - hostent *result = gethostbyname(hostName.toLatin1().constData()); + hostent *result = gethostbyname(aceHostname.constData()); if (result) { if (result->h_addrtype == AF_INET) { QList<QHostAddress> addresses; diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp index 93dc720..c5dc2d2 100644 --- a/src/network/kernel/qhostinfo_win.cpp +++ b/src/network/kernel/qhostinfo_win.cpp @@ -52,6 +52,7 @@ #include <qlibrary.h> #include <qtimer.h> #include <qmutex.h> +#include <qurl.h> #include <private/qmutexpool_p.h> QT_BEGIN_NAMESPACE @@ -129,7 +130,6 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) } QHostInfo results; - results.setHostName(hostName); #if defined(QHOSTINFO_DEBUG) qDebug("QHostInfoAgent::fromName(%p): looking up \"%s\" (IPv6 support is %s)", @@ -178,12 +178,28 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) } } + // IDN support + QByteArray aceHostname; + if (results.hostName().isEmpty()) { + // it's a hostname resolution + aceHostname = QUrl::toAce(hostName); + results.setHostName(hostName); + if (aceHostname.isEmpty()) { + results.setError(QHostInfo::HostNotFound); + results.setErrorString(hostName.isEmpty() ? QObject::tr("No host name given") : QObject::tr("Invalid hostname")); + return results; + } + } else { + // it's an IP reverse resolution + aceHostname = results.hostName().toLatin1(); + } + if (local_getaddrinfo && local_freeaddrinfo) { // Call getaddrinfo, and place all IPv4 addresses at the start // and the IPv6 addresses at the end of the address list in // results. qt_addrinfo *res; - int err = local_getaddrinfo(hostName.toLatin1().constData(), 0, 0, &res); + int err = local_getaddrinfo(aceHostname.constData(), 0, 0, &res); if (err == 0) { QList<QHostAddress> addresses; for (qt_addrinfo *p = res; p != 0; p = p->ai_next) { @@ -218,7 +234,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) } } else { // Fall back to gethostbyname, which only supports IPv4. - hostent *ent = gethostbyname(hostName.toLatin1().constData()); + hostent *ent = gethostbyname(aceHostname.constData()); if (ent) { char **p; QList<QHostAddress> addresses; diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 34f7e7a..5b6a714 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -246,6 +246,7 @@ void QGLTextureGlyphCache::resizeTextureData(int width, int height) #ifdef QT_OPENGL_ES_2 QDataBuffer<uchar> buffer(4*oldWidth*oldHeight); + buffer.resize(4*oldWidth*oldHeight); glReadPixels(0, 0, oldWidth, oldHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer.data()); // do an in-place conversion from GL_RGBA to GL_ALPHA diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp index ba715c3..956189c 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp @@ -559,7 +559,9 @@ void QDirectFBPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pixmap, QRasterPaintEngine::drawPixmap(r, pixmap, sr); } else if (!(d->compositionModeStatus & QDirectFBPaintEnginePrivate::PorterDuff_SupportedBlits) || (d->transformationType & QDirectFBPaintEnginePrivate::Matrix_BlitsUnsupported) - || d->clipType == QDirectFBPaintEnginePrivate::ComplexClip) { + || d->clipType == QDirectFBPaintEnginePrivate::ComplexClip + || (state()->renderHints & QPainter::SmoothPixmapTransform + && state()->matrix.mapRect(r).size() != sr.size())) { RASTERFALLBACK(DRAW_PIXMAP, r, pixmap.size(), sr); const QImage *img = static_cast<QDirectFBPixmapData*>(pixmap.pixmapData())->buffer(DSLF_READ); d->lock(); @@ -593,7 +595,8 @@ void QDirectFBPaintEngine::drawTiledPixmap(const QRectF &r, QRasterPaintEngine::drawTiledPixmap(r, pixmap, offset); } else if (!(d->compositionModeStatus & QDirectFBPaintEnginePrivate::PorterDuff_SupportedBlits) || (d->transformationType & QDirectFBPaintEnginePrivate::Matrix_BlitsUnsupported) - || d->clipType == QDirectFBPaintEnginePrivate::ComplexClip) { + || d->clipType == QDirectFBPaintEnginePrivate::ComplexClip + || (state()->renderHints & QPainter::SmoothPixmapTransform && state()->matrix.isScaling())) { RASTERFALLBACK(DRAW_TILED_PIXMAP, r, pixmap.size(), offset); const QImage *img = static_cast<QDirectFBPixmapData*>(pixmap.pixmapData())->buffer(DSLF_READ); d->lock(); @@ -709,7 +712,8 @@ void QDirectFBPaintEngine::fillRect(const QRectF &rect, const QBrush &brush) case Qt::TexturePattern: { if (!(d->compositionModeStatus & QDirectFBPaintEnginePrivate::PorterDuff_SupportedBlits) - || (d->transformationType & QDirectFBPaintEnginePrivate::Matrix_BlitsUnsupported)) { + || (d->transformationType & QDirectFBPaintEnginePrivate::Matrix_BlitsUnsupported) + || (state()->renderHints & QPainter::SmoothPixmapTransform && state()->matrix.isScaling())) { break; } @@ -843,6 +847,13 @@ void QDirectFBPaintEnginePrivate::setCompositionMode(QPainter::CompositionMode m { if (!surface) return; + + static const bool forceRasterFallBack = qgetenv("QT_DIRECTFB_FORCE_RASTER").toInt() > 0; + if (forceRasterFallBack) { + compositionModeStatus = 0; + return; + } + compositionModeStatus = PorterDuff_SupportedBlits; switch (mode) { case QPainter::CompositionMode_Clear: diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index dc53847..45de07a 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -1029,10 +1029,10 @@ bool QDirectFBScreen::connect(const QString &displaySpec) surface = createDFBSurface(description, DontTrackSurface); #endif // Work out what format we're going to use for surfaces with an alpha channel - d_ptr->alphaPixmapFormat = QDirectFBScreen::getImageFormat(surface); + QImage::Format pixelFormat = QDirectFBScreen::getImageFormat(surface); + d_ptr->alphaPixmapFormat = pixelFormat; - setPixelFormat(d_ptr->alphaPixmapFormat); - switch (d_ptr->alphaPixmapFormat) { + switch (pixelFormat) { case QImage::Format_RGB666: d_ptr->alphaPixmapFormat = QImage::Format_ARGB6666_Premultiplied; break; @@ -1040,9 +1040,9 @@ bool QDirectFBScreen::connect(const QString &displaySpec) d_ptr->alphaPixmapFormat = QImage::Format_ARGB4444_Premultiplied; break; case QImage::Format_RGB32: - qWarning("QDirectFBScreen::connect(). Qt/DirectFB does not work with the RGB32 pixelformat. " - "We recommmend using ARGB instead"); - return false; + pixelFormat = d_ptr->alphaPixmapFormat = QImage::Format_ARGB32_Premultiplied; + // ### Format_RGB32 doesn't work so well with Qt. Force ARGB32 for windows/pixmaps + break; case QImage::Format_Indexed8: qWarning("QDirectFBScreen::connect(). Qt/DirectFB does not work with the LUT8 pixelformat."); return false; @@ -1064,8 +1064,8 @@ bool QDirectFBScreen::connect(const QString &displaySpec) // works already break; } - - QScreen::d = ::depth(pixelFormat()); + setPixelFormat(pixelFormat); + QScreen::d = ::depth(pixelFormat); data = 0; lstep = 0; size = 0; diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp index ace4cb8..ef2dd5a 100644 --- a/src/svg/qsvggenerator.cpp +++ b/src/svg/qsvggenerator.cpp @@ -921,7 +921,8 @@ void QSvgPaintEngine::drawImage(const QRectF &r, const QImage &image, stream() << "x=\""<<r.x()<<"\" " "y=\""<<r.y()<<"\" " "width=\""<<r.width()<<"\" " - "height=\""<<r.height()<<"\" "; + "height=\""<<r.height()<<"\" " + "preserveAspectRatio=\"none\" "; QByteArray data; QBuffer buffer(&data); diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index a79e4a0..adfe468 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -2012,6 +2012,14 @@ static bool parseAimateMotionNode(QSvgNode *parent, return true; } +static void parseNumberTriplet(QVector<qreal> &values, const QChar *&s) +{ + QVector<qreal> list = parseNumbersList(s); + values << list; + for (int i = 3 - list.size(); i > 0; --i) + values.append(0.0); +} + static bool parseAnimateTransformNode(QSvgNode *parent, const QXmlStreamAttributes &attributes, QSvgHandler *handler) @@ -2025,28 +2033,47 @@ static bool parseAnimateTransformNode(QSvgNode *parent, QString fillStr = attributes.value(QLatin1String("fill")).toString(); QString fromStr = attributes.value(QLatin1String("from")).toString(); QString toStr = attributes.value(QLatin1String("to")).toString(); + QString byStr = attributes.value(QLatin1String("by")).toString(); + QString addtv = attributes.value(QLatin1String("additive")).toString(); + + QSvgAnimateTransform::Additive additive = QSvgAnimateTransform::Replace; + if (addtv == QLatin1String("sum")) + additive = QSvgAnimateTransform::Sum; QVector<qreal> vals; if (values.isEmpty()) { - const QChar *s = fromStr.constData(); - QVector<qreal> lst = parseNumbersList(s); - while (lst.count() < 3) - lst.append(0.0); - vals << lst; - - s = toStr.constData(); - lst = parseNumbersList(s); - while (lst.count() < 3) - lst.append(0.0); - vals << lst; + const QChar *s; + if (fromStr.isEmpty()) { + if (!byStr.isEmpty()) { + // By-animation. + additive = QSvgAnimateTransform::Sum; + vals.append(0.0); + vals.append(0.0); + vals.append(0.0); + parseNumberTriplet(vals, s = byStr.constData()); + } else { + // To-animation not defined. + return false; + } + } else { + if (!toStr.isEmpty()) { + // From-to-animation. + parseNumberTriplet(vals, s = fromStr.constData()); + parseNumberTriplet(vals, s = toStr.constData()); + } else if (!byStr.isEmpty()) { + // From-by-animation. + parseNumberTriplet(vals, s = fromStr.constData()); + parseNumberTriplet(vals, s = byStr.constData()); + for (int i = vals.size() - 3; i < vals.size(); ++i) + vals[i] += vals[i - 3]; + } else { + return false; + } + } } else { const QChar *s = values.constData(); while (s && *s != QLatin1Char(0)) { - QVector<qreal> tmpVals = parseNumbersList(s); - while (tmpVals.count() < 3) - tmpVals.append(0.0); - - vals << tmpVals; + parseNumberTriplet(vals, s); if (*s == QLatin1Char(0)) break; ++s; @@ -2088,7 +2115,7 @@ static bool parseAnimateTransformNode(QSvgNode *parent, } QSvgAnimateTransform *anim = new QSvgAnimateTransform(begin, end, 0); - anim->setArgs(type, vals); + anim->setArgs(type, additive, vals); anim->setFreeze(fillStr == QLatin1String("freeze")); anim->setRepeatCount( (repeatStr == QLatin1String("indefinite"))? -1 : diff --git a/src/svg/qsvgstyle.cpp b/src/svg/qsvgstyle.cpp index 1ecf870..e1a7049 100644 --- a/src/svg/qsvgstyle.cpp +++ b/src/svg/qsvgstyle.cpp @@ -509,10 +509,25 @@ void QSvgStyle::apply(QPainter *p, const QRectF &rect, QSvgNode *node, QSvgExtra //animated transforms have to be applied //_after_ the original object transformations if (!animateTransforms.isEmpty()) { - QList<QSvgRefCounter<QSvgAnimateTransform> >::const_iterator itr; - for (itr = animateTransforms.constBegin(); itr != animateTransforms.constEnd(); - ++itr) { - (*itr)->apply(p, rect, node, states); + qreal totalTimeElapsed = node->document()->currentElapsed(); + // Find the last animateTransform with additive="replace", since this will override all + // previous animateTransforms. + QList<QSvgRefCounter<QSvgAnimateTransform> >::const_iterator itr = animateTransforms.constEnd(); + do { + --itr; + if ((*itr)->animActive(totalTimeElapsed) + && (*itr)->additiveType() == QSvgAnimateTransform::Replace) { + // An animateTransform with additive="replace" will replace the transform attribute. + if (transform) + transform->revert(p, states); + break; + } + } while (itr != animateTransforms.constBegin()); + + // Apply the animateTransforms after and including the last one with additive="replace". + for (; itr != animateTransforms.constEnd(); ++itr) { + if ((*itr)->animActive(totalTimeElapsed)) + (*itr)->apply(p, rect, node, states); } } @@ -558,13 +573,15 @@ void QSvgStyle::revert(QPainter *p, QSvgExtraStates &states) //animated transforms need to be reverted _before_ //the native transforms if (!animateTransforms.isEmpty()) { - QList<QSvgRefCounter<QSvgAnimateTransform> >::const_iterator itr; - itr = animateTransforms.constBegin(); - //only need to rever the first one because that - //one has the original world matrix for the primitve - if (itr != animateTransforms.constEnd()) { - (*itr)->revert(p, states); + QList<QSvgRefCounter<QSvgAnimateTransform> >::const_iterator itr = animateTransforms.constBegin(); + for (; itr != animateTransforms.constEnd(); ++itr) { + if ((*itr)->transformApplied()) { + (*itr)->revert(p, states); + break; + } } + for (; itr != animateTransforms.constEnd(); ++itr) + (*itr)->clearTransformApplied(); } if (transform) { @@ -587,15 +604,16 @@ void QSvgStyle::revert(QPainter *p, QSvgExtraStates &states) QSvgAnimateTransform::QSvgAnimateTransform(int startMs, int endMs, int byMs ) : QSvgStyleProperty(), m_from(startMs), m_to(endMs), m_by(byMs), - m_type(Empty), m_count(0), m_finished(false) + m_type(Empty), m_count(0), m_finished(false), m_additive(Replace), m_transformApplied(false) { m_totalRunningTime = m_to - m_from; } -void QSvgAnimateTransform::setArgs(TransformType type, const QVector<qreal> &args) +void QSvgAnimateTransform::setArgs(TransformType type, Additive additive, const QVector<qreal> &args) { m_type = type; m_args = args; + m_additive = additive; Q_ASSERT(!(args.count()%3)); m_count = args.count() / 3; } @@ -604,15 +622,14 @@ void QSvgAnimateTransform::apply(QPainter *p, const QRectF &, QSvgNode *node, QS { m_oldWorldTransform = p->worldTransform(); resolveMatrix(node); - if (!m_finished || m_freeze) - p->setWorldTransform(m_transform, true); + p->setWorldTransform(m_transform, true); + m_transformApplied = true; } void QSvgAnimateTransform::revert(QPainter *p, QSvgExtraStates &) { - if (!m_finished || m_freeze) { - p->setWorldTransform(m_oldWorldTransform, false /* don't combine */); - } + p->setWorldTransform(m_oldWorldTransform, false /* don't combine */); + m_transformApplied = false; } void QSvgAnimateTransform::resolveMatrix(QSvgNode *node) @@ -622,11 +639,14 @@ void QSvgAnimateTransform::resolveMatrix(QSvgNode *node) if (totalTimeElapsed < m_from || m_finished) return; - qreal animationFrame = (totalTimeElapsed - m_from) / m_to; + qreal animationFrame = 0; + if (m_totalRunningTime != 0) { + animationFrame = (totalTimeElapsed - m_from) / m_totalRunningTime; - if (m_repeatCount >= 0 && m_repeatCount < animationFrame) { - m_finished = true; - animationFrame = m_repeatCount; + if (m_repeatCount >= 0 && m_repeatCount < animationFrame) { + m_finished = true; + animationFrame = m_repeatCount; + } } qreal percentOfAnimation = animationFrame; diff --git a/src/svg/qsvgstyle_p.h b/src/svg/qsvgstyle_p.h index c18a265..056b73b 100644 --- a/src/svg/qsvgstyle_p.h +++ b/src/svg/qsvgstyle_p.h @@ -250,7 +250,7 @@ public: { return m_style; } - + void setGradientId(const QString &Id) { m_gradientId = Id; @@ -529,20 +529,56 @@ public: SkewX, SkewY }; + enum Additive + { + Sum, + Replace + }; public: QSvgAnimateTransform(int startMs, int endMs, int by = 0); - void setArgs(TransformType type, const QVector<qreal> &args); + void setArgs(TransformType type, Additive additive, const QVector<qreal> &args); void setFreeze(bool freeze); void setRepeatCount(qreal repeatCount); virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states); virtual void revert(QPainter *p, QSvgExtraStates &states); virtual Type type() const; + QSvgAnimateTransform::Additive additiveType() const + { + return m_additive; + } + + bool animActive(qreal totalTimeElapsed) + { + if (totalTimeElapsed < m_from) + return false; + if (m_freeze || m_repeatCount < 0) // fill="freeze" or repeat="indefinite" + return true; + if (m_totalRunningTime == 0) + return false; + qreal animationFrame = (totalTimeElapsed - m_from) / m_totalRunningTime; + if (animationFrame > m_repeatCount) + return false; + return true; + } + + bool transformApplied() const + { + return m_transformApplied; + } + + // Call this instead of revert if you know that revert is unnecessary. + void clearTransformApplied() + { + m_transformApplied = false; + } + protected: void resolveMatrix(QSvgNode *node); private: qreal m_from, m_to, m_by; qreal m_totalRunningTime; TransformType m_type; + Additive m_additive; QVector<qreal> m_args; int m_count; QTransform m_transform; @@ -550,6 +586,7 @@ private: bool m_finished; bool m_freeze; qreal m_repeatCount; + bool m_transformApplied; }; diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index f19c94b..cc6fa88 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -45,44 +45,9 @@ #include <QtCore/qmetatype.h> #include <stdio.h> -QT_BEGIN_NAMESPACE +#include <private/qmetaobject_p.h> //for the flags. -// if the flags change, you MUST to change it in qmetaobject.cpp too -enum PropertyFlags { - Invalid = 0x00000000, - Readable = 0x00000001, - Writable = 0x00000002, - Resettable = 0x00000004, - EnumOrFlag = 0x00000008, - StdCppSet = 0x00000100, -// Override = 0x00000200, - Constant = 0x00000400, - Final = 0x00000800, - Designable = 0x00001000, - ResolveDesignable = 0x00002000, - Scriptable = 0x00004000, - ResolveScriptable = 0x00008000, - Stored = 0x00010000, - ResolveStored = 0x00020000, - Editable = 0x00040000, - ResolveEditable = 0x00080000, - User = 0x00100000, - ResolveUser = 0x00200000, - Notify = 0x00400000 -}; - -enum MethodFlags { - AccessPrivate = 0x00, - AccessProtected = 0x01, - AccessPublic = 0x02, - MethodMethod = 0x00, - MethodSignal = 0x04, - MethodSlot = 0x08, - MethodConstructor = 0x0c, - MethodCompatibility = 0x10, - MethodCloned = 0x20, - MethodScriptable = 0x40 -}; +QT_BEGIN_NAMESPACE uint qvariant_nameToType(const char* name) { @@ -205,10 +170,10 @@ void Generator::generateCode() QByteArray qualifiedClassNameIdentifier = cdef->qualified; qualifiedClassNameIdentifier.replace(':', '_'); - int index = 13; + int index = 14; fprintf(out, "static const uint qt_meta_data_%s[] = {\n", qualifiedClassNameIdentifier.constData()); fprintf(out, "\n // content:\n"); - fprintf(out, " %4d, // revision\n", 3); + fprintf(out, " %4d, // revision\n", 4); fprintf(out, " %4d, // classname\n", strreg(cdef->qualified)); fprintf(out, " %4d, %4d, // classinfo\n", cdef->classInfoList.count(), cdef->classInfoList.count() ? index : 0); index += cdef->classInfoList.count() * 2; @@ -229,6 +194,7 @@ void Generator::generateCode() isConstructible ? index : 0); fprintf(out, " %4d, // flags\n", 0); + fprintf(out, " %4d, // signalCount\n", cdef->signalList.count()); // @@ -1016,14 +982,7 @@ void Generator::generateSignal(FunctionDef *def,int index) else fprintf(out, ", const_cast<void*>(reinterpret_cast<const void*>(&_t%d))", i); fprintf(out, " };\n"); - int n = 0; - for (i = 0; i < def->arguments.count(); ++i) - if (def->arguments.at(i).isDefault) - ++n; - if (n) - fprintf(out, " QMetaObject::activate(%s, &staticMetaObject, %d, %d, _a);\n", thisPtr.constData(), index, index + n); - else - fprintf(out, " QMetaObject::activate(%s, &staticMetaObject, %d, _a);\n", thisPtr.constData(), index); + fprintf(out, " QMetaObject::activate(%s, &staticMetaObject, %d, _a);\n", thisPtr.constData(), index); if (def->normalizedType.size()) fprintf(out, " return _t0;\n"); fprintf(out, "}\n"); diff --git a/src/xmlpatterns/parser/createTokenLookup.sh b/src/xmlpatterns/parser/createTokenLookup.sh index a4e1eff..f84ee72 100755 --- a/src/xmlpatterns/parser/createTokenLookup.sh +++ b/src/xmlpatterns/parser/createTokenLookup.sh @@ -1,5 +1,50 @@ +#!/bin/sh outFile="qtokenlookup.cpp" +license=`cat <<EOF +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtXmlPatterns module of the Qt Toolkit. +** +** \\$QT_BEGIN_LICENSE:LGPL\\$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, 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.0, 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** \\$QT_END_LICENSE\\$ +** +****************************************************************************/ +EOF` +echo "$license" > $outFile + # Watch out, the --output option is not supported in the # gperf version that apt-get pulls in on Mac OS X. -gperf TokenLookup.gperf > $outFile +gperf TokenLookup.gperf >> $outFile diff --git a/src/xmlpatterns/parser/qtokenlookup.cpp b/src/xmlpatterns/parser/qtokenlookup.cpp index 6e9c343..6bd1121 100644 --- a/src/xmlpatterns/parser/qtokenlookup.cpp +++ b/src/xmlpatterns/parser/qtokenlookup.cpp @@ -1,4 +1,44 @@ -/* C++ code produced by gperf version 3.0.2 */ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtXmlPatterns module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, 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.0, 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ +/* C++ code produced by gperf version 3.0.3 */ /* Command-line: gperf TokenLookup.gperf */ /* Computed positions: -k'1,3,$' */ @@ -29,7 +69,7 @@ #error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>." #endif -#line 80 "TokenLookup.gperf" +#line 107 "TokenLookup.gperf" QT_BEGIN_NAMESPACE @@ -37,7 +77,7 @@ QT_BEGIN_NAMESPACE namespace QPatternist { -#line 74 "TokenLookup.gperf" +#line 101 "TokenLookup.gperf" struct TokenMap { const char *name; @@ -120,255 +160,255 @@ TokenLookup::value (register const char *str, register unsigned int len) static const struct TokenMap wordlist[] = { {"",ERROR}, {"",ERROR}, -#line 125 "TokenLookup.gperf" +#line 152 "TokenLookup.gperf" {"eq", EQ}, {"",ERROR}, -#line 103 "TokenLookup.gperf" +#line 130 "TokenLookup.gperf" {"by", BY}, -#line 126 "TokenLookup.gperf" +#line 153 "TokenLookup.gperf" {"every", EVERY}, {"",ERROR}, -#line 96 "TokenLookup.gperf" +#line 123 "TokenLookup.gperf" {"as", AS}, {"",ERROR}, -#line 121 "TokenLookup.gperf" +#line 148 "TokenLookup.gperf" {"else", ELSE}, -#line 190 "TokenLookup.gperf" +#line 217 "TokenLookup.gperf" {"where", WHERE}, -#line 177 "TokenLookup.gperf" +#line 204 "TokenLookup.gperf" {"stable", STABLE}, -#line 99 "TokenLookup.gperf" +#line 126 "TokenLookup.gperf" {"at", AT}, {"",ERROR}, -#line 104 "TokenLookup.gperf" +#line 131 "TokenLookup.gperf" {"case", CASE}, {"",ERROR}, -#line 102 "TokenLookup.gperf" +#line 129 "TokenLookup.gperf" {"boundary-space", BOUNDARY_SPACE}, -#line 120 "TokenLookup.gperf" +#line 147 "TokenLookup.gperf" {"element", ELEMENT}, -#line 105 "TokenLookup.gperf" +#line 132 "TokenLookup.gperf" {"castable", CASTABLE}, -#line 100 "TokenLookup.gperf" +#line 127 "TokenLookup.gperf" {"attribute", ATTRIBUTE}, {"",ERROR}, -#line 127 "TokenLookup.gperf" +#line 154 "TokenLookup.gperf" {"except", EXCEPT}, -#line 134 "TokenLookup.gperf" +#line 161 "TokenLookup.gperf" {"ge", GE}, {"",ERROR}, -#line 106 "TokenLookup.gperf" +#line 133 "TokenLookup.gperf" {"cast", CAST}, -#line 183 "TokenLookup.gperf" +#line 210 "TokenLookup.gperf" {"treat", TREAT}, -#line 191 "TokenLookup.gperf" +#line 218 "TokenLookup.gperf" {"xquery", XQUERY}, -#line 154 "TokenLookup.gperf" +#line 181 "TokenLookup.gperf" {"ne", NE}, {"",ERROR}, -#line 171 "TokenLookup.gperf" +#line 198 "TokenLookup.gperf" {"satisfies", SATISFIES}, {"",ERROR}, {"",ERROR}, -#line 136 "TokenLookup.gperf" +#line 163 "TokenLookup.gperf" {"gt", GT}, -#line 124 "TokenLookup.gperf" +#line 151 "TokenLookup.gperf" {"encoding", ENCODING}, -#line 97 "TokenLookup.gperf" +#line 124 "TokenLookup.gperf" {"ascending", ASCENDING}, {"",ERROR}, -#line 98 "TokenLookup.gperf" +#line 125 "TokenLookup.gperf" {"assign", ASSIGN}, -#line 112 "TokenLookup.gperf" +#line 139 "TokenLookup.gperf" {"declare", DECLARE}, -#line 135 "TokenLookup.gperf" +#line 162 "TokenLookup.gperf" {"greatest", GREATEST}, -#line 181 "TokenLookup.gperf" +#line 208 "TokenLookup.gperf" {"then", THEN}, {"",ERROR}, -#line 94 "TokenLookup.gperf" +#line 121 "TokenLookup.gperf" {"ancestor-or-self", ANCESTOR_OR_SELF}, -#line 148 "TokenLookup.gperf" +#line 175 "TokenLookup.gperf" {"le", LE}, -#line 119 "TokenLookup.gperf" +#line 146 "TokenLookup.gperf" {"document-node", DOCUMENT_NODE}, -#line 180 "TokenLookup.gperf" +#line 207 "TokenLookup.gperf" {"text", TEXT}, {"",ERROR}, -#line 174 "TokenLookup.gperf" +#line 201 "TokenLookup.gperf" {"schema", SCHEMA}, {"",ERROR}, -#line 118 "TokenLookup.gperf" +#line 145 "TokenLookup.gperf" {"document", DOCUMENT}, {"",ERROR}, -#line 114 "TokenLookup.gperf" +#line 141 "TokenLookup.gperf" {"descendant", DESCENDANT}, {"",ERROR}, -#line 150 "TokenLookup.gperf" +#line 177 "TokenLookup.gperf" {"lt", LT}, -#line 95 "TokenLookup.gperf" +#line 122 "TokenLookup.gperf" {"and", AND}, -#line 155 "TokenLookup.gperf" +#line 182 "TokenLookup.gperf" {"node", NODE}, -#line 147 "TokenLookup.gperf" +#line 174 "TokenLookup.gperf" {"least", LEAST}, -#line 172 "TokenLookup.gperf" +#line 199 "TokenLookup.gperf" {"schema-attribute", SCHEMA_ATTRIBUTE}, {"",ERROR}, -#line 128 "TokenLookup.gperf" +#line 155 "TokenLookup.gperf" {"external", EXTERNAL}, {"",ERROR}, -#line 116 "TokenLookup.gperf" +#line 143 "TokenLookup.gperf" {"descending", DESCENDING}, -#line 157 "TokenLookup.gperf" +#line 184 "TokenLookup.gperf" {"no-preserve", NO_PRESERVE}, -#line 113 "TokenLookup.gperf" +#line 140 "TokenLookup.gperf" {"default", DEFAULT}, -#line 149 "TokenLookup.gperf" +#line 176 "TokenLookup.gperf" {"let", LET}, -#line 173 "TokenLookup.gperf" +#line 200 "TokenLookup.gperf" {"schema-element", SCHEMA_ELEMENT}, {"",ERROR}, {"",ERROR}, -#line 110 "TokenLookup.gperf" +#line 137 "TokenLookup.gperf" {"construction", CONSTRUCTION}, -#line 115 "TokenLookup.gperf" +#line 142 "TokenLookup.gperf" {"descendant-or-self", DESCENDANT_OR_SELF}, -#line 175 "TokenLookup.gperf" +#line 202 "TokenLookup.gperf" {"self", SELF}, -#line 156 "TokenLookup.gperf" +#line 183 "TokenLookup.gperf" {"no-inherit", NO_INHERIT}, {"",ERROR}, -#line 131 "TokenLookup.gperf" +#line 158 "TokenLookup.gperf" {"follows", FOLLOWS}, -#line 93 "TokenLookup.gperf" +#line 120 "TokenLookup.gperf" {"ancestor", ANCESTOR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, -#line 182 "TokenLookup.gperf" +#line 209 "TokenLookup.gperf" {"to", TO}, -#line 133 "TokenLookup.gperf" +#line 160 "TokenLookup.gperf" {"function", FUNCTION}, -#line 108 "TokenLookup.gperf" +#line 135 "TokenLookup.gperf" {"collation", COLLATION}, {"",ERROR}, -#line 178 "TokenLookup.gperf" +#line 205 "TokenLookup.gperf" {"strict", STRICT}, {"",ERROR}, -#line 146 "TokenLookup.gperf" +#line 173 "TokenLookup.gperf" {"lax", LAX}, {"",ERROR}, -#line 122 "TokenLookup.gperf" +#line 149 "TokenLookup.gperf" {"empty", EMPTY}, {"",ERROR}, -#line 158 "TokenLookup.gperf" +#line 185 "TokenLookup.gperf" {"of", OF}, -#line 168 "TokenLookup.gperf" +#line 195 "TokenLookup.gperf" {"preserve", PRESERVE}, -#line 129 "TokenLookup.gperf" +#line 156 "TokenLookup.gperf" {"following", FOLLOWING}, {"",ERROR}, {"",ERROR}, -#line 144 "TokenLookup.gperf" +#line 171 "TokenLookup.gperf" {"is", IS}, -#line 165 "TokenLookup.gperf" +#line 192 "TokenLookup.gperf" {"precedes", PRECEDES}, -#line 123 "TokenLookup.gperf" +#line 150 "TokenLookup.gperf" {"empty-sequence", EMPTY_SEQUENCE}, {"",ERROR}, {"",ERROR}, -#line 130 "TokenLookup.gperf" +#line 157 "TokenLookup.gperf" {"following-sibling", FOLLOWING_SIBLING}, -#line 142 "TokenLookup.gperf" +#line 169 "TokenLookup.gperf" {"instance", INSTANCE}, -#line 186 "TokenLookup.gperf" +#line 213 "TokenLookup.gperf" {"unordered", UNORDERED}, -#line 101 "TokenLookup.gperf" +#line 128 "TokenLookup.gperf" {"base-uri", BASEURI}, -#line 170 "TokenLookup.gperf" +#line 197 "TokenLookup.gperf" {"return", RETURN}, {"",ERROR}, -#line 187 "TokenLookup.gperf" +#line 214 "TokenLookup.gperf" {"validate", VALIDATE}, {"",ERROR}, -#line 111 "TokenLookup.gperf" +#line 138 "TokenLookup.gperf" {"copy-namespaces", COPY_NAMESPACES}, -#line 159 "TokenLookup.gperf" +#line 186 "TokenLookup.gperf" {"option", OPTION}, -#line 138 "TokenLookup.gperf" +#line 165 "TokenLookup.gperf" {"if", IF}, {"",ERROR}, -#line 166 "TokenLookup.gperf" +#line 193 "TokenLookup.gperf" {"preceding", PRECEDING}, {"",ERROR}, {"",ERROR}, -#line 141 "TokenLookup.gperf" +#line 168 "TokenLookup.gperf" {"in", IN}, {"",ERROR}, -#line 143 "TokenLookup.gperf" +#line 170 "TokenLookup.gperf" {"intersect", INTERSECT}, -#line 185 "TokenLookup.gperf" +#line 212 "TokenLookup.gperf" {"union", UNION}, {"",ERROR}, -#line 167 "TokenLookup.gperf" +#line 194 "TokenLookup.gperf" {"preceding-sibling", PRECEDING_SIBLING}, -#line 161 "TokenLookup.gperf" +#line 188 "TokenLookup.gperf" {"ordering", ORDERING}, -#line 176 "TokenLookup.gperf" +#line 203 "TokenLookup.gperf" {"some", SOME}, -#line 107 "TokenLookup.gperf" +#line 134 "TokenLookup.gperf" {"child", CHILD}, {"",ERROR}, -#line 160 "TokenLookup.gperf" +#line 187 "TokenLookup.gperf" {"ordered", ORDERED}, -#line 188 "TokenLookup.gperf" +#line 215 "TokenLookup.gperf" {"variable", VARIABLE}, {"",ERROR}, {"",ERROR}, {"",ERROR}, -#line 163 "TokenLookup.gperf" +#line 190 "TokenLookup.gperf" {"or", OR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, -#line 109 "TokenLookup.gperf" +#line 136 "TokenLookup.gperf" {"comment", COMMENT}, {"",ERROR}, {"",ERROR}, -#line 184 "TokenLookup.gperf" +#line 211 "TokenLookup.gperf" {"typeswitch", TYPESWITCH}, {"",ERROR}, -#line 140 "TokenLookup.gperf" +#line 167 "TokenLookup.gperf" {"inherit", INHERIT}, -#line 117 "TokenLookup.gperf" +#line 144 "TokenLookup.gperf" {"div", DIV}, {"",ERROR}, {"",ERROR}, -#line 152 "TokenLookup.gperf" +#line 179 "TokenLookup.gperf" {"module", MODULE}, {"",ERROR}, -#line 132 "TokenLookup.gperf" +#line 159 "TokenLookup.gperf" {"for", FOR}, -#line 153 "TokenLookup.gperf" +#line 180 "TokenLookup.gperf" {"namespace", NAMESPACE}, {"",ERROR}, {"",ERROR}, -#line 189 "TokenLookup.gperf" +#line 216 "TokenLookup.gperf" {"version", VERSION}, {"",ERROR}, {"",ERROR}, -#line 179 "TokenLookup.gperf" +#line 206 "TokenLookup.gperf" {"strip", STRIP}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, -#line 162 "TokenLookup.gperf" +#line 189 "TokenLookup.gperf" {"order", ORDER}, -#line 164 "TokenLookup.gperf" +#line 191 "TokenLookup.gperf" {"parent", PARENT}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, -#line 151 "TokenLookup.gperf" +#line 178 "TokenLookup.gperf" {"mod", MOD}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, -#line 139 "TokenLookup.gperf" +#line 166 "TokenLookup.gperf" {"import", IMPORT}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, -#line 169 "TokenLookup.gperf" +#line 196 "TokenLookup.gperf" {"processing-instruction", PROCESSING_INSTRUCTION}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, -#line 145 "TokenLookup.gperf" +#line 172 "TokenLookup.gperf" {"item", ITEM}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, @@ -378,7 +418,7 @@ TokenLookup::value (register const char *str, register unsigned int len) {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, {"",ERROR}, -#line 137 "TokenLookup.gperf" +#line 164 "TokenLookup.gperf" {"idiv", IDIV} }; @@ -396,7 +436,7 @@ TokenLookup::value (register const char *str, register unsigned int len) } return 0; } -#line 192 "TokenLookup.gperf" +#line 219 "TokenLookup.gperf" } /* Close the QPatternist namespace. */ |