From 0d00798f6bdd098dbb59c6f1da5be5efd6c283fa Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Tue, 24 Mar 2009 11:07:00 +1000 Subject: Squashed commit of the following: commit 39de3862f5678b3226b4932eeb342c4a023d2f2b Author: Ian Walters Date: Thu Feb 19 14:16:05 2009 +1000 Fixes: Test runs (and passes), doc links. Task: QT-308 Details: Minor changes related to the code having moved. commit 5a8910dd1018fb228d0e2e2819ea429577bfa834 Author: Ian Walters Date: Thu Feb 19 09:47:20 2009 +1000 Fixes: Checkin of QOffsetVector stuff for branch Task: QT-308 Details: Files originally from research/qcircularbuffer This checkin likely won't compile. Just a copy for now. --- doc/src/examples/offsetvector.qdoc | 70 +++++ examples/tools/offsetvector/main.cpp | 15 + examples/tools/offsetvector/offsetvector.pro | 9 + examples/tools/offsetvector/randomlistmodel.cpp | 56 ++++ examples/tools/offsetvector/randomlistmodel.h | 26 ++ examples/tools/tools.pro | 1 + src/corelib/tools/qoffsetvector.cpp | 360 ++++++++++++++++++++++ src/corelib/tools/qoffsetvector.h | 386 ++++++++++++++++++++++++ src/corelib/tools/tools.pri | 2 + tests/auto/auto.pro | 1 + tests/auto/qoffsetvector/qoffsetvector.pro | 8 + tests/auto/qoffsetvector/tst_qoffsetvector.cpp | 361 ++++++++++++++++++++++ 12 files changed, 1295 insertions(+) create mode 100644 doc/src/examples/offsetvector.qdoc create mode 100644 examples/tools/offsetvector/main.cpp create mode 100644 examples/tools/offsetvector/offsetvector.pro create mode 100644 examples/tools/offsetvector/randomlistmodel.cpp create mode 100644 examples/tools/offsetvector/randomlistmodel.h create mode 100644 src/corelib/tools/qoffsetvector.cpp create mode 100644 src/corelib/tools/qoffsetvector.h create mode 100644 tests/auto/qoffsetvector/qoffsetvector.pro create mode 100644 tests/auto/qoffsetvector/tst_qoffsetvector.cpp diff --git a/doc/src/examples/offsetvector.qdoc b/doc/src/examples/offsetvector.qdoc new file mode 100644 index 0000000..256569e --- /dev/null +++ b/doc/src/examples/offsetvector.qdoc @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +/*! + \example tools/offsetvector + \title Offset Vector Example + + The Offset Vector example shows how to use QOffsetVector to manage memory usage for + very large models. In some environments memory is limited, and even when it + isn't users still dislike an application using + excessive memory. Using QOffsetVector to manage a list rather than loading + the entire list into memory allows the application to limit the amount + of memory it uses regardless of the size of the data set it accesses + + The simplest way to use QOffsetVector is to cache as items are requested. When + a view requests an item at row N it is also likely to ask for items at rows near + to N. + + \snippet examples/tools/offsetvector/randomlistmodel.cpp 0 + + After getting the row the class determines if the row is in the bounds + of the offset vector's current range. It would have been equally valid to + simply have the following code instead. + + \code + while (row > m_words.lastIndex()) + m_words.append(fetchWord(m_words.lastIndex()+1); + while (row < m_words.firstIndex()) + m_words.prepend(fetchWord(m_words.firstIndex()-1); + \endcode + + However a list will often jump rows if the scroll bar is used directly, and + the above code would cause every row between where the cache was last centered + to where the cache is currently centered to be cached before the requested + row is reached. + + Using QOffsetVector::lastIndex() and QOffsetVector::firstIndex() allows + the example to determine where the list the vector is currently over. These values + don't represent the indexes into the vector own memory, but rather a virtual + infinite array that the vector represents. + + By using QOffsetVector::append() and QOffsetVector::prepend() the code ensures + that items that may be still on the screen are not lost when the requested row + has not moved far from the current vector range. QOffsetVector::insert() can + potentially remove more than one item from the cache as QOffsetVector does not + allow for gaps. If your cache needs to quickly jump back and forth between + rows with significant gaps between them consider using QCache instead. + + And thats it. A perfectly reasonable cache, using minimal memory for a very large + list. In this case the accessor for getting the words into cache: + + \snippet examples/tools/offsetvector/randomlistmodel.cpp 1 + + Generates random information rather than fixed information. This allows you + to see how the cache range is kept for a local number of rows when running the + example. + + It is also worth considering pre-fetching items into the cache outside of the + applications paint routine. This can be done either with a separate thread + or using a QTimer to incrementally expand the range of the thread prior to + rows being requested out of the current vector range. +*/ diff --git a/examples/tools/offsetvector/main.cpp b/examples/tools/offsetvector/main.cpp new file mode 100644 index 0000000..bdeb3f3 --- /dev/null +++ b/examples/tools/offsetvector/main.cpp @@ -0,0 +1,15 @@ +#include "randomlistmodel.h" +#include +#include + +int main(int c, char **v) +{ + QApplication a(c, v); + + QListView view; + view.setUniformItemSizes(true); + view.setModel(new RandomListModel(&view)); + view.show(); + + return a.exec(); +} diff --git a/examples/tools/offsetvector/offsetvector.pro b/examples/tools/offsetvector/offsetvector.pro new file mode 100644 index 0000000..f329bb9 --- /dev/null +++ b/examples/tools/offsetvector/offsetvector.pro @@ -0,0 +1,9 @@ +HEADERS = randomlistmodel.h +SOURCES = randomlistmodel.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tools/offsetvector +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS offsetvector.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tools/offsetvector +INSTALLS += target sources diff --git a/examples/tools/offsetvector/randomlistmodel.cpp b/examples/tools/offsetvector/randomlistmodel.cpp new file mode 100644 index 0000000..5c0953b --- /dev/null +++ b/examples/tools/offsetvector/randomlistmodel.cpp @@ -0,0 +1,56 @@ +#include "randomlistmodel.h" + +static const int bufferSize(500); +static const int lookAhead(100); +static const int halfLookAhead(lookAhead/2); + +RandomListModel::RandomListModel(QObject *parent) +: QAbstractListModel(parent), m_rows(bufferSize), m_count(10000) +{ +} + +RandomListModel::~RandomListModel() +{ +} + +int RandomListModel::rowCount(const QModelIndex &) const +{ + return m_count; +} + +//! [0] +QVariant RandomListModel::data(const QModelIndex &index, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + int row = index.row(); + + if (row > m_rows.lastIndex()) { + if (row - m_rows.lastIndex() > lookAhead) + cacheRows(row-halfLookAhead, qMin(m_count, row+halfLookAhead)); + else while (row > m_rows.lastIndex()) + m_rows.append(fetchRow(m_rows.lastIndex()+1)); + } else if (row < m_rows.firstIndex()) { + if (m_rows.firstIndex() - row > lookAhead) + cacheRows(qMax(0, row-halfLookAhead), row+halfLookAhead); + else while (row < m_rows.firstIndex()) + m_rows.prepend(fetchRow(m_rows.firstIndex()-1)); + } + + return m_rows.at(row); +} + +void RandomListModel::cacheRows(int from, int to) const +{ + for (int i = from; i <= to; ++i) + m_rows.insert(i, fetchRow(i)); +} +//![0] + +//![1] +QString RandomListModel::fetchRow(int position) const +{ + return QString::number(rand() % ++position); +} +//![1] diff --git a/examples/tools/offsetvector/randomlistmodel.h b/examples/tools/offsetvector/randomlistmodel.h new file mode 100644 index 0000000..e102255 --- /dev/null +++ b/examples/tools/offsetvector/randomlistmodel.h @@ -0,0 +1,26 @@ +#ifndef RANDOMLISTMODEL_H +#define RANDOMLISTMODEL_H + +#include +#include + +class QTimer; +class RandomListModel : public QAbstractListModel +{ + Q_OBJECT +public: + RandomListModel(QObject *parent = 0); + ~RandomListModel(); + + int rowCount(const QModelIndex & = QModelIndex()) const; + QVariant data(const QModelIndex &, int) const; + +private: + void cacheRows(int, int) const; + QString fetchRow(int) const; + + mutable QOffsetVector m_rows; + const int m_count; +}; + +#endif diff --git a/examples/tools/tools.pro b/examples/tools/tools.pro index 79f0faa..424f286 100644 --- a/examples/tools/tools.pro +++ b/examples/tools/tools.pro @@ -5,6 +5,7 @@ SUBDIRS = codecs \ customcompleter \ echoplugin \ i18n \ + offsetvector \ plugandpaintplugins \ plugandpaint \ regexp \ diff --git a/src/corelib/tools/qoffsetvector.cpp b/src/corelib/tools/qoffsetvector.cpp new file mode 100644 index 0000000..32d2872 --- /dev/null +++ b/src/corelib/tools/qoffsetvector.cpp @@ -0,0 +1,360 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#include "qoffsetvector.h" +#include + +void QOffsetVectorData::dump() const +{ + qDebug() << "capacity:" << alloc; + qDebug() << "count:" << count; + qDebug() << "start:" << start; + qDebug() << "offset:" << offset; +} + +/*! \class QOffsetVector + \brief The QOffsetVector class is a template class that provides a offset vector. + \ingroup tools + \ingroup shared + \reentrant + + The QOffsetVector class provides an efficient way of caching items for + display in a user interface view. It does this by providing a window + into a theoretical infinite sized vector. This has the advantage that + it matches how user interface views most commonly request the data, in + a set of rows localized around the current scrolled position. It also + allows the cache to use less overhead than QCache both in terms of + performance and memory. In turn, unlike a QCache, the key has to be + an int and has to be contiguous. That is to say if an item is inserted + at index 85, then if there were no previous items at 84 or 86 then the + cache will be cleared before the new item at 85 is inserted. If this + restriction is not suitable consider using QCache instead. + + The simplest way of using an offset vector is to use the append() + and prepend() functions to slide the window to where it is needed. + +\code +MyRecord record(int row) const +{ + Q_ASSERT(row >= 0 && row < count()); + + while(row > cache.lastIndex()) + cache.append(slowFetchRecord(cache.lastIndex()+1)); + while(row < cache.firstIndex()) + cache.prepend(slowFetchRecord(cache.firstIndex()-1)); + + return cache.at(row); +} +\endcode + + The append() and prepend() functions cause the vector window to move to + where the current row is requested from. This usage can be further + optimized by using the insert() function to reset the vector window to + a row in the case where the row is a long way from the current row. It + may also be worth while to fetch multiple records into the cache if + it is faster to retrieve them in a batch operation. + + See the The \l{Offset Vector Example}{Offset Vector} example. +*/ + +/*! \fn QOffsetVector::QOffsetVector(int capacity) + + Constructs a vector with the given \a capacity. + + \sa setCapacity() +*/ + +/*! \fn QOffsetVector::QOffsetVector(const QOffsetVector &other) + + Constructs a copy of \a other. + + This operation takes \l{constant time}, because QOffsetVector is + \l{implicitly shared}. This makes returning a QOffsetVector from a + function very fast. If a shared instance is modified, it will be + copied (copy-on-write), and that takes \l{linear time}. + + \sa operator=() +*/ + +/*! \fn QOffsetVector::~QOffsetVector() + Destorys the vector. +*/ + +/*! \fn void QOffsetVector::detach() + + \internal +*/ + +/*! \fn bool QOffsetVector::isDetached() const + + \internal +*/ + +/*! \fn void QOffsetVector::setSharable(bool sharable) + + \internal +*/ + + +/*! \fn QOffsetVector &QOffsetVector::operator=(const QOffsetVector &other) + + Assigns \a other to this vector and returns a reference to this vector. +*/ + +/*! \fn bool QOffsetVector::operator==(const QOffsetVector &other) const + + Returns true if \a other is equal to this vector; otherwise returns false. + + Two vectors are considered equal if they contain the same values at the same + indexes. This function requires the value type to implement the \c operator==(). + + \sa operator!=() +*/ + +/*! \fn bool QOffsetVector::operator!=(const QOffsetVector &other) const + + Returns true if \a other is not equal to this vector; otherwise + returns false. + + Two vector are considered equal if they contain the same values at the same + indexes. This function requires the value type to implement the \c operator==(). + + \sa operator==() +*/ + +/*! \fn int QOffsetVector::capacity() const + + Returns the number of items the vector can store before it is full. + When a vector contains a number of items equal to its capacity, adding new + items will cause items furthest from the added item to be removed. + + \sa setCapacity(), size() +*/ + +/*! \fn int QOffsetVector::count() const + + \overload + + Same as size(). +*/ + +/*! \fn int QOffsetVector::size() const + + Returns the number of items contained within the vector. + + \sa capacity() +*/ + +/*! \fn bool QOffsetVector::isEmpty() const + + Returns true if no items are stored within the vector. + + \sa size(), capacity() +*/ + +/*! \fn bool QOffsetVector::isFull() const + + Returns true if the number of items stored within the vector is equal + to the capacity of the vector. + + \sa size(), capacity() +*/ + +/*! \fn int QOffsetVector::available() const + + Returns the number of items that can be added to the vector before it becomes full. + + \sa size(), capacity(), isFull() +*/ + +/*! \fn void QOffsetVector::clear() + + Removes all items from the vector. The capacity is unchanged. +*/ + +/*! \fn void QOffsetVector::setCapacity(int size) + + Sets the capacity of the vector to the given \a size. A vector can hold a + number of items equal to its capacity. When inserting, appending or prepending + items to the vector, if the vector is already full then the item furthest from + the added item will be removed. + + If the given \a size is smaller than the current count of items in the vector + then only the last \a size items from the vector will remain. + + \sa capacity(), isFull() +*/ + +/*! \fn const T &QOffsetVector::at(int i) const + + Returns the item at index position \a i in the vector. \a i must + be a valid index position in the vector (i.e, firstIndex() <= \a i <= lastIndex()). + + The indexes in the vector refer to number of positions the item is from the + first item appended into the vector. That is to say a vector with a capacity of + 100, that has had 150 items appended will have a valid index range of + 50 to 149. This allows inserting an retrieving items into the vector based + on a theoretical infinite list + + \sa firstIndex(), lastIndex(), insert(), operator[]() +*/ + +/*! \fn T &QOffsetVector::operator[](int i) + + Returns the item at index position \a i as a modifiable reference. If + the vector does not contain an item at the given index position \a i + then it will first insert an empty item at that position. + + In most cases it is better to use either at() or insert(). + + Note that using non-const operators can cause QOffsetVector to do a deep + copy. + + \sa insert(), at() +*/ + +/*! \fn const T &QOffsetVector::operator[](int i) const + + \overload + + Same as at(\a i). +*/ + +/*! \fn void QOffsetVector::append(const T &value) + + Inserts \a value at the end of the vector. If the vector is already full + the item at the start of the vector will be removed. + + \sa prepend(), insert(), isFull() +*/ + +/*! \fn void QOffsetVector::prepend(const T &value) + + Inserts \a value at the start of the vector. If the vector is already full + the item at the end of the vector will be removed. + + \sa append(), insert(), isFull() +*/ + +/*! \fn void QOffsetVector::insert(int i, const T &value) + + Inserts the \a value at the index position \a i. If the vector already contains + an item at \a i then that value is replaced. If \a i is either one more than + lastIndex() or one less than firstIndex() it is the equivalent to an append() + or a prepend(). + + If the given index \a i is not within the current range of the vector nor adjacent + to the bounds of the vector's index range the vector is first cleared before + inserting the item. At this point the vector will have a size of 1. It is worth + while then taking effort to insert items in an order than starts adjacent to the + current index range for the vector. + + \sa prepend(), append(), isFull(), firstIndex(), lastIndex() +*/ + +/*! \fn bool QOffsetVector::containsIndex(int i) const + + Returns true if the vector's index range includes the given index \a i. + + \sa firstIndex(), lastIndex() +*/ + +/*! \fn int QOffsetVector::firstIndex() const + Returns the first valid index in the vector. The index will be invalid if the + vector is empty. However the following code is valid even when the vector is empty: + + \code + for (int i = vector.firstIndex(); i <= vector.lastIndex(); ++i) + qDebug() << "Item" << i << "of the vector is" << vector.at(i); + \endcode + + \sa capacity(), size(), lastIndex() +*/ + +/*! \fn int QOffsetVector::lastIndex() const + + Returns the last valid index in the vector. If the vector is empty will return -1. + + \code + for (int i = vector.firstIndex(); i <= vector.lastIndex(); ++i) + qDebug() << "Item" << i << "of the vector is" << vector.at(i); + \endcode + + \sa capacity(), size(), firstIndex() +*/ + + +/*! \fn T &QOffsetVector::first() + + Returns a reference to the first item in the vector. This function + assumes that the vector isn't empty. + + \sa last(), isEmpty() +*/ + +/*! \fn T &QOffsetVector::last() + + Returns a reference to the last item in the vector. This function + assumes that the vector isn't empty. + + \sa first(), isEmpty() +*/ + +/*! \fn const T& QOffsetVector::first() const + + \overload +*/ + +/*! \fn const T& QOffsetVector::last() const + + \overload +*/ + +/*! \fn void QOffsetVector::removeFirst() + + Removes the first item from the vector. This function assumes that + the vector isn't empty. + + \sa removeLast() +*/ + +/*! \fn void QOffsetVector::removeLast() + + Removes the last item from the vector. This function assumes that + the vector isn't empty. + + \sa removeFirst() +*/ + +/*! \fn T QOffsetVector::takeFirst() + + Removes the first item in the vector and returns it. + + If you don't sue the return value, removeFirst() is more efficient. + + \sa takeLast(), removeFirst() +*/ + +/*! \fn T QOffsetVector::takeLast() + + Removes the last item in the vector and returns it. + + If you don't sue the return value, removeLast() is more efficient. + + \sa takeFirst(), removeLast() +*/ + +/*! \fn void QOffsetVector::dump() const + + \internal + + Sends information about the vector's internal structure to qDebug() +*/ diff --git a/src/corelib/tools/qoffsetvector.h b/src/corelib/tools/qoffsetvector.h new file mode 100644 index 0000000..7030862 --- /dev/null +++ b/src/corelib/tools/qoffsetvector.h @@ -0,0 +1,386 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#ifndef QCIRCULARBUFFER_H +#define QCIRCULARBUFFER_H + +#include + +struct QOffsetVectorData +{ + QBasicAtomicInt ref; + int alloc; + int count; + int start; + int offset; + uint sharable : 1; + + void dump() const; +}; + +template +struct QOffsetVectorTypedData +{ + QBasicAtomicInt ref; + int alloc; + int count; + int start; + int offset; + uint sharable : 1; + + T array[1]; +}; + +class QOffsetVectorDevice; + +template +class QOffsetVector { + typedef QOffsetVectorTypedData Data; + union { QOffsetVectorData *p; QOffsetVectorTypedData *d; }; +public: + explicit QOffsetVector(int capacity = 0); + QOffsetVector(const QOffsetVector &v) : d(v.d) { d->ref.ref(); if (!d->sharable) detach_helper(); } + + inline ~QOffsetVector() { if (!d) return; if (!d->ref.deref()) free(d); } + + inline void detach() { if (d->ref != 1) detach_helper(); } + inline bool isDetached() const { return d->ref == 1; } + inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; } + + QOffsetVector &operator=(const QOffsetVector &other); + bool operator==(const QOffsetVector &other) const; + inline bool operator!=(const QOffsetVector &other) const { return !(*this == other); } + + inline int capacity() const {return d->alloc; } + inline int count() const { return d->count; } + inline int size() const { return d->count; } + + inline bool isEmpty() const { return d->count == 0; } + inline bool isFull() const { return d->count == d->alloc; } + inline int available() const { return d->alloc - d->count; } + + void clear(); + void setCapacity(int size); + + const T &at(int pos) const; + T &operator[](int i); + const T &operator[](int i) const; + + void append(const T &value); + void prepend(const T &value); + void insert(int pos, const T &value); + + inline bool containsIndex(int pos) const { return pos >= d->offset && pos - d->offset < d->count; } + inline int firstIndex() const { return d->offset; } + inline int lastIndex() const { return d->offset + d->count - 1; } + + inline const T &first() const { Q_ASSERT(!isEmpty()); return d->array[d->start]; } + inline const T &last() const { Q_ASSERT(!isEmpty()); return d->array[(d->start + d->count -1) % d->alloc]; } + inline T &first() { Q_ASSERT(!isEmpty()); detach(); return d->array[d->start]; } + inline T &last() { Q_ASSERT(!isEmpty()); detach(); return d->array[(d->start + d->count -1) % d->alloc]; } + + void removeFirst(); + T takeFirst(); + void removeLast(); + T takeLast(); + + // debug + void dump() const { p->dump(); } +private: + void detach_helper(); + + QOffsetVectorData *malloc(int alloc); + void free(Data *d); + int sizeOfTypedData() { + // this is more or less the same as sizeof(Data), except that it doesn't + // count the padding at the end + return reinterpret_cast(&(reinterpret_cast(this))->array[1]) - reinterpret_cast(this); + } +}; + +template +void QOffsetVector::detach_helper() +{ + union { QOffsetVectorData *p; QOffsetVectorTypedData *d; } x; + + x.p = malloc(d->alloc); + x.d->ref = 1; + x.d->count = d->count; + x.d->start = d->start; + x.d->offset = d->offset; + x.d->alloc = d->alloc; + x.d->sharable = true; + + T *dest = x.d->array + x.d->start; + T *src = d->array + d->start; + int count = x.d->count; + while (count--) { + if (QTypeInfo::isComplex) { + new (dest) T(*src); + } else { + *dest = *src; + } + dest++; + if (dest == x.d->array + x.d->alloc) + dest = x.d->array; + src++; + if (src == d->array + d->alloc) + src = d->array; + } + + if (!d->ref.deref()) + free(d); + d = x.d; +} + +template +void QOffsetVector::setCapacity(int asize) +{ + if (asize == d->alloc) + return; + detach(); + union { QOffsetVectorData *p; QOffsetVectorTypedData *d; } x; + x.p = malloc(asize); + x.d->alloc = asize; + x.d->count = qMin(d->count, asize); + x.d->offset = d->offset + d->count - x.d->count; + x.d->start = x.d->offset % x.d->alloc; + /* deep copy - + slow way now, get unit test working, then + improve performance if need be. (e.g. memcpy) + */ + T *dest = x.d->array + (x.d->start + x.d->count-1) % x.d->alloc; + T *src = d->array + (d->start + d->count-1) % d->alloc; + int count = x.d->count; + while (count--) { + if (QTypeInfo::isComplex) { + new (dest) T(*src); + } else { + *dest = *src; + } + if (dest == x.d->array) + dest = x.d->array + x.d->alloc; + dest--; + if (src == d->array) + src = d->array + d->alloc; + src--; + } + /* free old */ + free(d); + d = x.d; +} + +template +void QOffsetVector::clear() +{ + if (d->ref == 1) { + if (QTypeInfo::isComplex) { + int count = d->count; + T * i = d->array + d->start; + T * e = d->array + d->alloc; + while (count--) { + i->~T(); + i++; + if (i == e) + i = d->array; + } + } + d->count = d->start = d->offset = 0; + } else { + union { QOffsetVectorData *p; QOffsetVectorTypedData *d; } x; + x.p = malloc(d->alloc); + x.d->ref = 1; + x.d->alloc = d->alloc; + x.d->count = x.d->start = x.d->offset = 0; + x.d->sharable = true; + if (!d->ref.deref()) free(d); + d = x.d; + } +} + +template +inline QOffsetVectorData *QOffsetVector::malloc(int aalloc) +{ + return static_cast(qMalloc(sizeOfTypedData() + (aalloc - 1) * sizeof(T))); +} + +template +QOffsetVector::QOffsetVector(int asize) +{ + p = malloc(asize); + d->ref = 1; + d->alloc = asize; + d->count = d->start = d->offset = 0; + d->sharable = true; +} + +template +QOffsetVector &QOffsetVector::operator=(const QOffsetVector &other) +{ + other.d->ref.ref(); + if (!d->ref.deref()) + free(d); + d = other.d; + if (!d->sharable) + detach_helper(); + return *this; +} + +template +bool QOffsetVector::operator==(const QOffsetVector &other) const +{ + if (other.d == d) + return true; + if (other.d->start != d->start + || other.d->count != d->count + || other.d->offset != d->offset + || other.d->alloc != d->alloc) + return false; + for (int i = firstIndex(); i <= lastIndex(); ++i) + if (!(at(i) == other.at(i))) + return false; + return true; +} + +template +void QOffsetVector::free(Data *x) +{ + if (QTypeInfo::isComplex) { + int count = d->count; + T * i = d->array + d->start; + T * e = d->array + d->alloc; + while (count--) { + i->~T(); + i++; + if (i == e) + i = d->array; + } + } + qFree(x); +} + +template +void QOffsetVector::append(const T &value) +{ + detach(); + if (QTypeInfo::isComplex) { + if (d->count == d->alloc) + (d->array + (d->start+d->count) % d->alloc)->~T(); + new (d->array + (d->start+d->count) % d->alloc) T(value); + } else { + d->array[(d->start+d->count) % d->alloc] = value; + } + + if (d->count == d->alloc) { + d->start++; + d->start %= d->alloc; + d->offset++; + } else { + d->count++; + } +} + +template +void QOffsetVector::prepend(const T &value) +{ + detach(); + if (d->start) + d->start--; + else + d->start = d->alloc-1; + d->offset--; + + if (d->count != d->alloc) + d->count++; + else + if (d->count == d->alloc) + (d->array + d->start)->~T(); + + if (QTypeInfo::isComplex) + new (d->array + d->start) T(value); + else + d->array[d->start] = value; +} + +template +void QOffsetVector::insert(int pos, const T &value) +{ + detach(); + if (containsIndex(pos)) { + if(QTypeInfo::isComplex) + new (d->array + pos % d->alloc) T(value); + else + d->array[pos % d->alloc] = value; + } else if (pos == d->offset-1) + prepend(value); + else if (pos == d->offset+d->count) + append(value); + else { + // we don't leave gaps. + clear(); + d->offset = d->start = pos; + d->start %= d->alloc; + d->count = 1; + if (QTypeInfo::isComplex) + new (d->array + d->start) T(value); + else + d->array[d->start] = value; + } +} + +template +inline const T &QOffsetVector::at(int pos) const +{ Q_ASSERT_X(pos >= d->offset && pos - d->offset < d->count, "QOffsetVector::at", "index out of range"); return d->array[pos % d->alloc]; } +template +inline const T &QOffsetVector::operator[](int pos) const +{ Q_ASSERT_X(pos >= d->offset && pos - d->offset < d->count, "QOffsetVector::at", "index out of range"); return d->array[pos % d->alloc]; } +template + +// can use the non-inline one to modify the index range. +inline T &QOffsetVector::operator[](int pos) +{ + detach(); + if (!containsIndex(pos)) + insert(pos, T()); + return d->array[pos % d->alloc]; +} + +template +inline void QOffsetVector::removeFirst() +{ + Q_ASSERT(d->count > 0); + detach(); + d->count--; + if (QTypeInfo::isComplex) + (d->array + d->start)->~T(); + d->start = (d->start + 1) % d->alloc; + d->offset++; +} + +template +inline void QOffsetVector::removeLast() +{ + Q_ASSERT(d->count > 0); + detach(); + d->count--; + if (QTypeInfo::isComplex) + (d->array + (d->start + d->count) % d->alloc)->~T(); +} + +template +inline T QOffsetVector::takeFirst() +{ T t = first(); removeFirst(); return t; } + +template +inline T QOffsetVector::takeLast() +{ T t = last(); removeLast(); return t; } + +#endif diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index e5bf7e4..626c9e5 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -19,6 +19,7 @@ HEADERS += \ tools/qlocale_p.h \ tools/qlocale_data_p.h \ tools/qmap.h \ + tools/qoffsetvector.h \ tools/qpodlist_p.h \ tools/qpoint.h \ tools/qqueue.h \ @@ -53,6 +54,7 @@ SOURCES += \ tools/qlocale.cpp \ tools/qpoint.cpp \ tools/qmap.cpp \ + tools/qoffsetvector.cpp \ tools/qrect.cpp \ tools/qregexp.cpp \ tools/qshareddata.cpp \ diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 19f6b43..5d71e79 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -209,6 +209,7 @@ SUBDIRS += bic \ qnumeric \ qobject \ qobjectrace \ + qoffsetvector \ qpaintengine \ qpainter \ qpainterpath \ diff --git a/tests/auto/qoffsetvector/qoffsetvector.pro b/tests/auto/qoffsetvector/qoffsetvector.pro new file mode 100644 index 0000000..0b801f3 --- /dev/null +++ b/tests/auto/qoffsetvector/qoffsetvector.pro @@ -0,0 +1,8 @@ +load(qttest_p4) + +QT = core + +SOURCES += tst_qoffsetvector.cpp + + + diff --git a/tests/auto/qoffsetvector/tst_qoffsetvector.cpp b/tests/auto/qoffsetvector/tst_qoffsetvector.cpp new file mode 100644 index 0000000..439ea2c --- /dev/null +++ b/tests/auto/qoffsetvector/tst_qoffsetvector.cpp @@ -0,0 +1,361 @@ +/**************************************************************************** +** +** This file is part of the $PACKAGE_NAME$. +** +** Copyright (C) $THISYEAR$ $COMPANY_NAME$. +** +** $QT_EXTENDED_DUAL_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include +#include + + +#if defined(FORCE_UREF) +template +inline QDebug &operator<<(QDebug debug, const QOffsetVector &offsetVector) +#else +template +inline QDebug operator<<(QDebug debug, const QOffsetVector &offsetVector) +#endif +{ + debug.nospace() << "QOffsetVector("; + for (int i = offsetVector.firstIndex(); i <= offsetVector.lastIndex(); ++i) { + debug << offsetVector[i]; + if (i != offsetVector.lastIndex()) + debug << ", "; + } + debug << ")"; + return debug.space(); +} + +#if defined(NO_BENCHMARK) and defined(QBENCHMARK) +#undef QBENCHMARK +#define QBENCHMARK +#endif + +class tst_QOffsetVector : public QObject +{ + Q_OBJECT +public: + tst_QOffsetVector() {} + virtual ~tst_QOffsetVector() {} +private slots: + void empty(); + void forwardBuffer(); + void scrollingList(); + + void complexType(); + + void operatorAt(); + + void cacheBenchmark(); + void offsetVectorBenchmark(); + + void setCapacity(); +}; + +QTEST_MAIN(tst_QOffsetVector) + +void tst_QOffsetVector::empty() +{ + QOffsetVector c(10); + QCOMPARE(c.capacity(), 10); + QCOMPARE(c.count(), 0); + QVERIFY(c.isEmpty()); + c.append(1); + QVERIFY(!c.isEmpty()); + c.clear(); + QCOMPARE(c.capacity(), 10); + QCOMPARE(c.count(), 0); + QVERIFY(c.isEmpty()); + c.prepend(1); + QVERIFY(!c.isEmpty()); + c.clear(); + QCOMPARE(c.count(), 0); + QVERIFY(c.isEmpty()); + QCOMPARE(c.capacity(), 10); +} + +void tst_QOffsetVector::forwardBuffer() +{ + int i; + QOffsetVector c(10); + for(i = 1; i < 30; ++i) { + c.append(i); + QCOMPARE(c.first(), qMax(1, i-9)); + QCOMPARE(c.last(), i); + QCOMPARE(c.count(), qMin(i, 10)); + } + + c.clear(); + + for(i = 1; i < 30; ++i) { + c.prepend(i); + QCOMPARE(c.last(), qMax(1, i-9)); + QCOMPARE(c.first(), i); + QCOMPARE(c.count(), qMin(i, 10)); + } +} + +void tst_QOffsetVector::scrollingList() +{ + int i; + QOffsetVector c(10); + + // Once allocated QOffsetVector should not + // allocate any additional memory for non + // complex data types. + QBENCHMARK { + // simulate scrolling in a list of items; + for(i = 0; i < 10; ++i) + c.append(i); + + QCOMPARE(c.firstIndex(), 0); + QCOMPARE(c.lastIndex(), 9); + QVERIFY(c.containsIndex(0)); + QVERIFY(c.containsIndex(9)); + QVERIFY(!c.containsIndex(10)); + + for (i = 0; i < 10; ++i) + QCOMPARE(c.at(i), i); + + for (i = 10; i < 30; ++i) + c.append(i); + + QCOMPARE(c.firstIndex(), 20); + QCOMPARE(c.lastIndex(), 29); + QVERIFY(c.containsIndex(20)); + QVERIFY(c.containsIndex(29)); + QVERIFY(!c.containsIndex(30)); + + for (i = 20; i < 30; ++i) + QCOMPARE(c.at(i), i); + + for (i = 19; i >= 10; --i) + c.prepend(i); + + QCOMPARE(c.firstIndex(), 10); + QCOMPARE(c.lastIndex(), 19); + QVERIFY(c.containsIndex(10)); + QVERIFY(c.containsIndex(19)); + QVERIFY(!c.containsIndex(20)); + + for (i = 10; i < 20; ++i) + QCOMPARE(c.at(i), i); + + for (i = 200; i < 220; ++i) + c.insert(i, i); + + QCOMPARE(c.firstIndex(), 210); + QCOMPARE(c.lastIndex(), 219); + QVERIFY(c.containsIndex(210)); + QVERIFY(c.containsIndex(219)); + QVERIFY(!c.containsIndex(300)); + QVERIFY(!c.containsIndex(209)); + + for (i = 220; i < 220; ++i) { + QVERIFY(c.containsIndex(i)); + QCOMPARE(c.at(i), i); + } + c.clear(); // needed to reset benchmark + } + + // from a specific bug that was encountered. 100 to 299 cached, attempted to cache 250 - 205 via insert, failed. + // bug was that item at 150 would instead be item that should have been inserted at 250 + c.setCapacity(200); + for(i = 100; i < 300; ++i) + c.insert(i, i); + for (i = 250; i <= 306; ++i) + c.insert(i, 1000+i); + for (i = 107; i <= 306; ++i) { + QVERIFY(c.containsIndex(i)); + QCOMPARE(c.at(i), i < 250 ? i : 1000+i); + } +} + +struct RefCountingClassData +{ + QBasicAtomicInt ref; + static RefCountingClassData shared_null; +}; + +RefCountingClassData RefCountingClassData::shared_null = { + Q_BASIC_ATOMIC_INITIALIZER(1) +}; + +class RefCountingClass +{ +public: + RefCountingClass() : d(&RefCountingClassData::shared_null) { d->ref.ref(); } + + RefCountingClass(const RefCountingClass &other) + { + d = other.d; + d->ref.ref(); + } + + ~RefCountingClass() + { + if (!d->ref.deref()) + delete d; + } + + RefCountingClass &operator=(const RefCountingClass &other) + { + if (!d->ref.deref()) + delete d; + d = other.d; + d->ref.ref(); + return *this; + } + + int refCount() const { return d->ref; } +private: + RefCountingClassData *d; +}; + +void tst_QOffsetVector::complexType() +{ + RefCountingClass original; + + QOffsetVector offsetVector(10); + offsetVector.append(original); + QCOMPARE(original.refCount(), 3); + offsetVector.removeFirst(); + QCOMPARE(original.refCount(), 2); // shared null, 'original'. + offsetVector.append(original); + QCOMPARE(original.refCount(), 3); + offsetVector.clear(); + QCOMPARE(original.refCount(), 2); + + for(int i = 0; i < 100; ++i) + offsetVector.insert(i, original); + + QCOMPARE(original.refCount(), 12); // shared null, 'original', + 10 in offsetVector. + + offsetVector.clear(); + QCOMPARE(original.refCount(), 2); + for (int i = 0; i < 100; i++) + offsetVector.append(original); + + QCOMPARE(original.refCount(), 12); // shared null, 'original', + 10 in offsetVector. + offsetVector.clear(); + QCOMPARE(original.refCount(), 2); + + for (int i = 0; i < 100; i++) + offsetVector.prepend(original); + + QCOMPARE(original.refCount(), 12); // shared null, 'original', + 10 in offsetVector. + offsetVector.clear(); + QCOMPARE(original.refCount(), 2); + + for (int i = 0; i < 100; i++) + offsetVector.append(original); + + offsetVector.takeLast(); + QCOMPARE(original.refCount(), 11); + + offsetVector.takeFirst(); + QCOMPARE(original.refCount(), 10); +} + +void tst_QOffsetVector::operatorAt() +{ + RefCountingClass original; + QOffsetVector offsetVector(10); + + for (int i = 25; i < 35; ++i) + offsetVector[i] = original; + + QCOMPARE(original.refCount(), 12); // shared null, orig, items in vector + + // verify const access does not copy items. + const QOffsetVector copy(offsetVector); + for (int i = 25; i < 35; ++i) + QCOMPARE(copy[i].refCount(), 12); + + // verify modifying the original increments ref count (e.g. does a detach) + offsetVector[25] = original; + QCOMPARE(original.refCount(), 22); +} + +/* + Benchmarks must be near identical in tasks to be fair. + QCache uses pointers to ints as its a requirement of QCache, + whereas QOffsetVector doesn't support pointers (won't free them). + Given the ability to use simple data types is a benefit, its + fair. Although this obviously must take into account we are + testing QOffsetVector use cases here, QCache has its own + areas where it is the more sensible class to use. +*/ +void tst_QOffsetVector::cacheBenchmark() +{ + QBENCHMARK { + QCache cache; + cache.setMaxCost(100); + + for (int i = 0; i < 1000; i++) + cache.insert(i, new int(i)); + } +} + +void tst_QOffsetVector::offsetVectorBenchmark() +{ + QBENCHMARK { + QOffsetVector offsetVector(100); + for (int i = 0; i < 1000; i++) + offsetVector.insert(i, i); + } +} + +void tst_QOffsetVector::setCapacity() +{ + int i; + QOffsetVector offsetVector(100); + for (i = 280; i < 310; ++i) + offsetVector.insert(i, i); + QCOMPARE(offsetVector.capacity(), 100); + QCOMPARE(offsetVector.count(), 30); + QCOMPARE(offsetVector.firstIndex(), 280); + QCOMPARE(offsetVector.lastIndex(), 309); + + for (i = offsetVector.firstIndex(); i <= offsetVector.lastIndex(); ++i) { + QVERIFY(offsetVector.containsIndex(i)); + QCOMPARE(offsetVector.at(i), i); + } + + offsetVector.setCapacity(150); + + QCOMPARE(offsetVector.capacity(), 150); + QCOMPARE(offsetVector.count(), 30); + QCOMPARE(offsetVector.firstIndex(), 280); + QCOMPARE(offsetVector.lastIndex(), 309); + + for (i = offsetVector.firstIndex(); i <= offsetVector.lastIndex(); ++i) { + QVERIFY(offsetVector.containsIndex(i)); + QCOMPARE(offsetVector.at(i), i); + } + + offsetVector.setCapacity(20); + + QCOMPARE(offsetVector.capacity(), 20); + QCOMPARE(offsetVector.count(), 20); + QCOMPARE(offsetVector.firstIndex(), 290); + QCOMPARE(offsetVector.lastIndex(), 309); + + for (i = offsetVector.firstIndex(); i <= offsetVector.lastIndex(); ++i) { + QVERIFY(offsetVector.containsIndex(i)); + QCOMPARE(offsetVector.at(i), i); + } +} + +#include "tst_qoffsetvector.moc" -- cgit v0.12 From 423d6052844b2026c8acc8826d6546d3afc494d3 Mon Sep 17 00:00:00 2001 From: Ian Walters Date: Fri, 3 Apr 2009 12:44:38 +1000 Subject: Rename OffsetVector to ContiguousCache --- doc/src/examples/contiguouscache.qdoc | 69 ++++ doc/src/examples/offsetvector.qdoc | 70 ---- examples/tools/contiguouscache/contiguouscache.pro | 9 + examples/tools/contiguouscache/main.cpp | 15 + examples/tools/contiguouscache/randomlistmodel.cpp | 56 +++ examples/tools/contiguouscache/randomlistmodel.h | 26 ++ examples/tools/offsetvector/main.cpp | 15 - examples/tools/offsetvector/offsetvector.pro | 9 - examples/tools/offsetvector/randomlistmodel.cpp | 56 --- examples/tools/offsetvector/randomlistmodel.h | 26 -- examples/tools/tools.pro | 2 +- src/corelib/tools/qcontiguouscache.cpp | 359 +++++++++++++++++++ src/corelib/tools/qcontiguouscache.h | 386 +++++++++++++++++++++ src/corelib/tools/qoffsetvector.cpp | 360 ------------------- src/corelib/tools/qoffsetvector.h | 386 --------------------- src/corelib/tools/tools.pri | 4 +- tests/auto/qcontiguouscache/qcontiguouscache.pro | 8 + .../auto/qcontiguouscache/tst_qcontiguouscache.cpp | 361 +++++++++++++++++++ tests/auto/qoffsetvector/qoffsetvector.pro | 8 - tests/auto/qoffsetvector/tst_qoffsetvector.cpp | 361 ------------------- 20 files changed, 1292 insertions(+), 1294 deletions(-) create mode 100644 doc/src/examples/contiguouscache.qdoc delete mode 100644 doc/src/examples/offsetvector.qdoc create mode 100644 examples/tools/contiguouscache/contiguouscache.pro create mode 100644 examples/tools/contiguouscache/main.cpp create mode 100644 examples/tools/contiguouscache/randomlistmodel.cpp create mode 100644 examples/tools/contiguouscache/randomlistmodel.h delete mode 100644 examples/tools/offsetvector/main.cpp delete mode 100644 examples/tools/offsetvector/offsetvector.pro delete mode 100644 examples/tools/offsetvector/randomlistmodel.cpp delete mode 100644 examples/tools/offsetvector/randomlistmodel.h create mode 100644 src/corelib/tools/qcontiguouscache.cpp create mode 100644 src/corelib/tools/qcontiguouscache.h delete mode 100644 src/corelib/tools/qoffsetvector.cpp delete mode 100644 src/corelib/tools/qoffsetvector.h create mode 100644 tests/auto/qcontiguouscache/qcontiguouscache.pro create mode 100644 tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp delete mode 100644 tests/auto/qoffsetvector/qoffsetvector.pro delete mode 100644 tests/auto/qoffsetvector/tst_qoffsetvector.cpp diff --git a/doc/src/examples/contiguouscache.qdoc b/doc/src/examples/contiguouscache.qdoc new file mode 100644 index 0000000..22c97fa --- /dev/null +++ b/doc/src/examples/contiguouscache.qdoc @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +/*! + \example tools/contiguouscache + \title Contiguous Cache Example + + The Contiguous Cache example shows how to use QContiguousCache to manage memory usage for + very large models. In some environments memory is limited, and even when it + isn't users still dislike an application using + excessive memory. Using QContiguousCache to manage a list rather than loading + the entire list into memory allows the application to limit the amount + of memory it uses regardless of the size of the data set it accesses + + The simplest way to use QContiguousCache is to cache as items are requested. When + a view requests an item at row N it is also likely to ask for items at rows near + to N. + + \snippet examples/tools/contiguouscache/randomlistmodel.cpp 0 + + After getting the row the class determines if the row is in the bounds + of the contiguous cache's current range. It would have been equally valid to + simply have the following code instead. + + \code + while (row > m_words.lastIndex()) + m_words.append(fetchWord(m_words.lastIndex()+1); + while (row < m_words.firstIndex()) + m_words.prepend(fetchWord(m_words.firstIndex()-1); + \endcode + + However a list will often jump rows if the scroll bar is used directly, resulting in + the code above to cause every row between where the cache was last centered + to the requested row to be fetched before the requested row is fetched. + + Using QContiguousCache::lastIndex() and QContiguousCache::firstIndex() allows + the example to determine where in the list the cache is currently over. These values + don't represent the indexes into the cache own memory, but rather a virtual + infinite array that the cache represents. + + By using QContiguousCache::append() and QContiguousCache::prepend() the code ensures + that items that may be still on the screen are not lost when the requested row + has not moved far from the current cache range. QContiguousCache::insert() can + potentially remove more than one item from the cache as QContiguousCache does not + allow for gaps. If your cache needs to quickly jump back and forth between + rows with significant gaps between them consider using QCache instead. + + And thats it. A perfectly reasonable cache, using minimal memory for a very large + list. In this case the accessor for getting the words into cache: + + \snippet examples/tools/contiguouscache/randomlistmodel.cpp 1 + + Generates random information rather than fixed information. This allows you + to see how the cache range is kept for a local number of rows when running the + example. + + It is also worth considering pre-fetching items into the cache outside of the + applications paint routine. This can be done either with a separate thread + or using a QTimer to incrementally expand the range of the thread prior to + rows being requested out of the current cache range. +*/ diff --git a/doc/src/examples/offsetvector.qdoc b/doc/src/examples/offsetvector.qdoc deleted file mode 100644 index 256569e..0000000 --- a/doc/src/examples/offsetvector.qdoc +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $TROLLTECH_DUAL_LICENSE$ -** -****************************************************************************/ - -/*! - \example tools/offsetvector - \title Offset Vector Example - - The Offset Vector example shows how to use QOffsetVector to manage memory usage for - very large models. In some environments memory is limited, and even when it - isn't users still dislike an application using - excessive memory. Using QOffsetVector to manage a list rather than loading - the entire list into memory allows the application to limit the amount - of memory it uses regardless of the size of the data set it accesses - - The simplest way to use QOffsetVector is to cache as items are requested. When - a view requests an item at row N it is also likely to ask for items at rows near - to N. - - \snippet examples/tools/offsetvector/randomlistmodel.cpp 0 - - After getting the row the class determines if the row is in the bounds - of the offset vector's current range. It would have been equally valid to - simply have the following code instead. - - \code - while (row > m_words.lastIndex()) - m_words.append(fetchWord(m_words.lastIndex()+1); - while (row < m_words.firstIndex()) - m_words.prepend(fetchWord(m_words.firstIndex()-1); - \endcode - - However a list will often jump rows if the scroll bar is used directly, and - the above code would cause every row between where the cache was last centered - to where the cache is currently centered to be cached before the requested - row is reached. - - Using QOffsetVector::lastIndex() and QOffsetVector::firstIndex() allows - the example to determine where the list the vector is currently over. These values - don't represent the indexes into the vector own memory, but rather a virtual - infinite array that the vector represents. - - By using QOffsetVector::append() and QOffsetVector::prepend() the code ensures - that items that may be still on the screen are not lost when the requested row - has not moved far from the current vector range. QOffsetVector::insert() can - potentially remove more than one item from the cache as QOffsetVector does not - allow for gaps. If your cache needs to quickly jump back and forth between - rows with significant gaps between them consider using QCache instead. - - And thats it. A perfectly reasonable cache, using minimal memory for a very large - list. In this case the accessor for getting the words into cache: - - \snippet examples/tools/offsetvector/randomlistmodel.cpp 1 - - Generates random information rather than fixed information. This allows you - to see how the cache range is kept for a local number of rows when running the - example. - - It is also worth considering pre-fetching items into the cache outside of the - applications paint routine. This can be done either with a separate thread - or using a QTimer to incrementally expand the range of the thread prior to - rows being requested out of the current vector range. -*/ diff --git a/examples/tools/contiguouscache/contiguouscache.pro b/examples/tools/contiguouscache/contiguouscache.pro new file mode 100644 index 0000000..f840514 --- /dev/null +++ b/examples/tools/contiguouscache/contiguouscache.pro @@ -0,0 +1,9 @@ +HEADERS = randomlistmodel.h +SOURCES = randomlistmodel.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tools/contiguouscache +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS contiguouscache.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tools/contiguouscache +INSTALLS += target sources diff --git a/examples/tools/contiguouscache/main.cpp b/examples/tools/contiguouscache/main.cpp new file mode 100644 index 0000000..bdeb3f3 --- /dev/null +++ b/examples/tools/contiguouscache/main.cpp @@ -0,0 +1,15 @@ +#include "randomlistmodel.h" +#include +#include + +int main(int c, char **v) +{ + QApplication a(c, v); + + QListView view; + view.setUniformItemSizes(true); + view.setModel(new RandomListModel(&view)); + view.show(); + + return a.exec(); +} diff --git a/examples/tools/contiguouscache/randomlistmodel.cpp b/examples/tools/contiguouscache/randomlistmodel.cpp new file mode 100644 index 0000000..5c0953b --- /dev/null +++ b/examples/tools/contiguouscache/randomlistmodel.cpp @@ -0,0 +1,56 @@ +#include "randomlistmodel.h" + +static const int bufferSize(500); +static const int lookAhead(100); +static const int halfLookAhead(lookAhead/2); + +RandomListModel::RandomListModel(QObject *parent) +: QAbstractListModel(parent), m_rows(bufferSize), m_count(10000) +{ +} + +RandomListModel::~RandomListModel() +{ +} + +int RandomListModel::rowCount(const QModelIndex &) const +{ + return m_count; +} + +//! [0] +QVariant RandomListModel::data(const QModelIndex &index, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + int row = index.row(); + + if (row > m_rows.lastIndex()) { + if (row - m_rows.lastIndex() > lookAhead) + cacheRows(row-halfLookAhead, qMin(m_count, row+halfLookAhead)); + else while (row > m_rows.lastIndex()) + m_rows.append(fetchRow(m_rows.lastIndex()+1)); + } else if (row < m_rows.firstIndex()) { + if (m_rows.firstIndex() - row > lookAhead) + cacheRows(qMax(0, row-halfLookAhead), row+halfLookAhead); + else while (row < m_rows.firstIndex()) + m_rows.prepend(fetchRow(m_rows.firstIndex()-1)); + } + + return m_rows.at(row); +} + +void RandomListModel::cacheRows(int from, int to) const +{ + for (int i = from; i <= to; ++i) + m_rows.insert(i, fetchRow(i)); +} +//![0] + +//![1] +QString RandomListModel::fetchRow(int position) const +{ + return QString::number(rand() % ++position); +} +//![1] diff --git a/examples/tools/contiguouscache/randomlistmodel.h b/examples/tools/contiguouscache/randomlistmodel.h new file mode 100644 index 0000000..ad8cfad --- /dev/null +++ b/examples/tools/contiguouscache/randomlistmodel.h @@ -0,0 +1,26 @@ +#ifndef RANDOMLISTMODEL_H +#define RANDOMLISTMODEL_H + +#include +#include + +class QTimer; +class RandomListModel : public QAbstractListModel +{ + Q_OBJECT +public: + RandomListModel(QObject *parent = 0); + ~RandomListModel(); + + int rowCount(const QModelIndex & = QModelIndex()) const; + QVariant data(const QModelIndex &, int) const; + +private: + void cacheRows(int, int) const; + QString fetchRow(int) const; + + mutable QContiguousCache m_rows; + const int m_count; +}; + +#endif diff --git a/examples/tools/offsetvector/main.cpp b/examples/tools/offsetvector/main.cpp deleted file mode 100644 index bdeb3f3..0000000 --- a/examples/tools/offsetvector/main.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "randomlistmodel.h" -#include -#include - -int main(int c, char **v) -{ - QApplication a(c, v); - - QListView view; - view.setUniformItemSizes(true); - view.setModel(new RandomListModel(&view)); - view.show(); - - return a.exec(); -} diff --git a/examples/tools/offsetvector/offsetvector.pro b/examples/tools/offsetvector/offsetvector.pro deleted file mode 100644 index f329bb9..0000000 --- a/examples/tools/offsetvector/offsetvector.pro +++ /dev/null @@ -1,9 +0,0 @@ -HEADERS = randomlistmodel.h -SOURCES = randomlistmodel.cpp \ - main.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/tools/offsetvector -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS offsetvector.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/tools/offsetvector -INSTALLS += target sources diff --git a/examples/tools/offsetvector/randomlistmodel.cpp b/examples/tools/offsetvector/randomlistmodel.cpp deleted file mode 100644 index 5c0953b..0000000 --- a/examples/tools/offsetvector/randomlistmodel.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "randomlistmodel.h" - -static const int bufferSize(500); -static const int lookAhead(100); -static const int halfLookAhead(lookAhead/2); - -RandomListModel::RandomListModel(QObject *parent) -: QAbstractListModel(parent), m_rows(bufferSize), m_count(10000) -{ -} - -RandomListModel::~RandomListModel() -{ -} - -int RandomListModel::rowCount(const QModelIndex &) const -{ - return m_count; -} - -//! [0] -QVariant RandomListModel::data(const QModelIndex &index, int role) const -{ - if (role != Qt::DisplayRole) - return QVariant(); - - int row = index.row(); - - if (row > m_rows.lastIndex()) { - if (row - m_rows.lastIndex() > lookAhead) - cacheRows(row-halfLookAhead, qMin(m_count, row+halfLookAhead)); - else while (row > m_rows.lastIndex()) - m_rows.append(fetchRow(m_rows.lastIndex()+1)); - } else if (row < m_rows.firstIndex()) { - if (m_rows.firstIndex() - row > lookAhead) - cacheRows(qMax(0, row-halfLookAhead), row+halfLookAhead); - else while (row < m_rows.firstIndex()) - m_rows.prepend(fetchRow(m_rows.firstIndex()-1)); - } - - return m_rows.at(row); -} - -void RandomListModel::cacheRows(int from, int to) const -{ - for (int i = from; i <= to; ++i) - m_rows.insert(i, fetchRow(i)); -} -//![0] - -//![1] -QString RandomListModel::fetchRow(int position) const -{ - return QString::number(rand() % ++position); -} -//![1] diff --git a/examples/tools/offsetvector/randomlistmodel.h b/examples/tools/offsetvector/randomlistmodel.h deleted file mode 100644 index e102255..0000000 --- a/examples/tools/offsetvector/randomlistmodel.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef RANDOMLISTMODEL_H -#define RANDOMLISTMODEL_H - -#include -#include - -class QTimer; -class RandomListModel : public QAbstractListModel -{ - Q_OBJECT -public: - RandomListModel(QObject *parent = 0); - ~RandomListModel(); - - int rowCount(const QModelIndex & = QModelIndex()) const; - QVariant data(const QModelIndex &, int) const; - -private: - void cacheRows(int, int) const; - QString fetchRow(int) const; - - mutable QOffsetVector m_rows; - const int m_count; -}; - -#endif diff --git a/examples/tools/tools.pro b/examples/tools/tools.pro index 424f286..c694dd8 100644 --- a/examples/tools/tools.pro +++ b/examples/tools/tools.pro @@ -5,7 +5,7 @@ SUBDIRS = codecs \ customcompleter \ echoplugin \ i18n \ - offsetvector \ + contiguouscache \ plugandpaintplugins \ plugandpaint \ regexp \ diff --git a/src/corelib/tools/qcontiguouscache.cpp b/src/corelib/tools/qcontiguouscache.cpp new file mode 100644 index 0000000..5046912 --- /dev/null +++ b/src/corelib/tools/qcontiguouscache.cpp @@ -0,0 +1,359 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#include "qcontiguouscache.h" +#include + +void QContiguousCacheData::dump() const +{ + qDebug() << "capacity:" << alloc; + qDebug() << "count:" << count; + qDebug() << "start:" << start; + qDebug() << "offset:" << offset; +} + +/*! \class QContiguousCache + \brief The QContiguousCache class is a template class that provides a contiguous cache. + \ingroup tools + \ingroup shared + \reentrant + + The QContiguousCache class provides an efficient way of caching items for + display in a user interface view. Unlike QCache though it adds a restriction + that elements within the cache are contiguous. This has the advantage that + of matching how user interface views most commonly request data, as + a set of rows localized around the current scrolled position. It also + allows the cache to use less overhead than QCache both in terms of + performance and memory. + + The simplest way of using an contiguous cache is to use the append() + and prepend(). + +\code +MyRecord record(int row) const +{ + Q_ASSERT(row >= 0 && row < count()); + + while(row > cache.lastIndex()) + cache.append(slowFetchRecord(cache.lastIndex()+1)); + while(row < cache.firstIndex()) + cache.prepend(slowFetchRecord(cache.firstIndex()-1)); + + return cache.at(row); +} +\endcode + + If the cache is full then the item with the furthest index from where + the new item is appended or prepended is removed. + + This usage can be further optimized by using the insert() function + in the case where the requested row is a long way from the currently cached + items. If there is a is a gap between where the new item is inserted and the currently + cached items then the existing cached items are first removed to retain + the contiguous nature of the cache. Hence it is important to take some care then + when using insert() in order to avoid to unwanted clearing of the cache. + + See the The \l{Contiguous Cache Example}{Contiguous Cache} example. +*/ + +/*! \fn QContiguousCache::QContiguousCache(int capacity) + + Constructs a cache with the given \a capacity. + + \sa setCapacity() +*/ + +/*! \fn QContiguousCache::QContiguousCache(const QContiguousCache &other) + + Constructs a copy of \a other. + + This operation takes \l{constant time}, because QContiguousCache is + \l{implicitly shared}. This makes returning a QContiguousCache from a + function very fast. If a shared instance is modified, it will be + copied (copy-on-write), and that takes \l{linear time}. + + \sa operator=() +*/ + +/*! \fn QContiguousCache::~QContiguousCache() + Destroys the cache. +*/ + +/*! \fn void QContiguousCache::detach() + + \internal +*/ + +/*! \fn bool QContiguousCache::isDetached() const + + \internal +*/ + +/*! \fn void QContiguousCache::setSharable(bool sharable) + + \internal +*/ + + +/*! \fn QContiguousCache &QContiguousCache::operator=(const QContiguousCache &other) + + Assigns \a other to this cache and returns a reference to this cache. +*/ + +/*! \fn bool QContiguousCache::operator==(const QContiguousCache &other) const + + Returns true if \a other is equal to this cache; otherwise returns false. + + Two cache are considered equal if they contain the same values at the same + indexes. This function requires the value type to implement the \c operator==(). + + \sa operator!=() +*/ + +/*! \fn bool QContiguousCache::operator!=(const QContiguousCache &other) const + + Returns true if \a other is not equal to this cache; otherwise + returns false. + + Two cache are considered equal if they contain the same values at the same + indexes. This function requires the value type to implement the \c operator==(). + + \sa operator==() +*/ + +/*! \fn int QContiguousCache::capacity() const + + Returns the number of items the cache can store before it is full. + When a cache contains a number of items equal to its capacity, adding new + items will cause items furthest from the added item to be removed. + + \sa setCapacity(), size() +*/ + +/*! \fn int QContiguousCache::count() const + + \overload + + Same as size(). +*/ + +/*! \fn int QContiguousCache::size() const + + Returns the number of items contained within the cache. + + \sa capacity() +*/ + +/*! \fn bool QContiguousCache::isEmpty() const + + Returns true if no items are stored within the cache. + + \sa size(), capacity() +*/ + +/*! \fn bool QContiguousCache::isFull() const + + Returns true if the number of items stored within the cache is equal + to the capacity of the cache. + + \sa size(), capacity() +*/ + +/*! \fn int QContiguousCache::available() const + + Returns the number of items that can be added to the cache before it becomes full. + + \sa size(), capacity(), isFull() +*/ + +/*! \fn void QContiguousCache::clear() + + Removes all items from the cache. The capacity is unchanged. +*/ + +/*! \fn void QContiguousCache::setCapacity(int size) + + Sets the capacity of the cache to the given \a size. A cache can hold a + number of items equal to its capacity. When inserting, appending or prepending + items to the cache, if the cache is already full then the item furthest from + the added item will be removed. + + If the given \a size is smaller than the current count of items in the cache + then only the last \a size items from the cache will remain. + + \sa capacity(), isFull() +*/ + +/*! \fn const T &QContiguousCache::at(int i) const + + Returns the item at index position \a i in the cache. \a i must + be a valid index position in the cache (i.e, firstIndex() <= \a i <= lastIndex()). + + The indexes in the cache refer to number of positions the item is from the + first item appended into the cache. That is to say a cache with a capacity of + 100, that has had 150 items appended will have a valid index range of + 50 to 149. This allows inserting an retrieving items into the cache based + on a theoretical infinite list + + \sa firstIndex(), lastIndex(), insert(), operator[]() +*/ + +/*! \fn T &QContiguousCache::operator[](int i) + + Returns the item at index position \a i as a modifiable reference. If + the cache does not contain an item at the given index position \a i + then it will first insert an empty item at that position. + + In most cases it is better to use either at() or insert(). + + Note that using non-const operators can cause QContiguousCache to do a deep + copy. + + \sa insert(), at() +*/ + +/*! \fn const T &QContiguousCache::operator[](int i) const + + \overload + + Same as at(\a i). +*/ + +/*! \fn void QContiguousCache::append(const T &value) + + Inserts \a value at the end of the cache. If the cache is already full + the item at the start of the cache will be removed. + + \sa prepend(), insert(), isFull() +*/ + +/*! \fn void QContiguousCache::prepend(const T &value) + + Inserts \a value at the start of the cache. If the cache is already full + the item at the end of the cache will be removed. + + \sa append(), insert(), isFull() +*/ + +/*! \fn void QContiguousCache::insert(int i, const T &value) + + Inserts the \a value at the index position \a i. If the cache already contains + an item at \a i then that value is replaced. If \a i is either one more than + lastIndex() or one less than firstIndex() it is the equivalent to an append() + or a prepend(). + + If the given index \a i is not within the current range of the cache nor adjacent + to the bounds of the cache's index range the cache is first cleared before + inserting the item. At this point the cache will have a size of 1. It is worth + while then taking effort to insert items in an order that starts adjacent to the + current index range for the cache. + + \sa prepend(), append(), isFull(), firstIndex(), lastIndex() +*/ + +/*! \fn bool QContiguousCache::containsIndex(int i) const + + Returns true if the cache's index range includes the given index \a i. + + \sa firstIndex(), lastIndex() +*/ + +/*! \fn int QContiguousCache::firstIndex() const + Returns the first valid index in the cache. The index will be invalid if the + cache is empty. However the following code is valid even when the cache is empty: + + \code + for (int i = cache.firstIndex(); i <= cache.lastIndex(); ++i) + qDebug() << "Item" << i << "of the cache is" << cache.at(i); + \endcode + + \sa capacity(), size(), lastIndex() +*/ + +/*! \fn int QContiguousCache::lastIndex() const + + Returns the last valid index in the cache. If the cache is empty will return -1. + + \code + for (int i = cache.firstIndex(); i <= cache.lastIndex(); ++i) + qDebug() << "Item" << i << "of the cache is" << cache.at(i); + \endcode + + \sa capacity(), size(), firstIndex() +*/ + + +/*! \fn T &QContiguousCache::first() + + Returns a reference to the first item in the cache. This function + assumes that the cache isn't empty. + + \sa last(), isEmpty() +*/ + +/*! \fn T &QContiguousCache::last() + + Returns a reference to the last item in the cache. This function + assumes that the cache isn't empty. + + \sa first(), isEmpty() +*/ + +/*! \fn const T& QContiguousCache::first() const + + \overload +*/ + +/*! \fn const T& QContiguousCache::last() const + + \overload +*/ + +/*! \fn void QContiguousCache::removeFirst() + + Removes the first item from the cache. This function assumes that + the cache isn't empty. + + \sa removeLast() +*/ + +/*! \fn void QContiguousCache::removeLast() + + Removes the last item from the cache. This function assumes that + the cache isn't empty. + + \sa removeFirst() +*/ + +/*! \fn T QContiguousCache::takeFirst() + + Removes the first item in the cache and returns it. + + If you don't sue the return value, removeFirst() is more efficient. + + \sa takeLast(), removeFirst() +*/ + +/*! \fn T QContiguousCache::takeLast() + + Removes the last item in the cache and returns it. + + If you don't sue the return value, removeLast() is more efficient. + + \sa takeFirst(), removeLast() +*/ + +/*! \fn void QContiguousCache::dump() const + + \internal + + Sends information about the cache's internal structure to qDebug() +*/ diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h new file mode 100644 index 0000000..03012a2 --- /dev/null +++ b/src/corelib/tools/qcontiguouscache.h @@ -0,0 +1,386 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#ifndef QCONTIGUOUSCACHE_H +#define QCONTIGUOUSCACHE_H + +#include + +struct QContiguousCacheData +{ + QBasicAtomicInt ref; + int alloc; + int count; + int start; + int offset; + uint sharable : 1; + + void dump() const; +}; + +template +struct QContiguousCacheTypedData +{ + QBasicAtomicInt ref; + int alloc; + int count; + int start; + int offset; + uint sharable : 1; + + T array[1]; +}; + +class QContiguousCacheDevice; + +template +class QContiguousCache { + typedef QContiguousCacheTypedData Data; + union { QContiguousCacheData *p; QContiguousCacheTypedData *d; }; +public: + explicit QContiguousCache(int capacity = 0); + QContiguousCache(const QContiguousCache &v) : d(v.d) { d->ref.ref(); if (!d->sharable) detach_helper(); } + + inline ~QContiguousCache() { if (!d) return; if (!d->ref.deref()) free(d); } + + inline void detach() { if (d->ref != 1) detach_helper(); } + inline bool isDetached() const { return d->ref == 1; } + inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; } + + QContiguousCache &operator=(const QContiguousCache &other); + bool operator==(const QContiguousCache &other) const; + inline bool operator!=(const QContiguousCache &other) const { return !(*this == other); } + + inline int capacity() const {return d->alloc; } + inline int count() const { return d->count; } + inline int size() const { return d->count; } + + inline bool isEmpty() const { return d->count == 0; } + inline bool isFull() const { return d->count == d->alloc; } + inline int available() const { return d->alloc - d->count; } + + void clear(); + void setCapacity(int size); + + const T &at(int pos) const; + T &operator[](int i); + const T &operator[](int i) const; + + void append(const T &value); + void prepend(const T &value); + void insert(int pos, const T &value); + + inline bool containsIndex(int pos) const { return pos >= d->offset && pos - d->offset < d->count; } + inline int firstIndex() const { return d->offset; } + inline int lastIndex() const { return d->offset + d->count - 1; } + + inline const T &first() const { Q_ASSERT(!isEmpty()); return d->array[d->start]; } + inline const T &last() const { Q_ASSERT(!isEmpty()); return d->array[(d->start + d->count -1) % d->alloc]; } + inline T &first() { Q_ASSERT(!isEmpty()); detach(); return d->array[d->start]; } + inline T &last() { Q_ASSERT(!isEmpty()); detach(); return d->array[(d->start + d->count -1) % d->alloc]; } + + void removeFirst(); + T takeFirst(); + void removeLast(); + T takeLast(); + + // debug + void dump() const { p->dump(); } +private: + void detach_helper(); + + QContiguousCacheData *malloc(int alloc); + void free(Data *d); + int sizeOfTypedData() { + // this is more or less the same as sizeof(Data), except that it doesn't + // count the padding at the end + return reinterpret_cast(&(reinterpret_cast(this))->array[1]) - reinterpret_cast(this); + } +}; + +template +void QContiguousCache::detach_helper() +{ + union { QContiguousCacheData *p; QContiguousCacheTypedData *d; } x; + + x.p = malloc(d->alloc); + x.d->ref = 1; + x.d->count = d->count; + x.d->start = d->start; + x.d->offset = d->offset; + x.d->alloc = d->alloc; + x.d->sharable = true; + + T *dest = x.d->array + x.d->start; + T *src = d->array + d->start; + int count = x.d->count; + while (count--) { + if (QTypeInfo::isComplex) { + new (dest) T(*src); + } else { + *dest = *src; + } + dest++; + if (dest == x.d->array + x.d->alloc) + dest = x.d->array; + src++; + if (src == d->array + d->alloc) + src = d->array; + } + + if (!d->ref.deref()) + free(d); + d = x.d; +} + +template +void QContiguousCache::setCapacity(int asize) +{ + if (asize == d->alloc) + return; + detach(); + union { QContiguousCacheData *p; QContiguousCacheTypedData *d; } x; + x.p = malloc(asize); + x.d->alloc = asize; + x.d->count = qMin(d->count, asize); + x.d->offset = d->offset + d->count - x.d->count; + x.d->start = x.d->offset % x.d->alloc; + /* deep copy - + slow way now, get unit test working, then + improve performance if need be. (e.g. memcpy) + */ + T *dest = x.d->array + (x.d->start + x.d->count-1) % x.d->alloc; + T *src = d->array + (d->start + d->count-1) % d->alloc; + int count = x.d->count; + while (count--) { + if (QTypeInfo::isComplex) { + new (dest) T(*src); + } else { + *dest = *src; + } + if (dest == x.d->array) + dest = x.d->array + x.d->alloc; + dest--; + if (src == d->array) + src = d->array + d->alloc; + src--; + } + /* free old */ + free(d); + d = x.d; +} + +template +void QContiguousCache::clear() +{ + if (d->ref == 1) { + if (QTypeInfo::isComplex) { + int count = d->count; + T * i = d->array + d->start; + T * e = d->array + d->alloc; + while (count--) { + i->~T(); + i++; + if (i == e) + i = d->array; + } + } + d->count = d->start = d->offset = 0; + } else { + union { QContiguousCacheData *p; QContiguousCacheTypedData *d; } x; + x.p = malloc(d->alloc); + x.d->ref = 1; + x.d->alloc = d->alloc; + x.d->count = x.d->start = x.d->offset = 0; + x.d->sharable = true; + if (!d->ref.deref()) free(d); + d = x.d; + } +} + +template +inline QContiguousCacheData *QContiguousCache::malloc(int aalloc) +{ + return static_cast(qMalloc(sizeOfTypedData() + (aalloc - 1) * sizeof(T))); +} + +template +QContiguousCache::QContiguousCache(int asize) +{ + p = malloc(asize); + d->ref = 1; + d->alloc = asize; + d->count = d->start = d->offset = 0; + d->sharable = true; +} + +template +QContiguousCache &QContiguousCache::operator=(const QContiguousCache &other) +{ + other.d->ref.ref(); + if (!d->ref.deref()) + free(d); + d = other.d; + if (!d->sharable) + detach_helper(); + return *this; +} + +template +bool QContiguousCache::operator==(const QContiguousCache &other) const +{ + if (other.d == d) + return true; + if (other.d->start != d->start + || other.d->count != d->count + || other.d->offset != d->offset + || other.d->alloc != d->alloc) + return false; + for (int i = firstIndex(); i <= lastIndex(); ++i) + if (!(at(i) == other.at(i))) + return false; + return true; +} + +template +void QContiguousCache::free(Data *x) +{ + if (QTypeInfo::isComplex) { + int count = d->count; + T * i = d->array + d->start; + T * e = d->array + d->alloc; + while (count--) { + i->~T(); + i++; + if (i == e) + i = d->array; + } + } + qFree(x); +} + +template +void QContiguousCache::append(const T &value) +{ + detach(); + if (QTypeInfo::isComplex) { + if (d->count == d->alloc) + (d->array + (d->start+d->count) % d->alloc)->~T(); + new (d->array + (d->start+d->count) % d->alloc) T(value); + } else { + d->array[(d->start+d->count) % d->alloc] = value; + } + + if (d->count == d->alloc) { + d->start++; + d->start %= d->alloc; + d->offset++; + } else { + d->count++; + } +} + +template +void QContiguousCache::prepend(const T &value) +{ + detach(); + if (d->start) + d->start--; + else + d->start = d->alloc-1; + d->offset--; + + if (d->count != d->alloc) + d->count++; + else + if (d->count == d->alloc) + (d->array + d->start)->~T(); + + if (QTypeInfo::isComplex) + new (d->array + d->start) T(value); + else + d->array[d->start] = value; +} + +template +void QContiguousCache::insert(int pos, const T &value) +{ + detach(); + if (containsIndex(pos)) { + if(QTypeInfo::isComplex) + new (d->array + pos % d->alloc) T(value); + else + d->array[pos % d->alloc] = value; + } else if (pos == d->offset-1) + prepend(value); + else if (pos == d->offset+d->count) + append(value); + else { + // we don't leave gaps. + clear(); + d->offset = d->start = pos; + d->start %= d->alloc; + d->count = 1; + if (QTypeInfo::isComplex) + new (d->array + d->start) T(value); + else + d->array[d->start] = value; + } +} + +template +inline const T &QContiguousCache::at(int pos) const +{ Q_ASSERT_X(pos >= d->offset && pos - d->offset < d->count, "QContiguousCache::at", "index out of range"); return d->array[pos % d->alloc]; } +template +inline const T &QContiguousCache::operator[](int pos) const +{ Q_ASSERT_X(pos >= d->offset && pos - d->offset < d->count, "QContiguousCache::at", "index out of range"); return d->array[pos % d->alloc]; } +template + +// can use the non-inline one to modify the index range. +inline T &QContiguousCache::operator[](int pos) +{ + detach(); + if (!containsIndex(pos)) + insert(pos, T()); + return d->array[pos % d->alloc]; +} + +template +inline void QContiguousCache::removeFirst() +{ + Q_ASSERT(d->count > 0); + detach(); + d->count--; + if (QTypeInfo::isComplex) + (d->array + d->start)->~T(); + d->start = (d->start + 1) % d->alloc; + d->offset++; +} + +template +inline void QContiguousCache::removeLast() +{ + Q_ASSERT(d->count > 0); + detach(); + d->count--; + if (QTypeInfo::isComplex) + (d->array + (d->start + d->count) % d->alloc)->~T(); +} + +template +inline T QContiguousCache::takeFirst() +{ T t = first(); removeFirst(); return t; } + +template +inline T QContiguousCache::takeLast() +{ T t = last(); removeLast(); return t; } + +#endif diff --git a/src/corelib/tools/qoffsetvector.cpp b/src/corelib/tools/qoffsetvector.cpp deleted file mode 100644 index 32d2872..0000000 --- a/src/corelib/tools/qoffsetvector.cpp +++ /dev/null @@ -1,360 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $TROLLTECH_DUAL_LICENSE$ -** -****************************************************************************/ - -#include "qoffsetvector.h" -#include - -void QOffsetVectorData::dump() const -{ - qDebug() << "capacity:" << alloc; - qDebug() << "count:" << count; - qDebug() << "start:" << start; - qDebug() << "offset:" << offset; -} - -/*! \class QOffsetVector - \brief The QOffsetVector class is a template class that provides a offset vector. - \ingroup tools - \ingroup shared - \reentrant - - The QOffsetVector class provides an efficient way of caching items for - display in a user interface view. It does this by providing a window - into a theoretical infinite sized vector. This has the advantage that - it matches how user interface views most commonly request the data, in - a set of rows localized around the current scrolled position. It also - allows the cache to use less overhead than QCache both in terms of - performance and memory. In turn, unlike a QCache, the key has to be - an int and has to be contiguous. That is to say if an item is inserted - at index 85, then if there were no previous items at 84 or 86 then the - cache will be cleared before the new item at 85 is inserted. If this - restriction is not suitable consider using QCache instead. - - The simplest way of using an offset vector is to use the append() - and prepend() functions to slide the window to where it is needed. - -\code -MyRecord record(int row) const -{ - Q_ASSERT(row >= 0 && row < count()); - - while(row > cache.lastIndex()) - cache.append(slowFetchRecord(cache.lastIndex()+1)); - while(row < cache.firstIndex()) - cache.prepend(slowFetchRecord(cache.firstIndex()-1)); - - return cache.at(row); -} -\endcode - - The append() and prepend() functions cause the vector window to move to - where the current row is requested from. This usage can be further - optimized by using the insert() function to reset the vector window to - a row in the case where the row is a long way from the current row. It - may also be worth while to fetch multiple records into the cache if - it is faster to retrieve them in a batch operation. - - See the The \l{Offset Vector Example}{Offset Vector} example. -*/ - -/*! \fn QOffsetVector::QOffsetVector(int capacity) - - Constructs a vector with the given \a capacity. - - \sa setCapacity() -*/ - -/*! \fn QOffsetVector::QOffsetVector(const QOffsetVector &other) - - Constructs a copy of \a other. - - This operation takes \l{constant time}, because QOffsetVector is - \l{implicitly shared}. This makes returning a QOffsetVector from a - function very fast. If a shared instance is modified, it will be - copied (copy-on-write), and that takes \l{linear time}. - - \sa operator=() -*/ - -/*! \fn QOffsetVector::~QOffsetVector() - Destorys the vector. -*/ - -/*! \fn void QOffsetVector::detach() - - \internal -*/ - -/*! \fn bool QOffsetVector::isDetached() const - - \internal -*/ - -/*! \fn void QOffsetVector::setSharable(bool sharable) - - \internal -*/ - - -/*! \fn QOffsetVector &QOffsetVector::operator=(const QOffsetVector &other) - - Assigns \a other to this vector and returns a reference to this vector. -*/ - -/*! \fn bool QOffsetVector::operator==(const QOffsetVector &other) const - - Returns true if \a other is equal to this vector; otherwise returns false. - - Two vectors are considered equal if they contain the same values at the same - indexes. This function requires the value type to implement the \c operator==(). - - \sa operator!=() -*/ - -/*! \fn bool QOffsetVector::operator!=(const QOffsetVector &other) const - - Returns true if \a other is not equal to this vector; otherwise - returns false. - - Two vector are considered equal if they contain the same values at the same - indexes. This function requires the value type to implement the \c operator==(). - - \sa operator==() -*/ - -/*! \fn int QOffsetVector::capacity() const - - Returns the number of items the vector can store before it is full. - When a vector contains a number of items equal to its capacity, adding new - items will cause items furthest from the added item to be removed. - - \sa setCapacity(), size() -*/ - -/*! \fn int QOffsetVector::count() const - - \overload - - Same as size(). -*/ - -/*! \fn int QOffsetVector::size() const - - Returns the number of items contained within the vector. - - \sa capacity() -*/ - -/*! \fn bool QOffsetVector::isEmpty() const - - Returns true if no items are stored within the vector. - - \sa size(), capacity() -*/ - -/*! \fn bool QOffsetVector::isFull() const - - Returns true if the number of items stored within the vector is equal - to the capacity of the vector. - - \sa size(), capacity() -*/ - -/*! \fn int QOffsetVector::available() const - - Returns the number of items that can be added to the vector before it becomes full. - - \sa size(), capacity(), isFull() -*/ - -/*! \fn void QOffsetVector::clear() - - Removes all items from the vector. The capacity is unchanged. -*/ - -/*! \fn void QOffsetVector::setCapacity(int size) - - Sets the capacity of the vector to the given \a size. A vector can hold a - number of items equal to its capacity. When inserting, appending or prepending - items to the vector, if the vector is already full then the item furthest from - the added item will be removed. - - If the given \a size is smaller than the current count of items in the vector - then only the last \a size items from the vector will remain. - - \sa capacity(), isFull() -*/ - -/*! \fn const T &QOffsetVector::at(int i) const - - Returns the item at index position \a i in the vector. \a i must - be a valid index position in the vector (i.e, firstIndex() <= \a i <= lastIndex()). - - The indexes in the vector refer to number of positions the item is from the - first item appended into the vector. That is to say a vector with a capacity of - 100, that has had 150 items appended will have a valid index range of - 50 to 149. This allows inserting an retrieving items into the vector based - on a theoretical infinite list - - \sa firstIndex(), lastIndex(), insert(), operator[]() -*/ - -/*! \fn T &QOffsetVector::operator[](int i) - - Returns the item at index position \a i as a modifiable reference. If - the vector does not contain an item at the given index position \a i - then it will first insert an empty item at that position. - - In most cases it is better to use either at() or insert(). - - Note that using non-const operators can cause QOffsetVector to do a deep - copy. - - \sa insert(), at() -*/ - -/*! \fn const T &QOffsetVector::operator[](int i) const - - \overload - - Same as at(\a i). -*/ - -/*! \fn void QOffsetVector::append(const T &value) - - Inserts \a value at the end of the vector. If the vector is already full - the item at the start of the vector will be removed. - - \sa prepend(), insert(), isFull() -*/ - -/*! \fn void QOffsetVector::prepend(const T &value) - - Inserts \a value at the start of the vector. If the vector is already full - the item at the end of the vector will be removed. - - \sa append(), insert(), isFull() -*/ - -/*! \fn void QOffsetVector::insert(int i, const T &value) - - Inserts the \a value at the index position \a i. If the vector already contains - an item at \a i then that value is replaced. If \a i is either one more than - lastIndex() or one less than firstIndex() it is the equivalent to an append() - or a prepend(). - - If the given index \a i is not within the current range of the vector nor adjacent - to the bounds of the vector's index range the vector is first cleared before - inserting the item. At this point the vector will have a size of 1. It is worth - while then taking effort to insert items in an order than starts adjacent to the - current index range for the vector. - - \sa prepend(), append(), isFull(), firstIndex(), lastIndex() -*/ - -/*! \fn bool QOffsetVector::containsIndex(int i) const - - Returns true if the vector's index range includes the given index \a i. - - \sa firstIndex(), lastIndex() -*/ - -/*! \fn int QOffsetVector::firstIndex() const - Returns the first valid index in the vector. The index will be invalid if the - vector is empty. However the following code is valid even when the vector is empty: - - \code - for (int i = vector.firstIndex(); i <= vector.lastIndex(); ++i) - qDebug() << "Item" << i << "of the vector is" << vector.at(i); - \endcode - - \sa capacity(), size(), lastIndex() -*/ - -/*! \fn int QOffsetVector::lastIndex() const - - Returns the last valid index in the vector. If the vector is empty will return -1. - - \code - for (int i = vector.firstIndex(); i <= vector.lastIndex(); ++i) - qDebug() << "Item" << i << "of the vector is" << vector.at(i); - \endcode - - \sa capacity(), size(), firstIndex() -*/ - - -/*! \fn T &QOffsetVector::first() - - Returns a reference to the first item in the vector. This function - assumes that the vector isn't empty. - - \sa last(), isEmpty() -*/ - -/*! \fn T &QOffsetVector::last() - - Returns a reference to the last item in the vector. This function - assumes that the vector isn't empty. - - \sa first(), isEmpty() -*/ - -/*! \fn const T& QOffsetVector::first() const - - \overload -*/ - -/*! \fn const T& QOffsetVector::last() const - - \overload -*/ - -/*! \fn void QOffsetVector::removeFirst() - - Removes the first item from the vector. This function assumes that - the vector isn't empty. - - \sa removeLast() -*/ - -/*! \fn void QOffsetVector::removeLast() - - Removes the last item from the vector. This function assumes that - the vector isn't empty. - - \sa removeFirst() -*/ - -/*! \fn T QOffsetVector::takeFirst() - - Removes the first item in the vector and returns it. - - If you don't sue the return value, removeFirst() is more efficient. - - \sa takeLast(), removeFirst() -*/ - -/*! \fn T QOffsetVector::takeLast() - - Removes the last item in the vector and returns it. - - If you don't sue the return value, removeLast() is more efficient. - - \sa takeFirst(), removeLast() -*/ - -/*! \fn void QOffsetVector::dump() const - - \internal - - Sends information about the vector's internal structure to qDebug() -*/ diff --git a/src/corelib/tools/qoffsetvector.h b/src/corelib/tools/qoffsetvector.h deleted file mode 100644 index 7030862..0000000 --- a/src/corelib/tools/qoffsetvector.h +++ /dev/null @@ -1,386 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $TROLLTECH_DUAL_LICENSE$ -** -****************************************************************************/ - -#ifndef QCIRCULARBUFFER_H -#define QCIRCULARBUFFER_H - -#include - -struct QOffsetVectorData -{ - QBasicAtomicInt ref; - int alloc; - int count; - int start; - int offset; - uint sharable : 1; - - void dump() const; -}; - -template -struct QOffsetVectorTypedData -{ - QBasicAtomicInt ref; - int alloc; - int count; - int start; - int offset; - uint sharable : 1; - - T array[1]; -}; - -class QOffsetVectorDevice; - -template -class QOffsetVector { - typedef QOffsetVectorTypedData Data; - union { QOffsetVectorData *p; QOffsetVectorTypedData *d; }; -public: - explicit QOffsetVector(int capacity = 0); - QOffsetVector(const QOffsetVector &v) : d(v.d) { d->ref.ref(); if (!d->sharable) detach_helper(); } - - inline ~QOffsetVector() { if (!d) return; if (!d->ref.deref()) free(d); } - - inline void detach() { if (d->ref != 1) detach_helper(); } - inline bool isDetached() const { return d->ref == 1; } - inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; } - - QOffsetVector &operator=(const QOffsetVector &other); - bool operator==(const QOffsetVector &other) const; - inline bool operator!=(const QOffsetVector &other) const { return !(*this == other); } - - inline int capacity() const {return d->alloc; } - inline int count() const { return d->count; } - inline int size() const { return d->count; } - - inline bool isEmpty() const { return d->count == 0; } - inline bool isFull() const { return d->count == d->alloc; } - inline int available() const { return d->alloc - d->count; } - - void clear(); - void setCapacity(int size); - - const T &at(int pos) const; - T &operator[](int i); - const T &operator[](int i) const; - - void append(const T &value); - void prepend(const T &value); - void insert(int pos, const T &value); - - inline bool containsIndex(int pos) const { return pos >= d->offset && pos - d->offset < d->count; } - inline int firstIndex() const { return d->offset; } - inline int lastIndex() const { return d->offset + d->count - 1; } - - inline const T &first() const { Q_ASSERT(!isEmpty()); return d->array[d->start]; } - inline const T &last() const { Q_ASSERT(!isEmpty()); return d->array[(d->start + d->count -1) % d->alloc]; } - inline T &first() { Q_ASSERT(!isEmpty()); detach(); return d->array[d->start]; } - inline T &last() { Q_ASSERT(!isEmpty()); detach(); return d->array[(d->start + d->count -1) % d->alloc]; } - - void removeFirst(); - T takeFirst(); - void removeLast(); - T takeLast(); - - // debug - void dump() const { p->dump(); } -private: - void detach_helper(); - - QOffsetVectorData *malloc(int alloc); - void free(Data *d); - int sizeOfTypedData() { - // this is more or less the same as sizeof(Data), except that it doesn't - // count the padding at the end - return reinterpret_cast(&(reinterpret_cast(this))->array[1]) - reinterpret_cast(this); - } -}; - -template -void QOffsetVector::detach_helper() -{ - union { QOffsetVectorData *p; QOffsetVectorTypedData *d; } x; - - x.p = malloc(d->alloc); - x.d->ref = 1; - x.d->count = d->count; - x.d->start = d->start; - x.d->offset = d->offset; - x.d->alloc = d->alloc; - x.d->sharable = true; - - T *dest = x.d->array + x.d->start; - T *src = d->array + d->start; - int count = x.d->count; - while (count--) { - if (QTypeInfo::isComplex) { - new (dest) T(*src); - } else { - *dest = *src; - } - dest++; - if (dest == x.d->array + x.d->alloc) - dest = x.d->array; - src++; - if (src == d->array + d->alloc) - src = d->array; - } - - if (!d->ref.deref()) - free(d); - d = x.d; -} - -template -void QOffsetVector::setCapacity(int asize) -{ - if (asize == d->alloc) - return; - detach(); - union { QOffsetVectorData *p; QOffsetVectorTypedData *d; } x; - x.p = malloc(asize); - x.d->alloc = asize; - x.d->count = qMin(d->count, asize); - x.d->offset = d->offset + d->count - x.d->count; - x.d->start = x.d->offset % x.d->alloc; - /* deep copy - - slow way now, get unit test working, then - improve performance if need be. (e.g. memcpy) - */ - T *dest = x.d->array + (x.d->start + x.d->count-1) % x.d->alloc; - T *src = d->array + (d->start + d->count-1) % d->alloc; - int count = x.d->count; - while (count--) { - if (QTypeInfo::isComplex) { - new (dest) T(*src); - } else { - *dest = *src; - } - if (dest == x.d->array) - dest = x.d->array + x.d->alloc; - dest--; - if (src == d->array) - src = d->array + d->alloc; - src--; - } - /* free old */ - free(d); - d = x.d; -} - -template -void QOffsetVector::clear() -{ - if (d->ref == 1) { - if (QTypeInfo::isComplex) { - int count = d->count; - T * i = d->array + d->start; - T * e = d->array + d->alloc; - while (count--) { - i->~T(); - i++; - if (i == e) - i = d->array; - } - } - d->count = d->start = d->offset = 0; - } else { - union { QOffsetVectorData *p; QOffsetVectorTypedData *d; } x; - x.p = malloc(d->alloc); - x.d->ref = 1; - x.d->alloc = d->alloc; - x.d->count = x.d->start = x.d->offset = 0; - x.d->sharable = true; - if (!d->ref.deref()) free(d); - d = x.d; - } -} - -template -inline QOffsetVectorData *QOffsetVector::malloc(int aalloc) -{ - return static_cast(qMalloc(sizeOfTypedData() + (aalloc - 1) * sizeof(T))); -} - -template -QOffsetVector::QOffsetVector(int asize) -{ - p = malloc(asize); - d->ref = 1; - d->alloc = asize; - d->count = d->start = d->offset = 0; - d->sharable = true; -} - -template -QOffsetVector &QOffsetVector::operator=(const QOffsetVector &other) -{ - other.d->ref.ref(); - if (!d->ref.deref()) - free(d); - d = other.d; - if (!d->sharable) - detach_helper(); - return *this; -} - -template -bool QOffsetVector::operator==(const QOffsetVector &other) const -{ - if (other.d == d) - return true; - if (other.d->start != d->start - || other.d->count != d->count - || other.d->offset != d->offset - || other.d->alloc != d->alloc) - return false; - for (int i = firstIndex(); i <= lastIndex(); ++i) - if (!(at(i) == other.at(i))) - return false; - return true; -} - -template -void QOffsetVector::free(Data *x) -{ - if (QTypeInfo::isComplex) { - int count = d->count; - T * i = d->array + d->start; - T * e = d->array + d->alloc; - while (count--) { - i->~T(); - i++; - if (i == e) - i = d->array; - } - } - qFree(x); -} - -template -void QOffsetVector::append(const T &value) -{ - detach(); - if (QTypeInfo::isComplex) { - if (d->count == d->alloc) - (d->array + (d->start+d->count) % d->alloc)->~T(); - new (d->array + (d->start+d->count) % d->alloc) T(value); - } else { - d->array[(d->start+d->count) % d->alloc] = value; - } - - if (d->count == d->alloc) { - d->start++; - d->start %= d->alloc; - d->offset++; - } else { - d->count++; - } -} - -template -void QOffsetVector::prepend(const T &value) -{ - detach(); - if (d->start) - d->start--; - else - d->start = d->alloc-1; - d->offset--; - - if (d->count != d->alloc) - d->count++; - else - if (d->count == d->alloc) - (d->array + d->start)->~T(); - - if (QTypeInfo::isComplex) - new (d->array + d->start) T(value); - else - d->array[d->start] = value; -} - -template -void QOffsetVector::insert(int pos, const T &value) -{ - detach(); - if (containsIndex(pos)) { - if(QTypeInfo::isComplex) - new (d->array + pos % d->alloc) T(value); - else - d->array[pos % d->alloc] = value; - } else if (pos == d->offset-1) - prepend(value); - else if (pos == d->offset+d->count) - append(value); - else { - // we don't leave gaps. - clear(); - d->offset = d->start = pos; - d->start %= d->alloc; - d->count = 1; - if (QTypeInfo::isComplex) - new (d->array + d->start) T(value); - else - d->array[d->start] = value; - } -} - -template -inline const T &QOffsetVector::at(int pos) const -{ Q_ASSERT_X(pos >= d->offset && pos - d->offset < d->count, "QOffsetVector::at", "index out of range"); return d->array[pos % d->alloc]; } -template -inline const T &QOffsetVector::operator[](int pos) const -{ Q_ASSERT_X(pos >= d->offset && pos - d->offset < d->count, "QOffsetVector::at", "index out of range"); return d->array[pos % d->alloc]; } -template - -// can use the non-inline one to modify the index range. -inline T &QOffsetVector::operator[](int pos) -{ - detach(); - if (!containsIndex(pos)) - insert(pos, T()); - return d->array[pos % d->alloc]; -} - -template -inline void QOffsetVector::removeFirst() -{ - Q_ASSERT(d->count > 0); - detach(); - d->count--; - if (QTypeInfo::isComplex) - (d->array + d->start)->~T(); - d->start = (d->start + 1) % d->alloc; - d->offset++; -} - -template -inline void QOffsetVector::removeLast() -{ - Q_ASSERT(d->count > 0); - detach(); - d->count--; - if (QTypeInfo::isComplex) - (d->array + (d->start + d->count) % d->alloc)->~T(); -} - -template -inline T QOffsetVector::takeFirst() -{ T t = first(); removeFirst(); return t; } - -template -inline T QOffsetVector::takeLast() -{ T t = last(); removeLast(); return t; } - -#endif diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 626c9e5..aaf3f21 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -19,7 +19,7 @@ HEADERS += \ tools/qlocale_p.h \ tools/qlocale_data_p.h \ tools/qmap.h \ - tools/qoffsetvector.h \ + tools/qcontiguouscache.h \ tools/qpodlist_p.h \ tools/qpoint.h \ tools/qqueue.h \ @@ -54,7 +54,7 @@ SOURCES += \ tools/qlocale.cpp \ tools/qpoint.cpp \ tools/qmap.cpp \ - tools/qoffsetvector.cpp \ + tools/qcontiguouscache.cpp \ tools/qrect.cpp \ tools/qregexp.cpp \ tools/qshareddata.cpp \ diff --git a/tests/auto/qcontiguouscache/qcontiguouscache.pro b/tests/auto/qcontiguouscache/qcontiguouscache.pro new file mode 100644 index 0000000..618efed --- /dev/null +++ b/tests/auto/qcontiguouscache/qcontiguouscache.pro @@ -0,0 +1,8 @@ +load(qttest_p4) + +QT = core + +SOURCES += tst_qcontiguouscache.cpp + + + diff --git a/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp b/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp new file mode 100644 index 0000000..493032a --- /dev/null +++ b/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp @@ -0,0 +1,361 @@ +/**************************************************************************** +** +** This file is part of the $PACKAGE_NAME$. +** +** Copyright (C) $THISYEAR$ $COMPANY_NAME$. +** +** $QT_EXTENDED_DUAL_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include +#include + + +#if defined(FORCE_UREF) +template +inline QDebug &operator<<(QDebug debug, const QContiguousCache &contiguousCache) +#else +template +inline QDebug operator<<(QDebug debug, const QContiguousCache &contiguousCache) +#endif +{ + debug.nospace() << "QContiguousCache("; + for (int i = contiguousCache.firstIndex(); i <= contiguousCache.lastIndex(); ++i) { + debug << contiguousCache[i]; + if (i != contiguousCache.lastIndex()) + debug << ", "; + } + debug << ")"; + return debug.space(); +} + +#if defined(NO_BENCHMARK) and defined(QBENCHMARK) +#undef QBENCHMARK +#define QBENCHMARK +#endif + +class tst_QContiguousCache : public QObject +{ + Q_OBJECT +public: + tst_QContiguousCache() {} + virtual ~tst_QContiguousCache() {} +private slots: + void empty(); + void forwardBuffer(); + void scrollingList(); + + void complexType(); + + void operatorAt(); + + void cacheBenchmark(); + void contiguousCacheBenchmark(); + + void setCapacity(); +}; + +QTEST_MAIN(tst_QContiguousCache) + +void tst_QContiguousCache::empty() +{ + QContiguousCache c(10); + QCOMPARE(c.capacity(), 10); + QCOMPARE(c.count(), 0); + QVERIFY(c.isEmpty()); + c.append(1); + QVERIFY(!c.isEmpty()); + c.clear(); + QCOMPARE(c.capacity(), 10); + QCOMPARE(c.count(), 0); + QVERIFY(c.isEmpty()); + c.prepend(1); + QVERIFY(!c.isEmpty()); + c.clear(); + QCOMPARE(c.count(), 0); + QVERIFY(c.isEmpty()); + QCOMPARE(c.capacity(), 10); +} + +void tst_QContiguousCache::forwardBuffer() +{ + int i; + QContiguousCache c(10); + for(i = 1; i < 30; ++i) { + c.append(i); + QCOMPARE(c.first(), qMax(1, i-9)); + QCOMPARE(c.last(), i); + QCOMPARE(c.count(), qMin(i, 10)); + } + + c.clear(); + + for(i = 1; i < 30; ++i) { + c.prepend(i); + QCOMPARE(c.last(), qMax(1, i-9)); + QCOMPARE(c.first(), i); + QCOMPARE(c.count(), qMin(i, 10)); + } +} + +void tst_QContiguousCache::scrollingList() +{ + int i; + QContiguousCache c(10); + + // Once allocated QContiguousCache should not + // allocate any additional memory for non + // complex data types. + QBENCHMARK { + // simulate scrolling in a list of items; + for(i = 0; i < 10; ++i) + c.append(i); + + QCOMPARE(c.firstIndex(), 0); + QCOMPARE(c.lastIndex(), 9); + QVERIFY(c.containsIndex(0)); + QVERIFY(c.containsIndex(9)); + QVERIFY(!c.containsIndex(10)); + + for (i = 0; i < 10; ++i) + QCOMPARE(c.at(i), i); + + for (i = 10; i < 30; ++i) + c.append(i); + + QCOMPARE(c.firstIndex(), 20); + QCOMPARE(c.lastIndex(), 29); + QVERIFY(c.containsIndex(20)); + QVERIFY(c.containsIndex(29)); + QVERIFY(!c.containsIndex(30)); + + for (i = 20; i < 30; ++i) + QCOMPARE(c.at(i), i); + + for (i = 19; i >= 10; --i) + c.prepend(i); + + QCOMPARE(c.firstIndex(), 10); + QCOMPARE(c.lastIndex(), 19); + QVERIFY(c.containsIndex(10)); + QVERIFY(c.containsIndex(19)); + QVERIFY(!c.containsIndex(20)); + + for (i = 10; i < 20; ++i) + QCOMPARE(c.at(i), i); + + for (i = 200; i < 220; ++i) + c.insert(i, i); + + QCOMPARE(c.firstIndex(), 210); + QCOMPARE(c.lastIndex(), 219); + QVERIFY(c.containsIndex(210)); + QVERIFY(c.containsIndex(219)); + QVERIFY(!c.containsIndex(300)); + QVERIFY(!c.containsIndex(209)); + + for (i = 220; i < 220; ++i) { + QVERIFY(c.containsIndex(i)); + QCOMPARE(c.at(i), i); + } + c.clear(); // needed to reset benchmark + } + + // from a specific bug that was encountered. 100 to 299 cached, attempted to cache 250 - 205 via insert, failed. + // bug was that item at 150 would instead be item that should have been inserted at 250 + c.setCapacity(200); + for(i = 100; i < 300; ++i) + c.insert(i, i); + for (i = 250; i <= 306; ++i) + c.insert(i, 1000+i); + for (i = 107; i <= 306; ++i) { + QVERIFY(c.containsIndex(i)); + QCOMPARE(c.at(i), i < 250 ? i : 1000+i); + } +} + +struct RefCountingClassData +{ + QBasicAtomicInt ref; + static RefCountingClassData shared_null; +}; + +RefCountingClassData RefCountingClassData::shared_null = { + Q_BASIC_ATOMIC_INITIALIZER(1) +}; + +class RefCountingClass +{ +public: + RefCountingClass() : d(&RefCountingClassData::shared_null) { d->ref.ref(); } + + RefCountingClass(const RefCountingClass &other) + { + d = other.d; + d->ref.ref(); + } + + ~RefCountingClass() + { + if (!d->ref.deref()) + delete d; + } + + RefCountingClass &operator=(const RefCountingClass &other) + { + if (!d->ref.deref()) + delete d; + d = other.d; + d->ref.ref(); + return *this; + } + + int refCount() const { return d->ref; } +private: + RefCountingClassData *d; +}; + +void tst_QContiguousCache::complexType() +{ + RefCountingClass original; + + QContiguousCache contiguousCache(10); + contiguousCache.append(original); + QCOMPARE(original.refCount(), 3); + contiguousCache.removeFirst(); + QCOMPARE(original.refCount(), 2); // shared null, 'original'. + contiguousCache.append(original); + QCOMPARE(original.refCount(), 3); + contiguousCache.clear(); + QCOMPARE(original.refCount(), 2); + + for(int i = 0; i < 100; ++i) + contiguousCache.insert(i, original); + + QCOMPARE(original.refCount(), 12); // shared null, 'original', + 10 in contiguousCache. + + contiguousCache.clear(); + QCOMPARE(original.refCount(), 2); + for (int i = 0; i < 100; i++) + contiguousCache.append(original); + + QCOMPARE(original.refCount(), 12); // shared null, 'original', + 10 in contiguousCache. + contiguousCache.clear(); + QCOMPARE(original.refCount(), 2); + + for (int i = 0; i < 100; i++) + contiguousCache.prepend(original); + + QCOMPARE(original.refCount(), 12); // shared null, 'original', + 10 in contiguousCache. + contiguousCache.clear(); + QCOMPARE(original.refCount(), 2); + + for (int i = 0; i < 100; i++) + contiguousCache.append(original); + + contiguousCache.takeLast(); + QCOMPARE(original.refCount(), 11); + + contiguousCache.takeFirst(); + QCOMPARE(original.refCount(), 10); +} + +void tst_QContiguousCache::operatorAt() +{ + RefCountingClass original; + QContiguousCache contiguousCache(10); + + for (int i = 25; i < 35; ++i) + contiguousCache[i] = original; + + QCOMPARE(original.refCount(), 12); // shared null, orig, items in cache + + // verify const access does not copy items. + const QContiguousCache copy(contiguousCache); + for (int i = 25; i < 35; ++i) + QCOMPARE(copy[i].refCount(), 12); + + // verify modifying the original increments ref count (e.g. does a detach) + contiguousCache[25] = original; + QCOMPARE(original.refCount(), 22); +} + +/* + Benchmarks must be near identical in tasks to be fair. + QCache uses pointers to ints as its a requirement of QCache, + whereas QContiguousCache doesn't support pointers (won't free them). + Given the ability to use simple data types is a benefit, its + fair. Although this obviously must take into account we are + testing QContiguousCache use cases here, QCache has its own + areas where it is the more sensible class to use. +*/ +void tst_QContiguousCache::cacheBenchmark() +{ + QBENCHMARK { + QCache cache; + cache.setMaxCost(100); + + for (int i = 0; i < 1000; i++) + cache.insert(i, new int(i)); + } +} + +void tst_QContiguousCache::contiguousCacheBenchmark() +{ + QBENCHMARK { + QContiguousCache contiguousCache(100); + for (int i = 0; i < 1000; i++) + contiguousCache.insert(i, i); + } +} + +void tst_QContiguousCache::setCapacity() +{ + int i; + QContiguousCache contiguousCache(100); + for (i = 280; i < 310; ++i) + contiguousCache.insert(i, i); + QCOMPARE(contiguousCache.capacity(), 100); + QCOMPARE(contiguousCache.count(), 30); + QCOMPARE(contiguousCache.firstIndex(), 280); + QCOMPARE(contiguousCache.lastIndex(), 309); + + for (i = contiguousCache.firstIndex(); i <= contiguousCache.lastIndex(); ++i) { + QVERIFY(contiguousCache.containsIndex(i)); + QCOMPARE(contiguousCache.at(i), i); + } + + contiguousCache.setCapacity(150); + + QCOMPARE(contiguousCache.capacity(), 150); + QCOMPARE(contiguousCache.count(), 30); + QCOMPARE(contiguousCache.firstIndex(), 280); + QCOMPARE(contiguousCache.lastIndex(), 309); + + for (i = contiguousCache.firstIndex(); i <= contiguousCache.lastIndex(); ++i) { + QVERIFY(contiguousCache.containsIndex(i)); + QCOMPARE(contiguousCache.at(i), i); + } + + contiguousCache.setCapacity(20); + + QCOMPARE(contiguousCache.capacity(), 20); + QCOMPARE(contiguousCache.count(), 20); + QCOMPARE(contiguousCache.firstIndex(), 290); + QCOMPARE(contiguousCache.lastIndex(), 309); + + for (i = contiguousCache.firstIndex(); i <= contiguousCache.lastIndex(); ++i) { + QVERIFY(contiguousCache.containsIndex(i)); + QCOMPARE(contiguousCache.at(i), i); + } +} + +#include "tst_qcontiguouscache.moc" diff --git a/tests/auto/qoffsetvector/qoffsetvector.pro b/tests/auto/qoffsetvector/qoffsetvector.pro deleted file mode 100644 index 0b801f3..0000000 --- a/tests/auto/qoffsetvector/qoffsetvector.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4) - -QT = core - -SOURCES += tst_qoffsetvector.cpp - - - diff --git a/tests/auto/qoffsetvector/tst_qoffsetvector.cpp b/tests/auto/qoffsetvector/tst_qoffsetvector.cpp deleted file mode 100644 index 439ea2c..0000000 --- a/tests/auto/qoffsetvector/tst_qoffsetvector.cpp +++ /dev/null @@ -1,361 +0,0 @@ -/**************************************************************************** -** -** This file is part of the $PACKAGE_NAME$. -** -** Copyright (C) $THISYEAR$ $COMPANY_NAME$. -** -** $QT_EXTENDED_DUAL_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include - -#include -#include - - -#if defined(FORCE_UREF) -template -inline QDebug &operator<<(QDebug debug, const QOffsetVector &offsetVector) -#else -template -inline QDebug operator<<(QDebug debug, const QOffsetVector &offsetVector) -#endif -{ - debug.nospace() << "QOffsetVector("; - for (int i = offsetVector.firstIndex(); i <= offsetVector.lastIndex(); ++i) { - debug << offsetVector[i]; - if (i != offsetVector.lastIndex()) - debug << ", "; - } - debug << ")"; - return debug.space(); -} - -#if defined(NO_BENCHMARK) and defined(QBENCHMARK) -#undef QBENCHMARK -#define QBENCHMARK -#endif - -class tst_QOffsetVector : public QObject -{ - Q_OBJECT -public: - tst_QOffsetVector() {} - virtual ~tst_QOffsetVector() {} -private slots: - void empty(); - void forwardBuffer(); - void scrollingList(); - - void complexType(); - - void operatorAt(); - - void cacheBenchmark(); - void offsetVectorBenchmark(); - - void setCapacity(); -}; - -QTEST_MAIN(tst_QOffsetVector) - -void tst_QOffsetVector::empty() -{ - QOffsetVector c(10); - QCOMPARE(c.capacity(), 10); - QCOMPARE(c.count(), 0); - QVERIFY(c.isEmpty()); - c.append(1); - QVERIFY(!c.isEmpty()); - c.clear(); - QCOMPARE(c.capacity(), 10); - QCOMPARE(c.count(), 0); - QVERIFY(c.isEmpty()); - c.prepend(1); - QVERIFY(!c.isEmpty()); - c.clear(); - QCOMPARE(c.count(), 0); - QVERIFY(c.isEmpty()); - QCOMPARE(c.capacity(), 10); -} - -void tst_QOffsetVector::forwardBuffer() -{ - int i; - QOffsetVector c(10); - for(i = 1; i < 30; ++i) { - c.append(i); - QCOMPARE(c.first(), qMax(1, i-9)); - QCOMPARE(c.last(), i); - QCOMPARE(c.count(), qMin(i, 10)); - } - - c.clear(); - - for(i = 1; i < 30; ++i) { - c.prepend(i); - QCOMPARE(c.last(), qMax(1, i-9)); - QCOMPARE(c.first(), i); - QCOMPARE(c.count(), qMin(i, 10)); - } -} - -void tst_QOffsetVector::scrollingList() -{ - int i; - QOffsetVector c(10); - - // Once allocated QOffsetVector should not - // allocate any additional memory for non - // complex data types. - QBENCHMARK { - // simulate scrolling in a list of items; - for(i = 0; i < 10; ++i) - c.append(i); - - QCOMPARE(c.firstIndex(), 0); - QCOMPARE(c.lastIndex(), 9); - QVERIFY(c.containsIndex(0)); - QVERIFY(c.containsIndex(9)); - QVERIFY(!c.containsIndex(10)); - - for (i = 0; i < 10; ++i) - QCOMPARE(c.at(i), i); - - for (i = 10; i < 30; ++i) - c.append(i); - - QCOMPARE(c.firstIndex(), 20); - QCOMPARE(c.lastIndex(), 29); - QVERIFY(c.containsIndex(20)); - QVERIFY(c.containsIndex(29)); - QVERIFY(!c.containsIndex(30)); - - for (i = 20; i < 30; ++i) - QCOMPARE(c.at(i), i); - - for (i = 19; i >= 10; --i) - c.prepend(i); - - QCOMPARE(c.firstIndex(), 10); - QCOMPARE(c.lastIndex(), 19); - QVERIFY(c.containsIndex(10)); - QVERIFY(c.containsIndex(19)); - QVERIFY(!c.containsIndex(20)); - - for (i = 10; i < 20; ++i) - QCOMPARE(c.at(i), i); - - for (i = 200; i < 220; ++i) - c.insert(i, i); - - QCOMPARE(c.firstIndex(), 210); - QCOMPARE(c.lastIndex(), 219); - QVERIFY(c.containsIndex(210)); - QVERIFY(c.containsIndex(219)); - QVERIFY(!c.containsIndex(300)); - QVERIFY(!c.containsIndex(209)); - - for (i = 220; i < 220; ++i) { - QVERIFY(c.containsIndex(i)); - QCOMPARE(c.at(i), i); - } - c.clear(); // needed to reset benchmark - } - - // from a specific bug that was encountered. 100 to 299 cached, attempted to cache 250 - 205 via insert, failed. - // bug was that item at 150 would instead be item that should have been inserted at 250 - c.setCapacity(200); - for(i = 100; i < 300; ++i) - c.insert(i, i); - for (i = 250; i <= 306; ++i) - c.insert(i, 1000+i); - for (i = 107; i <= 306; ++i) { - QVERIFY(c.containsIndex(i)); - QCOMPARE(c.at(i), i < 250 ? i : 1000+i); - } -} - -struct RefCountingClassData -{ - QBasicAtomicInt ref; - static RefCountingClassData shared_null; -}; - -RefCountingClassData RefCountingClassData::shared_null = { - Q_BASIC_ATOMIC_INITIALIZER(1) -}; - -class RefCountingClass -{ -public: - RefCountingClass() : d(&RefCountingClassData::shared_null) { d->ref.ref(); } - - RefCountingClass(const RefCountingClass &other) - { - d = other.d; - d->ref.ref(); - } - - ~RefCountingClass() - { - if (!d->ref.deref()) - delete d; - } - - RefCountingClass &operator=(const RefCountingClass &other) - { - if (!d->ref.deref()) - delete d; - d = other.d; - d->ref.ref(); - return *this; - } - - int refCount() const { return d->ref; } -private: - RefCountingClassData *d; -}; - -void tst_QOffsetVector::complexType() -{ - RefCountingClass original; - - QOffsetVector offsetVector(10); - offsetVector.append(original); - QCOMPARE(original.refCount(), 3); - offsetVector.removeFirst(); - QCOMPARE(original.refCount(), 2); // shared null, 'original'. - offsetVector.append(original); - QCOMPARE(original.refCount(), 3); - offsetVector.clear(); - QCOMPARE(original.refCount(), 2); - - for(int i = 0; i < 100; ++i) - offsetVector.insert(i, original); - - QCOMPARE(original.refCount(), 12); // shared null, 'original', + 10 in offsetVector. - - offsetVector.clear(); - QCOMPARE(original.refCount(), 2); - for (int i = 0; i < 100; i++) - offsetVector.append(original); - - QCOMPARE(original.refCount(), 12); // shared null, 'original', + 10 in offsetVector. - offsetVector.clear(); - QCOMPARE(original.refCount(), 2); - - for (int i = 0; i < 100; i++) - offsetVector.prepend(original); - - QCOMPARE(original.refCount(), 12); // shared null, 'original', + 10 in offsetVector. - offsetVector.clear(); - QCOMPARE(original.refCount(), 2); - - for (int i = 0; i < 100; i++) - offsetVector.append(original); - - offsetVector.takeLast(); - QCOMPARE(original.refCount(), 11); - - offsetVector.takeFirst(); - QCOMPARE(original.refCount(), 10); -} - -void tst_QOffsetVector::operatorAt() -{ - RefCountingClass original; - QOffsetVector offsetVector(10); - - for (int i = 25; i < 35; ++i) - offsetVector[i] = original; - - QCOMPARE(original.refCount(), 12); // shared null, orig, items in vector - - // verify const access does not copy items. - const QOffsetVector copy(offsetVector); - for (int i = 25; i < 35; ++i) - QCOMPARE(copy[i].refCount(), 12); - - // verify modifying the original increments ref count (e.g. does a detach) - offsetVector[25] = original; - QCOMPARE(original.refCount(), 22); -} - -/* - Benchmarks must be near identical in tasks to be fair. - QCache uses pointers to ints as its a requirement of QCache, - whereas QOffsetVector doesn't support pointers (won't free them). - Given the ability to use simple data types is a benefit, its - fair. Although this obviously must take into account we are - testing QOffsetVector use cases here, QCache has its own - areas where it is the more sensible class to use. -*/ -void tst_QOffsetVector::cacheBenchmark() -{ - QBENCHMARK { - QCache cache; - cache.setMaxCost(100); - - for (int i = 0; i < 1000; i++) - cache.insert(i, new int(i)); - } -} - -void tst_QOffsetVector::offsetVectorBenchmark() -{ - QBENCHMARK { - QOffsetVector offsetVector(100); - for (int i = 0; i < 1000; i++) - offsetVector.insert(i, i); - } -} - -void tst_QOffsetVector::setCapacity() -{ - int i; - QOffsetVector offsetVector(100); - for (i = 280; i < 310; ++i) - offsetVector.insert(i, i); - QCOMPARE(offsetVector.capacity(), 100); - QCOMPARE(offsetVector.count(), 30); - QCOMPARE(offsetVector.firstIndex(), 280); - QCOMPARE(offsetVector.lastIndex(), 309); - - for (i = offsetVector.firstIndex(); i <= offsetVector.lastIndex(); ++i) { - QVERIFY(offsetVector.containsIndex(i)); - QCOMPARE(offsetVector.at(i), i); - } - - offsetVector.setCapacity(150); - - QCOMPARE(offsetVector.capacity(), 150); - QCOMPARE(offsetVector.count(), 30); - QCOMPARE(offsetVector.firstIndex(), 280); - QCOMPARE(offsetVector.lastIndex(), 309); - - for (i = offsetVector.firstIndex(); i <= offsetVector.lastIndex(); ++i) { - QVERIFY(offsetVector.containsIndex(i)); - QCOMPARE(offsetVector.at(i), i); - } - - offsetVector.setCapacity(20); - - QCOMPARE(offsetVector.capacity(), 20); - QCOMPARE(offsetVector.count(), 20); - QCOMPARE(offsetVector.firstIndex(), 290); - QCOMPARE(offsetVector.lastIndex(), 309); - - for (i = offsetVector.firstIndex(); i <= offsetVector.lastIndex(); ++i) { - QVERIFY(offsetVector.containsIndex(i)); - QCOMPARE(offsetVector.at(i), i); - } -} - -#include "tst_qoffsetvector.moc" -- cgit v0.12 From f7516971028d4637eeff6899fbbc6f3e8b8b5c79 Mon Sep 17 00:00:00 2001 From: Ian Walters Date: Tue, 7 Apr 2009 16:37:51 +1000 Subject: Update licensing headers. Update files to have consistent licencesing with the rest of Qt. --- doc/src/examples/contiguouscache.qdoc | 34 +++++++++++++++- examples/tools/contiguouscache/main.cpp | 41 +++++++++++++++++++ examples/tools/contiguouscache/randomlistmodel.cpp | 40 +++++++++++++++++++ examples/tools/contiguouscache/randomlistmodel.h | 40 +++++++++++++++++++ src/corelib/tools/qcontiguouscache.cpp | 40 +++++++++++++++++-- src/corelib/tools/qcontiguouscache.h | 46 ++++++++++++++++++++-- .../auto/qcontiguouscache/tst_qcontiguouscache.cpp | 37 +++++++++++++++-- 7 files changed, 267 insertions(+), 11 deletions(-) diff --git a/doc/src/examples/contiguouscache.qdoc b/doc/src/examples/contiguouscache.qdoc index 22c97fa..6c67d77 100644 --- a/doc/src/examples/contiguouscache.qdoc +++ b/doc/src/examples/contiguouscache.qdoc @@ -3,9 +3,39 @@ ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** -** This file is part of the $MODULE$ of the Qt Toolkit. +** This file is part of the documentation of the Qt Toolkit. ** -** $TROLLTECH_DUAL_LICENSE$ +** $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 qt-sales@nokia.com. +** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/examples/tools/contiguouscache/main.cpp b/examples/tools/contiguouscache/main.cpp index bdeb3f3..291aaf4 100644 --- a/examples/tools/contiguouscache/main.cpp +++ b/examples/tools/contiguouscache/main.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include "randomlistmodel.h" #include #include diff --git a/examples/tools/contiguouscache/randomlistmodel.cpp b/examples/tools/contiguouscache/randomlistmodel.cpp index 5c0953b..0f58c0e 100644 --- a/examples/tools/contiguouscache/randomlistmodel.cpp +++ b/examples/tools/contiguouscache/randomlistmodel.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ #include "randomlistmodel.h" static const int bufferSize(500); diff --git a/examples/tools/contiguouscache/randomlistmodel.h b/examples/tools/contiguouscache/randomlistmodel.h index ad8cfad..d32bf16 100644 --- a/examples/tools/contiguouscache/randomlistmodel.h +++ b/examples/tools/contiguouscache/randomlistmodel.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef RANDOMLISTMODEL_H #define RANDOMLISTMODEL_H diff --git a/src/corelib/tools/qcontiguouscache.cpp b/src/corelib/tools/qcontiguouscache.cpp index 5046912..1bcac96 100644 --- a/src/corelib/tools/qcontiguouscache.cpp +++ b/src/corelib/tools/qcontiguouscache.cpp @@ -1,17 +1,49 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** -** This file is part of the $MODULE$ of the Qt Toolkit. +** This file is part of the QtCore module of the Qt Toolkit. ** -** $TROLLTECH_DUAL_LICENSE$ +** $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 qt-sales@nokia.com. +** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qcontiguouscache.h" #include +QT_BEGIN_NAMESPACE + void QContiguousCacheData::dump() const { qDebug() << "capacity:" << alloc; @@ -357,3 +389,5 @@ MyRecord record(int row) const Sends information about the cache's internal structure to qDebug() */ + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h index 03012a2..5250a79 100644 --- a/src/corelib/tools/qcontiguouscache.h +++ b/src/corelib/tools/qcontiguouscache.h @@ -1,11 +1,41 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** -** This file is part of the $MODULE$ of the Qt Toolkit. +** This file is part of the QtCore module of the Qt Toolkit. ** -** $TROLLTECH_DUAL_LICENSE$ +** $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 qt-sales@nokia.com. +** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -14,6 +44,12 @@ #include +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Core) + struct QContiguousCacheData { QBasicAtomicInt ref; @@ -383,4 +419,8 @@ template inline T QContiguousCache::takeLast() { T t = last(); removeLast(); return t; } +QT_END_NAMESPACE + +QT_END_HEADER + #endif diff --git a/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp b/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp index 493032a..6580f87 100644 --- a/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp +++ b/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp @@ -1,10 +1,41 @@ /**************************************************************************** ** -** This file is part of the $PACKAGE_NAME$. +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) ** -** Copyright (C) $THISYEAR$ $COMPANY_NAME$. +** This file is part of the test suite of the Qt Toolkit. ** -** $QT_EXTENDED_DUAL_LICENSE$ +** $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 qt-sales@nokia.com. +** $QT_END_LICENSE$ ** ****************************************************************************/ -- cgit v0.12 From 21f15b50777ab3507f79061e749c5cee9acecb3b Mon Sep 17 00:00:00 2001 From: Ian Walters Date: Wed, 8 Apr 2009 10:05:27 +1000 Subject: Move qDebug code to correct location --- src/corelib/io/qdebug.h | 19 +++++++++++++++++ .../auto/qcontiguouscache/tst_qcontiguouscache.cpp | 24 ---------------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 8334146..6c05756 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -51,6 +51,7 @@ #include #include #include +#include QT_BEGIN_HEADER @@ -232,6 +233,24 @@ inline QDebug operator<<(QDebug debug, const QSet &set) return operator<<(debug, set.toList()); } +#if defined(FORCE_UREF) +template +inline QDebug &operator<<(QDebug debug, const QContiguousCache &contiguousCache) +#else +template +inline QDebug operator<<(QDebug debug, const QContiguousCache &cache) +#endif +{ + debug.nospace() << "QContiguousCache("; + for (int i = cache.firstIndex(); i <= cache.lastIndex(); ++i) { + debug << cache[i]; + if (i != cache.lastIndex()) + debug << ", "; + } + debug << ")"; + return debug.space(); +} + #if !defined(QT_NO_DEBUG_STREAM) Q_CORE_EXPORT_INLINE QDebug qDebug() { return QDebug(QtDebugMsg); } diff --git a/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp b/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp index 6580f87..91f6a9c 100644 --- a/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp +++ b/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp @@ -49,30 +49,6 @@ #include #include - -#if defined(FORCE_UREF) -template -inline QDebug &operator<<(QDebug debug, const QContiguousCache &contiguousCache) -#else -template -inline QDebug operator<<(QDebug debug, const QContiguousCache &contiguousCache) -#endif -{ - debug.nospace() << "QContiguousCache("; - for (int i = contiguousCache.firstIndex(); i <= contiguousCache.lastIndex(); ++i) { - debug << contiguousCache[i]; - if (i != contiguousCache.lastIndex()) - debug << ", "; - } - debug << ")"; - return debug.space(); -} - -#if defined(NO_BENCHMARK) and defined(QBENCHMARK) -#undef QBENCHMARK -#define QBENCHMARK -#endif - class tst_QContiguousCache : public QObject { Q_OBJECT -- cgit v0.12 From 142c059031f42f1f4cb64873c634e655f3b7a46d Mon Sep 17 00:00:00 2001 From: Ian Walters Date: Mon, 11 May 2009 10:26:10 +1000 Subject: Documentation patch from Jason A bunch of minor doc fixes. --- doc/src/examples/contiguouscache.qdoc | 34 ++++++++--------- src/corelib/tools/qcontiguouscache.cpp | 67 ++++++++++++++++++---------------- 2 files changed, 51 insertions(+), 50 deletions(-) diff --git a/doc/src/examples/contiguouscache.qdoc b/doc/src/examples/contiguouscache.qdoc index 6c67d77..71e7740 100644 --- a/doc/src/examples/contiguouscache.qdoc +++ b/doc/src/examples/contiguouscache.qdoc @@ -44,11 +44,11 @@ \title Contiguous Cache Example The Contiguous Cache example shows how to use QContiguousCache to manage memory usage for - very large models. In some environments memory is limited, and even when it - isn't users still dislike an application using - excessive memory. Using QContiguousCache to manage a list rather than loading - the entire list into memory allows the application to limit the amount - of memory it uses regardless of the size of the data set it accesses + very large models. In some environments memory is limited and, even when it + isn't, users still dislike an application using excessive memory. + Using QContiguousCache to manage a list, rather than loading + the entire list into memory, allows the application to limit the amount + of memory it uses, regardless of the size of the data set it accesses The simplest way to use QContiguousCache is to cache as items are requested. When a view requests an item at row N it is also likely to ask for items at rows near @@ -56,7 +56,7 @@ \snippet examples/tools/contiguouscache/randomlistmodel.cpp 0 - After getting the row the class determines if the row is in the bounds + After getting the row, the class determines if the row is in the bounds of the contiguous cache's current range. It would have been equally valid to simply have the following code instead. @@ -68,13 +68,12 @@ \endcode However a list will often jump rows if the scroll bar is used directly, resulting in - the code above to cause every row between where the cache was last centered - to the requested row to be fetched before the requested row is fetched. + the code above causing every row between the old and new rows to be fetched. Using QContiguousCache::lastIndex() and QContiguousCache::firstIndex() allows - the example to determine where in the list the cache is currently over. These values - don't represent the indexes into the cache own memory, but rather a virtual - infinite array that the cache represents. + the example to determine what part of the list the cache is currently caching. + These values don't represent the indexes into the cache's own memory, but rather + a virtual infinite array that the cache represents. By using QContiguousCache::append() and QContiguousCache::prepend() the code ensures that items that may be still on the screen are not lost when the requested row @@ -84,16 +83,15 @@ rows with significant gaps between them consider using QCache instead. And thats it. A perfectly reasonable cache, using minimal memory for a very large - list. In this case the accessor for getting the words into cache: - - \snippet examples/tools/contiguouscache/randomlistmodel.cpp 1 - - Generates random information rather than fixed information. This allows you + list. In this case the accessor for getting the words into the cache + generates random information rather than fixed information. This allows you to see how the cache range is kept for a local number of rows when running the example. + \snippet examples/tools/contiguouscache/randomlistmodel.cpp 1 + It is also worth considering pre-fetching items into the cache outside of the - applications paint routine. This can be done either with a separate thread - or using a QTimer to incrementally expand the range of the thread prior to + application's paint routine. This can be done either with a separate thread + or using a QTimer to incrementally expand the range of the cache prior to rows being requested out of the current cache range. */ diff --git a/src/corelib/tools/qcontiguouscache.cpp b/src/corelib/tools/qcontiguouscache.cpp index 1bcac96..95fa9e7 100644 --- a/src/corelib/tools/qcontiguouscache.cpp +++ b/src/corelib/tools/qcontiguouscache.cpp @@ -59,14 +59,14 @@ void QContiguousCacheData::dump() const \reentrant The QContiguousCache class provides an efficient way of caching items for - display in a user interface view. Unlike QCache though it adds a restriction - that elements within the cache are contiguous. This has the advantage that + display in a user interface view. Unlike QCache, it adds a restriction + that elements within the cache are contiguous. This has the advantage of matching how user interface views most commonly request data, as a set of rows localized around the current scrolled position. It also - allows the cache to use less overhead than QCache both in terms of - performance and memory. + allows the cache to consume less memory and processor cycles than QCache + for this use-case. - The simplest way of using an contiguous cache is to use the append() + The simplest way of using a contiguous cache is to use the append() and prepend(). \code @@ -82,18 +82,18 @@ MyRecord record(int row) const return cache.at(row); } \endcode - - If the cache is full then the item with the furthest index from where - the new item is appended or prepended is removed. + + If the cache is full then the item at the opposite end of the cache from where + the new item is appended or prepended will be removed. This usage can be further optimized by using the insert() function - in the case where the requested row is a long way from the currently cached - items. If there is a is a gap between where the new item is inserted and the currently + in the case where the requested row is a long way from the currently cached + items. If there is a gap between where the new item is inserted and the currently cached items then the existing cached items are first removed to retain the contiguous nature of the cache. Hence it is important to take some care then - when using insert() in order to avoid to unwanted clearing of the cache. + when using insert() in order to avoid unwanted clearing of the cache. - See the The \l{Contiguous Cache Example}{Contiguous Cache} example. + See the \l{Contiguous Cache Example}{Contiguous Cache} example. */ /*! \fn QContiguousCache::QContiguousCache(int capacity) @@ -116,6 +116,7 @@ MyRecord record(int row) const */ /*! \fn QContiguousCache::~QContiguousCache() + Destroys the cache. */ @@ -134,7 +135,6 @@ MyRecord record(int row) const \internal */ - /*! \fn QContiguousCache &QContiguousCache::operator=(const QContiguousCache &other) Assigns \a other to this cache and returns a reference to this cache. @@ -144,7 +144,7 @@ MyRecord record(int row) const Returns true if \a other is equal to this cache; otherwise returns false. - Two cache are considered equal if they contain the same values at the same + Two caches are considered equal if they contain the same values at the same indexes. This function requires the value type to implement the \c operator==(). \sa operator!=() @@ -155,17 +155,17 @@ MyRecord record(int row) const Returns true if \a other is not equal to this cache; otherwise returns false. - Two cache are considered equal if they contain the same values at the same + Two caches are considered equal if they contain the same values at the same indexes. This function requires the value type to implement the \c operator==(). \sa operator==() */ /*! \fn int QContiguousCache::capacity() const - + Returns the number of items the cache can store before it is full. When a cache contains a number of items equal to its capacity, adding new - items will cause items furthest from the added item to be removed. + items will cause items farthest from the added item to be removed. \sa setCapacity(), size() */ @@ -215,7 +215,7 @@ MyRecord record(int row) const Sets the capacity of the cache to the given \a size. A cache can hold a number of items equal to its capacity. When inserting, appending or prepending - items to the cache, if the cache is already full then the item furthest from + items to the cache, if the cache is already full then the item farthest from the added item will be removed. If the given \a size is smaller than the current count of items in the cache @@ -229,10 +229,10 @@ MyRecord record(int row) const Returns the item at index position \a i in the cache. \a i must be a valid index position in the cache (i.e, firstIndex() <= \a i <= lastIndex()). - The indexes in the cache refer to number of positions the item is from the + The indexes in the cache refer to the number of positions the item is from the first item appended into the cache. That is to say a cache with a capacity of 100, that has had 150 items appended will have a valid index range of - 50 to 149. This allows inserting an retrieving items into the cache based + 50 to 149. This allows inserting and retrieving items into the cache based on a theoretical infinite list \sa firstIndex(), lastIndex(), insert(), operator[]() @@ -283,10 +283,10 @@ MyRecord record(int row) const or a prepend(). If the given index \a i is not within the current range of the cache nor adjacent - to the bounds of the cache's index range the cache is first cleared before - inserting the item. At this point the cache will have a size of 1. It is worth - while then taking effort to insert items in an order that starts adjacent to the - current index range for the cache. + to the bounds of the cache's index range, the cache is first cleared before + inserting the item. At this point the cache will have a size of 1. It is + worthwhile taking effort to insert items in an order that starts adjacent + to the current index range for the cache. \sa prepend(), append(), isFull(), firstIndex(), lastIndex() */ @@ -299,6 +299,7 @@ MyRecord record(int row) const */ /*! \fn int QContiguousCache::firstIndex() const + Returns the first valid index in the cache. The index will be invalid if the cache is empty. However the following code is valid even when the cache is empty: @@ -350,7 +351,7 @@ MyRecord record(int row) const */ /*! \fn void QContiguousCache::removeFirst() - + Removes the first item from the cache. This function assumes that the cache isn't empty. @@ -358,7 +359,7 @@ MyRecord record(int row) const */ /*! \fn void QContiguousCache::removeLast() - + Removes the last item from the cache. This function assumes that the cache isn't empty. @@ -366,19 +367,21 @@ MyRecord record(int row) const */ /*! \fn T QContiguousCache::takeFirst() - - Removes the first item in the cache and returns it. - If you don't sue the return value, removeFirst() is more efficient. + Removes the first item in the cache and returns it. This function + assumes that the cache isn't empty. + + If you don't use the return value, removeFirst() is more efficient. \sa takeLast(), removeFirst() */ /*! \fn T QContiguousCache::takeLast() - - Removes the last item in the cache and returns it. - If you don't sue the return value, removeLast() is more efficient. + Removes the last item in the cache and returns it. This function + assumes that the cache isn't empty. + + If you don't use the return value, removeLast() is more efficient. \sa takeFirst(), removeLast() */ -- cgit v0.12 From aeea8fd5a940787600002dda39a10dff4d19d090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Mon, 11 May 2009 13:37:59 +0200 Subject: Made QFontEngineFT compile on 64-bit platforms with legacy headers. In older Freetype headers FT_LCD_FILTER_DEFAULT is apparently defined to be ((const FT_Byte*)(void*)(ft_ptrdiff_t)1), which leads to a compile error due to precision loss when casting to int. Task-number: 253186 Reviewed-by: Trond --- src/gui/text/qfontengine_ft.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp index 7a236fd..6f5ee1f 100644 --- a/src/gui/text/qfontengine_ft.cpp +++ b/src/gui/text/qfontengine_ft.cpp @@ -613,7 +613,7 @@ QFontEngineFT::QFontEngineFT(const QFontDef &fd) subpixelType = Subpixel_None; lcdFilterType = 0; #if defined(FT_LCD_FILTER_H) - lcdFilterType = (int) FT_LCD_FILTER_DEFAULT; + lcdFilterType = (int)((quintptr) FT_LCD_FILTER_DEFAULT); #endif defaultFormat = Format_None; canUploadGlyphsToServer = false; -- cgit v0.12 From e51c865ceb47dddfedb83ca4554ead21bd24ce7c Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Mon, 11 May 2009 14:19:17 +0200 Subject: Explaining details in QKeyEvent consruktor signature Explained the role of the key attribute. Task-number:246839 Rev-by: Richard Moe Gustavsen --- src/gui/kernel/qevent.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 8c7e47d..2aed287 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -675,12 +675,13 @@ QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease, or QEvent::ShortcutOverride. - If \a key is 0, the event is not a result of - a known key; for example, it may be the result of a compose - sequence or keyboard macro. The \a modifiers holds the keyboard - modifiers, and the given \a text is the Unicode text that the - key generated. If \a autorep is true, isAutoRepeat() will be - true. \a count is the number of keys involved in the event. + Int \a key is the code for the Qt::Key that the event loop should listen + for. If \a key is 0, the event is not a result of a known key; for + example, it may be the result of a compose sequence or keyboard macro. + The \a modifiers holds the keyboard modifiers, and the given \a text + is the Unicode text that the key generated. If \a autorep is true, + isAutoRepeat() will be true. \a count is the number of keys involved + in the event. */ QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text, bool autorep, ushort count) -- cgit v0.12 From 1d09e9cfd77d398788b6a31eb8c07ca2ac6fa9a8 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Mon, 11 May 2009 14:52:00 +0200 Subject: Set the instruction set when building on Debian's Linux/MIPS port We use MIPS2 instructions in the inline assembler, so we need to make sure that the assembler is informed of this. Task-number: 253275 Reviewed-by: thiago --- src/corelib/arch/qatomic_mips.h | 106 ++++++++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 20 deletions(-) diff --git a/src/corelib/arch/qatomic_mips.h b/src/corelib/arch/qatomic_mips.h index b263aab..ea9954b 100644 --- a/src/corelib/arch/qatomic_mips.h +++ b/src/corelib/arch/qatomic_mips.h @@ -103,16 +103,25 @@ Q_INLINE_TEMPLATE bool QBasicAtomicPointer::isFetchAndAddWaitFree() #if defined(Q_CC_GNU) && !defined(Q_OS_IRIX) +#if _MIPS_SIM == _ABIO32 +#define SET_MIPS2 ".set mips2\n\t" +#else +#define SET_MIPS2 +#endif + inline bool QBasicAtomicInt::ref() { register int originalValue; register int newValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" "ll %[originalValue], %[_q_value]\n" "addiu %[newValue], %[originalValue], %[one]\n" "sc %[newValue], %[_q_value]\n" "beqz %[newValue], 0b\n" "nop\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [_q_value] "+m" (_q_value), [newValue] "=&r" (newValue) @@ -125,12 +134,15 @@ inline bool QBasicAtomicInt::deref() { register int originalValue; register int newValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" "ll %[originalValue], %[_q_value]\n" "addiu %[newValue], %[originalValue], %[minusOne]\n" "sc %[newValue], %[_q_value]\n" "beqz %[newValue], 0b\n" "nop\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [_q_value] "+m" (_q_value), [newValue] "=&r" (newValue) @@ -143,7 +155,9 @@ inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue) { register int result; register int tempValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" "ll %[result], %[_q_value]\n" "xor %[result], %[result], %[expectedValue]\n" "bnez %[result], 0f\n" @@ -153,6 +167,7 @@ inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue) "beqz %[tempValue], 0b\n" "nop\n" "0:\n" + ".set pop\n" : [result] "=&r" (result), [tempValue] "=&r" (tempValue), [_q_value] "+m" (_q_value) @@ -166,7 +181,9 @@ inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue) { register int result; register int tempValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" "ll %[result], %[_q_value]\n" "xor %[result], %[result], %[expectedValue]\n" "bnez %[result], 0f\n" @@ -177,6 +194,7 @@ inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue) "nop\n" "sync\n" "0:\n" + ".set pop\n" : [result] "=&r" (result), [tempValue] "=&r" (tempValue), [_q_value] "+m" (_q_value) @@ -190,7 +208,9 @@ inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue) { register int result; register int tempValue; - asm volatile("sync\n" + asm volatile(".set push\n" + SET_MIPS2 + "sync\n" "0:\n" "ll %[result], %[_q_value]\n" "xor %[result], %[result], %[expectedValue]\n" @@ -201,6 +221,7 @@ inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue) "beqz %[tempValue], 0b\n" "nop\n" "0:\n" + ".set pop\n" : [result] "=&r" (result), [tempValue] "=&r" (tempValue), [_q_value] "+m" (_q_value) @@ -219,12 +240,15 @@ inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue) { register int originalValue; register int tempValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" "ll %[originalValue], %[_q_value]\n" "move %[tempValue], %[newValue]\n" "sc %[tempValue], %[_q_value]\n" "beqz %[tempValue], 0b\n" "nop\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [tempValue] "=&r" (tempValue), [_q_value] "+m" (_q_value) @@ -237,13 +261,16 @@ inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue) { register int originalValue; register int tempValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" "ll %[originalValue], %[_q_value]\n" "move %[tempValue], %[newValue]\n" "sc %[tempValue], %[_q_value]\n" "beqz %[tempValue], 0b\n" "nop\n" "sync\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [tempValue] "=&r" (tempValue), [_q_value] "+m" (_q_value) @@ -256,13 +283,16 @@ inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue) { register int originalValue; register int tempValue; - asm volatile("sync\n" + asm volatile(".set push\n" + SET_MIPS2 + "sync\n" "0:\n" "ll %[originalValue], %[_q_value]\n" "move %[tempValue], %[newValue]\n" "sc %[tempValue], %[_q_value]\n" "beqz %[tempValue], 0b\n" "nop\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [tempValue] "=&r" (tempValue), [_q_value] "+m" (_q_value) @@ -280,12 +310,15 @@ inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd) { register int originalValue; register int newValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" "ll %[originalValue], %[_q_value]\n" "addu %[newValue], %[originalValue], %[valueToAdd]\n" "sc %[newValue], %[_q_value]\n" "beqz %[newValue], 0b\n" "nop\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [_q_value] "+m" (_q_value), [newValue] "=&r" (newValue) @@ -298,13 +331,16 @@ inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd) { register int originalValue; register int newValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" "ll %[originalValue], %[_q_value]\n" "addu %[newValue], %[originalValue], %[valueToAdd]\n" "sc %[newValue], %[_q_value]\n" "beqz %[newValue], 0b\n" "nop\n" "sync\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [_q_value] "+m" (_q_value), [newValue] "=&r" (newValue) @@ -317,13 +353,16 @@ inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd) { register int originalValue; register int newValue; - asm volatile("sync\n" + asm volatile(".set push\n" + SET_MIPS2 + "sync\n" "0:\n" "ll %[originalValue], %[_q_value]\n" "addu %[newValue], %[originalValue], %[valueToAdd]\n" "sc %[newValue], %[_q_value]\n" "beqz %[newValue], 0b\n" "nop\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [_q_value] "+m" (_q_value), [newValue] "=&r" (newValue) @@ -350,7 +389,9 @@ Q_INLINE_TEMPLATE bool QBasicAtomicPointer::testAndSetRelaxed(T *expectedValu { register T *result; register T *tempValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" LLP" %[result], %[_q_value]\n" "xor %[result], %[result], %[expectedValue]\n" "bnez %[result], 0f\n" @@ -360,6 +401,7 @@ Q_INLINE_TEMPLATE bool QBasicAtomicPointer::testAndSetRelaxed(T *expectedValu "beqz %[tempValue], 0b\n" "nop\n" "0:\n" + ".set pop\n" : [result] "=&r" (result), [tempValue] "=&r" (tempValue), [_q_value] "+m" (_q_value) @@ -374,7 +416,9 @@ Q_INLINE_TEMPLATE bool QBasicAtomicPointer::testAndSetAcquire(T *expectedValu { register T *result; register T *tempValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" LLP" %[result], %[_q_value]\n" "xor %[result], %[result], %[expectedValue]\n" "bnez %[result], 0f\n" @@ -385,6 +429,7 @@ Q_INLINE_TEMPLATE bool QBasicAtomicPointer::testAndSetAcquire(T *expectedValu "nop\n" "sync\n" "0:\n" + ".set pop\n" : [result] "=&r" (result), [tempValue] "=&r" (tempValue), [_q_value] "+m" (_q_value) @@ -399,7 +444,9 @@ Q_INLINE_TEMPLATE bool QBasicAtomicPointer::testAndSetRelease(T *expectedValu { register T *result; register T *tempValue; - asm volatile("sync\n" + asm volatile(".set push\n" + SET_MIPS2 + "sync\n" "0:\n" LLP" %[result], %[_q_value]\n" "xor %[result], %[result], %[expectedValue]\n" @@ -410,6 +457,7 @@ Q_INLINE_TEMPLATE bool QBasicAtomicPointer::testAndSetRelease(T *expectedValu "beqz %[tempValue], 0b\n" "nop\n" "0:\n" + ".set pop\n" : [result] "=&r" (result), [tempValue] "=&r" (tempValue), [_q_value] "+m" (_q_value) @@ -430,12 +478,15 @@ Q_INLINE_TEMPLATE T *QBasicAtomicPointer::fetchAndStoreRelaxed(T *newValue) { register T *originalValue; register T *tempValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" LLP" %[originalValue], %[_q_value]\n" "move %[tempValue], %[newValue]\n" SCP" %[tempValue], %[_q_value]\n" "beqz %[tempValue], 0b\n" "nop\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [tempValue] "=&r" (tempValue), [_q_value] "+m" (_q_value) @@ -449,13 +500,16 @@ Q_INLINE_TEMPLATE T *QBasicAtomicPointer::fetchAndStoreAcquire(T *newValue) { register T *originalValue; register T *tempValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" LLP" %[originalValue], %[_q_value]\n" "move %[tempValue], %[newValue]\n" SCP" %[tempValue], %[_q_value]\n" "beqz %[tempValue], 0b\n" "nop\n" "sync\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [tempValue] "=&r" (tempValue), [_q_value] "+m" (_q_value) @@ -469,13 +523,16 @@ Q_INLINE_TEMPLATE T *QBasicAtomicPointer::fetchAndStoreRelease(T *newValue) { register T *originalValue; register T *tempValue; - asm volatile("sync\n" + asm volatile(".set push\n" + SET_MIPS2 + "sync\n" "0:\n" LLP" %[originalValue], %[_q_value]\n" "move %[tempValue], %[newValue]\n" SCP" %[tempValue], %[_q_value]\n" "beqz %[tempValue], 0b\n" "nop\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [tempValue] "=&r" (tempValue), [_q_value] "+m" (_q_value) @@ -495,12 +552,15 @@ Q_INLINE_TEMPLATE T *QBasicAtomicPointer::fetchAndAddRelaxed(qptrdiff valueTo { register T *originalValue; register T *newValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" LLP" %[originalValue], %[_q_value]\n" "addu %[newValue], %[originalValue], %[valueToAdd]\n" SCP" %[newValue], %[_q_value]\n" "beqz %[newValue], 0b\n" "nop\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [_q_value] "+m" (_q_value), [newValue] "=&r" (newValue) @@ -514,13 +574,16 @@ Q_INLINE_TEMPLATE T *QBasicAtomicPointer::fetchAndAddAcquire(qptrdiff valueTo { register T *originalValue; register T *newValue; - asm volatile("0:\n" + asm volatile(".set push\n" + SET_MIPS2 + "0:\n" LLP" %[originalValue], %[_q_value]\n" "addu %[newValue], %[originalValue], %[valueToAdd]\n" SCP" %[newValue], %[_q_value]\n" "beqz %[newValue], 0b\n" "nop\n" "sync\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [_q_value] "+m" (_q_value), [newValue] "=&r" (newValue) @@ -534,13 +597,16 @@ Q_INLINE_TEMPLATE T *QBasicAtomicPointer::fetchAndAddRelease(qptrdiff valueTo { register T *originalValue; register T *newValue; - asm volatile("sync\n" + asm volatile(".set push\n" + SET_MIPS2 + "sync\n" "0:\n" LLP" %[originalValue], %[_q_value]\n" "addu %[newValue], %[originalValue], %[valueToAdd]\n" SCP" %[newValue], %[_q_value]\n" "beqz %[newValue], 0b\n" "nop\n" + ".set pop\n" : [originalValue] "=&r" (originalValue), [_q_value] "+m" (_q_value), [newValue] "=&r" (newValue) -- cgit v0.12 From 27d2f348792be0e08e204896dad8f3d80f51d80b Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Mon, 11 May 2009 15:35:49 +0200 Subject: qdoc: Fixed qdoc errors, or tried to. --- src/corelib/tools/qhash.cpp | 219 +++++++++++++++++++++----------------------- 1 file changed, 102 insertions(+), 117 deletions(-) diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 21d98b5..b2512e1 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -379,6 +379,107 @@ void QHashData::checkSanity() #endif /*! + \fn uint qHash(const QPair &key) + \relates QHash + \since 4.3 + + Returns the hash value for the \a key. + + Types \c T1 and \c T2 must be supported by qHash(). +*/ + +/*! \fn uint qHash(char key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(uchar key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(signed char key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(ushort key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(short key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(uint key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(int key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(ulong key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(long key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(quint64 key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(qint64 key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(QChar key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(const QByteArray &key) + \fn uint qHash(const QBitArray &key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(const QString &key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \fn uint qHash(const T *key) + \relates QHash + + Returns the hash value for the \a key. +*/ + +/*! \class QHash \brief The QHash class is a template class that provides a hash-table-based dictionary. @@ -401,7 +502,7 @@ void QHashData::checkSanity() key. With QHash, the items are arbitrarily ordered. \i The key type of a QMap must provide operator<(). The key type of a QHash must provide operator==() and a global - \l{qHash()}{qHash}(Key) function. + \l{qHash()} {hash} function. \endlist Here's an example QHash with QString keys and \c int values: @@ -732,7 +833,6 @@ void QHashData::checkSanity() */ /*! \fn const T QHash::value(const Key &key, const T &defaultValue) const - \overload If the hash contains no item with the given \a key, the function returns @@ -1490,121 +1590,6 @@ void QHashData::checkSanity() \sa operator+=(), operator-() */ -/*! \fn uint qHash(char key) - \relates QHash - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(uchar key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(signed char key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(ushort key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(short key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(uint key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(int key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(ulong key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(long key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(quint64 key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(qint64 key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(QChar key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(const QByteArray &key) - \fn uint qHash(const QBitArray &key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(const QString &key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(const T *key) - \relates QHash - \overload - - Returns the hash value for the \a key. -*/ - -/*! - \fn uint qHash(const QPair &key) - \relates QHash - \since 4.3 - - Returns the hash value for the \a key. - - Types \c T1 and \c T2 must be supported by qHash(). -*/ - /*! \fn QDataStream &operator<<(QDataStream &out, const QHash& hash) \relates QHash -- cgit v0.12 From 0ce24108aa20a38e53a7f307231a6752f89ef65a Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Mon, 11 May 2009 15:41:26 +0200 Subject: Correcting bug in custom Database Driver code snipptet Adding const to call. Changing QSqlRecord record() { return QSqlRecord(); } to QSqlRecord record() const { return QSqlRecord(); } This is needed since record() is a virtual function. Task-number:204557 Rev-by: Geir Vattekar --- doc/src/snippets/sqldatabase/sqldatabase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/snippets/sqldatabase/sqldatabase.cpp b/doc/src/snippets/sqldatabase/sqldatabase.cpp index ae176ac..06afa0c 100644 --- a/doc/src/snippets/sqldatabase/sqldatabase.cpp +++ b/doc/src/snippets/sqldatabase/sqldatabase.cpp @@ -524,7 +524,7 @@ protected: bool fetchLast() { return false; } int size() { return 0; } int numRowsAffected() { return 0; } - QSqlRecord record() { return QSqlRecord(); } + QSqlRecord record() const { return QSqlRecord(); } }; //! [47] -- cgit v0.12 From fecfc325bbd4decc0d61e10dc6536575c305f812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Mon, 11 May 2009 13:32:46 +0200 Subject: QFSFileEngine: Fix access to uninitialized memory Reviewed-by: Peter Hartmann --- src/corelib/io/qfsfileengine_unix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 0d88b06..18b92e2 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -780,7 +780,7 @@ QString QFSFileEngine::fileName(FileName file) const #endif if (len > 0) { QString ret; - if (S_ISDIR(d->st.st_mode) && s[0] != '/') { + if (d->doStat() && S_ISDIR(d->st.st_mode) && s[0] != '/') { QDir parent(d->filePath); parent.cdUp(); ret = parent.path(); -- cgit v0.12 From 6200d413487517eadb8f4696d92a38fc73ba737c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Mon, 11 May 2009 16:40:33 +0200 Subject: Improved caching of QSvgIconEngine::actualSize() calls. If an application calls QIcon::actualSize() for SVG based icons, before the icon is drawn for the first time, the actualSize() call will result in the SVG file being loaded and parsed for each call. Instead of doing that, just render a pixmap of the queried size and then the resulting actualSize() calls will used the size of the cached pixmap. Task-number: related to 251106 Reviewed-by: Kim --- src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp b/src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp index c7249d3..3273513 100644 --- a/src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp +++ b/src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp @@ -122,16 +122,10 @@ QSize QSvgIconEngine::actualSize(const QSize &size, QIcon::Mode mode, return size; } - QSvgRenderer renderer; - d->loadDataForModeAndState(&renderer, mode, state); - if (renderer.isValid()) { - QSize defaultSize = renderer.defaultSize(); - if (!defaultSize.isNull()) - defaultSize.scale(size, Qt::KeepAspectRatio); - return defaultSize; - } else { + QPixmap pm = pixmap(size, mode, state); + if (pm.isNull()) return QSize(); - } + return pm.size(); } void QSvgIconEnginePrivate::loadDataForModeAndState(QSvgRenderer *renderer, QIcon::Mode mode, QIcon::State state) -- cgit v0.12 From 5f135bd9ba053c0ef41df9fe5450c78460ad89d3 Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Mon, 11 May 2009 10:16:44 -0700 Subject: Fix a type in warning QDirecttFBPixmapData => QDirectFBPixmapData Reviewed-by: TrustMe --- src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp index 7297a99..c9b676a 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp @@ -271,7 +271,7 @@ void QDirectFBPixmapData::fill(const QColor &color) forceRaster = false; setSerialNumber(++global_ser_no); if (!dfbSurface) { - qWarning("QDirecttFBPixmapData::fill()"); + qWarning("QDirectFBPixmapData::fill()"); invalidate(); return; } -- cgit v0.12 From 15e5a770635ca891bb3e0297fab130f7c1538655 Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Mon, 11 May 2009 14:01:54 -0700 Subject: Remove unused variable Reviewed-by: TrustMe --- src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp index 91a60e7..989a37a 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp @@ -275,7 +275,6 @@ private: int lastLockedHeight; IDirectFB *fb; - DFBSurfaceDescription fbDescription; int fbWidth; int fbHeight; -- cgit v0.12 From e16c235ecdb0b13ece15722b69e180a53cff431a Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Mon, 11 May 2009 14:07:39 -0700 Subject: initialize all DFBSurfaceDescriptions to 0 Since this is C there are no constructors. Reviewed-by: Donald --- src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index f571d1b..65fddbf 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -205,6 +205,7 @@ IDirectFBSurface *QDirectFBScreen::createDFBSurface(const QSize &size, SurfaceCreationOptions options) { DFBSurfaceDescription desc; + memset(&desc, 0, sizeof(DFBSurfaceDescription)); desc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH|DSDESC_HEIGHT); if (!QDirectFBScreen::initSurfaceDescriptionPixelFormat(&desc, format)) return 0; @@ -213,7 +214,6 @@ IDirectFBSurface *QDirectFBScreen::createDFBSurface(const QSize &size, return createDFBSurface(desc, options); } - IDirectFBSurface *QDirectFBScreen::createDFBSurface(DFBSurfaceDescription desc, SurfaceCreationOptions options) { DFBResult result = DFB_OK; @@ -247,6 +247,7 @@ IDirectFBSurface *QDirectFBScreen::createDFBSurface(DFBSurfaceDescription desc, } desc.caps = DFBSurfaceCapabilities(desc.caps & ~DSCAPS_VIDEOONLY); } + if (d_ptr->directFBFlags & SystemOnly) desc.caps = DFBSurfaceCapabilities(desc.caps | DSCAPS_SYSTEMONLY); @@ -445,6 +446,7 @@ QImage::Format QDirectFBScreen::getImageFormat(IDirectFBSurface *surface) DFBSurfaceDescription QDirectFBScreen::getSurfaceDescription(const QImage &image) { DFBSurfaceDescription description; + memset(&description, 0, sizeof(DFBSurfaceDescription)); const DFBSurfacePixelFormat format = getSurfacePixelFormat(image.format()); @@ -479,6 +481,7 @@ DFBSurfaceDescription QDirectFBScreen::getSurfaceDescription(const uint *buffer, int length) { DFBSurfaceDescription description; + memset(&description, 0, sizeof(DFBSurfaceDescription)); description.flags = DFBSurfaceDescriptionFlags(DSDESC_CAPS | DSDESC_WIDTH @@ -917,6 +920,8 @@ bool QDirectFBScreen::connect(const QString &displaySpec) d_ptr->dfb->SetCooperativeLevel(d_ptr->dfb, DFSCL_FULLSCREEN); DFBSurfaceDescription description; + memset(&description, 0, sizeof(DFBSurfaceDescription)); + description.flags = DFBSurfaceDescriptionFlags(DSDESC_CAPS); if (::setIntOption(displayArgs, QLatin1String("width"), &description.width)) description.flags = DFBSurfaceDescriptionFlags(description.flags | DSDESC_WIDTH); -- cgit v0.12 From ee533dd0818c3bf7c940cd2d543adb1c6807dd1c Mon Sep 17 00:00:00 2001 From: Ian Walters Date: Tue, 12 May 2009 10:09:23 +1000 Subject: Various fixes resulting from QA code review. Some documentation fixes. More clear handling of what is and isn't a valid indexes. Added functions for the 'really long lived circular buffer use case' Improved unit tests. --- doc/src/examples/contiguouscache.qdoc | 8 +- src/corelib/io/qdebug.h | 2 +- src/corelib/tools/qcontiguouscache.cpp | 73 ++++++--- src/corelib/tools/qcontiguouscache.h | 32 ++-- tests/auto/auto.pro | 2 +- .../auto/qcontiguouscache/tst_qcontiguouscache.cpp | 169 +++++++++++++++++---- 6 files changed, 217 insertions(+), 69 deletions(-) diff --git a/doc/src/examples/contiguouscache.qdoc b/doc/src/examples/contiguouscache.qdoc index 71e7740..fbfde3f 100644 --- a/doc/src/examples/contiguouscache.qdoc +++ b/doc/src/examples/contiguouscache.qdoc @@ -61,10 +61,10 @@ simply have the following code instead. \code - while (row > m_words.lastIndex()) - m_words.append(fetchWord(m_words.lastIndex()+1); - while (row < m_words.firstIndex()) - m_words.prepend(fetchWord(m_words.firstIndex()-1); + while (row > m_rows.lastIndex()) + m_rows.append(fetchWord(m_rows.lastIndex()+1); + while (row < m_rows.firstIndex()) + m_rows.prepend(fetchWord(m_rows.firstIndex()-1); \endcode However a list will often jump rows if the scroll bar is used directly, resulting in diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 6c05756..9b0fbe5 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -235,7 +235,7 @@ inline QDebug operator<<(QDebug debug, const QSet &set) #if defined(FORCE_UREF) template -inline QDebug &operator<<(QDebug debug, const QContiguousCache &contiguousCache) +inline QDebug &operator<<(QDebug debug, const QContiguousCache &cache) #else template inline QDebug operator<<(QDebug debug, const QContiguousCache &cache) diff --git a/src/corelib/tools/qcontiguouscache.cpp b/src/corelib/tools/qcontiguouscache.cpp index 95fa9e7..6671982 100644 --- a/src/corelib/tools/qcontiguouscache.cpp +++ b/src/corelib/tools/qcontiguouscache.cpp @@ -62,9 +62,10 @@ void QContiguousCacheData::dump() const display in a user interface view. Unlike QCache, it adds a restriction that elements within the cache are contiguous. This has the advantage of matching how user interface views most commonly request data, as - a set of rows localized around the current scrolled position. It also - allows the cache to consume less memory and processor cycles than QCache - for this use-case. + a set of rows localized around the current scrolled position. This + restriction allows the cache to consume less memory and processor + cycles than QCache. The QContiguousCache class also can provide + an upper bound on memory usage via setCapacity(). The simplest way of using a contiguous cache is to use the append() and prepend(). @@ -83,8 +84,8 @@ MyRecord record(int row) const } \endcode - If the cache is full then the item at the opposite end of the cache from where - the new item is appended or prepended will be removed. + If the cache is full then the item at the opposite end of the cache from + where the new item is appended or prepended will be removed. This usage can be further optimized by using the insert() function in the case where the requested row is a long way from the currently cached @@ -93,6 +94,19 @@ MyRecord record(int row) const the contiguous nature of the cache. Hence it is important to take some care then when using insert() in order to avoid unwanted clearing of the cache. + The range of valid indexes for the QContiguousCache class are from + 0 to INT_MAX. Calling prepend() such that the first index would become less + than 0 or append() such that the last index would become greater + than INT_MAX can result in the indexes of the cache being invalid. + When the cache indexes are invalid it is important to call + normalizeIndexes() before calling any of containsIndex(), firstIndex(), + lastIndex(), at() or the [] operator. Calling these + functions when the cache has invalid indexes will result in undefined + behavior. The indexes can be checked by using areIndexesValid() + + In most cases the indexes will not exceed 0 to INT_MAX, and + normalizeIndexes() will not need to be be used. + See the \l{Contiguous Cache Example}{Contiguous Cache} example. */ @@ -288,6 +302,10 @@ MyRecord record(int row) const worthwhile taking effort to insert items in an order that starts adjacent to the current index range for the cache. + The range of valid indexes for the QContiguousCache class are from + 0 to INT_MAX. Inserting outside of this range has undefined behavior. + + \sa prepend(), append(), isFull(), firstIndex(), lastIndex() */ @@ -301,24 +319,14 @@ MyRecord record(int row) const /*! \fn int QContiguousCache::firstIndex() const Returns the first valid index in the cache. The index will be invalid if the - cache is empty. However the following code is valid even when the cache is empty: - - \code - for (int i = cache.firstIndex(); i <= cache.lastIndex(); ++i) - qDebug() << "Item" << i << "of the cache is" << cache.at(i); - \endcode + cache is empty. \sa capacity(), size(), lastIndex() */ /*! \fn int QContiguousCache::lastIndex() const - Returns the last valid index in the cache. If the cache is empty will return -1. - - \code - for (int i = cache.firstIndex(); i <= cache.lastIndex(); ++i) - qDebug() << "Item" << i << "of the cache is" << cache.at(i); - \endcode + Returns the last valid index in the cache. The index will be invalid if the cache is empty. \sa capacity(), size(), firstIndex() */ @@ -386,6 +394,37 @@ MyRecord record(int row) const \sa takeFirst(), removeLast() */ +/*! \fn void QContiguousCache::normalizeIndexes() + + Moves the first index and last index of the cache + such that they point to valid indexes. The function does not modify + the contents of the cache or the ordering of elements within the cache. + + It is provided so that index overflows can be corrected when using the + cache as a circular buffer. + + \code + QContiguousCache cache(10); + cache.insert(INT_MAX, 1); // cache contains one value and has valid indexes, INT_MAX to INT_MAX + cache.append(2); // cache contains two values but does not have valid indexes. + cache.normalizeIndexes(); // cache has two values, 1 and 2. New first index will be in the range of 0 to capacity(). + \endcode + + \sa areIndexesValid(), append(), prepend() +*/ + +/*! \fn bool QContiguousCache::areIndexesValid() const + + Returns whether the indexes for items stored in the cache are valid. + Indexes can become invalid if items are appended after the index position + INT_MAX or prepended before the index position 0. This is only expected + to occur in very long lived circular buffer style usage of the + contiguous cache. Indexes can be made valid again by calling + normalizeIndexs(). + + \sa normalizeIndexes(), append(), prepend() +*/ + /*! \fn void QContiguousCache::dump() const \internal diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h index 5250a79..5cd1582 100644 --- a/src/corelib/tools/qcontiguouscache.h +++ b/src/corelib/tools/qcontiguouscache.h @@ -43,6 +43,7 @@ #define QCONTIGUOUSCACHE_H #include +#include QT_BEGIN_HEADER @@ -50,7 +51,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Core) -struct QContiguousCacheData +struct Q_CORE_EXPORT QContiguousCacheData { QBasicAtomicInt ref; int alloc; @@ -75,8 +76,6 @@ struct QContiguousCacheTypedData T array[1]; }; -class QContiguousCacheDevice; - template class QContiguousCache { typedef QContiguousCacheTypedData Data; @@ -128,13 +127,17 @@ public: void removeLast(); T takeLast(); + inline bool areIndexesValid() const + { return d->offset >= 0 && d->offset < INT_MAX - d->count && (d->offset % d->alloc) == d->start; } + + inline void normalizeIndexes() { d->offset = d->start; } // debug void dump() const { p->dump(); } private: void detach_helper(); - QContiguousCacheData *malloc(int alloc); - void free(Data *d); + QContiguousCacheData *malloc(int aalloc); + void free(Data *x); int sizeOfTypedData() { // this is more or less the same as sizeof(Data), except that it doesn't // count the padding at the end @@ -189,10 +192,6 @@ void QContiguousCache::setCapacity(int asize) x.d->count = qMin(d->count, asize); x.d->offset = d->offset + d->count - x.d->count; x.d->start = x.d->offset % x.d->alloc; - /* deep copy - - slow way now, get unit test working, then - improve performance if need be. (e.g. memcpy) - */ T *dest = x.d->array + (x.d->start + x.d->count-1) % x.d->alloc; T *src = d->array + (d->start + d->count-1) % d->alloc; int count = x.d->count; @@ -249,11 +248,11 @@ inline QContiguousCacheData *QContiguousCache::malloc(int aalloc) } template -QContiguousCache::QContiguousCache(int asize) +QContiguousCache::QContiguousCache(int capacity) { - p = malloc(asize); + p = malloc(capacity); d->ref = 1; - d->alloc = asize; + d->alloc = capacity; d->count = d->start = d->offset = 0; d->sharable = true; } @@ -302,7 +301,6 @@ void QContiguousCache::free(Data *x) } qFree(x); } - template void QContiguousCache::append(const T &value) { @@ -349,6 +347,7 @@ void QContiguousCache::prepend(const T &value) template void QContiguousCache::insert(int pos, const T &value) { + Q_ASSERT_X(pos >= 0 && pos < INT_MAX, "QContiguousCache::insert", "index out of range"); detach(); if (containsIndex(pos)) { if(QTypeInfo::isComplex) @@ -362,8 +361,8 @@ void QContiguousCache::insert(int pos, const T &value) else { // we don't leave gaps. clear(); - d->offset = d->start = pos; - d->start %= d->alloc; + d->offset = pos; + d->start = pos % d->alloc; d->count = 1; if (QTypeInfo::isComplex) new (d->array + d->start) T(value); @@ -378,9 +377,8 @@ inline const T &QContiguousCache::at(int pos) const template inline const T &QContiguousCache::operator[](int pos) const { Q_ASSERT_X(pos >= d->offset && pos - d->offset < d->count, "QContiguousCache::at", "index out of range"); return d->array[pos % d->alloc]; } -template -// can use the non-inline one to modify the index range. +template inline T &QContiguousCache::operator[](int pos) { detach(); diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index cfd9525..1f972bf 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -209,7 +209,7 @@ SUBDIRS += bic \ qnumeric \ qobject \ qobjectrace \ - qoffsetvector \ + qcontiguouscache \ qpaintengine \ qpainter \ qpainterpath \ diff --git a/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp b/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp index 91f6a9c..6d59390 100644 --- a/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp +++ b/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp @@ -41,8 +41,6 @@ #include #include -#include -#include #include #include @@ -57,8 +55,13 @@ public: virtual ~tst_QContiguousCache() {} private slots: void empty(); - void forwardBuffer(); - void scrollingList(); + void append_data(); + void append(); + + void prepend_data(); + void prepend(); + + void asScrollingList(); void complexType(); @@ -79,12 +82,14 @@ void tst_QContiguousCache::empty() QCOMPARE(c.count(), 0); QVERIFY(c.isEmpty()); c.append(1); + QCOMPARE(c.count(), 1); QVERIFY(!c.isEmpty()); c.clear(); QCOMPARE(c.capacity(), 10); QCOMPARE(c.count(), 0); QVERIFY(c.isEmpty()); c.prepend(1); + QCOMPARE(c.count(), 1); QVERIFY(!c.isEmpty()); c.clear(); QCOMPARE(c.count(), 0); @@ -92,28 +97,111 @@ void tst_QContiguousCache::empty() QCOMPARE(c.capacity(), 10); } -void tst_QContiguousCache::forwardBuffer() +void tst_QContiguousCache::append_data() { - int i; - QContiguousCache c(10); - for(i = 1; i < 30; ++i) { + QTest::addColumn("start"); + QTest::addColumn("count"); + QTest::addColumn("cacheSize"); + QTest::addColumn("invalidIndexes"); + + QTest::newRow("0+30[10]") << 0 << 30 << 10 << false; + QTest::newRow("300+30[10]") << 300 << 30 << 10 << false; + QTest::newRow("MAX-10+30[10]") << INT_MAX-10 << 30 << 10 << true; +} + +void tst_QContiguousCache::append() +{ + QFETCH(int, start); + QFETCH(int, count); + QFETCH(int, cacheSize); + QFETCH(bool, invalidIndexes); + + int i, j; + QContiguousCache c(cacheSize); + + i = 1; + QCOMPARE(c.available(), cacheSize); + if (start == 0) + c.append(i++); + else + c.insert(start, i++); + while (i < count) { c.append(i); - QCOMPARE(c.first(), qMax(1, i-9)); + QCOMPARE(c.available(), qMax(0, cacheSize - i)); + QCOMPARE(c.first(), qMax(1, i-cacheSize+1)); QCOMPARE(c.last(), i); - QCOMPARE(c.count(), qMin(i, 10)); + QCOMPARE(c.count(), qMin(i, cacheSize)); + QCOMPARE(c.isFull(), i >= cacheSize); + i++; } - c.clear(); + QCOMPARE(c.areIndexesValid(), !invalidIndexes); + if (invalidIndexes) + c.normalizeIndexes(); + QVERIFY(c.areIndexesValid()); + + // test taking from end until empty. + for (j = 0; j < cacheSize; j++, i--) { + QCOMPARE(c.takeLast(), i-1); + QCOMPARE(c.count(), cacheSize-j-1); + QCOMPARE(c.available(), j+1); + QVERIFY(!c.isFull()); + QCOMPARE(c.isEmpty(), j==cacheSize-1); + } + +} + +void tst_QContiguousCache::prepend_data() +{ + QTest::addColumn("start"); + QTest::addColumn("count"); + QTest::addColumn("cacheSize"); + QTest::addColumn("invalidIndexes"); + + QTest::newRow("30-30[10]") << 30 << 30 << 10 << false; + QTest::newRow("300-30[10]") << 300 << 30 << 10 << false; + QTest::newRow("10-30[10]") << 10 << 30 << 10 << true; +} - for(i = 1; i < 30; ++i) { +void tst_QContiguousCache::prepend() +{ + QFETCH(int, start); + QFETCH(int, count); + QFETCH(int, cacheSize); + QFETCH(bool, invalidIndexes); + + int i, j; + QContiguousCache c(cacheSize); + + i = 1; + QCOMPARE(c.available(), cacheSize); + c.insert(start, i++); + while(i < count) { c.prepend(i); - QCOMPARE(c.last(), qMax(1, i-9)); + QCOMPARE(c.available(), qMax(0, cacheSize - i)); + QCOMPARE(c.last(), qMax(1, i-cacheSize+1)); QCOMPARE(c.first(), i); - QCOMPARE(c.count(), qMin(i, 10)); + QCOMPARE(c.count(), qMin(i, cacheSize)); + QCOMPARE(c.isFull(), i >= cacheSize); + i++; + } + + QCOMPARE(c.areIndexesValid(), !invalidIndexes); + if (invalidIndexes) + c.normalizeIndexes(); + QVERIFY(c.areIndexesValid()); + + // test taking from start until empty. + for (j = 0; j < cacheSize; j++, i--) { + QCOMPARE(c.takeFirst(), i-1); + QCOMPARE(c.count(), cacheSize-j-1); + QCOMPARE(c.available(), j+1); + QVERIFY(!c.isFull()); + QCOMPARE(c.isEmpty(), j==cacheSize-1); } } -void tst_QContiguousCache::scrollingList() +void tst_QContiguousCache::asScrollingList() { int i; QContiguousCache c(10); @@ -123,55 +211,78 @@ void tst_QContiguousCache::scrollingList() // complex data types. QBENCHMARK { // simulate scrolling in a list of items; - for(i = 0; i < 10; ++i) + for(i = 0; i < 10; ++i) { + QCOMPARE(c.available(), 10-i); c.append(i); + } QCOMPARE(c.firstIndex(), 0); QCOMPARE(c.lastIndex(), 9); - QVERIFY(c.containsIndex(0)); - QVERIFY(c.containsIndex(9)); + QCOMPARE(c.first(), 0); + QCOMPARE(c.last(), 9); + QVERIFY(!c.containsIndex(-1)); QVERIFY(!c.containsIndex(10)); + QCOMPARE(c.available(), 0); - for (i = 0; i < 10; ++i) + for (i = 0; i < 10; ++i) { + QVERIFY(c.containsIndex(i)); QCOMPARE(c.at(i), i); + QCOMPARE(c[i], i); + QCOMPARE(((const QContiguousCache)c)[i], i); + } for (i = 10; i < 30; ++i) c.append(i); QCOMPARE(c.firstIndex(), 20); QCOMPARE(c.lastIndex(), 29); - QVERIFY(c.containsIndex(20)); - QVERIFY(c.containsIndex(29)); + QCOMPARE(c.first(), 20); + QCOMPARE(c.last(), 29); + QVERIFY(!c.containsIndex(19)); QVERIFY(!c.containsIndex(30)); + QCOMPARE(c.available(), 0); - for (i = 20; i < 30; ++i) + for (i = 20; i < 30; ++i) { + QVERIFY(c.containsIndex(i)); QCOMPARE(c.at(i), i); + QCOMPARE(c[i], i); + QCOMPARE(((const QContiguousCache )c)[i], i); + } for (i = 19; i >= 10; --i) c.prepend(i); QCOMPARE(c.firstIndex(), 10); QCOMPARE(c.lastIndex(), 19); - QVERIFY(c.containsIndex(10)); - QVERIFY(c.containsIndex(19)); + QCOMPARE(c.first(), 10); + QCOMPARE(c.last(), 19); + QVERIFY(!c.containsIndex(9)); QVERIFY(!c.containsIndex(20)); + QCOMPARE(c.available(), 0); - for (i = 10; i < 20; ++i) + for (i = 10; i < 20; ++i) { + QVERIFY(c.containsIndex(i)); QCOMPARE(c.at(i), i); + QCOMPARE(c[i], i); + QCOMPARE(((const QContiguousCache )c)[i], i); + } for (i = 200; i < 220; ++i) c.insert(i, i); QCOMPARE(c.firstIndex(), 210); QCOMPARE(c.lastIndex(), 219); - QVERIFY(c.containsIndex(210)); - QVERIFY(c.containsIndex(219)); - QVERIFY(!c.containsIndex(300)); + QCOMPARE(c.first(), 210); + QCOMPARE(c.last(), 219); QVERIFY(!c.containsIndex(209)); + QVERIFY(!c.containsIndex(300)); + QCOMPARE(c.available(), 0); - for (i = 220; i < 220; ++i) { + for (i = 210; i < 220; ++i) { QVERIFY(c.containsIndex(i)); QCOMPARE(c.at(i), i); + QCOMPARE(c[i], i); + QCOMPARE(((const QContiguousCache )c)[i], i); } c.clear(); // needed to reset benchmark } -- cgit v0.12 From 7f0ffec90467c12d41566bb20fc02e09cfe3afa1 Mon Sep 17 00:00:00 2001 From: kh Date: Tue, 12 May 2009 09:09:33 +0200 Subject: Version update. --- tools/assistant/tools/assistant/assistant.qch | Bin 368640 -> 368640 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/tools/assistant/tools/assistant/assistant.qch b/tools/assistant/tools/assistant/assistant.qch index 64763f7..99687ed 100644 Binary files a/tools/assistant/tools/assistant/assistant.qch and b/tools/assistant/tools/assistant/assistant.qch differ -- cgit v0.12 From 8d94fcce0a2ca382eac8357dae05ad387551e364 Mon Sep 17 00:00:00 2001 From: jasplin Date: Tue, 12 May 2009 09:47:29 +0200 Subject: Fixed bug with Qt::WidgetWithChildren shortcut context in QGraphicsWidget. For a QGraphicsWidget w, a shortcut with Qt::WidgetWithChildren context would trigger even if w did not have focus (provided no other widgets in the view had focus). Reviewed-by: andreas Task-number: 250119 --- src/gui/kernel/qshortcutmap.cpp | 1 + tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 85 ++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp index ed9654b..86894b4 100644 --- a/src/gui/kernel/qshortcutmap.cpp +++ b/src/gui/kernel/qshortcutmap.cpp @@ -753,6 +753,7 @@ bool QShortcutMap::correctGraphicsWidgetContext(Qt::ShortcutContext context, QGr tw = tw->parentWidget(); return tw == w; } + return false; } // Below is Qt::WindowShortcut context diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index f25a079..b85abd3 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include "../../shared/util.h" @@ -150,6 +151,7 @@ private slots: // Task fixes void task236127_bspTreeIndexFails(); void task243004_setStyleCrash(); + void task250119_shortcutContext(); }; @@ -1827,6 +1829,89 @@ void tst_QGraphicsWidget::task243004_setStyleCrash() delete item2; } +class GraphicsWidget_task250119 : public QGraphicsWidget +{ +public: + GraphicsWidget_task250119() + : shortcutEvents(0) + { + setFocusPolicy(Qt::StrongFocus); + resize(100, 100); + } + + int shortcutEvents; + +private: + bool event(QEvent *event) + { + if (event->type() == QEvent::Shortcut) + shortcutEvents++; + return QGraphicsWidget::event(event); + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + { + if (hasFocus()) { + painter->setPen(QPen(Qt::black, 0, Qt::DashLine)); + painter->drawRect(rect()); + } + painter->setPen(QPen(Qt::black, 0, Qt::SolidLine)); + painter->fillRect(rect().adjusted(2, 2, -2, -2), Qt::yellow); + painter->drawRect(rect().adjusted(2, 2, -2, -2)); + } +}; + +void tst_QGraphicsWidget::task250119_shortcutContext() +{ + QGraphicsScene scene; + QGraphicsView view; + view.setScene(&scene); + view.show(); + QTest::qWait(100); + + + // *** Event: *** + + GraphicsWidget_task250119 w_event; + scene.addItem(&w_event); + + const int id = w_event.grabShortcut(Qt::Key_A, Qt::WidgetWithChildrenShortcut); + w_event.setShortcutEnabled(id, true); + + w_event.setFocus(); + QTest::keyPress(&view, Qt::Key_A); + QCOMPARE(w_event.shortcutEvents, 1); + + w_event.clearFocus(); + QTest::keyPress(&view, Qt::Key_A); + QCOMPARE(w_event.shortcutEvents, 1); + + scene.removeItem(&w_event); + + + // *** Signal: *** + + GraphicsWidget_task250119 w_signal; + scene.addItem(&w_signal); + + QAction action(0); + action.setShortcut(Qt::Key_B); + action.setShortcutContext(Qt::WidgetWithChildrenShortcut); + QSignalSpy spy(&action, SIGNAL(triggered())); + + w_signal.addAction(&action); + + w_signal.setFocus(); + QTest::keyPress(&view, Qt::Key_B); + QCOMPARE(spy.count(), 1); + + w_signal.clearFocus(); + QTest::keyPress(&view, Qt::Key_B); + QCOMPARE(spy.count(), 1); + + scene.removeItem(&w_signal); +} + QTEST_MAIN(tst_QGraphicsWidget) #include "tst_qgraphicswidget.moc" -- cgit v0.12 From bb0e2a55192cd134eb642dfa2f5e7ee93668a059 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Tue, 12 May 2009 10:21:21 +0200 Subject: Fix handling of gradients on pens in the emulation paint engine. The handling of gradients with object bounding mode on pens in the emulation paint engine has been changed to agree with the SVG standard, where pen widths are ignored when calculating bounding boxes. Instead of converting strokes to fills and then transforming the gradients based on the fills' bounding box, the gradients are now transformed first based on the bounding box of the stroke path. Reviewed-by: Trond --- src/gui/painting/qemulationpaintengine.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/gui/painting/qemulationpaintengine.cpp b/src/gui/painting/qemulationpaintengine.cpp index 3397c45..175f1ab 100644 --- a/src/gui/painting/qemulationpaintengine.cpp +++ b/src/gui/painting/qemulationpaintengine.cpp @@ -123,14 +123,30 @@ void QEmulationPaintEngine::stroke(const QVectorPath &path, const QPen &pen) real_engine->stroke(path, bgPen); } - QBrush brush = pen.brush(); + QPen copy = pen; Qt::BrushStyle style = qbrush_style(brush); if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) { const QGradient *g = brush.gradient(); + if (g->coordinateMode() > QGradient::LogicalMode) { - QPaintEngineEx::stroke(path, pen); - return; + if (g->coordinateMode() == QGradient::StretchToDeviceMode) { + QTransform mat = brush.transform(); + mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height()); + brush.setTransform(mat); + copy.setBrush(brush); + real_engine->stroke(path, copy); + return; + } else if (g->coordinateMode() == QGradient::ObjectBoundingMode) { + QTransform mat = brush.transform(); + QRealRect r = path.controlPointRect(); + mat.translate(r.x1, r.y1); + mat.scale(r.x2 - r.x1, r.y2 - r.y1); + brush.setTransform(mat); + copy.setBrush(brush); + real_engine->stroke(path, copy); + return; + } } } -- cgit v0.12 From bc184432c49eb56254bc5db07c6af03718c6b0e7 Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Tue, 12 May 2009 13:52:28 +0200 Subject: Correcting bug in QString::fromWCharArray documentation Clearifying details about bit size of the wchar_t input and the way they are handled. Task-number:227709 Rev-by: Marius Storm-Olsen --- src/corelib/tools/qstring.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 375d672..c3649e3 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -743,7 +743,9 @@ int QString::grow(int size) /*! \since 4.2 - Returns a copy of the \a string string encoded in ucs4. + Returns a copy of the \a string, where the encoding of \a string depends on + the size of wchar. If wchar is 4 bytes, the \a string is interpreted as ucs-4, + if wchar is 2 bytes it is interpreted as ucs-2. If \a size is -1 (default), the \a string has to be 0 terminated. -- cgit v0.12 From 4d5a5149b716c67f031a3a40e23370f90542c92f Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Tue, 12 May 2009 14:34:10 +0200 Subject: Make QAccessibleLineEdit actually accessible Q_ACCESSIBLE_OBJECT was missing --- src/plugins/accessible/widgets/simplewidgets.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/accessible/widgets/simplewidgets.h b/src/plugins/accessible/widgets/simplewidgets.h index d4552e3..d1fd0da 100644 --- a/src/plugins/accessible/widgets/simplewidgets.h +++ b/src/plugins/accessible/widgets/simplewidgets.h @@ -115,6 +115,7 @@ public: class QAccessibleLineEdit : public QAccessibleWidgetEx, public QAccessibleTextInterface, public QAccessibleSimpleEditableTextInterface { + Q_ACCESSIBLE_OBJECT public: explicit QAccessibleLineEdit(QWidget *o, const QString &name = QString()); -- cgit v0.12 From 8c4aee1be1e50bd49207aee61ac41613e07e0605 Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Tue, 5 May 2009 11:09:25 +0200 Subject: Fix typo in spreadsheet example Reviewed-by: Kavindra Palaraja --- demos/spreadsheet/spreadsheet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/spreadsheet/spreadsheet.cpp b/demos/spreadsheet/spreadsheet.cpp index 742855e..d740aee 100644 --- a/demos/spreadsheet/spreadsheet.cpp +++ b/demos/spreadsheet/spreadsheet.cpp @@ -481,7 +481,7 @@ void SpreadSheet::setupContents() table->setItem(3, 0, new SpreadSheetItem("Lunch")); table->setItem(4, 0, new SpreadSheetItem("Flight (LA)")); table->setItem(5, 0, new SpreadSheetItem("Taxi")); - table->setItem(6, 0, new SpreadSheetItem("Diinner")); + table->setItem(6, 0, new SpreadSheetItem("Dinner")); table->setItem(7, 0, new SpreadSheetItem("Hotel")); table->setItem(8, 0, new SpreadSheetItem("Flight (Oslo)")); table->setItem(9, 0, new SpreadSheetItem("Total:")); -- cgit v0.12 From 62edc8d78a8e38c62a87420bd3b37c886c6926d3 Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Tue, 12 May 2009 16:11:41 +0200 Subject: Adding documentation to the fancy browser example Added documentation to the fancy browser example. Task-number:252097 Rev-by: Geir Vattekar Rev-by: Ariya Hidayat --- doc/src/examples/fancybrowser.qdoc | 103 +++++++++++++++++++++++++++- examples/webkit/fancybrowser/mainwindow.cpp | 20 +++++- examples/webkit/fancybrowser/mainwindow.h | 4 +- 3 files changed, 122 insertions(+), 5 deletions(-) diff --git a/doc/src/examples/fancybrowser.qdoc b/doc/src/examples/fancybrowser.qdoc index 9001c20..8338d8b 100644 --- a/doc/src/examples/fancybrowser.qdoc +++ b/doc/src/examples/fancybrowser.qdoc @@ -40,12 +40,109 @@ ****************************************************************************/ /*! - \example webkit/fancybrowser - \title Fancy Browser Example + \example webkit/fancybrowser + \title Fancy Browser Example The Fancy Browser example shows how to use jQuery with QtWebKit to - make a web browser with some special effects and content manipulation. + create a web browser with special effects and content + manipulation. \image fancybrowser-example.png + The application makes use of QWebFrame::evaluateJavaScript to + evaluate the jQuery JavaScript code. A QMainWindow with a QWebView + as central widget builds up the browser itself. + + \section1 MainWindow Class Definition + + The \c MainWindow class inherits QMainWindow. It implements a number of + slots to perform actions on both the application and on the web content. + + \snippet examples/webkit/fancybrowser/mainwindow.h 1 + + We also declare a QString that contains the jQuery, a QWebView + that displays the web content, and a QLineEdit that acts as the + address bar. + + \section1 MainWindow Class Implementation + + We start by implementing the constructor. + + \snippet examples/webkit/fancybrowser/mainwindow.cpp 1 + + The first part of the constructor sets the value of \c progress to + 0. This value will be used later in the code to visualize the + loading of a webpage. + + Next, the jQuery library is loaded using a QFile and reading the file + content. The jQuery library is a JavaScript library that provides different + functions for manipulating HTML. + + \snippet examples/webkit/fancybrowser/mainwindow.cpp 2 + + The second part of the constructor creates a QWebView and connects + slots to the views signals. Furthermore, we create a QLineEdit as + the browsers address bar. We then set the horizontal QSizePolicy + to fill the available area in the browser at all times. We add the + QLineEdit to a QToolbar together with a set of navigation actions + from QWebView::pageAction. + + \snippet examples/webkit/fancybrowser/mainwindow.cpp 3 + + The third and last part of the constructor implements two QMenus and assigns + a set of actions to them. The last line sets the QWebView as the central + widget in the QMainWindow. + + \snippet examples/webkit/fancybrowser/mainwindow.cpp 4 + + When the page is loaded, \c adjustLocation() updates the address + bar; \c adjustLocation() is triggered by the \c loadFinished() + signal in QWebView. In \c changeLocation() we create a QUrl + objecti, and then use it to load the page into the QWebView. When + the new web page has finished loading, \c adjustLocation() will be + run once more to update the address bar. + + \snippet examples/webkit/fancybrowser/mainwindow.cpp 5 + + \c adjustTitle() sets the window title and displays the loading + progress. This slot is triggered by the \c titleChanged() signal + in QWebView. + + \snippet examples/webkit/fancybrowser/mainwindow.cpp 6 + + When a web page has loaded, \c finishLoading() is triggered by the + \c loadFinished() signal in QWebView. \c finishLoading() then updates the + progress in the title bar and calls \c evaluateJavaScript() to evaluate the + jQuery library. This evaluates the JavaScript against the current web page. + What that means is that the JavaScript can be viewed as part of the content + loaded into the QWebView, and therefore needs to be loaded every time a new + page is loaded. Once the jQuery library is loaded, we can start executing + the different jQuery functions in the browser. + + \snippet examples/webkit/fancybrowser/mainwindow.cpp 7 + + The first jQuery-based function, \c highlightAllLinks(), is designed to + highlight all links in the current webpage. The JavaScript code looks + for web elements named \i {a}, which is the tag for a hyperlink. + For each such element, the background color is set to be yellow by + using CSS. + + \snippet examples/webkit/fancybrowser/mainwindow.cpp 8 + + The \c rotateImages() function rotates the images on the current + web page. Webkit supports CSS transforms and this JavaScript code + looks up all \i {img} elements and rotates the images 180 degrees + and then back again. + + \snippet examples/webkit/fancybrowser/mainwindow.cpp 9 + + The remaining four methods remove different elements from the current web + page. \c removeGifImages() removes all Gif images on the page by looking up + the \i {src} attribute of all the elements on the web page. Any element with + a \i {gif} file as its source is removed. \c removeInlineFrames() removes all + \i {iframe} or inline elements. \c removeObjectElements() removes all + \i {object} elements, and \c removeEmbeddedElements() removes any elements + such as plugins embedded on the page using the \i {embed} element. + */ + diff --git a/examples/webkit/fancybrowser/mainwindow.cpp b/examples/webkit/fancybrowser/mainwindow.cpp index bf61f9c..e24f6cf 100644 --- a/examples/webkit/fancybrowser/mainwindow.cpp +++ b/examples/webkit/fancybrowser/mainwindow.cpp @@ -43,6 +43,8 @@ #include #include "mainwindow.h" +//! [1] + MainWindow::MainWindow() { progress = 0; @@ -52,7 +54,9 @@ MainWindow::MainWindow() file.open(QIODevice::ReadOnly); jQuery = file.readAll(); file.close(); +//! [1] +//! [2] view = new QWebView(this); view->load(QUrl("http://www.google.com/ncr")); connect(view, SIGNAL(loadFinished(bool)), SLOT(adjustLocation())); @@ -70,7 +74,9 @@ MainWindow::MainWindow() toolBar->addAction(view->pageAction(QWebPage::Reload)); toolBar->addAction(view->pageAction(QWebPage::Stop)); toolBar->addWidget(locationEdit); +//! [2] +//! [3] QMenu *effectMenu = menuBar()->addMenu(tr("&Effect")); effectMenu->addAction("Highlight all links", this, SLOT(highlightAllLinks())); @@ -89,7 +95,9 @@ MainWindow::MainWindow() setCentralWidget(view); } +//! [3] +//! [4] void MainWindow::adjustLocation() { locationEdit->setText(view->url().toString()); @@ -98,11 +106,12 @@ void MainWindow::adjustLocation() void MainWindow::changeLocation() { QUrl url = QUrl(locationEdit->text()); - locationEdit->setText(url.toString()); view->load(url); view->setFocus(); } +//! [4] +//! [5] void MainWindow::adjustTitle() { if (progress <= 0 || progress >= 100) @@ -116,20 +125,26 @@ void MainWindow::setProgress(int p) progress = p; adjustTitle(); } +//! [5] +//! [6] void MainWindow::finishLoading(bool) { progress = 100; adjustTitle(); view->page()->mainFrame()->evaluateJavaScript(jQuery); } +//! [6] +//! [7] void MainWindow::highlightAllLinks() { QString code = "$('a').each( function () { $(this).css('background-color', 'yellow') } )"; view->page()->mainFrame()->evaluateJavaScript(code); } +//! [7] +//! [8] void MainWindow::rotateImages(bool toggle) { QString code = "$('img').each( function () { $(this).css('-webkit-transition', '-webkit-transform 2s') } )"; @@ -140,7 +155,9 @@ void MainWindow::rotateImages(bool toggle) code = "$('img').each( function () { $(this).css('-webkit-transform', 'rotate(0deg)') } )"; view->page()->mainFrame()->evaluateJavaScript(code); } +//! [8] +//! [9] void MainWindow::removeGifImages() { QString code = "$('[src*=gif]').remove()"; @@ -164,4 +181,5 @@ void MainWindow::removeEmbeddedElements() QString code = "$('embed').remove()"; view->page()->mainFrame()->evaluateJavaScript(code); } +//! [9] diff --git a/examples/webkit/fancybrowser/mainwindow.h b/examples/webkit/fancybrowser/mainwindow.h index 9362ca7..2e1068c 100644 --- a/examples/webkit/fancybrowser/mainwindow.h +++ b/examples/webkit/fancybrowser/mainwindow.h @@ -39,13 +39,14 @@ ** ****************************************************************************/ -#include +#include QT_BEGIN_NAMESPACE class QWebView; class QLineEdit; QT_END_NAMESPACE +//! [1] class MainWindow : public QMainWindow { Q_OBJECT @@ -73,4 +74,5 @@ private: QWebView *view; QLineEdit *locationEdit; int progress; +//! [1] }; -- cgit v0.12 From 0c3d59a34c404ba1cec1ab6dbe88e4bf0664538b Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 12 May 2009 16:13:40 +0200 Subject: QListView was assuming that selected indexes were always children of their root. This can be different. ...especially if one manages the selection by program or if you share the selection model with a treeview. Task-number: 196118 Reviewed-by: ogoffart --- src/gui/itemviews/qlistview.cpp | 8 ++++++-- tests/auto/qlistview/tst_qlistview.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp index 3e00cd0..1071c1d 100644 --- a/src/gui/itemviews/qlistview.cpp +++ b/src/gui/itemviews/qlistview.cpp @@ -1608,6 +1608,10 @@ QRegion QListView::visualRegionForSelection(const QItemSelection &selection) con if (!selection.at(i).isValid()) continue; QModelIndex parent = selection.at(i).topLeft().parent(); + //we only display the children of the root in a listview + //we're not interested in the other model indexes + if (parent != d->root) + continue; int t = selection.at(i).topLeft().row(); int b = selection.at(i).bottomRight().row(); if (d->viewMode == IconMode || d->isWrapping()) { // in non-static mode, we have to go through all selected items @@ -1616,8 +1620,8 @@ QRegion QListView::visualRegionForSelection(const QItemSelection &selection) con } else { // in static mode, we can optimize a bit while (t <= b && d->isHidden(t)) ++t; while (b >= t && d->isHidden(b)) --b; - const QModelIndex top = d->model->index(t, c, d->root); - const QModelIndex bottom = d->model->index(b, c, d->root); + const QModelIndex top = d->model->index(t, c, parent); + const QModelIndex bottom = d->model->index(b, c, parent); QRect rect(visualRect(top).topLeft(), visualRect(bottom).bottomRight()); selectionRegion += QRegion(rect); diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp index 791a472..f70db14 100644 --- a/tests/auto/qlistview/tst_qlistview.cpp +++ b/tests/auto/qlistview/tst_qlistview.cpp @@ -106,6 +106,7 @@ private slots: void task228566_infiniteRelayout(); void task248430_crashWith0SizedItem(); void task250446_scrollChanged(); + void task196118_visualRegionForSelection(); void keyboardSearch(); }; @@ -1556,6 +1557,29 @@ void tst_QListView::task250446_scrollChanged() QCOMPARE(view.currentIndex(), index); } +void tst_QListView::task196118_visualRegionForSelection() +{ + class MyListView : public QListView + { + public: + QRegion visualRegionForSelection() const + { return QListView::visualRegionForSelection( selectionModel()->selection()); } + } view; + + QStandardItemModel model; + QStandardItem top1("top1"); + QStandardItem sub1("sub1"); + top1.appendRow(QList() << &sub1); + model.appendColumn(QList() << &top1); + view.setModel(&model); + view.setRootIndex(top1.index()); + + view.selectionModel()->select(top1.index(), QItemSelectionModel::Select); + + QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1); + QVERIFY(view.visualRegionForSelection().isEmpty()); +} + void tst_QListView::keyboardSearch() { QStringList items; -- cgit v0.12 From 544072cae31038ab16425c06186d8bca176f26e4 Mon Sep 17 00:00:00 2001 From: Benjamin Poulain Date: Tue, 12 May 2009 16:12:52 +0200 Subject: The description cited MySQL and the code is for PostgreSQL. Task-number: 253427 Reviewed-by: TrustMe --- src/sql/kernel/qsqldatabase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp index 6232452..a270c0e 100644 --- a/src/sql/kernel/qsqldatabase.cpp +++ b/src/sql/kernel/qsqldatabase.cpp @@ -378,7 +378,7 @@ void QSqlDatabasePrivate::disable() the connection name argument, if you don't pass the connection name argument, the default connection is assumed. The following snippet shows how to create and open a default connection to a - MySQL database: + PostgreSQL database: \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 0 -- cgit v0.12 From 661096f7ed2d9d5c91d716ba414c7286220c6cf9 Mon Sep 17 00:00:00 2001 From: Benjamin Poulain Date: Tue, 12 May 2009 16:12:52 +0200 Subject: The description cited MySQL and the code is for PostgreSQL. Task-number: 253427 Reviewed-by: TrustMe --- src/sql/kernel/qsqldatabase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp index 6232452..a270c0e 100644 --- a/src/sql/kernel/qsqldatabase.cpp +++ b/src/sql/kernel/qsqldatabase.cpp @@ -378,7 +378,7 @@ void QSqlDatabasePrivate::disable() the connection name argument, if you don't pass the connection name argument, the default connection is assumed. The following snippet shows how to create and open a default connection to a - MySQL database: + PostgreSQL database: \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 0 -- cgit v0.12 From 64f86caef81ee0047fe28f0bc9c1d8a4ca606ebb Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 12 May 2009 17:05:33 +0200 Subject: Reviewed-by: TrustMe Small polishing. --- doc/src/examples/fancybrowser.qdoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/examples/fancybrowser.qdoc b/doc/src/examples/fancybrowser.qdoc index 8338d8b..ea4da71 100644 --- a/doc/src/examples/fancybrowser.qdoc +++ b/doc/src/examples/fancybrowser.qdoc @@ -98,7 +98,7 @@ When the page is loaded, \c adjustLocation() updates the address bar; \c adjustLocation() is triggered by the \c loadFinished() signal in QWebView. In \c changeLocation() we create a QUrl - objecti, and then use it to load the page into the QWebView. When + object, and then use it to load the page into the QWebView. When the new web page has finished loading, \c adjustLocation() will be run once more to update the address bar. @@ -142,7 +142,7 @@ a \i {gif} file as its source is removed. \c removeInlineFrames() removes all \i {iframe} or inline elements. \c removeObjectElements() removes all \i {object} elements, and \c removeEmbeddedElements() removes any elements - such as plugins embedded on the page using the \i {embed} element. + such as plugins embedded on the page using the \i {embed} tag. */ -- cgit v0.12 From e58b7a29206bf81735ce45c964285de2e94ccc70 Mon Sep 17 00:00:00 2001 From: Trond Kjernaasen Date: Tue, 12 May 2009 17:22:33 +0200 Subject: Fixed a memory leak that occured when loading system icons on Windows. There was a qFree() call missing. Task-number: related to 253367 Reviewed-by: jbache --- src/gui/image/qpixmap_win.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/image/qpixmap_win.cpp b/src/gui/image/qpixmap_win.cpp index 3ec441b..cbe9004 100644 --- a/src/gui/image/qpixmap_win.cpp +++ b/src/gui/image/qpixmap_win.cpp @@ -319,6 +319,7 @@ static QImage qt_fromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h) } else { qWarning("qt_fromWinHBITMAP(), failed to get bitmap bits"); } + qFree(data); return image; } -- cgit v0.12 From 6c154a5fc2b6e3fe3ccf9dbee709b01c08c27f6c Mon Sep 17 00:00:00 2001 From: Norwegian Rock Cat Date: Tue, 12 May 2009 17:49:41 +0200 Subject: Ensure that windows hidden by deletion affect closeOnLastWindow Our destructor didn't call close, which meant that we never emitted lastWindowClosed. Task-number: 253333 Reviewed-by: Bradley T. Hughes --- src/gui/kernel/qwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index b7c4d33..0942f8b 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -1345,7 +1345,7 @@ QWidget::~QWidget() d->setDirtyOpaqueRegion(); if (isWindow() && isVisible() && internalWinId()) - hide(); + d->close_helper(QWidgetPrivate::CloseNoEvent); #if defined(Q_WS_WIN) || defined(Q_WS_X11) else if (!internalWinId() && isVisible()) qApp->d_func()->sendSyntheticEnterLeave(this); -- cgit v0.12 From 8a4934d8b97b55b80b2709dba04346e068251906 Mon Sep 17 00:00:00 2001 From: Norwegian Rock Cat Date: Tue, 12 May 2009 17:53:27 +0200 Subject: Document a gotcha with QIcon::addFile addFile makes a QIcon not null, which may be a surprise if the path given is bad. Reviewed-by: Jens Bache-Wiig --- src/gui/image/qicon.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 3c71f15..53430ab 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -854,6 +854,9 @@ void QIcon::addPixmap(const QPixmap &pixmap, Mode mode, State state) QImageWriter::supportedImageFormats() functions to retrieve a complete list of the supported file formats. + Note: When you add a non-empty filename to a QIcon, the icon becomes + non-null, even if the file doesn't exist or points to a corrupt file. + \sa addPixmap() */ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State state) -- cgit v0.12 From efad5df3ee7dea6cb587aacd27010e15a69f4320 Mon Sep 17 00:00:00 2001 From: Kavindra Devi Palaraja Date: Tue, 12 May 2009 18:18:29 +0200 Subject: Doc - cleaning up the documentation of QUiLoader. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also mentioned an important point: If you subclass QUiLoader and reimplement either createAction(), createActionGroup(), createLayout(), or createWidget() -- you must call the original implementation first, within your implementation. Reviewed-by: João Abecasis --- tools/designer/src/uitools/quiloader.cpp | 194 +++++++++++++++++-------------- 1 file changed, 105 insertions(+), 89 deletions(-) diff --git a/tools/designer/src/uitools/quiloader.cpp b/tools/designer/src/uitools/quiloader.cpp index 67bd29c..106e641 100644 --- a/tools/designer/src/uitools/quiloader.cpp +++ b/tools/designer/src/uitools/quiloader.cpp @@ -572,53 +572,52 @@ void QUiLoaderPrivate::setupWidgetMap() const \class QUiLoader \inmodule QtUiTools - \brief The QUiLoader class allows standalone applications dynamically - create user interfaces at run-time using the information stored in - .ui files or specified plugin paths. + \brief enables standalone applications to dynamically create user + interfaces at run-time using the information stored in .ui files or + specified in plugin paths. - In addition, you can customize of creating an user interface by + In addition, you can customize or create your own user interface by deriving your own loader class. - If you have a custom component or an application that embeds Qt - Designer, you can also use the QFormBuilder class provided by the - QtDesigner module to create user interfaces from .ui files. + If you have a custom component or an application that embeds \QD, you can + also use the QFormBuilder class provided by the QtDesigner module to create + user interfaces from \c{.ui} files. - The QUiLoader class provides a collection of functions that allows - you to create widgets based on the information stored in \c .ui - files (created with Qt Designer) or available in the specified - plugin paths. The specified plugin paths can be retrieved using - the pluginPaths() function. You can retrieve the contents of an \c - .ui file using the load() function. For example: + The QUiLoader class provides a collection of functions allowing you to + create widgets based on the information stored in \c .ui files (created + with \QD) or available in the specified plugin paths. The specified plugin + paths can be retrieved using the pluginPaths() function. Similarly, the + contents of a \c{.ui} file can be retrieved using the load() function. For + example: \snippet doc/src/snippets/quiloader/mywidget.cpp 0 - By including the user interface in the form's resources (\c myform.qrc), - we ensure that it will be present at run-time: + By including the user interface in the form's resources (\c myform.qrc), we + ensure that it will be present at run-time: \quotefile doc/src/snippets/quiloader/mywidget.qrc - The availableWidgets() function returns a QStringList with the - class names of the widgets available in the specified plugin - paths. You can create any of these widgets using the - createWidget() function. For example: + The availableWidgets() function returns a QStringList with the class names + of the widgets available in the specified plugin paths. To create these + widgets, simply use the createWidget() function. For example: \snippet doc/src/snippets/quiloader/main.cpp 0 - You can make a custom widget available to the loader using the - addPluginPath() function, and you can remove all the available widgets - by calling the clearPluginPaths() function. + To make a custom widget available to the loader, you can use the + addPluginPath() function; to remove all available widgets, you can call + the clearPluginPaths() function. - The createAction(), createActionGroup(), createLayout() and - createWidget() functions are used internally by the QUiLoader class - whenever it has to create an action, action group, layout or - widget respectively. For that reason, you can subclass the QUiLoader - class and reimplement these functions to intervene the process of - constructing an user interface. For example, you might want to - create a list of the actions created when loading a form or - creating a custom widget. + The createAction(), createActionGroup(), createLayout(), and createWidget() + functions are used internally by the QUiLoader class whenever it has to + create an action, action group, layout, or widget respectively. For that + reason, you can subclass the QUiLoader class and reimplement these + functions to intervene the process of constructing a user interface. For + example, you might want to have a list of the actions created when loading + a form or creating a custom widget. However, in your reimplementation, you + must call QUiLoader's original implementation of these functions first. - For a complete example using the QUiLoader class, see the \l - {designer/calculatorbuilder}{Calculator Builder} example. + For a complete example using the QUiLoader class, see the + \l{Calculator Builder Example}. \sa QtUiTools, QFormBuilder */ @@ -653,8 +652,8 @@ QUiLoader::~QUiLoader() } /*! - Loads a form from the given \a device and creates a new widget with the given - \a parentWidget to hold its contents. + Loads a form from the given \a device and creates a new widget with the + given \a parentWidget to hold its contents. \sa createWidget() */ @@ -668,8 +667,8 @@ QWidget *QUiLoader::load(QIODevice *device, QWidget *parentWidget) } /*! - Returns a list naming the paths the loader searches when locating - custom widget plugins. + Returns a list naming the paths in which the loader will search when + locating custom widget plugins. \sa addPluginPath(), clearPluginPaths() */ @@ -680,7 +679,7 @@ QStringList QUiLoader::pluginPaths() const } /*! - Clears the list of paths the loader searches when locating + Clears the list of paths in which the loader will search when locating plugins. \sa addPluginPath(), pluginPaths() @@ -692,7 +691,7 @@ void QUiLoader::clearPluginPaths() } /*! - Adds the given \a path to the list of paths the loader searches + Adds the given \a path to the list of paths in which the loader will search when locating plugins. \sa pluginPaths(), clearPluginPaths() @@ -704,17 +703,17 @@ void QUiLoader::addPluginPath(const QString &path) } /*! - Creates a new widget with the given \a parent and \a name - using the class specified by \a className. You can use this - function to create any of the widgets returned by the - availableWidgets() function. + Creates a new widget with the given \a parent and \a name using the class + specified by \a className. You can use this function to create any of the + widgets returned by the availableWidgets() function. - The function is also used internally by the QUiLoader class whenever - it has to create a widget. For that reason, you can subclass the - QUiLoader class and reimplement this function to intervene in the - process of constructing a user interface or widget. + The function is also used internally by the QUiLoader class whenever it + creates a widget. Hence, you can subclass QUiLoader and reimplement this + function to intervene process of constructing a user interface or widget. + However, in your implementation, ensure that you call QUiLoader's version + first. - \sa availableWidgets(), load() + \sa availableWidgets(), load() */ QWidget *QUiLoader::createWidget(const QString &className, QWidget *parent, const QString &name) { @@ -723,13 +722,14 @@ QWidget *QUiLoader::createWidget(const QString &className, QWidget *parent, cons } /*! - Creates a new layout with the given \a parent and \a name - using the class specified by \a className. + Creates a new layout with the given \a parent and \a name using the class + specified by \a className. - The function is used internally by the QUiLoader class whenever it - has to create a layout. For that reason, you can subclass the - QUiLoader class and reimplement this function to intervene the - process of constructing an user interface or widget. + The function is also used internally by the QUiLoader class whenever it + creates a widget. Hence, you can subclass QUiLoader and reimplement this + function to intervene process of constructing a user interface or widget. + However, in your implementation, ensure that you call QUiLoader's version + first. \sa createWidget(), load() */ @@ -742,10 +742,11 @@ QLayout *QUiLoader::createLayout(const QString &className, QObject *parent, cons /*! Creates a new action group with the given \a parent and \a name. - The function is used internally by the QUiLoader class whenever it - has to create an action group. For that reason, you can subclass - the QUiLoader class and reimplement this function to intervene the - process of constructing an user interface or widget. + The function is also used internally by the QUiLoader class whenever it + creates a widget. Hence, you can subclass QUiLoader and reimplement this + function to intervene process of constructing a user interface or widget. + However, in your implementation, ensure that you call QUiLoader's version + first. \sa createAction(), createWidget(), load() */ @@ -758,10 +759,11 @@ QActionGroup *QUiLoader::createActionGroup(QObject *parent, const QString &name) /*! Creates a new action with the given \a parent and \a name. - The function is used internally by the QUiLoader class whenever it - has to create an action. For that reason, you can subclass the - QUiLoader class and reimplement this function to intervene the - process of constructing an user interface or widget. + The function is also used internally by the QUiLoader class whenever it + creates a widget. Hence, you can subclass QUiLoader and reimplement this + function to intervene process of constructing a user interface or widget. + However, in your implementation, ensure that you call QUiLoader's version + first. \sa createActionGroup(), createWidget(), load() */ @@ -772,9 +774,9 @@ QAction *QUiLoader::createAction(QObject *parent, const QString &name) } /*! - Returns a list naming the available widgets that can be built - using the createWidget() function, i.e all the widgets specified - within the given plugin paths. + Returns a list naming all available widgets that can be built using the + createWidget() function, i.e all the widgets specified within the given + plugin paths. \sa pluginPaths(), createWidget() @@ -795,11 +797,11 @@ QStringList QUiLoader::availableWidgets() const /*! - Returns a list naming the available layouts that can be built - using the createLayout() function + \since 4.5 + Returns a list naming all available layouts that can be built using the + createLayout() function \sa createLayout() - \since 4.5 */ QStringList QUiLoader::availableLayouts() const @@ -816,9 +818,9 @@ QStringList QUiLoader::availableLayouts() const } /*! - Sets the working directory of the loader to \a dir. The loader - looks for other resources, such as icons and resource files, - in paths relative to this directory. + Sets the working directory of the loader to \a dir. The loader will look + for other resources, such as icons and resource files, in paths relative to + this directory. \sa workingDirectory() */ @@ -842,9 +844,13 @@ QDir QUiLoader::workingDirectory() const } /*! - Sets whether the execution of scripts is enabled to \a enabled. - \since 4.3 \internal + \since 4.3 + + If \a enabled is true, the loader will be able to execute scripts. + Otherwise, execution of scripts will be disabled. + + \sa isScriptingEnabled() */ void QUiLoader::setScriptingEnabled(bool enabled) @@ -854,10 +860,12 @@ void QUiLoader::setScriptingEnabled(bool enabled) } /*! - Returns whether the execution of scripts is enabled. - \sa setScriptingEnabled() - \since 4.3 - \internal + \internal + \since 4.3 + + Returns true if execution of scripts is enabled; returns false otherwise. + + \sa setScriptingEnabled() */ bool QUiLoader::isScriptingEnabled() const @@ -867,11 +875,13 @@ bool QUiLoader::isScriptingEnabled() const } /*! - Sets whether user interfaces loaded by this loader automatically - retranslate themselves upon receiving a language change event or not, - depending on \a enabled. - \since 4.5 + + If \a enabled is true, user interfaces loaded by this loader will + automatically retranslate themselves upon receiving a language change + event. Otherwise, the user interfaces will not be retranslated. + + \sa isLanguageChangeEnabled() */ void QUiLoader::setLanguageChangeEnabled(bool enabled) @@ -881,9 +891,12 @@ void QUiLoader::setLanguageChangeEnabled(bool enabled) } /*! - Returns whether dynamic retranslation on language change is enabled. - \sa setLanguageChangeEnabled() - \since 4.5 + \since 4.5 + + Returns true if dynamic retranslation on language change is enabled; + returns false otherwise. + + \sa setLanguageChangeEnabled() */ bool QUiLoader::isLanguageChangeEnabled() const @@ -894,11 +907,14 @@ bool QUiLoader::isLanguageChangeEnabled() const /*! \internal + \since 4.5 + + If \a enabled is true, user interfaces loaded by this loader will be + translated. Otherwise, the user interfaces will not be translated. - Sets whether user interfaces loaded by this loader are translated - at all. Note that this is orthogonal to languageChangeEnabled. + \note This is orthogonal to languageChangeEnabled. - \since 4.5 + \sa isLanguageChangeEnabled(), setLanguageChangeEnabled() */ void QUiLoader::setTranslationEnabled(bool enabled) @@ -909,11 +925,11 @@ void QUiLoader::setTranslationEnabled(bool enabled) /*! \internal + \since 4.5 - Returns whether translation is enabled. - \sa setTranslationEnabled() + Returns true if translation is enabled; returns false otherwise. - \since 4.5 + \sa setTranslationEnabled() */ bool QUiLoader::isTranslationEnabled() const -- cgit v0.12 From 7f5e15034a324ecd7df082e012403ad99c5b5476 Mon Sep 17 00:00:00 2001 From: Kavindra Devi Palaraja Date: Tue, 12 May 2009 18:25:30 +0200 Subject: Doc - removing trailing whitespaces --- tools/designer/src/uitools/quiloader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/designer/src/uitools/quiloader.cpp b/tools/designer/src/uitools/quiloader.cpp index 106e641..548f07e 100644 --- a/tools/designer/src/uitools/quiloader.cpp +++ b/tools/designer/src/uitools/quiloader.cpp @@ -862,7 +862,7 @@ void QUiLoader::setScriptingEnabled(bool enabled) /*! \internal \since 4.3 - + Returns true if execution of scripts is enabled; returns false otherwise. \sa setScriptingEnabled() @@ -908,7 +908,7 @@ bool QUiLoader::isLanguageChangeEnabled() const /*! \internal \since 4.5 - + If \a enabled is true, user interfaces loaded by this loader will be translated. Otherwise, the user interfaces will not be translated. -- cgit v0.12 From 4ffda2918b3f5c789ef325cdeaac72e5e7ef2c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Tue, 12 May 2009 16:54:18 +0200 Subject: Reduce QWidget footprint and do some cleanup. This patch cleans up several things, like bit fields that are interleaved with with other variables, resulting in bits not being packed properly. Example: "uint a : 8; int c; uint b: 8;" -> "uint a : 8; uint b : 8; int c;" In that case we'll use 12 bytes instead of 8 bytes. I've also changed the order we declare certain variables to avoid unnecessary gaps/padding on 64-bit architectures. Example: "char *a; int c; char *b;" -> "char *a; char *b; int c;" Pointers are 64-bit aligned, so padding appears between 'c' and 'b', resulting in a total use of 24 bytes instead of 20 bytes. ...and since I anyways was moving the code around, I took the opportunity to add some overall structure by first declaring cross-platform functions/variables followed by platform specific functions/variables. ...and it was kinda scary to actually be able to see all the QStrings, pointers and whatnot we put into QWidgetPrivate. I'm sure we can remove lots of stuff, but I'll do that in a separate commit. Quick numbers (X11/64 bit): sizeof(QWidgetPrivate) == before: 472, after: 456 sizeof(QTLWExtra) == before: 112, after: 104 sizeof(QWExtra) == before: 152, after: 144 Acked-by: Olivier --- src/gui/kernel/qwidget.cpp | 130 +++++----- src/gui/kernel/qwidget_mac.mm | 6 +- src/gui/kernel/qwidget_p.h | 518 +++++++++++++++++++-------------------- src/gui/kernel/qwidget_qws.cpp | 3 + src/gui/kernel/qwidget_win.cpp | 11 +- src/gui/kernel/qwidget_wince.cpp | 7 - src/gui/kernel/qwidget_x11.cpp | 7 +- 7 files changed, 332 insertions(+), 350 deletions(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 0942f8b..a8eae9b 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -167,39 +167,48 @@ static inline bool bypassGraphicsProxyWidget(QWidget *p) extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp -QWidgetPrivate::QWidgetPrivate(int version) : - QObjectPrivate(version), extra(0), focus_child(0) - ,layout(0), widgetItem(0) - ,leftmargin(0), topmargin(0), rightmargin(0), bottommargin(0) - ,leftLayoutItemMargin(0), topLayoutItemMargin(0), rightLayoutItemMargin(0) - ,bottomLayoutItemMargin(0) - ,fg_role(QPalette::NoRole) - ,bg_role(QPalette::NoRole) - ,hd(0) - ,dirty(0) - ,needsFlush(0) - ,dirtyOpaqueChildren(1) - ,isOpaque(0) - ,inDirtyList(0) - ,isScrolled(0) - ,isMoved(0) - ,usesDoubleBufferedGLContext(0) -#ifdef Q_WS_WIN - ,noPaintOnScreen(0) -#endif - ,inheritedFontResolveMask(0) - ,inheritedPaletteResolveMask(0) +QWidgetPrivate::QWidgetPrivate(int version) + : QObjectPrivate(version) + , extra(0) + , focus_next(0) + , focus_prev(0) + , focus_child(0) + , layout(0) + , needsFlush(0) + , redirectDev(0) + , widgetItem(0) + , extraPaintEngine(0) + , polished(0) + , inheritedFontResolveMask(0) + , inheritedPaletteResolveMask(0) + , leftmargin(0) + , topmargin(0) + , rightmargin(0) + , bottommargin(0) + , leftLayoutItemMargin(0) + , topLayoutItemMargin(0) + , rightLayoutItemMargin(0) + , bottomLayoutItemMargin(0) + , hd(0) + , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred) + , fg_role(QPalette::NoRole) + , bg_role(QPalette::NoRole) + , dirtyOpaqueChildren(1) + , isOpaque(0) + , inDirtyList(0) + , isScrolled(0) + , isMoved(0) + , usesDoubleBufferedGLContext(0) #if defined(Q_WS_X11) - ,picture(0) -#endif -#ifdef Q_WS_MAC - ,needWindowChange(0) - ,isGLWidget(0) + , picture(0) +#elif defined(Q_WS_WIN) + , noPaintOnScreen(0) +#elif defined(Q_WS_MAC) + , needWindowChange(0) + , isGLWidget(0) + , window_event(0) + , qd_hd(0) #endif - ,polished(0) - - , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred) - , redirectDev(0) { if (!qApp) { qFatal("QWidget: Must construct a QApplication before a QPaintDevice"); @@ -1412,36 +1421,26 @@ void QWidgetPrivate::createTLExtra() createExtra(); if (!extra->topextra) { QTLWExtra* x = extra->topextra = new QTLWExtra; + x->icon = 0; + x->iconPixmap = 0; + x->backingStore = 0; x->windowSurface = 0; + x->sharedPainter = 0; + x->incw = x->inch = 0; + x->basew = x->baseh = 0; + x->frameStrut.setCoords(0, 0, 0, 0); + x->normalGeometry = QRect(0,0,-1,-1); + x->savedFlags = 0; x->opacity = 255; x->posFromMove = false; x->sizeAdjusted = false; x->inTopLevelResize = false; x->inRepaint = false; - x->backingStore = 0; - x->icon = 0; - x->iconPixmap = 0; - x->frameStrut.setCoords(0, 0, 0, 0); - x->incw = x->inch = 0; - x->basew = x->baseh = 0; - x->normalGeometry = QRect(0,0,-1,-1); -#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_MAC) x->embedded = 0; -#endif -#if defined(Q_WS_X11) - x->parentWinId = 0; - x->spont_unmapped = 0; - x->dnd = 0; -#endif - x->savedFlags = 0; -#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER) - x->qwsManager = 0; -#endif - x->sharedPainter = 0; createTLSysExtra(); #ifdef QWIDGET_EXTRA_DEBUG - static int count = 0; - qDebug() << "tlextra" << ++count; + static int count = 0; + qDebug() << "tlextra" << ++count; #endif } } @@ -1455,27 +1454,28 @@ void QWidgetPrivate::createExtra() { if (!extra) { // if not exists extra = new QWExtra; - extra->minw = extra->minh = 0; - extra->maxw = extra->maxh = QWIDGETSIZE_MAX; + extra->glContext = 0; + extra->topextra = 0; + extra->proxyWidget = 0; +#ifndef QT_NO_CURSOR + extra->curs = 0; +#endif + extra->minw = 0; + extra->minh = 0; + extra->maxw = QWIDGETSIZE_MAX; + extra->maxh = QWIDGETSIZE_MAX; + extra->customDpiX = 0; + extra->customDpiY = 0; extra->explicitMinSize = 0; extra->explicitMaxSize = 0; extra->autoFillBackground = 0; extra->nativeChildrenForced = 0; extra->inRenderWithPainter = 0; extra->hasMask = 0; -#ifndef QT_NO_CURSOR - extra->curs = 0; -#endif - extra->style = 0; - extra->topextra = 0; - extra->proxyWidget = 0; - extra->glContext = 0; - extra->customDpiX = 0; - extra->customDpiY = 0; createSysExtra(); #ifdef QWIDGET_EXTRA_DEBUG - static int count = 0; - qDebug() << "extra" << ++count; + static int count = 0; + qDebug() << "extra" << ++count; #endif } } diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 1896b97..cbfdaa0 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -4438,11 +4438,13 @@ void QWidgetPrivate::deleteSysExtra() void QWidgetPrivate::createTLSysExtra() { + extra->topextra->resizer = 0; + extra->topextra->isSetGeometry = 0; + extra->topextra->isMove = 0; + extra->topextra->wattr = 0; extra->topextra->wclass = 0; extra->topextra->group = 0; extra->topextra->windowIcon = 0; - extra->topextra->resizer = 0; - extra->topextra->isSetGeometry = 0; extra->topextra->savedWindowAttributesFromMaximized = 0; } diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 8c6a234..6dc4c95 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -99,88 +99,92 @@ class QWidgetItemV2; class QStyle; struct QTLWExtra { + // *************************** Cross-platform variables ***************************** + + // Regular pointers (keep them together to avoid gaps on 64 bits architectures). + QIcon *icon; // widget icon + QPixmap *iconPixmap; + QWidgetBackingStore *backingStore; + QWindowSurface *windowSurface; + QPainter *sharedPainter; + + // Implicit pointers (shared_null). QString caption; // widget caption QString iconText; // widget icon text QString role; // widget role QString filePath; // widget file path - QIcon *icon; // widget icon - QPixmap *iconPixmap; + + // Other variables. short incw, inch; // size increments + short basew, baseh; // base sizes // frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead. QRect frameStrut; + QRect normalGeometry; // used by showMin/maximized/FullScreen + Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen + + // *************************** Cross-platform bit fields **************************** uint opacity : 8; uint posFromMove : 1; uint sizeAdjusted : 1; uint inTopLevelResize : 1; uint inRepaint : 1; - QWidgetBackingStore *backingStore; -#if defined(Q_WS_WIN) - ulong savedFlags; // Save window flags while showing fullscreen - uint embedded : 1; // window is embedded in another application -#else - Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen -#endif - short basew, baseh; // base sizes -#if defined(Q_WS_X11) - WId parentWinId; // parent window Id (valid after reparenting) - uint embedded : 1; // window is embedded in another Qt application + uint embedded : 1; + + // *************************** Platform specific values (bit fields first) ********** +#if defined(Q_WS_X11) // <----------------------------------------------------------- X11 uint spont_unmapped: 1; // window was spontaneously unmapped uint dnd : 1; // DND properties installed uint validWMState : 1; // is WM_STATE valid? uint waitingForMapNotify : 1; // show() has been called, haven't got the MapNotify yet + WId parentWinId; // parent window Id (valid after reparenting) WId userTimeWindow; // window id that contains user-time timestamp when WM supports a _NET_WM_USER_TIME_WINDOW atom QPoint fullScreenOffset; -#endif -#if defined(Q_WS_MAC) +#elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN + HICON winIconBig; // internal big Windows icon + HICON winIconSmall; // internal small Windows icon +#elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC + uint resizer : 4; + uint isSetGeometry : 1; + uint isMove : 1; quint32 wattr; quint32 wclass; WindowGroupRef group; IconRef windowIcon; // the current window icon, if set with setWindowIcon_sys. quint32 savedWindowAttributesFromMaximized; // Saved attributes from when the calling updateMaximizeButton_sys() - uint resizer : 4; - uint isSetGeometry : 1; - uint isMove : 1; - uint embedded : 1; -#endif -#if defined(Q_WS_QWS) && !defined (QT_NO_QWS_MANAGER) +#elif defined(Q_WS_QWS) // <--------------------------------------------------------- QWS +#ifndef QT_NO_QWS_MANAGER QWSManager *qwsManager; #endif -#if defined(Q_WS_WIN) - HICON winIconBig; // internal big Windows icon - HICON winIconSmall; // internal small Windows icon #endif - QRect normalGeometry; // used by showMin/maximized/FullScreen - QWindowSurface *windowSurface; - QPainter *sharedPainter; }; struct QWExtra { - qint32 minw, minh; // minimum size - qint32 maxw, maxh; // maximum size - QPointer focus_proxy; -#ifndef QT_NO_CURSOR - QCursor *curs; -#endif + // *************************** Cross-platform variables ***************************** + + // Regular pointers (keep them together to avoid gaps on 64 bits architectures). + void *glContext; // if the widget is hijacked by QGLWindowSurface QTLWExtra *topextra; // only useful for TLWs QGraphicsProxyWidget *proxyWidget; // if the widget is embedded - void *glContext; // if the widget is hijacked by QGLWindowSurface -#if defined(Q_WS_WIN) && !defined(QT_NO_DRAGANDDROP) - QOleDropTarget *dropTarget; // drop target - QList > oleDropWidgets; -#endif -#if defined(Q_WS_X11) - WId xDndProxy; // XDND forwarding to embedded windows +#ifndef QT_NO_CURSOR + QCursor *curs; #endif + QPointer style; + QPointer focus_proxy; + + // Implicit pointers (shared_empty/shared_null). QRegion mask; // widget mask + QString styleSheet; + + // Other variables. + qint32 minw; + qint32 minh; // minimum size + qint32 maxw; + qint32 maxh; // maximum size + quint16 customDpiX; + quint16 customDpiY; QSize staticContentsSize; -//bit flags at the end to improve packing -#if defined(Q_WS_WIN) - uint shown_mode : 8; // widget show mode -#endif -#if defined(Q_WS_X11) - uint compress_events : 1; -#endif + // *************************** Cross-platform bit fields **************************** uint explicitMinSize : 2; uint explicitMaxSize : 2; uint autoFillBackground : 1; @@ -188,16 +192,22 @@ struct QWExtra { uint inRenderWithPainter : 1; uint hasMask : 1; - QPointer style; - QString styleSheet; - - quint16 customDpiX; - quint16 customDpiY; -#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA) + // *************************** Platform specific values (bit fields first) ********** +#if defined(Q_WS_WIN) // <----------------------------------------------------------- WIN +#ifndef QT_NO_DRAGANDDROP + QOleDropTarget *dropTarget; // drop target + QList > oleDropWidgets; +#endif +#elif defined(Q_WS_X11) // <--------------------------------------------------------- X11 + uint compress_events : 1; + WId xDndProxy; // XDND forwarding to embedded windows +#elif defined(Q_WS_MAC) // <------------------------------------------------------ MAC +#ifdef QT_MAC_USE_COCOA // Cocoa Mask stuff QImage maskBits; CGImageRef imageMask; #endif +#endif }; class Q_GUI_EXPORT QWidgetPrivate : public QObjectPrivate @@ -205,6 +215,24 @@ class Q_GUI_EXPORT QWidgetPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QWidget) public: + // *************************** Cross-platform *************************************** + enum DrawWidgetFlags { + DrawAsRoot = 0x01, + DrawPaintOnScreen = 0x02, + DrawRecursive = 0x04, + DrawInvisible = 0x08, + DontSubtractOpaqueChildren = 0x10, + DontSetCompositionMode = 0x20, + DontDrawOpaqueChildren = 0x40 + }; + + enum CloseMode { + CloseNoEvent, + CloseWithEvent, + CloseWithSpontaneousEvent + }; + + // Functions. explicit QWidgetPrivate(int version = QObjectPrivateVersion); ~QWidgetPrivate(); @@ -214,10 +242,6 @@ public: QPainter *sharedPainter() const; void setSharedPainter(QPainter *painter); QWidgetBackingStore *maybeBackingStore() const; -#ifdef Q_WS_QWS - void setMaxWindowState_helper(); - void setFullScreenSize_helper(); -#endif void init(QWidget *desktopWidget, Qt::WindowFlags f); void create_sys(WId window, bool initializeWindow, bool destroyOldWindow); void createRecursively(); @@ -238,24 +262,6 @@ public: QPalette naturalWidgetPalette(uint inheritedMask) const; void setMask_sys(const QRegion &); -#ifdef Q_WS_WIN - bool shouldShowMaximizeButton(); - void winUpdateIsOpaque(); -#endif - -#ifdef Q_WS_MAC - void macUpdateSizeAttribute(); - void macUpdateHideOnSuspend(); - void macUpdateOpaqueSizeGrip(); - void macUpdateIgnoreMouseEvents(); - void macUpdateMetalAttribute(); - void macUpdateIsOpaque(); - void setEnabled_helper_sys(bool enable); - bool isRealWindow() const; - void adjustWithinMaxAndMinSize(int &w, int &h); - void applyMaxAndMinSizeOnWindow(); -#endif - void raise_sys(); void lower_sys(); void stackUnder_sys(QWidget *); @@ -285,15 +291,6 @@ public: void setUpdatesEnabled_helper(bool ); void paintBackground(QPainter *, const QRegion &, const QPoint & = QPoint(), int flags = DrawAsRoot) const; - enum DrawWidgetFlags { - DrawAsRoot = 0x01, - DrawPaintOnScreen = 0x02, - DrawRecursive = 0x04, - DrawInvisible = 0x08, - DontSubtractOpaqueChildren = 0x10, - DontSetCompositionMode = 0x20, - DontDrawOpaqueChildren = 0x40 - }; bool isAboutToShow() const; QRegion prepareToRender(const QRegion ®ion, QWidget::RenderFlags renderFlags); void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion, @@ -316,10 +313,6 @@ public: QWindowSurface *createDefaultWindowSurface(); QWindowSurface *createDefaultWindowSurface_sys(); void repaint_sys(const QRegion &rgn); -#ifdef Q_WS_MAC - void update_sys(const QRect &rect); - void update_sys(const QRegion &rgn); -#endif QRect clipRect() const; QRegion clipRegion() const; @@ -337,35 +330,15 @@ public: const QRegion &getOpaqueChildren() const; void setDirtyOpaqueRegion(); - QRegion opaqueChildren; - - enum CloseMode { - CloseNoEvent, - CloseWithEvent, - CloseWithSpontaneousEvent - }; bool close_helper(CloseMode mode); bool compositeEvent(QEvent *e); void setWindowIcon_helper(); void setWindowIcon_sys(bool forceReset = false); void setWindowOpacity_sys(qreal opacity); - void adjustQuitOnCloseAttribute(); -#if defined(Q_WS_X11) - void setWindowRole(); - void sendStartupMessage(const char *message) const; - void setNetWmWindowTypes(); - void x11UpdateIsOpaque(); -#endif - -#if defined (Q_WS_WIN) - void reparentChildren(); -#endif - void scrollChildren(int dx, int dy); - void moveRect(const QRect &, int dx, int dy); void scrollRect(const QRect &, int dx, int dy); void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize); @@ -389,9 +362,6 @@ public: void scroll_sys(int dx, int dy, const QRect &r); void deactivateWidgetCleanup(); void setGeometry_sys(int, int, int, int, bool); -#ifdef Q_WS_MAC - void setGeometry_sys_helper(int, int, int, int, bool); -#endif void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false); void activateChildLayoutsRecursively(); void show_recursive(); @@ -403,10 +373,6 @@ public: void setEnabled_helper(bool); void registerDropSite(bool); -#if defined(Q_WS_WIN) && !defined(QT_NO_DRAGANDDROP) - QOleDropTarget *registerOleDnd(QWidget *widget); - void unregisterOleDnd(QWidget *widget, QOleDropTarget *target); -#endif static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0); void updateFrameStrut(); @@ -416,32 +382,11 @@ public: void setWindowIconText_helper(const QString &cap); void setWindowTitle_sys(const QString &cap); -#ifdef Q_OS_WIN - void grabMouseWhileInWindow(); -#endif - #ifndef QT_NO_CURSOR void setCursor_sys(const QCursor &cursor); void unsetCursor_sys(); #endif -#ifdef Q_WS_MAC - void setWindowModified_sys(bool b); - void updateMaximizeButton_sys(); - void setWindowFilePath_sys(const QString &filePath); - void createWindow_sys(); - void recreateMacWindow(); -#ifndef QT_MAC_USE_COCOA - void initWindowPtr(); - void finishCreateWindow_sys_Carbon(OSWindowRef windowRef); -#else - void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef); - void syncCocoaMask(); - void finishCocoaMaskSetup(); -#endif - void determineWindowClass(); - void transferChildren(); -#endif void setWindowTitle_helper(const QString &cap); void setWindowFilePath_helper(const QString &filePath); @@ -457,59 +402,89 @@ public: QInputContext *inputContext() const; -#if defined(Q_WS_QWS) - void moveSurface(QWindowSurface *surface, const QPoint &offset); + void setModal_sys(); - QRegion localRequestedRegion() const; - QRegion localAllocatedRegion() const; + inline void setRedirected(QPaintDevice *replacement, const QPoint &offset) + { + Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent)); + redirectDev = replacement; + redirectOffset = offset; + } - void blitToScreen(const QRegion &globalrgn); -#ifndef QT_NO_CURSOR - void updateCursor() const; -#endif + inline QPaintDevice *redirected(QPoint *offset) const + { + if (offset) + *offset = redirectDev ? redirectOffset : QPoint(); + return redirectDev; + } - QScreen* getScreen() const; + inline void restoreRedirected() + { redirectDev = 0; } - friend class QWSManager; - friend class QWSManagerPrivate; - friend class QDecoration; -#endif + inline void enforceNativeChildren() + { + if (!extra) + createExtra(); - static int instanceCounter; // Current number of widget instances - static int maxInstances; // Maximum number of widget instances + if (extra->nativeChildrenForced) + return; + extra->nativeChildrenForced = 1; -#ifdef QT_KEYPAD_NAVIGATION - static QPointer editingWidget; -#endif + for (int i = 0; i < children.size(); ++i) { + if (QWidget *child = qobject_cast(children.at(i))) + child->setAttribute(Qt::WA_NativeWindow); + } + } - QWidgetData data; + inline bool nativeChildrenForced() const + { + return extra ? extra->nativeChildrenForced : false; + } + + QSize adjustedSize() const; + +#ifndef Q_WS_QWS // Almost cross-platform :-) + void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect()); + inline QPoint mapToWS(const QPoint &p) const + { return p - data.wrect.topLeft(); } + + inline QPoint mapFromWS(const QPoint &p) const + { return p + data.wrect.topLeft(); } + + inline QRect mapToWS(const QRect &r) const + { QRect rr(r); rr.translate(-data.wrect.topLeft()); return rr; } + + inline QRect mapFromWS(const QRect &r) const + { QRect rr(r); rr.translate(data.wrect.topLeft()); return rr; } +#endif + + // Variables. + // Regular pointers (keep them together to avoid gaps on 64 bit architectures). QWExtra *extra; QWidget *focus_next; QWidget *focus_prev; QWidget *focus_child; -#ifndef QT_NO_ACTION - QList actions; -#endif QLayout *layout; + QRegion *needsFlush; + QPaintDevice *redirectDev; QWidgetItemV2 *widgetItem; -#if !defined(QT_NO_IM) - QPointer ic; -#endif + QPaintEngine *extraPaintEngine; + mutable const QMetaObject *polished; // All widgets are initially added into the uncreatedWidgets set. Once // they receive a window id they are removed and added to the mapper static QWidgetMapper *mapper; static QWidgetSet *uncreatedWidgets; +#if !defined(QT_NO_IM) + QPointer ic; +#endif +#ifdef QT_KEYPAD_NAVIGATION + static QPointer editingWidget; +#endif - short leftmargin, topmargin, rightmargin, bottommargin; - - signed char leftLayoutItemMargin; - signed char topLayoutItemMargin; - signed char rightLayoutItemMargin; - signed char bottomLayoutItemMargin; - - // ### TODO: reorganize private/extra/topextra to save memory - QPointer compositeChildGrab; + // Implicit pointers (shared_null/shared_empty). + QRegion opaqueChildren; + QRegion dirty; #ifndef QT_NO_TOOLTIP QString toolTip; #endif @@ -519,14 +494,37 @@ public: #ifndef QT_NO_WHATSTHIS QString whatsThis; #endif - QString accessibleName, accessibleDescription; +#ifndef QT_NO_ACCESSIBILITY + QString accessibleName; + QString accessibleDescription; +#endif + + // Other variables. + uint inheritedFontResolveMask; + uint inheritedPaletteResolveMask; + short leftmargin; + short topmargin; + short rightmargin; + short bottommargin; + signed char leftLayoutItemMargin; + signed char topLayoutItemMargin; + signed char rightLayoutItemMargin; + signed char bottomLayoutItemMargin; + static int instanceCounter; // Current number of widget instances + static int maxInstances; // Maximum number of widget instances + Qt::HANDLE hd; + QWidgetData data; + QSizePolicy size_policy; + QLocale locale; + QPoint redirectOffset; +#ifndef QT_NO_ACTION + QList actions; +#endif + // Bit fields. + uint high_attributes[3]; // the low ones are in QWidget::widget_attributes QPalette::ColorRole fg_role : 8; QPalette::ColorRole bg_role : 8; - uint high_attributes[3]; // the low ones are in QWidget::widget_attributes - Qt::HANDLE hd; - QRegion dirty; - QRegion *needsFlush; uint dirtyOpaqueChildren : 1; uint isOpaque : 1; uint inDirtyList : 1; @@ -534,35 +532,39 @@ public: uint isMoved : 1; uint usesDoubleBufferedGLContext : 1; -#ifdef Q_WS_WIN - uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine() -#endif - - uint inheritedFontResolveMask; - uint inheritedPaletteResolveMask; -#if defined(Q_WS_X11) + // *************************** Platform specific ************************************ +#if defined(Q_WS_X11) // <----------------------------------------------------------- X11 QX11Info xinfo; Qt::HANDLE picture; + static QWidget *mouseGrabber; + static QWidget *keyboardGrabber; + + void setWindowRole(); + void sendStartupMessage(const char *message) const; + void setNetWmWindowTypes(); + void x11UpdateIsOpaque(); +#elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN + uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine() + + bool shouldShowMaximizeButton(); + void winUpdateIsOpaque(); + void reparentChildren(); +#ifndef QT_NO_DRAGANDDROP + QOleDropTarget *registerOleDnd(QWidget *widget); + void unregisterOleDnd(QWidget *widget, QOleDropTarget *target); #endif -#if defined(Q_WS_MAC) + void grabMouseWhileInWindow(); +#elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC + // This is new stuff + uint needWindowChange : 1; + uint isGLWidget : 1; + enum PaintChildrenOPs { PC_None = 0x00, PC_Now = 0x01, PC_NoPaint = 0x04, PC_Later = 0x10 }; - EventHandlerRef window_event; - bool qt_mac_dnd_event(uint, DragRef); - void toggleDrawers(bool); - //mac event functions - static bool qt_create_root_win(); - static void qt_clean_root_win(); - static bool qt_recreate_root_win(); - static bool qt_mac_update_sizer(QWidget *, int up = 0); - static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *); - static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *); - static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool); - static bool qt_widget_shape(QWidget *, short, HIMutableShapeRef, bool); // Each wiget keeps a list of all its child and grandchild OpenGL widgets. // This list is used to update the gl context whenever a parent and a granparent @@ -575,95 +577,73 @@ public: QWidget * widget; QWidget * lastUpdateWidget; }; - QList glWidgets; // dirtyOnWidget contains the areas in the widget that needs to be repained, // in the same way as dirtyOnScreen does for the window. Areas are added in // dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use // this information repaint invalid areas when widgets are scrolled. QRegion dirtyOnWidget; + EventHandlerRef window_event; + QList glWidgets; //these are here just for code compat (HIViews) Qt::HANDLE qd_hd; - // This is new stuff - uint needWindowChange : 1; - uint isGLWidget : 1; -#endif - -#if defined(Q_WS_X11) || defined (Q_WS_WIN) || defined(Q_WS_MAC) -#ifdef Q_WS_MAC - void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect()); + void macUpdateSizeAttribute(); + void macUpdateHideOnSuspend(); + void macUpdateOpaqueSizeGrip(); + void macUpdateIgnoreMouseEvents(); + void macUpdateMetalAttribute(); + void macUpdateIsOpaque(); + void setEnabled_helper_sys(bool enable); + bool isRealWindow() const; + void adjustWithinMaxAndMinSize(int &w, int &h); + void applyMaxAndMinSizeOnWindow(); + void update_sys(const QRect &rect); + void update_sys(const QRegion &rgn); + void setGeometry_sys_helper(int, int, int, int, bool); + void setWindowModified_sys(bool b); + void updateMaximizeButton_sys(); + void setWindowFilePath_sys(const QString &filePath); + void createWindow_sys(); + void recreateMacWindow(); +#ifndef QT_MAC_USE_COCOA + void initWindowPtr(); + void finishCreateWindow_sys_Carbon(OSWindowRef windowRef); #else - void setWSGeometry(bool dontShow=false); + void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef); + void syncCocoaMask(); + void finishCocoaMaskSetup(); #endif + void determineWindowClass(); + void transferChildren(); + bool qt_mac_dnd_event(uint, DragRef); + void toggleDrawers(bool); + //mac event functions + static bool qt_create_root_win(); + static void qt_clean_root_win(); + static bool qt_recreate_root_win(); + static bool qt_mac_update_sizer(QWidget *, int up = 0); + static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *); + static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *); + static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool); + static bool qt_widget_shape(QWidget *, short, HIMutableShapeRef, bool); +#elif defined(Q_WS_QWS) // <--------------------------------------------------------- QWS + void setMaxWindowState_helper(); + void setFullScreenSize_helper(); + void moveSurface(QWindowSurface *surface, const QPoint &offset); + QRegion localRequestedRegion() const; + QRegion localAllocatedRegion() const; + void blitToScreen(const QRegion &globalrgn); - inline QPoint mapToWS(const QPoint &p) const - { return p - data.wrect.topLeft(); } - - inline QPoint mapFromWS(const QPoint &p) const - { return p + data.wrect.topLeft(); } - - inline QRect mapToWS(const QRect &r) const - { QRect rr(r); rr.translate(-data.wrect.topLeft()); return rr; } - - inline QRect mapFromWS(const QRect &r) const - { QRect rr(r); rr.translate(data.wrect.topLeft()); return rr; } + friend class QWSManager; + friend class QWSManagerPrivate; + friend class QDecoration; +#ifndef QT_NO_CURSOR + void updateCursor() const; #endif - - QPaintEngine *extraPaintEngine; - - mutable const QMetaObject *polished; - - void setModal_sys(); - QSizePolicy size_policy; - QLocale locale; - -#ifdef Q_WS_X11 - static QWidget *mouseGrabber; - static QWidget *keyboardGrabber; + QScreen* getScreen() const; #endif - QPaintDevice *redirectDev; - QPoint redirectOffset; - - inline void setRedirected(QPaintDevice *replacement, const QPoint &offset) - { - Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent)); - redirectDev = replacement; - redirectOffset = offset; - } - - inline QPaintDevice *redirected(QPoint *offset) const - { - if (offset) - *offset = redirectDev ? redirectOffset : QPoint(); - return redirectDev; - } - - inline void restoreRedirected() - { redirectDev = 0; } - - inline void enforceNativeChildren() - { - if (!extra) - createExtra(); - - if (extra->nativeChildrenForced) - return; - extra->nativeChildrenForced = 1; - - for (int i = 0; i < children.size(); ++i) { - if (QWidget *child = qobject_cast(children.at(i))) - child->setAttribute(Qt::WA_NativeWindow); - } - } - - inline bool nativeChildrenForced() const - { - return extra ? extra->nativeChildrenForced : false; - } - - QSize adjustedSize() const; }; inline QWExtra *QWidgetPrivate::extraData() const diff --git a/src/gui/kernel/qwidget_qws.cpp b/src/gui/kernel/qwidget_qws.cpp index 1445f57..096116f 100644 --- a/src/gui/kernel/qwidget_qws.cpp +++ b/src/gui/kernel/qwidget_qws.cpp @@ -1037,6 +1037,9 @@ void QWidgetPrivate::deleteSysExtra() void QWidgetPrivate::createTLSysExtra() { +#ifndef QT_NO_QWS_MANAGER + extra->topextra->qwsManager = 0; +#endif } void QWidgetPrivate::deleteTLSysExtra() diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp index cfdabaf..0f341fd 100644 --- a/src/gui/kernel/qwidget_win.cpp +++ b/src/gui/kernel/qwidget_win.cpp @@ -1025,13 +1025,13 @@ void QWidget::setWindowState(Qt::WindowStates newstate) if (newstate & Qt::WindowFullScreen) { if (d->topData()->normalGeometry.width() < 0 && !(oldstate & Qt::WindowMaximized)) d->topData()->normalGeometry = geometry(); - d->topData()->savedFlags = GetWindowLongA(internalWinId(), GWL_STYLE); + d->topData()->savedFlags = Qt::WindowFlags(GetWindowLongA(internalWinId(), GWL_STYLE)); #ifndef Q_FLATTEN_EXPOSE UINT style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP; #else UINT style = WS_POPUP; #endif - if (d->topData()->savedFlags & WS_SYSMENU) + if (ulong(d->topData()->savedFlags) & WS_SYSMENU) style |= WS_SYSMENU; if (isVisible()) style |= WS_VISIBLE; @@ -1234,7 +1234,7 @@ void QWidgetPrivate::stackUnder_sys(QWidget* w) (In all comments below: s/X/Windows/g) */ -void QWidgetPrivate::setWSGeometry(bool dontShow) +void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &) { Q_Q(QWidget); Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); @@ -1704,7 +1704,6 @@ int QWidget::metric(PaintDeviceMetric m) const return val; } -#ifndef Q_WS_WINCE void QWidgetPrivate::createSysExtra() { #ifndef QT_NO_DRAGANDDROP @@ -1712,6 +1711,7 @@ void QWidgetPrivate::createSysExtra() #endif } +#ifndef Q_WS_WINCE void QWidgetPrivate::deleteSysExtra() { } @@ -1719,8 +1719,9 @@ void QWidgetPrivate::deleteSysExtra() void QWidgetPrivate::createTLSysExtra() { - extra->topextra->winIconSmall = 0; + extra->topextra->savedFlags = 0; extra->topextra->winIconBig = 0; + extra->topextra->winIconSmall = 0; } void QWidgetPrivate::deleteTLSysExtra() diff --git a/src/gui/kernel/qwidget_wince.cpp b/src/gui/kernel/qwidget_wince.cpp index cca928e..0ed40fa 100644 --- a/src/gui/kernel/qwidget_wince.cpp +++ b/src/gui/kernel/qwidget_wince.cpp @@ -598,13 +598,6 @@ void QWidget::setWindowState(Qt::WindowStates newstate) QApplication::sendEvent(this, &e); } - -void QWidgetPrivate::createSysExtra() { -#ifndef QT_NO_DRAGANDDROP - extra->dropTarget = 0; -#endif -} - void QWidgetPrivate::deleteSysExtra() { Q_Q(QWidget); diff --git a/src/gui/kernel/qwidget_x11.cpp b/src/gui/kernel/qwidget_x11.cpp index 6202b35..906500e 100644 --- a/src/gui/kernel/qwidget_x11.cpp +++ b/src/gui/kernel/qwidget_x11.cpp @@ -2152,7 +2152,7 @@ static void do_size_hints(QWidget* widget, QWExtra *x) parentWRect is the geometry of the parent's X rect, measured in parent's coord sys */ -void QWidgetPrivate::setWSGeometry(bool dontShow) +void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &) { Q_Q(QWidget); Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); @@ -2610,8 +2610,8 @@ int QWidget::metric(PaintDeviceMetric m) const void QWidgetPrivate::createSysExtra() { - extra->xDndProxy = 0; extra->compress_events = true; + extra->xDndProxy = 0; } void QWidgetPrivate::deleteSysExtra() @@ -2620,8 +2620,11 @@ void QWidgetPrivate::deleteSysExtra() void QWidgetPrivate::createTLSysExtra() { + extra->topextra->spont_unmapped = 0; + extra->topextra->dnd = 0; extra->topextra->validWMState = 0; extra->topextra->waitingForMapNotify = 0; + extra->topextra->parentWinId = 0; extra->topextra->userTimeWindow = 0; } -- cgit v0.12 From 8a4fbf2edfd88128aeead769adb9842338e09623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Tue, 12 May 2009 17:46:52 +0200 Subject: Cleanup private QWidget functions. I actually found a few functions that were not even implemented, only declared. Those should obviously not be in the header file. I've also removed a few functions not in use / not belonging to QWidgetPrivate. Reviewed-by: Olivier --- src/gui/kernel/qlayoutitem.cpp | 6 ++-- src/gui/kernel/qwidget.cpp | 65 ------------------------------------------ src/gui/kernel/qwidget_mac.mm | 18 ------------ src/gui/kernel/qwidget_p.h | 16 +---------- src/gui/kernel/qwidget_qws.cpp | 14 --------- src/gui/kernel/qwidget_x11.cpp | 38 ++++++++++++++++++++++++ 6 files changed, 43 insertions(+), 114 deletions(-) diff --git a/src/gui/kernel/qlayoutitem.cpp b/src/gui/kernel/qlayoutitem.cpp index 0fd73b8..c70ab2d 100644 --- a/src/gui/kernel/qlayoutitem.cpp +++ b/src/gui/kernel/qlayoutitem.cpp @@ -54,7 +54,8 @@ QT_BEGIN_NAMESPACE inline static QRect fromLayoutItemRect(QWidgetPrivate *priv, const QRect &rect) { - return priv->fromOrToLayoutItemRect(rect, -1); + return rect.adjusted(priv->leftLayoutItemMargin, priv->topLayoutItemMargin, + -priv->rightLayoutItemMargin, -priv->bottomLayoutItemMargin); } inline static QSize fromLayoutItemSize(QWidgetPrivate *priv, const QSize &size) @@ -64,7 +65,8 @@ inline static QSize fromLayoutItemSize(QWidgetPrivate *priv, const QSize &size) inline static QRect toLayoutItemRect(QWidgetPrivate *priv, const QRect &rect) { - return priv->fromOrToLayoutItemRect(rect, +1); + return rect.adjusted(-priv->leftLayoutItemMargin, -priv->topLayoutItemMargin, + priv->rightLayoutItemMargin, priv->bottomLayoutItemMargin); } inline static QSize toLayoutItemSize(QWidgetPrivate *priv, const QSize &size) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index a8eae9b..ab529fe 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -1516,45 +1516,6 @@ void QWidgetPrivate::deleteExtra() } /* - Returns true if the background is inherited; otherwise returns - false. - - Mainly used in the paintOnScreen case. -*/ - -bool QWidgetPrivate::isBackgroundInherited() const -{ - Q_Q(const QWidget); - - // windows do not inherit their background - if (q->isWindow() || q->windowType() == Qt::SubWindow) - return false; - - if (q->testAttribute(Qt::WA_NoSystemBackground) || q->testAttribute(Qt::WA_OpaquePaintEvent)) - return false; - - const QPalette &pal = q->palette(); - QPalette::ColorRole bg = q->backgroundRole(); - QBrush brush = pal.brush(bg); - - // non opaque brushes leaves us no choice, we must inherit - if (!q->autoFillBackground() || !brush.isOpaque()) - return true; - - if (brush.style() == Qt::SolidPattern) { - // the background is just a solid color. If there is no - // propagated contents, then we claim as performance - // optimization that it was not inheritet. This is the normal - // case in standard Windows or Motif style. - const QWidget *w = q->parentWidget(); - if (!w->d_func()->isBackgroundInherited()) - return false; - } - - return true; -} - -/* Returns true if there are widgets above this which overlap with \a rect, which is in parent's coordinate system (same as crect). */ @@ -1900,24 +1861,6 @@ void QWidgetPrivate::clipToEffectiveMask(QRegion ®ion) const } } -bool QWidgetPrivate::hasBackground() const -{ - Q_Q(const QWidget); - if (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_PaintOnScreen)) - return true; - if (q->testAttribute(Qt::WA_PaintOnScreen)) - return true; - if (!q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) { - const QPalette &pal = q->palette(); - QPalette::ColorRole bg = q->backgroundRole(); - QBrush bgBrush = pal.brush(bg); - return (bgBrush.style() != Qt::NoBrush && - ((q->isWindow() || q->windowType() == Qt::SubWindow) - || (QPalette::ColorRole(bg_role) != QPalette::NoRole || (pal.resolve() & (1<window(); - QBrush bgBrush = win->palette().brush(win->backgroundRole()); - bool opaque = bgBrush.style() == Qt::NoBrush || bgBrush.isOpaque(); - QWidget::qwsDisplay()->repaintRegion(win->data->winid, win->windowFlags(), opaque, globalrgn); -} - void QWidgetPrivate::show_sys() { Q_Q(QWidget); diff --git a/src/gui/kernel/qwidget_x11.cpp b/src/gui/kernel/qwidget_x11.cpp index 906500e..b35740a 100644 --- a/src/gui/kernel/qwidget_x11.cpp +++ b/src/gui/kernel/qwidget_x11.cpp @@ -906,6 +906,44 @@ void QWidgetPrivate::x11UpdateIsOpaque() #endif } +/* + Returns true if the background is inherited; otherwise returns + false. + + Mainly used in the paintOnScreen case. +*/ +bool QWidgetPrivate::isBackgroundInherited() const +{ + Q_Q(const QWidget); + + // windows do not inherit their background + if (q->isWindow() || q->windowType() == Qt::SubWindow) + return false; + + if (q->testAttribute(Qt::WA_NoSystemBackground) || q->testAttribute(Qt::WA_OpaquePaintEvent)) + return false; + + const QPalette &pal = q->palette(); + QPalette::ColorRole bg = q->backgroundRole(); + QBrush brush = pal.brush(bg); + + // non opaque brushes leaves us no choice, we must inherit + if (!q->autoFillBackground() || !brush.isOpaque()) + return true; + + if (brush.style() == Qt::SolidPattern) { + // the background is just a solid color. If there is no + // propagated contents, then we claim as performance + // optimization that it was not inheritet. This is the normal + // case in standard Windows or Motif style. + const QWidget *w = q->parentWidget(); + if (!w->d_func()->isBackgroundInherited()) + return false; + } + + return true; +} + void QWidget::destroy(bool destroyWindow, bool destroySubWindows) { Q_D(QWidget); -- cgit v0.12 From d3f8c08548cf7a454d3fd31c3313031d3e0bb223 Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Tue, 12 May 2009 16:31:32 -0700 Subject: Fixed wrong function name in warning Reviewed-by: Donald --- src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index 65fddbf..98e32ed 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -294,14 +294,14 @@ IDirectFBSurface *QDirectFBScreen::copyToDFBSurface(const QImage &img, IDirectFBSurface *dfbSurface = createDFBSurface(image.size(), pixmapFormat, options); if (!dfbSurface) { - qWarning("QDirectFBPixmapData::fromImage() Couldn't create surface"); + qWarning("QDirectFBScreen::copyToDFBSurface() Couldn't create surface"); return 0; } #ifndef QT_NO_DIRECTFB_PREALLOCATED IDirectFBSurface *imgSurface = createDFBSurface(image, DontTrackSurface); if (!imgSurface) { - qWarning("QDirectFBPixmapData::fromImage()"); + qWarning("QDirectFBScreen::copyToDFBSurface()"); QDirectFBScreen::releaseDFBSurface(dfbSurface); return 0; } @@ -316,7 +316,7 @@ IDirectFBSurface *QDirectFBScreen::copyToDFBSurface(const QImage &img, dfbSurface->SetBlittingFlags(dfbSurface, flags); DFBResult result = dfbSurface->Blit(dfbSurface, imgSurface, 0, 0, 0); if (result != DFB_OK) - DirectFBError("QDirectFBPixmapData::fromImage()", result); + DirectFBError("QDirectFBScreen::copyToDFBSurface()", result); dfbSurface->ReleaseSource(dfbSurface); imgSurface->Release(imgSurface); #else // QT_NO_DIRECTFB_PREALLOCATED -- cgit v0.12 From dde94b1737e9860838c87d3f432cf76de3157ad7 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Wed, 13 May 2009 10:33:59 +1000 Subject: Fixed compile on Windows in debug-only mode. A Qt project can't unconditionally do `CONFIG+=release' or `CONFIG+=debug' since the release and debug libraries are named differently on Windows. In this case, CONFIG+=release meant this project was looking for QtSql.lib, but when Qt is configured with `-debug', only QtSqld.lib exists. Reviewed-by: Rhys Weatherley --- tools/qtestlib/chart/chart.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/qtestlib/chart/chart.pro b/tools/qtestlib/chart/chart.pro index 6f6e6d5..7328e5d 100644 --- a/tools/qtestlib/chart/chart.pro +++ b/tools/qtestlib/chart/chart.pro @@ -4,7 +4,7 @@ SOURCES += main.cpp RESOURCES = $$PWD/chart.qrc QT += sql xml -CONFIG += console release +CONFIG += console CONFIG -= app_bundle -- cgit v0.12 From dcf1867f5715991e233120122f6252b18ccd26e3 Mon Sep 17 00:00:00 2001 From: Bill King Date: Wed, 13 May 2009 14:06:47 +1000 Subject: Fixes a segfault from out of order cleanup of mysql resources. If a QSqlQuery survived the lifetime of removal of a mysql db connection (that failed), the cleanup code would cause a segfault because it was using an out of date pointer that was pointing at memory that'd been freed by the removeDatabase() call. Revby: Justin McPherson Task-number: 205701 --- src/sql/drivers/mysql/qsql_mysql.cpp | 123 +++++++++++++++++++-------------- tests/auto/qsqlquery/tst_qsqlquery.cpp | 22 +++++- 2 files changed, 93 insertions(+), 52 deletions(-) diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp index 1f54db7..fbefa0c 100644 --- a/src/sql/drivers/mysql/qsql_mysql.cpp +++ b/src/sql/drivers/mysql/qsql_mysql.cpp @@ -163,18 +163,21 @@ static inline QVariant qDateTimeFromString(QString &val) #endif } -class QMYSQLResultPrivate +class QMYSQLResultPrivate : public QObject { + Q_OBJECT public: - QMYSQLResultPrivate(QMYSQLDriverPrivate* dp) : d(dp), result(0), + QMYSQLResultPrivate(const QMYSQLDriver* dp) : driver(dp), result(0), rowsAffected(0), hasBlobs(false) #if MYSQL_VERSION_ID >= 40108 , stmt(0), meta(0), inBinds(0), outBinds(0) #endif , precisionPolicy(QSql::HighPrecision) - {} + { + connect(dp, SIGNAL(destroyed()), this, SLOT(driverDestroyed())); + } - QMYSQLDriverPrivate* d; + const QMYSQLDriver* driver; MYSQL_RES *result; MYSQL_ROW row; @@ -207,6 +210,8 @@ public: MYSQL_BIND *outBinds; #endif QSql::NumericalPrecisionPolicy precisionPolicy; +private Q_SLOTS: + void driverDestroyed() { driver = NULL; } }; #ifndef QT_NO_TEXTCODEC @@ -379,7 +384,7 @@ bool QMYSQLResultPrivate::bindInValues() QMYSQLResult::QMYSQLResult(const QMYSQLDriver* db) : QSqlResult(db) { - d = new QMYSQLResultPrivate(db->d); + d = new QMYSQLResultPrivate(db); } QMYSQLResult::~QMYSQLResult() @@ -391,7 +396,7 @@ QMYSQLResult::~QMYSQLResult() QVariant QMYSQLResult::handle() const { #if MYSQL_VERSION_ID >= 40108 - if(d->d->preparedQuerys) + if(d->driver && d->driver->d->preparedQuerys) return d->meta ? qVariantFromValue(d->meta) : qVariantFromValue(d->stmt); else #endif @@ -406,8 +411,8 @@ void QMYSQLResult::cleanup() // must iterate trough leftover result sets from multi-selects or stored procedures // if this isn't done subsequent queries will fail with "Commands out of sync" #if MYSQL_VERSION_ID >= 40100 - while (d->d->mysql && mysql_next_result(d->d->mysql) == 0) { - MYSQL_RES *res = mysql_store_result(d->d->mysql); + while (d->driver && d->driver->d->mysql && mysql_next_result(d->driver->d->mysql) == 0) { + MYSQL_RES *res = mysql_store_result(d->driver->d->mysql); if (res) mysql_free_result(res); } @@ -447,11 +452,14 @@ void QMYSQLResult::cleanup() setAt(-1); setActive(false); - d->d->preparedQuerys = d->d->preparedQuerysEnabled; + if(d->driver) + d->driver->d->preparedQuerys = d->driver->d->preparedQuerysEnabled; } bool QMYSQLResult::fetch(int i) { + if(!d->driver) + return false; if (isForwardOnly()) { // fake a forward seek if (at() < i) { int x = i - at(); @@ -463,7 +471,7 @@ bool QMYSQLResult::fetch(int i) } if (at() == i) return true; - if (d->d->preparedQuerys) { + if (d->driver->d->preparedQuerys) { #if MYSQL_VERSION_ID >= 40108 mysql_stmt_data_seek(d->stmt, i); @@ -494,7 +502,9 @@ bool QMYSQLResult::fetch(int i) bool QMYSQLResult::fetchNext() { - if (d->d->preparedQuerys) { + if(!d->driver) + return false; + if (d->driver->d->preparedQuerys) { #if MYSQL_VERSION_ID >= 40108 if (mysql_stmt_fetch(d->stmt)) return false; @@ -512,6 +522,8 @@ bool QMYSQLResult::fetchNext() bool QMYSQLResult::fetchLast() { + if(!d->driver) + return false; if (isForwardOnly()) { // fake this since MySQL can't seek on forward only queries bool success = fetchNext(); // did we move at all? while (fetchNext()) {}; @@ -519,7 +531,7 @@ bool QMYSQLResult::fetchLast() } my_ulonglong numRows; - if (d->d->preparedQuerys) { + if (d->driver->d->preparedQuerys) { #if MYSQL_VERSION_ID >= 40108 numRows = mysql_stmt_num_rows(d->stmt); #else @@ -553,15 +565,18 @@ QVariant QMYSQLResult::data(int field) return QVariant(); } + if (!d->driver) + return QVariant(); + int fieldLength = 0; const QMYSQLResultPrivate::QMyField &f = d->fields.at(field); QString val; - if (d->d->preparedQuerys) { + if (d->driver->d->preparedQuerys) { if (f.nullIndicator) return QVariant(f.type); if (f.type != QVariant::ByteArray) - val = toUnicode(d->d->tc, f.outField, f.bufLength); + val = toUnicode(d->driver->d->tc, f.outField, f.bufLength); } else { if (d->row[field] == NULL) { // NULL value @@ -569,7 +584,7 @@ QVariant QMYSQLResult::data(int field) } fieldLength = mysql_fetch_lengths(d->result)[field]; if (f.type != QVariant::ByteArray) - val = toUnicode(d->d->tc, d->row[field], fieldLength); + val = toUnicode(d->driver->d->tc, d->row[field], fieldLength); } switch(f.type) { @@ -614,7 +629,7 @@ QVariant QMYSQLResult::data(int field) case QVariant::ByteArray: { QByteArray ba; - if (d->d->preparedQuerys) { + if (d->driver->d->preparedQuerys) { ba = QByteArray(f.outField, f.bufLength); } else { ba = QByteArray(d->row[field], fieldLength); @@ -631,7 +646,7 @@ QVariant QMYSQLResult::data(int field) bool QMYSQLResult::isNull(int field) { - if (d->d->preparedQuerys) + if (d->driver->d->preparedQuerys) return d->fields.at(field).nullIndicator; else return d->row[field] == NULL; @@ -639,31 +654,31 @@ bool QMYSQLResult::isNull(int field) bool QMYSQLResult::reset (const QString& query) { - if (!driver() || !driver()->isOpen() || driver()->isOpenError()) + if (!driver() || !driver()->isOpen() || driver()->isOpenError() || !d->driver) return false; - if(d->d->preparedQuerysEnabled && prepare(query)) { - d->d->preparedQuerys = true; + if(d->driver->d->preparedQuerysEnabled && prepare(query)) { + d->driver->d->preparedQuerys = true; return exec(); } - d->d->preparedQuerys = false; + d->driver->d->preparedQuerys = false; - const QByteArray encQuery(fromUnicode(d->d->tc, query)); - if (mysql_real_query(d->d->mysql, encQuery.data(), encQuery.length())) { + const QByteArray encQuery(fromUnicode(d->driver->d->tc, query)); + if (mysql_real_query(d->driver->d->mysql, encQuery.data(), encQuery.length())) { setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to execute query"), - QSqlError::StatementError, d->d)); + QSqlError::StatementError, d->driver->d)); return false; } - d->result = mysql_store_result(d->d->mysql); - if (!d->result && mysql_field_count(d->d->mysql) > 0) { + d->result = mysql_store_result(d->driver->d->mysql); + if (!d->result && mysql_field_count(d->driver->d->mysql) > 0) { setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to store result"), - QSqlError::StatementError, d->d)); + QSqlError::StatementError, d->driver->d)); return false; } - int numFields = mysql_field_count(d->d->mysql); + int numFields = mysql_field_count(d->driver->d->mysql); setSelect(numFields != 0); d->fields.resize(numFields); - d->rowsAffected = mysql_affected_rows(d->d->mysql); + d->rowsAffected = mysql_affected_rows(d->driver->d->mysql); if (isSelect()) { for(int i = 0; i < numFields; i++) { MYSQL_FIELD* field = mysql_fetch_field_direct(d->result, i); @@ -677,8 +692,8 @@ bool QMYSQLResult::reset (const QString& query) int QMYSQLResult::size() { - if (isSelect()) - if (d->d->preparedQuerys) + if (d->driver && isSelect()) + if (d->driver->d->preparedQuerys) #if MYSQL_VERSION_ID >= 40108 return mysql_stmt_num_rows(d->stmt); #else @@ -697,17 +712,17 @@ int QMYSQLResult::numRowsAffected() QVariant QMYSQLResult::lastInsertId() const { - if (!isActive()) + if (!isActive() || !d->driver) return QVariant(); - if (d->d->preparedQuerys) { + if (d->driver->d->preparedQuerys) { #if MYSQL_VERSION_ID >= 40108 quint64 id = mysql_stmt_insert_id(d->stmt); if (id) return QVariant(id); #endif } else { - quint64 id = mysql_insert_id(d->d->mysql); + quint64 id = mysql_insert_id(d->driver->d->mysql); if (id) return QVariant(id); } @@ -718,20 +733,20 @@ QSqlRecord QMYSQLResult::record() const { QSqlRecord info; MYSQL_RES *res; - if (!isActive() || !isSelect()) + if (!isActive() || !isSelect() || !d->driver) return info; #if MYSQL_VERSION_ID >= 40108 - res = d->d->preparedQuerys ? d->meta : d->result; + res = d->driver->d->preparedQuerys ? d->meta : d->result; #else res = d->result; #endif - if (!mysql_errno(d->d->mysql)) { + if (!mysql_errno(d->driver->d->mysql)) { mysql_field_seek(res, 0); MYSQL_FIELD* field = mysql_fetch_field(res); while(field) { - info.append(qToField(field, d->d->tc)); + info.append(qToField(field, d->driver->d->tc)); field = mysql_fetch_field(res); } } @@ -741,6 +756,8 @@ QSqlRecord QMYSQLResult::record() const bool QMYSQLResult::nextResult() { + if(!d->driver) + return false; #if MYSQL_VERSION_ID >= 40100 setAt(-1); setActive(false); @@ -754,26 +771,26 @@ bool QMYSQLResult::nextResult() delete[] d->fields[i].outField; d->fields.clear(); - int status = mysql_next_result(d->d->mysql); + int status = mysql_next_result(d->driver->d->mysql); if (status > 0) { setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to execute next query"), - QSqlError::StatementError, d->d)); + QSqlError::StatementError, d->driver->d)); return false; } else if (status == -1) { return false; // No more result sets } - d->result = mysql_store_result(d->d->mysql); - int numFields = mysql_field_count(d->d->mysql); + d->result = mysql_store_result(d->driver->d->mysql); + int numFields = mysql_field_count(d->driver->d->mysql); if (!d->result && numFields > 0) { setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to store next result"), - QSqlError::StatementError, d->d)); + QSqlError::StatementError, d->driver->d)); return false; } setSelect(numFields > 0); d->fields.resize(numFields); - d->rowsAffected = mysql_affected_rows(d->d->mysql); + d->rowsAffected = mysql_affected_rows(d->driver->d->mysql); if (isSelect()) { for (int i = 0; i < numFields; i++) { @@ -833,9 +850,11 @@ static MYSQL_TIME *toMySqlDate(QDate date, QTime time, QVariant::Type type) bool QMYSQLResult::prepare(const QString& query) { + if(!d->driver) + return false; #if MYSQL_VERSION_ID >= 40108 cleanup(); - if (!d->d->preparedQuerys) + if (!d->driver->d->preparedQuerys) return QSqlResult::prepare(query); int r; @@ -844,14 +863,14 @@ bool QMYSQLResult::prepare(const QString& query) return false; if (!d->stmt) - d->stmt = mysql_stmt_init(d->d->mysql); + d->stmt = mysql_stmt_init(d->driver->d->mysql); if (!d->stmt) { setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to prepare statement"), - QSqlError::StatementError, d->d)); + QSqlError::StatementError, d->driver->d)); return false; } - const QByteArray encQuery(fromUnicode(d->d->tc, query)); + const QByteArray encQuery(fromUnicode(d->driver->d->tc, query)); r = mysql_stmt_prepare(d->stmt, encQuery.constData(), encQuery.length()); if (r != 0) { setLastError(qMakeStmtError(QCoreApplication::translate("QMYSQLResult", @@ -873,7 +892,9 @@ bool QMYSQLResult::prepare(const QString& query) bool QMYSQLResult::exec() { - if (!d->d->preparedQuerys) + if (!d->driver) + return false; + if (!d->driver->d->preparedQuerys) return QSqlResult::exec(); if (!d->stmt) return false; @@ -963,7 +984,7 @@ bool QMYSQLResult::exec() break; case QVariant::String: default: { - QByteArray ba = fromUnicode(d->d->tc, val.toString()); + QByteArray ba = fromUnicode(d->driver->d->tc, val.toString()); stringVector.append(ba); currBind->buffer_type = MYSQL_TYPE_STRING; currBind->buffer = const_cast(ba.constData()); @@ -1459,3 +1480,5 @@ bool QMYSQLDriver::isIdentifierEscapedImplementation(const QString &identifier, } QT_END_NAMESPACE + +#include "qsql_mysql.moc" \ No newline at end of file diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 074f16f..7f97972 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -178,9 +178,11 @@ private slots: void task_217003_data() { generic_data(); } void task_217003(); #endif - void task_250026_data() { generic_data("QODBC"); } void task_250026(); + void task_205701_data() { generic_data("QMYSQL"); } + void task_205701(); + private: @@ -297,7 +299,7 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) #ifdef NOT_READY_YET tablenames << qTableName( "Planet" ); #endif - tablenames << qTableName( "task_250026" ); + tablenames << qTableName( "task_250026" ); tst_Databases::safeDropTables( db, tablenames ); } @@ -2711,5 +2713,21 @@ void tst_QSqlQuery::task_250026() QCOMPARE( q.value( 0 ).toString().length(), data1026.length() ); } +void tst_QSqlQuery::task_205701() +{ + QSqlDatabase qsdb = QSqlDatabase::addDatabase("QMYSQL", "atest"); + qsdb.setHostName("test"); + qsdb.setDatabaseName("test"); + qsdb.setUserName("test"); + qsdb.setPassword("test"); + qsdb.open(); + +// { + QSqlQuery query(qsdb); +// } + QSqlDatabase::removeDatabase("atest"); +} + + QTEST_MAIN( tst_QSqlQuery ) #include "tst_qsqlquery.moc" -- cgit v0.12 From 03415f5db33ee1d8af15b924f84b547a9ed8020b Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Fri, 8 May 2009 09:09:32 +0200 Subject: fix WinCE build Reviewed-by: thartman --- src/gui/widgets/qmenu_wince.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/widgets/qmenu_wince.cpp b/src/gui/widgets/qmenu_wince.cpp index 847a623..fbe54fe 100644 --- a/src/gui/widgets/qmenu_wince.cpp +++ b/src/gui/widgets/qmenu_wince.cpp @@ -214,10 +214,12 @@ static HWND qt_wce_create_menubar(HWND parentHandle, HINSTANCE resourceHandle, i mbi.nToolBarId = toolbarID; if (ptrCreateMenuBar(&mbi)) { +#ifdef Q_WS_WINCE_WM // Tell the menu bar that we want to override hot key behaviour. LPARAM lparam = MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, SHMBOF_NODEFAULT | SHMBOF_NOTIFY); SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK, lparam); +#endif return mbi.hwndMB; } } -- cgit v0.12 From 23a76927148ef6e2bf6aed6c894e23e838f763e6 Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Wed, 13 May 2009 08:52:16 +0200 Subject: fix wince build in 4ffda2918b3f5c789ef325cdeaac72e5e7ef2c0c savedFlags has been made crossplatform by switching from ulong to Qt::WindowFlags. WinCE does not have an automatic conversion between those types, thus bails out with an error. Need to cast it to the proper type. Reviewed-by: Marius Storm-Olsen --- src/gui/kernel/qwidget_wince.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/kernel/qwidget_wince.cpp b/src/gui/kernel/qwidget_wince.cpp index 0ed40fa..435fd31 100644 --- a/src/gui/kernel/qwidget_wince.cpp +++ b/src/gui/kernel/qwidget_wince.cpp @@ -535,7 +535,7 @@ void QWidget::setWindowState(Qt::WindowStates newstate) if (newstate & Qt::WindowFullScreen) { if (d->topData()->normalGeometry.width() < 0 && !(oldstate & Qt::WindowMaximized)) d->topData()->normalGeometry = geometry(); - d->topData()->savedFlags = GetWindowLongA(internalWinId(), GWL_STYLE); + d->topData()->savedFlags = (Qt::WindowFlags) GetWindowLongA(internalWinId(), GWL_STYLE); UINT style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP; if (isVisible()) style |= WS_VISIBLE; -- cgit v0.12 From 5cbaaa1a8baf14b66efe89fe967a3e966dac659c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 13 May 2009 09:40:05 +0200 Subject: Fixed Qt 4.6 source package compilation by moving the qvfb skins. Move skins to tools/shared/deviceskin and have them included automatically by the profile. Acked-by: Jason McDonald Acked-by: Warwick Allison --- tools/designer/src/lib/sdk/abstractformeditor.cpp | 1 - tools/designer/src/lib/shared/shared.pri | 15 +-- tools/qvfb/ClamshellPhone.qrc | 5 - tools/qvfb/ClamshellPhone.skin/ClamshellPhone.skin | 30 ----- .../ClamshellPhone1-5-closed.png | Bin 68200 -> 0 bytes .../ClamshellPhone1-5-pressed.png | Bin 113907 -> 0 bytes .../qvfb/ClamshellPhone.skin/ClamshellPhone1-5.png | Bin 113450 -> 0 bytes tools/qvfb/ClamshellPhone.skin/defaultbuttons.conf | 78 ----------- .../DualScreenPhone.skin/DualScreen-pressed.png | Bin 115575 -> 0 bytes tools/qvfb/DualScreenPhone.skin/DualScreen.png | Bin 104711 -> 0 bytes .../qvfb/DualScreenPhone.skin/DualScreenPhone.skin | 29 ----- .../qvfb/DualScreenPhone.skin/defaultbuttons.conf | 78 ----------- tools/qvfb/PDAPhone.qrc | 5 - tools/qvfb/PDAPhone.skin/PDAPhone.skin | 18 --- tools/qvfb/PDAPhone.skin/defaultbuttons.conf | 36 ------ tools/qvfb/PDAPhone.skin/finger.png | Bin 40343 -> 0 bytes tools/qvfb/PDAPhone.skin/pda_down.png | Bin 52037 -> 0 bytes tools/qvfb/PDAPhone.skin/pda_up.png | Bin 100615 -> 0 bytes tools/qvfb/PortableMedia.qrc | 5 - tools/qvfb/PortableMedia.skin/PortableMedia.skin | 14 -- tools/qvfb/PortableMedia.skin/defaultbuttons.conf | 23 ---- .../PortableMedia.skin/portablemedia-pressed.png | Bin 6183 -> 0 bytes tools/qvfb/PortableMedia.skin/portablemedia.png | Bin 6182 -> 0 bytes tools/qvfb/PortableMedia.skin/portablemedia.xcf | Bin 41592 -> 0 bytes tools/qvfb/S60-QVGA-Candybar.qrc | 5 - .../S60-QVGA-Candybar-down.png | Bin 161184 -> 0 bytes .../S60-QVGA-Candybar.skin/S60-QVGA-Candybar.png | Bin 156789 -> 0 bytes .../S60-QVGA-Candybar.skin/S60-QVGA-Candybar.skin | 15 --- .../S60-QVGA-Candybar.skin/defaultbuttons.conf | 78 ----------- tools/qvfb/S60-nHD-Touchscreen.qrc | 5 - .../S60-nHD-Touchscreen-down.png | Bin 241501 -> 0 bytes .../S60-nHD-Touchscreen.png | Bin 240615 -> 0 bytes .../S60-nHD-Touchscreen.skin | 10 -- .../S60-nHD-Touchscreen.skin/defaultbuttons.conf | 53 -------- tools/qvfb/SmartPhone.qrc | 5 - tools/qvfb/SmartPhone.skin/SmartPhone-pressed.png | Bin 111515 -> 0 bytes tools/qvfb/SmartPhone.skin/SmartPhone.png | Bin 101750 -> 0 bytes tools/qvfb/SmartPhone.skin/SmartPhone.skin | 28 ---- tools/qvfb/SmartPhone.skin/defaultbuttons.conf | 78 ----------- tools/qvfb/SmartPhone2.qrc | 5 - .../qvfb/SmartPhone2.skin/SmartPhone2-pressed.png | Bin 134749 -> 0 bytes tools/qvfb/SmartPhone2.skin/SmartPhone2.png | Bin 121915 -> 0 bytes tools/qvfb/SmartPhone2.skin/SmartPhone2.skin | 25 ---- tools/qvfb/SmartPhone2.skin/defaultbuttons.conf | 52 -------- tools/qvfb/SmartPhoneWithButtons.qrc | 5 - .../SmartPhoneWithButtons-pressed.png | Bin 103838 -> 0 bytes .../SmartPhoneWithButtons.png | Bin 88470 -> 0 bytes .../SmartPhoneWithButtons.skin | 31 ----- .../SmartPhoneWithButtons.skin/defaultbuttons.conf | 103 --------------- tools/qvfb/TouchscreenPhone.qrc | 5 - .../TouchscreenPhone-pressed.png | Bin 88599 -> 0 bytes .../TouchscreenPhone.skin/TouchscreenPhone.png | Bin 61809 -> 0 bytes .../TouchscreenPhone.skin/TouchscreenPhone.skin | 16 --- .../qvfb/TouchscreenPhone.skin/defaultbuttons.conf | 45 ------- tools/qvfb/Trolltech-Keypad.qrc | 5 - .../Trolltech-Keypad-closed.png | Bin 69447 -> 0 bytes .../Trolltech-Keypad-down.png | Bin 242107 -> 0 bytes .../Trolltech-Keypad.skin/Trolltech-Keypad.png | Bin 230638 -> 0 bytes .../Trolltech-Keypad.skin/Trolltech-Keypad.skin | 35 ----- .../qvfb/Trolltech-Keypad.skin/defaultbuttons.conf | 142 --------------------- tools/qvfb/Trolltech-Touchscreen.qrc | 5 - .../Trolltech-Touchscreen-down.png | Bin 133117 -> 0 bytes .../Trolltech-Touchscreen.png | Bin 133180 -> 0 bytes .../Trolltech-Touchscreen.skin | 17 --- .../Trolltech-Touchscreen.skin/defaultbuttons.conf | 53 -------- tools/qvfb/pda.qrc | 5 - tools/qvfb/pda.skin | 14 -- tools/qvfb/pda_down.png | Bin 102655 -> 0 bytes tools/qvfb/pda_up.png | Bin 100615 -> 0 bytes tools/qvfb/qvfb.pro | 13 +- tools/shared/deviceskin/deviceskin.pri | 12 ++ tools/shared/deviceskin/skins/ClamshellPhone.qrc | 5 + .../skins/ClamshellPhone.skin/ClamshellPhone.skin | 30 +++++ .../ClamshellPhone1-5-closed.png | Bin 0 -> 68200 bytes .../ClamshellPhone1-5-pressed.png | Bin 0 -> 113907 bytes .../ClamshellPhone.skin/ClamshellPhone1-5.png | Bin 0 -> 113450 bytes .../skins/ClamshellPhone.skin/defaultbuttons.conf | 78 +++++++++++ .../DualScreenPhone.skin/DualScreen-pressed.png | Bin 0 -> 115575 bytes .../skins/DualScreenPhone.skin/DualScreen.png | Bin 0 -> 104711 bytes .../DualScreenPhone.skin/DualScreenPhone.skin | 29 +++++ .../skins/DualScreenPhone.skin/defaultbuttons.conf | 78 +++++++++++ tools/shared/deviceskin/skins/PDAPhone.qrc | 5 + .../deviceskin/skins/PDAPhone.skin/PDAPhone.skin | 18 +++ .../skins/PDAPhone.skin/defaultbuttons.conf | 36 ++++++ .../deviceskin/skins/PDAPhone.skin/finger.png | Bin 0 -> 40343 bytes .../deviceskin/skins/PDAPhone.skin/pda_down.png | Bin 0 -> 52037 bytes .../deviceskin/skins/PDAPhone.skin/pda_up.png | Bin 0 -> 100615 bytes tools/shared/deviceskin/skins/PortableMedia.qrc | 5 + .../skins/PortableMedia.skin/PortableMedia.skin | 14 ++ .../skins/PortableMedia.skin/defaultbuttons.conf | 23 ++++ .../PortableMedia.skin/portablemedia-pressed.png | Bin 0 -> 6183 bytes .../skins/PortableMedia.skin/portablemedia.png | Bin 0 -> 6182 bytes .../skins/PortableMedia.skin/portablemedia.xcf | Bin 0 -> 41592 bytes .../shared/deviceskin/skins/S60-QVGA-Candybar.qrc | 5 + .../S60-QVGA-Candybar-down.png | Bin 0 -> 161184 bytes .../S60-QVGA-Candybar.skin/S60-QVGA-Candybar.png | Bin 0 -> 156789 bytes .../S60-QVGA-Candybar.skin/S60-QVGA-Candybar.skin | 15 +++ .../S60-QVGA-Candybar.skin/defaultbuttons.conf | 78 +++++++++++ .../deviceskin/skins/S60-nHD-Touchscreen.qrc | 5 + .../S60-nHD-Touchscreen-down.png | Bin 0 -> 241501 bytes .../S60-nHD-Touchscreen.png | Bin 0 -> 240615 bytes .../S60-nHD-Touchscreen.skin | 10 ++ .../S60-nHD-Touchscreen.skin/defaultbuttons.conf | 53 ++++++++ tools/shared/deviceskin/skins/SmartPhone.qrc | 5 + .../skins/SmartPhone.skin/SmartPhone-pressed.png | Bin 0 -> 111515 bytes .../skins/SmartPhone.skin/SmartPhone.png | Bin 0 -> 101750 bytes .../skins/SmartPhone.skin/SmartPhone.skin | 28 ++++ .../skins/SmartPhone.skin/defaultbuttons.conf | 78 +++++++++++ tools/shared/deviceskin/skins/SmartPhone2.qrc | 5 + .../skins/SmartPhone2.skin/SmartPhone2-pressed.png | Bin 0 -> 134749 bytes .../skins/SmartPhone2.skin/SmartPhone2.png | Bin 0 -> 121915 bytes .../skins/SmartPhone2.skin/SmartPhone2.skin | 25 ++++ .../skins/SmartPhone2.skin/defaultbuttons.conf | 52 ++++++++ .../deviceskin/skins/SmartPhoneWithButtons.qrc | 5 + .../SmartPhoneWithButtons-pressed.png | Bin 0 -> 103838 bytes .../SmartPhoneWithButtons.png | Bin 0 -> 88470 bytes .../SmartPhoneWithButtons.skin | 31 +++++ .../SmartPhoneWithButtons.skin/defaultbuttons.conf | 103 +++++++++++++++ tools/shared/deviceskin/skins/TouchscreenPhone.qrc | 5 + .../TouchscreenPhone-pressed.png | Bin 0 -> 88599 bytes .../TouchscreenPhone.skin/TouchscreenPhone.png | Bin 0 -> 61809 bytes .../TouchscreenPhone.skin/TouchscreenPhone.skin | 16 +++ .../TouchscreenPhone.skin/defaultbuttons.conf | 45 +++++++ tools/shared/deviceskin/skins/Trolltech-Keypad.qrc | 5 + .../Trolltech-Keypad-closed.png | Bin 0 -> 69447 bytes .../Trolltech-Keypad-down.png | Bin 0 -> 242107 bytes .../Trolltech-Keypad.skin/Trolltech-Keypad.png | Bin 0 -> 230638 bytes .../Trolltech-Keypad.skin/Trolltech-Keypad.skin | 35 +++++ .../Trolltech-Keypad.skin/defaultbuttons.conf | 142 +++++++++++++++++++++ .../deviceskin/skins/Trolltech-Touchscreen.qrc | 5 + .../Trolltech-Touchscreen-down.png | Bin 0 -> 133117 bytes .../Trolltech-Touchscreen.png | Bin 0 -> 133180 bytes .../Trolltech-Touchscreen.skin | 17 +++ .../Trolltech-Touchscreen.skin/defaultbuttons.conf | 53 ++++++++ 134 files changed, 1156 insertions(+), 1188 deletions(-) delete mode 100644 tools/qvfb/ClamshellPhone.qrc delete mode 100644 tools/qvfb/ClamshellPhone.skin/ClamshellPhone.skin delete mode 100644 tools/qvfb/ClamshellPhone.skin/ClamshellPhone1-5-closed.png delete mode 100644 tools/qvfb/ClamshellPhone.skin/ClamshellPhone1-5-pressed.png delete mode 100644 tools/qvfb/ClamshellPhone.skin/ClamshellPhone1-5.png delete mode 100644 tools/qvfb/ClamshellPhone.skin/defaultbuttons.conf delete mode 100644 tools/qvfb/DualScreenPhone.skin/DualScreen-pressed.png delete mode 100644 tools/qvfb/DualScreenPhone.skin/DualScreen.png delete mode 100644 tools/qvfb/DualScreenPhone.skin/DualScreenPhone.skin delete mode 100644 tools/qvfb/DualScreenPhone.skin/defaultbuttons.conf delete mode 100644 tools/qvfb/PDAPhone.qrc delete mode 100644 tools/qvfb/PDAPhone.skin/PDAPhone.skin delete mode 100644 tools/qvfb/PDAPhone.skin/defaultbuttons.conf delete mode 100644 tools/qvfb/PDAPhone.skin/finger.png delete mode 100644 tools/qvfb/PDAPhone.skin/pda_down.png delete mode 100644 tools/qvfb/PDAPhone.skin/pda_up.png delete mode 100644 tools/qvfb/PortableMedia.qrc delete mode 100644 tools/qvfb/PortableMedia.skin/PortableMedia.skin delete mode 100644 tools/qvfb/PortableMedia.skin/defaultbuttons.conf delete mode 100644 tools/qvfb/PortableMedia.skin/portablemedia-pressed.png delete mode 100644 tools/qvfb/PortableMedia.skin/portablemedia.png delete mode 100644 tools/qvfb/PortableMedia.skin/portablemedia.xcf delete mode 100644 tools/qvfb/S60-QVGA-Candybar.qrc delete mode 100644 tools/qvfb/S60-QVGA-Candybar.skin/S60-QVGA-Candybar-down.png delete mode 100644 tools/qvfb/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.png delete mode 100644 tools/qvfb/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.skin delete mode 100644 tools/qvfb/S60-QVGA-Candybar.skin/defaultbuttons.conf delete mode 100644 tools/qvfb/S60-nHD-Touchscreen.qrc delete mode 100644 tools/qvfb/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen-down.png delete mode 100644 tools/qvfb/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.png delete mode 100644 tools/qvfb/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.skin delete mode 100644 tools/qvfb/S60-nHD-Touchscreen.skin/defaultbuttons.conf delete mode 100644 tools/qvfb/SmartPhone.qrc delete mode 100644 tools/qvfb/SmartPhone.skin/SmartPhone-pressed.png delete mode 100644 tools/qvfb/SmartPhone.skin/SmartPhone.png delete mode 100644 tools/qvfb/SmartPhone.skin/SmartPhone.skin delete mode 100644 tools/qvfb/SmartPhone.skin/defaultbuttons.conf delete mode 100644 tools/qvfb/SmartPhone2.qrc delete mode 100644 tools/qvfb/SmartPhone2.skin/SmartPhone2-pressed.png delete mode 100644 tools/qvfb/SmartPhone2.skin/SmartPhone2.png delete mode 100644 tools/qvfb/SmartPhone2.skin/SmartPhone2.skin delete mode 100644 tools/qvfb/SmartPhone2.skin/defaultbuttons.conf delete mode 100644 tools/qvfb/SmartPhoneWithButtons.qrc delete mode 100644 tools/qvfb/SmartPhoneWithButtons.skin/SmartPhoneWithButtons-pressed.png delete mode 100644 tools/qvfb/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.png delete mode 100644 tools/qvfb/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.skin delete mode 100644 tools/qvfb/SmartPhoneWithButtons.skin/defaultbuttons.conf delete mode 100644 tools/qvfb/TouchscreenPhone.qrc delete mode 100644 tools/qvfb/TouchscreenPhone.skin/TouchscreenPhone-pressed.png delete mode 100644 tools/qvfb/TouchscreenPhone.skin/TouchscreenPhone.png delete mode 100644 tools/qvfb/TouchscreenPhone.skin/TouchscreenPhone.skin delete mode 100644 tools/qvfb/TouchscreenPhone.skin/defaultbuttons.conf delete mode 100644 tools/qvfb/Trolltech-Keypad.qrc delete mode 100644 tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad-closed.png delete mode 100644 tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad-down.png delete mode 100644 tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad.png delete mode 100644 tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad.skin delete mode 100644 tools/qvfb/Trolltech-Keypad.skin/defaultbuttons.conf delete mode 100644 tools/qvfb/Trolltech-Touchscreen.qrc delete mode 100644 tools/qvfb/Trolltech-Touchscreen.skin/Trolltech-Touchscreen-down.png delete mode 100644 tools/qvfb/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.png delete mode 100644 tools/qvfb/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.skin delete mode 100644 tools/qvfb/Trolltech-Touchscreen.skin/defaultbuttons.conf delete mode 100644 tools/qvfb/pda.qrc delete mode 100644 tools/qvfb/pda.skin delete mode 100644 tools/qvfb/pda_down.png delete mode 100644 tools/qvfb/pda_up.png create mode 100644 tools/shared/deviceskin/skins/ClamshellPhone.qrc create mode 100644 tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone.skin create mode 100644 tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone1-5-closed.png create mode 100644 tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone1-5-pressed.png create mode 100644 tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone1-5.png create mode 100644 tools/shared/deviceskin/skins/ClamshellPhone.skin/defaultbuttons.conf create mode 100644 tools/shared/deviceskin/skins/DualScreenPhone.skin/DualScreen-pressed.png create mode 100644 tools/shared/deviceskin/skins/DualScreenPhone.skin/DualScreen.png create mode 100644 tools/shared/deviceskin/skins/DualScreenPhone.skin/DualScreenPhone.skin create mode 100644 tools/shared/deviceskin/skins/DualScreenPhone.skin/defaultbuttons.conf create mode 100644 tools/shared/deviceskin/skins/PDAPhone.qrc create mode 100644 tools/shared/deviceskin/skins/PDAPhone.skin/PDAPhone.skin create mode 100644 tools/shared/deviceskin/skins/PDAPhone.skin/defaultbuttons.conf create mode 100644 tools/shared/deviceskin/skins/PDAPhone.skin/finger.png create mode 100644 tools/shared/deviceskin/skins/PDAPhone.skin/pda_down.png create mode 100644 tools/shared/deviceskin/skins/PDAPhone.skin/pda_up.png create mode 100644 tools/shared/deviceskin/skins/PortableMedia.qrc create mode 100644 tools/shared/deviceskin/skins/PortableMedia.skin/PortableMedia.skin create mode 100644 tools/shared/deviceskin/skins/PortableMedia.skin/defaultbuttons.conf create mode 100644 tools/shared/deviceskin/skins/PortableMedia.skin/portablemedia-pressed.png create mode 100644 tools/shared/deviceskin/skins/PortableMedia.skin/portablemedia.png create mode 100644 tools/shared/deviceskin/skins/PortableMedia.skin/portablemedia.xcf create mode 100644 tools/shared/deviceskin/skins/S60-QVGA-Candybar.qrc create mode 100644 tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/S60-QVGA-Candybar-down.png create mode 100644 tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.png create mode 100644 tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.skin create mode 100644 tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/defaultbuttons.conf create mode 100644 tools/shared/deviceskin/skins/S60-nHD-Touchscreen.qrc create mode 100644 tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen-down.png create mode 100644 tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.png create mode 100644 tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.skin create mode 100644 tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/defaultbuttons.conf create mode 100644 tools/shared/deviceskin/skins/SmartPhone.qrc create mode 100644 tools/shared/deviceskin/skins/SmartPhone.skin/SmartPhone-pressed.png create mode 100644 tools/shared/deviceskin/skins/SmartPhone.skin/SmartPhone.png create mode 100644 tools/shared/deviceskin/skins/SmartPhone.skin/SmartPhone.skin create mode 100644 tools/shared/deviceskin/skins/SmartPhone.skin/defaultbuttons.conf create mode 100644 tools/shared/deviceskin/skins/SmartPhone2.qrc create mode 100644 tools/shared/deviceskin/skins/SmartPhone2.skin/SmartPhone2-pressed.png create mode 100644 tools/shared/deviceskin/skins/SmartPhone2.skin/SmartPhone2.png create mode 100644 tools/shared/deviceskin/skins/SmartPhone2.skin/SmartPhone2.skin create mode 100644 tools/shared/deviceskin/skins/SmartPhone2.skin/defaultbuttons.conf create mode 100644 tools/shared/deviceskin/skins/SmartPhoneWithButtons.qrc create mode 100644 tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/SmartPhoneWithButtons-pressed.png create mode 100644 tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.png create mode 100644 tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.skin create mode 100644 tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/defaultbuttons.conf create mode 100644 tools/shared/deviceskin/skins/TouchscreenPhone.qrc create mode 100644 tools/shared/deviceskin/skins/TouchscreenPhone.skin/TouchscreenPhone-pressed.png create mode 100644 tools/shared/deviceskin/skins/TouchscreenPhone.skin/TouchscreenPhone.png create mode 100644 tools/shared/deviceskin/skins/TouchscreenPhone.skin/TouchscreenPhone.skin create mode 100644 tools/shared/deviceskin/skins/TouchscreenPhone.skin/defaultbuttons.conf create mode 100644 tools/shared/deviceskin/skins/Trolltech-Keypad.qrc create mode 100644 tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad-closed.png create mode 100644 tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad-down.png create mode 100644 tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad.png create mode 100644 tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad.skin create mode 100644 tools/shared/deviceskin/skins/Trolltech-Keypad.skin/defaultbuttons.conf create mode 100644 tools/shared/deviceskin/skins/Trolltech-Touchscreen.qrc create mode 100644 tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/Trolltech-Touchscreen-down.png create mode 100644 tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.png create mode 100644 tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.skin create mode 100644 tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/defaultbuttons.conf diff --git a/tools/designer/src/lib/sdk/abstractformeditor.cpp b/tools/designer/src/lib/sdk/abstractformeditor.cpp index e6debd5..09d6976 100644 --- a/tools/designer/src/lib/sdk/abstractformeditor.cpp +++ b/tools/designer/src/lib/sdk/abstractformeditor.cpp @@ -72,7 +72,6 @@ static void initResources() Q_INIT_RESOURCE(shared); Q_INIT_RESOURCE(ClamshellPhone); Q_INIT_RESOURCE(PDAPhone); - Q_INIT_RESOURCE(pda); Q_INIT_RESOURCE(PortableMedia); Q_INIT_RESOURCE(S60_nHD_Touchscreen); Q_INIT_RESOURCE(S60_QVGA_Candybar); diff --git a/tools/designer/src/lib/shared/shared.pri b/tools/designer/src/lib/shared/shared.pri index 0424a41..8ed051a 100644 --- a/tools/designer/src/lib/shared/shared.pri +++ b/tools/designer/src/lib/shared/shared.pri @@ -186,17 +186,4 @@ SOURCES += \ $$PWD/filterwidget.cpp \ $$PWD/plugindialog.cpp -RESOURCES += $$PWD/shared.qrc \ -$$QT_SOURCE_TREE/tools/qvfb/ClamshellPhone.qrc \ -$$QT_SOURCE_TREE/tools/qvfb/PDAPhone.qrc \ -$$QT_SOURCE_TREE/tools/qvfb/pda.qrc \ -$$QT_SOURCE_TREE/tools/qvfb/PortableMedia.qrc \ -$$QT_SOURCE_TREE/tools/qvfb/qvfb.qrc \ -$$QT_SOURCE_TREE/tools/qvfb/S60-nHD-Touchscreen.qrc \ -$$QT_SOURCE_TREE/tools/qvfb/S60-QVGA-Candybar.qrc \ -$$QT_SOURCE_TREE/tools/qvfb/SmartPhone2.qrc \ -$$QT_SOURCE_TREE/tools/qvfb/SmartPhone.qrc \ -$$QT_SOURCE_TREE/tools/qvfb/SmartPhoneWithButtons.qrc \ -$$QT_SOURCE_TREE/tools/qvfb/TouchscreenPhone.qrc \ -$$QT_SOURCE_TREE/tools/qvfb/Trolltech-Keypad.qrc \ -$$QT_SOURCE_TREE/tools/qvfb/Trolltech-Touchscreen.qrc +RESOURCES += $$PWD/shared.qrc diff --git a/tools/qvfb/ClamshellPhone.qrc b/tools/qvfb/ClamshellPhone.qrc deleted file mode 100644 index 39cd422..0000000 --- a/tools/qvfb/ClamshellPhone.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - ClamshellPhone.skin - - diff --git a/tools/qvfb/ClamshellPhone.skin/ClamshellPhone.skin b/tools/qvfb/ClamshellPhone.skin/ClamshellPhone.skin deleted file mode 100644 index cb24a8e..0000000 --- a/tools/qvfb/ClamshellPhone.skin/ClamshellPhone.skin +++ /dev/null @@ -1,30 +0,0 @@ -[SkinFile] -Up=ClamshellPhone1-5.png -Down=ClamshellPhone1-5-pressed.png -Closed=ClamshellPhone1-5-closed.png -Screen=72 84 176 208 -Areas=22 -HasMouseHover=false - -"Power" 0x0100000a 205 563 249 586 -"1" 0x0031 62 414 119 438 -"2" 0x0032 130 414 189 438 -"3" 0x0033 198 413 257 438 -"4" 0x0034 54 444 117 470 -"5" 0x0035 128 444 189 471 -"6" 0x0036 202 444 264 471 -"7" 0x0037 47 477 113 507 -"8" 0x0038 126 477 190 507 -"9" 0x0039 205 478 270 509 -"*" 0x002a 39 515 110 552 -"0" 0x0030 122 515 195 553 -"#" 0x0023 207 516 280 553 -"Context1" 0x01100000 137 360 108 383 123 410 90 409 60 387 63 378 100 362 -"Back" 0x01000061 184 361 206 376 213 387 197 410 226 410 256 392 258 381 244 369 -"Backspace" 0x01000003 68 563 113 587 -"Select" 0x01010000 160 391 172 390 181 386 184 381 180 377 173 373 165 372 155 372 145 375 138 378 136 382 138 387 147 390 -"Left" 0x1000012 141 390 136 385 136 381 143 375 132 371 120 380 121 393 129 401 -"Down" 0x1000015 143 389 130 402 162 412 191 404 175 390 -"Right" 0x1000014 186 370 176 375 184 382 182 387 175 390 190 404 201 396 202 375 -"Up" 0x1000013 133 370 143 374 176 374 185 370 169 362 149 362 -"Flip" 0x01100006 98 325 225 353 diff --git a/tools/qvfb/ClamshellPhone.skin/ClamshellPhone1-5-closed.png b/tools/qvfb/ClamshellPhone.skin/ClamshellPhone1-5-closed.png deleted file mode 100644 index 88ba3a1..0000000 Binary files a/tools/qvfb/ClamshellPhone.skin/ClamshellPhone1-5-closed.png and /dev/null differ diff --git a/tools/qvfb/ClamshellPhone.skin/ClamshellPhone1-5-pressed.png b/tools/qvfb/ClamshellPhone.skin/ClamshellPhone1-5-pressed.png deleted file mode 100644 index 971cdef..0000000 Binary files a/tools/qvfb/ClamshellPhone.skin/ClamshellPhone1-5-pressed.png and /dev/null differ diff --git a/tools/qvfb/ClamshellPhone.skin/ClamshellPhone1-5.png b/tools/qvfb/ClamshellPhone.skin/ClamshellPhone1-5.png deleted file mode 100644 index f3550ee..0000000 Binary files a/tools/qvfb/ClamshellPhone.skin/ClamshellPhone1-5.png and /dev/null differ diff --git a/tools/qvfb/ClamshellPhone.skin/defaultbuttons.conf b/tools/qvfb/ClamshellPhone.skin/defaultbuttons.conf deleted file mode 100644 index e349dbc..0000000 --- a/tools/qvfb/ClamshellPhone.skin/defaultbuttons.conf +++ /dev/null @@ -1,78 +0,0 @@ -[Translation] -File=QtopiaDefaults -Context=Buttons -[Menu] -Rows=4 -Columns=3 -Map=123456789*0# -Default=5 -1=Applications/camera.desktop -2=Applications/datebook.desktop -3=Applications -4=Applications/qtmail.desktop -5=Applications/addressbook.desktop -6=Games -7=Settings/Beaming.desktop -8=Applications/simapp.desktop,Applications/calculator.desktop -9=Settings -*=Applications/mediarecorder.desktop -0=Applications/todolist.desktop -#=Documents -Animator=Bounce -AnimatorBackground=Radial -[SoftKeys] -Count=3 -Key0=Context1 -Key1=Select -Key2=Back -[SystemButtons] -Count=5 -Key0=Context1 -Key1=Select -Key2=Back -Key3=Flip -Key4=Backspace -[TextButtons] -Buttons=0123456789*# -Hold0='0 -Hold1='1 -Hold2='2 -Hold3='3 -Hold4='4 -Hold5='5 -Hold6='6 -Hold7='7 -Hold8='8 -Hold9='9 -Hold*=symbol -Hold#=mode -Tap0=space -Tap1="\".,'?!-@:1" -Tap2="\"a\xe4\xe5\xe6\xe0\xe1\xe2\x62\x63\xe7\x32" -Tap3="\"de\xe8\xe9\xea\x66\x33" -Tap4="\"ghi\xec\xed\xee\x34" -Tap5="\"jkl5" -Tap6="\"mn\xf1o\xf6\xf8\xf2\xf3\x36" -Tap7="\"pqrs\xdf\x37" -Tap8="\"tu\xfc\xf9\xfav8" -Tap9="\"wxyz9" -Tap*=modify -Tap#=shift -[LocaleTextButtons] -Buttons=23456789 -Tap2[]='abc -Tap3[]='def -Tap4[]='ghi -Tap5[]='jkl -Tap6[]='mno -Tap7[]='pqrs -Tap8[]='tuv -Tap9[]='wxyz -[PhoneTextButtons] -Buttons=*# -Tap*='*+pw -Hold*=+ -Tap#=# -Hold#=mode -[Device] -PrimaryInput=Keypad diff --git a/tools/qvfb/DualScreenPhone.skin/DualScreen-pressed.png b/tools/qvfb/DualScreenPhone.skin/DualScreen-pressed.png deleted file mode 100644 index d62ef4a..0000000 Binary files a/tools/qvfb/DualScreenPhone.skin/DualScreen-pressed.png and /dev/null differ diff --git a/tools/qvfb/DualScreenPhone.skin/DualScreen.png b/tools/qvfb/DualScreenPhone.skin/DualScreen.png deleted file mode 100644 index cb3d1a7..0000000 Binary files a/tools/qvfb/DualScreenPhone.skin/DualScreen.png and /dev/null differ diff --git a/tools/qvfb/DualScreenPhone.skin/DualScreenPhone.skin b/tools/qvfb/DualScreenPhone.skin/DualScreenPhone.skin deleted file mode 100644 index a82ef23..0000000 --- a/tools/qvfb/DualScreenPhone.skin/DualScreenPhone.skin +++ /dev/null @@ -1,29 +0,0 @@ -[SkinFile] -Up=DualScreen.png -Down=DualScreen-pressed.png -Screen=128 155 176 208 -BackScreen=18 44 98 119 -Areas=21 -HasMouseHover=false - -"Context1" 0x1100000 144 368 189 368 168 396 176 427 150 398 -"Back" 0x1000061 245 365 291 366 283 398 258 424 265 394 -"Select" 0x1010000 202 401 210 389 224 388 233 402 224 415 208 415 -"Up" 0x1000013 202 381 196 374 218 363 239 373 229 382 -"Left" 0x1000012 199 385 189 375 176 403 185 426 197 415 194 401 -"Right" 0x1000014 235 390 248 379 253 402 246 421 238 413 -"Down" 0x1000015 204 421 233 422 241 432 214 443 191 430 -"Call" 0x1100004 163 452 137 450 125 465 136 484 159 485 169 467 -"Hangup" 0x1100005 266 475 279 448 295 447 309 460 301 480 289 487 -"1" 0x31 175 514 147 504 133 518 161 532 180 534 -"2" 0x32 199 515 229 519 238 533 222 540 195 538 -"2" 0x32 260 512 286 506 299 513 284 527 264 535 248 525 -"4" 0x34 164 541 177 546 182 560 164 565 146 560 135 545 154 539 -"5" 0x35 204 546 225 546 243 560 231 574 205 573 191 558 -"6" 0x36 257 547 281 537 294 540 287 555 274 566 254 561 -"7" 0x37 145 569 176 578 177 595 156 597 138 584 -"8" 0x38 197 582 229 584 241 593 226 604 201 603 189 594 -"9" 0x39 253 577 288 564 301 578 283 593 259 597 251 586 -"*" 0x2a 145 598 181 611 182 623 163 632 144 623 138 607 -"0" 0x30 196 611 233 613 240 630 220 642 193 637 191 622 -"#" 0x23 255 610 286 600 302 615 279 625 258 629 247 616 diff --git a/tools/qvfb/DualScreenPhone.skin/defaultbuttons.conf b/tools/qvfb/DualScreenPhone.skin/defaultbuttons.conf deleted file mode 100644 index 1103350..0000000 --- a/tools/qvfb/DualScreenPhone.skin/defaultbuttons.conf +++ /dev/null @@ -1,78 +0,0 @@ -[Translation] -File=QtopiaDefaults -Context=Buttons -[Menu] -Rows=4 -Columns=3 -Map=123456789*0# -Default=5 -1=Applications/camera.desktop -2=Applications/datebook.desktop -3=Applications -4=Applications/qtmail.desktop -5=Applications/addressbook.desktop -6=Games -7=Settings/Beaming.desktop -8=Applications/simapp.desktop,Applications/calculator.desktop -9=Settings -*=Applications/mediarecorder.desktop -0=Applications/todolist.desktop -#=Documents -Animator=Bounce -AnimatorBackground=Radial -[SoftKeys] -Count=3 -Key0=Context1 -Key1=Select -Key2=Back -[SystemButtons] -Count=5 -Key0=Context1 -Key1=Select -Key2=Back -Key3=Call -Key4=Hangup -[TextButtons] -Buttons=0123456789*# -Hold0='0 -Hold1='1 -Hold2='2 -Hold3='3 -Hold4='4 -Hold5='5 -Hold6='6 -Hold7='7 -Hold8='8 -Hold9='9 -Hold*=symbol -Hold#=mode -Tap0=space -Tap1="\".,'?!-@:1" -Tap2="\"a\xe4\xe5\xe6\xe0\xe1\xe2\x62\x63\xe7\x32" -Tap3="\"de\xe8\xe9\xea\x66\x33" -Tap4="\"ghi\xec\xed\xee\x34" -Tap5="\"jkl5" -Tap6="\"mn\xf1o\xf6\xf8\xf2\xf3\x36" -Tap7="\"pqrs\xdf\x37" -Tap8="\"tu\xfc\xf9\xfav8" -Tap9="\"wxyz9" -Tap*=modify -Tap#=shift -[LocaleTextButtons] -Buttons=23456789 -Tap2[]='abc -Tap3[]='def -Tap4[]='ghi -Tap5[]='jkl -Tap6[]='mno -Tap7[]='pqrs -Tap8[]='tuv -Tap9[]='wxyz -[PhoneTextButtons] -Buttons=*# -Tap*='*+pw -Hold*=+ -Tap#='# -Hold#=mode -[Device] -PrimaryInput=Keypad diff --git a/tools/qvfb/PDAPhone.qrc b/tools/qvfb/PDAPhone.qrc deleted file mode 100644 index 1a1c35a..0000000 --- a/tools/qvfb/PDAPhone.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - PDAPhone.skin - - diff --git a/tools/qvfb/PDAPhone.skin/PDAPhone.skin b/tools/qvfb/PDAPhone.skin/PDAPhone.skin deleted file mode 100644 index d6a1966..0000000 --- a/tools/qvfb/PDAPhone.skin/PDAPhone.skin +++ /dev/null @@ -1,18 +0,0 @@ -[SkinFile] -Up=pda_up.png -Down=pda_down.png -Screen=42 59 176 220 -Cursor=finger.png 20 20 -Areas=10 -HasMouseHover=false - -"Power" 0x0100000a 117 21 141 42 -"Context1" 0x01100000 43 284 74 315 -"Call" 0x01100004 74 284 104 315 -"Hangup" 0x01100005 154 284 184 315 -"Back" 0x01000061 184 284 214 315 -"Left" 0x1000012 123 315 110 326 106 307 113 288 123 300 120 307 -"Down" 0x1000015 123 315 130 318 138 315 150 326 129 335 111 325 -"Right" 0x1000014 137 301 149 290 155 308 150 324 138 315 140 308 -"Up" 0x1000013 123 300 112 289 130 282 149 290 137 300 130 298 -"Select" 0x01010000 131 298 137 300 140 307 138 315 130 318 123 316 120 307 123 300 diff --git a/tools/qvfb/PDAPhone.skin/defaultbuttons.conf b/tools/qvfb/PDAPhone.skin/defaultbuttons.conf deleted file mode 100644 index e3ae813..0000000 --- a/tools/qvfb/PDAPhone.skin/defaultbuttons.conf +++ /dev/null @@ -1,36 +0,0 @@ -[Translation] -File=QtopiaDefaults -Context=Buttons -[Menu] -Rows=4 -Columns=3 -Map=123456789*0# -Default=5 -1=Applications/camera.desktop -2=Applications/datebook.desktop -3=Applications -4=Applications/qtmail.desktop -5=Applications/addressbook.desktop -6=Games -7=Settings/Beaming.desktop -8=Applications/simapp.desktop,Applications/calculator.desktop -9=Settings -*=Applications/mediarecorder.desktop -0=Applications/todolist.desktop -#=Documents -Animator=Bounce -AnimatorBackground=Radial -[SoftKeys] -Count=3 -Key0=Context1 -Key1=Select -Key2=Back -[SystemButtons] -Count=5 -Key0=Context1 -Key1=Back -Key2=Select -Key3=Call -Key4=Hangup -[Device] -PrimaryInput=Touchscreen diff --git a/tools/qvfb/PDAPhone.skin/finger.png b/tools/qvfb/PDAPhone.skin/finger.png deleted file mode 100644 index 24cf0cb..0000000 Binary files a/tools/qvfb/PDAPhone.skin/finger.png and /dev/null differ diff --git a/tools/qvfb/PDAPhone.skin/pda_down.png b/tools/qvfb/PDAPhone.skin/pda_down.png deleted file mode 100644 index f65c059..0000000 Binary files a/tools/qvfb/PDAPhone.skin/pda_down.png and /dev/null differ diff --git a/tools/qvfb/PDAPhone.skin/pda_up.png b/tools/qvfb/PDAPhone.skin/pda_up.png deleted file mode 100644 index 541e3c4..0000000 Binary files a/tools/qvfb/PDAPhone.skin/pda_up.png and /dev/null differ diff --git a/tools/qvfb/PortableMedia.qrc b/tools/qvfb/PortableMedia.qrc deleted file mode 100644 index a902f1a..0000000 --- a/tools/qvfb/PortableMedia.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - PortableMedia.skin - - diff --git a/tools/qvfb/PortableMedia.skin/PortableMedia.skin b/tools/qvfb/PortableMedia.skin/PortableMedia.skin deleted file mode 100644 index b76e5cf..0000000 --- a/tools/qvfb/PortableMedia.skin/PortableMedia.skin +++ /dev/null @@ -1,14 +0,0 @@ -[SkinFile] -Up=portablemedia.png -Down=portablemedia-pressed.png -Screen=18 20 480 272 -Areas=7 -HasMouseHover=false - -"Context1" 0x01100000 530 192 565 223 -"Back" 0x01000061 530 138 565 173 -"Select" 0x01010000 530 65 565 98 -"Left" 0x1000012 529 67 519 57 511 65 511 104 519 110 529 100 529 98 -"Down" 0x1000015 530 102 520 111 529 120 569 120 577 114 566 103 564 103 -"Right" 0x1000014 565 65 576 52 585 67 585 102 578 113 567 104 -"Up" 0x1000013 530 65 519 55 528 48 567 48 573 51 564 66 diff --git a/tools/qvfb/PortableMedia.skin/defaultbuttons.conf b/tools/qvfb/PortableMedia.skin/defaultbuttons.conf deleted file mode 100644 index 514e881..0000000 --- a/tools/qvfb/PortableMedia.skin/defaultbuttons.conf +++ /dev/null @@ -1,23 +0,0 @@ -[Translation] -File=QtopiaDefaults -Context=Buttons -[Menu] -Map=123 -Default=1 -1=Applications/mediaplayer.desktop -2=Applications/photoedit.desktop -3=Settings -Animator=Bounce -AnimatorBackground=Radial -[SoftKeys] -Count=3 -Key0=Context1 -Key1=Select -Key2=Back -[SystemButtons] -Count=5 -Key0=Context1 -Key1=Select -Key2=Back -[Device] -PrimaryInput=Keypad diff --git a/tools/qvfb/PortableMedia.skin/portablemedia-pressed.png b/tools/qvfb/PortableMedia.skin/portablemedia-pressed.png deleted file mode 100644 index 730e762..0000000 Binary files a/tools/qvfb/PortableMedia.skin/portablemedia-pressed.png and /dev/null differ diff --git a/tools/qvfb/PortableMedia.skin/portablemedia.png b/tools/qvfb/PortableMedia.skin/portablemedia.png deleted file mode 100644 index e44cbe1..0000000 Binary files a/tools/qvfb/PortableMedia.skin/portablemedia.png and /dev/null differ diff --git a/tools/qvfb/PortableMedia.skin/portablemedia.xcf b/tools/qvfb/PortableMedia.skin/portablemedia.xcf deleted file mode 100644 index 127e07c..0000000 Binary files a/tools/qvfb/PortableMedia.skin/portablemedia.xcf and /dev/null differ diff --git a/tools/qvfb/S60-QVGA-Candybar.qrc b/tools/qvfb/S60-QVGA-Candybar.qrc deleted file mode 100644 index 8138484..0000000 --- a/tools/qvfb/S60-QVGA-Candybar.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - S60-QVGA-Candybar.skin - - diff --git a/tools/qvfb/S60-QVGA-Candybar.skin/S60-QVGA-Candybar-down.png b/tools/qvfb/S60-QVGA-Candybar.skin/S60-QVGA-Candybar-down.png deleted file mode 100644 index 89d40cb..0000000 Binary files a/tools/qvfb/S60-QVGA-Candybar.skin/S60-QVGA-Candybar-down.png and /dev/null differ diff --git a/tools/qvfb/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.png b/tools/qvfb/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.png deleted file mode 100644 index 0d0e598..0000000 Binary files a/tools/qvfb/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.png and /dev/null differ diff --git a/tools/qvfb/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.skin b/tools/qvfb/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.skin deleted file mode 100644 index 4f8fe5d..0000000 --- a/tools/qvfb/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.skin +++ /dev/null @@ -1,15 +0,0 @@ -[SkinFile] -Up=S60-QVGA-Candybar.png -Down=S60-QVGA-Candybar-down.png -Screen=61 93 240 320 -Areas=7 -HasMouseHover=false - - -"Context1" 0x01100000 54 469 151 469 140 483 88 485 81 496 54 498 -"Back" 0x01000061 211 468 307 467 307 498 278 497 219 486 -"Select" 0x01010000 165 491 196 522 -"Left" 0x1000012 149 474 166 492 163 519 143 538 142 481 -"Down" 0x1000015 164 521 195 522 212 539 204 545 154 544 145 536 -"Right" 0x1000014 214 475 219 487 219 528 212 539 196 522 197 492 -"Up" 0x1000013 150 474 156 467 209 467 213 476 197 489 165 489 diff --git a/tools/qvfb/S60-QVGA-Candybar.skin/defaultbuttons.conf b/tools/qvfb/S60-QVGA-Candybar.skin/defaultbuttons.conf deleted file mode 100644 index e349dbc..0000000 --- a/tools/qvfb/S60-QVGA-Candybar.skin/defaultbuttons.conf +++ /dev/null @@ -1,78 +0,0 @@ -[Translation] -File=QtopiaDefaults -Context=Buttons -[Menu] -Rows=4 -Columns=3 -Map=123456789*0# -Default=5 -1=Applications/camera.desktop -2=Applications/datebook.desktop -3=Applications -4=Applications/qtmail.desktop -5=Applications/addressbook.desktop -6=Games -7=Settings/Beaming.desktop -8=Applications/simapp.desktop,Applications/calculator.desktop -9=Settings -*=Applications/mediarecorder.desktop -0=Applications/todolist.desktop -#=Documents -Animator=Bounce -AnimatorBackground=Radial -[SoftKeys] -Count=3 -Key0=Context1 -Key1=Select -Key2=Back -[SystemButtons] -Count=5 -Key0=Context1 -Key1=Select -Key2=Back -Key3=Flip -Key4=Backspace -[TextButtons] -Buttons=0123456789*# -Hold0='0 -Hold1='1 -Hold2='2 -Hold3='3 -Hold4='4 -Hold5='5 -Hold6='6 -Hold7='7 -Hold8='8 -Hold9='9 -Hold*=symbol -Hold#=mode -Tap0=space -Tap1="\".,'?!-@:1" -Tap2="\"a\xe4\xe5\xe6\xe0\xe1\xe2\x62\x63\xe7\x32" -Tap3="\"de\xe8\xe9\xea\x66\x33" -Tap4="\"ghi\xec\xed\xee\x34" -Tap5="\"jkl5" -Tap6="\"mn\xf1o\xf6\xf8\xf2\xf3\x36" -Tap7="\"pqrs\xdf\x37" -Tap8="\"tu\xfc\xf9\xfav8" -Tap9="\"wxyz9" -Tap*=modify -Tap#=shift -[LocaleTextButtons] -Buttons=23456789 -Tap2[]='abc -Tap3[]='def -Tap4[]='ghi -Tap5[]='jkl -Tap6[]='mno -Tap7[]='pqrs -Tap8[]='tuv -Tap9[]='wxyz -[PhoneTextButtons] -Buttons=*# -Tap*='*+pw -Hold*=+ -Tap#=# -Hold#=mode -[Device] -PrimaryInput=Keypad diff --git a/tools/qvfb/S60-nHD-Touchscreen.qrc b/tools/qvfb/S60-nHD-Touchscreen.qrc deleted file mode 100644 index daf0cc3..0000000 --- a/tools/qvfb/S60-nHD-Touchscreen.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - S60-nHD-Touchscreen.skin - - diff --git a/tools/qvfb/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen-down.png b/tools/qvfb/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen-down.png deleted file mode 100644 index 7253e38..0000000 Binary files a/tools/qvfb/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen-down.png and /dev/null differ diff --git a/tools/qvfb/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.png b/tools/qvfb/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.png deleted file mode 100644 index 675563e..0000000 Binary files a/tools/qvfb/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.png and /dev/null differ diff --git a/tools/qvfb/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.skin b/tools/qvfb/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.skin deleted file mode 100644 index ed25d0e..0000000 --- a/tools/qvfb/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.skin +++ /dev/null @@ -1,10 +0,0 @@ -[SkinFile] -Up=S60-nHD-Touchscreen.png -Down=S60-nHD-Touchscreen-down.png -Screen=53 183 360 640 -Areas=3 -HasMouseHover=false - -"Call" 0x01100004 76 874 171 899 -"Hangup" 0x01100005 300 876 393 899 -"Home" 0x1000010 174 878 298 899 diff --git a/tools/qvfb/S60-nHD-Touchscreen.skin/defaultbuttons.conf b/tools/qvfb/S60-nHD-Touchscreen.skin/defaultbuttons.conf deleted file mode 100644 index 6665125..0000000 --- a/tools/qvfb/S60-nHD-Touchscreen.skin/defaultbuttons.conf +++ /dev/null @@ -1,53 +0,0 @@ -[Translation] -File=QtopiaDefaults -Context=Buttons -[Menu] -Rows=4 -Columns=3 -Map=123456789*0# -Default=5 -1=Applications/camera.desktop -2=Applications/mediaplayer.desktop -3=Applications/simapp.desktop,Applications/calculator.desktop -4=Applications/qtmail.desktop -5=Applications/addressbook.desktop -6=Applications/datebook.desktop -7=Games -8=Settings/beaming.desktop -9=Applications/todolist.desktop -*=Settings -0=Applications -#=Documents -Animator=Bounce -AnimatorBackground=Radial -[SoftKeys] -Count=3 -Key0=Context1 -Key1=Select -Key2=Back -[SystemButtons] -Count=5 -Key0=Context1 -Key1=Back -Key2=Select -Key3=Call -Key4=Hangup -[Device] -PrimaryInput=Touchscreen -[Button] -Count=2 -[Button0] -Name[]=Home Button -Key=Home -PressedActionMappable=0 -PressedActionService=TaskManager -PressedActionMessage=multitask() -HeldActionMappable=0 -HeldActionService=TaskManager -HeldActionMessage=showRunningTasks() -[Button1] -Name=Power Button -Key=Hangup -HeldActionService=Launcher -HeldActionMessage=execute(QString) -HeldActionArgs=@ByteArray(\0\0\0\x1\0\0\0\n\0\0\0\0\x10\0s\0h\0u\0t\0\x64\0o\0w\0n) diff --git a/tools/qvfb/SmartPhone.qrc b/tools/qvfb/SmartPhone.qrc deleted file mode 100644 index 8bb5325..0000000 --- a/tools/qvfb/SmartPhone.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - SmartPhone.skin - - diff --git a/tools/qvfb/SmartPhone.skin/SmartPhone-pressed.png b/tools/qvfb/SmartPhone.skin/SmartPhone-pressed.png deleted file mode 100644 index d0db2ed..0000000 Binary files a/tools/qvfb/SmartPhone.skin/SmartPhone-pressed.png and /dev/null differ diff --git a/tools/qvfb/SmartPhone.skin/SmartPhone.png b/tools/qvfb/SmartPhone.skin/SmartPhone.png deleted file mode 100644 index e6ac5a0..0000000 Binary files a/tools/qvfb/SmartPhone.skin/SmartPhone.png and /dev/null differ diff --git a/tools/qvfb/SmartPhone.skin/SmartPhone.skin b/tools/qvfb/SmartPhone.skin/SmartPhone.skin deleted file mode 100644 index 2f44c5a..0000000 --- a/tools/qvfb/SmartPhone.skin/SmartPhone.skin +++ /dev/null @@ -1,28 +0,0 @@ -[SkinFile] -Up=SmartPhone.png -Down=SmartPhone-pressed.png -Screen=90 107 176 208 -Areas=21 -HasMouseHover=false - -"1" 0x0031 138 459 149 473 142 483 120 484 102 477 95 464 99 457 121 454 -"2" 0x0032 153 467 202 492 -"3" 0x0033 258 457 260 470 243 483 215 484 207 474 218 460 248 453 -"4" 0x0034 138 492 149 506 142 516 120 517 102 510 95 497 99 490 121 487 -"5" 0x0035 153 499 202 524 -"6" 0x0036 258 489 260 502 243 515 215 516 207 506 218 492 248 485 -"7" 0x0037 138 524 149 538 142 548 120 549 102 542 95 529 99 522 121 519 -"8" 0x0038 153 531 202 556 -"9" 0x0039 258 521 260 534 243 547 215 548 207 538 218 524 248 517 -"*" 0x002a 138 556 149 570 142 580 120 581 102 574 95 561 99 554 121 551 -"0" 0x0030 153 564 202 589 -"#" 0x0023 258 554 260 567 243 580 215 581 207 571 218 557 248 550 -"Call" 0x01100004 88 395 130 439 -"Hangup" 0x01100005 227 395 269 439 -"Context1" 0x01100000 145 321 134 333 132 361 134 374 110 343 109 318 -"Back" 0x01000061 249 322 240 354 219 373 223 344 216 325 208 318 -"Select" 0x01010000 160 338 195 371 -"Left" 0x1000012 159 338 149 328 141 336 141 373 149 381 159 371 159 369 -"Down" 0x1000015 160 373 150 382 159 391 199 391 207 385 196 374 194 374 -"Right" 0x1000014 195 336 206 323 215 338 215 373 208 384 197 375 -"Up" 0x1000013 160 336 149 326 158 319 197 319 203 322 194 337 diff --git a/tools/qvfb/SmartPhone.skin/defaultbuttons.conf b/tools/qvfb/SmartPhone.skin/defaultbuttons.conf deleted file mode 100644 index 1103350..0000000 --- a/tools/qvfb/SmartPhone.skin/defaultbuttons.conf +++ /dev/null @@ -1,78 +0,0 @@ -[Translation] -File=QtopiaDefaults -Context=Buttons -[Menu] -Rows=4 -Columns=3 -Map=123456789*0# -Default=5 -1=Applications/camera.desktop -2=Applications/datebook.desktop -3=Applications -4=Applications/qtmail.desktop -5=Applications/addressbook.desktop -6=Games -7=Settings/Beaming.desktop -8=Applications/simapp.desktop,Applications/calculator.desktop -9=Settings -*=Applications/mediarecorder.desktop -0=Applications/todolist.desktop -#=Documents -Animator=Bounce -AnimatorBackground=Radial -[SoftKeys] -Count=3 -Key0=Context1 -Key1=Select -Key2=Back -[SystemButtons] -Count=5 -Key0=Context1 -Key1=Select -Key2=Back -Key3=Call -Key4=Hangup -[TextButtons] -Buttons=0123456789*# -Hold0='0 -Hold1='1 -Hold2='2 -Hold3='3 -Hold4='4 -Hold5='5 -Hold6='6 -Hold7='7 -Hold8='8 -Hold9='9 -Hold*=symbol -Hold#=mode -Tap0=space -Tap1="\".,'?!-@:1" -Tap2="\"a\xe4\xe5\xe6\xe0\xe1\xe2\x62\x63\xe7\x32" -Tap3="\"de\xe8\xe9\xea\x66\x33" -Tap4="\"ghi\xec\xed\xee\x34" -Tap5="\"jkl5" -Tap6="\"mn\xf1o\xf6\xf8\xf2\xf3\x36" -Tap7="\"pqrs\xdf\x37" -Tap8="\"tu\xfc\xf9\xfav8" -Tap9="\"wxyz9" -Tap*=modify -Tap#=shift -[LocaleTextButtons] -Buttons=23456789 -Tap2[]='abc -Tap3[]='def -Tap4[]='ghi -Tap5[]='jkl -Tap6[]='mno -Tap7[]='pqrs -Tap8[]='tuv -Tap9[]='wxyz -[PhoneTextButtons] -Buttons=*# -Tap*='*+pw -Hold*=+ -Tap#='# -Hold#=mode -[Device] -PrimaryInput=Keypad diff --git a/tools/qvfb/SmartPhone2.qrc b/tools/qvfb/SmartPhone2.qrc deleted file mode 100644 index 751e985..0000000 --- a/tools/qvfb/SmartPhone2.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - SmartPhone2.skin - - diff --git a/tools/qvfb/SmartPhone2.skin/SmartPhone2-pressed.png b/tools/qvfb/SmartPhone2.skin/SmartPhone2-pressed.png deleted file mode 100644 index d4eb5b0..0000000 Binary files a/tools/qvfb/SmartPhone2.skin/SmartPhone2-pressed.png and /dev/null differ diff --git a/tools/qvfb/SmartPhone2.skin/SmartPhone2.png b/tools/qvfb/SmartPhone2.skin/SmartPhone2.png deleted file mode 100644 index 48ccc1c..0000000 Binary files a/tools/qvfb/SmartPhone2.skin/SmartPhone2.png and /dev/null differ diff --git a/tools/qvfb/SmartPhone2.skin/SmartPhone2.skin b/tools/qvfb/SmartPhone2.skin/SmartPhone2.skin deleted file mode 100644 index 16884bf..0000000 --- a/tools/qvfb/SmartPhone2.skin/SmartPhone2.skin +++ /dev/null @@ -1,25 +0,0 @@ -SmartPhone2.png SmartPhone2-pressed.png -90 107 -176 220 -21 -"Menu" 0x01100000 70 400 115 427 -"Backspace" 0x01000003 238 400 285 427 -"1" 0x0031 138 437 149 451 142 461 120 462 102 455 95 442 99 435 121 432 -"2" 0x0032 153 445 202 470 -"3" 0x0033 258 435 260 448 243 461 215 462 207 452 218 438 248 431 -"4" 0x0034 138 470 149 484 142 494 120 495 102 488 95 475 99 468 121 465 -"5" 0x0035 153 477 202 502 -"6" 0x0036 258 467 260 480 243 493 215 494 207 484 218 470 248 463 -"7" 0x0037 138 502 149 516 142 526 120 527 102 520 95 507 99 500 121 497 -"8" 0x0038 153 509 202 534 -"9" 0x0039 258 499 260 512 243 525 215 526 207 516 218 502 248 495 -"*" 0x002a 138 534 149 548 142 558 120 559 102 552 95 539 99 532 121 529 -"0" 0x0030 153 542 202 567 -"#" 0x0023 258 532 260 545 243 558 215 559 207 549 218 535 248 528 -"Yes" 0x01010001 91 343 141 393 -"No" 0x01010002 219 343 269 393 -"Select" 0x01010000 160 356 195 389 -"Left" 0x1000012 159 356 149 346 141 354 141 391 149 399 159 389 159 387 -"Down" 0x1000015 160 391 150 400 159 409 199 409 207 403 196 392 194 392 -"Right" 0x1000014 195 354 206 341 215 356 215 391 208 402 197 393 -"Up" 0x1000013 160 354 149 344 158 337 197 337 203 340 194 355 diff --git a/tools/qvfb/SmartPhone2.skin/defaultbuttons.conf b/tools/qvfb/SmartPhone2.skin/defaultbuttons.conf deleted file mode 100644 index b083203..0000000 --- a/tools/qvfb/SmartPhone2.skin/defaultbuttons.conf +++ /dev/null @@ -1,52 +0,0 @@ -[Button] -[IMethod] -key_count = 5 -key_hold_action_1 = insertText -key_hold_action_2 = insertText -key_hold_action_3 = insertSymbol -key_hold_action_4 = changeMode -key_hold_arg_1 = 1 -key_hold_arg_2 = 0 -key_id_1 = 1 -key_id_2 = 0 -key_id_3 = * -key_id_4 = # -key_id_5 = * -key_mode_1 = Abc -key_mode_2 = Abc -key_mode_3 = Abc -key_mode_4 = Abc -key_mode_5 = Phone -key_tap_action_1 = insertText -key_tap_action_2 = insertSpace -key_tap_action_3 = modifyText -key_tap_action_4 = changeShift -key_tap_action_5 = insertText -key_tap_arg_1 = .,'?!-@:〓 -key_tap_arg_5 = *+pw -[Menu] -1 = Applications/camera.desktop -2 = Applications/datebook.desktop -3 = Games -4 = Applications/qtmail.desktop -5 = Applications/addressbook.desktop -6 = Settings -7 = Settings/Beaming.desktop -8 = Applications -9 = Documents -Columns = 3 -Default = 5 -Map = 123456789 -Rows = 3 -Animator=Bounce -AnimatorBackground=Radial -[SoftKeys] -[SystemButtons] -Count=5 -Key0=Yes -Key1=Select -Key2=No -Key3=Menu -Key4=Backspace -[Device] -PrimaryInput=Keypad diff --git a/tools/qvfb/SmartPhoneWithButtons.qrc b/tools/qvfb/SmartPhoneWithButtons.qrc deleted file mode 100644 index f3393ba..0000000 --- a/tools/qvfb/SmartPhoneWithButtons.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - SmartPhoneWithButtons.skin - - diff --git a/tools/qvfb/SmartPhoneWithButtons.skin/SmartPhoneWithButtons-pressed.png b/tools/qvfb/SmartPhoneWithButtons.skin/SmartPhoneWithButtons-pressed.png deleted file mode 100644 index 456a068..0000000 Binary files a/tools/qvfb/SmartPhoneWithButtons.skin/SmartPhoneWithButtons-pressed.png and /dev/null differ diff --git a/tools/qvfb/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.png b/tools/qvfb/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.png deleted file mode 100644 index 5ffbd6e..0000000 Binary files a/tools/qvfb/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.png and /dev/null differ diff --git a/tools/qvfb/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.skin b/tools/qvfb/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.skin deleted file mode 100644 index 9afa67f..0000000 --- a/tools/qvfb/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.skin +++ /dev/null @@ -1,31 +0,0 @@ -[SkinFile] -Up=SmartPhoneWithButtons.png -Down=SmartPhoneWithButtons-pressed.png -Screen=90 107 176 208 -Areas=24 -HasMouseHover=false - -"1" 0x0031 138 459 149 473 142 483 120 484 102 477 95 464 99 457 121 454 -"2" 0x0032 153 467 202 492 -"3" 0x0033 258 457 260 470 243 483 215 484 207 474 218 460 248 453 -"4" 0x0034 138 492 149 506 142 516 120 517 102 510 95 497 99 490 121 487 -"5" 0x0035 153 499 202 524 -"6" 0x0036 258 489 260 502 243 515 215 516 207 506 218 492 248 485 -"7" 0x0037 138 524 149 538 142 548 120 549 102 542 95 529 99 522 121 519 -"8" 0x0038 153 531 202 556 -"9" 0x0039 258 521 260 534 243 547 215 548 207 538 218 524 248 517 -"*" 0x002a 138 556 149 570 142 580 120 581 102 574 95 561 99 554 121 551 -"0" 0x0030 153 564 202 589 -"#" 0x0023 258 554 260 567 243 580 215 581 207 571 218 557 248 550 -"Call" 0x01100004 88 395 130 439 -"Hangup" 0x01100005 227 395 269 439 -"Context1" 0x01100000 145 321 134 333 132 361 134 374 110 343 109 318 -"Back" 0x01000061 249 322 240 354 219 373 223 344 216 325 208 318 -"Select" 0x01010000 160 338 195 371 -"Left" 0x1000012 159 338 149 328 141 336 141 373 149 381 159 371 159 369 -"Down" 0x1000015 160 373 150 382 159 391 199 391 207 385 196 374 194 374 -"Right" 0x1000014 195 336 206 323 215 338 215 373 208 384 197 375 -"Up" 0x1000013 160 336 149 326 158 319 197 319 203 322 194 337 -"Home" 0x1000010 164 402 195 434 -"F1" 0x1000030 138 422 163 448 -"F2" 0x1000031 196 422 220 448 diff --git a/tools/qvfb/SmartPhoneWithButtons.skin/defaultbuttons.conf b/tools/qvfb/SmartPhoneWithButtons.skin/defaultbuttons.conf deleted file mode 100644 index ebd6926..0000000 --- a/tools/qvfb/SmartPhoneWithButtons.skin/defaultbuttons.conf +++ /dev/null @@ -1,103 +0,0 @@ -[Translation] -File=QtopiaDefaults -Context=Buttons -[Button] -Count=3 -[Button0] -Name[]=Calendar Button -Key=F1 -PressedActionService=Calendar -PressedActionMessage=raiseToday() -HeldActionService=Calendar -HeldActionMessage=newEvent() -[Button1] -Name[]=Tasks Button -Key=F2 -PressedActionService=Tasks -PressedActionMessage=raise() -HeldActionService=Tasks -HeldActionMessage=newTask() -[Button2] -Name[]=Home Button -Key=Home -PressedActionMappable=0 -PressedActionService=TaskManager -PressedActionMessage=multitask() -HeldActionMappable=0 -HeldActionService=TaskManager -HeldActionMessage=showRunningTasks() -[Menu] -Rows=4 -Columns=3 -Map=123456789*0# -Default=5 -1=Applications/camera.desktop -2=Applications/datebook.desktop -3=Applications -4=Applications/qtmail.desktop -5=Applications/addressbook.desktop -6=Games -7=Settings/Beaming.desktop -8=Applications/simapp.desktop,Applications/calculator.desktop -9=Settings -*=Applications/mediarecorder.desktop -0=Applications/todolist.desktop -#=Documents -Animator=Bounce -AnimatorBackground=Radial -[SoftKeys] -Count=3 -Key0=Context1 -Key1=Select -Key2=Back -[SystemButtons] -Count=5 -Key0=Context1 -Key1=Select -Key2=Back -Key3=Call -Key4=Hangup -[TextButtons] -Buttons=0123456789*# -Hold0='0 -Hold1='1 -Hold2='2 -Hold3='3 -Hold4='4 -Hold5='5 -Hold6='6 -Hold7='7 -Hold8='8 -Hold9='9 -Hold*=symbol -Hold#=mode -Tap0=space -Tap1="\".,'?!-@:1" -Tap2="\"a\xe4\xe5\xe6\xe0\xe1\xe2\x62\x63\xe7\x32" -Tap3="\"de\xe8\xe9\xea\x66\x33" -Tap4="\"ghi\xec\xed\xee\x34" -Tap5="\"jkl5" -Tap6="\"mn\xf1o\xf6\xf8\xf2\xf3\x36" -Tap7="\"pqrs\xdf\x37" -Tap8="\"tu\xfc\xf9\xfav8" -Tap9="\"wxyz9" -Tap*=modify -Tap#=shift -[LocaleTextButtons] -Buttons=23456789 -Tap2[]='abc -Tap3[]='def -Tap4[]='ghi -Tap5[]='jkl -Tap6[]='mno -Tap7[]='pqrs -Tap8[]='tuv -Tap9[]='wxyz -[PhoneTextButtons] -Buttons=*# -Tap*='*+pw -Hold*=+ -Tap#='# -Hold#=mode -[Device] -PrimaryInput=Keypad diff --git a/tools/qvfb/TouchscreenPhone.qrc b/tools/qvfb/TouchscreenPhone.qrc deleted file mode 100644 index 023144d..0000000 --- a/tools/qvfb/TouchscreenPhone.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - TouchscreenPhone.skin - - diff --git a/tools/qvfb/TouchscreenPhone.skin/TouchscreenPhone-pressed.png b/tools/qvfb/TouchscreenPhone.skin/TouchscreenPhone-pressed.png deleted file mode 100644 index 01acb86..0000000 Binary files a/tools/qvfb/TouchscreenPhone.skin/TouchscreenPhone-pressed.png and /dev/null differ diff --git a/tools/qvfb/TouchscreenPhone.skin/TouchscreenPhone.png b/tools/qvfb/TouchscreenPhone.skin/TouchscreenPhone.png deleted file mode 100644 index e90de0d..0000000 Binary files a/tools/qvfb/TouchscreenPhone.skin/TouchscreenPhone.png and /dev/null differ diff --git a/tools/qvfb/TouchscreenPhone.skin/TouchscreenPhone.skin b/tools/qvfb/TouchscreenPhone.skin/TouchscreenPhone.skin deleted file mode 100644 index 24316a1..0000000 --- a/tools/qvfb/TouchscreenPhone.skin/TouchscreenPhone.skin +++ /dev/null @@ -1,16 +0,0 @@ -[SkinFile] -Up=TouchscreenPhone.png -Down=TouchscreenPhone-pressed.png -Screen=90 107 176 208 -Areas=9 -HasMouseHover=false - -"Context1" 0x01100000 145 321 134 333 132 361 134 374 110 343 109 318 -"Call" 0x01100004 88 395 130 439 -"Hangup" 0x01100005 227 395 269 439 -"Back" 0x01000061 249 322 240 354 219 373 223 344 216 325 208 318 -"Left" 0x1000012 159 338 149 328 141 336 141 373 149 381 159 371 159 369 -"Down" 0x1000015 160 373 150 382 159 391 199 391 207 385 196 374 194 374 -"Right" 0x1000014 195 336 206 323 215 338 215 373 208 384 197 375 -"Up" 0x1000013 160 336 149 326 158 319 197 319 203 322 194 337 -"Select" 0x01010000 160 338 195 371 diff --git a/tools/qvfb/TouchscreenPhone.skin/defaultbuttons.conf b/tools/qvfb/TouchscreenPhone.skin/defaultbuttons.conf deleted file mode 100644 index a13dfdc..0000000 --- a/tools/qvfb/TouchscreenPhone.skin/defaultbuttons.conf +++ /dev/null @@ -1,45 +0,0 @@ -[Translation] -File=QtopiaDefaults -Context=Buttons -[Menu] -Rows=4 -Columns=3 -Map=123456789*0# -Default=5 -1=Applications/camera.desktop -2=Applications/datebook.desktop -3=Applications -4=Applications/qtmail.desktop -5=Applications/addressbook.desktop -6=Games -7=Settings/Beaming.desktop -8=Applications/simapp.desktop,Applications/calculator.desktop -9=Settings -*=Applications/mediarecorder.desktop -0=Applications/todolist.desktop -#=Documents -Animator=Bounce -AnimatorBackground=Radial -[SoftKeys] -Count=3 -Key0=Context1 -Key1=Select -Key2=Back -[SystemButtons] -Count=5 -Key0=Context1 -Key1=Back -Key2=Select -Key3=Call -Key4=Hangup -[Button] -Count=1 -[Button0] -Name=Power Button -Key=Hangup -HeldActionService=Launcher -HeldActionMessage=execute(QString) -HeldActionArgs=@ByteArray(\0\0\0\x1\0\0\0\n\0\0\0\0\x10\0s\0h\0u\0t\0\x64\0o\0w\0n) -[Device] -PrimaryInput=Touchscreen - diff --git a/tools/qvfb/Trolltech-Keypad.qrc b/tools/qvfb/Trolltech-Keypad.qrc deleted file mode 100644 index 4775068..0000000 --- a/tools/qvfb/Trolltech-Keypad.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - Trolltech-Keypad.skin - - diff --git a/tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad-closed.png b/tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad-closed.png deleted file mode 100644 index 8dd5719..0000000 Binary files a/tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad-closed.png and /dev/null differ diff --git a/tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad-down.png b/tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad-down.png deleted file mode 100644 index 5e1e6be..0000000 Binary files a/tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad-down.png and /dev/null differ diff --git a/tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad.png b/tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad.png deleted file mode 100644 index fb3d549..0000000 Binary files a/tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad.png and /dev/null differ diff --git a/tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad.skin b/tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad.skin deleted file mode 100644 index 4d90321..0000000 --- a/tools/qvfb/Trolltech-Keypad.skin/Trolltech-Keypad.skin +++ /dev/null @@ -1,35 +0,0 @@ -[SkinFile] -Up=Trolltech-Keypad.png -Down=Trolltech-Keypad-down.png -Closed=Trolltech-Keypad-closed.png -ClosedAreas=F1 F2 F3 Flip -ClosedScreen=95 456 128 96 -Screen=75 85 176 220 -Areas=25 -HasMouseHover=false -"1" 0x0031 65 542 68 536 76 532 114 536 114 573 64 568 -"2" 0x0032 133 537 188 574 -"3" 0x0033 206 536 246 532 252 536 256 542 258 569 205 572 -"4" 0x0034 64 578 114 618 -"5" 0x0035 133 581 188 618 -"6" 0x0036 206 580 256 577 258 613 206 616 -"7" 0x0037 66 622 116 625 114 662 66 658 -"8" 0x0038 133 626 188 662 -"9" 0x0039 206 625 256 622 256 658 206 661 -"*" 0x002a 68 667 116 670 114 705 86 699 76 693 69 686 -"0" 0x0030 133 671 188 708 -"#" 0x0023 206 670 254 665 254 684 245 692 232 699 206 704 -"Context1" 0x01100000 69 420 75 410 85 404 101 404 102 458 69 458 -"Back" 0x01000061 218 404 234 404 240 408 248 418 248 456 218 457 -"Home" 0x1000010 140 494 180 514 -"Hangup" 0x01100005 218 457 248 456 248 496 243 507 230 514 194 514 194 494 206 492 213 486 218 478 -"Call" 0x01100004 68 458 102 460 102 479 108 487 118 492 126 494 126 514 86 514 77 507 72 496 -"Select" 0x01010000 138 426 182 458 -"Up" 0x1000013 118 406 201 402 184 423 134 422 -"Right" 0x1000014 184 424 201 402 202 476 184 460 -"Down" 0x1000015 135 462 184 461 199 477 118 477 -"Left" 0x1000012 118 406 134 424 134 461 117 476 -"F1" 0x1000030 0 408 45 456 -"F2" 0x1000031 0 456 45 509 -"F3" 0x1000032 0 545 45 582 -"Flip" 0x1100006 32 353 293 386 diff --git a/tools/qvfb/Trolltech-Keypad.skin/defaultbuttons.conf b/tools/qvfb/Trolltech-Keypad.skin/defaultbuttons.conf deleted file mode 100644 index 6a78e67..0000000 --- a/tools/qvfb/Trolltech-Keypad.skin/defaultbuttons.conf +++ /dev/null @@ -1,142 +0,0 @@ -[Translation] -File=QtopiaDefaults -Context=Buttons -[Button] -Count=8 -[Button7] -Name[]=Home Down Button -Key=Down -Context=HomeScreen -PressedActionMappable=0 -HeldActionService=Messaging -HeldActionMessage=raise() -[Button6] -Name[]=Home Up Button -Key=Up -Context=HomeScreen -PressedActionMappable=0 -HeldActionService=Contacts -HeldActionMessage=raise() -[Button5] -Name[]=Home Right Button -Key=Right -Context=HomeScreen -PressedActionMappable=0 -HeldActionService=mediaplayer -HeldActionMessage=raise() -[Button4] -Name[]=Calender Button -Key=Left -Context=HomeScreen -PressedActionMappable=0 -HeldActionService=Calendar -HeldActionMessage=raiseToday() -[Button3] -Name[]=Left Soft Key -Key=Context1 -HeldActionService=TaskManager -HeldActionMessage=showRunningTasks() -HeldActionMappable=0 -PressActionMappable=0 -[Button2] -Name[]=VoiceNotes Button -Key=F1 -PressedActionService=mediarecorder -PressedActionMessage=raise() -HeldActionService=mediarecorder -HeldActionMessage=newEvent() -[Button1] -Name[]=Camera Button -Key=F2 -PressedActionService=Camera -PressedActionMessage=raise() -HeldActionService=Tasks -HeldActionMessage=newTask() -[Button0] -Name[]=Home Button -Key=Home -PressedActionMappable=0 -PressedActionService=TaskManager -PressedActionMessage=multitask() -HeldActionMappable=0 -HeldActionService=TaskManager -HeldActionMessage=showRunningTasks() -[Menu] -Rows=4 -Columns=3 -Map=123456789*0# -Default=5 -1=Applications/camera.desktop -2=Applications/mediaplayer.desktop -3=Applications/simapp.desktop,Applications/calculator.desktop -4=Applications/qtmail.desktop -5=Applications/addressbook.desktop -6=Applications/datebook.desktop -7=Games -8=Settings/Beaming.desktop -9=Applications/todolist.desktop -*=Settings -0=Applications -#=Documents -Animator=Bounce -AnimatorBackground=Radial -[SoftKeys] -Count=3 -Key0=Context1 -Key1=Select -Key2=Back -[SystemButtons] -Count=6 -Key0=Context1 -Key1=Select -Key2=Back -Key3=Call -Key4=Hangup -Key5=Flip -[TextButtons] -Buttons=0123456789*# -Hold0='0 -Hold1='1 -Hold2='2 -Hold3='3 -Hold4='4 -Hold5='5 -Hold6='6 -Hold7='7 -Hold8='8 -Hold9='9 -Hold*=symbol -Hold#=mode -Tap0=space -Tap0=space -Tap1="\".,'?!-@:1" -Tap2="\"a\xe4\xe5\xe6\xe0\xe1\xe2\x62\x63\xe7\x32" -Tap3="\"de\xe8\xe9\xea\x66\x33" -Tap4="\"ghi\xec\xed\xee\x34" -Tap5="\"jkl5" -Tap6="\"mn\xf1o\xf6\xf8\xf2\xf3\x36" -Tap7="\"pqrs\xdf\x37" -Tap8="\"tu\xfc\xf9\xfav8" -Tap9="\"wxyz9" -Tap*=modify -Tap#=shift -[LocaleTextButtons] -Buttons=23456789 -Tap2[]='abc -Tap3[]='def -Tap4[]='ghi -Tap5[]='jkl -Tap6[]='mno -Tap7[]='pqrs -Tap8[]='tuv -Tap9[]='wxyz -[PhoneTextButtons] -Buttons=*# -Tap*='*+pw -Hold*=+ -Tap#='# -Hold#=mode -[Device] -PrimaryInput=Keypad -[Environment] -QWS_DISPLAY=Multi: LinuxFb:mmHeight57:0 LinuxFb:offset=0,320:1 :0 diff --git a/tools/qvfb/Trolltech-Touchscreen.qrc b/tools/qvfb/Trolltech-Touchscreen.qrc deleted file mode 100644 index 40fafeb..0000000 --- a/tools/qvfb/Trolltech-Touchscreen.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - Trolltech-Touchscreen.skin - - diff --git a/tools/qvfb/Trolltech-Touchscreen.skin/Trolltech-Touchscreen-down.png b/tools/qvfb/Trolltech-Touchscreen.skin/Trolltech-Touchscreen-down.png deleted file mode 100644 index c1a422f..0000000 Binary files a/tools/qvfb/Trolltech-Touchscreen.skin/Trolltech-Touchscreen-down.png and /dev/null differ diff --git a/tools/qvfb/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.png b/tools/qvfb/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.png deleted file mode 100644 index 544a425..0000000 Binary files a/tools/qvfb/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.png and /dev/null differ diff --git a/tools/qvfb/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.skin b/tools/qvfb/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.skin deleted file mode 100644 index 5de882e..0000000 --- a/tools/qvfb/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.skin +++ /dev/null @@ -1,17 +0,0 @@ -[SkinFile] -Up=Trolltech-Touchscreen.png -Down=Trolltech-Touchscreen-down.png -Screen=40 109 176 220 -Areas=10 -HasMouseHover=false - -"Context1" 0x01100000 38 420 44 408 52 404 68 403 68 458 40 458 -"Back" 0x01000061 185 42 202 398 211 410 216 418 219 456 186 456 -"Call" 0x01100004 38 458 70 458 71 478 75 486 83 492 94 494 94 516 56 516 45 507 38 498 -"Hangup" 0x01100005 186 458 220 458 220 496 214 508 200 516 162 516 161 494 172 492 180 486 185 478 -"Left" 0x1000012 86 405 106 426 106 461 85 478 -"Down" 0x1000015 106 460 151 460 170 480 85 480 -"Right" 0x1000014 151 424 170 404 170 480 151 460 -"Up" 0x1000013 85 403 168 403 150 424 106 424 -"Select" 0x01010000 106 426 150 456 -"Home" 0x1000010 105 493 145 512 diff --git a/tools/qvfb/Trolltech-Touchscreen.skin/defaultbuttons.conf b/tools/qvfb/Trolltech-Touchscreen.skin/defaultbuttons.conf deleted file mode 100644 index 6665125..0000000 --- a/tools/qvfb/Trolltech-Touchscreen.skin/defaultbuttons.conf +++ /dev/null @@ -1,53 +0,0 @@ -[Translation] -File=QtopiaDefaults -Context=Buttons -[Menu] -Rows=4 -Columns=3 -Map=123456789*0# -Default=5 -1=Applications/camera.desktop -2=Applications/mediaplayer.desktop -3=Applications/simapp.desktop,Applications/calculator.desktop -4=Applications/qtmail.desktop -5=Applications/addressbook.desktop -6=Applications/datebook.desktop -7=Games -8=Settings/beaming.desktop -9=Applications/todolist.desktop -*=Settings -0=Applications -#=Documents -Animator=Bounce -AnimatorBackground=Radial -[SoftKeys] -Count=3 -Key0=Context1 -Key1=Select -Key2=Back -[SystemButtons] -Count=5 -Key0=Context1 -Key1=Back -Key2=Select -Key3=Call -Key4=Hangup -[Device] -PrimaryInput=Touchscreen -[Button] -Count=2 -[Button0] -Name[]=Home Button -Key=Home -PressedActionMappable=0 -PressedActionService=TaskManager -PressedActionMessage=multitask() -HeldActionMappable=0 -HeldActionService=TaskManager -HeldActionMessage=showRunningTasks() -[Button1] -Name=Power Button -Key=Hangup -HeldActionService=Launcher -HeldActionMessage=execute(QString) -HeldActionArgs=@ByteArray(\0\0\0\x1\0\0\0\n\0\0\0\0\x10\0s\0h\0u\0t\0\x64\0o\0w\0n) diff --git a/tools/qvfb/pda.qrc b/tools/qvfb/pda.qrc deleted file mode 100644 index b14e7b3..0000000 --- a/tools/qvfb/pda.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - pda.skin - - diff --git a/tools/qvfb/pda.skin b/tools/qvfb/pda.skin deleted file mode 100644 index 037f750..0000000 --- a/tools/qvfb/pda.skin +++ /dev/null @@ -1,14 +0,0 @@ -pda_up.png pda_down.png -57 81 -240 320 -11 -"Power" 0x0100000a 277 36 302 57 -"F1" 0x01000030 52 439 81 470 -"F2" 0x01000031 101 422 130 451 -"F3" 0x01000032 232 423 260 452 -"F4" 0x01000033 279 445 309 473 -"Left" 0x01000012 155 438 176 472 -"Down" 0x01000015 169 471 203 486 -"Right" 0x01000014 193 448 215 472 -"Up" 0x01000013 166 427 199 451 -"Enter" 0x01000005 177 448 193 468 diff --git a/tools/qvfb/pda_down.png b/tools/qvfb/pda_down.png deleted file mode 100644 index 0ea157d..0000000 Binary files a/tools/qvfb/pda_down.png and /dev/null differ diff --git a/tools/qvfb/pda_up.png b/tools/qvfb/pda_up.png deleted file mode 100644 index 541e3c4..0000000 Binary files a/tools/qvfb/pda_up.png and /dev/null differ diff --git a/tools/qvfb/qvfb.pro b/tools/qvfb/qvfb.pro index 85c4d96..247337a 100644 --- a/tools/qvfb/qvfb.pro +++ b/tools/qvfb/qvfb.pro @@ -60,15 +60,4 @@ unix:x11 { LIBS += -lXtst } -RESOURCES += qvfb.qrc \ - ClamshellPhone.qrc \ - PDAPhone.qrc \ - SmartPhone2.qrc \ - SmartPhone.qrc \ - SmartPhoneWithButtons.qrc \ - TouchscreenPhone.qrc \ - Trolltech-Keypad.qrc \ - Trolltech-Touchscreen.qrc \ - PortableMedia.qrc \ - S60-QVGA-Candybar.qrc \ - S60-nHD-Touchscreen.qrc +RESOURCES += qvfb.qrc diff --git a/tools/shared/deviceskin/deviceskin.pri b/tools/shared/deviceskin/deviceskin.pri index e4c9ef7..2552c92 100644 --- a/tools/shared/deviceskin/deviceskin.pri +++ b/tools/shared/deviceskin/deviceskin.pri @@ -1,3 +1,15 @@ INCLUDEPATH += $$PWD HEADERS += $$PWD/deviceskin.h SOURCES += $$PWD/deviceskin.cpp +RESOURCES += $$PWD/skins/ClamshellPhone.qrc \ + $$PWD/skins/PDAPhone.qrc \ + $$PWD/skins/SmartPhone2.qrc \ + $$PWD/skins/SmartPhone.qrc \ + $$PWD/skins/SmartPhoneWithButtons.qrc \ + $$PWD/skins/TouchscreenPhone.qrc \ + $$PWD/skins/Trolltech-Keypad.qrc \ + $$PWD/skins/Trolltech-Touchscreen.qrc \ + $$PWD/skins/PortableMedia.qrc \ + $$PWD/skins/S60-QVGA-Candybar.qrc \ + $$PWD/skins/S60-nHD-Touchscreen.qrc + diff --git a/tools/shared/deviceskin/skins/ClamshellPhone.qrc b/tools/shared/deviceskin/skins/ClamshellPhone.qrc new file mode 100644 index 0000000..39cd422 --- /dev/null +++ b/tools/shared/deviceskin/skins/ClamshellPhone.qrc @@ -0,0 +1,5 @@ + + + ClamshellPhone.skin + + diff --git a/tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone.skin b/tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone.skin new file mode 100644 index 0000000..cb24a8e --- /dev/null +++ b/tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone.skin @@ -0,0 +1,30 @@ +[SkinFile] +Up=ClamshellPhone1-5.png +Down=ClamshellPhone1-5-pressed.png +Closed=ClamshellPhone1-5-closed.png +Screen=72 84 176 208 +Areas=22 +HasMouseHover=false + +"Power" 0x0100000a 205 563 249 586 +"1" 0x0031 62 414 119 438 +"2" 0x0032 130 414 189 438 +"3" 0x0033 198 413 257 438 +"4" 0x0034 54 444 117 470 +"5" 0x0035 128 444 189 471 +"6" 0x0036 202 444 264 471 +"7" 0x0037 47 477 113 507 +"8" 0x0038 126 477 190 507 +"9" 0x0039 205 478 270 509 +"*" 0x002a 39 515 110 552 +"0" 0x0030 122 515 195 553 +"#" 0x0023 207 516 280 553 +"Context1" 0x01100000 137 360 108 383 123 410 90 409 60 387 63 378 100 362 +"Back" 0x01000061 184 361 206 376 213 387 197 410 226 410 256 392 258 381 244 369 +"Backspace" 0x01000003 68 563 113 587 +"Select" 0x01010000 160 391 172 390 181 386 184 381 180 377 173 373 165 372 155 372 145 375 138 378 136 382 138 387 147 390 +"Left" 0x1000012 141 390 136 385 136 381 143 375 132 371 120 380 121 393 129 401 +"Down" 0x1000015 143 389 130 402 162 412 191 404 175 390 +"Right" 0x1000014 186 370 176 375 184 382 182 387 175 390 190 404 201 396 202 375 +"Up" 0x1000013 133 370 143 374 176 374 185 370 169 362 149 362 +"Flip" 0x01100006 98 325 225 353 diff --git a/tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone1-5-closed.png b/tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone1-5-closed.png new file mode 100644 index 0000000..88ba3a1 Binary files /dev/null and b/tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone1-5-closed.png differ diff --git a/tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone1-5-pressed.png b/tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone1-5-pressed.png new file mode 100644 index 0000000..971cdef Binary files /dev/null and b/tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone1-5-pressed.png differ diff --git a/tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone1-5.png b/tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone1-5.png new file mode 100644 index 0000000..f3550ee Binary files /dev/null and b/tools/shared/deviceskin/skins/ClamshellPhone.skin/ClamshellPhone1-5.png differ diff --git a/tools/shared/deviceskin/skins/ClamshellPhone.skin/defaultbuttons.conf b/tools/shared/deviceskin/skins/ClamshellPhone.skin/defaultbuttons.conf new file mode 100644 index 0000000..e349dbc --- /dev/null +++ b/tools/shared/deviceskin/skins/ClamshellPhone.skin/defaultbuttons.conf @@ -0,0 +1,78 @@ +[Translation] +File=QtopiaDefaults +Context=Buttons +[Menu] +Rows=4 +Columns=3 +Map=123456789*0# +Default=5 +1=Applications/camera.desktop +2=Applications/datebook.desktop +3=Applications +4=Applications/qtmail.desktop +5=Applications/addressbook.desktop +6=Games +7=Settings/Beaming.desktop +8=Applications/simapp.desktop,Applications/calculator.desktop +9=Settings +*=Applications/mediarecorder.desktop +0=Applications/todolist.desktop +#=Documents +Animator=Bounce +AnimatorBackground=Radial +[SoftKeys] +Count=3 +Key0=Context1 +Key1=Select +Key2=Back +[SystemButtons] +Count=5 +Key0=Context1 +Key1=Select +Key2=Back +Key3=Flip +Key4=Backspace +[TextButtons] +Buttons=0123456789*# +Hold0='0 +Hold1='1 +Hold2='2 +Hold3='3 +Hold4='4 +Hold5='5 +Hold6='6 +Hold7='7 +Hold8='8 +Hold9='9 +Hold*=symbol +Hold#=mode +Tap0=space +Tap1="\".,'?!-@:1" +Tap2="\"a\xe4\xe5\xe6\xe0\xe1\xe2\x62\x63\xe7\x32" +Tap3="\"de\xe8\xe9\xea\x66\x33" +Tap4="\"ghi\xec\xed\xee\x34" +Tap5="\"jkl5" +Tap6="\"mn\xf1o\xf6\xf8\xf2\xf3\x36" +Tap7="\"pqrs\xdf\x37" +Tap8="\"tu\xfc\xf9\xfav8" +Tap9="\"wxyz9" +Tap*=modify +Tap#=shift +[LocaleTextButtons] +Buttons=23456789 +Tap2[]='abc +Tap3[]='def +Tap4[]='ghi +Tap5[]='jkl +Tap6[]='mno +Tap7[]='pqrs +Tap8[]='tuv +Tap9[]='wxyz +[PhoneTextButtons] +Buttons=*# +Tap*='*+pw +Hold*=+ +Tap#=# +Hold#=mode +[Device] +PrimaryInput=Keypad diff --git a/tools/shared/deviceskin/skins/DualScreenPhone.skin/DualScreen-pressed.png b/tools/shared/deviceskin/skins/DualScreenPhone.skin/DualScreen-pressed.png new file mode 100644 index 0000000..d62ef4a Binary files /dev/null and b/tools/shared/deviceskin/skins/DualScreenPhone.skin/DualScreen-pressed.png differ diff --git a/tools/shared/deviceskin/skins/DualScreenPhone.skin/DualScreen.png b/tools/shared/deviceskin/skins/DualScreenPhone.skin/DualScreen.png new file mode 100644 index 0000000..cb3d1a7 Binary files /dev/null and b/tools/shared/deviceskin/skins/DualScreenPhone.skin/DualScreen.png differ diff --git a/tools/shared/deviceskin/skins/DualScreenPhone.skin/DualScreenPhone.skin b/tools/shared/deviceskin/skins/DualScreenPhone.skin/DualScreenPhone.skin new file mode 100644 index 0000000..a82ef23 --- /dev/null +++ b/tools/shared/deviceskin/skins/DualScreenPhone.skin/DualScreenPhone.skin @@ -0,0 +1,29 @@ +[SkinFile] +Up=DualScreen.png +Down=DualScreen-pressed.png +Screen=128 155 176 208 +BackScreen=18 44 98 119 +Areas=21 +HasMouseHover=false + +"Context1" 0x1100000 144 368 189 368 168 396 176 427 150 398 +"Back" 0x1000061 245 365 291 366 283 398 258 424 265 394 +"Select" 0x1010000 202 401 210 389 224 388 233 402 224 415 208 415 +"Up" 0x1000013 202 381 196 374 218 363 239 373 229 382 +"Left" 0x1000012 199 385 189 375 176 403 185 426 197 415 194 401 +"Right" 0x1000014 235 390 248 379 253 402 246 421 238 413 +"Down" 0x1000015 204 421 233 422 241 432 214 443 191 430 +"Call" 0x1100004 163 452 137 450 125 465 136 484 159 485 169 467 +"Hangup" 0x1100005 266 475 279 448 295 447 309 460 301 480 289 487 +"1" 0x31 175 514 147 504 133 518 161 532 180 534 +"2" 0x32 199 515 229 519 238 533 222 540 195 538 +"2" 0x32 260 512 286 506 299 513 284 527 264 535 248 525 +"4" 0x34 164 541 177 546 182 560 164 565 146 560 135 545 154 539 +"5" 0x35 204 546 225 546 243 560 231 574 205 573 191 558 +"6" 0x36 257 547 281 537 294 540 287 555 274 566 254 561 +"7" 0x37 145 569 176 578 177 595 156 597 138 584 +"8" 0x38 197 582 229 584 241 593 226 604 201 603 189 594 +"9" 0x39 253 577 288 564 301 578 283 593 259 597 251 586 +"*" 0x2a 145 598 181 611 182 623 163 632 144 623 138 607 +"0" 0x30 196 611 233 613 240 630 220 642 193 637 191 622 +"#" 0x23 255 610 286 600 302 615 279 625 258 629 247 616 diff --git a/tools/shared/deviceskin/skins/DualScreenPhone.skin/defaultbuttons.conf b/tools/shared/deviceskin/skins/DualScreenPhone.skin/defaultbuttons.conf new file mode 100644 index 0000000..1103350 --- /dev/null +++ b/tools/shared/deviceskin/skins/DualScreenPhone.skin/defaultbuttons.conf @@ -0,0 +1,78 @@ +[Translation] +File=QtopiaDefaults +Context=Buttons +[Menu] +Rows=4 +Columns=3 +Map=123456789*0# +Default=5 +1=Applications/camera.desktop +2=Applications/datebook.desktop +3=Applications +4=Applications/qtmail.desktop +5=Applications/addressbook.desktop +6=Games +7=Settings/Beaming.desktop +8=Applications/simapp.desktop,Applications/calculator.desktop +9=Settings +*=Applications/mediarecorder.desktop +0=Applications/todolist.desktop +#=Documents +Animator=Bounce +AnimatorBackground=Radial +[SoftKeys] +Count=3 +Key0=Context1 +Key1=Select +Key2=Back +[SystemButtons] +Count=5 +Key0=Context1 +Key1=Select +Key2=Back +Key3=Call +Key4=Hangup +[TextButtons] +Buttons=0123456789*# +Hold0='0 +Hold1='1 +Hold2='2 +Hold3='3 +Hold4='4 +Hold5='5 +Hold6='6 +Hold7='7 +Hold8='8 +Hold9='9 +Hold*=symbol +Hold#=mode +Tap0=space +Tap1="\".,'?!-@:1" +Tap2="\"a\xe4\xe5\xe6\xe0\xe1\xe2\x62\x63\xe7\x32" +Tap3="\"de\xe8\xe9\xea\x66\x33" +Tap4="\"ghi\xec\xed\xee\x34" +Tap5="\"jkl5" +Tap6="\"mn\xf1o\xf6\xf8\xf2\xf3\x36" +Tap7="\"pqrs\xdf\x37" +Tap8="\"tu\xfc\xf9\xfav8" +Tap9="\"wxyz9" +Tap*=modify +Tap#=shift +[LocaleTextButtons] +Buttons=23456789 +Tap2[]='abc +Tap3[]='def +Tap4[]='ghi +Tap5[]='jkl +Tap6[]='mno +Tap7[]='pqrs +Tap8[]='tuv +Tap9[]='wxyz +[PhoneTextButtons] +Buttons=*# +Tap*='*+pw +Hold*=+ +Tap#='# +Hold#=mode +[Device] +PrimaryInput=Keypad diff --git a/tools/shared/deviceskin/skins/PDAPhone.qrc b/tools/shared/deviceskin/skins/PDAPhone.qrc new file mode 100644 index 0000000..1a1c35a --- /dev/null +++ b/tools/shared/deviceskin/skins/PDAPhone.qrc @@ -0,0 +1,5 @@ + + + PDAPhone.skin + + diff --git a/tools/shared/deviceskin/skins/PDAPhone.skin/PDAPhone.skin b/tools/shared/deviceskin/skins/PDAPhone.skin/PDAPhone.skin new file mode 100644 index 0000000..d6a1966 --- /dev/null +++ b/tools/shared/deviceskin/skins/PDAPhone.skin/PDAPhone.skin @@ -0,0 +1,18 @@ +[SkinFile] +Up=pda_up.png +Down=pda_down.png +Screen=42 59 176 220 +Cursor=finger.png 20 20 +Areas=10 +HasMouseHover=false + +"Power" 0x0100000a 117 21 141 42 +"Context1" 0x01100000 43 284 74 315 +"Call" 0x01100004 74 284 104 315 +"Hangup" 0x01100005 154 284 184 315 +"Back" 0x01000061 184 284 214 315 +"Left" 0x1000012 123 315 110 326 106 307 113 288 123 300 120 307 +"Down" 0x1000015 123 315 130 318 138 315 150 326 129 335 111 325 +"Right" 0x1000014 137 301 149 290 155 308 150 324 138 315 140 308 +"Up" 0x1000013 123 300 112 289 130 282 149 290 137 300 130 298 +"Select" 0x01010000 131 298 137 300 140 307 138 315 130 318 123 316 120 307 123 300 diff --git a/tools/shared/deviceskin/skins/PDAPhone.skin/defaultbuttons.conf b/tools/shared/deviceskin/skins/PDAPhone.skin/defaultbuttons.conf new file mode 100644 index 0000000..e3ae813 --- /dev/null +++ b/tools/shared/deviceskin/skins/PDAPhone.skin/defaultbuttons.conf @@ -0,0 +1,36 @@ +[Translation] +File=QtopiaDefaults +Context=Buttons +[Menu] +Rows=4 +Columns=3 +Map=123456789*0# +Default=5 +1=Applications/camera.desktop +2=Applications/datebook.desktop +3=Applications +4=Applications/qtmail.desktop +5=Applications/addressbook.desktop +6=Games +7=Settings/Beaming.desktop +8=Applications/simapp.desktop,Applications/calculator.desktop +9=Settings +*=Applications/mediarecorder.desktop +0=Applications/todolist.desktop +#=Documents +Animator=Bounce +AnimatorBackground=Radial +[SoftKeys] +Count=3 +Key0=Context1 +Key1=Select +Key2=Back +[SystemButtons] +Count=5 +Key0=Context1 +Key1=Back +Key2=Select +Key3=Call +Key4=Hangup +[Device] +PrimaryInput=Touchscreen diff --git a/tools/shared/deviceskin/skins/PDAPhone.skin/finger.png b/tools/shared/deviceskin/skins/PDAPhone.skin/finger.png new file mode 100644 index 0000000..24cf0cb Binary files /dev/null and b/tools/shared/deviceskin/skins/PDAPhone.skin/finger.png differ diff --git a/tools/shared/deviceskin/skins/PDAPhone.skin/pda_down.png b/tools/shared/deviceskin/skins/PDAPhone.skin/pda_down.png new file mode 100644 index 0000000..f65c059 Binary files /dev/null and b/tools/shared/deviceskin/skins/PDAPhone.skin/pda_down.png differ diff --git a/tools/shared/deviceskin/skins/PDAPhone.skin/pda_up.png b/tools/shared/deviceskin/skins/PDAPhone.skin/pda_up.png new file mode 100644 index 0000000..541e3c4 Binary files /dev/null and b/tools/shared/deviceskin/skins/PDAPhone.skin/pda_up.png differ diff --git a/tools/shared/deviceskin/skins/PortableMedia.qrc b/tools/shared/deviceskin/skins/PortableMedia.qrc new file mode 100644 index 0000000..a902f1a --- /dev/null +++ b/tools/shared/deviceskin/skins/PortableMedia.qrc @@ -0,0 +1,5 @@ + + + PortableMedia.skin + + diff --git a/tools/shared/deviceskin/skins/PortableMedia.skin/PortableMedia.skin b/tools/shared/deviceskin/skins/PortableMedia.skin/PortableMedia.skin new file mode 100644 index 0000000..b76e5cf --- /dev/null +++ b/tools/shared/deviceskin/skins/PortableMedia.skin/PortableMedia.skin @@ -0,0 +1,14 @@ +[SkinFile] +Up=portablemedia.png +Down=portablemedia-pressed.png +Screen=18 20 480 272 +Areas=7 +HasMouseHover=false + +"Context1" 0x01100000 530 192 565 223 +"Back" 0x01000061 530 138 565 173 +"Select" 0x01010000 530 65 565 98 +"Left" 0x1000012 529 67 519 57 511 65 511 104 519 110 529 100 529 98 +"Down" 0x1000015 530 102 520 111 529 120 569 120 577 114 566 103 564 103 +"Right" 0x1000014 565 65 576 52 585 67 585 102 578 113 567 104 +"Up" 0x1000013 530 65 519 55 528 48 567 48 573 51 564 66 diff --git a/tools/shared/deviceskin/skins/PortableMedia.skin/defaultbuttons.conf b/tools/shared/deviceskin/skins/PortableMedia.skin/defaultbuttons.conf new file mode 100644 index 0000000..514e881 --- /dev/null +++ b/tools/shared/deviceskin/skins/PortableMedia.skin/defaultbuttons.conf @@ -0,0 +1,23 @@ +[Translation] +File=QtopiaDefaults +Context=Buttons +[Menu] +Map=123 +Default=1 +1=Applications/mediaplayer.desktop +2=Applications/photoedit.desktop +3=Settings +Animator=Bounce +AnimatorBackground=Radial +[SoftKeys] +Count=3 +Key0=Context1 +Key1=Select +Key2=Back +[SystemButtons] +Count=5 +Key0=Context1 +Key1=Select +Key2=Back +[Device] +PrimaryInput=Keypad diff --git a/tools/shared/deviceskin/skins/PortableMedia.skin/portablemedia-pressed.png b/tools/shared/deviceskin/skins/PortableMedia.skin/portablemedia-pressed.png new file mode 100644 index 0000000..730e762 Binary files /dev/null and b/tools/shared/deviceskin/skins/PortableMedia.skin/portablemedia-pressed.png differ diff --git a/tools/shared/deviceskin/skins/PortableMedia.skin/portablemedia.png b/tools/shared/deviceskin/skins/PortableMedia.skin/portablemedia.png new file mode 100644 index 0000000..e44cbe1 Binary files /dev/null and b/tools/shared/deviceskin/skins/PortableMedia.skin/portablemedia.png differ diff --git a/tools/shared/deviceskin/skins/PortableMedia.skin/portablemedia.xcf b/tools/shared/deviceskin/skins/PortableMedia.skin/portablemedia.xcf new file mode 100644 index 0000000..127e07c Binary files /dev/null and b/tools/shared/deviceskin/skins/PortableMedia.skin/portablemedia.xcf differ diff --git a/tools/shared/deviceskin/skins/S60-QVGA-Candybar.qrc b/tools/shared/deviceskin/skins/S60-QVGA-Candybar.qrc new file mode 100644 index 0000000..8138484 --- /dev/null +++ b/tools/shared/deviceskin/skins/S60-QVGA-Candybar.qrc @@ -0,0 +1,5 @@ + + + S60-QVGA-Candybar.skin + + diff --git a/tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/S60-QVGA-Candybar-down.png b/tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/S60-QVGA-Candybar-down.png new file mode 100644 index 0000000..89d40cb Binary files /dev/null and b/tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/S60-QVGA-Candybar-down.png differ diff --git a/tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.png b/tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.png new file mode 100644 index 0000000..0d0e598 Binary files /dev/null and b/tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.png differ diff --git a/tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.skin b/tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.skin new file mode 100644 index 0000000..4f8fe5d --- /dev/null +++ b/tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/S60-QVGA-Candybar.skin @@ -0,0 +1,15 @@ +[SkinFile] +Up=S60-QVGA-Candybar.png +Down=S60-QVGA-Candybar-down.png +Screen=61 93 240 320 +Areas=7 +HasMouseHover=false + + +"Context1" 0x01100000 54 469 151 469 140 483 88 485 81 496 54 498 +"Back" 0x01000061 211 468 307 467 307 498 278 497 219 486 +"Select" 0x01010000 165 491 196 522 +"Left" 0x1000012 149 474 166 492 163 519 143 538 142 481 +"Down" 0x1000015 164 521 195 522 212 539 204 545 154 544 145 536 +"Right" 0x1000014 214 475 219 487 219 528 212 539 196 522 197 492 +"Up" 0x1000013 150 474 156 467 209 467 213 476 197 489 165 489 diff --git a/tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/defaultbuttons.conf b/tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/defaultbuttons.conf new file mode 100644 index 0000000..e349dbc --- /dev/null +++ b/tools/shared/deviceskin/skins/S60-QVGA-Candybar.skin/defaultbuttons.conf @@ -0,0 +1,78 @@ +[Translation] +File=QtopiaDefaults +Context=Buttons +[Menu] +Rows=4 +Columns=3 +Map=123456789*0# +Default=5 +1=Applications/camera.desktop +2=Applications/datebook.desktop +3=Applications +4=Applications/qtmail.desktop +5=Applications/addressbook.desktop +6=Games +7=Settings/Beaming.desktop +8=Applications/simapp.desktop,Applications/calculator.desktop +9=Settings +*=Applications/mediarecorder.desktop +0=Applications/todolist.desktop +#=Documents +Animator=Bounce +AnimatorBackground=Radial +[SoftKeys] +Count=3 +Key0=Context1 +Key1=Select +Key2=Back +[SystemButtons] +Count=5 +Key0=Context1 +Key1=Select +Key2=Back +Key3=Flip +Key4=Backspace +[TextButtons] +Buttons=0123456789*# +Hold0='0 +Hold1='1 +Hold2='2 +Hold3='3 +Hold4='4 +Hold5='5 +Hold6='6 +Hold7='7 +Hold8='8 +Hold9='9 +Hold*=symbol +Hold#=mode +Tap0=space +Tap1="\".,'?!-@:1" +Tap2="\"a\xe4\xe5\xe6\xe0\xe1\xe2\x62\x63\xe7\x32" +Tap3="\"de\xe8\xe9\xea\x66\x33" +Tap4="\"ghi\xec\xed\xee\x34" +Tap5="\"jkl5" +Tap6="\"mn\xf1o\xf6\xf8\xf2\xf3\x36" +Tap7="\"pqrs\xdf\x37" +Tap8="\"tu\xfc\xf9\xfav8" +Tap9="\"wxyz9" +Tap*=modify +Tap#=shift +[LocaleTextButtons] +Buttons=23456789 +Tap2[]='abc +Tap3[]='def +Tap4[]='ghi +Tap5[]='jkl +Tap6[]='mno +Tap7[]='pqrs +Tap8[]='tuv +Tap9[]='wxyz +[PhoneTextButtons] +Buttons=*# +Tap*='*+pw +Hold*=+ +Tap#=# +Hold#=mode +[Device] +PrimaryInput=Keypad diff --git a/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.qrc b/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.qrc new file mode 100644 index 0000000..daf0cc3 --- /dev/null +++ b/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.qrc @@ -0,0 +1,5 @@ + + + S60-nHD-Touchscreen.skin + + diff --git a/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen-down.png b/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen-down.png new file mode 100644 index 0000000..7253e38 Binary files /dev/null and b/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen-down.png differ diff --git a/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.png b/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.png new file mode 100644 index 0000000..675563e Binary files /dev/null and b/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.png differ diff --git a/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.skin b/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.skin new file mode 100644 index 0000000..ed25d0e --- /dev/null +++ b/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/S60-nHD-Touchscreen.skin @@ -0,0 +1,10 @@ +[SkinFile] +Up=S60-nHD-Touchscreen.png +Down=S60-nHD-Touchscreen-down.png +Screen=53 183 360 640 +Areas=3 +HasMouseHover=false + +"Call" 0x01100004 76 874 171 899 +"Hangup" 0x01100005 300 876 393 899 +"Home" 0x1000010 174 878 298 899 diff --git a/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/defaultbuttons.conf b/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/defaultbuttons.conf new file mode 100644 index 0000000..6665125 --- /dev/null +++ b/tools/shared/deviceskin/skins/S60-nHD-Touchscreen.skin/defaultbuttons.conf @@ -0,0 +1,53 @@ +[Translation] +File=QtopiaDefaults +Context=Buttons +[Menu] +Rows=4 +Columns=3 +Map=123456789*0# +Default=5 +1=Applications/camera.desktop +2=Applications/mediaplayer.desktop +3=Applications/simapp.desktop,Applications/calculator.desktop +4=Applications/qtmail.desktop +5=Applications/addressbook.desktop +6=Applications/datebook.desktop +7=Games +8=Settings/beaming.desktop +9=Applications/todolist.desktop +*=Settings +0=Applications +#=Documents +Animator=Bounce +AnimatorBackground=Radial +[SoftKeys] +Count=3 +Key0=Context1 +Key1=Select +Key2=Back +[SystemButtons] +Count=5 +Key0=Context1 +Key1=Back +Key2=Select +Key3=Call +Key4=Hangup +[Device] +PrimaryInput=Touchscreen +[Button] +Count=2 +[Button0] +Name[]=Home Button +Key=Home +PressedActionMappable=0 +PressedActionService=TaskManager +PressedActionMessage=multitask() +HeldActionMappable=0 +HeldActionService=TaskManager +HeldActionMessage=showRunningTasks() +[Button1] +Name=Power Button +Key=Hangup +HeldActionService=Launcher +HeldActionMessage=execute(QString) +HeldActionArgs=@ByteArray(\0\0\0\x1\0\0\0\n\0\0\0\0\x10\0s\0h\0u\0t\0\x64\0o\0w\0n) diff --git a/tools/shared/deviceskin/skins/SmartPhone.qrc b/tools/shared/deviceskin/skins/SmartPhone.qrc new file mode 100644 index 0000000..8bb5325 --- /dev/null +++ b/tools/shared/deviceskin/skins/SmartPhone.qrc @@ -0,0 +1,5 @@ + + + SmartPhone.skin + + diff --git a/tools/shared/deviceskin/skins/SmartPhone.skin/SmartPhone-pressed.png b/tools/shared/deviceskin/skins/SmartPhone.skin/SmartPhone-pressed.png new file mode 100644 index 0000000..d0db2ed Binary files /dev/null and b/tools/shared/deviceskin/skins/SmartPhone.skin/SmartPhone-pressed.png differ diff --git a/tools/shared/deviceskin/skins/SmartPhone.skin/SmartPhone.png b/tools/shared/deviceskin/skins/SmartPhone.skin/SmartPhone.png new file mode 100644 index 0000000..e6ac5a0 Binary files /dev/null and b/tools/shared/deviceskin/skins/SmartPhone.skin/SmartPhone.png differ diff --git a/tools/shared/deviceskin/skins/SmartPhone.skin/SmartPhone.skin b/tools/shared/deviceskin/skins/SmartPhone.skin/SmartPhone.skin new file mode 100644 index 0000000..2f44c5a --- /dev/null +++ b/tools/shared/deviceskin/skins/SmartPhone.skin/SmartPhone.skin @@ -0,0 +1,28 @@ +[SkinFile] +Up=SmartPhone.png +Down=SmartPhone-pressed.png +Screen=90 107 176 208 +Areas=21 +HasMouseHover=false + +"1" 0x0031 138 459 149 473 142 483 120 484 102 477 95 464 99 457 121 454 +"2" 0x0032 153 467 202 492 +"3" 0x0033 258 457 260 470 243 483 215 484 207 474 218 460 248 453 +"4" 0x0034 138 492 149 506 142 516 120 517 102 510 95 497 99 490 121 487 +"5" 0x0035 153 499 202 524 +"6" 0x0036 258 489 260 502 243 515 215 516 207 506 218 492 248 485 +"7" 0x0037 138 524 149 538 142 548 120 549 102 542 95 529 99 522 121 519 +"8" 0x0038 153 531 202 556 +"9" 0x0039 258 521 260 534 243 547 215 548 207 538 218 524 248 517 +"*" 0x002a 138 556 149 570 142 580 120 581 102 574 95 561 99 554 121 551 +"0" 0x0030 153 564 202 589 +"#" 0x0023 258 554 260 567 243 580 215 581 207 571 218 557 248 550 +"Call" 0x01100004 88 395 130 439 +"Hangup" 0x01100005 227 395 269 439 +"Context1" 0x01100000 145 321 134 333 132 361 134 374 110 343 109 318 +"Back" 0x01000061 249 322 240 354 219 373 223 344 216 325 208 318 +"Select" 0x01010000 160 338 195 371 +"Left" 0x1000012 159 338 149 328 141 336 141 373 149 381 159 371 159 369 +"Down" 0x1000015 160 373 150 382 159 391 199 391 207 385 196 374 194 374 +"Right" 0x1000014 195 336 206 323 215 338 215 373 208 384 197 375 +"Up" 0x1000013 160 336 149 326 158 319 197 319 203 322 194 337 diff --git a/tools/shared/deviceskin/skins/SmartPhone.skin/defaultbuttons.conf b/tools/shared/deviceskin/skins/SmartPhone.skin/defaultbuttons.conf new file mode 100644 index 0000000..1103350 --- /dev/null +++ b/tools/shared/deviceskin/skins/SmartPhone.skin/defaultbuttons.conf @@ -0,0 +1,78 @@ +[Translation] +File=QtopiaDefaults +Context=Buttons +[Menu] +Rows=4 +Columns=3 +Map=123456789*0# +Default=5 +1=Applications/camera.desktop +2=Applications/datebook.desktop +3=Applications +4=Applications/qtmail.desktop +5=Applications/addressbook.desktop +6=Games +7=Settings/Beaming.desktop +8=Applications/simapp.desktop,Applications/calculator.desktop +9=Settings +*=Applications/mediarecorder.desktop +0=Applications/todolist.desktop +#=Documents +Animator=Bounce +AnimatorBackground=Radial +[SoftKeys] +Count=3 +Key0=Context1 +Key1=Select +Key2=Back +[SystemButtons] +Count=5 +Key0=Context1 +Key1=Select +Key2=Back +Key3=Call +Key4=Hangup +[TextButtons] +Buttons=0123456789*# +Hold0='0 +Hold1='1 +Hold2='2 +Hold3='3 +Hold4='4 +Hold5='5 +Hold6='6 +Hold7='7 +Hold8='8 +Hold9='9 +Hold*=symbol +Hold#=mode +Tap0=space +Tap1="\".,'?!-@:1" +Tap2="\"a\xe4\xe5\xe6\xe0\xe1\xe2\x62\x63\xe7\x32" +Tap3="\"de\xe8\xe9\xea\x66\x33" +Tap4="\"ghi\xec\xed\xee\x34" +Tap5="\"jkl5" +Tap6="\"mn\xf1o\xf6\xf8\xf2\xf3\x36" +Tap7="\"pqrs\xdf\x37" +Tap8="\"tu\xfc\xf9\xfav8" +Tap9="\"wxyz9" +Tap*=modify +Tap#=shift +[LocaleTextButtons] +Buttons=23456789 +Tap2[]='abc +Tap3[]='def +Tap4[]='ghi +Tap5[]='jkl +Tap6[]='mno +Tap7[]='pqrs +Tap8[]='tuv +Tap9[]='wxyz +[PhoneTextButtons] +Buttons=*# +Tap*='*+pw +Hold*=+ +Tap#='# +Hold#=mode +[Device] +PrimaryInput=Keypad diff --git a/tools/shared/deviceskin/skins/SmartPhone2.qrc b/tools/shared/deviceskin/skins/SmartPhone2.qrc new file mode 100644 index 0000000..751e985 --- /dev/null +++ b/tools/shared/deviceskin/skins/SmartPhone2.qrc @@ -0,0 +1,5 @@ + + + SmartPhone2.skin + + diff --git a/tools/shared/deviceskin/skins/SmartPhone2.skin/SmartPhone2-pressed.png b/tools/shared/deviceskin/skins/SmartPhone2.skin/SmartPhone2-pressed.png new file mode 100644 index 0000000..d4eb5b0 Binary files /dev/null and b/tools/shared/deviceskin/skins/SmartPhone2.skin/SmartPhone2-pressed.png differ diff --git a/tools/shared/deviceskin/skins/SmartPhone2.skin/SmartPhone2.png b/tools/shared/deviceskin/skins/SmartPhone2.skin/SmartPhone2.png new file mode 100644 index 0000000..48ccc1c Binary files /dev/null and b/tools/shared/deviceskin/skins/SmartPhone2.skin/SmartPhone2.png differ diff --git a/tools/shared/deviceskin/skins/SmartPhone2.skin/SmartPhone2.skin b/tools/shared/deviceskin/skins/SmartPhone2.skin/SmartPhone2.skin new file mode 100644 index 0000000..16884bf --- /dev/null +++ b/tools/shared/deviceskin/skins/SmartPhone2.skin/SmartPhone2.skin @@ -0,0 +1,25 @@ +SmartPhone2.png SmartPhone2-pressed.png +90 107 +176 220 +21 +"Menu" 0x01100000 70 400 115 427 +"Backspace" 0x01000003 238 400 285 427 +"1" 0x0031 138 437 149 451 142 461 120 462 102 455 95 442 99 435 121 432 +"2" 0x0032 153 445 202 470 +"3" 0x0033 258 435 260 448 243 461 215 462 207 452 218 438 248 431 +"4" 0x0034 138 470 149 484 142 494 120 495 102 488 95 475 99 468 121 465 +"5" 0x0035 153 477 202 502 +"6" 0x0036 258 467 260 480 243 493 215 494 207 484 218 470 248 463 +"7" 0x0037 138 502 149 516 142 526 120 527 102 520 95 507 99 500 121 497 +"8" 0x0038 153 509 202 534 +"9" 0x0039 258 499 260 512 243 525 215 526 207 516 218 502 248 495 +"*" 0x002a 138 534 149 548 142 558 120 559 102 552 95 539 99 532 121 529 +"0" 0x0030 153 542 202 567 +"#" 0x0023 258 532 260 545 243 558 215 559 207 549 218 535 248 528 +"Yes" 0x01010001 91 343 141 393 +"No" 0x01010002 219 343 269 393 +"Select" 0x01010000 160 356 195 389 +"Left" 0x1000012 159 356 149 346 141 354 141 391 149 399 159 389 159 387 +"Down" 0x1000015 160 391 150 400 159 409 199 409 207 403 196 392 194 392 +"Right" 0x1000014 195 354 206 341 215 356 215 391 208 402 197 393 +"Up" 0x1000013 160 354 149 344 158 337 197 337 203 340 194 355 diff --git a/tools/shared/deviceskin/skins/SmartPhone2.skin/defaultbuttons.conf b/tools/shared/deviceskin/skins/SmartPhone2.skin/defaultbuttons.conf new file mode 100644 index 0000000..b083203 --- /dev/null +++ b/tools/shared/deviceskin/skins/SmartPhone2.skin/defaultbuttons.conf @@ -0,0 +1,52 @@ +[Button] +[IMethod] +key_count = 5 +key_hold_action_1 = insertText +key_hold_action_2 = insertText +key_hold_action_3 = insertSymbol +key_hold_action_4 = changeMode +key_hold_arg_1 = 1 +key_hold_arg_2 = 0 +key_id_1 = 1 +key_id_2 = 0 +key_id_3 = * +key_id_4 = # +key_id_5 = * +key_mode_1 = Abc +key_mode_2 = Abc +key_mode_3 = Abc +key_mode_4 = Abc +key_mode_5 = Phone +key_tap_action_1 = insertText +key_tap_action_2 = insertSpace +key_tap_action_3 = modifyText +key_tap_action_4 = changeShift +key_tap_action_5 = insertText +key_tap_arg_1 = .,'?!-@:〓 +key_tap_arg_5 = *+pw +[Menu] +1 = Applications/camera.desktop +2 = Applications/datebook.desktop +3 = Games +4 = Applications/qtmail.desktop +5 = Applications/addressbook.desktop +6 = Settings +7 = Settings/Beaming.desktop +8 = Applications +9 = Documents +Columns = 3 +Default = 5 +Map = 123456789 +Rows = 3 +Animator=Bounce +AnimatorBackground=Radial +[SoftKeys] +[SystemButtons] +Count=5 +Key0=Yes +Key1=Select +Key2=No +Key3=Menu +Key4=Backspace +[Device] +PrimaryInput=Keypad diff --git a/tools/shared/deviceskin/skins/SmartPhoneWithButtons.qrc b/tools/shared/deviceskin/skins/SmartPhoneWithButtons.qrc new file mode 100644 index 0000000..f3393ba --- /dev/null +++ b/tools/shared/deviceskin/skins/SmartPhoneWithButtons.qrc @@ -0,0 +1,5 @@ + + + SmartPhoneWithButtons.skin + + diff --git a/tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/SmartPhoneWithButtons-pressed.png b/tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/SmartPhoneWithButtons-pressed.png new file mode 100644 index 0000000..456a068 Binary files /dev/null and b/tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/SmartPhoneWithButtons-pressed.png differ diff --git a/tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.png b/tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.png new file mode 100644 index 0000000..5ffbd6e Binary files /dev/null and b/tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.png differ diff --git a/tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.skin b/tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.skin new file mode 100644 index 0000000..9afa67f --- /dev/null +++ b/tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/SmartPhoneWithButtons.skin @@ -0,0 +1,31 @@ +[SkinFile] +Up=SmartPhoneWithButtons.png +Down=SmartPhoneWithButtons-pressed.png +Screen=90 107 176 208 +Areas=24 +HasMouseHover=false + +"1" 0x0031 138 459 149 473 142 483 120 484 102 477 95 464 99 457 121 454 +"2" 0x0032 153 467 202 492 +"3" 0x0033 258 457 260 470 243 483 215 484 207 474 218 460 248 453 +"4" 0x0034 138 492 149 506 142 516 120 517 102 510 95 497 99 490 121 487 +"5" 0x0035 153 499 202 524 +"6" 0x0036 258 489 260 502 243 515 215 516 207 506 218 492 248 485 +"7" 0x0037 138 524 149 538 142 548 120 549 102 542 95 529 99 522 121 519 +"8" 0x0038 153 531 202 556 +"9" 0x0039 258 521 260 534 243 547 215 548 207 538 218 524 248 517 +"*" 0x002a 138 556 149 570 142 580 120 581 102 574 95 561 99 554 121 551 +"0" 0x0030 153 564 202 589 +"#" 0x0023 258 554 260 567 243 580 215 581 207 571 218 557 248 550 +"Call" 0x01100004 88 395 130 439 +"Hangup" 0x01100005 227 395 269 439 +"Context1" 0x01100000 145 321 134 333 132 361 134 374 110 343 109 318 +"Back" 0x01000061 249 322 240 354 219 373 223 344 216 325 208 318 +"Select" 0x01010000 160 338 195 371 +"Left" 0x1000012 159 338 149 328 141 336 141 373 149 381 159 371 159 369 +"Down" 0x1000015 160 373 150 382 159 391 199 391 207 385 196 374 194 374 +"Right" 0x1000014 195 336 206 323 215 338 215 373 208 384 197 375 +"Up" 0x1000013 160 336 149 326 158 319 197 319 203 322 194 337 +"Home" 0x1000010 164 402 195 434 +"F1" 0x1000030 138 422 163 448 +"F2" 0x1000031 196 422 220 448 diff --git a/tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/defaultbuttons.conf b/tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/defaultbuttons.conf new file mode 100644 index 0000000..ebd6926 --- /dev/null +++ b/tools/shared/deviceskin/skins/SmartPhoneWithButtons.skin/defaultbuttons.conf @@ -0,0 +1,103 @@ +[Translation] +File=QtopiaDefaults +Context=Buttons +[Button] +Count=3 +[Button0] +Name[]=Calendar Button +Key=F1 +PressedActionService=Calendar +PressedActionMessage=raiseToday() +HeldActionService=Calendar +HeldActionMessage=newEvent() +[Button1] +Name[]=Tasks Button +Key=F2 +PressedActionService=Tasks +PressedActionMessage=raise() +HeldActionService=Tasks +HeldActionMessage=newTask() +[Button2] +Name[]=Home Button +Key=Home +PressedActionMappable=0 +PressedActionService=TaskManager +PressedActionMessage=multitask() +HeldActionMappable=0 +HeldActionService=TaskManager +HeldActionMessage=showRunningTasks() +[Menu] +Rows=4 +Columns=3 +Map=123456789*0# +Default=5 +1=Applications/camera.desktop +2=Applications/datebook.desktop +3=Applications +4=Applications/qtmail.desktop +5=Applications/addressbook.desktop +6=Games +7=Settings/Beaming.desktop +8=Applications/simapp.desktop,Applications/calculator.desktop +9=Settings +*=Applications/mediarecorder.desktop +0=Applications/todolist.desktop +#=Documents +Animator=Bounce +AnimatorBackground=Radial +[SoftKeys] +Count=3 +Key0=Context1 +Key1=Select +Key2=Back +[SystemButtons] +Count=5 +Key0=Context1 +Key1=Select +Key2=Back +Key3=Call +Key4=Hangup +[TextButtons] +Buttons=0123456789*# +Hold0='0 +Hold1='1 +Hold2='2 +Hold3='3 +Hold4='4 +Hold5='5 +Hold6='6 +Hold7='7 +Hold8='8 +Hold9='9 +Hold*=symbol +Hold#=mode +Tap0=space +Tap1="\".,'?!-@:1" +Tap2="\"a\xe4\xe5\xe6\xe0\xe1\xe2\x62\x63\xe7\x32" +Tap3="\"de\xe8\xe9\xea\x66\x33" +Tap4="\"ghi\xec\xed\xee\x34" +Tap5="\"jkl5" +Tap6="\"mn\xf1o\xf6\xf8\xf2\xf3\x36" +Tap7="\"pqrs\xdf\x37" +Tap8="\"tu\xfc\xf9\xfav8" +Tap9="\"wxyz9" +Tap*=modify +Tap#=shift +[LocaleTextButtons] +Buttons=23456789 +Tap2[]='abc +Tap3[]='def +Tap4[]='ghi +Tap5[]='jkl +Tap6[]='mno +Tap7[]='pqrs +Tap8[]='tuv +Tap9[]='wxyz +[PhoneTextButtons] +Buttons=*# +Tap*='*+pw +Hold*=+ +Tap#='# +Hold#=mode +[Device] +PrimaryInput=Keypad diff --git a/tools/shared/deviceskin/skins/TouchscreenPhone.qrc b/tools/shared/deviceskin/skins/TouchscreenPhone.qrc new file mode 100644 index 0000000..023144d --- /dev/null +++ b/tools/shared/deviceskin/skins/TouchscreenPhone.qrc @@ -0,0 +1,5 @@ + + + TouchscreenPhone.skin + + diff --git a/tools/shared/deviceskin/skins/TouchscreenPhone.skin/TouchscreenPhone-pressed.png b/tools/shared/deviceskin/skins/TouchscreenPhone.skin/TouchscreenPhone-pressed.png new file mode 100644 index 0000000..01acb86 Binary files /dev/null and b/tools/shared/deviceskin/skins/TouchscreenPhone.skin/TouchscreenPhone-pressed.png differ diff --git a/tools/shared/deviceskin/skins/TouchscreenPhone.skin/TouchscreenPhone.png b/tools/shared/deviceskin/skins/TouchscreenPhone.skin/TouchscreenPhone.png new file mode 100644 index 0000000..e90de0d Binary files /dev/null and b/tools/shared/deviceskin/skins/TouchscreenPhone.skin/TouchscreenPhone.png differ diff --git a/tools/shared/deviceskin/skins/TouchscreenPhone.skin/TouchscreenPhone.skin b/tools/shared/deviceskin/skins/TouchscreenPhone.skin/TouchscreenPhone.skin new file mode 100644 index 0000000..24316a1 --- /dev/null +++ b/tools/shared/deviceskin/skins/TouchscreenPhone.skin/TouchscreenPhone.skin @@ -0,0 +1,16 @@ +[SkinFile] +Up=TouchscreenPhone.png +Down=TouchscreenPhone-pressed.png +Screen=90 107 176 208 +Areas=9 +HasMouseHover=false + +"Context1" 0x01100000 145 321 134 333 132 361 134 374 110 343 109 318 +"Call" 0x01100004 88 395 130 439 +"Hangup" 0x01100005 227 395 269 439 +"Back" 0x01000061 249 322 240 354 219 373 223 344 216 325 208 318 +"Left" 0x1000012 159 338 149 328 141 336 141 373 149 381 159 371 159 369 +"Down" 0x1000015 160 373 150 382 159 391 199 391 207 385 196 374 194 374 +"Right" 0x1000014 195 336 206 323 215 338 215 373 208 384 197 375 +"Up" 0x1000013 160 336 149 326 158 319 197 319 203 322 194 337 +"Select" 0x01010000 160 338 195 371 diff --git a/tools/shared/deviceskin/skins/TouchscreenPhone.skin/defaultbuttons.conf b/tools/shared/deviceskin/skins/TouchscreenPhone.skin/defaultbuttons.conf new file mode 100644 index 0000000..a13dfdc --- /dev/null +++ b/tools/shared/deviceskin/skins/TouchscreenPhone.skin/defaultbuttons.conf @@ -0,0 +1,45 @@ +[Translation] +File=QtopiaDefaults +Context=Buttons +[Menu] +Rows=4 +Columns=3 +Map=123456789*0# +Default=5 +1=Applications/camera.desktop +2=Applications/datebook.desktop +3=Applications +4=Applications/qtmail.desktop +5=Applications/addressbook.desktop +6=Games +7=Settings/Beaming.desktop +8=Applications/simapp.desktop,Applications/calculator.desktop +9=Settings +*=Applications/mediarecorder.desktop +0=Applications/todolist.desktop +#=Documents +Animator=Bounce +AnimatorBackground=Radial +[SoftKeys] +Count=3 +Key0=Context1 +Key1=Select +Key2=Back +[SystemButtons] +Count=5 +Key0=Context1 +Key1=Back +Key2=Select +Key3=Call +Key4=Hangup +[Button] +Count=1 +[Button0] +Name=Power Button +Key=Hangup +HeldActionService=Launcher +HeldActionMessage=execute(QString) +HeldActionArgs=@ByteArray(\0\0\0\x1\0\0\0\n\0\0\0\0\x10\0s\0h\0u\0t\0\x64\0o\0w\0n) +[Device] +PrimaryInput=Touchscreen + diff --git a/tools/shared/deviceskin/skins/Trolltech-Keypad.qrc b/tools/shared/deviceskin/skins/Trolltech-Keypad.qrc new file mode 100644 index 0000000..4775068 --- /dev/null +++ b/tools/shared/deviceskin/skins/Trolltech-Keypad.qrc @@ -0,0 +1,5 @@ + + + Trolltech-Keypad.skin + + diff --git a/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad-closed.png b/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad-closed.png new file mode 100644 index 0000000..8dd5719 Binary files /dev/null and b/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad-closed.png differ diff --git a/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad-down.png b/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad-down.png new file mode 100644 index 0000000..5e1e6be Binary files /dev/null and b/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad-down.png differ diff --git a/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad.png b/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad.png new file mode 100644 index 0000000..fb3d549 Binary files /dev/null and b/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad.png differ diff --git a/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad.skin b/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad.skin new file mode 100644 index 0000000..4d90321 --- /dev/null +++ b/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/Trolltech-Keypad.skin @@ -0,0 +1,35 @@ +[SkinFile] +Up=Trolltech-Keypad.png +Down=Trolltech-Keypad-down.png +Closed=Trolltech-Keypad-closed.png +ClosedAreas=F1 F2 F3 Flip +ClosedScreen=95 456 128 96 +Screen=75 85 176 220 +Areas=25 +HasMouseHover=false +"1" 0x0031 65 542 68 536 76 532 114 536 114 573 64 568 +"2" 0x0032 133 537 188 574 +"3" 0x0033 206 536 246 532 252 536 256 542 258 569 205 572 +"4" 0x0034 64 578 114 618 +"5" 0x0035 133 581 188 618 +"6" 0x0036 206 580 256 577 258 613 206 616 +"7" 0x0037 66 622 116 625 114 662 66 658 +"8" 0x0038 133 626 188 662 +"9" 0x0039 206 625 256 622 256 658 206 661 +"*" 0x002a 68 667 116 670 114 705 86 699 76 693 69 686 +"0" 0x0030 133 671 188 708 +"#" 0x0023 206 670 254 665 254 684 245 692 232 699 206 704 +"Context1" 0x01100000 69 420 75 410 85 404 101 404 102 458 69 458 +"Back" 0x01000061 218 404 234 404 240 408 248 418 248 456 218 457 +"Home" 0x1000010 140 494 180 514 +"Hangup" 0x01100005 218 457 248 456 248 496 243 507 230 514 194 514 194 494 206 492 213 486 218 478 +"Call" 0x01100004 68 458 102 460 102 479 108 487 118 492 126 494 126 514 86 514 77 507 72 496 +"Select" 0x01010000 138 426 182 458 +"Up" 0x1000013 118 406 201 402 184 423 134 422 +"Right" 0x1000014 184 424 201 402 202 476 184 460 +"Down" 0x1000015 135 462 184 461 199 477 118 477 +"Left" 0x1000012 118 406 134 424 134 461 117 476 +"F1" 0x1000030 0 408 45 456 +"F2" 0x1000031 0 456 45 509 +"F3" 0x1000032 0 545 45 582 +"Flip" 0x1100006 32 353 293 386 diff --git a/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/defaultbuttons.conf b/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/defaultbuttons.conf new file mode 100644 index 0000000..6a78e67 --- /dev/null +++ b/tools/shared/deviceskin/skins/Trolltech-Keypad.skin/defaultbuttons.conf @@ -0,0 +1,142 @@ +[Translation] +File=QtopiaDefaults +Context=Buttons +[Button] +Count=8 +[Button7] +Name[]=Home Down Button +Key=Down +Context=HomeScreen +PressedActionMappable=0 +HeldActionService=Messaging +HeldActionMessage=raise() +[Button6] +Name[]=Home Up Button +Key=Up +Context=HomeScreen +PressedActionMappable=0 +HeldActionService=Contacts +HeldActionMessage=raise() +[Button5] +Name[]=Home Right Button +Key=Right +Context=HomeScreen +PressedActionMappable=0 +HeldActionService=mediaplayer +HeldActionMessage=raise() +[Button4] +Name[]=Calender Button +Key=Left +Context=HomeScreen +PressedActionMappable=0 +HeldActionService=Calendar +HeldActionMessage=raiseToday() +[Button3] +Name[]=Left Soft Key +Key=Context1 +HeldActionService=TaskManager +HeldActionMessage=showRunningTasks() +HeldActionMappable=0 +PressActionMappable=0 +[Button2] +Name[]=VoiceNotes Button +Key=F1 +PressedActionService=mediarecorder +PressedActionMessage=raise() +HeldActionService=mediarecorder +HeldActionMessage=newEvent() +[Button1] +Name[]=Camera Button +Key=F2 +PressedActionService=Camera +PressedActionMessage=raise() +HeldActionService=Tasks +HeldActionMessage=newTask() +[Button0] +Name[]=Home Button +Key=Home +PressedActionMappable=0 +PressedActionService=TaskManager +PressedActionMessage=multitask() +HeldActionMappable=0 +HeldActionService=TaskManager +HeldActionMessage=showRunningTasks() +[Menu] +Rows=4 +Columns=3 +Map=123456789*0# +Default=5 +1=Applications/camera.desktop +2=Applications/mediaplayer.desktop +3=Applications/simapp.desktop,Applications/calculator.desktop +4=Applications/qtmail.desktop +5=Applications/addressbook.desktop +6=Applications/datebook.desktop +7=Games +8=Settings/Beaming.desktop +9=Applications/todolist.desktop +*=Settings +0=Applications +#=Documents +Animator=Bounce +AnimatorBackground=Radial +[SoftKeys] +Count=3 +Key0=Context1 +Key1=Select +Key2=Back +[SystemButtons] +Count=6 +Key0=Context1 +Key1=Select +Key2=Back +Key3=Call +Key4=Hangup +Key5=Flip +[TextButtons] +Buttons=0123456789*# +Hold0='0 +Hold1='1 +Hold2='2 +Hold3='3 +Hold4='4 +Hold5='5 +Hold6='6 +Hold7='7 +Hold8='8 +Hold9='9 +Hold*=symbol +Hold#=mode +Tap0=space +Tap0=space +Tap1="\".,'?!-@:1" +Tap2="\"a\xe4\xe5\xe6\xe0\xe1\xe2\x62\x63\xe7\x32" +Tap3="\"de\xe8\xe9\xea\x66\x33" +Tap4="\"ghi\xec\xed\xee\x34" +Tap5="\"jkl5" +Tap6="\"mn\xf1o\xf6\xf8\xf2\xf3\x36" +Tap7="\"pqrs\xdf\x37" +Tap8="\"tu\xfc\xf9\xfav8" +Tap9="\"wxyz9" +Tap*=modify +Tap#=shift +[LocaleTextButtons] +Buttons=23456789 +Tap2[]='abc +Tap3[]='def +Tap4[]='ghi +Tap5[]='jkl +Tap6[]='mno +Tap7[]='pqrs +Tap8[]='tuv +Tap9[]='wxyz +[PhoneTextButtons] +Buttons=*# +Tap*='*+pw +Hold*=+ +Tap#='# +Hold#=mode +[Device] +PrimaryInput=Keypad +[Environment] +QWS_DISPLAY=Multi: LinuxFb:mmHeight57:0 LinuxFb:offset=0,320:1 :0 diff --git a/tools/shared/deviceskin/skins/Trolltech-Touchscreen.qrc b/tools/shared/deviceskin/skins/Trolltech-Touchscreen.qrc new file mode 100644 index 0000000..40fafeb --- /dev/null +++ b/tools/shared/deviceskin/skins/Trolltech-Touchscreen.qrc @@ -0,0 +1,5 @@ + + + Trolltech-Touchscreen.skin + + diff --git a/tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/Trolltech-Touchscreen-down.png b/tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/Trolltech-Touchscreen-down.png new file mode 100644 index 0000000..c1a422f Binary files /dev/null and b/tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/Trolltech-Touchscreen-down.png differ diff --git a/tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.png b/tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.png new file mode 100644 index 0000000..544a425 Binary files /dev/null and b/tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.png differ diff --git a/tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.skin b/tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.skin new file mode 100644 index 0000000..5de882e --- /dev/null +++ b/tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/Trolltech-Touchscreen.skin @@ -0,0 +1,17 @@ +[SkinFile] +Up=Trolltech-Touchscreen.png +Down=Trolltech-Touchscreen-down.png +Screen=40 109 176 220 +Areas=10 +HasMouseHover=false + +"Context1" 0x01100000 38 420 44 408 52 404 68 403 68 458 40 458 +"Back" 0x01000061 185 42 202 398 211 410 216 418 219 456 186 456 +"Call" 0x01100004 38 458 70 458 71 478 75 486 83 492 94 494 94 516 56 516 45 507 38 498 +"Hangup" 0x01100005 186 458 220 458 220 496 214 508 200 516 162 516 161 494 172 492 180 486 185 478 +"Left" 0x1000012 86 405 106 426 106 461 85 478 +"Down" 0x1000015 106 460 151 460 170 480 85 480 +"Right" 0x1000014 151 424 170 404 170 480 151 460 +"Up" 0x1000013 85 403 168 403 150 424 106 424 +"Select" 0x01010000 106 426 150 456 +"Home" 0x1000010 105 493 145 512 diff --git a/tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/defaultbuttons.conf b/tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/defaultbuttons.conf new file mode 100644 index 0000000..6665125 --- /dev/null +++ b/tools/shared/deviceskin/skins/Trolltech-Touchscreen.skin/defaultbuttons.conf @@ -0,0 +1,53 @@ +[Translation] +File=QtopiaDefaults +Context=Buttons +[Menu] +Rows=4 +Columns=3 +Map=123456789*0# +Default=5 +1=Applications/camera.desktop +2=Applications/mediaplayer.desktop +3=Applications/simapp.desktop,Applications/calculator.desktop +4=Applications/qtmail.desktop +5=Applications/addressbook.desktop +6=Applications/datebook.desktop +7=Games +8=Settings/beaming.desktop +9=Applications/todolist.desktop +*=Settings +0=Applications +#=Documents +Animator=Bounce +AnimatorBackground=Radial +[SoftKeys] +Count=3 +Key0=Context1 +Key1=Select +Key2=Back +[SystemButtons] +Count=5 +Key0=Context1 +Key1=Back +Key2=Select +Key3=Call +Key4=Hangup +[Device] +PrimaryInput=Touchscreen +[Button] +Count=2 +[Button0] +Name[]=Home Button +Key=Home +PressedActionMappable=0 +PressedActionService=TaskManager +PressedActionMessage=multitask() +HeldActionMappable=0 +HeldActionService=TaskManager +HeldActionMessage=showRunningTasks() +[Button1] +Name=Power Button +Key=Hangup +HeldActionService=Launcher +HeldActionMessage=execute(QString) +HeldActionArgs=@ByteArray(\0\0\0\x1\0\0\0\n\0\0\0\0\x10\0s\0h\0u\0t\0\x64\0o\0w\0n) -- cgit v0.12 From f1d1be98036ea4d03c505d54e7adb408491434d4 Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Tue, 12 May 2009 15:30:46 +0200 Subject: Remove unused file qfileinfo_p.h The private class was already declared and defined in the qfileinfo.cpp file. Reviewed-by: thiago --- qmake/qmake.pri | 1 - src/corelib/io/io.pri | 1 - src/corelib/io/qfileinfo_p.h | 145 ------------------------------------------- 3 files changed, 147 deletions(-) delete mode 100644 src/corelib/io/qfileinfo_p.h diff --git a/qmake/qmake.pri b/qmake/qmake.pri index 02ff38e..9147ee8 100644 --- a/qmake/qmake.pri +++ b/qmake/qmake.pri @@ -79,7 +79,6 @@ bootstrap { #Qt code qfile.h \ qabstractfileengine.h \ qfileinfo.h \ - qfileinfo_p.h \ qglobal.h \ qnumeric.h \ qhash.h \ diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri index 3690d4b..c62959d 100644 --- a/src/corelib/io/io.pri +++ b/src/corelib/io/io.pri @@ -10,7 +10,6 @@ HEADERS += \ io/qdiriterator.h \ io/qfile.h \ io/qfileinfo.h \ - io/qfileinfo_p.h \ io/qiodevice.h \ io/qiodevice_p.h \ io/qprocess.h \ diff --git a/src/corelib/io/qfileinfo_p.h b/src/corelib/io/qfileinfo_p.h deleted file mode 100644 index 7d66581..0000000 --- a/src/corelib/io/qfileinfo_p.h +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtCore 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFILEINFO_P_H -#define QFILEINFO_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of QIODevice. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qfileinfo.h" - -QT_BEGIN_NAMESPACE - -class QFileInfoPrivate -{ -public: - QFileInfoPrivate(const QFileInfo *copy=0); - ~QFileInfoPrivate(); - - void initFileEngine(const QString &); - - enum Access { - ReadAccess, - WriteAccess, - ExecuteAccess - }; - bool hasAccess(Access access) const; - - uint getFileFlags(QAbstractFileEngine::FileFlags) const; - QDateTime &getFileTime(QAbstractFileEngine::FileTime) const; - QString getFileName(QAbstractFileEngine::FileName) const; - - enum { - CachedFileFlags = 0x01, - CachedLinkTypeFlag = 0x02, - CachedBundleTypeFlag= 0x04, - CachedMTime = 0x10, - CachedCTime = 0x20, - CachedATime = 0x40, - CachedSize = 0x08 - }; - - struct Data - { - inline Data() - : ref(1), fileEngine(0), cache_enabled(1) - { - clear(); - } - - inline Data(const Data ©) - : ref(1), fileEngine(QAbstractFileEngine::create(copy.fileName)), - fileName(copy.fileName), cache_enabled(copy.cache_enabled) - { - clear(); - } - - inline ~Data() - { - delete fileEngine; - } - - inline void clear() - { - fileNames.clear(); - fileFlags = 0; - cachedFlags = 0; - } - - mutable QAtomicInt ref; - - QAbstractFileEngine *fileEngine; - mutable QString fileName; - mutable QHash fileNames; - mutable uint cachedFlags : 31; - mutable uint cache_enabled : 1; - mutable uint fileFlags; - mutable qint64 fileSize; - mutable QDateTime fileTimes[3]; - - inline bool getCachedFlag(uint c) const - { return cache_enabled ? (cachedFlags & c) : 0; } - - inline void setCachedFlag(uint c) - { if (cache_enabled) cachedFlags |= c; } - } *data; - - inline void reset() { - detach(); - data->clear(); - } - - void detach(); -}; - - -QT_END_NAMESPACE -#endif - -- cgit v0.12 From 55829ebc5664a65fcef158e7ccd3579aaffa8d20 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Mon, 11 May 2009 17:37:37 +0200 Subject: Reset the 'connectedToScene' flag when changing the scene of a view In QGraphicsScene::_q_emitUpdated() the slot QGrpahicsView::updateScene(QList) gets connected and a boolean (connectedToScene) is set to prevent double connections. The problem is that this boolean was not reset when the view gets a new scene. Task-number: 253415 Reviewed-by: andreas --- src/gui/graphicsview/qgraphicsview.cpp | 1 + tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 05e4907..8b133f3 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -1681,6 +1681,7 @@ void QGraphicsView::setScene(QGraphicsScene *scene) disconnect(d->scene, SIGNAL(sceneRectChanged(QRectF)), this, SLOT(updateSceneRect(QRectF))); d->scene->d_func()->views.removeAll(this); + d->connectedToScene = false; } // Assign the new scene and update the contents (scrollbars, etc.)). diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index b5af115..db1e4c3 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -200,6 +200,7 @@ private slots: void task239729_noViewUpdate(); void task239047_fitInViewSmallViewport(); void task245469_itemsAtPointWithClip(); + void task253415_reconnectUpdateSceneOnSceneChanged(); }; void tst_QGraphicsView::initTestCase() @@ -3044,5 +3045,28 @@ void tst_QGraphicsView::centerOnDirtyItem() QCOMPARE(before, after); } +void tst_QGraphicsView::task253415_reconnectUpdateSceneOnSceneChanged() +{ + QGraphicsView view; + QGraphicsView dummyView; + view.setWindowFlags(view.windowFlags() | Qt::WindowStaysOnTopHint); + view.resize(200, 200); + + QGraphicsScene scene1; + QObject::connect(&scene1, SIGNAL(changed(QList)), &dummyView, SLOT(updateScene(QList))); + view.setScene(&scene1); + + QTest::qWait(125); + + QGraphicsScene scene2; + QObject::connect(&scene2, SIGNAL(changed(QList)), &dummyView, SLOT(updateScene(QList))); + view.setScene(&scene2); + + QTest::qWait(125); + + bool wasConnected2 = QObject::disconnect(&scene2, SIGNAL(changed(QList)), &view, 0); + QVERIFY(wasConnected2); +} + QTEST_MAIN(tst_QGraphicsView) #include "tst_qgraphicsview.moc" -- cgit v0.12 From 589dfd480d6158aaa59ab56c8be6a6bfc41da3ef Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Wed, 13 May 2009 12:59:07 +0200 Subject: qdoc: Fixed some qdoc errors. --- doc/src/examples/fancybrowser.qdoc | 14 +++++++------- src/corelib/tools/qhash.cpp | 6 +++--- tools/designer/src/uitools/quiloader.cpp | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/doc/src/examples/fancybrowser.qdoc b/doc/src/examples/fancybrowser.qdoc index ea4da71..631aff9 100644 --- a/doc/src/examples/fancybrowser.qdoc +++ b/doc/src/examples/fancybrowser.qdoc @@ -123,7 +123,7 @@ The first jQuery-based function, \c highlightAllLinks(), is designed to highlight all links in the current webpage. The JavaScript code looks - for web elements named \i {a}, which is the tag for a hyperlink. + for web elements named \e {a}, which is the tag for a hyperlink. For each such element, the background color is set to be yellow by using CSS. @@ -131,18 +131,18 @@ The \c rotateImages() function rotates the images on the current web page. Webkit supports CSS transforms and this JavaScript code - looks up all \i {img} elements and rotates the images 180 degrees + looks up all \e {img} elements and rotates the images 180 degrees and then back again. \snippet examples/webkit/fancybrowser/mainwindow.cpp 9 The remaining four methods remove different elements from the current web page. \c removeGifImages() removes all Gif images on the page by looking up - the \i {src} attribute of all the elements on the web page. Any element with - a \i {gif} file as its source is removed. \c removeInlineFrames() removes all - \i {iframe} or inline elements. \c removeObjectElements() removes all - \i {object} elements, and \c removeEmbeddedElements() removes any elements - such as plugins embedded on the page using the \i {embed} tag. + the \e {src} attribute of all the elements on the web page. Any element with + a \e {gif} file as its source is removed. \c removeInlineFrames() removes all + \e {iframe} or inline elements. \c removeObjectElements() removes all + \e {object} elements, and \c removeEmbeddedElements() removes any elements + such as plugins embedded on the page using the \e {embed} tag. */ diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index b2512e1..6c4a3ba 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -379,8 +379,7 @@ void QHashData::checkSanity() #endif /*! - \fn uint qHash(const QPair &key) - \relates QHash + \ \since 4.3 Returns the hash value for the \a key. @@ -502,7 +501,8 @@ void QHashData::checkSanity() key. With QHash, the items are arbitrarily ordered. \i The key type of a QMap must provide operator<(). The key type of a QHash must provide operator==() and a global - \l{qHash()} {hash} function. + hash function called qHash() (see the related non-member + functions). \endlist Here's an example QHash with QString keys and \c int values: diff --git a/tools/designer/src/uitools/quiloader.cpp b/tools/designer/src/uitools/quiloader.cpp index 548f07e..2a66095 100644 --- a/tools/designer/src/uitools/quiloader.cpp +++ b/tools/designer/src/uitools/quiloader.cpp @@ -572,9 +572,9 @@ void QUiLoaderPrivate::setupWidgetMap() const \class QUiLoader \inmodule QtUiTools - \brief enables standalone applications to dynamically create user - interfaces at run-time using the information stored in .ui files or - specified in plugin paths. + \brief The QUiLoader class enables standalone applications to + dynamically create user interfaces at run-time using the + information stored in .ui files or specified in plugin paths. In addition, you can customize or create your own user interface by deriving your own loader class. -- cgit v0.12 From 8a7f9857350c50dc77d2a39a864b22cdaffa78ff Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 13 May 2009 12:48:22 +0200 Subject: Fix warning Reviewed-by: Denis --- src/gui/kernel/qdnd_x11.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/kernel/qdnd_x11.cpp b/src/gui/kernel/qdnd_x11.cpp index ed93b34..9b2305d 100644 --- a/src/gui/kernel/qdnd_x11.cpp +++ b/src/gui/kernel/qdnd_x11.cpp @@ -543,7 +543,7 @@ bool QX11Data::xdndMimeDataForAtom(Atom a, QMimeData *mimeData, QByteArray *data (dm->xdndMimeTransferedPixmapIndex + 1) % 2; } } else { - DEBUG("QClipboard: xdndMimeDataForAtom(): converting to type '%s' is not supported", atomName); + DEBUG("QClipboard: xdndMimeDataForAtom(): converting to type '%s' is not supported", qPrintable(atomName)); } } return data; @@ -624,7 +624,6 @@ QVariant QX11Data::xdndMimeConvertToFormat(Atom a, const QByteArray &data, const if (format == QLatin1String("image/ppm")) { if (a == XA_PIXMAP && data.size() == sizeof(Pixmap)) { Pixmap xpm = *((Pixmap*)data.data()); - Display *dpy = display; if (!xpm) return QByteArray(); QPixmap qpm = QPixmap::fromX11Pixmap(xpm); -- cgit v0.12 From 0076f04c3637aaebb4d70d7c7e5fd0a78527c260 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 13 May 2009 11:00:40 +0200 Subject: QRingBuffer: Enanced with readPointerAtPosition Ability to read from a QRingBuffer at any position without modifying it. --- src/corelib/tools/qringbuffer_p.h | 46 +++++++ tests/auto/auto.pro | 1 + tests/auto/qringbuffer/qringbuffer.pro | 6 + tests/auto/qringbuffer/tst_qringbuffer.cpp | 200 +++++++++++++++++++++++++++++ 4 files changed, 253 insertions(+) create mode 100644 tests/auto/qringbuffer/qringbuffer.pro create mode 100644 tests/auto/qringbuffer/tst_qringbuffer.cpp diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index eed4ba9..02cc497 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -74,6 +74,52 @@ public: return buffers.isEmpty() ? 0 : (buffers.first().constData() + head); } + // access the bytes at a specified position + // the out-variable length will contain the amount of bytes readable + // from there, e.g. the amount still the same QByteArray + inline const char *readPointerAtPosition(qint64 pos, qint64 &length) const { + if (buffers.isEmpty()) { + length = 0; + return 0; + } + + if (pos >= bufferSize) { + length = 0; + return 0; + } + + // special case: it is in the first buffer + int nextDataBlockSizeValue = nextDataBlockSize(); + if (pos - head < nextDataBlockSizeValue) { + length = nextDataBlockSizeValue - pos; + return buffers.at(0).constData() + head + pos; + } + + // special case: we only had one buffer and tried to read over it + if (buffers.length() == 1) { + length = 0; + return 0; + } + + // skip the first + pos -= nextDataBlockSizeValue; + + // normal case: it is somewhere in the second to the-one-before-the-tailBuffer + for (int i = 1; i < tailBuffer; i++) { + if (pos >= buffers[i].size()) { + pos -= buffers[i].size(); + continue; + } + + length = buffers[i].length() - pos; + return buffers[i].constData() + pos; + } + + // it is in the tail buffer + length = tail - pos; + return buffers[tailBuffer].constData() + pos; + } + inline void free(int bytes) { bufferSize -= bytes; if (bufferSize < 0) diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 443ee7e..a3a6916 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -238,6 +238,7 @@ SUBDIRS += bic \ qregexpvalidator \ qregion \ qresourceengine \ + qringbuffer \ qscriptable \ qscriptclass \ qscriptcontext \ diff --git a/tests/auto/qringbuffer/qringbuffer.pro b/tests/auto/qringbuffer/qringbuffer.pro new file mode 100644 index 0000000..91fb0a0 --- /dev/null +++ b/tests/auto/qringbuffer/qringbuffer.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +SOURCES += tst_qringbuffer.cpp + +QT = core + + diff --git a/tests/auto/qringbuffer/tst_qringbuffer.cpp b/tests/auto/qringbuffer/tst_qringbuffer.cpp new file mode 100644 index 0000000..c741c2e --- /dev/null +++ b/tests/auto/qringbuffer/tst_qringbuffer.cpp @@ -0,0 +1,200 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite 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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include + +class tst_QRingBuffer : public QObject +{ + Q_OBJECT + +public: + tst_QRingBuffer(); + virtual ~tst_QRingBuffer(); +public slots: + void initTestCase(); + void cleanupTestCase(); +private slots: + void readPointerAtPositionWriteRead(); + void readPointerAtPositionEmptyRead(); + void readPointerAtPositionWithHead(); + void readPointerAtPositionReadTooMuch(); + void sizeWhenEmpty(); + void sizeWhenReservedAndChopped(); + void sizeWhenReserved(); +}; + +tst_QRingBuffer::tst_QRingBuffer() +{ +} + +tst_QRingBuffer::~tst_QRingBuffer() +{ +} + +void tst_QRingBuffer::initTestCase() +{ +} + +void tst_QRingBuffer::cleanupTestCase() +{ +} + +void tst_QRingBuffer::sizeWhenReserved() +{ + QRingBuffer ringBuffer; + ringBuffer.reserve(5); + + QCOMPARE(ringBuffer.size(), 5); +} + +void tst_QRingBuffer::sizeWhenReservedAndChopped() +{ + QRingBuffer ringBuffer; + ringBuffer.reserve(31337); + ringBuffer.chop(31337); + + QCOMPARE(ringBuffer.size(), 0); +} + +void tst_QRingBuffer::sizeWhenEmpty() +{ + QRingBuffer ringBuffer; + + QCOMPARE(ringBuffer.size(), 0); +} + +void tst_QRingBuffer::readPointerAtPositionReadTooMuch() +{ + QRingBuffer ringBuffer; + + qint64 length; + const char *buf = ringBuffer.readPointerAtPosition(42, length); + QVERIFY(buf == 0); + QVERIFY(length == 0); +} + +void tst_QRingBuffer::readPointerAtPositionWithHead() +{ + QRingBuffer ringBuffer; + char *buf = ringBuffer.reserve(4); + memcpy (buf, "0123", 4); + ringBuffer.free(2); + + // ringBuffer should have stayed the same except + // its head it had moved to position 2 + qint64 length; + const char* buf2 = ringBuffer.readPointerAtPosition(0, length); + + QCOMPARE(length, qint64(2)); + QVERIFY(*buf2 == '2'); + QVERIFY(*(buf2+1) == '3'); + + // advance 2 more, ringBuffer should be empty then + ringBuffer.free(2); + buf2 = ringBuffer.readPointerAtPosition(0, length); + QCOMPARE(length, qint64(0)); + QVERIFY(buf2 == 0); +} + +void tst_QRingBuffer::readPointerAtPositionEmptyRead() +{ + QRingBuffer ringBuffer; + + qint64 length; + const char *buf = ringBuffer.readPointerAtPosition(0, length); + QVERIFY(buf == 0); + QVERIFY(length == 0); +} + +void tst_QRingBuffer::readPointerAtPositionWriteRead() +{ + //create some data + QBuffer inData; + inData.open(QIODevice::ReadWrite); + inData.putChar(0x42); + inData.putChar(0x23); + inData.write("Qt rocks!"); + for (int i = 0; i < 5000; i++) + inData.write(QString("Number %1").arg(i).toUtf8()); + inData.reset(); + QVERIFY(inData.size() > 0); + + //put the inData in the QRingBuffer + QRingBuffer ringBuffer; + qint64 remaining = inData.size(); + while (remaining > 0) { + // write in chunks of 50 bytes + // this ensures there will be multiple QByteArrays inside the QRingBuffer + // since QRingBuffer is then only using individual arrays of around 4000 bytes + qint64 thisWrite = qMin(remaining, qint64(50)); + char *pos = ringBuffer.reserve(thisWrite); + inData.read(pos, thisWrite); + remaining -= thisWrite; + } + // was data put into it? + QVERIFY(ringBuffer.size() > 0); + QCOMPARE(qint64(ringBuffer.size()), inData.size()); + + //read from the QRingBuffer in loop, put back into another QBuffer + QBuffer outData; + outData.open(QIODevice::ReadWrite); + remaining = ringBuffer.size(); + while (remaining > 0) { + qint64 thisRead; + // always try to read as much as possible + const char *buf = ringBuffer.readPointerAtPosition(ringBuffer.size() - remaining, thisRead); + outData.write(buf, thisRead); + remaining -= thisRead; + } + outData.reset(); + + QVERIFY(outData.size() > 0); + + // was the data read from the QRingBuffer the same as the one written into it? + QCOMPARE(outData.size(), inData.size()); + QVERIFY(outData.buffer().startsWith(inData.buffer())); +} + + +QTEST_APPLESS_MAIN(tst_QRingBuffer) +#include "tst_qringbuffer.moc" -- cgit v0.12 From 78866bec190ca56f977d5a4b5130bbd3d2e8c412 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 13 May 2009 11:03:03 +0200 Subject: QNonContiguousByteDevice: An wrapper around QByteArray, QIODevice, ... New private class, needed for the rewrite of the upload side of QNetworkAccessManager. Allows to have a "byte pointer view" on stuff like QRingBuffer, QByteArray, QFile and any QIODevice. Reviewed-by: Thiago Macieira Reviewed-by: Peter Hartmann --- src/corelib/io/io.pri | 2 + src/corelib/io/qnoncontiguousbytedevice.cpp | 542 ++++++++++++++++++++++++++++ src/corelib/io/qnoncontiguousbytedevice_p.h | 189 ++++++++++ 3 files changed, 733 insertions(+) create mode 100644 src/corelib/io/qnoncontiguousbytedevice.cpp create mode 100644 src/corelib/io/qnoncontiguousbytedevice_p.h diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri index c62959d..8f37e25 100644 --- a/src/corelib/io/io.pri +++ b/src/corelib/io/io.pri @@ -12,6 +12,7 @@ HEADERS += \ io/qfileinfo.h \ io/qiodevice.h \ io/qiodevice_p.h \ + io/qnoncontiguousbytedevice_p.h \ io/qprocess.h \ io/qprocess_p.h \ io/qtextstream.h \ @@ -37,6 +38,7 @@ SOURCES += \ io/qfile.cpp \ io/qfileinfo.cpp \ io/qiodevice.cpp \ + io/qnoncontiguousbytedevice.cpp \ io/qprocess.cpp \ io/qtextstream.cpp \ io/qtemporaryfile.cpp \ diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp new file mode 100644 index 0000000..6233fde --- /dev/null +++ b/src/corelib/io/qnoncontiguousbytedevice.cpp @@ -0,0 +1,542 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtCore 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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnoncontiguousbytedevice_p.h" +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \class QNonContiguousByteDevice + \brief A QNonContiguousByteDevice is a representation of a + file, array or buffer that allows access with a read pointer. + \since 4.6 + + \inmodule QtCore + + The goal of this class is to have a data representation that + allows us to avoid doing a memcpy as we have to do with QIODevice. + + \sa QNonContiguousByteDeviceFactory + + \internal +*/ +/*! + \fn virtual const char* QNonContiguousByteDevice::readPointer(qint64 maximumLength, qint64 &len) + + Return a byte pointer for at most \a maximumLength bytes of that device. + if \a maximumLength is -1, the caller does not care about the length and + the device may return what it desires to. + The actual number of bytes the pointer is valid for is returned in + the \a len variable. + \a len will be -1 if EOF or an error occurs. + If it was really EOF can then afterwards be checked with atEnd() + Returns 0 if it is not possible to read at that position. + + \sa atEnd() + + \internal +*/ +/*! + \fn virtual bool QNonContiguousByteDevice::advanceReadPointer(qint64 amount) + + will advance the internal read pointer by \a amount bytes. + The old readPointer is invalid after this call. + + \sa readPointer() + + \internal +*/ +/*! + \fn virtual bool QNonContiguousByteDevice::atEnd() + + Returns true if everything has been read and the read + pointer cannot be advanced anymore. + + \sa readPointer(), advanceReadPointer(), reset() + + \internal +*/ +/*! + \fn virtual bool QNonContiguousByteDevice::reset() + + Moves the internal read pointer back to the beginning. + Returns false if this was not possible. + + \sa atEnd(), disableReset() + + \internal +*/ +/*! + \fn void QNonContiguousByteDevice::disableReset() + + Disable the reset() call, e.g. it will always + do nothing and return false. + + \sa reset() + + \internal +*/ +/*! + \fn virtual qint64 QNonContiguousByteDevice::size() + + Returns the size of the complete device or -1 if unknown. + May also return less/more than what can be actually read with readPointer() + + \internal +*/ +/*! + \fn void QNonContiguousByteDevice::readyRead() + + Emitted when there is data available + + \internal +*/ +/*! + \fn void QNonContiguousByteDevice::readProgress(qint64 current, qint64 total) + + Emitted when data has been "read" by advancing the read pointer + + \internal +*/ + +QNonContiguousByteDevice::QNonContiguousByteDevice() : QObject((QObject*)0), resetDisabled(false) +{ +}; + +QNonContiguousByteDevice::~QNonContiguousByteDevice() +{ +}; + +void QNonContiguousByteDevice::disableReset() +{ + resetDisabled = true; +} + +QNonContiguousByteDeviceBufferImpl::QNonContiguousByteDeviceBufferImpl(QBuffer *b) : QNonContiguousByteDevice() +{ + buffer = b; + byteArray = QByteArray::fromRawData(buffer->buffer().constData() + buffer->pos(), buffer->size() - buffer->pos()); + arrayImpl = new QNonContiguousByteDeviceByteArrayImpl(&byteArray); + arrayImpl->setParent(this); + connect(arrayImpl, SIGNAL(readyRead()), SIGNAL(readyRead())); + connect(arrayImpl, SIGNAL(readProgress(qint64,qint64)), SIGNAL(readProgress(qint64,qint64))); +} + +QNonContiguousByteDeviceBufferImpl::~QNonContiguousByteDeviceBufferImpl() +{ +} + +const char* QNonContiguousByteDeviceBufferImpl::readPointer(qint64 maximumLength, qint64 &len) +{ + return arrayImpl->readPointer(maximumLength, len); +} + +bool QNonContiguousByteDeviceBufferImpl::advanceReadPointer(qint64 amount) +{ + return arrayImpl->advanceReadPointer(amount); +} + +bool QNonContiguousByteDeviceBufferImpl::atEnd() +{ + return arrayImpl->atEnd(); +} + +bool QNonContiguousByteDeviceBufferImpl::reset() +{ + if (resetDisabled) + return false; + return arrayImpl->reset(); +} + +qint64 QNonContiguousByteDeviceBufferImpl::size() +{ + return arrayImpl->size(); +} + +QNonContiguousByteDeviceByteArrayImpl::QNonContiguousByteDeviceByteArrayImpl(QByteArray *ba) : QNonContiguousByteDevice(), currentPosition(0) +{ + byteArray = ba; +} + +QNonContiguousByteDeviceByteArrayImpl::~QNonContiguousByteDeviceByteArrayImpl() +{ +} + +const char* QNonContiguousByteDeviceByteArrayImpl::readPointer(qint64 maximumLength, qint64 &len) +{ + if (atEnd()) { + len = -1; + return 0; + } + + if (maximumLength != -1) + len = qMin(maximumLength, size() - currentPosition); + else + len = size() - currentPosition; + + return byteArray->constData() + currentPosition; +} + +bool QNonContiguousByteDeviceByteArrayImpl::advanceReadPointer(qint64 amount) +{ + currentPosition += amount; + emit readProgress(currentPosition, size()); + return true; +} + +bool QNonContiguousByteDeviceByteArrayImpl::atEnd() +{ + return currentPosition >= size(); +} + +bool QNonContiguousByteDeviceByteArrayImpl::reset() +{ + if (resetDisabled) + return false; + + currentPosition = 0; + return true; +} + +qint64 QNonContiguousByteDeviceByteArrayImpl::size() +{ + return byteArray->size(); +} + +QNonContiguousByteDeviceRingBufferImpl::QNonContiguousByteDeviceRingBufferImpl(QRingBuffer *rb) + : QNonContiguousByteDevice(), currentPosition(0) +{ + ringBuffer = rb; +} + +QNonContiguousByteDeviceRingBufferImpl::~QNonContiguousByteDeviceRingBufferImpl() +{ +}; + +const char* QNonContiguousByteDeviceRingBufferImpl::readPointer(qint64 maximumLength, qint64 &len) +{ + if (atEnd()) { + len = -1; + return 0; + } + + const char *returnValue = ringBuffer->readPointerAtPosition(currentPosition, len); + + if (maximumLength != -1) + len = qMin(len, maximumLength); + + return returnValue; +}; + +bool QNonContiguousByteDeviceRingBufferImpl::advanceReadPointer(qint64 amount) +{ + currentPosition += amount; + emit readProgress(currentPosition, size()); + return true; +}; + +bool QNonContiguousByteDeviceRingBufferImpl::atEnd() +{ + return currentPosition >= size(); +}; + +bool QNonContiguousByteDeviceRingBufferImpl::reset() +{ + if (resetDisabled) + return false; + + currentPosition = 0; + return true; +}; + +qint64 QNonContiguousByteDeviceRingBufferImpl::size() +{ + return ringBuffer->size(); +}; + +QNonContiguousByteDeviceIoDeviceImpl::QNonContiguousByteDeviceIoDeviceImpl(QIODevice *d) + : QNonContiguousByteDevice(), + currentReadBuffer(0), currentReadBufferSize(16*1024), + currentReadBufferAmount(0), currentReadBufferPosition(0), totalAdvancements(0), + eof(false) +{ + device = d; + initialPosition = d->pos(); + connect(device, SIGNAL(readyRead()), this, SIGNAL(readyRead()), Qt::QueuedConnection); + connect(device, SIGNAL(readChannelFinished()), this, SIGNAL(readyRead()), Qt::QueuedConnection); +}; + +QNonContiguousByteDeviceIoDeviceImpl::~QNonContiguousByteDeviceIoDeviceImpl() +{ + delete currentReadBuffer; +}; + +const char* QNonContiguousByteDeviceIoDeviceImpl::readPointer(qint64 maximumLength, qint64 &len) +{ + if (eof == true) { + len = -1; + return 0; + } + + if (currentReadBuffer == 0) + currentReadBuffer = new QByteArray(currentReadBufferSize, '\0'); // lazy alloc + + if (maximumLength == -1) + maximumLength = currentReadBufferSize; + + if (currentReadBufferAmount - currentReadBufferPosition > 0) { + len = currentReadBufferAmount - currentReadBufferPosition; + return currentReadBuffer->data() + currentReadBufferPosition; + } + + qint64 haveRead = device->read(currentReadBuffer->data(), qMin(maximumLength, currentReadBufferSize)); + + if ((haveRead == -1) || (haveRead == 0 && device->atEnd() && !device->isSequential())) { + eof = true; + len = -1; + // size was unknown before, emit a readProgress with the final size + if (size() == -1) + emit readProgress(totalAdvancements, totalAdvancements); + return 0; + } + + currentReadBufferAmount = haveRead; + currentReadBufferPosition = 0; + + len = haveRead; + return currentReadBuffer->data(); +}; + +bool QNonContiguousByteDeviceIoDeviceImpl::advanceReadPointer(qint64 amount) +{ + totalAdvancements += amount; + + // normal advancement + currentReadBufferPosition += amount; + + // advancing over that what has actually been read before + if (currentReadBufferPosition > currentReadBufferAmount) { + qint64 i = currentReadBufferPosition - currentReadBufferAmount; + while (i > 0) { + if (device->getChar(0) == false) { + emit readProgress(totalAdvancements - i, size()); + return false; // ### FIXME handle eof + } + i--; + } + + currentReadBufferPosition = 0; + currentReadBufferAmount = 0; + } + + if (size() == -1) + emit readProgress(totalAdvancements, totalAdvancements); + else + emit readProgress(totalAdvancements, size()); + + return true; +}; + +bool QNonContiguousByteDeviceIoDeviceImpl::atEnd() +{ + return eof == true; +}; + +bool QNonContiguousByteDeviceIoDeviceImpl::reset() +{ + if (resetDisabled) + return false; + + if (device->seek(initialPosition)) { + eof = false; // assume eof is false, it will be true after a read has been attempted + return true; + } + + return false; +}; + +qint64 QNonContiguousByteDeviceIoDeviceImpl::size() +{ + // note that this is different from the size() implementation of QIODevice! + + if (device->isSequential()) + return -1; + + return device->size() - initialPosition; +}; + +QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(QNonContiguousByteDevice *bd) : QIODevice((QObject*)0) +{ + byteDevice = bd; + connect(bd, SIGNAL(readyRead()), SIGNAL(readyRead())); + + open(ReadOnly); +} + +QByteDeviceWrappingIoDevice::~QByteDeviceWrappingIoDevice() +{ + +} + +bool QByteDeviceWrappingIoDevice::isSequential() const +{ + return (byteDevice->size() == -1); +} + +bool QByteDeviceWrappingIoDevice::atEnd() const +{ + return byteDevice->atEnd(); +} + +bool QByteDeviceWrappingIoDevice::reset() +{ + return byteDevice->reset(); +} + +qint64 QByteDeviceWrappingIoDevice::size() const +{ + if (isSequential()) + return 0; + + return byteDevice->size(); +} + + +qint64 QByteDeviceWrappingIoDevice::readData( char * data, qint64 maxSize) +{ + qint64 len; + const char *readPointer = byteDevice->readPointer(maxSize, len); + if (len == -1) + return -1; + + memcpy(data, readPointer, len); + byteDevice->advanceReadPointer(len); + return len; +} + +qint64 QByteDeviceWrappingIoDevice::writeData( const char* data, qint64 maxSize) +{ + return -1; +} + +/*! + \class QNonContiguousByteDeviceFactory + \since 4.6 + + \inmodule QtCore + + Creates a QNonContiguousByteDevice out of a QIODevice, + QByteArray etc. + + \sa QNonContiguousByteDevice + + \internal +*/ + +/*! + \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QIODevice *device); + + Create a QNonContiguousByteDevice out of a QIODevice. + For QFile, QBuffer and all other QIoDevice, sequential or not. + + \internal +*/ +QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QIODevice *device) +{ + // shortcut if it is a QBuffer + if (QBuffer* buffer = qobject_cast(device)) { + return new QNonContiguousByteDeviceBufferImpl(buffer); + } + + // ### FIXME special case if device is a QFile that supports map() + // then we can actually deal with the file without using read/peek + + // generic QIODevice + return new QNonContiguousByteDeviceIoDeviceImpl(device); // FIXME +}; + +/*! + \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QRingBuffer *ringBuffer); + + Create a QNonContiguousByteDevice out of a QRingBuffer. + + \internal +*/ +QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QRingBuffer *ringBuffer) +{ + return new QNonContiguousByteDeviceRingBufferImpl(ringBuffer); +}; + +/*! + \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *byteArray); + + Create a QNonContiguousByteDevice out of a QByteArray. + + \internal +*/ +QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *byteArray) +{ + return new QNonContiguousByteDeviceByteArrayImpl(byteArray); +}; + +/*! + \fn static QIODevice* QNonContiguousByteDeviceFactory::wrap(QNonContiguousByteDevice* byteDevice); + + Wrap the \a byteDevice (possibly again) into a QIODevice. + + \internal +*/ +QIODevice* QNonContiguousByteDeviceFactory::wrap(QNonContiguousByteDevice* byteDevice) +{ + // ### FIXME if it already has been based on QIoDevice, we could that one out again + // and save some calling + + // needed for FTP backend + + return new QByteDeviceWrappingIoDevice(byteDevice); +} + +QT_END_NAMESPACE + diff --git a/src/corelib/io/qnoncontiguousbytedevice_p.h b/src/corelib/io/qnoncontiguousbytedevice_p.h new file mode 100644 index 0000000..2a7e40b --- /dev/null +++ b/src/corelib/io/qnoncontiguousbytedevice_p.h @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtCore 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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNONCONTIGUOUSBYTEDEVICE_H +#define QNONCONTIGUOUSBYTEDEVICE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of a number of Qt sources files. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include +#include "private/qringbuffer_p.h" + +QT_BEGIN_NAMESPACE + +class Q_CORE_EXPORT QNonContiguousByteDevice : public QObject +{ + Q_OBJECT +public: + virtual const char* readPointer(qint64 maximumLength, qint64 &len) = 0; + virtual bool advanceReadPointer(qint64 amount) = 0; + virtual bool atEnd() = 0; + virtual bool reset() = 0; + void disableReset(); + virtual qint64 size() = 0; + +protected: + QNonContiguousByteDevice(); + virtual ~QNonContiguousByteDevice(); + + bool resetDisabled; +signals: + void readyRead(); + void readProgress(qint64 current, qint64 total); +}; + +class Q_CORE_EXPORT QNonContiguousByteDeviceFactory +{ +public: + static QNonContiguousByteDevice* create(QIODevice *device); + static QNonContiguousByteDevice* create(QByteArray *byteArray); + static QNonContiguousByteDevice* create(QRingBuffer *ringBuffer); + static QIODevice* wrap(QNonContiguousByteDevice* byteDevice); +}; + +// the actual implementations +// + +class QNonContiguousByteDeviceByteArrayImpl : public QNonContiguousByteDevice +{ + Q_OBJECT +public: + QNonContiguousByteDeviceByteArrayImpl(QByteArray *ba); + ~QNonContiguousByteDeviceByteArrayImpl(); + const char* readPointer(qint64 maximumLength, qint64 &len); + bool advanceReadPointer(qint64 amount); + bool atEnd(); + bool reset(); + qint64 size(); +protected: + QByteArray* byteArray; + qint64 currentPosition; +}; + +class QNonContiguousByteDeviceRingBufferImpl : public QNonContiguousByteDevice +{ + Q_OBJECT +public: + QNonContiguousByteDeviceRingBufferImpl(QRingBuffer *rb); + ~QNonContiguousByteDeviceRingBufferImpl(); + const char* readPointer(qint64 maximumLength, qint64 &len); + bool advanceReadPointer(qint64 amount); + bool atEnd(); + bool reset(); + qint64 size(); +protected: + QRingBuffer* ringBuffer; + qint64 currentPosition; +}; + + +class QNonContiguousByteDeviceIoDeviceImpl : public QNonContiguousByteDevice +{ + Q_OBJECT +public: + QNonContiguousByteDeviceIoDeviceImpl(QIODevice *d); + ~QNonContiguousByteDeviceIoDeviceImpl(); + const char* readPointer(qint64 maximumLength, qint64 &len); + bool advanceReadPointer(qint64 amount); + bool atEnd(); + bool reset(); + qint64 size(); +protected: + QIODevice* device; + QByteArray* currentReadBuffer; + qint64 currentReadBufferSize; + qint64 currentReadBufferAmount; + qint64 currentReadBufferPosition; + qint64 totalAdvancements; + bool eof; + qint64 initialPosition; +}; + +class QNonContiguousByteDeviceBufferImpl : public QNonContiguousByteDevice +{ + Q_OBJECT +public: + QNonContiguousByteDeviceBufferImpl(QBuffer *b); + ~QNonContiguousByteDeviceBufferImpl(); + const char* readPointer(qint64 maximumLength, qint64 &len); + bool advanceReadPointer(qint64 amount); + bool atEnd(); + bool reset(); + qint64 size(); +protected: + QBuffer* buffer; + QByteArray byteArray; + QNonContiguousByteDeviceByteArrayImpl* arrayImpl; +}; + +// ... and the reverse thing +class QByteDeviceWrappingIoDevice : public QIODevice +{ + Q_OBJECT +public: + QByteDeviceWrappingIoDevice (QNonContiguousByteDevice *bd); + ~QByteDeviceWrappingIoDevice (); + virtual bool isSequential () const; + virtual bool atEnd () const; + virtual bool reset (); + virtual qint64 size () const; +protected: + virtual qint64 readData ( char * data, qint64 maxSize ); + virtual qint64 writeData ( const char * data, qint64 maxSize ); + + QNonContiguousByteDevice *byteDevice; +}; + +QT_END_NAMESPACE + +#endif -- cgit v0.12 From 66534102f76c89c6f07f42dab0a47b0d2debec97 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 13 May 2009 13:06:43 +0200 Subject: QNAM: Added DoNotBufferUploadDataAttribute Reviewed-by: Thiago Macieira --- src/network/access/qnetworkrequest.cpp | 7 +++++++ src/network/access/qnetworkrequest.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index 56b793d..8b1afba 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -162,6 +162,13 @@ QT_BEGIN_NAMESPACE Indicates whether the data was obtained from cache or not. + \value DoNotBufferUploadDataAttribute + Requests only, type: QVariant::Bool (default: false) + Indicates whether the QNetworkAccessManager code is + allowed to buffer the upload data, e.g. when doing a HTTP POST. + When using this flag with sequential upload data, the ContentLengthHeader + header must be set. + \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 6f34bce..5dea1df 100644 --- a/src/network/access/qnetworkrequest.h +++ b/src/network/access/qnetworkrequest.h @@ -75,6 +75,7 @@ public: CacheLoadControlAttribute, CacheSaveControlAttribute, SourceIsFromCacheAttribute, + DoNotBufferUploadDataAttribute, User = 1000, UserMax = 32767 -- cgit v0.12 From 9d827648b7618cd3bdad6548e83b1d16453c96bf Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 13 May 2009 13:12:25 +0200 Subject: QNAM: Upload architecture change: HTTP implementation Reviewed-by: Peter Hartmann Reviewed-by: Thiago Macieira --- src/network/access/qhttpnetworkconnection.cpp | 215 ++++++++++++++------------ src/network/access/qhttpnetworkconnection_p.h | 8 +- src/network/access/qhttpnetworkreply.cpp | 12 +- src/network/access/qhttpnetworkreply_p.h | 7 +- src/network/access/qhttpnetworkrequest.cpp | 19 +-- src/network/access/qhttpnetworkrequest_p.h | 9 +- 6 files changed, 144 insertions(+), 126 deletions(-) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 5940fba..af0ac84 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qhttpnetworkconnection_p.h" +#include "private/qnoncontiguousbytedevice_p.h" #include #include #include @@ -71,6 +72,7 @@ QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(const QString &host #ifndef QT_NO_NETWORKPROXY , networkProxy(QNetworkProxy::NoProxy) #endif + { } @@ -205,12 +207,19 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair) // add missing fields for the request QByteArray value; // check if Content-Length is provided - QIODevice *data = request.data(); - if (data && request.contentLength() == -1) { - if (!data->isSequential()) - request.setContentLength(data->size()); - else - bufferData(messagePair); // ### or do chunked upload + QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice(); + if (uploadByteDevice) { + if (request.contentLength() != -1 && uploadByteDevice->size() != -1) { + // both values known, take the smaller one. + request.setContentLength(qMin(uploadByteDevice->size(), request.contentLength())); + } else if (request.contentLength() == -1 && uploadByteDevice->size() != -1) { + // content length not supplied by user, but the upload device knows it + request.setContentLength(uploadByteDevice->size()); + } else if (request.contentLength() != -1 && uploadByteDevice->size() == -1) { + // everything OK, the user supplied us the contentLength + } else if (request.contentLength() == -1 && uploadByteDevice->size() == -1) { + qFatal("QHttpNetworkConnectionPrivate: Neither content-length nor upload device size were given"); + } } // set the Connection/Proxy-Connection: Keep-Alive headers #ifndef QT_NO_NETWORKPROXY @@ -361,18 +370,12 @@ bool QHttpNetworkConnectionPrivate::sendRequest(QAbstractSocket *socket) false); #endif socket->write(header); - QIODevice *data = channels[i].request.d->data; - QHttpNetworkReply *reply = channels[i].reply; - if (reply && reply->d_func()->requestDataBuffer.size()) - data = &channels[i].reply->d_func()->requestDataBuffer; - if (data && (data->isOpen() || data->open(QIODevice::ReadOnly))) { - if (data->isSequential()) { - channels[i].bytesTotal = -1; - QObject::connect(data, SIGNAL(readyRead()), q, SLOT(_q_dataReadyReadNoBuffer())); - QObject::connect(data, SIGNAL(readChannelFinished()), q, SLOT(_q_dataReadyReadNoBuffer())); - } else { - channels[i].bytesTotal = data->size(); - } + QNonContiguousByteDevice* uploadByteDevice = channels[i].request.uploadByteDevice(); + if (uploadByteDevice) { + // connect the signals so this function gets called again + QObject::connect(uploadByteDevice, SIGNAL(readyRead()), q, SLOT(_q_uploadDataReadyRead())); + + channels[i].bytesTotal = channels[i].request.contentLength(); } else { channels[i].state = WaitingState; break; @@ -380,30 +383,81 @@ bool QHttpNetworkConnectionPrivate::sendRequest(QAbstractSocket *socket) // write the initial chunk together with the headers // fall through } - case WritingState: { // write the data - QIODevice *data = channels[i].request.d->data; - if (channels[i].reply->d_func()->requestDataBuffer.size()) - data = &channels[i].reply->d_func()->requestDataBuffer; - if (!data || channels[i].bytesTotal == channels[i].written) { + case 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 = WaitingState; // now wait for response + sendRequest(socket); break; } - QByteArray chunk; - chunk.resize(ChunkSize); - qint64 readSize = data->read(chunk.data(), ChunkSize); - if (readSize == -1) { - // source has reached EOF - channels[i].state = WaitingState; // now wait for response - } else if (readSize > 0) { - // source gave us something useful - channels[i].written += socket->write(chunk.data(), readSize); - if (channels[i].reply) - emit channels[i].reply->dataSendProgress(channels[i].written, channels[i].bytesTotal); + // 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(socket); + while ((sslSocket->encryptedBytesToWrite() + sslSocket->bytesToWrite()) <= 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 = WaitingState; + sendRequest(socket); + break; + } + } + } } break; } + case WaitingState: + { + QNonContiguousByteDevice* uploadByteDevice = channels[i].request.uploadByteDevice(); + if (uploadByteDevice) { + QObject::disconnect(uploadByteDevice, SIGNAL(readyRead()), q, 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 ReadingState: case Wait4AuthState: // ignore _q_bytesWritten in these states @@ -479,6 +533,9 @@ bool QHttpNetworkConnectionPrivate::expand(QAbstractSocket *socket, QHttpNetwork // make sure that the reply is valid if (channels[i].reply != reply) return true; + // emit dataReadProgress signal (signal is currently not connected + // to the rest of QNAM) since readProgress of the + // QNonContiguousByteDevice is used emit reply->dataReadProgress(reply->d_func()->totalProgress, 0); // make sure that the reply is valid if (channels[i].reply != reply) @@ -569,6 +626,9 @@ void QHttpNetworkConnectionPrivate::receiveReply(QAbstractSocket *socket, QHttpN // make sure that the reply is valid if (channels[i].reply != reply) return; + // emit dataReadProgress signal (signal is currently not connected + // to the rest of QNAM) since readProgress of the + // QNonContiguousByteDevice is used emit reply->dataReadProgress(reply->d_func()->totalProgress, reply->d_func()->bodyLength); // make sure that the reply is valid if (channels[i].reply != reply) @@ -635,8 +695,25 @@ void QHttpNetworkConnectionPrivate::handleStatus(QAbstractSocket *socket, QHttpN case 407: 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); - sendRequest(socket); + + // 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); + } break; default: @@ -970,6 +1047,7 @@ void QHttpNetworkConnectionPrivate::_q_bytesWritten(qint64 bytes) QAbstractSocket *socket = qobject_cast(q->sender()); if (!socket) return; // ### error + // bytes have been written to the socket. write even more of them :) if (isSocketWriting(socket)) sendRequest(socket); // otherwise we do nothing @@ -1128,80 +1206,21 @@ void QHttpNetworkConnectionPrivate::_q_proxyAuthenticationRequired(const QNetwor } #endif -void QHttpNetworkConnectionPrivate::_q_dataReadyReadNoBuffer() +void QHttpNetworkConnectionPrivate::_q_uploadDataReadyRead() { Q_Q(QHttpNetworkConnection); - // data emitted either readyRead() + // upload data emitted readyRead() // find out which channel it is for - QIODevice *sender = qobject_cast(q->sender()); + QObject *sender = q->sender(); - // won't match anything if the qobject_cast above failed for (int i = 0; i < channelCount; ++i) { - if (sender == channels[i].request.data()) { + if (sender == channels[i].request.uploadByteDevice()) { sendRequest(channels[i].socket); break; } } } -void QHttpNetworkConnectionPrivate::_q_dataReadyReadBuffer() -{ - Q_Q(QHttpNetworkConnection); - QIODevice *sender = qobject_cast(q->sender()); - HttpMessagePair *thePair = 0; - for (int i = 0; !thePair && i < lowPriorityQueue.size(); ++i) - if (lowPriorityQueue.at(i).first.data() == sender) - thePair = &lowPriorityQueue[i]; - - for (int i = 0; !thePair && i < highPriorityQueue.size(); ++i) - if (highPriorityQueue.at(i).first.data() == sender) - thePair = &highPriorityQueue[i]; - - if (thePair) { - bufferData(*thePair); - - // are we finished buffering? - if (!thePair->second->d_func()->requestIsBuffering) - _q_startNextRequest(); - } -} - -void QHttpNetworkConnectionPrivate::bufferData(HttpMessagePair &messagePair) -{ - Q_Q(QHttpNetworkConnection); - QHttpNetworkRequest &request = messagePair.first; - QHttpNetworkReply *reply = messagePair.second; - Q_ASSERT(request.data()); - if (!reply->d_func()->requestIsBuffering) { // first time - QObject::connect(request.data(), SIGNAL(readyRead()), q, SLOT(_q_dataReadyReadBuffer())); - QObject::connect(request.data(), SIGNAL(readChannelFinished()), q, SLOT(_q_dataReadyReadBuffer())); - reply->d_func()->requestIsBuffering = true; - reply->d_func()->requestDataBuffer.open(QIODevice::ReadWrite); - } - - // always try to read at least one byte - // ### FIXME! use a QRingBuffer - qint64 bytesToRead = qMax(1, request.data()->bytesAvailable()); - QByteArray newData; - newData.resize(bytesToRead); - qint64 bytesActuallyRead = request.data()->read(newData.data(), bytesToRead); - - if (bytesActuallyRead > 0) { - // we read something - newData.chop(bytesToRead - bytesActuallyRead); - reply->d_func()->requestDataBuffer.write(newData); - } else if (bytesActuallyRead == -1) { // last time - QObject::disconnect(request.data(), SIGNAL(readyRead()), q, SLOT(_q_dataReadyReadBuffer())); - QObject::disconnect(request.data(), SIGNAL(readChannelFinished()), q, SLOT(_q_dataReadyReadBuffer())); - - request.setContentLength(reply->d_func()->requestDataBuffer.size()); - reply->d_func()->requestDataBuffer.seek(0); - reply->d_func()->requestIsBuffering = false; - } -} - -// QHttpNetworkConnection - QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt, QObject *parent) : QObject(*(new QHttpNetworkConnectionPrivate(hostName, port, encrypt)), parent) { diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 09bd459..9b127dd 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -146,8 +146,7 @@ private: #ifndef QT_NO_NETWORKPROXY Q_PRIVATE_SLOT(d_func(), void _q_proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)) #endif - Q_PRIVATE_SLOT(d_func(), void _q_dataReadyReadBuffer()) - Q_PRIVATE_SLOT(d_func(), void _q_dataReadyReadNoBuffer()) + Q_PRIVATE_SLOT(d_func(), void _q_uploadDataReadyRead()) #ifndef QT_NO_OPENSSL Q_PRIVATE_SLOT(d_func(), void _q_encrypted()) @@ -209,8 +208,8 @@ public: #ifndef QT_NO_NETWORKPROXY void _q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); // from transparent proxy #endif - void _q_dataReadyReadNoBuffer(); - void _q_dataReadyReadBuffer(); + + void _q_uploadDataReadyRead(); void createAuthorization(QAbstractSocket *socket, QHttpNetworkRequest &request); bool ensureConnection(QAbstractSocket *socket); @@ -219,7 +218,6 @@ public: #ifndef QT_NO_COMPRESS bool expand(QAbstractSocket *socket, QHttpNetworkReply *reply, bool dataComplete); #endif - void bufferData(HttpMessagePair &request); void removeReply(QHttpNetworkReply *reply); QString hostName; diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index fe3f6af..4485485 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -521,13 +521,13 @@ qint64 QHttpNetworkReplyPrivate::readBody(QAbstractSocket *socket, QIODevice *ou { qint64 bytes = 0; if (isChunked()) { - bytes += transferChunked(socket, out); // chunked transfer encoding (rfc 2616, sec 3.6) + bytes += readReplyBodyChunked(socket, out); // chunked transfer encoding (rfc 2616, sec 3.6) } else if (bodyLength > 0) { // we have a Content-Length - bytes += transferRaw(socket, out, bodyLength - contentRead); + bytes += readReplyBodyRaw(socket, out, bodyLength - contentRead); if (contentRead + bytes == bodyLength) state = AllDoneState; } else { - bytes += transferRaw(socket, out, socket->bytesAvailable()); + bytes += readReplyBodyRaw(socket, out, socket->bytesAvailable()); } if (state == AllDoneState) socket->readAll(); // Read the rest to clean (CRLF) @@ -535,7 +535,7 @@ qint64 QHttpNetworkReplyPrivate::readBody(QAbstractSocket *socket, QIODevice *ou return bytes; } -qint64 QHttpNetworkReplyPrivate::transferRaw(QIODevice *in, QIODevice *out, qint64 size) +qint64 QHttpNetworkReplyPrivate::readReplyBodyRaw(QIODevice *in, QIODevice *out, qint64 size) { qint64 bytes = 0; Q_ASSERT(in); @@ -561,7 +561,7 @@ qint64 QHttpNetworkReplyPrivate::transferRaw(QIODevice *in, QIODevice *out, qint } -qint64 QHttpNetworkReplyPrivate::transferChunked(QIODevice *in, QIODevice *out) +qint64 QHttpNetworkReplyPrivate::readReplyBodyChunked(QIODevice *in, QIODevice *out) { qint64 bytes = 0; while (in->bytesAvailable()) { // while we can read from input @@ -660,4 +660,4 @@ void QHttpNetworkReply::ignoreSslErrors() QT_END_NAMESPACE -#endif // QT_NO_HTTP \ No newline at end of file +#endif // QT_NO_HTTP diff --git a/src/network/access/qhttpnetworkreply_p.h b/src/network/access/qhttpnetworkreply_p.h index c17c65c..238a1da 100644 --- a/src/network/access/qhttpnetworkreply_p.h +++ b/src/network/access/qhttpnetworkreply_p.h @@ -139,7 +139,7 @@ Q_SIGNALS: void finishedWithError(QNetworkReply::NetworkError errorCode, const QString &detail = QString()); void headerChanged(); void dataReadProgress(int done, int total); - void dataSendProgress(int done, int total); + void dataSendProgress(qint64 done, qint64 total); private: Q_DECLARE_PRIVATE(QHttpNetworkReply) @@ -162,8 +162,8 @@ public: QAuthenticatorPrivate::Method authenticationMethod(bool isProxy) const; void clear(); - qint64 transferRaw(QIODevice *in, QIODevice *out, qint64 size); - qint64 transferChunked(QIODevice *in, QIODevice *out); + qint64 readReplyBodyRaw(QIODevice *in, QIODevice *out, qint64 size); + qint64 readReplyBodyChunked(QIODevice *in, QIODevice *out); qint64 getChunkSize(QIODevice *in, qint64 *chunkSize); qint64 bytesAvailable() const; @@ -206,7 +206,6 @@ public: QByteArray responseData; // uncompressed body QByteArray compressedData; // compressed body (temporary) - QBuffer requestDataBuffer; bool requestIsBuffering; bool requestIsPrepared; }; diff --git a/src/network/access/qhttpnetworkrequest.cpp b/src/network/access/qhttpnetworkrequest.cpp index 420cb69..7df68fc 100644 --- a/src/network/access/qhttpnetworkrequest.cpp +++ b/src/network/access/qhttpnetworkrequest.cpp @@ -40,12 +40,13 @@ ****************************************************************************/ #include "qhttpnetworkrequest_p.h" +#include "private/qnoncontiguousbytedevice_p.h" QT_BEGIN_NAMESPACE QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(QHttpNetworkRequest::Operation op, QHttpNetworkRequest::Priority pri, const QUrl &newUrl) - : QHttpNetworkHeaderPrivate(newUrl), operation(op), priority(pri), data(0), + : QHttpNetworkHeaderPrivate(newUrl), operation(op), priority(pri), uploadByteDevice(0), autoDecompress(false) { } @@ -55,7 +56,7 @@ QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(const QHttpNetworkRequest { operation = other.operation; priority = other.priority; - data = other.data; + uploadByteDevice = other.uploadByteDevice; autoDecompress = other.autoDecompress; } @@ -67,7 +68,7 @@ bool QHttpNetworkRequestPrivate::operator==(const QHttpNetworkRequestPrivate &ot { return QHttpNetworkHeaderPrivate::operator==(other) && (operation == other.operation) - && (data == other.data); + && (uploadByteDevice == other.uploadByteDevice); } QByteArray QHttpNetworkRequestPrivate::methodName() const @@ -109,7 +110,7 @@ QByteArray QHttpNetworkRequestPrivate::uri(bool throughProxy) const QUrl::FormattingOptions format(QUrl::RemoveFragment); // for POST, query data is send as content - if (operation == QHttpNetworkRequest::Post && !data) + if (operation == QHttpNetworkRequest::Post && !uploadByteDevice) format |= QUrl::RemoveQuery; // for requests through proxy, the Request-URI contains full url if (throughProxy) @@ -140,7 +141,7 @@ QByteArray QHttpNetworkRequestPrivate::header(const QHttpNetworkRequest &request // add content type, if not set in the request if (request.headerField("content-type").isEmpty()) ba += "Content-Type: application/x-www-form-urlencoded\r\n"; - if (!request.d->data && request.d->url.hasQuery()) { + if (!request.d->uploadByteDevice && request.d->url.hasQuery()) { QByteArray query = request.d->url.encodedQuery(); ba += "Content-Length: "+ QByteArray::number(query.size()) + "\r\n"; ba += "\r\n"; @@ -236,14 +237,14 @@ void QHttpNetworkRequest::setPriority(Priority priority) d->priority = priority; } -QIODevice *QHttpNetworkRequest::data() const +void QHttpNetworkRequest::setUploadByteDevice(QNonContiguousByteDevice *bd) { - return d->data; + d->uploadByteDevice = bd; } -void QHttpNetworkRequest::setData(QIODevice *data) +QNonContiguousByteDevice* QHttpNetworkRequest::uploadByteDevice() const { - d->data = data; + return d->uploadByteDevice; } int QHttpNetworkRequest::majorVersion() const diff --git a/src/network/access/qhttpnetworkrequest_p.h b/src/network/access/qhttpnetworkrequest_p.h index d18e116..ed4325a 100644 --- a/src/network/access/qhttpnetworkrequest_p.h +++ b/src/network/access/qhttpnetworkrequest_p.h @@ -58,6 +58,8 @@ QT_BEGIN_NAMESPACE +class QNonContiguousByteDevice; + class QHttpNetworkRequestPrivate; class Q_AUTOTEST_EXPORT QHttpNetworkRequest: public QHttpNetworkHeader { @@ -104,8 +106,8 @@ public: Priority priority() const; void setPriority(Priority priority); - QIODevice *data() const; - void setData(QIODevice *data); + void setUploadByteDevice(QNonContiguousByteDevice *bd); + QNonContiguousByteDevice* uploadByteDevice() const; private: QSharedDataPointer d; @@ -113,7 +115,6 @@ private: friend class QHttpNetworkConnectionPrivate; }; - class QHttpNetworkRequestPrivate : public QHttpNetworkHeaderPrivate { public: @@ -129,7 +130,7 @@ public: QHttpNetworkRequest::Operation operation; QHttpNetworkRequest::Priority priority; - mutable QIODevice *data; + mutable QNonContiguousByteDevice* uploadByteDevice; bool autoDecompress; }; -- cgit v0.12 From 21199a2bb0b5d6c4d419157656c975c16c947b8f Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 13 May 2009 13:16:04 +0200 Subject: QNAM: Upload architecture change: Backend and QNetworkReplyImpl changes Reviewed-by: Thiago Macieira Reviewed-by: Peter Hartmann --- src/network/access/qnetworkaccessbackend.cpp | 57 +++++--- src/network/access/qnetworkaccessbackend_p.h | 38 ++--- src/network/access/qnetworkaccessmanager.cpp | 8 +- src/network/access/qnetworkreplyimpl.cpp | 202 ++++++++++++++++----------- src/network/access/qnetworkreplyimpl_p.h | 17 ++- 5 files changed, 188 insertions(+), 134 deletions(-) diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index df468b8..b9d1b85 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -50,6 +50,8 @@ #include "qnetworkaccesscachebackend_p.h" #include "qabstractnetworkcache.h" +#include "private/qnoncontiguousbytedevice_p.h" + QT_BEGIN_NAMESPACE static bool factoryDataShutdown = false; @@ -109,17 +111,43 @@ QNetworkAccessBackend *QNetworkAccessManagerPrivate::findBackend(QNetworkAccessM return 0; } -QNetworkAccessBackend::QNetworkAccessBackend() + +QNonContiguousByteDevice* QNetworkAccessBackend::createUploadByteDevice() { + QNonContiguousByteDevice* device = 0; + + if (reply->outgoingDataBuffer) + device = QNonContiguousByteDeviceFactory::create(reply->outgoingDataBuffer); + else + device = QNonContiguousByteDeviceFactory::create(reply->outgoingData); + + bool bufferDisallowed = + reply->request.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute, + QVariant(false)) == QVariant(true); + if (bufferDisallowed) + device->disableReset(); + + // make sure we delete this later + device->setParent(this); + + connect(device, SIGNAL(readProgress(qint64,qint64)), this, SLOT(emitReplyUploadProgress(qint64,qint64))); + + return device; } -QNetworkAccessBackend::~QNetworkAccessBackend() +// need to have this function since the reply is a private member variable +// and the special backends need to access this. +void QNetworkAccessBackend::emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal) { + reply->emitUploadProgress(bytesSent, bytesTotal); } -void QNetworkAccessBackend::upstreamReadyRead() +QNetworkAccessBackend::QNetworkAccessBackend() +{ +} + +QNetworkAccessBackend::~QNetworkAccessBackend() { - // do nothing } void QNetworkAccessBackend::downstreamReadyWrite() @@ -184,23 +212,6 @@ bool QNetworkAccessBackend::isCachingEnabled() const return reply->isCachingEnabled(); } -qint64 QNetworkAccessBackend::upstreamBytesAvailable() const -{ - return reply->writeBuffer.size(); -} - -void QNetworkAccessBackend::upstreamBytesConsumed(qint64 count) -{ - // remove count bytes from the write buffer - reply->consume(count); -} - -QByteArray QNetworkAccessBackend::readUpstream() -{ - // ### this is expensive. Consider making QRingBuffer::peekAll keep the buffer it returns - return reply->writeBuffer.peek(upstreamBytesAvailable()); -} - qint64 QNetworkAccessBackend::nextDownstreamBlockSize() const { return reply->nextDownstreamBlockSize(); @@ -213,12 +224,12 @@ qint64 QNetworkAccessBackend::downstreamBytesToConsume() const void QNetworkAccessBackend::writeDownstreamData(const QByteArray &data) { - reply->feed(data); + reply->appendDownstreamData(data); } void QNetworkAccessBackend::writeDownstreamData(QIODevice *data) { - reply->feed(data); + reply->appendDownstreamData(data); } QVariant QNetworkAccessBackend::header(QNetworkRequest::KnownHeaders header) const diff --git a/src/network/access/qnetworkaccessbackend_p.h b/src/network/access/qnetworkaccessbackend_p.h index 9012396..6035f3a 100644 --- a/src/network/access/qnetworkaccessbackend_p.h +++ b/src/network/access/qnetworkaccessbackend_p.h @@ -70,6 +70,8 @@ class QNetworkAccessManagerPrivate; class QNetworkReplyImplPrivate; class QAbstractNetworkCache; class QNetworkCacheMetaData; +class QNetworkAccessBackendUploadIODevice; +class QNonContiguousByteDevice; // Should support direct file upload from disk or download to disk. // @@ -86,14 +88,13 @@ public: // have different names. The Connection has two streams: // // - Upstream: - // Upstream is data that is being written into this connection, - // from the user. Upstream operates in a "pull" mechanism: the - // connection will be notified that there is more data available - // by a call to "upstreamReadyRead". The number of bytes - // available is given by upstreamBytesAvailable(). A call to - // readUpstream() always yields the entire upstream buffer. When - // the connection has processed a certain amount of bytes from - // that buffer, it should call upstreamBytesConsumed(). + // The upstream uses a QNonContiguousByteDevice provided + // by the backend. This device emits the usual readyRead() + // signal when the backend has data available for the connection + // to write. The different backends can listen on this signal + // and then pull upload data from the QNonContiguousByteDevice and + // deal with it. + // // // - Downstream: // Downstream is the data that is being read from this @@ -111,12 +112,9 @@ public: virtual void open() = 0; virtual void closeDownstreamChannel() = 0; - virtual void closeUpstreamChannel() = 0; virtual bool waitForDownstreamReadyRead(int msecs) = 0; - virtual bool waitForUpstreamBytesWritten(int msecs) = 0; // slot-like: - virtual void upstreamReadyRead(); virtual void downstreamReadyWrite(); virtual void copyFinished(QIODevice *); virtual void ignoreSslErrors(); @@ -155,18 +153,24 @@ public: QVariant attribute(QNetworkRequest::Attribute code) const; void setAttribute(QNetworkRequest::Attribute code, const QVariant &value); + // return true if the QNonContiguousByteDevice of the upload + // data needs to support reset(). Currently needed for HTTP. + // This will possibly enable buffering of the upload data. + virtual bool needsResetableUploadData() {return false;}; + protected: - // these functions control the upstream mechanism - // that is, data coming into the backend and out via the connection - qint64 upstreamBytesAvailable() const; - void upstreamBytesConsumed(qint64 count); - QByteArray readUpstream(); + // Create the device used for reading the upload data + QNonContiguousByteDevice* createUploadByteDevice(); + // these functions control the downstream mechanism // that is, data that has come via the connection and is going out the backend qint64 nextDownstreamBlockSize() const; qint64 downstreamBytesToConsume() const; void writeDownstreamData(const QByteArray &data); + +public slots: + // for task 251801, needs to be a slot to be called asynchronously void writeDownstreamData(QIODevice *data); protected slots: @@ -179,10 +183,12 @@ protected slots: void metaDataChanged(); void redirectionRequested(const QUrl &destination); void sslErrors(const QList &errors); + void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal); private: friend class QNetworkAccessManager; friend class QNetworkAccessManagerPrivate; + friend class QNetworkAccessBackendUploadIODevice; QNetworkAccessManagerPrivate *manager; QNetworkReplyImplPrivate *reply; }; diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index bcbeef1..bf06ede 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -686,7 +686,10 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera priv->urlForLastAuthentication = url; } - // third step: setup the reply + // third step: find a backend + priv->backend = d->findBackend(op, request); + + // fourth step: setup the reply priv->setup(op, request, outgoingData); if (request.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt() != QNetworkRequest::AlwaysNetwork) @@ -695,9 +698,6 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera QList proxyList = d->queryProxy(QNetworkProxyQuery(request.url())); priv->proxyList = proxyList; #endif - - // fourth step: find a backend - priv->backend = d->findBackend(op, request); if (priv->backend) { priv->backend->setParent(reply); priv->backend->reply = priv; diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 79c3d1a..749a462 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -46,13 +46,15 @@ #include "QtCore/qcoreapplication.h" #include "QtCore/qdatetime.h" #include "QtNetwork/qsslconfiguration.h" +#include "qnetworkaccesshttpbackend_p.h" #include QT_BEGIN_NAMESPACE inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate() - : copyDevice(0), networkCache(0), + : backend(0), outgoingData(0), outgoingDataBuffer(0), + copyDevice(0), networkCache(0), cacheEnabled(false), cacheSaveDevice(0), bytesDownloaded(0), lastBytesDownloaded(-1), bytesUploaded(-1), state(Idle) @@ -61,8 +63,13 @@ inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate() void QNetworkReplyImplPrivate::_q_startOperation() { - // This function is called exactly once + // ensure this function is only being called once + if (state == Working) { + qDebug("QNetworkReplyImpl::_q_startOperation was called more than once"); + return; + } state = Working; + if (!backend) { error(QNetworkReplyImpl::ProtocolUnknownError, QCoreApplication::translate("QNetworkReply", "Protocol \"%1\" is unknown").arg(url.scheme())); // not really true!; @@ -74,57 +81,11 @@ void QNetworkReplyImplPrivate::_q_startOperation() if (state != Finished) { if (operation == QNetworkAccessManager::GetOperation) pendingNotifications.append(NotifyDownstreamReadyWrite); - if (outgoingData) { - _q_sourceReadyRead(); -#if 0 // ### FIXME - if (outgoingData->atEndOfStream() && writeBuffer.isEmpty()) - // empty upload - emit q->uploadProgress(0, 0); -#endif - } handleNotifications(); } } -void QNetworkReplyImplPrivate::_q_sourceReadyRead() -{ - // read data from the outgoingData QIODevice into our internal buffer - enum { DesiredBufferSize = 32 * 1024 }; - - if (writeBuffer.size() >= DesiredBufferSize) - return; // don't grow the buffer too much - - // read as many bytes are available or up until we fill up the buffer - // but always read at least one byte - qint64 bytesToRead = qBound(1, outgoingData->bytesAvailable(), - DesiredBufferSize - writeBuffer.size()); - char *ptr = writeBuffer.reserve(bytesToRead); - qint64 bytesActuallyRead = outgoingData->read(ptr, bytesToRead); - if (bytesActuallyRead == -1) { - // EOF - writeBuffer.chop(bytesToRead); - backendNotify(NotifyCloseUpstreamChannel); - return; - } - - if (bytesActuallyRead < bytesToRead) - writeBuffer.chop(bytesToRead - bytesActuallyRead); - - // if we did read anything, let the backend know and handle it - if (bytesActuallyRead) - backendNotify(NotifyUpstreamReadyRead); - - // check for EOF again - if (!outgoingData->isSequential() && outgoingData->atEnd()) - backendNotify(NotifyCloseUpstreamChannel); -} - -void QNetworkReplyImplPrivate::_q_sourceReadChannelFinished() -{ - _q_sourceReadyRead(); -} - void QNetworkReplyImplPrivate::_q_copyReadyRead() { Q_Q(QNetworkReplyImpl); @@ -143,7 +104,7 @@ void QNetworkReplyImplPrivate::_q_copyReadyRead() if (bytesActuallyRead == -1) { readBuffer.chop(bytesToRead); backendNotify(NotifyCopyFinished); - return; + break; } if (bytesActuallyRead != bytesToRead) @@ -151,6 +112,7 @@ void QNetworkReplyImplPrivate::_q_copyReadyRead() if (!copyDevice->isSequential() && copyDevice->atEnd()) { backendNotify(NotifyCopyFinished); + bytesDownloaded += bytesActuallyRead; break; } @@ -174,6 +136,67 @@ void QNetworkReplyImplPrivate::_q_copyReadChannelFinished() _q_copyReadyRead(); } +void QNetworkReplyImplPrivate::_q_bufferOutgoingDataFinished() +{ + Q_Q(QNetworkReplyImpl); + + // make sure this is only called once, ever. + //_q_bufferOutgoingData may call it or the readChannelFinished emission + if (state != Buffering) + return; + + // disconnect signals + QObject::disconnect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData())); + QObject::disconnect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished())); + + // finally, start the request + QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); +} + +void QNetworkReplyImplPrivate::_q_bufferOutgoingData() +{ + Q_Q(QNetworkReplyImpl); + + if (!outgoingDataBuffer) { + // first call, create our buffer + outgoingDataBuffer = new QRingBuffer(); + + QObject::connect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData())); + QObject::connect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished())); + } + + qint64 bytesBuffered = 0; + qint64 bytesToBuffer = 0; + + // read data into our buffer + forever { + bytesToBuffer = outgoingData->bytesAvailable(); + // unknown? just try 2 kB, this also ensures we always try to read the EOF + if (bytesToBuffer <= 0) + bytesToBuffer = 2*1024; + + char *dst = outgoingDataBuffer->reserve(bytesToBuffer); + bytesBuffered = outgoingData->read(dst, bytesToBuffer); + + if (bytesBuffered == -1) { + // EOF has been reached. + outgoingDataBuffer->chop(bytesToBuffer); + + _q_bufferOutgoingDataFinished(); + break; + } else if (bytesBuffered == 0) { + // nothing read right now, just wait until we get called again + outgoingDataBuffer->chop(bytesToBuffer); + + break; + } else { + // don't break, try to read() again + outgoingDataBuffer->chop(bytesToBuffer - bytesBuffered); + } + } +} + + void QNetworkReplyImplPrivate::setup(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *data) { @@ -184,13 +207,42 @@ void QNetworkReplyImplPrivate::setup(QNetworkAccessManager::Operation op, const url = request.url(); operation = op; - if (outgoingData) { - q->connect(outgoingData, SIGNAL(readyRead()), SLOT(_q_sourceReadyRead())); - q->connect(outgoingData, SIGNAL(readChannelFinished()), SLOT(_q_sourceReadChannelFinished())); + if (outgoingData && backend) { + // there is data to be uploaded, e.g. HTTP POST. + + if (!backend->needsResetableUploadData() || !outgoingData->isSequential()) { + // backend does not need upload buffering or + // fixed size non-sequential + // just start the operation + QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); + } else { + bool bufferingDisallowed = + req.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute, + false).toBool(); + + if (bufferingDisallowed) { + // if a valid content-length header for the request was supplied, we can disable buffering + // if not, we will buffer anyway + if (req.header(QNetworkRequest::ContentLengthHeader).isValid()) { + QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); + } else { + state = Buffering; + QMetaObject::invokeMethod(q, "_q_bufferOutgoingData", Qt::QueuedConnection); + } + } else { + // _q_startOperation will be called when the buffering has finished. + state = Buffering; + QMetaObject::invokeMethod(q, "_q_bufferOutgoingData", Qt::QueuedConnection); + } + } + } else { + // No outgoing data (e.g. HTTP GET request) + // or no backend + // if no backend, _q_startOperation will handle the error of this + QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); } q->QIODevice::open(QIODevice::ReadOnly); - QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); } void QNetworkReplyImplPrivate::setNetworkCache(QAbstractNetworkCache *nc) @@ -226,18 +278,10 @@ void QNetworkReplyImplPrivate::handleNotifications() backend->downstreamReadyWrite(); break; - case NotifyUpstreamReadyRead: - backend->upstreamReadyRead(); - break; - case NotifyCloseDownstreamChannel: backend->closeDownstreamChannel(); break; - case NotifyCloseUpstreamChannel: - backend->closeUpstreamChannel(); - break; - case NotifyCopyFinished: { QIODevice *dev = copyDevice; copyDevice = 0; @@ -299,29 +343,14 @@ void QNetworkReplyImplPrivate::completeCacheSave() cacheEnabled = false; } -void QNetworkReplyImplPrivate::consume(qint64 count) +void QNetworkReplyImplPrivate::emitUploadProgress(qint64 bytesSent, qint64 bytesTotal) { Q_Q(QNetworkReplyImpl); - if (count <= 0) { - qWarning("QNetworkConnection: backend signalled that it consumed %ld bytes", long(count)); - return; - } - - if (outgoingData) - // schedule another read from the source - QMetaObject::invokeMethod(q_func(), "_q_sourceReadyRead", Qt::QueuedConnection); - - writeBuffer.skip(count); - if (bytesUploaded == -1) - bytesUploaded = count; - else - bytesUploaded += count; - - QVariant totalSize = request.header(QNetworkRequest::ContentLengthHeader); - emit q->uploadProgress(bytesUploaded, - totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong()); + bytesUploaded = bytesSent; + emit q->uploadProgress(bytesSent, bytesTotal); } + qint64 QNetworkReplyImplPrivate::nextDownstreamBlockSize() const { enum { DesiredBufferSize = 32 * 1024 }; @@ -331,7 +360,9 @@ qint64 QNetworkReplyImplPrivate::nextDownstreamBlockSize() const return qMax(0, readBufferMaxSize - readBuffer.size()); } -void QNetworkReplyImplPrivate::feed(const QByteArray &data) +// we received downstream data and send this to the cache +// and to our readBuffer (which in turn gets read by the user of QNetworkReply) +void QNetworkReplyImplPrivate::appendDownstreamData(const QByteArray &data) { Q_Q(QNetworkReplyImpl); if (!q->isOpen()) @@ -379,7 +410,8 @@ void QNetworkReplyImplPrivate::feed(const QByteArray &data) } } -void QNetworkReplyImplPrivate::feed(QIODevice *data) +// this is used when it was fetched from the cache, right? +void QNetworkReplyImplPrivate::appendDownstreamData(QIODevice *data) { Q_Q(QNetworkReplyImpl); Q_ASSERT(q->isOpen()); @@ -409,9 +441,11 @@ void QNetworkReplyImplPrivate::finished() pendingNotifications.clear(); QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); - if (bytesDownloaded != lastBytesDownloaded || totalSize.isNull()) + if (totalSize.isNull() || totalSize == -1) { emit q->downloadProgress(bytesDownloaded, bytesDownloaded); - if (bytesUploaded == -1 && outgoingData) + } + + if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer)) emit q->uploadProgress(0, 0); completeCacheSave(); diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index ad06f78..8d3c90e 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -59,6 +59,7 @@ #include "qnetworkproxy.h" #include "QtCore/qmap.h" #include "QtCore/qqueue.h" +#include "QtCore/qbuffer.h" #include "private/qringbuffer_p.h" QT_BEGIN_NAMESPACE @@ -91,10 +92,10 @@ public: Q_DECLARE_PRIVATE(QNetworkReplyImpl) Q_PRIVATE_SLOT(d_func(), void _q_startOperation()) - Q_PRIVATE_SLOT(d_func(), void _q_sourceReadyRead()) - Q_PRIVATE_SLOT(d_func(), void _q_sourceReadChannelFinished()) Q_PRIVATE_SLOT(d_func(), void _q_copyReadyRead()) Q_PRIVATE_SLOT(d_func(), void _q_copyReadChannelFinished()) + Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingData()) + Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingDataFinished()) }; class QNetworkReplyImplPrivate: public QNetworkReplyPrivate @@ -102,15 +103,13 @@ class QNetworkReplyImplPrivate: public QNetworkReplyPrivate public: enum InternalNotifications { NotifyDownstreamReadyWrite, - NotifyUpstreamReadyRead, NotifyCloseDownstreamChannel, - NotifyCloseUpstreamChannel, NotifyCopyFinished }; enum State { Idle, - Opening, + Buffering, Working, Finished, Aborted @@ -125,6 +124,8 @@ public: void _q_sourceReadChannelFinished(); void _q_copyReadyRead(); void _q_copyReadChannelFinished(); + void _q_bufferOutgoingData(); + void _q_bufferOutgoingDataFinished(); void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData); @@ -138,9 +139,10 @@ public: void setCachingEnabled(bool enable); bool isCachingEnabled() const; void consume(qint64 count); + void emitUploadProgress(qint64 bytesSent, qint64 bytesTotal); qint64 nextDownstreamBlockSize() const; - void feed(const QByteArray &data); - void feed(QIODevice *data); + void appendDownstreamData(const QByteArray &data); + void appendDownstreamData(QIODevice *data); void finished(); void error(QNetworkReply::NetworkError code, const QString &errorString); void metaDataChanged(); @@ -149,6 +151,7 @@ public: QNetworkAccessBackend *backend; QIODevice *outgoingData; + QRingBuffer *outgoingDataBuffer; QIODevice *copyDevice; QAbstractNetworkCache *networkCache; -- cgit v0.12 From ccf5680b2e9746b5b70c2311e66c9dcde92cc462 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 13 May 2009 13:17:43 +0200 Subject: QNAM: ContentReSendError Reviewed-by: Peter Hartmann Reviewed-by: Thiago Macieira --- src/network/access/qnetworkreply.cpp | 4 ++++ src/network/access/qnetworkreply.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp index f4dad3c..0990b17 100644 --- a/src/network/access/qnetworkreply.cpp +++ b/src/network/access/qnetworkreply.cpp @@ -151,6 +151,10 @@ QNetworkReplyPrivate::QNetworkReplyPrivate() authentication to serve the content but the credentials provided were not accepted (if any) + \value ContentReSendError the request needed to be sent + again, but this failed for example because the upload data + could not be read a second time. + \value ProtocolUnknownError the Network Access API cannot honor the request because the protocol is not known diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h index 6f763b3..2f864fe 100644 --- a/src/network/access/qnetworkreply.h +++ b/src/network/access/qnetworkreply.h @@ -92,6 +92,7 @@ public: ContentOperationNotPermittedError, ContentNotFoundError, AuthenticationRequiredError, + ContentReSendError, UnknownContentError = 299, // protocol errors -- cgit v0.12 From 51ad9b25af4379d80ba1992994beffca548194a7 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 13 May 2009 13:18:57 +0200 Subject: QNAM: Upload architecture change: Auto test Reviewed-by: Thiago Macieira Reviewed-by: Peter Hartmann --- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 532 ++++++++++++++++++++++++- 1 file changed, 516 insertions(+), 16 deletions(-) diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 104b788..a8ba36f 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -91,6 +92,15 @@ class tst_QNetworkReply: public QObject { Q_OBJECT + struct ProxyData { + ProxyData(const QNetworkProxy &p, const QByteArray &t, bool auth) + : tag(t), proxy(p), requiresAuthentication(auth) + { } + QByteArray tag; + QNetworkProxy proxy; + bool requiresAuthentication; + }; + QEventLoop *loop; enum RunSimpleRequestReturn { Timeout = 0, Success, Failure }; int returnCode; @@ -99,6 +109,7 @@ class tst_QNetworkReply: public QObject QString wronlyFileName; #endif QString uniqueExtension; + QList proxies; QNetworkAccessManager manager; MyCookieJar *cookieJar; #ifndef QT_NO_OPENSSL @@ -190,11 +201,20 @@ private Q_SLOTS: void ioPutToHttpFromFile(); void ioPostToHttpFromFile_data(); void ioPostToHttpFromFile(); + void ioPostToHttpFromSocket_data(); + void ioPostToHttpFromSocket(); + void ioPostToHttpFromMiddleOfFileToEnd(); + void ioPostToHttpFromMiddleOfFileFiveBytes(); + void ioPostToHttpFromMiddleOfQBufferFiveBytes(); + void ioPostToHttpNoBufferFlag(); + void ioPostToHttpUploadProgress(); + void ioPostToHttpEmtpyUploadProgress(); void rateControl_data(); void rateControl(); void downloadPerformance(); void uploadPerformance(); + void httpUploadPerformance(); void performanceControlRate(); void downloadProgress_data(); @@ -364,6 +384,63 @@ public slots: } }; +class FixedSizeDataGenerator : public QIODevice +{ + Q_OBJECT + enum { Idle, Started, Stopped } state; +public: + FixedSizeDataGenerator(qint64 size) : state(Idle) + { open(ReadOnly | Unbuffered); + toBeGeneratedTotalCount = toBeGeneratedCount = size; + } + + virtual qint64 bytesAvailable() const + { + return state == Started ? toBeGeneratedCount + QIODevice::bytesAvailable() : 0; + } + + virtual bool isSequential() const{ + return false; + } + + virtual bool reset() const{ + return false; + } + + qint64 size() const { + return toBeGeneratedTotalCount; + } + +public slots: + void start() { state = Started; emit readyRead(); } + +protected: + virtual qint64 readData(char *data, qint64 maxlen) + { + memset(data, '@', maxlen); + + if (toBeGeneratedCount <= 0) { + return -1; + } + + qint64 n = qMin(maxlen, toBeGeneratedCount); + toBeGeneratedCount -= n; + + if (toBeGeneratedCount <= 0) { + // make sure this is a queued connection! + emit readChannelFinished(); + } + + return n; + } + virtual qint64 writeData(const char *, qint64) + { return -1; } + + qint64 toBeGeneratedCount; + qint64 toBeGeneratedTotalCount; +}; + + class DataGenerator: public QIODevice { Q_OBJECT @@ -384,6 +461,7 @@ protected: { if (state == Stopped) return -1; // EOF + // return as many bytes as are wanted memset(data, '@', maxlen); return maxlen; @@ -392,6 +470,8 @@ protected: { return -1; } }; + + class SocketPair: public QObject { Q_OBJECT @@ -629,7 +709,7 @@ protected: return; transferRate = totalBytes * 1000 / timer.elapsed(); - qDebug() << "receive rate:" << (transferRate / 1024) << "kB/s in" + qDebug() << "TimedSender::run" << "receive rate:" << (transferRate / 1024) << "kB/s in" << timer.elapsed() << "ms"; } @@ -643,12 +723,13 @@ protected: class ThreadedDataReader: public QThread { Q_OBJECT + // used to make the constructor only return after the tcp server started listening QSemaphore ready; QTcpSocket *client; int timeout; int port; public: - int transferRate; + qint64 transferRate; ThreadedDataReader() : port(-1), transferRate(-1) { @@ -676,12 +757,65 @@ protected: QTime timer; timer.start(); eventLoop.exec(); + qint64 elapsed = timer.elapsed(); + + transferRate = reader.totalBytes * 1000 / elapsed; + qDebug() << "ThreadedDataReader::run" << "send rate:" << (transferRate / 1024) << "kB/s in" << elapsed << "msec"; + } +}; + +class ThreadedDataReaderHttpServer: public QThread +{ + Q_OBJECT + // used to make the constructor only return after the tcp server started listening + QSemaphore ready; + QTcpSocket *client; + int timeout; + int port; +public: + qint64 transferRate; + ThreadedDataReaderHttpServer() + : port(-1), transferRate(-1) + { + start(); + ready.acquire(); + } + + inline int serverPort() const { return port; } + +protected: + void run() + { + QTcpServer server; + server.listen(); + port = server.serverPort(); + ready.release(); + + server.waitForNewConnection(-1); + client = server.nextPendingConnection(); + client->write("HTTP/1.0 200 OK\r\n"); + client->write("Content-length: 0\r\n"); + client->write("\r\n"); + client->flush(); + + QCoreApplication::processEvents(); + + QEventLoop eventLoop; + DataReader reader(client, false); + QObject::connect(client, SIGNAL(disconnected()), &eventLoop, SLOT(quit())); + + QTime timer; + timer.start(); + eventLoop.exec(); + qint64 elapsed = timer.elapsed(); - transferRate = reader.totalBytes * 1000 / timer.elapsed(); - qDebug() << "send rate:" << (transferRate / 1024) << "kB/s"; + transferRate = reader.totalBytes * 1000 / elapsed; + qDebug() << "ThreadedDataReaderHttpServer::run" << "send rate:" << (transferRate / 1024) << "kB/s in" << elapsed << "msec"; } }; + + tst_QNetworkReply::tst_QNetworkReply() { testFileName = QDir::currentPath() + "/testfile"; @@ -692,8 +826,28 @@ tst_QNetworkReply::tst_QNetworkReply() #endif cookieJar = new MyCookieJar; manager.setCookieJar(cookieJar); + + QHostInfo hostInfo = QHostInfo::fromName(QtNetworkSettings::serverName()); + + proxies << ProxyData(QNetworkProxy::NoProxy, "", false); + + if (hostInfo.error() == QHostInfo::NoError && !hostInfo.addresses().isEmpty()) { + QString proxyserver = hostInfo.addresses().first().toString(); + proxies << ProxyData(QNetworkProxy(QNetworkProxy::HttpProxy, proxyserver, 3128), "+proxy", false) + << ProxyData(QNetworkProxy(QNetworkProxy::HttpProxy, proxyserver, 3129), "+proxyauth", true) + // currently unsupported + // << ProxyData(QNetworkProxy(QNetworkProxy::HttpProxy, proxyserver, 3130), "+proxyauth-ntlm", true); + << ProxyData(QNetworkProxy(QNetworkProxy::Socks5Proxy, proxyserver, 1080), "+socks", false) + << ProxyData(QNetworkProxy(QNetworkProxy::Socks5Proxy, proxyserver, 1081), "+socksauth", true); + } else { + printf("==================================================================\n"); + printf("Proxy could not be looked up. No proxy will be used while testing!\n"); + printf("==================================================================\n"); + } } + + void tst_QNetworkReply::authenticationRequired(QNetworkReply*, QAuthenticator* auth) { auth->setUser("httptest"); @@ -2452,6 +2606,320 @@ void tst_QNetworkReply::ioPostToHttpFromFile() QCOMPARE(reply->readAll().trimmed(), md5sum(sourceFile.readAll()).toHex()); } +void tst_QNetworkReply::ioPostToHttpFromSocket_data() +{ + QTest::addColumn("data"); + QTest::addColumn("md5sum"); + QTest::addColumn("url"); + QTest::addColumn("proxy"); + QTest::addColumn("authenticationRequiredCount"); + QTest::addColumn("proxyAuthenticationRequiredCount"); + + for (int i = 0; i < proxies.count(); ++i) + for (int auth = 0; auth < 2; ++auth) { + QUrl url; + if (auth) + url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi"; + else + url = "http://" + QtNetworkSettings::serverName() + "/qtest/cgi-bin/md5sum.cgi"; + + QNetworkProxy proxy = proxies.at(i).proxy; + QByteArray testsuffix = QByteArray(auth ? "+auth" : "") + proxies.at(i).tag; + int proxyauthcount = proxies.at(i).requiresAuthentication; + + QByteArray data; + data = ""; + QTest::newRow("empty" + testsuffix) << data << md5sum(data) << url << proxy << auth << proxyauthcount; + + data = "This is a normal message."; + QTest::newRow("generic" + testsuffix) << data << md5sum(data) << url << proxy << auth << proxyauthcount; + + data = "This is a message to show that Qt rocks!\r\n\n"; + QTest::newRow("small" + testsuffix) << data << md5sum(data) << url << proxy << auth << proxyauthcount; + + data = QByteArray("abcd\0\1\2\abcd",12); + QTest::newRow("with-nul" + testsuffix) << data << md5sum(data) << url << proxy << auth << proxyauthcount; + + data = QByteArray(4097, '\4'); + QTest::newRow("4k+1" + testsuffix) << data << md5sum(data) << url << proxy << auth << proxyauthcount; + + data = QByteArray(128*1024+1, '\177'); + QTest::newRow("128k+1" + testsuffix) << data << md5sum(data) << url << proxy << auth << proxyauthcount; + } +} + +void tst_QNetworkReply::ioPostToHttpFromSocket() +{ + qRegisterMetaType(); // for QSignalSpy + qRegisterMetaType(); + qRegisterMetaType(); + + QFETCH(QByteArray, data); + QFETCH(QUrl, url); + QFETCH(QNetworkProxy, proxy); + SocketPair socketpair; + socketpair.create(); + QVERIFY(socketpair.endPoints[0] && socketpair.endPoints[1]); + + socketpair.endPoints[0]->write(data); + + QNetworkRequest request(url); + manager.setProxy(proxy); + QNetworkReplyPtr reply = manager.post(QNetworkRequest(url), socketpair.endPoints[1]); + socketpair.endPoints[0]->close(); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + connect(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), + SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); + connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); + + QSignalSpy authenticationRequiredSpy(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*))); + QSignalSpy proxyAuthenticationRequiredSpy(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); + + QTestEventLoop::instance().enterLoop(1); + + disconnect(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), + this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); + disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); + QVERIFY(!QTestEventLoop::instance().timeout()); + + QCOMPARE(reply->url(), url); + QCOMPARE(reply->error(), QNetworkReply::NoError); + // verify that the HTTP status code is 200 Ok + QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); + + QCOMPARE(reply->readAll().trimmed(), md5sum(data).toHex()); + + QTEST(authenticationRequiredSpy.count(), "authenticationRequiredCount"); + QTEST(proxyAuthenticationRequiredSpy.count(), "proxyAuthenticationRequiredCount"); + } + +// this tests checks if rewinding the POST-data to some place in the middle +// worked. +void tst_QNetworkReply::ioPostToHttpFromMiddleOfFileToEnd() +{ + QFile sourceFile(SRCDIR "/rfc3252.txt"); + QVERIFY(sourceFile.open(QIODevice::ReadOnly)); + // seeking to the middle + sourceFile.seek(sourceFile.size() / 2); + + QUrl url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi"; + QNetworkRequest request(url); + QNetworkReplyPtr reply = manager.post(QNetworkRequest(url), &sourceFile); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); + + QTestEventLoop::instance().enterLoop(2); + disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); + QVERIFY(!QTestEventLoop::instance().timeout()); + + // compare half data + sourceFile.seek(sourceFile.size() / 2); + QByteArray data = sourceFile.readAll(); + QCOMPARE(reply->readAll().trimmed(), md5sum(data).toHex()); +} + +void tst_QNetworkReply::ioPostToHttpFromMiddleOfFileFiveBytes() +{ + QFile sourceFile(SRCDIR "/rfc3252.txt"); + QVERIFY(sourceFile.open(QIODevice::ReadOnly)); + // seeking to the middle + sourceFile.seek(sourceFile.size() / 2); + + QUrl url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi"; + QNetworkRequest request(url); + // only send 5 bytes + request.setHeader(QNetworkRequest::ContentLengthHeader, 5); + QVERIFY(request.header(QNetworkRequest::ContentLengthHeader).isValid()); + QNetworkReplyPtr reply = manager.post(request, &sourceFile); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); + + QTestEventLoop::instance().enterLoop(2); + disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); + QVERIFY(!QTestEventLoop::instance().timeout()); + + // compare half data + sourceFile.seek(sourceFile.size() / 2); + QByteArray data = sourceFile.read(5); + QCOMPARE(reply->readAll().trimmed(), md5sum(data).toHex()); +} + +void tst_QNetworkReply::ioPostToHttpFromMiddleOfQBufferFiveBytes() +{ + // test needed since a QBuffer goes with a different codepath than the QFile + // tested in ioPostToHttpFromMiddleOfFileFiveBytes + QBuffer uploadBuffer; + uploadBuffer.open(QIODevice::ReadWrite); + uploadBuffer.write("1234567890"); + uploadBuffer.seek(5); + + QUrl url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi"; + QNetworkRequest request(url); + QNetworkReplyPtr reply = manager.post(request, &uploadBuffer); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); + + QTestEventLoop::instance().enterLoop(2); + disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); + QVERIFY(!QTestEventLoop::instance().timeout()); + + // compare half data + uploadBuffer.seek(5); + QByteArray data = uploadBuffer.read(5); + QCOMPARE(reply->readAll().trimmed(), md5sum(data).toHex()); +} + + +void tst_QNetworkReply::ioPostToHttpNoBufferFlag() +{ + QByteArray data = QByteArray("daaaaaaataaaaaaa"); + // create a sequential QIODevice by feeding the data into a local TCP server + SocketPair socketpair; + socketpair.create(); + QVERIFY(socketpair.endPoints[0] && socketpair.endPoints[1]); + socketpair.endPoints[0]->write(data); + + QUrl url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi"; + QNetworkRequest request(url); + // disallow buffering + request.setAttribute(QNetworkRequest::DoNotBufferUploadDataAttribute, true); + request.setHeader(QNetworkRequest::ContentLengthHeader, data.size()); + QNetworkReplyPtr reply = manager.post(request, socketpair.endPoints[1]); + socketpair.endPoints[0]->close(); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); + + QTestEventLoop::instance().enterLoop(2); + disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); + + // verify: error code is QNetworkReply::ContentReSendError + QCOMPARE(reply->error(), QNetworkReply::ContentReSendError); +} + + +void tst_QNetworkReply::ioPostToHttpUploadProgress() +{ + QFile sourceFile(SRCDIR "/bigfile"); + QVERIFY(sourceFile.open(QIODevice::ReadOnly)); + + // emulate a minimal http server + QTcpServer server; + server.listen(QHostAddress(QHostAddress::LocalHost), 0); + + // create the request + QUrl url = QUrl(QString("http://127.0.0.1:%1/").arg(server.serverPort())); + QNetworkRequest request(url); + QNetworkReplyPtr reply = manager.post(request, &sourceFile); + QSignalSpy spy(reply, SIGNAL(uploadProgress(qint64,qint64))); + connect(&server, SIGNAL(newConnection()), &QTestEventLoop::instance(), SLOT(exitLoop())); + + // get the request started and the incoming socket connected + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + QTcpSocket *incomingSocket = server.nextPendingConnection(); + QVERIFY(incomingSocket); + disconnect(&server, SIGNAL(newConnection()), &QTestEventLoop::instance(), SLOT(exitLoop())); + + incomingSocket->setReadBufferSize(1*1024); + QTestEventLoop::instance().enterLoop(2); + // some progress should have been made + QList args = spy.last(); + QVERIFY(!args.isEmpty()); + QVERIFY(args.at(0).toLongLong() > 0); + + incomingSocket->setReadBufferSize(32*1024); + incomingSocket->read(16*1024); + QTestEventLoop::instance().enterLoop(2); + // some more progress than before + QList args2 = spy.last(); + QVERIFY(!args2.isEmpty()); + QVERIFY(args2.at(0).toLongLong() > args.at(0).toLongLong()); + + // set the read buffer to unlimited + incomingSocket->setReadBufferSize(0); + QTestEventLoop::instance().enterLoop(10); + // progress should be finished + QList args3 = spy.last(); + QVERIFY(!args3.isEmpty()); + QVERIFY(args3.at(0).toLongLong() > args2.at(0).toLongLong()); + QCOMPARE(args3.at(0).toLongLong(), args3.at(1).toLongLong()); + QCOMPARE(args3.at(0).toLongLong(), sourceFile.size()); + + // after sending this, the QNAM should emit finished() + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + incomingSocket->write("HTTP/1.0 200 OK\r\n"); + incomingSocket->write("Content-Length: 0\r\n"); + incomingSocket->write("\r\n"); + QTestEventLoop::instance().enterLoop(10); + // not timeouted -> finished() was emitted + QVERIFY(!QTestEventLoop::instance().timeout()); + + incomingSocket->close(); + server.close(); +} + +void tst_QNetworkReply::ioPostToHttpEmtpyUploadProgress() +{ + QByteArray ba; + ba.resize(0); + QBuffer buffer(&ba,0); + QVERIFY(buffer.open(QIODevice::ReadOnly)); + + // emulate a minimal http server + QTcpServer server; + server.listen(QHostAddress(QHostAddress::LocalHost), 0); + + // create the request + QUrl url = QUrl(QString("http://127.0.0.1:%1/").arg(server.serverPort())); + QNetworkRequest request(url); + QNetworkReplyPtr reply = manager.post(request, &buffer); + QSignalSpy spy(reply, SIGNAL(uploadProgress(qint64,qint64))); + connect(&server, SIGNAL(newConnection()), &QTestEventLoop::instance(), SLOT(exitLoop())); + + + // get the request started and the incoming socket connected + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + QTcpSocket *incomingSocket = server.nextPendingConnection(); + QVERIFY(incomingSocket); + + // after sending this, the QNAM should emit finished() + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + incomingSocket->write("HTTP/1.0 200 OK\r\n"); + incomingSocket->write("Content-Length: 0\r\n"); + incomingSocket->write("\r\n"); + incomingSocket->flush(); + QTestEventLoop::instance().enterLoop(10); + // not timeouted -> finished() was emitted + QVERIFY(!QTestEventLoop::instance().timeout()); + + // final check: only 1 uploadProgress has been emitted + QVERIFY(spy.length() == 1); + QList args = spy.last(); + QVERIFY(!args.isEmpty()); + QCOMPARE(args.at(0).toLongLong(), buffer.size()); + QCOMPARE(args.at(0).toLongLong(), buffer.size()); + + incomingSocket->close(); + server.close(); +} + + void tst_QNetworkReply::rateControl_data() { QTest::addColumn("rate"); @@ -2488,8 +2956,8 @@ void tst_QNetworkReply::rateControl() QTestEventLoop::instance().enterLoop(40); int elapsedTime = loopTime.elapsed(); - qDebug() << "send rate:" << sender.transferRate; - qDebug() << "receive rate:" << reader.totalBytesRead * 1000 / elapsedTime + qDebug() << "tst_QNetworkReply::rateControl" << "send rate:" << sender.transferRate; + qDebug() << "tst_QNetworkReply::rateControl" << "receive rate:" << reader.totalBytesRead * 1000 / elapsedTime << "(it received" << reader.totalBytesRead << "bytes in" << elapsedTime << "ms)"; sender.wait(); @@ -2523,23 +2991,54 @@ void tst_QNetworkReply::downloadPerformance() sender.wait(); qint64 receivedBytes = reader.totalBytes; - qDebug() << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and" + qDebug() << "tst_QNetworkReply::downloadPerformance" << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and" << elapsedTime << "ms"; } void tst_QNetworkReply::uploadPerformance() { - ThreadedDataReader reader; - DataGenerator generator; - QNetworkRequest request("debugpipe://127.0.0.1:" + QString::number(reader.serverPort()) + "/?bare=1"); - QNetworkReplyPtr reply = manager.put(request, &generator); + ThreadedDataReader reader; + DataGenerator generator; - connect(&reader, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTimer::singleShot(5000, &generator, SLOT(stop())); - generator.start(); - QTestEventLoop::instance().enterLoop(40); + + QNetworkRequest request("debugpipe://127.0.0.1:" + QString::number(reader.serverPort()) + "/?bare=1"); + QNetworkReplyPtr reply = manager.put(request, &generator); + generator.start(); + connect(&reader, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTimer::singleShot(5000, &generator, SLOT(stop())); + + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); } +void tst_QNetworkReply::httpUploadPerformance() +{ + enum {UploadSize = 1000*1024*1024}; // 1000 MB + ThreadedDataReaderHttpServer reader; + FixedSizeDataGenerator generator(UploadSize); + + QNetworkRequest request(QUrl("http://127.0.0.1:" + QString::number(reader.serverPort()) + "/?bare=1")); + request.setHeader(QNetworkRequest::ContentLengthHeader,UploadSize); + + QNetworkReplyPtr reply = manager.put(request, &generator); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + + QTime time; + generator.start(); + time.start(); + QTestEventLoop::instance().enterLoop(40); + QVERIFY(!QTestEventLoop::instance().timeout()); + + qint64 elapsed = time.elapsed(); + qWarning() << "tst_QNetworkReply::httpUploadPerformance" << elapsed << "msec, " + << ((UploadSize/1024.0)/(elapsed/1000.0)) << " kB/sec"; + + reader.exit(); + reader.wait(3000); +} + + void tst_QNetworkReply::performanceControlRate() { // this is a control comparison for the other two above @@ -2560,7 +3059,7 @@ void tst_QNetworkReply::performanceControlRate() sender.wait(); qint64 receivedBytes = reader.totalBytes; - qDebug() << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and" + qDebug() << "tst_QNetworkReply::performanceControlRate" << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and" << elapsedTime << "ms"; } @@ -2592,6 +3091,7 @@ void tst_QNetworkReply::downloadProgress() QByteArray data(128, 'a'); QTcpSocket *sender = server.nextPendingConnection(); + QVERIFY(sender); QFETCH(int, loopCount); for (int i = 1; i <= loopCount; ++i) { -- cgit v0.12 From c2c69c117407990e5c2d8900f4aa27979273084a Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 13 May 2009 13:19:24 +0200 Subject: QNAM: Upload architecture change: Changed all QNAM backends Reviewed-by: Peter Hartmann Reviewed-by: Thiago Macieira --- .../access/qnetworkaccessdebugpipebackend.cpp | 283 ++++++++------------- .../access/qnetworkaccessdebugpipebackend_p.h | 23 +- src/network/access/qnetworkaccessfilebackend.cpp | 85 ++++--- src/network/access/qnetworkaccessfilebackend_p.h | 9 +- src/network/access/qnetworkaccessftpbackend.cpp | 64 +---- src/network/access/qnetworkaccessftpbackend_p.h | 5 +- src/network/access/qnetworkaccesshttpbackend.cpp | 89 +------ src/network/access/qnetworkaccesshttpbackend_p.h | 11 +- 8 files changed, 198 insertions(+), 371 deletions(-) diff --git a/src/network/access/qnetworkaccessdebugpipebackend.cpp b/src/network/access/qnetworkaccessdebugpipebackend.cpp index 2e5f1b1..d4bda9a 100644 --- a/src/network/access/qnetworkaccessdebugpipebackend.cpp +++ b/src/network/access/qnetworkaccessdebugpipebackend.cpp @@ -41,6 +41,8 @@ #include "qnetworkaccessdebugpipebackend_p.h" #include "QtCore/qdatastream.h" +#include +#include "private/qnoncontiguousbytedevice_p.h" QT_BEGIN_NAMESPACE @@ -51,12 +53,6 @@ enum { WriteBufferSize = ReadBufferSize }; -struct QNetworkAccessDebugPipeBackend::DataPacket -{ - QList > headers; - QByteArray data; -}; - QNetworkAccessBackend * QNetworkAccessDebugPipeBackendFactory::create(QNetworkAccessManager::Operation op, const QNetworkRequest &request) const @@ -79,12 +75,14 @@ QNetworkAccessDebugPipeBackendFactory::create(QNetworkAccessManager::Operation o } QNetworkAccessDebugPipeBackend::QNetworkAccessDebugPipeBackend() - : incomingPacketSize(0), bareProtocol(false) + : bareProtocol(false), hasUploadFinished(false), hasDownloadFinished(false), + hasEverythingFinished(false), bytesDownloaded(0), bytesUploaded(0) { } QNetworkAccessDebugPipeBackend::~QNetworkAccessDebugPipeBackend() { + // this is signals disconnect, not network! socket.disconnect(this); // we're not interested in the signals at this point } @@ -92,160 +90,150 @@ void QNetworkAccessDebugPipeBackend::open() { socket.connectToHost(url().host(), url().port(12345)); socket.setReadBufferSize(ReadBufferSize); + + // socket ready read -> we can push from socket to downstream connect(&socket, SIGNAL(readyRead()), SLOT(socketReadyRead())); - connect(&socket, SIGNAL(bytesWritten(qint64)), SLOT(socketBytesWritten(qint64))); connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketError())); connect(&socket, SIGNAL(disconnected()), SLOT(socketDisconnected())); + connect(&socket, SIGNAL(connected()), SLOT(socketConnected())); + // socket bytes written -> we can push more from upstream to socket + connect(&socket, SIGNAL(bytesWritten(qint64)), SLOT(socketBytesWritten(qint64))); bareProtocol = url().queryItemValue(QLatin1String("bare")) == QLatin1String("1"); - if (!bareProtocol) { - // "Handshake": - // send outgoing metadata and the URL being requested - DataPacket packet; - //packet.metaData = request().metaData(); - packet.data = url().toEncoded(); - send(packet); + if (operation() == QNetworkAccessManager::PutOperation) { + uploadByteDevice = createUploadByteDevice(); + QObject::connect(uploadByteDevice, SIGNAL(readyRead()), this, SLOT(uploadReadyReadSlot())); + QMetaObject::invokeMethod(this, "uploadReadyReadSlot", Qt::QueuedConnection); } } -void QNetworkAccessDebugPipeBackend::closeDownstreamChannel() +void QNetworkAccessDebugPipeBackend::socketReadyRead() { - if (operation() == QNetworkAccessManager::GetOperation) - socket.disconnectFromHost(); + pushFromSocketToDownstream(); } -void QNetworkAccessDebugPipeBackend::closeUpstreamChannel() +void QNetworkAccessDebugPipeBackend::downstreamReadyWrite() { - if (operation() == QNetworkAccessManager::PutOperation) - socket.disconnectFromHost(); - else if (operation() == QNetworkAccessManager::PostOperation) { - send(DataPacket()); - } + pushFromSocketToDownstream(); } -bool QNetworkAccessDebugPipeBackend::waitForDownstreamReadyRead(int ms) +void QNetworkAccessDebugPipeBackend::socketBytesWritten(qint64) { - readyReadEmitted = false; - if (socket.bytesAvailable()) { - socketReadyRead(); - if (readyReadEmitted) - return true; - } - socket.waitForReadyRead(ms); - return readyReadEmitted; + pushFromUpstreamToSocket(); } -bool QNetworkAccessDebugPipeBackend::waitForUpstreamBytesWritten(int ms) +void QNetworkAccessDebugPipeBackend::uploadReadyReadSlot() { - bytesWrittenEmitted = false; - upstreamReadyRead(); - if (bytesWrittenEmitted) - return true; - - socket.waitForBytesWritten(ms); - return bytesWrittenEmitted; + pushFromUpstreamToSocket(); } -void QNetworkAccessDebugPipeBackend::upstreamReadyRead() +void QNetworkAccessDebugPipeBackend::pushFromSocketToDownstream() { - int maxWrite = WriteBufferSize - socket.bytesToWrite(); - if (maxWrite <= 0) - return; // can't write yet, wait for the socket to write - - if (bareProtocol) { - QByteArray data = readUpstream(); - if (data.isEmpty()) - return; + QByteArray buffer; - socket.write(data); - upstreamBytesConsumed(data.size()); - bytesWrittenEmitted = true; + if (socket.state() == QAbstractSocket::ConnectingState) { return; } - DataPacket packet; - packet.data = readUpstream(); - if (packet.data.isEmpty()) - return; // we'll be called again when there's data - if (packet.data.size() > maxWrite) - packet.data.truncate(maxWrite); - - if (!send(packet)) { - QString msg = QObject::tr("Write error writing to %1: %2") - .arg(url().toString(), socket.errorString()); - error(QNetworkReply::ProtocolFailure, msg); + forever { + if (hasDownloadFinished) + return; - finished(); - return; + buffer.resize(ReadBufferSize); + qint64 haveRead = socket.read(buffer.data(), ReadBufferSize); + + if (haveRead == -1) { + hasDownloadFinished = true; + // this ensures a good last downloadProgress is emitted + setHeader(QNetworkRequest::ContentLengthHeader, QVariant()); + possiblyFinish(); + break; + } else if (haveRead == 0) { + break; + } else { + // have read something + buffer.resize(haveRead); + bytesDownloaded += haveRead; + writeDownstreamData(buffer); + } } - upstreamBytesConsumed(packet.data.size()); - bytesWrittenEmitted = true; } -void QNetworkAccessDebugPipeBackend::downstreamReadyWrite() +void QNetworkAccessDebugPipeBackend::pushFromUpstreamToSocket() { - socketReadyRead(); -} + // FIXME + if (operation() == QNetworkAccessManager::PutOperation) { + if (hasUploadFinished) + return; -void QNetworkAccessDebugPipeBackend::socketReadyRead() -{ - if (bareProtocol) { - qint64 bytesToRead = socket.bytesAvailable(); - if (bytesToRead) { - QByteArray buffer; - buffer.resize(bytesToRead); - qint64 bytesRead = socket.read(buffer.data(), bytesToRead); - if (bytesRead < bytesToRead) - buffer.truncate(bytesRead); - writeDownstreamData(buffer); - readyReadEmitted = true; + forever { + if (socket.bytesToWrite() >= WriteBufferSize) + return; + + qint64 haveRead; + const char *readPointer = uploadByteDevice->readPointer(WriteBufferSize, haveRead); + if (haveRead == -1) { + // EOF + hasUploadFinished = true; + emitReplyUploadProgress(bytesUploaded, bytesUploaded); + possiblyFinish(); + break; + } else if (haveRead == 0 || readPointer == 0) { + // nothing to read right now, we will be called again later + break; + } else { + qint64 haveWritten; + haveWritten = socket.write(readPointer, haveRead); + + if (haveWritten < 0) { + // write error! + QString msg = QCoreApplication::translate("QNetworkAccessDebugPipeBackend", "Write error writing to %1: %2") + .arg(url().toString(), socket.errorString()); + error(QNetworkReply::ProtocolFailure, msg); + finished(); + return; + } else { + uploadByteDevice->advanceReadPointer(haveWritten); + bytesUploaded += haveWritten; + emitReplyUploadProgress(bytesUploaded, -1); + } + + //QCoreApplication::processEvents(); + + } } - return; } +} - while (canReceive() && - (socket.state() == QAbstractSocket::UnconnectedState || nextDownstreamBlockSize())) { - DataPacket packet; - if (receive(packet)) { - if (!packet.headers.isEmpty()) { - QList >::ConstIterator - it = packet.headers.constBegin(), - end = packet.headers.constEnd(); - for ( ; it != end; ++it) - setRawHeader(it->first, it->second); - metaDataChanged(); - } +void QNetworkAccessDebugPipeBackend::possiblyFinish() +{ + if (hasEverythingFinished) + return; + hasEverythingFinished = true; - if (!packet.data.isEmpty()) { - writeDownstreamData(packet.data); - readyReadEmitted = true; - } + if ((operation() == QNetworkAccessManager::GetOperation) && hasDownloadFinished) { + socket.close(); + finished(); + } else if ((operation() == QNetworkAccessManager::PutOperation) && hasUploadFinished) { + socket.close(); + finished(); + } - if (packet.headers.isEmpty() && packet.data.isEmpty()) { - // it's an eof - socket.close(); - readyReadEmitted = true; - } - } else { - // got an error - QString msg = QObject::tr("Read error reading from %1: %2") - .arg(url().toString(), socket.errorString()); - error(QNetworkReply::ProtocolFailure, msg); - finished(); - return; - } - } } -void QNetworkAccessDebugPipeBackend::socketBytesWritten(qint64) +void QNetworkAccessDebugPipeBackend::closeDownstreamChannel() { - upstreamReadyRead(); + qWarning() << "QNetworkAccessDebugPipeBackend::closeDownstreamChannel()" << operation(); + //if (operation() == QNetworkAccessManager::GetOperation) + // socket.disconnectFromHost(); } + void QNetworkAccessDebugPipeBackend::socketError() { + qWarning() << "QNetworkAccessDebugPipeBackend::socketError()" << socket.error(); QNetworkReply::NetworkError code; switch (socket.error()) { case QAbstractSocket::RemoteHostClosedError: @@ -269,76 +257,27 @@ void QNetworkAccessDebugPipeBackend::socketError() void QNetworkAccessDebugPipeBackend::socketDisconnected() { - socketReadyRead(); - if (incomingPacketSize == 0 && socket.bytesToWrite() == 0) { + pushFromSocketToDownstream(); + + if (socket.bytesToWrite() == 0) { // normal close - finished(); } else { // abnormal close QString msg = QObject::tr("Remote host closed the connection prematurely on %1") .arg(url().toString()); error(QNetworkReply::RemoteHostClosedError, msg); - finished(); } } -bool QNetworkAccessDebugPipeBackend::send(const DataPacket &packet) -{ - QByteArray ba; - { - QDataStream stream(&ba, QIODevice::WriteOnly); - stream.setVersion(QDataStream::Qt_4_4); - - stream << packet.headers << packet.data; - } - - qint32 outgoingPacketSize = ba.size(); - qint64 written = socket.write((const char*)&outgoingPacketSize, sizeof outgoingPacketSize); - written += socket.write(ba); - return quint64(written) == (outgoingPacketSize + sizeof outgoingPacketSize); -} - -bool QNetworkAccessDebugPipeBackend::receive(DataPacket &packet) +void QNetworkAccessDebugPipeBackend::socketConnected() { - if (!canReceive()) - return false; - - // canReceive() does the setting up for us - Q_ASSERT(socket.bytesAvailable() >= incomingPacketSize); - QByteArray incomingPacket = socket.read(incomingPacketSize); - QDataStream stream(&incomingPacket, QIODevice::ReadOnly); - stream.setVersion(QDataStream::Qt_4_4); - stream >> packet.headers >> packet.data; - - // reset for next packet: - incomingPacketSize = 0; - socket.setReadBufferSize(ReadBufferSize); - return true; } -bool QNetworkAccessDebugPipeBackend::canReceive() +bool QNetworkAccessDebugPipeBackend::waitForDownstreamReadyRead(int ms) { - if (incomingPacketSize == 0) { - // read the packet size - if (quint64(socket.bytesAvailable()) >= sizeof incomingPacketSize) - socket.read((char*)&incomingPacketSize, sizeof incomingPacketSize); - else - return false; - } - - if (incomingPacketSize == 0) { - QString msg = QObject::tr("Protocol error: packet of size 0 received"); - error(QNetworkReply::ProtocolFailure, msg); - finished(); - - socket.blockSignals(true); - socket.abort(); - socket.blockSignals(false); - return false; - } - - return socket.bytesAvailable() >= incomingPacketSize; + qCritical("QNetworkAccess: Debug pipe backend does not support waitForReadyRead()"); + return false; } #endif diff --git a/src/network/access/qnetworkaccessdebugpipebackend_p.h b/src/network/access/qnetworkaccessdebugpipebackend_p.h index 73a35cf..a13edc4 100644 --- a/src/network/access/qnetworkaccessdebugpipebackend_p.h +++ b/src/network/access/qnetworkaccessdebugpipebackend_p.h @@ -66,35 +66,38 @@ class QNetworkAccessDebugPipeBackend: public QNetworkAccessBackend { Q_OBJECT public: - struct DataPacket; QNetworkAccessDebugPipeBackend(); virtual ~QNetworkAccessDebugPipeBackend(); virtual void open(); virtual void closeDownstreamChannel(); - virtual void closeUpstreamChannel(); virtual bool waitForDownstreamReadyRead(int msecs); - virtual bool waitForUpstreamBytesWritten(int msecs); - virtual void upstreamReadyRead(); virtual void downstreamReadyWrite(); +protected: + void pushFromSocketToDownstream(); + void pushFromUpstreamToSocket(); + void possiblyFinish(); + QNonContiguousByteDevice *uploadByteDevice; + private slots: + void uploadReadyReadSlot(); void socketReadyRead(); void socketBytesWritten(qint64 bytes); void socketError(); void socketDisconnected(); + void socketConnected(); private: QTcpSocket socket; - qint32 incomingPacketSize; - bool readyReadEmitted; - bool bytesWrittenEmitted; bool bareProtocol; + bool hasUploadFinished; + bool hasDownloadFinished; + bool hasEverythingFinished; - bool send(const DataPacket &packet); - bool canReceive(); - bool receive(DataPacket &packet); + qint64 bytesDownloaded; + qint64 bytesUploaded; }; class QNetworkAccessDebugPipeBackendFactory: public QNetworkAccessBackendFactory diff --git a/src/network/access/qnetworkaccessfilebackend.cpp b/src/network/access/qnetworkaccessfilebackend.cpp index 8a5a665..6374fde 100644 --- a/src/network/access/qnetworkaccessfilebackend.cpp +++ b/src/network/access/qnetworkaccessfilebackend.cpp @@ -43,6 +43,7 @@ #include "qfileinfo.h" #include "qurlinfo.h" #include "qdir.h" +#include "private/qnoncontiguousbytedevice_p.h" #include @@ -77,7 +78,7 @@ QNetworkAccessFileBackendFactory::create(QNetworkAccessManager::Operation op, } QNetworkAccessFileBackend::QNetworkAccessFileBackend() - : totalBytes(0) + : uploadByteDevice(0), totalBytes(0), hasUploadFinished(false) { } @@ -126,6 +127,9 @@ void QNetworkAccessFileBackend::open() break; case QNetworkAccessManager::PutOperation: mode = QIODevice::WriteOnly | QIODevice::Truncate; + uploadByteDevice = createUploadByteDevice(); + QObject::connect(uploadByteDevice, SIGNAL(readyRead()), this, SLOT(uploadReadyReadSlot())); + QMetaObject::invokeMethod(this, "uploadReadyReadSlot", Qt::QueuedConnection); break; default: Q_ASSERT_X(false, "QNetworkAccessFileBackend::open", @@ -152,19 +156,50 @@ void QNetworkAccessFileBackend::open() } } -void QNetworkAccessFileBackend::closeDownstreamChannel() +void QNetworkAccessFileBackend::uploadReadyReadSlot() { - if (operation() == QNetworkAccessManager::GetOperation) { - file.close(); - //downstreamChannelClosed(); + if (hasUploadFinished) + return; + + forever { + qint64 haveRead; + const char *readPointer = uploadByteDevice->readPointer(-1, haveRead); + if (haveRead == -1) { + // EOF + hasUploadFinished = true; + file.flush(); + file.close(); + finished(); + break; + } else if (haveRead == 0 || readPointer == 0) { + // nothing to read right now, we will be called again later + break; + } else { + qint64 haveWritten; + haveWritten = file.write(readPointer, haveRead); + + if (haveWritten < 0) { + // write error! + QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Write error writing to %1: %2") + .arg(url().toString(), file.errorString()); + error(QNetworkReply::ProtocolFailure, msg); + + finished(); + return; + } else { + uploadByteDevice->advanceReadPointer(haveWritten); + } + + + file.flush(); + } } } -void QNetworkAccessFileBackend::closeUpstreamChannel() +void QNetworkAccessFileBackend::closeDownstreamChannel() { - if (operation() == QNetworkAccessManager::PutOperation) { + if (operation() == QNetworkAccessManager::GetOperation) { file.close(); - finished(); } } @@ -174,40 +209,6 @@ bool QNetworkAccessFileBackend::waitForDownstreamReadyRead(int) return readMoreFromFile(); } -bool QNetworkAccessFileBackend::waitForUpstreamBytesWritten(int) -{ - Q_ASSERT_X(false, "QNetworkAccessFileBackend::waitForUpstreamBytesWritten", - "This function should never have been called, since there is never anything " - "left to be written!"); - return false; -} - -void QNetworkAccessFileBackend::upstreamReadyRead() -{ - Q_ASSERT_X(operation() == QNetworkAccessManager::PutOperation, "QNetworkAccessFileBackend", - "We're being told to upload data but operation isn't PUT!"); - - // there's more data to be written to the file - while (upstreamBytesAvailable()) { - // write everything and let QFile handle it - int written = file.write(readUpstream()); - - if (written < 0) { - // write error! - QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Write error writing to %1: %2") - .arg(url().toString(), file.errorString()); - error(QNetworkReply::ProtocolFailure, msg); - - finished(); - return; - } - - // successful write - file.flush(); - upstreamBytesConsumed(written); - } -} - void QNetworkAccessFileBackend::downstreamReadyWrite() { Q_ASSERT_X(operation() == QNetworkAccessManager::GetOperation, "QNetworkAccessFileBackend", diff --git a/src/network/access/qnetworkaccessfilebackend_p.h b/src/network/access/qnetworkaccessfilebackend_p.h index ce7d351..4615c5f 100644 --- a/src/network/access/qnetworkaccessfilebackend_p.h +++ b/src/network/access/qnetworkaccessfilebackend_p.h @@ -62,22 +62,25 @@ QT_BEGIN_NAMESPACE class QNetworkAccessFileBackend: public QNetworkAccessBackend { + Q_OBJECT public: QNetworkAccessFileBackend(); virtual ~QNetworkAccessFileBackend(); virtual void open(); virtual void closeDownstreamChannel(); - virtual void closeUpstreamChannel(); virtual bool waitForDownstreamReadyRead(int msecs); - virtual bool waitForUpstreamBytesWritten(int msecs); - virtual void upstreamReadyRead(); virtual void downstreamReadyWrite(); +public slots: + void uploadReadyReadSlot(); +protected: + QNonContiguousByteDevice *uploadByteDevice; private: QFile file; qint64 totalBytes; + bool hasUploadFinished; bool loadFileInfo(); bool readMoreFromFile(); diff --git a/src/network/access/qnetworkaccessftpbackend.cpp b/src/network/access/qnetworkaccessftpbackend.cpp index ea39dec..ad55b85 100644 --- a/src/network/access/qnetworkaccessftpbackend.cpp +++ b/src/network/access/qnetworkaccessftpbackend.cpp @@ -42,6 +42,7 @@ #include "qnetworkaccessftpbackend_p.h" #include "qnetworkaccessmanager_p.h" #include "QtNetwork/qauthenticator.h" +#include "private/qnoncontiguousbytedevice_p.h" #ifndef QT_NO_FTP @@ -81,41 +82,6 @@ QNetworkAccessFtpBackendFactory::create(QNetworkAccessManager::Operation op, return 0; } -class QNetworkAccessFtpIODevice: public QIODevice -{ - //Q_OBJECT -public: - QNetworkAccessFtpBackend *backend; - bool eof; - - inline QNetworkAccessFtpIODevice(QNetworkAccessFtpBackend *parent) - : QIODevice(parent), backend(parent), eof(false) - { open(ReadOnly); } - - bool isSequential() const { return true; } - bool atEnd() const { return backend->upstreamBytesAvailable() == 0; } - - qint64 bytesAvailable() const { return backend->upstreamBytesAvailable(); } - qint64 bytesToWrite() const { return backend->downstreamBytesToConsume(); } -protected: - qint64 readData(char *data, qint64 maxlen) - { - const QByteArray toSend = backend->readUpstream(); - maxlen = qMin(maxlen, toSend.size()); - if (!maxlen) - return eof ? -1 : 0; - - backend->upstreamBytesConsumed(maxlen); - memcpy(data, toSend.constData(), maxlen); - return maxlen; - } - - qint64 writeData(const char *, qint64) - { return -1; } - - friend class QNetworkAccessFtpBackend; -}; - class QNetworkAccessFtpFtp: public QFtp, public QNetworkAccessCache::CacheableObject { // Q_OBJECT @@ -198,7 +164,11 @@ void QNetworkAccessFtpBackend::open() ftpConnectionReady(ftp); } - uploadDevice = new QNetworkAccessFtpIODevice(this); + // Put operation + if (operation() == QNetworkAccessManager::PutOperation) { + uploadDevice = QNonContiguousByteDeviceFactory::wrap(createUploadByteDevice()); + uploadDevice->setParent(this); + } } void QNetworkAccessFtpBackend::closeDownstreamChannel() @@ -212,16 +182,6 @@ void QNetworkAccessFtpBackend::closeDownstreamChannel() #endif } -void QNetworkAccessFtpBackend::closeUpstreamChannel() -{ - if (operation() == QNetworkAccessManager::PutOperation) { - Q_ASSERT(uploadDevice); - uploadDevice->eof = true; - if (!upstreamBytesAvailable()) - emit uploadDevice->readyRead(); - } -} - bool QNetworkAccessFtpBackend::waitForDownstreamReadyRead(int ms) { if (!ftp) @@ -239,18 +199,6 @@ bool QNetworkAccessFtpBackend::waitForDownstreamReadyRead(int ms) return false; } -bool QNetworkAccessFtpBackend::waitForUpstreamBytesWritten(int ms) -{ - Q_UNUSED(ms); - qCritical("QNetworkAccess: FTP backend does not support waitForBytesWritten()"); - return false; -} - -void QNetworkAccessFtpBackend::upstreamReadyRead() -{ - // uh... how does QFtp operate? -} - void QNetworkAccessFtpBackend::downstreamReadyWrite() { if (state == Transferring && ftp && ftp->bytesAvailable()) diff --git a/src/network/access/qnetworkaccessftpbackend_p.h b/src/network/access/qnetworkaccessftpbackend_p.h index 9ec2dd8..1bb7ff2 100644 --- a/src/network/access/qnetworkaccessftpbackend_p.h +++ b/src/network/access/qnetworkaccessftpbackend_p.h @@ -87,11 +87,8 @@ public: virtual void open(); virtual void closeDownstreamChannel(); - virtual void closeUpstreamChannel(); virtual bool waitForDownstreamReadyRead(int msecs); - virtual bool waitForUpstreamBytesWritten(int msecs); - virtual void upstreamReadyRead(); virtual void downstreamReadyWrite(); void disconnectFromFtp(); @@ -105,7 +102,7 @@ public slots: private: friend class QNetworkAccessFtpIODevice; QPointer ftp; - QNetworkAccessFtpIODevice *uploadDevice; + QIODevice *uploadDevice; qint64 totalBytes; int helpId, sizeId, mdtmId; bool supportsSize, supportsMdtm; diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index a52b5a0..7d0438e 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -286,37 +286,6 @@ public: } }; -class QNetworkAccessHttpBackendIODevice: public QIODevice -{ - // Q_OBJECT -public: - bool eof; - QNetworkAccessHttpBackendIODevice(QNetworkAccessHttpBackend *parent) - : QIODevice(parent), eof(false) - { - setOpenMode(ReadOnly); - } - bool isSequential() const { return true; } - qint64 bytesAvailable() const - { return static_cast(parent())->upstreamBytesAvailable(); } - -protected: - virtual qint64 readData(char *buffer, qint64 maxlen) - { - qint64 ret = static_cast(parent())->deviceReadData(buffer, maxlen); - if (!ret && eof) - return -1; - return ret; - } - - virtual qint64 writeData(const char *, qint64) - { - return -1; // cannot write - } - - friend class QNetworkAccessHttpBackend; -}; - QNetworkAccessHttpBackend::QNetworkAccessHttpBackend() : QNetworkAccessBackend(), httpReply(0), http(0), uploadDevice(0) #ifndef QT_NO_OPENSSL @@ -507,20 +476,19 @@ void QNetworkAccessHttpBackend::postRequest() case QNetworkAccessManager::PostOperation: invalidateCache(); httpRequest.setOperation(QHttpNetworkRequest::Post); - uploadDevice = new QNetworkAccessHttpBackendIODevice(this); + httpRequest.setUploadByteDevice(createUploadByteDevice()); break; case QNetworkAccessManager::PutOperation: invalidateCache(); httpRequest.setOperation(QHttpNetworkRequest::Put); - uploadDevice = new QNetworkAccessHttpBackendIODevice(this); + httpRequest.setUploadByteDevice(createUploadByteDevice()); break; default: break; // can't happen } - httpRequest.setData(uploadDevice); httpRequest.setUrl(url()); QList headers = request().rawHeaderList(); @@ -528,7 +496,9 @@ void QNetworkAccessHttpBackend::postRequest() httpRequest.setHeaderField(header, request().rawHeader(header)); if (loadedFromCache) { - QNetworkAccessBackend::finished(); + // commented this out since it will be called later anyway + // by copyFinished() + //QNetworkAccessBackend::finished(); return; // no need to send the request! :) } @@ -624,14 +594,6 @@ void QNetworkAccessHttpBackend::closeDownstreamChannel() // this indicates that the user closed the stream while the reply isn't finished yet } -void QNetworkAccessHttpBackend::closeUpstreamChannel() -{ - // this indicates that the user finished uploading the data for POST - Q_ASSERT(uploadDevice); - uploadDevice->eof = true; - emit uploadDevice->readChannelFinished(); -} - bool QNetworkAccessHttpBackend::waitForDownstreamReadyRead(int msecs) { Q_ASSERT(http); @@ -651,38 +613,6 @@ bool QNetworkAccessHttpBackend::waitForDownstreamReadyRead(int msecs) return false; } -bool QNetworkAccessHttpBackend::waitForUpstreamBytesWritten(int msecs) -{ - - // ### FIXME: not implemented in QHttpNetworkAccess - Q_UNUSED(msecs); - qCritical("QNetworkAccess: HTTP backend does not support waitForBytesWritten()"); - return false; -} - -void QNetworkAccessHttpBackend::upstreamReadyRead() -{ - // There is more data available from the user to be uploaded - // QHttpNetworkAccess implements the upload rate control: - // we simply tell QHttpNetworkAccess that there is more data available - // it'll pull from us when it can (through uploadDevice) - - Q_ASSERT(uploadDevice); - emit uploadDevice->readyRead(); -} - -qint64 QNetworkAccessHttpBackend::deviceReadData(char *buffer, qint64 maxlen) -{ - QByteArray toBeUploaded = readUpstream(); - if (toBeUploaded.isEmpty()) - return 0; // nothing to be uploaded - - maxlen = qMin(maxlen, toBeUploaded.length()); - - memcpy(buffer, toBeUploaded.constData(), maxlen); - upstreamBytesConsumed(maxlen); - return maxlen; -} void QNetworkAccessHttpBackend::downstreamReadyWrite() { @@ -904,7 +834,14 @@ bool QNetworkAccessHttpBackend::sendCacheContents(const QNetworkCacheMetaData &m checkForRedirect(status); - writeDownstreamData(contents); + emit metaDataChanged(); + + // invoke this asynchronously, else Arora/QtDemoBrowser don't like cached downloads + // see task 250221 / 251801 + qRegisterMetaType("QIODevice*"); + QMetaObject::invokeMethod(this, "writeDownstreamData", Qt::QueuedConnection, Q_ARG(QIODevice*, contents)); + + #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) qDebug() << "Successfully sent cache:" << url() << contents->size() << "bytes"; #endif diff --git a/src/network/access/qnetworkaccesshttpbackend_p.h b/src/network/access/qnetworkaccesshttpbackend_p.h index 02915e7..225f944 100644 --- a/src/network/access/qnetworkaccesshttpbackend_p.h +++ b/src/network/access/qnetworkaccesshttpbackend_p.h @@ -79,11 +79,8 @@ public: virtual void open(); virtual void closeDownstreamChannel(); - virtual void closeUpstreamChannel(); virtual bool waitForDownstreamReadyRead(int msecs); - virtual bool waitForUpstreamBytesWritten(int msecs); - virtual void upstreamReadyRead(); virtual void downstreamReadyWrite(); virtual void copyFinished(QIODevice *); #ifndef QT_NO_OPENSSL @@ -96,6 +93,9 @@ public: qint64 deviceReadData(char *buffer, qint64 maxlen); + // we return true since HTTP needs to send PUT/POST data again after having authenticated + bool needsResetableUploadData() {return true;}; + private slots: void replyReadyRead(); void replyFinished(); @@ -108,7 +108,8 @@ private: QHttpNetworkReply *httpReply; QPointer http; QByteArray cacheKey; - QNetworkAccessHttpBackendIODevice *uploadDevice; + QNetworkAccessBackendUploadIODevice *uploadDevice; + #ifndef QT_NO_OPENSSL QSslConfiguration *pendingSslConfiguration; bool pendingIgnoreSslErrors; @@ -122,8 +123,6 @@ private: void postRequest(); void readFromHttp(); void checkForRedirect(const int statusCode); - - friend class QNetworkAccessHttpBackendIODevice; }; class QNetworkAccessHttpBackendFactory : public QNetworkAccessBackendFactory -- cgit v0.12 From ad7b21dd57d20cd55774d7a62db117905637e950 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Wed, 13 May 2009 13:44:03 +0200 Subject: qdoc: Fixed some qdoc errors. --- src/corelib/tools/qhash.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 6c4a3ba..2313e0e 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -379,9 +379,10 @@ void QHashData::checkSanity() #endif /*! - \ + \fn uint qHash(const QPair &key) \since 4.3 - + \relates QHash + Returns the hash value for the \a key. Types \c T1 and \c T2 must be supported by qHash(). -- cgit v0.12 From 4910404284b1bb4fdde89d4fd8a420767ee52069 Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Wed, 13 May 2009 13:48:13 +0200 Subject: Clearifying docs QSet::insert Chaning the sentence to clearify where the iterator points to. Task-number: 202656 Rev-by: Geir Vattekar --- doc/src/qset.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/qset.qdoc b/doc/src/qset.qdoc index 7fbf97a..afbedc3 100644 --- a/doc/src/qset.qdoc +++ b/doc/src/qset.qdoc @@ -437,7 +437,7 @@ \fn QSet::const_iterator QSet::insert(const T &value) Inserts item \a value into the set, if \a value isn't already - in the set, and returns an iterator positioned at the inserted + in the set, and returns an iterator pointing at the inserted item. \sa operator<<(), remove(), contains() -- cgit v0.12 From 87022c9a4ab00a9faaf6bcdaa8d5884962ccf305 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 13 May 2009 12:25:36 +0200 Subject: Fix handling of garbage data sent by the HTTP server instead of a proper HTTP reply. If the server's reply doesn't start with "HTTP/", then the reply is not valid. This could happen if we connected via HTTP to an HTTPS server. It could also happen with an Icecast server (reply ICY/x.y). Task-number: 248838 Reviewed-by: Markus Goetz --- src/network/access/qhttpnetworkconnection.cpp | 14 +++++++-- src/network/access/qhttpnetworkreply.cpp | 11 ++++++- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 42 ++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 5940fba..f558f2b 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -529,10 +529,20 @@ void QHttpNetworkConnectionPrivate::receiveReply(QAbstractSocket *socket, QHttpN QHttpNetworkReplyPrivate::ReplyState state = reply ? reply->d_func()->state : QHttpNetworkReplyPrivate::AllDoneState; switch (state) { case QHttpNetworkReplyPrivate::NothingDoneState: - case QHttpNetworkReplyPrivate::ReadingStatusState: - bytes += reply->d_func()->readStatus(socket); + 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) { diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index fe3f6af..1b41e1e 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -409,6 +409,9 @@ qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket) if (fragment.endsWith('\r')) { fragment.truncate(fragment.length()-1); } + if (!fragment.startsWith("HTTP/")) + return -1; + parseStatus(fragment); state = ReadingHeaderState; fragment.clear(); // next fragment @@ -418,7 +421,13 @@ qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket) bytes += socket->read(&c, 1); fragment.append(c); } + + // is this a valid reply? + if (fragment.length() >= 5 && !fragment.startsWith("HTTP/")) + return -1; + } + return bytes; } @@ -660,4 +669,4 @@ void QHttpNetworkReply::ignoreSslErrors() QT_END_NAMESPACE -#endif // QT_NO_HTTP \ No newline at end of file +#endif // QT_NO_HTTP diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 104b788..c97fcf3 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -172,6 +172,8 @@ private Q_SLOTS: void ioGetFromHttpsWithIgnoreSslErrors(); void ioGetFromHttpsWithSslHandshakeError(); #endif + void ioGetFromHttpBrokenServer_data(); + void ioGetFromHttpBrokenServer(); void ioGetWithManyProxies_data(); void ioGetWithManyProxies(); @@ -1887,6 +1889,46 @@ void tst_QNetworkReply::ioGetFromHttpsWithSslHandshakeError() } #endif +void tst_QNetworkReply::ioGetFromHttpBrokenServer_data() +{ + QTest::addColumn("dataToSend"); + QTest::addColumn("doDisconnect"); + + QTest::newRow("no-newline") << QByteArray("Hello World") << false; + QTest::newRow("just-newline") << QByteArray("\r\n") << false; + QTest::newRow("just-2newline") << QByteArray("\r\n\r\n") << false; + QTest::newRow("with-newlines") << QByteArray("Long first line\r\nLong second line") << false; + QTest::newRow("with-newlines2") << QByteArray("\r\nSecond line") << false; + QTest::newRow("with-newlines3") << QByteArray("ICY\r\nSecond line") << false; + + QTest::newRow("empty+disconnect") << QByteArray() << true; + + QTest::newRow("no-newline+disconnect") << QByteArray("Hello World") << true; + QTest::newRow("just-newline+disconnect") << QByteArray("\r\n") << true; + QTest::newRow("just-2newline+disconnect") << QByteArray("\r\n\r\n") << true; + QTest::newRow("with-newlines+disconnect") << QByteArray("Long first line\r\nLong second line") << true; + QTest::newRow("with-newlines2+disconnect") << QByteArray("\r\nSecond line") << true; + QTest::newRow("with-newlines3+disconnect") << QByteArray("ICY\r\nSecond line") << true; +} + +void tst_QNetworkReply::ioGetFromHttpBrokenServer() +{ + QFETCH(QByteArray, dataToSend); + QFETCH(bool, doDisconnect); + MiniHttpServer server(dataToSend); + server.doClose = doDisconnect; + + QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort()))); + QNetworkReplyPtr reply = manager.get(request); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + + QCOMPARE(reply->url(), request.url()); + QVERIFY(reply->error() != QNetworkReply::NoError); +} + void tst_QNetworkReply::ioGetWithManyProxies_data() { QTest::addColumn >("proxyList"); -- cgit v0.12 From a18ebd2a70e83863bc9a8cc64a65791a6d879f02 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 13 May 2009 13:27:01 +0200 Subject: Improve the HTTP status line parsing and catch more errors. There's no need for using QByteArrayMatcher for one single character, so avoid the overhead. Also validate the message header a bit more: we require the status line to start with "HTTP/n.m " where n and m are positive integers less than 10. Task-number: 248838 Reviewed-by: Markus Goetz --- src/network/access/qhttpnetworkreply.cpp | 58 ++++++++++++++++---------- src/network/access/qhttpnetworkreply_p.h | 2 +- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 7 ++++ 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index 1b41e1e..69e0a4c 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -409,12 +409,12 @@ qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket) if (fragment.endsWith('\r')) { fragment.truncate(fragment.length()-1); } - if (!fragment.startsWith("HTTP/")) - return -1; - - parseStatus(fragment); + bool ok = parseStatus(fragment); state = ReadingHeaderState; fragment.clear(); // next fragment + + if (!ok) + return -1; break; } else { c = 0; @@ -431,26 +431,40 @@ qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket) return bytes; } -void QHttpNetworkReplyPrivate::parseStatus(const QByteArray &status) +bool QHttpNetworkReplyPrivate::parseStatus(const QByteArray &status) { - const QByteArrayMatcher sp(" "); - int i = sp.indexIn(status); - const QByteArray version = status.mid(0, i); - int j = sp.indexIn(status, i + 1); + // from RFC 2616: + // Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF + // HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT + // that makes: 'HTTP/n.n xxx Message' + // byte count: 0123456789012 + + static const int minLength = 11; + static const int dotPos = 6; + static const int spacePos = 8; + static const char httpMagic[] = "HTTP/"; + + if (status.length() < minLength + || !status.startsWith(httpMagic) + || status.at(dotPos) != '.' + || status.at(spacePos) != ' ') { + // I don't know how to parse this status line + return false; + } + + // optimize for the valid case: defer checking until the end + majorVersion = status.at(dotPos - 1) - '0'; + minorVersion = status.at(dotPos + 1) - '0'; + + int i = spacePos; + int j = status.indexOf(' ', i + 1); // j == -1 || at(j) == ' ' so j+1 == 0 && j+1 <= length() const QByteArray code = status.mid(i + 1, j - i - 1); - const QByteArray reason = status.mid(j + 1, status.count() - j); - - const QByteArrayMatcher slash("/"); - int k = slash.indexIn(version); - const QByteArrayMatcher dot("."); - int l = dot.indexIn(version, k); - const QByteArray major = version.mid(k + 1, l - k - 1); - const QByteArray minor = version.mid(l + 1, version.count() - l); - - majorVersion = QString::fromAscii(major.constData()).toInt(); - minorVersion = QString::fromAscii(minor.constData()).toInt(); - statusCode = QString::fromAscii(code.constData()).toInt(); - reasonPhrase = QString::fromAscii(reason.constData()); + + bool ok; + statusCode = code.toInt(&ok); + reasonPhrase = QString::fromLatin1(status.constData() + j + 1); + + return ok && uint(majorVersion) <= 9 && uint(minorVersion) <= 9; } qint64 QHttpNetworkReplyPrivate::readHeader(QAbstractSocket *socket) diff --git a/src/network/access/qhttpnetworkreply_p.h b/src/network/access/qhttpnetworkreply_p.h index c17c65c..cb4d34f 100644 --- a/src/network/access/qhttpnetworkreply_p.h +++ b/src/network/access/qhttpnetworkreply_p.h @@ -154,7 +154,7 @@ public: QHttpNetworkReplyPrivate(const QUrl &newUrl = QUrl()); ~QHttpNetworkReplyPrivate(); qint64 readStatus(QAbstractSocket *socket); - void parseStatus(const QByteArray &status); + bool parseStatus(const QByteArray &status); qint64 readHeader(QAbstractSocket *socket); void parseHeader(const QByteArray &header); qint64 readBody(QAbstractSocket *socket, QIODevice *out); diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index c97fcf3..4be0863 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -1900,6 +1900,9 @@ void tst_QNetworkReply::ioGetFromHttpBrokenServer_data() QTest::newRow("with-newlines") << QByteArray("Long first line\r\nLong second line") << false; QTest::newRow("with-newlines2") << QByteArray("\r\nSecond line") << false; QTest::newRow("with-newlines3") << QByteArray("ICY\r\nSecond line") << false; + QTest::newRow("invalid-version") << QByteArray("HTTP/123 200 \r\n") << false; + QTest::newRow("invalid-version2") << QByteArray("HTTP/a.\033 200 \r\n") << false; + QTest::newRow("invalid-reply-code") << QByteArray("HTTP/1.0 fuu \r\n") << false; QTest::newRow("empty+disconnect") << QByteArray() << true; @@ -1909,6 +1912,10 @@ void tst_QNetworkReply::ioGetFromHttpBrokenServer_data() QTest::newRow("with-newlines+disconnect") << QByteArray("Long first line\r\nLong second line") << true; QTest::newRow("with-newlines2+disconnect") << QByteArray("\r\nSecond line") << true; QTest::newRow("with-newlines3+disconnect") << QByteArray("ICY\r\nSecond line") << true; + + QTest::newRow("invalid-version+disconnect") << QByteArray("HTTP/123 200 ") << true; + QTest::newRow("invalid-version2+disconnect") << QByteArray("HTTP/a.\033 200 ") << true; + QTest::newRow("invalid-reply-code+disconnect") << QByteArray("HTTP/1.0 fuu ") << true; } void tst_QNetworkReply::ioGetFromHttpBrokenServer() -- cgit v0.12 From 56191830cdad9cbaa81c2ed8f22f1b2650a5608a Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Wed, 13 May 2009 13:58:18 +0200 Subject: Turn off Link Time Code Generation (/LTCG) by default Turning on LTCG affected too many projects, where customers applications would take a long time linking, severly affecting their development time (even though it was only added for release builds) We turn it off by default, and add a -ltcg configuration option, and the possibility to also do CONFIG+=ltcg in projects, should they not want it for Qt, but in their own projects. (Same, they can build Qt with it, and do CONFIG-=ltcg for their project) Reviewed-by: andy --- configure.exe | Bin 860160 -> 856064 bytes mkspecs/features/win32/ltcg.prf | 5 +++++ mkspecs/win32-msvc2005/qmake.conf | 7 +++++-- mkspecs/win32-msvc2008/qmake.conf | 7 +++++-- tools/configure/configureapp.cpp | 13 +++++++++++++ 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 mkspecs/features/win32/ltcg.prf diff --git a/configure.exe b/configure.exe index ff71f08..40843b4 100644 Binary files a/configure.exe and b/configure.exe differ diff --git a/mkspecs/features/win32/ltcg.prf b/mkspecs/features/win32/ltcg.prf new file mode 100644 index 0000000..f6f1299 --- /dev/null +++ b/mkspecs/features/win32/ltcg.prf @@ -0,0 +1,5 @@ +CONFIG(release, debug|release) { + QMAKE_CFLAGS *= $$QMAKE_CFLAGS_LTCG + QMAKE_CXXFLAGS *= $$QMAKE_CXXFLAGS_LTCG + QMAKE_LFLAGS *= $$QMAKE_LFLAGS_LTCG +} diff --git a/mkspecs/win32-msvc2005/qmake.conf b/mkspecs/win32-msvc2005/qmake.conf index 00287cb..5ed8e01 100644 --- a/mkspecs/win32-msvc2005/qmake.conf +++ b/mkspecs/win32-msvc2005/qmake.conf @@ -19,9 +19,10 @@ QMAKE_YACCFLAGS = -d QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t- QMAKE_CFLAGS_WARN_ON = -W3 QMAKE_CFLAGS_WARN_OFF = -W0 -QMAKE_CFLAGS_RELEASE = -O2 -MD -GL +QMAKE_CFLAGS_RELEASE = -O2 -MD QMAKE_CFLAGS_DEBUG = -Zi -MDd QMAKE_CFLAGS_YACC = +QMAKE_CFLAGS_LTCG = -GL QMAKE_CXX = $$QMAKE_CC QMAKE_CXXFLAGS = $$QMAKE_CFLAGS @@ -30,6 +31,7 @@ QMAKE_CXXFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE QMAKE_CXXFLAGS_DEBUG = $$QMAKE_CFLAGS_DEBUG QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC +QMAKE_CXXFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG QMAKE_CXXFLAGS_STL_ON = -EHsc QMAKE_CXXFLAGS_STL_OFF = QMAKE_CXXFLAGS_RTTI_ON = -GR @@ -50,11 +52,12 @@ QMAKE_RUN_CXX_IMP_BATCH = $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fo$@ @<< QMAKE_LINK = link QMAKE_LFLAGS = /NOLOGO -QMAKE_LFLAGS_RELEASE = /INCREMENTAL:NO /LTCG +QMAKE_LFLAGS_RELEASE = /INCREMENTAL:NO QMAKE_LFLAGS_DEBUG = /DEBUG QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS \"/MANIFESTDEPENDENCY:type=\'win32\' name=\'Microsoft.Windows.Common-Controls\' version=\'6.0.0.0\' publicKeyToken=\'6595b64144ccf1df\' language=\'*\' processorArchitecture=\'*\'\" QMAKE_LFLAGS_DLL = /DLL +QMAKE_LFLAGS_LTCG = /LTCG QMAKE_LIBS_CORE = kernel32.lib user32.lib shell32.lib uuid.lib ole32.lib advapi32.lib ws2_32.lib QMAKE_LIBS_GUI = gdi32.lib comdlg32.lib oleaut32.lib imm32.lib winmm.lib winspool.lib ws2_32.lib ole32.lib user32.lib advapi32.lib diff --git a/mkspecs/win32-msvc2008/qmake.conf b/mkspecs/win32-msvc2008/qmake.conf index b56b41c..373a36d 100644 --- a/mkspecs/win32-msvc2008/qmake.conf +++ b/mkspecs/win32-msvc2008/qmake.conf @@ -19,9 +19,10 @@ QMAKE_YACCFLAGS = -d QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t- QMAKE_CFLAGS_WARN_ON = -W3 QMAKE_CFLAGS_WARN_OFF = -W0 -QMAKE_CFLAGS_RELEASE = -O2 -MD -GL +QMAKE_CFLAGS_RELEASE = -O2 -MD QMAKE_CFLAGS_DEBUG = -Zi -MDd QMAKE_CFLAGS_YACC = +QMAKE_CFLAGS_LTCG = -GL QMAKE_CXX = $$QMAKE_CC QMAKE_CXXFLAGS = $$QMAKE_CFLAGS @@ -30,6 +31,7 @@ QMAKE_CXXFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE QMAKE_CXXFLAGS_DEBUG = $$QMAKE_CFLAGS_DEBUG QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC +QMAKE_CXXFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG QMAKE_CXXFLAGS_STL_ON = -EHsc QMAKE_CXXFLAGS_STL_OFF = QMAKE_CXXFLAGS_RTTI_ON = -GR @@ -50,11 +52,12 @@ QMAKE_RUN_CXX_IMP_BATCH = $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fo$@ @<< QMAKE_LINK = link QMAKE_LFLAGS = /NOLOGO -QMAKE_LFLAGS_RELEASE = /INCREMENTAL:NO /LTCG +QMAKE_LFLAGS_RELEASE = /INCREMENTAL:NO QMAKE_LFLAGS_DEBUG = /DEBUG QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS \"/MANIFESTDEPENDENCY:type=\'win32\' name=\'Microsoft.Windows.Common-Controls\' version=\'6.0.0.0\' publicKeyToken=\'6595b64144ccf1df\' language=\'*\' processorArchitecture=\'*\'\" QMAKE_LFLAGS_DLL = /DLL +QMAKE_LFLAGS_LTCG = /LTCG QMAKE_LIBS_CORE = kernel32.lib user32.lib shell32.lib uuid.lib ole32.lib advapi32.lib ws2_32.lib QMAKE_LIBS_GUI = gdi32.lib comdlg32.lib oleaut32.lib imm32.lib winmm.lib winspool.lib ws2_32.lib ole32.lib user32.lib advapi32.lib diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index bcbf557..91344c8 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -351,6 +351,7 @@ Configure::Configure( int& argc, char** argv ) dictionary[ "QMAKESPEC" ] = tmp; dictionary[ "INCREDIBUILD_XGE" ] = "auto"; + dictionary[ "LTCG" ] = "no"; } Configure::~Configure() @@ -487,6 +488,12 @@ void Configure::parseCmdLine() else if( configCmdLine.at(i) == "-commercial" ) { dictionary[ "BUILDTYPE" ] = "commercial"; } + else if( configCmdLine.at(i) == "-ltcg" ) { + dictionary[ "LTCG" ] = "yes"; + } + else if( configCmdLine.at(i) == "-no-ltcg" ) { + dictionary[ "LTCG" ] = "no"; + } #endif else if( configCmdLine.at(i) == "-platform" ) { @@ -1465,6 +1472,9 @@ bool Configure::displayHelp() desc("SHARED", "yes", "-shared", "Create and use shared Qt libraries."); desc("SHARED", "no", "-static", "Create and use static Qt libraries.\n"); + desc("LTCG", "yes", "-ltcg", "Use Link Time Code Generation. (Release builds only)"); + desc("LTCG", "no", "-no-ltcg", "Do not use Link Time Code Generation.\n"); + desc("FAST", "no", "-no-fast", "Configure Qt normally by generating Makefiles for all project files."); desc("FAST", "yes", "-fast", "Configure Qt quickly by generating Makefiles only for library and " "subdirectory targets. All other Makefiles are created as wrappers " @@ -2494,6 +2504,8 @@ void Configure::generateCachefile() else configStream << " static"; + if( dictionary[ "LTCG" ] == "yes" ) + configStream << " ltcg"; if( dictionary[ "STL" ] == "yes" ) configStream << " stl"; if ( dictionary[ "EXCEPTIONS" ] == "yes" ) @@ -2916,6 +2928,7 @@ void Configure::displayConfig() cout << "Architecture................" << dictionary[ "ARCHITECTURE" ] << endl; cout << "Maketool...................." << dictionary[ "MAKE" ] << endl; cout << "Debug symbols..............." << (dictionary[ "BUILD" ] == "debug" ? "yes" : "no") << endl; + cout << "Link Time Code Generation..." << dictionary[ "LTCG" ] << endl; cout << "Accessibility support......." << dictionary[ "ACCESSIBILITY" ] << endl; cout << "STL support................." << dictionary[ "STL" ] << endl; cout << "Exception support..........." << dictionary[ "EXCEPTIONS" ] << endl; -- cgit v0.12 From bb000e03fc1e876eb6ee0d02de15a0bc9a6ea1b8 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 13 May 2009 14:53:24 +0200 Subject: Added API for quietly saving a form. Task-number: 163220 Added to FormWindowBase. Required among other things for Qt Creator code completion for uic-generated-headers. Acked-by: dt --- tools/designer/src/lib/shared/formwindowbase.cpp | 10 +++++++++- tools/designer/src/lib/shared/formwindowbase_p.h | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/designer/src/lib/shared/formwindowbase.cpp b/tools/designer/src/lib/shared/formwindowbase.cpp index 3e7e17b..b569b51 100644 --- a/tools/designer/src/lib/shared/formwindowbase.cpp +++ b/tools/designer/src/lib/shared/formwindowbase.cpp @@ -55,7 +55,7 @@ TRANSLATOR qdesigner_internal::FormWindowBase #include "deviceprofile_p.h" #include "qdesigner_utils_p.h" -#include +#include "qsimpleresource_p.h" #include #include @@ -482,6 +482,14 @@ void FormWindowBase::setupDefaultAction(QDesignerFormWindowInterface *fw) QObject::connect(fw, SIGNAL(activated(QWidget*)), fw, SLOT(triggerDefaultAction(QWidget*))); } +QString FormWindowBase::fileContents() const +{ + const bool oldValue = QSimpleResource::setWarningsEnabled(false); + const QString rc = contents(); + QSimpleResource::setWarningsEnabled(oldValue); + return rc; +} + } // namespace qdesigner_internal QT_END_NAMESPACE diff --git a/tools/designer/src/lib/shared/formwindowbase_p.h b/tools/designer/src/lib/shared/formwindowbase_p.h index 68e977e..0891f6e 100644 --- a/tools/designer/src/lib/shared/formwindowbase_p.h +++ b/tools/designer/src/lib/shared/formwindowbase_p.h @@ -90,6 +90,9 @@ public: QVariantMap formData(); void setFormData(const QVariantMap &vm); + // Return contents without warnings. Should be 'contents(bool quiet)' + QString fileContents() const; + // Return the widget containing the form. This is used to // apply embedded design settings to that are inherited (for example font). // These are meant to be applied to the form only and not to the other editors -- cgit v0.12 From 960d2a7639062b6582d460aaae140b4d2e0a8b70 Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Wed, 13 May 2009 14:59:52 +0200 Subject: Adding details to QVariant docs Adding note about requriements for converting QVariants Task-number: 192607 Rev-by: David Boddie --- src/corelib/kernel/qvariant.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index b4427c0..0a0500d 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1187,8 +1187,9 @@ const QVariant::Handler *QVariant::handler = &qt_kernel_variant_handler; and versatile, but may prove less memory and speed efficient than storing specific types in standard data structures. - QVariant also supports the notion of null values, where you have - a defined type with no value set. + QVariant also supports the notion of null values, where you can + have a defined type with no value set. However, note that QVariant + types can only be cast when they have had a value set. \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 1 -- cgit v0.12 From 62677589caf8b2f45f369cfc9df30ded323c4155 Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Wed, 13 May 2009 15:13:10 +0200 Subject: Cleaning docs Highlight part of the general description in QTimeLine Task-number: 218487 Rev-by: Geir Vattekar --- src/corelib/tools/qtimeline.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qtimeline.cpp b/src/corelib/tools/qtimeline.cpp index 2979a09..3a03558 100644 --- a/src/corelib/tools/qtimeline.cpp +++ b/src/corelib/tools/qtimeline.cpp @@ -225,7 +225,9 @@ void QTimeLinePrivate::setCurrentTime(int msecs) valueForTime() and emitting valueChanged(). By default, valueForTime() applies an interpolation algorithm to generate these value. You can choose from a set of predefined timeline algorithms by calling - setCurveShape(). By default, QTimeLine uses the EaseInOut curve shape, + setCurveShape(). + + Note that by default, QTimeLine uses the EaseInOut curve shape, which provides a value that grows slowly, then grows steadily, and finally grows slowly. For a custom timeline, you can reimplement valueForTime(), in which case QTimeLine's curveShape property is ignored. -- cgit v0.12 From 9820412d2551b655fec24ffde7b2a56e3ad168ea Mon Sep 17 00:00:00 2001 From: Norwegian Rock Cat Date: Wed, 13 May 2009 15:34:34 +0200 Subject: Ensure that sheets are hidden if the parents are hidden in Carbon. Seems to work correctly in Cocoa, but we need to handle this special case in Carbon ourselves. Task-number: 253324 Reviewed-by: Richard Moe Gustavsen --- src/gui/kernel/qwidget_mac.mm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 6d3da61..6524bc9 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -728,6 +728,7 @@ static OSWindowRef qt_mac_create_window(QWidget *, WindowClass wclass, WindowAtt static EventTypeSpec window_events[] = { { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowExpanded }, + { kEventClassWindow, kEventWindowHidden }, { kEventClassWindow, kEventWindowZoomed }, { kEventClassWindow, kEventWindowCollapsed }, { kEventClassWindow, kEventWindowToolbarSwitchMode }, @@ -997,6 +998,19 @@ OSStatus QWidgetPrivate::qt_window_event(EventHandlerCallRef er, EventRef event, } } } + } else if (ekind == kEventWindowHidden) { + // Make sure that we also hide any visible sheets on our window. + // Cocoa does the right thing for us. + const QObjectList children = widget->children(); + const int childCount = children.count(); + for (int i = 0; i < childCount; ++i) { + QObject *obj = children.at(i); + if (obj->isWidgetType()) { + QWidget *widget = static_cast(obj); + if (qt_mac_is_macsheet(widget) && widget->isVisible()) + widget->hide(); + } + } } else { handled_event = false; } -- cgit v0.12 From 1c22d96f15d46c222bf5f1720e3e49e202a6c941 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Tue, 12 May 2009 17:58:27 +0200 Subject: HTTP backend / network cache: only cache responses to GET by default responses to POST might be cacheable, but are not cacheable by default; responses to PUT or DELETE are never cacheable. Reviewed-by: Thiago Macieira Task-number: 252281 --- src/network/access/qnetworkaccesshttpbackend.cpp | 42 +++++++++++++++++------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index a52b5a0..f214699 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -1036,21 +1036,39 @@ QNetworkCacheMetaData QNetworkAccessHttpBackend::fetchCacheMetaData(const QNetwo if (it != cacheHeaders.rawHeaders.constEnd()) metaData.setLastModified(QNetworkHeadersPrivate::fromHttpDate(it->second)); - bool canDiskCache = true; // Everything defaults to being cacheable on disk - - // 14.32 - // HTTP/1.1 caches SHOULD treat "Pragma: no-cache" as if the client - // had sent "Cache-Control: no-cache". - it = cacheHeaders.findRawHeader("pragma"); - if (it != cacheHeaders.rawHeaders.constEnd() - && it->second == "no-cache") - canDiskCache = false; + bool canDiskCache; + // only cache GET replies by default, all other replies (POST, PUT, DELETE) + // are not cacheable by default (according to RFC 2616 section 9) + if (httpReply->request().operation() == QHttpNetworkRequest::Get) { + + canDiskCache = true; + // 14.32 + // HTTP/1.1 caches SHOULD treat "Pragma: no-cache" as if the client + // had sent "Cache-Control: no-cache". + it = cacheHeaders.findRawHeader("pragma"); + if (it != cacheHeaders.rawHeaders.constEnd() + && it->second == "no-cache") + canDiskCache = false; + + // HTTP/1.1. Check the Cache-Control header + if (cacheControl.contains("no-cache")) + canDiskCache = false; + else if (cacheControl.contains("no-store")) + canDiskCache = false; + + // responses to POST might be cacheable + } else if (httpReply->request().operation() == QHttpNetworkRequest::Post) { - // HTTP/1.1. Check the Cache-Control header - if (cacheControl.contains("no-cache")) canDiskCache = false; - else if (cacheControl.contains("no-store")) + // some pages contain "expires:" and "cache-control: no-cache" field, + // so we only might cache POST requests if we get "cache-control: max-age ..." + if (cacheControl.contains("max-age")) + canDiskCache = true; + + // responses to PUT and DELETE are not cacheable + } else { canDiskCache = false; + } metaData.setSaveToDisk(canDiskCache); int statusCode = httpReply->statusCode(); -- cgit v0.12 From 484ad0eccc84488b57d58a1223760623c70389a5 Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Wed, 13 May 2009 17:10:43 +0200 Subject: Correcting bug in cardLayout example Adding the count() function to the example. Task-number: 220766 Rev-by: Geir Vattekar --- doc/src/layout.qdoc | 16 +++++++----- doc/src/snippets/code/doc_src_layout.qdoc | 41 +++++++++++++++++-------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/doc/src/layout.qdoc b/doc/src/layout.qdoc index 55dfd8b..196999b 100644 --- a/doc/src/layout.qdoc +++ b/doc/src/layout.qdoc @@ -315,7 +315,11 @@ \snippet doc/src/snippets/code/doc_src_layout.qdoc 1 - First we define two functions that iterate over the layout: \c{itemAt()} + First we define \c{count()} to fetch the number of items in the list. + + \snippet doc/src/snippets/code/doc_src_layout.qdoc 2 + + Then we define two functions that iterate over the layout: \c{itemAt()} and \c{takeAt()}. These functions are used internally by the layout system to handle deletion of widgets. They are also available for application programmers. @@ -326,7 +330,7 @@ structure, we may have to spend more effort defining a linear order for the items. - \snippet doc/src/snippets/code/doc_src_layout.qdoc 2 + \snippet doc/src/snippets/code/doc_src_layout.qdoc 3 \c{addItem()} implements the default placement strategy for layout items. This function must be implemented. It is used by QLayout::add(), by the @@ -336,26 +340,26 @@ QGridLayout::addItem(), QGridLayout::addWidget(), and QGridLayout::addLayout(). - \snippet doc/src/snippets/code/doc_src_layout.qdoc 3 + \snippet doc/src/snippets/code/doc_src_layout.qdoc 4 The layout takes over responsibility of the items added. Since QLayoutItem does not inherit QObject, we must delete the items manually. The function QLayout::deleteAllItems() uses \c{takeAt()} defined above to delete all the items in the layout. - \snippet doc/src/snippets/code/doc_src_layout.qdoc 4 + \snippet doc/src/snippets/code/doc_src_layout.qdoc 5 The \c{setGeometry()} function actually performs the layout. The rectangle supplied as an argument does not include \c{margin()}. If relevant, use \c{spacing()} as the distance between items. - \snippet doc/src/snippets/code/doc_src_layout.qdoc 5 + \snippet doc/src/snippets/code/doc_src_layout.qdoc 6 \c{sizeHint()} and \c{minimumSize()} are normally very similar in implementation. The sizes returned by both functions should include \c{spacing()}, but not \c{margin()}. - \snippet doc/src/snippets/code/doc_src_layout.qdoc 6 + \snippet doc/src/snippets/code/doc_src_layout.qdoc 7 \section2 Further Notes diff --git a/doc/src/snippets/code/doc_src_layout.qdoc b/doc/src/snippets/code/doc_src_layout.qdoc index 48e10e9..fedcf0c 100644 --- a/doc/src/snippets/code/doc_src_layout.qdoc +++ b/doc/src/snippets/code/doc_src_layout.qdoc @@ -2,23 +2,21 @@ #ifndef CARD_H #define CARD_H -#include +#include #include class CardLayout : public QLayout { public: - CardLayout(QWidget *parent, int dist) - : QLayout(parent, 0, dist) {} - CardLayout(QLayout *parent, int dist) - : QLayout(parent, dist) {} - CardLayout(int dist) - : QLayout(dist) {} + CardLayout(QWidget *parent, int dist): QLayout(parent, 0, dist) {} + CardLayout(QLayout *parent, int dist): QLayout(parent, dist) {} + CardLayout(int dist): QLayout(dist) {} ~CardLayout(); void addItem(QLayoutItem *item); QSize sizeHint() const; QSize minimumSize() const; + QLayoutItem *count() const; QLayoutItem *itemAt(int) const; QLayoutItem *takeAt(int); void setGeometry(const QRect &rect); @@ -31,11 +29,18 @@ private: //! [1] -#include "card.h" +//#include "card.h" //! [1] - //! [2] +QLayoutItem *CardLayout::count() const +{ + // QList::size() returns the number of QLayoutItems in the list + return list.size(); +} +//! [2] + +//! [3] QLayoutItem *CardLayout::itemAt(int idx) const { // QList::value() performs index checking, and returns 0 if we are @@ -48,26 +53,26 @@ QLayoutItem *CardLayout::takeAt(int idx) // QList::take does not do index checking return idx >= 0 && idx < list.size() ? list.takeAt(idx) : 0; } -//! [2] +//! [3] -//! [3] +//! [4] void CardLayout::addItem(QLayoutItem *item) { list.append(item); } -//! [3] +//! [4] -//! [4] +//! [5] CardLayout::~CardLayout() { deleteAllItems(); } -//! [4] +//! [5] -//! [5] +//! [6] void CardLayout::setGeometry(const QRect &r) { QLayout::setGeometry(r); @@ -85,10 +90,10 @@ void CardLayout::setGeometry(const QRect &r) ++i; } } -//! [5] +//! [6] -//! [6] +//! [7] QSize CardLayout::sizeHint() const { QSize s(0,0); @@ -116,4 +121,4 @@ QSize CardLayout::minimumSize() const } return s + n*QSize(spacing(), spacing()); } -//! [6] +//! [7] \ No newline at end of file -- cgit v0.12 From 54ad50c99fee0db0dc9a64ee16dfcc4315b9d86d Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Thu, 14 May 2009 09:41:08 +1000 Subject: Fix broken wince build. The WinCE build was failing due to a spelling error in an #ifdef directive. Reviewed-by: Trust Me --- src/gui/widgets/qmenu_wince.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/qmenu_wince.cpp b/src/gui/widgets/qmenu_wince.cpp index fbe54fe..42a4e0b 100644 --- a/src/gui/widgets/qmenu_wince.cpp +++ b/src/gui/widgets/qmenu_wince.cpp @@ -214,7 +214,7 @@ static HWND qt_wce_create_menubar(HWND parentHandle, HINSTANCE resourceHandle, i mbi.nToolBarId = toolbarID; if (ptrCreateMenuBar(&mbi)) { -#ifdef Q_WS_WINCE_WM +#ifdef Q_OS_WINCE_WM // Tell the menu bar that we want to override hot key behaviour. LPARAM lparam = MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, SHMBOF_NODEFAULT | SHMBOF_NOTIFY); -- cgit v0.12 From 4cfe2b57d97488b4f312ad2ec2985f619b4984b6 Mon Sep 17 00:00:00 2001 From: Bill King Date: Thu, 14 May 2009 14:15:21 +1000 Subject: Use newer safer error function if available. Uses fb_interpret instead of isc_interprete if using firebird. Closes a potential security hole/buffer overrun. Reviewed-by: Justin McPherson --- src/sql/drivers/ibase/qsql_ibase.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sql/drivers/ibase/qsql_ibase.cpp b/src/sql/drivers/ibase/qsql_ibase.cpp index 6834d9a..4f3d79d 100644 --- a/src/sql/drivers/ibase/qsql_ibase.cpp +++ b/src/sql/drivers/ibase/qsql_ibase.cpp @@ -66,8 +66,11 @@ QT_BEGIN_NAMESPACE enum { QIBaseChunkSize = SHRT_MAX / 2 }; -static bool getIBaseError(QString& msg, ISC_STATUS* status, ISC_LONG &sqlcode, - QTextCodec *tc) +#if defined(FB_API_VER) && FB_API_VER >= 20 +static bool getIBaseError(QString& msg, const ISC_STATUS* status, ISC_LONG &sqlcode, QTextCodec *tc) +#else +static bool getIBaseError(QString& msg, ISC_STATUS* status, ISC_LONG &sqlcode, QTextCodec *tc) +#endif { if (status[0] != 1 || status[1] <= 0) return false; @@ -75,7 +78,11 @@ static bool getIBaseError(QString& msg, ISC_STATUS* status, ISC_LONG &sqlcode, msg.clear(); sqlcode = isc_sqlcode(status); char buf[512]; +#if defined(FB_API_VER) && FB_API_VER >= 20 + while(fb_interpret(buf, 512, &status)) { +#else while(isc_interprete(buf, &status)) { +#endif if(!msg.isEmpty()) msg += QLatin1String(" - "); if (tc) -- cgit v0.12 From df69dfe0ec549a259ed78cf48dff898d8a044c41 Mon Sep 17 00:00:00 2001 From: Ian Walters Date: Thu, 14 May 2009 14:23:40 +1000 Subject: Grammer fix, 'be be' to 'be' --- src/corelib/tools/qcontiguouscache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/tools/qcontiguouscache.cpp b/src/corelib/tools/qcontiguouscache.cpp index 6671982..7db3a5a 100644 --- a/src/corelib/tools/qcontiguouscache.cpp +++ b/src/corelib/tools/qcontiguouscache.cpp @@ -105,7 +105,7 @@ MyRecord record(int row) const behavior. The indexes can be checked by using areIndexesValid() In most cases the indexes will not exceed 0 to INT_MAX, and - normalizeIndexes() will not need to be be used. + normalizeIndexes() will not need to be used. See the \l{Contiguous Cache Example}{Contiguous Cache} example. */ -- cgit v0.12 From 572d57b255227f74c7ce61ab67476d4971955ea9 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Thu, 14 May 2009 10:03:42 +0200 Subject: Fixes missing translations in QFileIconProvider While lupdate ignores ifdefs, it cannot handle ifdefs inside the translate statement itself. Task-number: 188337 Reviewed-by: janarve --- src/gui/itemviews/qfileiconprovider.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/gui/itemviews/qfileiconprovider.cpp b/src/gui/itemviews/qfileiconprovider.cpp index 9f33af3..054f4cf 100644 --- a/src/gui/itemviews/qfileiconprovider.cpp +++ b/src/gui/itemviews/qfileiconprovider.cpp @@ -416,26 +416,22 @@ QString QFileIconProvider::type(const QFileInfo &info) const } if (info.isDir()) - return QApplication::translate("QFileDialog", #ifdef Q_WS_WIN - "File Folder", "Match Windows Explorer" + return QApplication::translate("QFileDialog", "File Folder", "Match Windows Explorer"); #else - "Folder", "All other platforms" + return QApplication::translate("QFileDialog", "Folder", "All other platforms"); #endif - ); // Windows - "File Folder" // OS X - "Folder" // Konqueror - "Folder" // Nautilus - "folder" if (info.isSymLink()) - return QApplication::translate("QFileDialog", #ifdef Q_OS_MAC - "Alias", "Mac OS X Finder" + return QApplication::translate("QFileDialog", "Alias", "Mac OS X Finder"); #else - "Shortcut", "All other platforms" + return QApplication::translate("QFileDialog", "Shortcut", "All other platforms"); #endif - ); // OS X - "Alias" // Windows - "Shortcut" // Konqueror - "Folder" or "TXT File" i.e. what it is pointing to -- cgit v0.12 From 8a97b3b9e506580b4a89c1277068b274794a858c Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 14 May 2009 10:37:37 +0200 Subject: Sheets misbehaviour on Carbon - Mac OS X Seems like some old legacy code was left behind when sheets behaved as application modal. This is not the case anymore, so this patch just removes the special case code for enforcing the old behaviour, and let carbon do the correct thing instead. Task-number: 252379 Reviewed-by: Trenton Schulz --- src/gui/kernel/qwidget_mac.mm | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index b315eaf..0e021dc 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -786,16 +786,6 @@ OSStatus QWidgetPrivate::qt_window_event(EventHandlerCallRef er, EventRef event, // By also setting the current modal window back into the event, we // help Carbon determining which window is supposed to be raised. handled_event = qApp->activePopupWidget() ? true : false; - QWidget *top = 0; - if (!QApplicationPrivate::tryModalHelper(widget, &top) && top && top != widget){ - if(!qt_mac_is_macsheet(top) || top->parentWidget() != widget) { - handled_event = true; - WindowPtr topWindowRef = qt_mac_window_for(top); - SetEventParameter(event, kEventParamModalWindow, typeWindowRef, sizeof(topWindowRef), &topWindowRef); - HIModalClickResult clickResult = kHIModalClickIsModal; - SetEventParameter(event, kEventParamModalClickResult, typeModalClickResult, sizeof(clickResult), &clickResult); - } - } #endif } else if(ekind == kEventWindowClose) { widget->d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent); -- cgit v0.12 From 8a0272a37aa44ed7583cce40eeff1b030c07741e Mon Sep 17 00:00:00 2001 From: Norwegian Rock Cat Date: Thu, 14 May 2009 10:57:22 +0200 Subject: Small updates to the .hgignore file. This is handy in cases where you are maybe using something like the hg-git extension in Mercurial or just storing release in Mercurial for patch queues or what have you. --- .hgignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.hgignore b/.hgignore index 784d507..eb6ff05 100755 --- a/.hgignore +++ b/.hgignore @@ -5,6 +5,8 @@ syntax: glob *~ *.a +*.la +*.pc *.core *.moc *.o @@ -45,7 +47,9 @@ bin/rcc* bin/uic* bin/qcollectiongenerator bin/qhelpgenerator +bin/macdeployqt tools/qdoc3/qdoc3* +tools/macdeployqt/macchangeqt/macchangeqt #configure.cache mkspecs/default mkspecs/qconfig.pri -- cgit v0.12 From e7ea80161aa91369cf700b79e96e97367ecf0ff6 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 14 May 2009 11:03:35 +0200 Subject: Fix Toolbutton font with pseudo-states So now QToolButton:pressed {text-decoration: underline} will works The change in QCommonStyle is to make it consistant with the setFont few lines later. Reveiwed-by: jbache --- src/gui/styles/qcommonstyle.cpp | 1 + src/gui/styles/qstylesheetstyle.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index c0899f8..6972803 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -1664,6 +1664,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, if (!styleHint(SH_UnderlineShortcut, opt, widget)) alignment |= Qt::TextHideMnemonic; rect.translate(shiftX, shiftY); + p->setFont(toolbutton->font); drawItemText(p, rect, alignment, toolbutton->palette, opt->state & State_Enabled, toolbutton->text, QPalette::ButtonText); diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index dcc11b8..cd44bfd 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -3030,6 +3030,7 @@ void QStyleSheetStyle::drawComplexControl(ComplexControl cc, const QStyleOptionC if (const QStyleOptionToolButton *tool = qstyleoption_cast(opt)) { QStyleOptionToolButton toolOpt(*tool); rule.configurePalette(&toolOpt.palette, QPalette::ButtonText, QPalette::Button); + toolOpt.font = rule.font.resolve(toolOpt.font); toolOpt.rect = rule.borderRect(opt->rect); bool customArrow = (tool->features & (QStyleOptionToolButton::HasMenu | QStyleOptionToolButton::MenuButtonPopup)); bool customDropDown = tool->features & QStyleOptionToolButton::MenuButtonPopup; -- cgit v0.12 From cf9277b5e9e20d47681ab084e4410c3566425c3c Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 14 May 2009 11:19:46 +0200 Subject: Remove useless code and comment in QTreeView In 8cd19116ae81c99fe28fbf91aa7f4c1c08163fe0 we changed viewItems to always contains the index to the columns 0, even if this columns is hidden. So this code and comment are now useless. --- src/gui/itemviews/qtreeview.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index f6c5cf0..d742698 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -3086,10 +3086,6 @@ void QTreeViewPrivate::layout(int i) Q_Q(QTreeView); QModelIndex current; QModelIndex parent = (i < 0) ? (QModelIndex)root : modelIndex(i); - // modelIndex() will return an index that don't have a parent if column 0 is hidden, - // so we must make sure that parent points to the actual parent that has children. - if (parent != root) - parent = model->index(parent.row(), 0, parent.parent()); if (i>=0 && !parent.isValid()) { //modelIndex() should never return something invalid for the real items. -- cgit v0.12 From 5db3e40ca796f29cbd7bfc5f7f88823f6e27c16f Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Thu, 14 May 2009 11:04:42 +0200 Subject: Fix sending of double-click events after explicit grab-ungrab. The bug report came from the Declarative UI project as part of Kinetic. In FxFlickable the mouse is explicitly grabbed inside the mouse press event handler, and it's (explicitly) released in the release handler. When doing this, lastMouseGrabber is 0, and the double-click is delivered as a press. The fix is to not convert the double-click to a press if the receiver is the first and only mouse grabber (i.e., lastMouseGrabber is 0). The fix isn't entirely correct, as it can in theory allow an item to receive a double-click event as the first received event. This seems to only be possible in the case of using explicit mouse grabbing in combinations with the press and release event handlers so it's quite a corner case. Reviewed-by: Alexis --- src/gui/graphicsview/qgraphicsscene.cpp | 3 +- tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 99 ++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 69e08d1..9892d36 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -1329,7 +1329,8 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou // check if the item we are sending to are disabled (before we send the event) bool disabled = !item->isEnabled(); bool isWindow = item->isWindow(); - if (mouseEvent->type() == QEvent::GraphicsSceneMouseDoubleClick && item != lastMouseGrabberItem) { + if (mouseEvent->type() == QEvent::GraphicsSceneMouseDoubleClick + && item != lastMouseGrabberItem && lastMouseGrabberItem) { // If this item is different from the item that received the last // mouse event, and mouseEvent is a doubleclick event, then the // event is converted to a press. Known limitation: diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 343aac6..a23ada9 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -149,6 +149,7 @@ private slots: void defaultSize(); void explicitMouseGrabber(); void implicitMouseGrabber(); + void doubleClickAfterExplicitMouseGrab(); void popupMouseGrabber(); void windowFlags_data(); void windowFlags(); @@ -1998,6 +1999,104 @@ void tst_QGraphicsWidget::implicitMouseGrabber() QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); } +class GrabOnPressItem : public QGraphicsRectItem +{ +public: + GrabOnPressItem(const QRectF &rect) + : QGraphicsRectItem(rect), + npress(0), nrelease(0), ndoubleClick(0), + ngrab(0), nungrab(0) + { + } + int npress; + int nrelease; + int ndoubleClick; + int ngrab; + int nungrab; +protected: + bool sceneEvent(QEvent *event) + { + switch (event->type()) { + case QEvent::GrabMouse: + ++ngrab; + break; + case QEvent::UngrabMouse: + ++nungrab; + break; + default: + break; + } + return QGraphicsRectItem::sceneEvent(event); + } + + void mousePressEvent(QGraphicsSceneMouseEvent *) + { + grabMouse(); + ++npress; + } + void mouseReleaseEvent(QGraphicsSceneMouseEvent *) + { + ungrabMouse(); + ++nrelease; + } + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) + { + ++ndoubleClick; + } +}; + +void tst_QGraphicsWidget::doubleClickAfterExplicitMouseGrab() +{ + QGraphicsScene scene; + GrabOnPressItem *item = new GrabOnPressItem(QRectF(0, 0, 100, 100)); + scene.addItem(item); + + { + QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); + event.setButton(Qt::LeftButton); + event.setButtons(Qt::LeftButton); + event.ignore(); + event.setScenePos(QPointF(50, 50)); + qApp->sendEvent(&scene, &event); + } + QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); + QCOMPARE(item->npress, 1); + QCOMPARE(item->ngrab, 1); + { + QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); + event.setButton(Qt::LeftButton); + event.setButtons(0); + event.ignore(); + event.setScenePos(QPointF(50, 50)); + qApp->sendEvent(&scene, &event); + } + QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); + QCOMPARE(item->nrelease, 1); + QCOMPARE(item->nungrab, 1); + { + QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseDoubleClick); + event.setButton(Qt::LeftButton); + event.setButtons(Qt::LeftButton); + event.ignore(); + event.setScenePos(QPointF(50, 50)); + qApp->sendEvent(&scene, &event); + } + QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); + QCOMPARE(item->ndoubleClick, 1); + QCOMPARE(item->ngrab, 2); + { + QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); + event.setButton(Qt::LeftButton); + event.setButtons(0); + event.ignore(); + event.setScenePos(QPointF(50, 50)); + qApp->sendEvent(&scene, &event); + } + QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); + QCOMPARE(item->nrelease, 2); + QCOMPARE(item->nungrab, 2); +} + void tst_QGraphicsWidget::popupMouseGrabber() { QGraphicsScene scene; -- cgit v0.12 From b038c1ac6bdac15b123946821bbff3ee25bfad2b Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Thu, 14 May 2009 05:09:58 -0700 Subject: Fixes combobox menu separator on XP While the delegate is somewhat abusing the ToolbarSeparator here, we should make sure we draw something for small heights as well. It seems microsoft requires us to allocate a few more pixels for the separator to actually be visible. Task-number: 249192 Reviewed-by: ogoffart --- src/gui/styles/qwindowsxpstyle.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/styles/qwindowsxpstyle.cpp b/src/gui/styles/qwindowsxpstyle.cpp index 639eff0..3dac9f5 100644 --- a/src/gui/styles/qwindowsxpstyle.cpp +++ b/src/gui/styles/qwindowsxpstyle.cpp @@ -1792,7 +1792,12 @@ case PE_Frame: return; case PE_IndicatorToolBarSeparator: - + if (option->rect.height() < 3) { + // XP style requires a few pixels for the separator + // to be visible. + QWindowsStyle::drawPrimitive(pe, option, p, widget); + return; + } name = QLatin1String("TOOLBAR"); partId = TP_SEPARATOR; -- cgit v0.12 From d6e87c332c721bbcb86bebc6f4daa8a3125e80c6 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 14 May 2009 15:07:25 +0200 Subject: Fixes build issue with WinCE and MSVC 2008 and MIPS-II Reviewed-by: Maurice --- mkspecs/wince50standard-mipsii-msvc2008/default_post.prf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkspecs/wince50standard-mipsii-msvc2008/default_post.prf b/mkspecs/wince50standard-mipsii-msvc2008/default_post.prf index a232ba3..d423784 100644 --- a/mkspecs/wince50standard-mipsii-msvc2008/default_post.prf +++ b/mkspecs/wince50standard-mipsii-msvc2008/default_post.prf @@ -1 +1 @@ -include(../wince50standard-mipsii-msvc2005/qmake.conf) +include(../wince50standard-mipsii-msvc2005/default_post.prf) -- cgit v0.12 From 7179792bbbc34a091bfc18ebc3e5bd2e401faa65 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Thu, 14 May 2009 15:06:48 +0200 Subject: Fix QGraphicsItem::deviceTransform() to also work with normal items. QGraphicsItem::deviceTransform() returns the item-to-device transform, provided with the device-to-scene transform, and combining it with the item's scene transform. This function is meant to handle items that enable ItemIgnoresTransformations, but it happened to not work properly for items that _don't_ enable that flag. Unfortunately this bug is hard to work around for users from the outside, as it requires you to check if the item or any ancestor enables ItemIgnoresTransformations. The fix also removes unnecessary branchs inside QGV so that we use the same function for all items. Reviewed-by: bnilsen --- src/gui/graphicsview/qgraphicsitem.cpp | 4 + src/gui/graphicsview/qgraphicsscene.cpp | 21 +---- src/gui/graphicsview/qgraphicsview.cpp | 13 +-- tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 110 +++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 28 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 30c15bc..4908296 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -2572,6 +2572,10 @@ QTransform QGraphicsItem::sceneTransform() const */ QTransform QGraphicsItem::deviceTransform(const QTransform &viewportTransform) const { + // Ensure we return the standard transform if we're not untransformable. + if (!d_ptr->itemIsUntransformable()) + return sceneTransform() * viewportTransform; + // Find the topmost item that ignores view transformations. const QGraphicsItem *untransformedAncestor = this; QList parents; diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 13f70e5..b89e352 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -2289,12 +2289,7 @@ void QGraphicsScene::render(QPainter *painter, const QRectF &target, const QRect // Calculate a simple level-of-detail metric. // ### almost identical code in QGraphicsView::paintEvent() // and QGraphicsView::render() - consider refactoring - QTransform itemToDeviceTransform; - if (item->d_ptr->itemIsUntransformable()) { - itemToDeviceTransform = item->deviceTransform(painterTransform); - } else { - itemToDeviceTransform = item->sceneTransform() * painterTransform; - } + QTransform itemToDeviceTransform = item->deviceTransform(painterTransform); option.levelOfDetail = qSqrt(itemToDeviceTransform.map(v1).length() * itemToDeviceTransform.map(v2).length()); option.matrix = itemToDeviceTransform.toAffine(); //### discards perspective @@ -5078,11 +5073,7 @@ void QGraphicsScene::drawItems(QPainter *painter, // optimization, but it's hit very rarely. for (int i = clippers.size() - 1; i >= 0; --i) { QGraphicsItem *clipper = clippers[i]; - if (clipper->d_ptr->itemIsUntransformable()) { - painter->setWorldTransform(clipper->deviceTransform(viewTransform), false); - } else { - painter->setWorldTransform(clipper->sceneTransform() * viewTransform, false); - } + painter->setWorldTransform(clipper->deviceTransform(viewTransform), false); childClippers.append(clipper); painter->save(); @@ -5093,12 +5084,8 @@ void QGraphicsScene::drawItems(QPainter *painter, } // Set up the painter transform - if (item->d_ptr->itemIsUntransformable()) { - painter->setWorldTransform(item->deviceTransform(viewTransform), false); - } else { - painter->setWorldTransform(item->sceneTransform() * viewTransform, false); - } - + painter->setWorldTransform(item->deviceTransform(viewTransform), false); + // Save painter bool saveState = (d->painterStateProtection || (item->flags() & QGraphicsItem::ItemClipsToShape)); if (saveState) diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 8b133f3..a795fb4 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -1153,11 +1153,7 @@ void QGraphicsViewPrivate::generateStyleOptions(const QList &it // Calculate a simple level-of-detail metric. // ### almost identical code in QGraphicsScene::render() // and QGraphicsView::render() - consider refactoring - if (item->d_ptr->itemIsUntransformable()) { - itemToViewportTransform = item->deviceTransform(worldTransform); - } else { - itemToViewportTransform = item->sceneTransform() * worldTransform; - } + itemToViewportTransform = item->deviceTransform(worldTransform); if (itemToViewportTransform.type() <= QTransform::TxTranslate) { // Translation and rotation only? The LOD is 1. @@ -2160,12 +2156,7 @@ void QGraphicsView::render(QPainter *painter, const QRectF &target, const QRect // Calculate a simple level-of-detail metric. // ### almost identical code in QGraphicsScene::render() // and QGraphicsView::paintEvent() - consider refactoring - QTransform itemToViewportTransform; - if (item->d_ptr->itemIsUntransformable()) { - itemToViewportTransform = item->deviceTransform(painterMatrix); - } else { - itemToViewportTransform = item->sceneTransform() * painterMatrix; - } + QTransform itemToViewportTransform = item->deviceTransform(painterMatrix); option->levelOfDetail = qSqrt(itemToViewportTransform.map(v1).length() * itemToViewportTransform.map(v2).length()); option->matrix = itemToViewportTransform.toAffine(); diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 6d150cb..58a17ea 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -215,6 +215,8 @@ private slots: void tabChangesFocus_data(); void cacheMode(); void updateCachedItemAfterMove(); + void deviceTransform_data(); + void deviceTransform(); // task specific tests below me void task141694_textItemEnsureVisible(); @@ -6200,5 +6202,113 @@ void tst_QGraphicsItem::updateCachedItemAfterMove() QCOMPARE(tester->repaints, 1); } +class Track : public QGraphicsRectItem +{ +public: + Track(const QRectF &rect) + : QGraphicsRectItem(rect) + { + setAcceptHoverEvents(true); + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) + { + QGraphicsRectItem::paint(painter, option, widget); + painter->drawText(boundingRect(), Qt::AlignCenter, QString("%1x%2\n%3x%4").arg(p.x()).arg(p.y()).arg(sp.x()).arg(sp.y())); + } + +protected: + void hoverMoveEvent(QGraphicsSceneHoverEvent *event) + { + p = event->pos(); + sp = event->widget()->mapFromGlobal(event->screenPos()); + update(); + } +private: + QPointF p; + QPoint sp; +}; + +void tst_QGraphicsItem::deviceTransform_data() +{ + QTest::addColumn("untransformable1"); + QTest::addColumn("untransformable2"); + QTest::addColumn("untransformable3"); + QTest::addColumn("rotation1"); + QTest::addColumn("rotation2"); + QTest::addColumn("rotation3"); + QTest::addColumn("deviceX"); + QTest::addColumn("mapResult1"); + QTest::addColumn("mapResult2"); + QTest::addColumn("mapResult3"); + + QTest::newRow("nil") << false << false << false + << qreal(0.0) << qreal(0.0) << qreal(0.0) + << QTransform() + << QPointF(150, 150) << QPointF(250, 250) << QPointF(350, 350); + QTest::newRow("deviceX rot 90") << false << false << false + << qreal(0.0) << qreal(0.0) << qreal(0.0) + << QTransform().rotate(90) + << QPointF(-150, 150) << QPointF(-250, 250) << QPointF(-350, 350); + QTest::newRow("deviceX rot 90 100") << true << false << false + << qreal(0.0) << qreal(0.0) << qreal(0.0) + << QTransform().rotate(90) + << QPointF(-50, 150) << QPointF(50, 250) << QPointF(150, 350); + QTest::newRow("deviceX rot 90 010") << false << true << false + << qreal(0.0) << qreal(0.0) << qreal(0.0) + << QTransform().rotate(90) + << QPointF(-150, 150) << QPointF(-150, 250) << QPointF(-50, 350); + QTest::newRow("deviceX rot 90 001") << false << false << true + << qreal(0.0) << qreal(0.0) << qreal(0.0) + << QTransform().rotate(90) + << QPointF(-150, 150) << QPointF(-250, 250) << QPointF(-250, 350); + QTest::newRow("deviceX rot 90 111") << true << true << true + << qreal(0.0) << qreal(0.0) << qreal(0.0) + << QTransform().rotate(90) + << QPointF(-50, 150) << QPointF(50, 250) << QPointF(150, 350); + QTest::newRow("deviceX rot 90 101") << true << false << true + << qreal(0.0) << qreal(0.0) << qreal(0.0) + << QTransform().rotate(90) + << QPointF(-50, 150) << QPointF(50, 250) << QPointF(150, 350); +} + +void tst_QGraphicsItem::deviceTransform() +{ + QFETCH(bool, untransformable1); + QFETCH(bool, untransformable2); + QFETCH(bool, untransformable3); + QFETCH(qreal, rotation1); + QFETCH(qreal, rotation2); + QFETCH(qreal, rotation3); + QFETCH(QTransform, deviceX); + QFETCH(QPointF, mapResult1); + QFETCH(QPointF, mapResult2); + QFETCH(QPointF, mapResult3); + + QGraphicsScene scene; + Track *rect1 = new Track(QRectF(0, 0, 100, 100)); + Track *rect2 = new Track(QRectF(0, 0, 100, 100)); + Track *rect3 = new Track(QRectF(0, 0, 100, 100)); + rect2->setParentItem(rect1); + rect3->setParentItem(rect2); + rect1->setPos(100, 100); + rect2->setPos(100, 100); + rect3->setPos(100, 100); + rect1->rotate(rotation1); + rect2->rotate(rotation2); + rect3->rotate(rotation3); + rect1->setFlag(QGraphicsItem::ItemIgnoresTransformations, untransformable1); + rect2->setFlag(QGraphicsItem::ItemIgnoresTransformations, untransformable2); + rect3->setFlag(QGraphicsItem::ItemIgnoresTransformations, untransformable3); + rect1->setBrush(Qt::red); + rect2->setBrush(Qt::green); + rect3->setBrush(Qt::blue); + scene.addItem(rect1); + + QCOMPARE(rect1->deviceTransform(deviceX).map(QPointF(50, 50)), mapResult1); + QCOMPARE(rect2->deviceTransform(deviceX).map(QPointF(50, 50)), mapResult2); + QCOMPARE(rect3->deviceTransform(deviceX).map(QPointF(50, 50)), mapResult3); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" -- cgit v0.12 From ed52c2f402b99541553aac163029d217f1dcd419 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Thu, 14 May 2009 06:28:47 -0700 Subject: Remove snapback/maximum drag distance from QSlider This feature was only intended for QScrollBar and was incorrectly inherited by QSlider. The only supported platform that use this feature seems to be Windows so instead of doing a nasty qobject cast in the styling it makes more sense to remove the functionality from QSlider entirely. Task-number: 245681 Reviewed-by: ogoffart --- src/gui/styles/qstyle.cpp | 2 +- src/gui/widgets/qslider.cpp | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp index b73332f..514f67b 100644 --- a/src/gui/styles/qstyle.cpp +++ b/src/gui/styles/qstyle.cpp @@ -1332,7 +1332,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value PM_LayoutVerticalSpacing Default \l{QLayout::spacing}{vertical spacing} for a QLayout. \value PM_MaximumDragDistance The maximum allowed distance between - the mouse and a slider when dragging. Exceeding the specified + the mouse and a scrollbar when dragging. Exceeding the specified distance will cause the slider to jump back to the original position; a value of -1 disables this behavior. diff --git a/src/gui/widgets/qslider.cpp b/src/gui/widgets/qslider.cpp index 32b9021..5b9c8a4 100644 --- a/src/gui/widgets/qslider.cpp +++ b/src/gui/widgets/qslider.cpp @@ -62,7 +62,6 @@ public: int tickInterval; QSlider::TickPosition tickPosition; int clickOffset; - int snapBackPosition; void init(); void resetLayoutItemMargins(); int pixelPosToRangeValue(int pos) const; @@ -493,7 +492,6 @@ void QSlider::mousePressEvent(QMouseEvent *ev) setRepeatAction(SliderNoAction); QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); d->clickOffset = d->pick(ev->pos() - sr.topLeft()); - d->snapBackPosition = d->position; update(sr); setSliderDown(true); } @@ -513,14 +511,6 @@ void QSlider::mouseMoveEvent(QMouseEvent *ev) int newPosition = d->pixelPosToRangeValue(d->pick(ev->pos()) - d->clickOffset); QStyleOptionSlider opt; initStyleOption(&opt); - int m = style()->pixelMetric(QStyle::PM_MaximumDragDistance, &opt, this); - if (m >= 0) { - QRect r = rect(); - r.adjust(-m, -m, m, m); - if (!r.contains(ev->pos())) { - newPosition = d->snapBackPosition; - } - } setSliderPosition(newPosition); } -- cgit v0.12 From d755bb5e8cfd88d0cd909f32d240d18e856bbd36 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 14 May 2009 15:37:00 +0200 Subject: Prevent duplicate entries in the sidebar when the paths are the same If two urls were added to the sidebar that only differed in how they referenced the added url (i.e. /foo/bar/. and /foo/bar) then only one entry should appear. Task-number: 253532 Reviewed-by: Alexis --- src/gui/dialogs/qsidebar.cpp | 4 ++-- tests/auto/qsidebar/tst_qsidebar.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gui/dialogs/qsidebar.cpp b/src/gui/dialogs/qsidebar.cpp index 26108d7..9abefdf 100644 --- a/src/gui/dialogs/qsidebar.cpp +++ b/src/gui/dialogs/qsidebar.cpp @@ -249,9 +249,9 @@ void QUrlModel::addUrls(const QList &list, int row, bool move) continue; for (int j = 0; move && j < rowCount(); ++j) { #if defined(Q_OS_WIN) - if (index(j, 0).data(UrlRole).toUrl().toLocalFile().toLower() == url.toLocalFile().toLower()) { + if (QDir::cleanPath(index(j, 0).data(UrlRole).toUrl().toLocalFile()).toLower() == QDir::cleanPath(url.toLocalFile()).toLower()) { #else - if (index(j, 0).data(UrlRole) == url) { + if (QDir::cleanPath(index(j, 0).data(UrlRole)) == QDir::cleanPath(url)) { #endif removeRow(j); if (j <= row) diff --git a/tests/auto/qsidebar/tst_qsidebar.cpp b/tests/auto/qsidebar/tst_qsidebar.cpp index 705e222..1384391 100644 --- a/tests/auto/qsidebar/tst_qsidebar.cpp +++ b/tests/auto/qsidebar/tst_qsidebar.cpp @@ -185,6 +185,13 @@ void tst_QSidebar::addUrls() qsidebar.addUrls(doubleUrls, 1); QCOMPARE(qsidebar.urls().size(), 1); + // Two paths that are effectively pointing to the same location + doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath()); + doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath() + "/."); + qsidebar.setUrls(emptyUrls); + qsidebar.addUrls(doubleUrls, 1); + QCOMPARE(qsidebar.urls().size(), 1); + #if defined(Q_OS_WIN) //Windows is case insensitive so no duplicate entries in that case doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath()); @@ -200,8 +207,6 @@ void tst_QSidebar::addUrls() qsidebar.addUrls(doubleUrls, 1); QCOMPARE(qsidebar.urls().size(), 2); #endif - - } void tst_QSidebar::goToUrl() -- cgit v0.12 From d45795809de0d5c4bb7a8c4dfd0b786373350c14 Mon Sep 17 00:00:00 2001 From: Norwegian Rock Cat Date: Thu, 14 May 2009 15:45:20 +0200 Subject: Ensure style option for drawing blank area in scrollarea is initialized. Then you can actually influence it's palette. Task-number: 253495 Reviewed-by: Jens Bache-Wiig --- src/gui/widgets/qabstractscrollarea.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp index 9886969..0d8b4de 100644 --- a/src/gui/widgets/qabstractscrollarea.cpp +++ b/src/gui/widgets/qabstractscrollarea.cpp @@ -873,21 +873,22 @@ bool QAbstractScrollArea::event(QEvent *e) case QEvent::Resize: d->layoutChildren(); break; - case QEvent::Paint: + case QEvent::Paint: { + QStyleOption option; + option.initFrom(this); if (d->cornerPaintingRect.isValid()) { - QStyleOption option; option.rect = d->cornerPaintingRect; QPainter p(this); style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, &option, &p, this); } #ifdef Q_WS_MAC if (d->reverseCornerPaintingRect.isValid()) { - QStyleOption option; option.rect = d->reverseCornerPaintingRect; QPainter p(this); style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, &option, &p, this); } #endif + } QFrame::paintEvent((QPaintEvent*)e); break; #ifndef QT_NO_CONTEXTMENU -- cgit v0.12 From f09304d46bac91f3e8329cb7147f8df44898d1e0 Mon Sep 17 00:00:00 2001 From: jasplin Date: Thu, 14 May 2009 15:45:21 +0200 Subject: Fixed regression that prevented any widget from having focus when graphics view was disabled. A bug in Commit d5c018f7b014ab794e49d6e1f24e02233555847d prevented any widget from having focus when QT_NO_GRAPHICSVIEW was defined. This patch fixes the bug. Reviewed-by: bnilsen Task-number: 249589 --- src/gui/kernel/qapplication.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index f3bd57b..4cf0ad7 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -2032,12 +2032,10 @@ QWidget *QApplication::focusWidget() void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason) { - if (focus && focus->window() #ifndef QT_NO_GRAPHICSVIEW - && focus->window()->graphicsProxyWidget() -#endif - ) + if (focus && focus->window()->graphicsProxyWidget()) return; +#endif hidden_focus_widget = 0; -- cgit v0.12 From 8e9b041f0081cd5af67c5c5f3cee0cf2b70ffe11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20Thomsch=C3=BCtz?= Date: Thu, 14 May 2009 15:48:31 +0200 Subject: Use isNull() for strings instead of comparing against QString(). foo == QString() should be foo.isNull(). Fixes 7 warnings in the Norwegian Breakfast Network Reviewed-by: Samuel --- qmake/generators/xmloutput.cpp | 2 +- src/corelib/concurrent/qfuturewatcher.cpp | 2 +- src/corelib/kernel/qcoreapplication.cpp | 4 ++-- tools/macdeployqt/shared/shared.cpp | 4 ++-- tools/porting/src/portingrules.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/qmake/generators/xmloutput.cpp b/qmake/generators/xmloutput.cpp index 68d22e1..d77dd4b 100644 --- a/qmake/generators/xmloutput.cpp +++ b/qmake/generators/xmloutput.cpp @@ -277,7 +277,7 @@ void XmlOutput::closeTag() void XmlOutput::closeTo(const QString &tag) { bool cont = true; - if (!tagStack.contains(tag) && tag != QString()) { + if (!tagStack.contains(tag) && !tag.isNull()) { //warn_msg(WarnLogic, "<%s>: Cannot close to tag <%s>, not on stack", tagStack.last().latin1(), tag.latin1()); qDebug("<%s>: Cannot close to tag <%s>, not on stack", tagStack.last().toLatin1().constData(), tag.toLatin1().constData()); return; diff --git a/src/corelib/concurrent/qfuturewatcher.cpp b/src/corelib/concurrent/qfuturewatcher.cpp index ea35e9e..39d7698 100644 --- a/src/corelib/concurrent/qfuturewatcher.cpp +++ b/src/corelib/concurrent/qfuturewatcher.cpp @@ -465,7 +465,7 @@ void QFutureWatcherBasePrivate::sendCallOutEvent(QFutureCallOutEvent *event) break; emit q->progressValueChanged(event->index1); - if (event->text != QString()) // ### + if (!event->text.isNull()) // ### q->progressTextChanged(event->text); break; case QFutureCallOutEvent::ProgressRange: diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index a23b2dd..f6ce4b3 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1696,7 +1696,7 @@ QString QCoreApplication::applicationDirPath() } QCoreApplicationPrivate *d = self->d_func(); - if (d->cachedApplicationDirPath == QString()) + if (d->cachedApplicationDirPath.isNull()) d->cachedApplicationDirPath = QFileInfo(applicationFilePath()).path(); return d->cachedApplicationDirPath; } @@ -1724,7 +1724,7 @@ QString QCoreApplication::applicationFilePath() } QCoreApplicationPrivate *d = self->d_func(); - if (d->cachedApplicationFilePath != QString()) + if (!d->cachedApplicationFilePath.isNull()) return d->cachedApplicationFilePath; #if defined( Q_WS_WIN ) diff --git a/tools/macdeployqt/shared/shared.cpp b/tools/macdeployqt/shared/shared.cpp index db76ef2..1faa63a 100644 --- a/tools/macdeployqt/shared/shared.cpp +++ b/tools/macdeployqt/shared/shared.cpp @@ -343,7 +343,7 @@ DeploymentInfo deployQtFrameworks(QList frameworks, const QString copiedFrameworks.append(framework.frameworkName); // Get the qt path from one of the Qt frameworks; - if (deploymenInfo.qtPath == QString() && framework.frameworkName.contains("Qt") + if (deploymenInfo.qtPath.isNull() && framework.frameworkName.contains("Qt") && framework.frameworkDirectory.contains("/lib")) { deploymenInfo.qtPath = framework.frameworkDirectory; @@ -364,7 +364,7 @@ DeploymentInfo deployQtFrameworks(QList frameworks, const QString // Copy farmework to app bundle. const QString deployedBinaryPath = copyFramework(framework, bundlePath); // Skip the rest if already was deployed. - if (deployedBinaryPath == QString()) + if (deployedBinaryPath.isNull()) continue; runStrip(deployedBinaryPath); diff --git a/tools/porting/src/portingrules.cpp b/tools/porting/src/portingrules.cpp index 4931064..cd29403 100644 --- a/tools/porting/src/portingrules.cpp +++ b/tools/porting/src/portingrules.cpp @@ -189,7 +189,7 @@ void PortingRules::parseXml(QString fileName) QString includeFile = xml[QLatin1String("Rules")][QLatin1String("Include")].text(); - if(includeFile != QString()) { + if(!includeFile.isNull()) { QString resolvedIncludeFile = resolveFileName(fileName, includeFile); if (!resolvedIncludeFile.isEmpty()) parseXml(resolvedIncludeFile); -- cgit v0.12 From a2f9d610c5cfd80819dc9a11c9452fcadba6ebb4 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Thu, 14 May 2009 16:09:41 +0200 Subject: Fix missing update of edit geometry on QSpinBox When showing or hiding spinbox buttons we did not update the child line edit geometry. This would on windows basically mean that the buttons would not show up as they were completely covered by the edit. Task-number: 235747 Reviewed-by: ogoffart --- src/gui/widgets/qabstractspinbox.cpp | 1 + tests/auto/qspinbox/tst_qspinbox.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/gui/widgets/qabstractspinbox.cpp b/src/gui/widgets/qabstractspinbox.cpp index 347f89a..d640c70 100644 --- a/src/gui/widgets/qabstractspinbox.cpp +++ b/src/gui/widgets/qabstractspinbox.cpp @@ -193,6 +193,7 @@ void QAbstractSpinBox::setButtonSymbols(ButtonSymbols buttonSymbols) Q_D(QAbstractSpinBox); if (d->buttonSymbols != buttonSymbols) { d->buttonSymbols = buttonSymbols; + d->updateEditFieldGeometry(); update(); } } diff --git a/tests/auto/qspinbox/tst_qspinbox.cpp b/tests/auto/qspinbox/tst_qspinbox.cpp index 1867356..575f261 100644 --- a/tests/auto/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/qspinbox/tst_qspinbox.cpp @@ -241,6 +241,12 @@ void tst_QSpinBox::getSetCheck() QCOMPARE(0.0, obj2.value()); obj2.setValue(1.0); QCOMPARE(1.0, obj2.value()); + + // Make sure we update line edit geometry when updating + // buttons - see task 235747 + QRect oldEditGeometry = obj1.childrenRect(); + obj1.setButtonSymbols(QAbstractSpinBox::NoButtons); + QVERIFY(obj1.childrenRect() != oldEditGeometry); } tst_QSpinBox::tst_QSpinBox() -- cgit v0.12 From d644a9a89ff4f7bf8866b69af5334ea1c696e4a7 Mon Sep 17 00:00:00 2001 From: Norwegian Rock Cat Date: Thu, 14 May 2009 16:19:22 +0200 Subject: Compile. Need the proper types. Reviewed-by: Andy --- src/gui/dialogs/qsidebar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/dialogs/qsidebar.cpp b/src/gui/dialogs/qsidebar.cpp index 9abefdf..000a06b 100644 --- a/src/gui/dialogs/qsidebar.cpp +++ b/src/gui/dialogs/qsidebar.cpp @@ -251,7 +251,7 @@ void QUrlModel::addUrls(const QList &list, int row, bool move) #if defined(Q_OS_WIN) if (QDir::cleanPath(index(j, 0).data(UrlRole).toUrl().toLocalFile()).toLower() == QDir::cleanPath(url.toLocalFile()).toLower()) { #else - if (QDir::cleanPath(index(j, 0).data(UrlRole)) == QDir::cleanPath(url)) { + if (QDir::cleanPath(index(j, 0).data(UrlRole).toUrl().toLocalFile()) == QDir::cleanPath(url.toLocalFile())) { #endif removeRow(j); if (j <= row) -- cgit v0.12 From d8a5799de2be228c10faaaa3e6f4c7eb07793b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Thu, 14 May 2009 16:45:17 +0200 Subject: Find chart.exe on windows. --- src/testlib/qtestcase.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 8c76c5d..041f2db 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1465,8 +1465,12 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) #if !defined(QT_NO_PROCESS) || !defined(QT_NO_SETTINGS) if (QBenchmarkGlobalData::current->createChart) { - QString chartLocation = QLibraryInfo::location(QLibraryInfo::BinariesPath) - + QLatin1String("/../tools/qtestlib/chart/chart"); + QString chartLocation = QLibraryInfo::location(QLibraryInfo::BinariesPath); +#ifdef Q_OS_WIN + chartLocation += QLatin1String("/../tools/qtestlib/chart/release/chart.exe"); +#else + chartLocation += QLatin1String("/../tools/qtestlib/chart/chart"); +#endif if (QFile::exists(chartLocation)) { QProcess p; p.setProcessChannelMode(QProcess::ForwardedChannels); -- cgit v0.12 From bacdcc7d2ed4816688c19ddbffa8d3aab98b2123 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Thu, 14 May 2009 16:42:13 +0200 Subject: Fix QSplitter::setHandleWidth to work with motif style Motif style was incorrectly adjusting it's size in sizeFromConents. This is wrong and prevents the function from overriding the huge minimum size on the widget. PM_SplitterWidth already ensures the proper default size for the splitter. Task-number: 194542 Reviewed-by: ogoffart --- src/gui/styles/qmotifstyle.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/gui/styles/qmotifstyle.cpp b/src/gui/styles/qmotifstyle.cpp index 7d4fab8..be0e3eb 100644 --- a/src/gui/styles/qmotifstyle.cpp +++ b/src/gui/styles/qmotifstyle.cpp @@ -2026,10 +2026,6 @@ QMotifStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, QSize sz(contentsSize); switch(ct) { - case CT_Splitter: - sz = QSize(10, 10); - break; - case CT_RadioButton: case CT_CheckBox: sz = QCommonStyle::sizeFromContents(ct, opt, contentsSize, widget); -- cgit v0.12 From 85f98acaa3a38079071bea711e43c9a86edec1f6 Mon Sep 17 00:00:00 2001 From: Trond Kjernaasen Date: Thu, 14 May 2009 17:38:56 +0200 Subject: Fixed an issue with text drawing under Windows. Some text drawn with OpenType fonts where cut off by a pixel or two under certain circumstances. This adds an additional 2 pixel pad margin to the glyph cache entries. The padding behaves slightly different when ClearType is enabled/disabled, hence the general 2 pixel padding. Task-number: 246196 Reviewed-by: Samuel --- src/gui/painting/qtextureglyphcache.cpp | 11 ++++------- src/gui/text/qfontengine_win.cpp | 6 +++--- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp index 1ea40ba..3fd1ffb 100644 --- a/src/gui/painting/qtextureglyphcache.cpp +++ b/src/gui/painting/qtextureglyphcache.cpp @@ -88,11 +88,12 @@ void QTextureGlyphCache::populate(const QTextItemInt &ti, ti.ascent.toReal(), ti.descent.toReal()); #endif - int glyph_width = metrics.width.ceil().toInt() + margin * 2; - int glyph_height = metrics.height.ceil().toInt() + margin * 2; + int glyph_width = metrics.width.ceil().toInt(); + int glyph_height = metrics.height.ceil().toInt(); if (glyph_height == 0 || glyph_width == 0) continue; - + glyph_width += margin * 2 + 2; + glyph_height += margin * 2 + 2; // align to 8-bit boundary if (m_type == QFontEngineGlyphCache::Raster_Mono) glyph_width = (glyph_width+7)&~7; @@ -188,11 +189,7 @@ void QImageTextureGlyphCache::createTextureData(int width, int height) int QImageTextureGlyphCache::glyphMargin() const { -#ifdef Q_WS_MAC return 2; -#else - return m_type == QFontEngineGlyphCache::Raster_RGBMask ? 2 : 0; -#endif } void QImageTextureGlyphCache::fillTexture(const Coord &c, glyph_t g) diff --git a/src/gui/text/qfontengine_win.cpp b/src/gui/text/qfontengine_win.cpp index 1996d44..bf3a176 100644 --- a/src/gui/text/qfontengine_win.cpp +++ b/src/gui/text/qfontengine_win.cpp @@ -1406,8 +1406,8 @@ QNativeImage *QFontEngineWin::drawGDIGlyph(HFONT font, glyph_t glyph, int margin #endif #endif - QNativeImage *ni = new QNativeImage(iw + 2 * margin, - ih + 2 * margin, + QNativeImage *ni = new QNativeImage(iw + 2 * margin + 2, + ih + 2 * margin + 2, QNativeImage::systemFormat(), true); ni->image.fill(0xffffffff); @@ -1449,7 +1449,7 @@ QImage QFontEngineWin::alphaMapForGlyph(glyph_t glyph, const QTransform &xform) font = CreateFontIndirectW(&lf); } - QNativeImage *mask = drawGDIGlyph(font, glyph, 0, xform); + QNativeImage *mask = drawGDIGlyph(font, glyph, 2, xform); if (mask == 0) return QImage(); -- cgit v0.12 From ae3f20e9ce7f592c22c23e8dea6bb9feb52c8b90 Mon Sep 17 00:00:00 2001 From: Benjamin Poulain Date: Thu, 14 May 2009 18:40:03 +0200 Subject: QColor::toCmyk() does not convert the color if it is already in CMYK QColor::toCmyk() converted the color to RGB and then to CMYK. If the color was already in CMYK, this conversion change it. The color is now returned directly if it is in CMYK Reviewed-by: Ariya Task-number: 253625 --- src/gui/painting/qcolor.cpp | 4 ++-- tests/auto/qcolor/tst_qcolor.cpp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index 5d7d4ab..1723a19 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -1369,7 +1369,7 @@ QColor QColor::toRgb() const */ QColor QColor::toHsv() const { - if (!isValid()) + if (!isValid() || cspec == Hsv) return *this; if (cspec != Rgb) @@ -1421,7 +1421,7 @@ QColor QColor::toHsv() const */ QColor QColor::toCmyk() const { - if (!isValid()) + if (!isValid() || cspec == Cmyk) return *this; if (cspec != Rgb) return toRgb().toCmyk(); diff --git a/tests/auto/qcolor/tst_qcolor.cpp b/tests/auto/qcolor/tst_qcolor.cpp index 7608a15..684d5b5 100644 --- a/tests/auto/qcolor/tst_qcolor.cpp +++ b/tests/auto/qcolor/tst_qcolor.cpp @@ -111,12 +111,15 @@ private slots: void toRgb_data(); void toRgb(); + void toRgbNonDestructive(); void toHsv_data(); void toHsv(); + void toHsvNonDestructive(); void toCmyk_data(); void toCmyk(); + void toCmykNonDestructive(); void convertTo(); @@ -1124,6 +1127,12 @@ void tst_QColor::toHsv_data() << QColor::fromCmykF(0., 1., 1., 0.); } +void tst_QColor::toRgbNonDestructive() +{ + QColor aColor = QColor::fromRgbF(0.11, 0.22, 0.33, 0.44); + QCOMPARE(aColor, aColor.toRgb()); +} + void tst_QColor::toHsv() { // invalid should remain invalid @@ -1136,6 +1145,12 @@ void tst_QColor::toHsv() QCOMPARE(cmykColor.toHsv(), expectedColor); } +void tst_QColor::toHsvNonDestructive() +{ + QColor aColor = QColor::fromHsvF(0.11, 0.22, 0.33, 0.44); + QCOMPARE(aColor, aColor.toHsv()); +} + void tst_QColor::toCmyk_data() { QTest::addColumn("expectedColor"); @@ -1165,6 +1180,12 @@ void tst_QColor::toCmyk() QCOMPARE(hsvColor.toCmyk(), expectedColor); } +void tst_QColor::toCmykNonDestructive() +{ + QColor aColor = QColor::fromCmykF(0.11, 0.22, 0.33, 0.44); + QCOMPARE(aColor, aColor.toCmyk()); +} + void tst_QColor::convertTo() { QColor color(Qt::black); -- cgit v0.12 From 38f8b6d63aa88bb4b05c164632e5058beed9a7db Mon Sep 17 00:00:00 2001 From: Benjamin Poulain Date: Thu, 14 May 2009 18:40:03 +0200 Subject: QColor::toCmyk() does not convert the color if it is already in CMYK QColor::toCmyk() converted the color to RGB and then to CMYK. If the color was already in CMYK, this conversion change it. The color is now returned directly if it is in CMYK Reviewed-by: Ariya Task-number: 253625 --- src/gui/painting/qcolor.cpp | 4 ++-- tests/auto/qcolor/tst_qcolor.cpp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index 24d167e..534a425 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -1369,7 +1369,7 @@ QColor QColor::toRgb() const */ QColor QColor::toHsv() const { - if (!isValid()) + if (!isValid() || cspec == Hsv) return *this; if (cspec != Rgb) @@ -1421,7 +1421,7 @@ QColor QColor::toHsv() const */ QColor QColor::toCmyk() const { - if (!isValid()) + if (!isValid() || cspec == Cmyk) return *this; if (cspec != Rgb) return toRgb().toCmyk(); diff --git a/tests/auto/qcolor/tst_qcolor.cpp b/tests/auto/qcolor/tst_qcolor.cpp index 7608a15..684d5b5 100644 --- a/tests/auto/qcolor/tst_qcolor.cpp +++ b/tests/auto/qcolor/tst_qcolor.cpp @@ -111,12 +111,15 @@ private slots: void toRgb_data(); void toRgb(); + void toRgbNonDestructive(); void toHsv_data(); void toHsv(); + void toHsvNonDestructive(); void toCmyk_data(); void toCmyk(); + void toCmykNonDestructive(); void convertTo(); @@ -1124,6 +1127,12 @@ void tst_QColor::toHsv_data() << QColor::fromCmykF(0., 1., 1., 0.); } +void tst_QColor::toRgbNonDestructive() +{ + QColor aColor = QColor::fromRgbF(0.11, 0.22, 0.33, 0.44); + QCOMPARE(aColor, aColor.toRgb()); +} + void tst_QColor::toHsv() { // invalid should remain invalid @@ -1136,6 +1145,12 @@ void tst_QColor::toHsv() QCOMPARE(cmykColor.toHsv(), expectedColor); } +void tst_QColor::toHsvNonDestructive() +{ + QColor aColor = QColor::fromHsvF(0.11, 0.22, 0.33, 0.44); + QCOMPARE(aColor, aColor.toHsv()); +} + void tst_QColor::toCmyk_data() { QTest::addColumn("expectedColor"); @@ -1165,6 +1180,12 @@ void tst_QColor::toCmyk() QCOMPARE(hsvColor.toCmyk(), expectedColor); } +void tst_QColor::toCmykNonDestructive() +{ + QColor aColor = QColor::fromCmykF(0.11, 0.22, 0.33, 0.44); + QCOMPARE(aColor, aColor.toCmyk()); +} + void tst_QColor::convertTo() { QColor color(Qt::black); -- cgit v0.12 From f36d2e5cd0655cee2a1bfb84a66400a4b7a4c454 Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Thu, 14 May 2009 23:29:28 +0200 Subject: Only build the QWS keymap converter in embedded builds. Reviewed-by: TrustMe --- tools/tools.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tools.pro b/tools/tools.pro index 0a56cfb..d034dcd 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -22,7 +22,7 @@ mac { SUBDIRS += macdeployqt } -SUBDIRS += kmap2qmap +embedded:SUBDIRS += kmap2qmap contains(QT_CONFIG, dbus):SUBDIRS += qdbus !wince*:contains(QT_CONFIG, xmlpatterns): SUBDIRS += xmlpatterns -- cgit v0.12