diff options
76 files changed, 1834 insertions, 1069 deletions
diff --git a/config.tests/unix/fvisibility.test b/config.tests/unix/fvisibility.test index 5bc4b93..27c6841 100755 --- a/config.tests/unix/fvisibility.test +++ b/config.tests/unix/fvisibility.test @@ -1,4 +1,4 @@ -#!/bin/sh -x +#!/bin/sh FVISIBILITY_SUPPORT=no COMPILER=$1 diff --git a/doc/src/development/rcc.qdoc b/doc/src/development/rcc.qdoc index 1541e11..999408b 100644 --- a/doc/src/development/rcc.qdoc +++ b/doc/src/development/rcc.qdoc @@ -60,28 +60,30 @@ \row \o \c{-o} \o \c{file} \o Write output to \c{file} rather than to stdout. \row \o \c{-name} \o \c{name} \o Create an external initialization - function with \c{name}. - - \row \o \c{-threshold} \o \c{level} \o Specifies a threshold \c{level} (in - bytes) to use when deciding whether - to compress a file. If the file is - smaller than the threshold \c{level}, - it is not compressed. The default - threshold level is 70 bytes. - + function with \c{name}. + + \row \o \c{-threshold} \o \c{level} \o Specifies a threshold \c{level} (as a + percentage) to use when deciding whether to compress + a file. If the reduction in the file size is greater than + the threshold \c{level}, it is compressed; otherwise, + the uncompressed data is stored instead. The default + threshold level is 70%, meaning that compressed files + which are 30% or less of their original size are + stored as compressed data. + \row \o \c{-compress} \o \c{level} \o Compress input files to the given - compression \c{level}, which is an - integer in the range 1 to 9. Level 1 - does the least compression but is - fastest. Level 9 does the most - compression but is slowest. To turn - off compression, use \c{-no-compress}. - The default value for \c{level} is -1, - which means use zlib's default - compression level. + compression \c{level}, which is an + integer in the range 1 to 9. Level 1 + does the least compression but is + fastest. Level 9 does the most + compression but is slowest. To turn + off compression, use \c{-no-compress}. + The default value for \c{level} is -1, + which means use zlib's default + compression level. \row \o \c{-root} \o \c{path} \o Prefix the resource access path with \c{path}. - The default is no prefix. + The default is no prefix. \row \o \c{-no-compress} \o \o Disable compression. diff --git a/doc/src/examples/pixelator.qdoc b/doc/src/examples/pixelator.qdoc index 09ae3e8..95099e1 100644 --- a/doc/src/examples/pixelator.qdoc +++ b/doc/src/examples/pixelator.qdoc @@ -80,8 +80,6 @@ functions to indicate the dimensions of the image and supply data to other components. - For convenience, the image to be used is passed in the constructor. - \section1 ImageModel Class Implementation The constructor is trivial: @@ -89,7 +87,7 @@ \snippet examples/itemviews/pixelator/imagemodel.cpp 0 The \c setImage() function sets the image that will be used by the model: - + \snippet examples/itemviews/pixelator/imagemodel.cpp 1 The QAbstractItemModel::reset() call tells the view(s) that the model @@ -233,7 +231,7 @@ This enables the items to be drawn without any gaps between them. Removing the headers also prevents the user from adjusting the sizes of individual rows and columns. - + We also set the minimum section size to 1 on the headers. If we didn't, the headers would default to a larger size, preventing us from displaying really small items (which can be specified diff --git a/doc/src/examples/qml-examples.qdoc b/doc/src/examples/qml-examples.qdoc index 56ba1c7..035628e 100644 --- a/doc/src/examples/qml-examples.qdoc +++ b/doc/src/examples/qml-examples.qdoc @@ -110,18 +110,27 @@ */ /*! - \title Graphics Layouts - \example declarative/cppextensions/qgraphicslayouts/graphicsLayouts + \title LayoutItem + \example declarative/cppextensions/qgraphicslayouts/layoutitem - This example show how to integrate Qt \l{Graphics View Framework}{Graphics View} components - like QGraphicsLayoutItem, QGraphicsLinearLayout and QGraphicsGridLayout into QML. + This example show how to use the LayoutItem element to integrate QML items into an existing + \l{Graphics View Framework}{Graphics View}-based application. */ /*! - \title Layout Item - \example declarative/cppextensions/qgraphicslayouts/layoutItem + \title QGraphicsGridLayout + \example declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout - This example show how to integrate QML into an existing - \l{Graphics View Framework}{Graphics View}-based application. + This example shows how to use QGraphicsGridLayout to lay out QML items. This is + useful if you need to integrate Qt \l{Graphics View Framework}{Graphics View} layouts with + QML. +*/ +/*! + \title QGraphicsLinearLayout + \example declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout + + This example shows how to use QGraphicsLinearLayout to lay out QML items. This is + useful if you need to integrate Qt \l{Graphics View Framework}{Graphics View} layouts with + QML. */ /*! \page declarative-cppextensions-qgraphicslayouts.html @@ -131,8 +140,9 @@ layout components with QML: \list - \o \l{declarative/cppextensions/qgraphicslayouts/graphicsLayouts}{Graphics Layouts} - \o \l{declarative/cppextensions/qgraphicslayouts/layoutItem}{Layout Item} + \o \l{declarative/cppextensions/qgraphicslayouts/layoutitem}{LayoutItem} + \o \l{declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout}{QGraphicsGridLayout} + \o \l{declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout}{QGraphicsLinearLayout} \endlist */ diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.pro b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.pro deleted file mode 100644 index e5d91b2..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE = app -TARGET = graphicslayouts -QT += declarative - -SOURCES += \ - graphicslayouts.cpp \ - main.cpp - -HEADERS += \ - graphicslayouts_p.h - -RESOURCES += \ - graphicslayouts.qrc diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject deleted file mode 100644 index d4909f8..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject +++ /dev/null @@ -1,16 +0,0 @@ -import QmlProject 1.0 - -Project { - /* Include .qml, .js, and image files from current directory and subdirectories */ - QmlFiles { - directory: "." - } - JavaScriptFiles { - directory: "." - } - ImageFiles { - directory: "." - } - /* List of plugin directories passed to QML runtime */ - // importPaths: [ " ../exampleplugin " ] -} diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp deleted file mode 100644 index 40e286d..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "graphicslayouts_p.h" - -#include <QtGui/qgraphicswidget.h> -#include <QtCore/qdebug.h> - -QT_BEGIN_NAMESPACE - -LinearLayoutAttached::LinearLayoutAttached(QObject *parent) -: QObject(parent), _stretch(1), _alignment(Qt::AlignCenter), _spacing(0) -{ -} - -void LinearLayoutAttached::setStretchFactor(int f) -{ - if (_stretch == f) - return; - - _stretch = f; - emit stretchChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _stretch); -} - -void LinearLayoutAttached::setSpacing(int s) -{ - if (_spacing == s) - return; - - _spacing = s; - emit spacingChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _spacing); -} - -void LinearLayoutAttached::setAlignment(Qt::Alignment a) -{ - if (_alignment == a) - return; - - _alignment = a; - emit alignmentChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _alignment); -} - -QGraphicsLinearLayoutStretchItemObject::QGraphicsLinearLayoutStretchItemObject(QObject *parent) - : QObject(parent) -{ -} - -QSizeF QGraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const -{ -Q_UNUSED(which); -Q_UNUSED(constraint); -return QSizeF(); -} - - -QGraphicsLinearLayoutObject::QGraphicsLinearLayoutObject(QObject *parent) -: QObject(parent) -{ -} - -QGraphicsLinearLayoutObject::~QGraphicsLinearLayoutObject() -{ -} - -void QGraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutItem *item) -{ -insertItem(index, item); - -//connect attached properties -if (LinearLayoutAttached *obj = attachedProperties.value(item)) { - setStretchFactor(item, obj->stretchFactor()); - setAlignment(item, obj->alignment()); - updateSpacing(item, obj->spacing()); - QObject::connect(obj, SIGNAL(stretchChanged(QGraphicsLayoutItem*,int)), - this, SLOT(updateStretch(QGraphicsLayoutItem*,int))); - QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)), - this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); - QObject::connect(obj, SIGNAL(spacingChanged(QGraphicsLayoutItem*,int)), - this, SLOT(updateSpacing(QGraphicsLayoutItem*,int))); - //### need to disconnect when widget is removed? -} -} - -//### is there a better way to do this? -void QGraphicsLinearLayoutObject::clearChildren() -{ -for (int i = 0; i < count(); ++i) - removeAt(i); -} - -qreal QGraphicsLinearLayoutObject::contentsMargin() const -{ - qreal a,b,c,d; - getContentsMargins(&a, &b, &c, &d); - if(a==b && a==c && a==d) - return a; - return -1; -} - -void QGraphicsLinearLayoutObject::setContentsMargin(qreal m) -{ - setContentsMargins(m,m,m,m); -} - -void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) -{ -QGraphicsLinearLayout::setStretchFactor(item, stretch); -} - -void QGraphicsLinearLayoutObject::updateSpacing(QGraphicsLayoutItem* item, int spacing) -{ - for(int i=0; i < count(); i++){ - if(itemAt(i) == item){ //I do not see the reverse function, which is why we must loop over all items - QGraphicsLinearLayout::setItemSpacing(i, spacing); - return; - } - } -} - -void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) -{ -QGraphicsLinearLayout::setAlignment(item, alignment); -} - -QHash<QGraphicsLayoutItem*, LinearLayoutAttached*> QGraphicsLinearLayoutObject::attachedProperties; -LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) -{ -// ### This is not allowed - you must attach to any object -if (!qobject_cast<QGraphicsLayoutItem*>(obj)) - return 0; -LinearLayoutAttached *rv = new LinearLayoutAttached(obj); -attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv); -return rv; -} - -////////////////////////////////////////////////////////////////////////////////////////////////////// -// QGraphicsGridLayout-related classes -////////////////////////////////////////////////////////////////////////////////////////////////////// -GridLayoutAttached::GridLayoutAttached(QObject *parent) -: QObject(parent), _row(-1), _column(-1), _rowspan(1), _colspan(1), _alignment(-1), _rowstretch(-1), - _colstretch(-1), _rowspacing(-1), _colspacing(-1), _rowprefheight(-1), _rowmaxheight(-1), _rowminheight(-1), - _rowfixheight(-1), _colprefwidth(-1), _colmaxwidth(-1), _colminwidth(-1), _colfixwidth(-1) -{ -} - -void GridLayoutAttached::setRow(int r) -{ - if (_row == r) - return; - - _row = r; - //emit rowChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _row); -} - -void GridLayoutAttached::setColumn(int c) -{ - if (_column == c) - return; - - _column = c; - //emit columnChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _column); -} - -void GridLayoutAttached::setRowSpan(int rs) -{ - if (_rowspan == rs) - return; - - _rowspan = rs; - //emit rowSpanChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _rowSpan); -} - -void GridLayoutAttached::setColumnSpan(int cs) -{ - if (_colspan == cs) - return; - - _colspan = cs; - //emit columnSpanChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _columnSpan); -} - -void GridLayoutAttached::setAlignment(Qt::Alignment a) -{ - if (_alignment == a) - return; - - _alignment = a; - emit alignmentChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _alignment); -} - -void GridLayoutAttached::setRowStretchFactor(int f) -{ - _rowstretch = f; -} - -void GridLayoutAttached::setColumnStretchFactor(int f) -{ - _colstretch = f; -} - -void GridLayoutAttached::setRowSpacing(int s) -{ - _rowspacing = s; -} - -void GridLayoutAttached::setColumnSpacing(int s) -{ - _colspacing = s; -} - - -QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent) -: QObject(parent) -{ -} - -QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject() -{ -} - -void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *wid) -{ -//use attached properties -if (QObject *obj = attachedProperties.value(qobject_cast<QGraphicsLayoutItem*>(wid))) { - int row = static_cast<GridLayoutAttached *>(obj)->row(); - int column = static_cast<GridLayoutAttached *>(obj)->column(); - int rowSpan = static_cast<GridLayoutAttached *>(obj)->rowSpan(); - int columnSpan = static_cast<GridLayoutAttached *>(obj)->columnSpan(); - if (row == -1 || column == -1) { - qWarning() << "Must set row and column for an item in a grid layout"; - return; - } - addItem(wid, row, column, rowSpan, columnSpan); -} -} - -void QGraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item) -{ -//use attached properties -if (GridLayoutAttached *obj = attachedProperties.value(item)) { - int row = obj->row(); - int column = obj->column(); - int rowSpan = obj->rowSpan(); - int columnSpan = obj->columnSpan(); - Qt::Alignment alignment = obj->alignment(); - if (row == -1 || column == -1) { - qWarning() << "Must set row and column for an item in a grid layout"; - return; - } - if(obj->rowSpacing() != -1) - setRowSpacing(row, obj->rowSpacing()); - if(obj->columnSpacing() != -1) - setColumnSpacing(column, obj->columnSpacing()); - if(obj->rowStretchFactor() != -1) - setRowStretchFactor(row, obj->rowStretchFactor()); - if(obj->columnStretchFactor() != -1) - setColumnStretchFactor(column, obj->columnStretchFactor()); - if(obj->rowPreferredHeight() != -1) - setRowPreferredHeight(row, obj->rowPreferredHeight()); - if(obj->rowMaximumHeight() != -1) - setRowMaximumHeight(row, obj->rowMaximumHeight()); - if(obj->rowMinimumHeight() != -1) - setRowMinimumHeight(row, obj->rowMinimumHeight()); - if(obj->rowFixedHeight() != -1) - setRowFixedHeight(row, obj->rowFixedHeight()); - if(obj->columnPreferredWidth() != -1) - setColumnPreferredWidth(row, obj->columnPreferredWidth()); - if(obj->columnMaximumWidth() != -1) - setColumnMaximumWidth(row, obj->columnMaximumWidth()); - if(obj->columnMinimumWidth() != -1) - setColumnMinimumWidth(row, obj->columnMinimumWidth()); - if(obj->columnFixedWidth() != -1) - setColumnFixedWidth(row, obj->columnFixedWidth()); - addItem(item, row, column, rowSpan, columnSpan); - if (alignment != -1) - setAlignment(item,alignment); - QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)), - this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); - //### need to disconnect when widget is removed? -} -} - -//### is there a better way to do this? -void QGraphicsGridLayoutObject::clearChildren() -{ -for (int i = 0; i < count(); ++i) - removeAt(i); -} - -qreal QGraphicsGridLayoutObject::spacing() const -{ -if (verticalSpacing() == horizontalSpacing()) - return verticalSpacing(); -return -1; //### -} - -qreal QGraphicsGridLayoutObject::contentsMargin() const -{ - qreal a,b,c,d; - getContentsMargins(&a, &b, &c, &d); - if(a==b && a==c && a==d) - return a; - return -1; -} - -void QGraphicsGridLayoutObject::setContentsMargin(qreal m) -{ - setContentsMargins(m,m,m,m); -} - - -void QGraphicsGridLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) -{ -QGraphicsGridLayout::setAlignment(item, alignment); -} - -QHash<QGraphicsLayoutItem*, GridLayoutAttached*> QGraphicsGridLayoutObject::attachedProperties; -GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) -{ -// ### This is not allowed - you must attach to any object -if (!qobject_cast<QGraphicsLayoutItem*>(obj)) - return 0; -GridLayoutAttached *rv = new GridLayoutAttached(obj); -attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv); -return rv; -} - -QT_END_NAMESPACE diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h deleted file mode 100644 index 7aa98df..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h +++ /dev/null @@ -1,302 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef GRAPHICSLAYOUTS_H -#define GRAPHICSLAYOUTS_H - -#include <QtGui/QGraphicsLinearLayout> -#include <QtGui/QGraphicsGridLayout> -#include <qdeclarative.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QGraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayoutItem) -public: - QGraphicsLinearLayoutStretchItemObject(QObject *parent = 0); - - virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const; -}; - -class LinearLayoutAttached; -class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) - - Q_PROPERTY(QDeclarativeListProperty<QGraphicsLayoutItem> children READ children) - Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) - Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsLinearLayoutObject(QObject * = 0); - ~QGraphicsLinearLayoutObject(); - - QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); } - - static LinearLayoutAttached *qmlAttachedProperties(QObject *); - - qreal contentsMargin() const; - void setContentsMargin(qreal); - -private Q_SLOTS: - void updateStretch(QGraphicsLayoutItem*,int); - void updateSpacing(QGraphicsLayoutItem*,int); - void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); - -private: - friend class LinearLayoutAttached; - void clearChildren(); - void insertLayoutItem(int, QGraphicsLayoutItem *); - static QHash<QGraphicsLayoutItem*, LinearLayoutAttached*> attachedProperties; - - static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) { - static_cast<QGraphicsLinearLayoutObject*>(prop->object)->insertLayoutItem(-1, item); - } - - static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { - static_cast<QGraphicsLinearLayoutObject*>(prop->object)->clearChildren(); - } - - static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { - return static_cast<QGraphicsLinearLayoutObject*>(prop->object)->count(); - } - - static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) { - return static_cast<QGraphicsLinearLayoutObject*>(prop->object)->itemAt(index); - } -}; - -class GridLayoutAttached; -class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) - - Q_PROPERTY(QDeclarativeListProperty<QGraphicsLayoutItem> children READ children) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) - Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) - Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing) - Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsGridLayoutObject(QObject * = 0); - ~QGraphicsGridLayoutObject(); - - QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); } - - qreal spacing() const; - qreal contentsMargin() const; - void setContentsMargin(qreal); - - static GridLayoutAttached *qmlAttachedProperties(QObject *); - -private Q_SLOTS: - void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); - -private: - friend class GraphicsLayoutAttached; - void addWidget(QGraphicsWidget *); - void clearChildren(); - void addLayoutItem(QGraphicsLayoutItem *); - static QHash<QGraphicsLayoutItem*, GridLayoutAttached*> attachedProperties; - - static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) { - static_cast<QGraphicsGridLayoutObject*>(prop->object)->addLayoutItem(item); - } - - static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { - static_cast<QGraphicsGridLayoutObject*>(prop->object)->clearChildren(); - } - - static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { - return static_cast<QGraphicsGridLayoutObject*>(prop->object)->count(); - } - - static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) { - return static_cast<QGraphicsGridLayoutObject*>(prop->object)->itemAt(index); - } -}; - -class LinearLayoutAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int stretchFactor READ stretchFactor WRITE setStretchFactor NOTIFY stretchChanged) - Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) - Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) -public: - LinearLayoutAttached(QObject *parent); - - int stretchFactor() const { return _stretch; } - void setStretchFactor(int f); - Qt::Alignment alignment() const { return _alignment; } - void setAlignment(Qt::Alignment a); - int spacing() const { return _spacing; } - void setSpacing(int s); - -Q_SIGNALS: - void stretchChanged(QGraphicsLayoutItem*,int); - void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); - void spacingChanged(QGraphicsLayoutItem*,int); - -private: - int _stretch; - Qt::Alignment _alignment; - int _spacing; -}; - -class GridLayoutAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int row READ row WRITE setRow) - Q_PROPERTY(int column READ column WRITE setColumn) - Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan) - Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan) - Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) - Q_PROPERTY(int rowStretchFactor READ rowStretchFactor WRITE setRowStretchFactor) - Q_PROPERTY(int columnStretchFactor READ columnStretchFactor WRITE setColumnStretchFactor) - Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing) - Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing) - Q_PROPERTY(int rowPreferredHeight READ rowPreferredHeight WRITE setRowPreferredHeight) - Q_PROPERTY(int rowMinimumHeight READ rowMinimumHeight WRITE setRowMinimumHeight) - Q_PROPERTY(int rowMaximumHeight READ rowMaximumHeight WRITE setRowMaximumHeight) - Q_PROPERTY(int rowFixedHeight READ rowFixedHeight WRITE setRowFixedHeight) - Q_PROPERTY(int columnPreferredWidth READ columnPreferredWidth WRITE setColumnPreferredWidth) - Q_PROPERTY(int columnMaximumWidth READ columnMaximumWidth WRITE setColumnMaximumWidth) - Q_PROPERTY(int columnMinimumWidth READ columnMinimumWidth WRITE setColumnMinimumWidth) - Q_PROPERTY(int columnFixedWidth READ columnFixedWidth WRITE setColumnFixedWidth) - -public: - GridLayoutAttached(QObject *parent); - - int row() const { return _row; } - void setRow(int r); - - int column() const { return _column; } - void setColumn(int c); - - int rowSpan() const { return _rowspan; } - void setRowSpan(int rs); - - int columnSpan() const { return _colspan; } - void setColumnSpan(int cs); - - Qt::Alignment alignment() const { return _alignment; } - void setAlignment(Qt::Alignment a); - - int rowStretchFactor() const { return _rowstretch; } - void setRowStretchFactor(int f); - int columnStretchFactor() const { return _colstretch; } - void setColumnStretchFactor(int f); - - int rowSpacing() const { return _rowspacing; } - void setRowSpacing(int s); - int columnSpacing() const { return _colspacing; } - void setColumnSpacing(int s); - - int rowPreferredHeight() const { return _rowprefheight; } - void setRowPreferredHeight(int s) { _rowprefheight = s; } - - int rowMaximumHeight() const { return _rowmaxheight; } - void setRowMaximumHeight(int s) { _rowmaxheight = s; } - - int rowMinimumHeight() const { return _rowminheight; } - void setRowMinimumHeight(int s) { _rowminheight = s; } - - int rowFixedHeight() const { return _rowfixheight; } - void setRowFixedHeight(int s) { _rowfixheight = s; } - - int columnPreferredWidth() const { return _colprefwidth; } - void setColumnPreferredWidth(int s) { _colprefwidth = s; } - - int columnMaximumWidth() const { return _colmaxwidth; } - void setColumnMaximumWidth(int s) { _colmaxwidth = s; } - - int columnMinimumWidth() const { return _colminwidth; } - void setColumnMinimumWidth(int s) { _colminwidth = s; } - - int columnFixedWidth() const { return _colfixwidth; } - void setColumnFixedWidth(int s) { _colfixwidth = s; } - -Q_SIGNALS: - void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); - -private: - int _row; - int _column; - int _rowspan; - int _colspan; - Qt::Alignment _alignment; - int _rowstretch; - int _colstretch; - int _rowspacing; - int _colspacing; - int _rowprefheight; - int _rowmaxheight; - int _rowminheight; - int _rowfixheight; - int _colprefwidth; - int _colmaxwidth; - int _colminwidth; - int _colfixwidth; -}; - -QT_END_NAMESPACE - -QML_DECLARE_INTERFACE(QGraphicsLayoutItem) -QML_DECLARE_INTERFACE(QGraphicsLayout) -QML_DECLARE_TYPE(QGraphicsLinearLayoutStretchItemObject) -QML_DECLARE_TYPE(QGraphicsLinearLayoutObject) -QML_DECLARE_TYPEINFO(QGraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QGraphicsGridLayoutObject) -QML_DECLARE_TYPEINFO(QGraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES) - -QT_END_HEADER - -#endif // GRAPHICSLAYOUTS_H diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.pro b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.pro index c85a400..77c6b2a 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.pro +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.pro @@ -5,4 +5,4 @@ INCLUDEPATH += . QT += declarative SOURCES += main.cpp -RESOURCES += layoutItem.qrc +RESOURCES += layoutitem.qrc diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qml b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qml index 6f377c5..6f377c5 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qml +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qml diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qmlproject b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qmlproject index d4909f8..d4909f8 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qmlproject +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qmlproject diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qrc b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qrc index deb0fba..2e52578 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qrc +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qrc @@ -1,5 +1,5 @@ <!DOCTYPE RCC><RCC version="1.0"> <qresource> - <file>layoutItem.qml</file> + <file>layoutitem.qml</file> </qresource> </RCC> diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/main.cpp index ef927d1..20a83e7 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/main.cpp +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/main.cpp @@ -64,7 +64,7 @@ int main(int argc, char* argv[]) //Add the QML snippet into the layout QDeclarativeEngine engine; - QDeclarativeComponent c(&engine, QUrl(":layoutItem.qml")); + QDeclarativeComponent c(&engine, QUrl(":layoutitem.qml")); QGraphicsLayoutItem* obj = qobject_cast<QGraphicsLayoutItem*>(c.create()); layout->addItem(obj); diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp new file mode 100644 index 0000000..b52305e --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "gridlayout.h" + +#include <QGraphicsWidget> +#include <QDebug> + +GridLayoutAttached::GridLayoutAttached(QObject *parent) +: QObject(parent), m_row(-1), m_column(-1), m_rowspan(1), m_colspan(1), m_alignment(-1), m_rowStretch(-1), + m_colStretch(-1), m_rowSpacing(-1), m_colSpacing(-1), m_rowPrefHeight(-1), m_rowMaxHeight(-1), m_rowMinHeight(-1), + m_rowFixHeight(-1), m_colPrefwidth(-1), m_colMaxwidth(-1), m_colMinwidth(-1), m_colFixwidth(-1) +{ +} + +void GridLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (m_alignment != a) { + m_alignment = a; + emit alignmentChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), m_alignment); + } +} + +QHash<QGraphicsLayoutItem*, GridLayoutAttached*> GraphicsGridLayoutObject::attachedProperties; + +GraphicsGridLayoutObject::GraphicsGridLayoutObject(QObject *parent) +: QObject(parent) +{ +} + +GraphicsGridLayoutObject::~GraphicsGridLayoutObject() +{ +} + +void GraphicsGridLayoutObject::addWidget(QGraphicsWidget *widget) +{ + //use attached properties + if (QObject *obj = attachedProperties.value(qobject_cast<QGraphicsLayoutItem*>(widget))) { + int row = static_cast<GridLayoutAttached *>(obj)->row(); + int column = static_cast<GridLayoutAttached *>(obj)->column(); + int rowSpan = static_cast<GridLayoutAttached *>(obj)->rowSpan(); + int columnSpan = static_cast<GridLayoutAttached *>(obj)->columnSpan(); + if (row == -1 || column == -1) { + qWarning() << "Must set row and column for an item in a grid layout"; + return; + } + addItem(widget, row, column, rowSpan, columnSpan); + } +} + +void GraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item) +{ + //use attached properties + if (GridLayoutAttached *obj = attachedProperties.value(item)) { + int row = obj->row(); + int column = obj->column(); + int rowSpan = obj->rowSpan(); + int columnSpan = obj->columnSpan(); + Qt::Alignment alignment = obj->alignment(); + + if (row == -1 || column == -1) { + qWarning() << "Must set row and column for an item in a grid layout"; + return; + } + + if (obj->rowSpacing() != -1) + setRowSpacing(row, obj->rowSpacing()); + if (obj->columnSpacing() != -1) + setColumnSpacing(column, obj->columnSpacing()); + if (obj->rowStretchFactor() != -1) + setRowStretchFactor(row, obj->rowStretchFactor()); + if (obj->columnStretchFactor() != -1) + setColumnStretchFactor(column, obj->columnStretchFactor()); + if (obj->rowPreferredHeight() != -1) + setRowPreferredHeight(row, obj->rowPreferredHeight()); + if (obj->rowMaximumHeight() != -1) + setRowMaximumHeight(row, obj->rowMaximumHeight()); + if (obj->rowMinimumHeight() != -1) + setRowMinimumHeight(row, obj->rowMinimumHeight()); + if (obj->rowFixedHeight() != -1) + setRowFixedHeight(row, obj->rowFixedHeight()); + if (obj->columnPreferredWidth() != -1) + setColumnPreferredWidth(row, obj->columnPreferredWidth()); + if (obj->columnMaximumWidth() != -1) + setColumnMaximumWidth(row, obj->columnMaximumWidth()); + if (obj->columnMinimumWidth() != -1) + setColumnMinimumWidth(row, obj->columnMinimumWidth()); + if (obj->columnFixedWidth() != -1) + setColumnFixedWidth(row, obj->columnFixedWidth()); + + addItem(item, row, column, rowSpan, columnSpan); + + if (alignment != -1) + setAlignment(item, alignment); + QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*, Qt::Alignment)), + this, SLOT(updateAlignment(QGraphicsLayoutItem*, Qt::Alignment))); + } +} + +void GraphicsGridLayoutObject::removeAt(int index) +{ + QGraphicsLayoutItem *item = itemAt(index); + if (item) { + GridLayoutAttached *obj = attachedProperties.value(item); + obj->disconnect(this); + attachedProperties.remove(item); + } + QGraphicsGridLayout::removeAt(index); +} + +void GraphicsGridLayoutObject::clearChildren() +{ + // do not delete the removed items; they will be deleted by the QML engine + while (count() > 0) + removeAt(count()-1); +} + +qreal GraphicsGridLayoutObject::spacing() const +{ + if (verticalSpacing() == horizontalSpacing()) + return verticalSpacing(); + return -1; +} + +qreal GraphicsGridLayoutObject::contentsMargin() const +{ + qreal a, b, c, d; + getContentsMargins(&a, &b, &c, &d); + if (a == b && a == c && a == d) + return a; + return -1; +} + +void GraphicsGridLayoutObject::setContentsMargin(qreal m) +{ + setContentsMargins(m, m, m, m); +} + +void GraphicsGridLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) +{ + QGraphicsGridLayout::setAlignment(item, alignment); +} + +GridLayoutAttached *GraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) +{ + GridLayoutAttached *rv = new GridLayoutAttached(obj); + if (qobject_cast<QGraphicsLayoutItem*>(obj)) + attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv); + return rv; +} + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h new file mode 100644 index 0000000..ca2cedc --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h @@ -0,0 +1,217 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GRIDLAYOUT_H +#define GRIDLAYOUT_H + +#include <qdeclarative.h> + +#include <QGraphicsGridLayout> +#include <QGraphicsLayoutItem> + +class GridLayoutAttached; +class GraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QDeclarativeListProperty<QGraphicsLayoutItem> children READ children) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) + Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing) + Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing) + Q_CLASSINFO("DefaultProperty", "children") + +public: + GraphicsGridLayoutObject(QObject * = 0); + ~GraphicsGridLayoutObject(); + + QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); } + + qreal spacing() const; + qreal contentsMargin() const; + void setContentsMargin(qreal); + + void removeAt(int index); + + static GridLayoutAttached *qmlAttachedProperties(QObject *); + +private slots: + void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); + +private: + friend class GraphicsLayoutAttached; + + void addWidget(QGraphicsWidget *); + void clearChildren(); + void addLayoutItem(QGraphicsLayoutItem *); + + static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) { + static_cast<GraphicsGridLayoutObject*>(prop->object)->addLayoutItem(item); + } + + static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { + static_cast<GraphicsGridLayoutObject*>(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { + return static_cast<GraphicsGridLayoutObject*>(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) { + return static_cast<GraphicsGridLayoutObject*>(prop->object)->itemAt(index); + } + + static QHash<QGraphicsLayoutItem*, GridLayoutAttached*> attachedProperties; +}; + + +class GridLayoutAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int row READ row WRITE setRow) + Q_PROPERTY(int column READ column WRITE setColumn) + + Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan) + Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) + + Q_PROPERTY(int rowStretchFactor READ rowStretchFactor WRITE setRowStretchFactor) + Q_PROPERTY(int columnStretchFactor READ columnStretchFactor WRITE setColumnStretchFactor) + Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing) + Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing) + + Q_PROPERTY(int rowPreferredHeight READ rowPreferredHeight WRITE setRowPreferredHeight) + Q_PROPERTY(int rowMinimumHeight READ rowMinimumHeight WRITE setRowMinimumHeight) + Q_PROPERTY(int rowMaximumHeight READ rowMaximumHeight WRITE setRowMaximumHeight) + Q_PROPERTY(int rowFixedHeight READ rowFixedHeight WRITE setRowFixedHeight) + + Q_PROPERTY(int columnPreferredWidth READ columnPreferredWidth WRITE setColumnPreferredWidth) + Q_PROPERTY(int columnMaximumWidth READ columnMaximumWidth WRITE setColumnMaximumWidth) + Q_PROPERTY(int columnMinimumWidth READ columnMinimumWidth WRITE setColumnMinimumWidth) + Q_PROPERTY(int columnFixedWidth READ columnFixedWidth WRITE setColumnFixedWidth) + +public: + GridLayoutAttached(QObject *parent); + + int row() const { return m_row; } + void setRow(int r) { m_row = r; } + + int column() const { return m_column; } + void setColumn(int c) { m_column = c; } + + int rowSpan() const { return m_rowspan; } + void setRowSpan(int rs) { m_rowspan = rs; } + + int columnSpan() const { return m_colspan; } + void setColumnSpan(int cs) { m_colspan = cs; } + + Qt::Alignment alignment() const { return m_alignment; } + void setAlignment(Qt::Alignment a); + + int rowStretchFactor() const { return m_rowStretch; } + void setRowStretchFactor(int f) { m_rowStretch = f; } + int columnStretchFactor() const { return m_colStretch; } + void setColumnStretchFactor(int f) { m_colStretch = f; } + + int rowSpacing() const { return m_rowSpacing; } + void setRowSpacing(int s) { m_rowSpacing = s; } + int columnSpacing() const { return m_colSpacing; } + void setColumnSpacing(int s) { m_colSpacing = s; } + + int rowPreferredHeight() const { return m_rowPrefHeight; } + void setRowPreferredHeight(int s) { m_rowPrefHeight = s; } + + int rowMaximumHeight() const { return m_rowMaxHeight; } + void setRowMaximumHeight(int s) { m_rowMaxHeight = s; } + + int rowMinimumHeight() const { return m_rowMinHeight; } + void setRowMinimumHeight(int s) { m_rowMinHeight = s; } + + int rowFixedHeight() const { return m_rowFixHeight; } + void setRowFixedHeight(int s) { m_rowFixHeight = s; } + + int columnPreferredWidth() const { return m_colPrefwidth; } + void setColumnPreferredWidth(int s) { m_colPrefwidth = s; } + + int columnMaximumWidth() const { return m_colMaxwidth; } + void setColumnMaximumWidth(int s) { m_colMaxwidth = s; } + + int columnMinimumWidth() const { return m_colMinwidth; } + void setColumnMinimumWidth(int s) { m_colMinwidth = s; } + + int columnFixedWidth() const { return m_colFixwidth; } + void setColumnFixedWidth(int s) { m_colFixwidth = s; } + +signals: + void alignmentChanged(QGraphicsLayoutItem*, Qt::Alignment); + +private: + int m_row; + int m_column; + + int m_rowspan; + int m_colspan; + Qt::Alignment m_alignment; + + int m_rowStretch; + int m_colStretch; + int m_rowSpacing; + int m_colSpacing; + + int m_rowPrefHeight; + int m_rowMaxHeight; + int m_rowMinHeight; + int m_rowFixHeight; + + int m_colPrefwidth; + int m_colMaxwidth; + int m_colMinwidth; + int m_colFixwidth; +}; + +QML_DECLARE_INTERFACE(QGraphicsLayoutItem) +QML_DECLARE_INTERFACE(QGraphicsLayout) +QML_DECLARE_TYPE(GraphicsGridLayoutObject) +QML_DECLARE_TYPEINFO(GraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES) + +#endif + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qrc b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.qrc index a199f8d..bdf8312 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qrc +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.qrc @@ -1,5 +1,6 @@ <!DOCTYPE RCC><RCC version="1.0"> <qresource> - <file>graphicslayouts.qml</file> + <file>qgraphicsgridlayout.qml</file> </qresource> </RCC> + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/main.cpp index b0a15fc..6525cb3 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/main.cpp +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/main.cpp @@ -38,22 +38,26 @@ ** ****************************************************************************/ +#include "gridlayout.h" + +#include <qdeclarative.h> +#include <QDeclarativeView> + #include <QApplication> -#include <QtDeclarative/qdeclarative.h> -#include "graphicslayouts_p.h" -#include <QtDeclarative/QDeclarativeView> int main(int argc, char* argv[]) { QApplication app(argc, argv); - QDeclarativeView view; + qmlRegisterInterface<QGraphicsLayoutItem>("QGraphicsLayoutItem"); qmlRegisterInterface<QGraphicsLayout>("QGraphicsLayout"); - qmlRegisterType<QGraphicsLinearLayoutStretchItemObject>("GraphicsLayouts",4,7,"QGraphicsLinearLayoutStretchItem"); - qmlRegisterType<QGraphicsLinearLayoutObject>("GraphicsLayouts",4,7,"QGraphicsLinearLayout"); - qmlRegisterType<QGraphicsGridLayoutObject>("GraphicsLayouts",4,7,"QGraphicsGridLayout"); - view.setSource(QUrl(":graphicslayouts.qml")); + qmlRegisterType<GraphicsGridLayoutObject>("GridLayouts", 4, 7, "GraphicsGridLayout"); + + QDeclarativeView view; + view.setSource(QUrl(":qgraphicsgridlayout.qml")); view.show(); + return app.exec(); }; + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.pro b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.pro new file mode 100644 index 0000000..ae6373d --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.pro @@ -0,0 +1,15 @@ +TEMPLATE = app +TARGET = qgraphicsgridlayout +QT += declarative + +SOURCES += \ + gridlayout.cpp \ + main.cpp + +HEADERS += \ + gridlayout.h + +RESOURCES += \ + gridlayout.qrc + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qml b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml index 586f7f9..50026f1 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qml +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml @@ -39,79 +39,62 @@ ****************************************************************************/ import Qt 4.7 -import GraphicsLayouts 4.7 +import GridLayouts 4.7 Item { - id: resizable - - width: 800 + width: 400 height: 400 QGraphicsWidget { - size.width: parent.width/2 + size.width: parent.width size.height: parent.height - layout: QGraphicsLinearLayout { - LayoutItem { - minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "100x100" - Rectangle { color: "yellow"; anchors.fill: parent } - } - LayoutItem { - minimumSize: "100x100" - maximumSize: "400x400" - preferredSize: "200x200" - Rectangle { color: "green"; anchors.fill: parent } - } - } - } - QGraphicsWidget { - x: parent.width/2 - size.width: parent.width/2 - size.height: parent.height + /* + Below we create a grid layout using the GraphicsGridLayout item + (defined by the GraphicsGridLayoutObject class in gridlayout.h). - layout: QGraphicsGridLayout { + The row, column etc. are set through attached properties on + GraphicsGridLayout, using the properties defined in the + GridLayoutAttached class (also defined in gridlayout.h). + */ + + layout: GraphicsGridLayout { LayoutItem { - QGraphicsGridLayout.row: 0 - QGraphicsGridLayout.column: 0 + GraphicsGridLayout.row: 0 + GraphicsGridLayout.column: 0 minimumSize: "100x100" maximumSize: "300x300" - preferredSize: "100x100" + preferredSize: "200x200" Rectangle { color: "red"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 1 - QGraphicsGridLayout.column: 0 + GraphicsGridLayout.row: 0 + GraphicsGridLayout.column: 1 minimumSize: "100x100" maximumSize: "200x200" - preferredSize: "100x100" + preferredSize: "200x200" Rectangle { color: "orange"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 2 - QGraphicsGridLayout.column: 0 + GraphicsGridLayout.row: 1 + GraphicsGridLayout.column: 0 + GraphicsGridLayout.columnSpan: 2 minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "200x200" Rectangle { color: "yellow"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 0 - QGraphicsGridLayout.column: 1 - minimumSize: "100x100" - maximumSize: "200x200" + GraphicsGridLayout.row: 2 + GraphicsGridLayout.column: 0 preferredSize: "200x200" Rectangle { color: "green"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 1 - QGraphicsGridLayout.column: 1 - minimumSize: "100x100" - maximumSize: "400x400" + GraphicsGridLayout.row: 2 + GraphicsGridLayout.column: 1 preferredSize: "200x200" Rectangle { color: "blue"; anchors.fill: parent } } } } } + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslayouts.pro b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslayouts.pro index d92a6f4..672120a 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslayouts.pro +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslayouts.pro @@ -1,5 +1,6 @@ TEMPLATE = subdirs SUBDIRS += \ - graphicsLayouts \ - layoutItem + layoutitem \ + qgraphicsgridlayout \ + qgraphicslinearlayout diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp new file mode 100644 index 0000000..d0e9783 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "linearlayout.h" + +#include <QGraphicsWidget> +#include <QGraphicsLayoutItem> + +LinearLayoutAttached::LinearLayoutAttached(QObject *parent) +: QObject(parent), m_stretch(1), m_alignment(Qt::AlignTop), m_spacing(0) +{ +} + +void LinearLayoutAttached::setStretchFactor(int f) +{ + if (m_stretch != f) { + m_stretch = f; + emit stretchChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), m_stretch); + } +} + +void LinearLayoutAttached::setSpacing(int s) +{ + if (m_spacing != s) { + m_spacing = s; + emit spacingChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), m_spacing); + } +} + +void LinearLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (m_alignment != a) { + m_alignment = a; + emit alignmentChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), m_alignment); + } +} + +GraphicsLinearLayoutStretchItemObject::GraphicsLinearLayoutStretchItemObject(QObject *parent) + : QObject(parent) +{ +} + +QSizeF GraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +{ + Q_UNUSED(which); + Q_UNUSED(constraint); + return QSizeF(); +} + + +GraphicsLinearLayoutObject::GraphicsLinearLayoutObject(QObject *parent) +: QObject(parent) +{ +} + +GraphicsLinearLayoutObject::~GraphicsLinearLayoutObject() +{ +} + +void GraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutItem *item) +{ + insertItem(index, item); + + if (LinearLayoutAttached *obj = attachedProperties.value(item)) { + setStretchFactor(item, obj->stretchFactor()); + setAlignment(item, obj->alignment()); + updateSpacing(item, obj->spacing()); + QObject::connect(obj, SIGNAL(stretchChanged(QGraphicsLayoutItem*,int)), + this, SLOT(updateStretch(QGraphicsLayoutItem*,int))); + QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)), + this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); + QObject::connect(obj, SIGNAL(spacingChanged(QGraphicsLayoutItem*,int)), + this, SLOT(updateSpacing(QGraphicsLayoutItem*,int))); + } +} + +void GraphicsLinearLayoutObject::removeAt(int index) +{ + QGraphicsLayoutItem *item = itemAt(index); + if (item) { + LinearLayoutAttached *obj = attachedProperties.value(item); + obj->disconnect(this); + attachedProperties.remove(item); + } + QGraphicsLinearLayout::removeAt(index); +} + +void GraphicsLinearLayoutObject::clearChildren() +{ + // do not delete the removed items; they will be deleted by the QML engine + while (count() > 0) + removeAt(count()-1); +} + +qreal GraphicsLinearLayoutObject::contentsMargin() const +{ + qreal a, b, c, d; + getContentsMargins(&a, &b, &c, &d); + if (a == b && a == c && a == d) + return a; + return -1; +} + +void GraphicsLinearLayoutObject::setContentsMargin(qreal m) +{ + setContentsMargins(m, m, m, m); +} + +void GraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) +{ + QGraphicsLinearLayout::setStretchFactor(item, stretch); +} + +void GraphicsLinearLayoutObject::updateSpacing(QGraphicsLayoutItem* item, int spacing) +{ + for (int i=0; i < count(); i++){ + if (itemAt(i) == item) { + QGraphicsLinearLayout::setItemSpacing(i, spacing); + return; + } + } +} + +void GraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) +{ + QGraphicsLinearLayout::setAlignment(item, alignment); +} + +QHash<QGraphicsLayoutItem*, LinearLayoutAttached*> GraphicsLinearLayoutObject::attachedProperties; +LinearLayoutAttached *GraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) +{ + LinearLayoutAttached *rv = new LinearLayoutAttached(obj); + if (qobject_cast<QGraphicsLayoutItem*>(obj)) + attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv); + return rv; +} + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h new file mode 100644 index 0000000..d9391ca --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h @@ -0,0 +1,152 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LINEARLAYOUT_H +#define LINEARLAYOUT_H + +#include <qdeclarative.h> + +#include <QGraphicsLinearLayout> +#include <QGraphicsLayoutItem> + +class GraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayoutItem) +public: + GraphicsLinearLayoutStretchItemObject(QObject *parent = 0); + + virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const; +}; + + +class LinearLayoutAttached; +class GraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QDeclarativeListProperty<QGraphicsLayoutItem> children READ children) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) + Q_CLASSINFO("DefaultProperty", "children") +public: + GraphicsLinearLayoutObject(QObject * = 0); + ~GraphicsLinearLayoutObject(); + + QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); } + + qreal contentsMargin() const; + void setContentsMargin(qreal); + + void removeAt(int index); + + static LinearLayoutAttached *qmlAttachedProperties(QObject *); + +private slots: + void updateStretch(QGraphicsLayoutItem*,int); + void updateSpacing(QGraphicsLayoutItem*,int); + void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); + +private: + friend class LinearLayoutAttached; + + void clearChildren(); + void insertLayoutItem(int, QGraphicsLayoutItem *); + + static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) { + static_cast<GraphicsLinearLayoutObject*>(prop->object)->insertLayoutItem(-1, item); + } + + static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { + static_cast<GraphicsLinearLayoutObject*>(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { + return static_cast<GraphicsLinearLayoutObject*>(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) { + return static_cast<GraphicsLinearLayoutObject*>(prop->object)->itemAt(index); + } + + static QHash<QGraphicsLayoutItem*, LinearLayoutAttached*> attachedProperties; +}; + + +class LinearLayoutAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int stretchFactor READ stretchFactor WRITE setStretchFactor NOTIFY stretchChanged) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) + Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) + +public: + LinearLayoutAttached(QObject *parent); + + int stretchFactor() const { return m_stretch; } + void setStretchFactor(int f); + Qt::Alignment alignment() const { return m_alignment; } + void setAlignment(Qt::Alignment a); + int spacing() const { return m_spacing; } + void setSpacing(int s); + +signals: + void stretchChanged(QGraphicsLayoutItem*, int); + void alignmentChanged(QGraphicsLayoutItem*, Qt::Alignment); + void spacingChanged(QGraphicsLayoutItem*, int); + +private: + int m_stretch; + Qt::Alignment m_alignment; + int m_spacing; +}; + +QML_DECLARE_INTERFACE(QGraphicsLayoutItem) +QML_DECLARE_INTERFACE(QGraphicsLayout) +QML_DECLARE_TYPE(GraphicsLinearLayoutStretchItemObject) +QML_DECLARE_TYPE(GraphicsLinearLayoutObject) +QML_DECLARE_TYPEINFO(GraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES) + +#endif + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.qrc b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.qrc new file mode 100644 index 0000000..93a3533 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>qgraphicslinearlayout.qml</file> +</qresource> +</RCC> + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp new file mode 100644 index 0000000..f8d08c2 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "linearlayout.h" + +#include <qdeclarative.h> +#include <QDeclarativeView> + +#include <QApplication> + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + + qmlRegisterInterface<QGraphicsLayoutItem>("QGraphicsLayoutItem"); + qmlRegisterInterface<QGraphicsLayout>("QGraphicsLayout"); + qmlRegisterType<GraphicsLinearLayoutStretchItemObject>("LinearLayouts", 4, 7, "GraphicsLinearLayoutStretchItem"); + qmlRegisterType<GraphicsLinearLayoutObject>("LinearLayouts", 4, 7, "GraphicsLinearLayout"); + + QDeclarativeView view; + view.setSource(QUrl(":qgraphicslinearlayout.qml")); + view.show(); + + return app.exec(); +}; + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.pro b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.pro new file mode 100644 index 0000000..79eb6ff --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.pro @@ -0,0 +1,15 @@ +TEMPLATE = app +TARGET = qgraphicslinearlayout +QT += declarative + +SOURCES += \ + linearlayout.cpp \ + main.cpp + +HEADERS += \ + linearlayout.h + +RESOURCES += \ + linearlayout.qrc + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml new file mode 100644 index 0000000..9a0bd55 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 +import LinearLayouts 4.7 + +Item { + width: 400 + height: 400 + + QGraphicsWidget { + size.width: parent.width + size.height: parent.height + + /* + Below we create a linear layout using the GraphicsLinearLayout item + (defined by the GraphicsLinearLayoutObject class in linearlayout.h). + + The first LayoutItem uses 'GraphicsLinearLayout.spacing' to set the + item's spacing: this is an attached property, set using the + properties defined in the LinearLayoutAttached class (also defined + in linearlayout.h). + */ + + layout: GraphicsLinearLayout { + LayoutItem { + GraphicsLinearLayout.spacing: 50 + minimumSize: "100x100" + maximumSize: "200x200" + preferredSize: "100x100" + Rectangle { color: "yellow"; anchors.fill: parent } + } + LayoutItem { + minimumSize: "100x100" + maximumSize: "400x400" + preferredSize: "300x300" + Rectangle { color: "green"; anchors.fill: parent } + } + } + } +} + diff --git a/examples/declarative/text/edit/edit.qml b/examples/declarative/text/edit/edit.qml new file mode 100644 index 0000000..2774739 --- /dev/null +++ b/examples/declarative/text/edit/edit.qml @@ -0,0 +1,248 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import Qt 4.7 + +Rectangle { + id: editor + color: "lightGrey" + width: 640; height: 480 + + Rectangle { + color: "white" + anchors.fill: parent + anchors.margins: 20 + + BorderImage { + id: startHandle + source: "pics/startHandle.sci" + opacity: 0.0 + width: 10 + x: edit.positionToRectangle(edit.selectionStart).x-flick.contentX-width + y: edit.positionToRectangle(edit.selectionStart).y-flick.contentY + height: edit.positionToRectangle(edit.selectionStart).height + } + + BorderImage { + id: endHandle + source: "pics/endHandle.sci" + opacity: 0.0 + width: 10 + x: edit.positionToRectangle(edit.selectionEnd).x-flick.contentX + y: edit.positionToRectangle(edit.selectionEnd).y-flick.contentY + height: edit.positionToRectangle(edit.selectionEnd).height + } + + Flickable { + id: flick + + anchors.fill: parent + contentWidth: edit.paintedWidth + contentHeight: edit.paintedHeight + interactive: true + clip: true + + function ensureVisible(r) + { + if (contentX >= r.x) + contentX = r.x; + else if (contentX+width <= r.x+r.width) + contentX = r.x+r.width-width; + if (contentY >= r.y) + contentY = r.y; + else if (contentY+height <= r.y+r.height) + contentY = r.y+r.height-height; + } + + TextEdit { + id: edit + width: flick.width + height: flick.height + focus: true + wrapMode: TextEdit.Wrap + onCursorRectangleChanged: flick.ensureVisible(cursorRectangle) + text: "<h1>Text Selection</h1>" + +"<p>This example is a whacky text selection mechanisms, showing how these can be implemented in the TextEdit element, to cater for whatever style is appropriate for the target platform." + +"<p><b>Press-and-hold</b> to select a word, then drag the selection handles." + +"<p><b>Drag outside the selection</b> to scroll the text." + +"<p><b>Click inside the selection</b> to cut/copy/paste/cancel selection." + +"<p>It's too whacky to let you paste if there is no current selection." + MouseArea { + x: -startHandle.width + y: 0 + width: parent.width+startHandle.width+endHandle.width + height: parent.height + property string drag: ""; + property int pressPos; + onPressAndHold: { + if (editor.state == "") { + edit.cursorPosition = edit.positionAt(mouse.x+x,mouse.y+y); + edit.selectWord(); + editor.state = "selection" + } + } + onClicked: { + if (editor.state == "") { + edit.cursorPosition = edit.positionAt(mouse.x+x,mouse.y+y); + } + } + function hitHandle(h,x,y) { return x>=h.x+flick.contentX && x<h.x+flick.contentX+h.width && y>=h.y+flick.contentY && y<h.y+flick.contentY+h.height } + onPressed: { + if (editor.state == "selection") { + if (hitHandle(startHandle,mouse.x+x,mouse.y+y)) { + drag = "start" + flick.interactive = false + } else if (hitHandle(endHandle,mouse.x+x,mouse.y+y)) { + drag = "end" + flick.interactive = false + } else { + var pos = edit.positionAt(mouse.x+x,mouse.y+y); + if (pos >= edit.selectionStart && pos <= edit.selectionEnd) { + drag = "selection" + flick.interactive = false + } else { + drag = "" + flick.interactive = true + } + } + } + } + onReleased: { + if (editor.state == "selection") { + if (drag == "selection") { + editor.state = "menu" + } + drag = "" + } + flick.interactive = true + } + onPositionChanged: { + if (editor.state == "selection" && drag != "") { + if (drag == "start") { + var pos = edit.positionAt(mouse.x+x+startHandle.width/2,mouse.y+y); + if (edit.selectionEnd < pos) + edit.selectionEnd = pos; + edit.selectionStart = pos; + } else if (drag == "end") { + var pos = edit.positionAt(mouse.x+x-endHandle.width/2,mouse.y+y); + if (edit.selectionStart > pos) + edit.selectionStart = pos; + edit.selectionEnd = pos; + } + } + } + } + } + } + + Item { + id: menu + opacity: 0.0 + width: 100 + height: 120 + anchors.centerIn: parent + Rectangle { + border.width: 1 + border.color: "darkBlue" + radius: 15 + color: "#806080FF" + anchors.fill: parent + } + Column { + anchors.centerIn: parent + spacing: 8 + Rectangle { + border.width: 1 + border.color: "darkBlue" + color: "#ff7090FF" + width: 60 + height: 16 + Text { anchors.centerIn: parent; text: "Cut" } + MouseArea { anchors.fill: parent; + onClicked: { edit.cut(); editor.state = "" } } + } + Rectangle { + border.width: 1 + border.color: "darkBlue" + color: "#ff7090FF" + width: 60 + height: 16 + Text { anchors.centerIn: parent; text: "Copy" } + MouseArea { anchors.fill: parent; + onClicked: { edit.copy(); editor.state = "selection" } } + } + Rectangle { + border.width: 1 + border.color: "darkBlue" + color: "#ff7090FF" + width: 60 + height: 16 + Text { anchors.centerIn: parent; text: "Paste" } + MouseArea { anchors.fill: parent; + onClicked: { edit.paste(); edit.cursorPosition = edit.selectionEnd; editor.state = "" } } + } + Rectangle { + border.width: 1 + border.color: "darkBlue" + color: "#ff7090FF" + width: 60 + height: 16 + Text { anchors.centerIn: parent; text: "Deselect" } + MouseArea { anchors.fill: parent; + onClicked: { edit.cursorPosition = edit.selectionEnd; edit.selectionStart = edit.selectionEnd; editor.state = "" } } + } + } + } + } + + states: [ + State { + name: "selection" + PropertyChanges { target: startHandle; opacity: 1.0 } + PropertyChanges { target: endHandle; opacity: 1.0 } + }, + State { + name: "menu" + PropertyChanges { target: startHandle; opacity: 0.5 } + PropertyChanges { target: endHandle; opacity: 0.5 } + PropertyChanges { target: menu; opacity: 1.0 } + } + ] +} diff --git a/examples/declarative/text/edit/pics/endHandle.png b/examples/declarative/text/edit/pics/endHandle.png Binary files differnew file mode 100644 index 0000000..1a4bc5d --- /dev/null +++ b/examples/declarative/text/edit/pics/endHandle.png diff --git a/examples/declarative/text/edit/pics/endHandle.sci b/examples/declarative/text/edit/pics/endHandle.sci new file mode 100644 index 0000000..4f51f24 --- /dev/null +++ b/examples/declarative/text/edit/pics/endHandle.sci @@ -0,0 +1,5 @@ +border.left: 0 +border.top: 6 +border.bottom: 6 +border.right: 6 +source: endHandle.png diff --git a/examples/declarative/text/edit/pics/startHandle.png b/examples/declarative/text/edit/pics/startHandle.png Binary files differnew file mode 100644 index 0000000..deedcd5 --- /dev/null +++ b/examples/declarative/text/edit/pics/startHandle.png diff --git a/examples/declarative/text/edit/pics/startHandle.sci b/examples/declarative/text/edit/pics/startHandle.sci new file mode 100644 index 0000000..f9eae20 --- /dev/null +++ b/examples/declarative/text/edit/pics/startHandle.sci @@ -0,0 +1,5 @@ +border.left: 6 +border.top: 6 +border.bottom: 6 +border.right: 0 +source: startHandle.png diff --git a/examples/itemviews/fetchmore/filelistmodel.cpp b/examples/itemviews/fetchmore/filelistmodel.cpp index 05ab45e..942150e 100644 --- a/examples/itemviews/fetchmore/filelistmodel.cpp +++ b/examples/itemviews/fetchmore/filelistmodel.cpp @@ -92,7 +92,7 @@ void FileListModel::fetchMore(const QModelIndex & /* index */) int remainder = fileList.size() - fileCount; int itemsToFetch = qMin(100, remainder); - beginInsertRows(QModelIndex(), fileCount, fileCount+itemsToFetch); + beginInsertRows(QModelIndex(), fileCount, fileCount+itemsToFetch-1); fileCount += itemsToFetch; diff --git a/src/corelib/global/qfeatures.h b/src/corelib/global/qfeatures.h index c66047a..a333153 100644 --- a/src/corelib/global/qfeatures.h +++ b/src/corelib/global/qfeatures.h @@ -335,11 +335,6 @@ #define QT_NO_DATESTRING #endif -// QtDBus module -#if !defined(QT_NO_DBUS) && (defined(QT_NO_PROPERTIES)) -#define QT_NO_DBUS -#endif - // QDial #if !defined(QT_NO_DIAL) && (defined(QT_NO_SLIDER)) #define QT_NO_DIAL @@ -515,6 +510,11 @@ #define QT_NO_CONTEXTMENU #endif +// QtDBus module +#if !defined(QT_NO_DBUS) && (defined(QT_NO_PROPERTIES) || defined(QT_NO_DOM)) +#define QT_NO_DBUS +#endif + // File Transfer Protocol #if !defined(QT_NO_FTP) && (defined(QT_NO_URLINFO) || defined(QT_NO_TEXTDATE)) #define QT_NO_FTP diff --git a/src/corelib/global/qfeatures.txt b/src/corelib/global/qfeatures.txt index ed173b1..3e6af24 100644 --- a/src/corelib/global/qfeatures.txt +++ b/src/corelib/global/qfeatures.txt @@ -1373,7 +1373,7 @@ SeeAlso: ??? Feature: DBUS Description: Provides classes for D-Bus. Section: D-Bus -Requires: PROPERTIES +Requires: PROPERTIES DOM Name: QtDBus module SeeAlso: ??? diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp index ae12007..853f311 100644 --- a/src/corelib/xml/qxmlstream.cpp +++ b/src/corelib/xml/qxmlstream.cpp @@ -560,7 +560,7 @@ void QXmlStreamReader::clear() chunk of XML can be added with addData(), if the XML is being read from a QByteArray, or by waiting for more data to arrive if the XML is being read from a QIODevice. Either way, atEnd() will - return false once more adata is available. + return false once more data is available. \sa hasError(), error(), device(), QIODevice::atEnd() */ diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 142920c..0df5f10 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -14,6 +14,8 @@ Component: status property instead - errorsString() renamed to errorString() +TextInput xToPosition -> positionAt (to match TextEdit.positionAt) + QList<QObject*> models no longer provide properties in model object. The properties are now updated when the object changes. An object's property "foo" may now be accessed as "foo", modelData.foo" or model.modelData.foo" diff --git a/src/declarative/debugger/debugger.pri b/src/declarative/debugger/debugger.pri index 6777868..33d0843 100644 --- a/src/declarative/debugger/debugger.pri +++ b/src/declarative/debugger/debugger.pri @@ -6,7 +6,7 @@ SOURCES += \ $$PWD/qdeclarativedebugservice.cpp \ $$PWD/qdeclarativedebugclient.cpp \ $$PWD/qdeclarativedebug.cpp \ - $$PWD/qdeclarativedebugtiming.cpp + $$PWD/qdeclarativedebugtrace.cpp HEADERS += \ $$PWD/qdeclarativedebuggerstatus_p.h \ @@ -14,4 +14,4 @@ HEADERS += \ $$PWD/qdeclarativedebugservice_p.h \ $$PWD/qdeclarativedebugclient_p.h \ $$PWD/qdeclarativedebug_p.h \ - $$PWD/qdeclarativedebugtiming_p.h + $$PWD/qdeclarativedebugtrace_p.h diff --git a/src/declarative/debugger/qdeclarativedebugtiming.cpp b/src/declarative/debugger/qdeclarativedebugtrace.cpp index 5b93852..5e6d5e7 100644 --- a/src/declarative/debugger/qdeclarativedebugtiming.cpp +++ b/src/declarative/debugger/qdeclarativedebugtrace.cpp @@ -39,37 +39,44 @@ ** ****************************************************************************/ -#include "qdeclarativedebugtiming_p.h" +#include "qdeclarativedebugtrace_p.h" #include <QtCore/qdatastream.h> +#include <QtCore/qurl.h> -Q_GLOBAL_STATIC(QDeclarativeDebugTiming, timerInstance); +Q_GLOBAL_STATIC(QDeclarativeDebugTrace, traceInstance); -QDeclarativeDebugTiming::QDeclarativeDebugTiming() +QDeclarativeDebugTrace::QDeclarativeDebugTrace() : QDeclarativeDebugService(QLatin1String("CanvasFrameRate")) { m_timer.start(); } -void QDeclarativeDebugTiming::addEvent(EventType t) +void QDeclarativeDebugTrace::addEvent(EventType t) { if (QDeclarativeDebugService::isDebuggingEnabled()) - timerInstance()->addEventImpl(t); + traceInstance()->addEventImpl(t); } -void QDeclarativeDebugTiming::startRange(RangeType t) +void QDeclarativeDebugTrace::startRange(RangeType t) { if (QDeclarativeDebugService::isDebuggingEnabled()) - timerInstance()->startRangeImpl(t); + traceInstance()->startRangeImpl(t); } -void QDeclarativeDebugTiming::endRange(RangeType t) +void QDeclarativeDebugTrace::rangeData(RangeType t, const QUrl &url) { if (QDeclarativeDebugService::isDebuggingEnabled()) - timerInstance()->endRangeImpl(t); + traceInstance()->rangeDataImpl(t, url); } -void QDeclarativeDebugTiming::addEventImpl(EventType event) +void QDeclarativeDebugTrace::endRange(RangeType t) +{ + if (QDeclarativeDebugService::isDebuggingEnabled()) + traceInstance()->endRangeImpl(t); +} + +void QDeclarativeDebugTrace::addEventImpl(EventType event) { QByteArray data; QDataStream ds(&data, QIODevice::WriteOnly); @@ -77,7 +84,7 @@ void QDeclarativeDebugTiming::addEventImpl(EventType event) sendMessage(data); } -void QDeclarativeDebugTiming::startRangeImpl(RangeType range) +void QDeclarativeDebugTrace::startRangeImpl(RangeType range) { QByteArray data; QDataStream ds(&data, QIODevice::WriteOnly); @@ -85,7 +92,15 @@ void QDeclarativeDebugTiming::startRangeImpl(RangeType range) sendMessage(data); } -void QDeclarativeDebugTiming::endRangeImpl(RangeType range) +void QDeclarativeDebugTrace::rangeDataImpl(RangeType range, const QUrl &u) +{ + QByteArray data; + QDataStream ds(&data, QIODevice::WriteOnly); + ds << m_timer.elapsed() << (int)RangeData << (int)range << (QString)u.toString(); + sendMessage(data); +} + +void QDeclarativeDebugTrace::endRangeImpl(RangeType range) { QByteArray data; QDataStream ds(&data, QIODevice::WriteOnly); diff --git a/src/declarative/debugger/qdeclarativedebugtiming_p.h b/src/declarative/debugger/qdeclarativedebugtrace_p.h index d9ed67c..5ba49a8 100644 --- a/src/declarative/debugger/qdeclarativedebugtiming_p.h +++ b/src/declarative/debugger/qdeclarativedebugtrace_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QDECLARATIVEDEBUGTIMING_P_H -#define QDECLARATIVEDEBUGTIMING_P_H +#ifndef QDECLARATIVEDEBUGTRACE_P_H +#define QDECLARATIVEDEBUGTRACE_P_H #include <private/qdeclarativedebugservice_p.h> #include <QtCore/qelapsedtimer.h> @@ -49,7 +49,8 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QDeclarativeDebugTiming : public QDeclarativeDebugService +class QUrl; +class QDeclarativeDebugTrace : public QDeclarativeDebugService { public: enum EventType { @@ -63,6 +64,7 @@ public: enum Message { Event, RangeStart, + RangeData, RangeEnd, MaximumMessage @@ -77,13 +79,16 @@ public: }; static void addEvent(EventType); + static void startRange(RangeType); + static void rangeData(RangeType, const QUrl &); static void endRange(RangeType); - QDeclarativeDebugTiming(); + QDeclarativeDebugTrace(); private: void addEventImpl(EventType); void startRangeImpl(RangeType); + void rangeDataImpl(RangeType, const QUrl &); void endRangeImpl(RangeType); QElapsedTimer m_timer; }; @@ -92,5 +97,5 @@ QT_END_NAMESPACE QT_END_HEADER -#endif // QDECLARATIVEDEBUGTIMING_P_H +#endif // QDECLARATIVEDEBUGTRACE_P_H diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp index 32a6321..a05e426 100644 --- a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp @@ -263,7 +263,9 @@ void QDeclarativeAnimatedImage::movieRequestFinished() d->_movie = new QMovie(d->reply); if (!d->_movie->isValid()){ +#ifndef QT_NO_DEBUG_STREAM qmlInfo(this) << "Error Reading Animated Image File " << d->url; +#endif delete d->_movie; d->_movie = 0; return; diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 7bd08ce..134bd6d 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -3131,6 +3131,7 @@ bool QDeclarativeItem::event(QEvent *ev) return QGraphicsObject::event(ev); } +#ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, QDeclarativeItem *item) { if (!item) { @@ -3144,6 +3145,7 @@ QDebug operator<<(QDebug debug, QDeclarativeItem *item) << ", z =" << item->zValue() << ')'; return debug; } +#endif qint64 QDeclarativeItemPrivate::consistentTime = -1; void QDeclarativeItemPrivate::setConsistentTime(qint64 t) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h index 29fd241..77e316b 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.h +++ b/src/declarative/graphicsitems/qdeclarativeitem.h @@ -209,7 +209,9 @@ T qobject_cast(QGraphicsItem *item) return qobject_cast<T>(o); } +#ifndef QT_NO_DEBUG_STREAM QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QDeclarativeItem *item); +#endif QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp index 151a9e9..0be8dac 100644 --- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp @@ -112,9 +112,11 @@ void QDeclarativeItemModule::defineModule() qmlRegisterType<QDeclarativePathPercent>("Qt",4,7,"PathPercent"); qmlRegisterType<QDeclarativePathQuad>("Qt",4,7,"PathQuad"); qmlRegisterType<QDeclarativePathView>("Qt",4,7,"PathView"); +#ifndef QT_NO_VALIDATOR qmlRegisterType<QIntValidator>("Qt",4,7,"IntValidator"); qmlRegisterType<QDoubleValidator>("Qt",4,7,"DoubleValidator"); qmlRegisterType<QRegExpValidator>("Qt",4,7,"RegExpValidator"); +#endif qmlRegisterType<QDeclarativeRectangle>("Qt",4,7,"Rectangle"); qmlRegisterType<QDeclarativeRepeater>("Qt",4,7,"Repeater"); qmlRegisterType<QGraphicsRotation>("Qt",4,7,"Rotation"); @@ -138,7 +140,9 @@ void QDeclarativeItemModule::defineModule() qmlRegisterType<QDeclarativePathElement>(); qmlRegisterType<QDeclarativeCurve>(); qmlRegisterType<QDeclarativeScaleGrid>(); +#ifndef QT_NO_VALIDATOR qmlRegisterType<QValidator>(); +#endif qmlRegisterType<QDeclarativeVisualModel>(); #ifndef QT_NO_ACTION qmlRegisterType<QAction>(); diff --git a/src/declarative/graphicsitems/qdeclarativelayoutitem.cpp b/src/declarative/graphicsitems/qdeclarativelayoutitem.cpp index c8ecbb6..4add66d 100644 --- a/src/declarative/graphicsitems/qdeclarativelayoutitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativelayoutitem.cpp @@ -50,20 +50,21 @@ QT_BEGIN_NAMESPACE /*! \qmlclass LayoutItem QDeclarativeLayoutItem \since 4.7 - \brief The LayoutItem element allows you to place your declarative UI elements inside a classical Qt layout. + \brief The LayoutItem element allows declarative UI elements to be placed inside Qt's Graphics View layouts. - LayoutItem is a variant of Item with a couple of additional properties. These properties provide the size hints - needed for items to work in conjunction with Qt Layouts. The Qt Layout will resize the LayoutItem as appropriate, + LayoutItem is a variant of \l Item with additional size hint properties. These properties provide the size hints + necessary for items to work in conjunction with Qt \l{Graphics View Framework}{Graphics View} layout classes + such as QGraphicsLinearLayout and QGraphicsGridLayout. The Qt layout mechanisms will resize the LayoutItem as appropriate, taking its size hints into account, and you can propagate this to the other elements in your UI via anchors and bindings. - This is a QGraphicsLayoutItem subclass, and the properties merely expose the QGraphicsLayoutItem functionality to QML. + This is a QGraphicsLayoutItem subclass, and its properties merely expose the QGraphicsLayoutItem functionality to QML. See the QGraphicsLayoutItem documentation for further details. */ /*! \internal \class QDeclarativeLayoutItem - \brief The QDeclarativeLayoutItem class allows you to place your Fluid UI elements inside a classical Qt layout. + \brief The QDeclarativeLayoutItem class allows you to place your QML UI elements inside Qt's Graphics View layouts. */ diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp index 2d08c7c..141a938 100644 --- a/src/declarative/graphicsitems/qdeclarativepath.cpp +++ b/src/declarative/graphicsitems/qdeclarativepath.cpp @@ -867,6 +867,9 @@ qreal QDeclarativePathPercent::value() const void QDeclarativePathPercent::setValue(qreal value) { - _value = value; + if (_value != value) { + _value = value; + emit changed(); + } } QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativepath_p.h b/src/declarative/graphicsitems/qdeclarativepath_p.h index 17a2ea3..dad43e6 100644 --- a/src/declarative/graphicsitems/qdeclarativepath_p.h +++ b/src/declarative/graphicsitems/qdeclarativepath_p.h @@ -175,7 +175,7 @@ private: class Q_DECLARATIVE_EXPORT QDeclarativePathPercent : public QDeclarativePathElement { Q_OBJECT - Q_PROPERTY(qreal value READ value WRITE setValue) + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) public: QDeclarativePathPercent(QObject *parent=0) : QDeclarativePathElement(parent) {} diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 2c1eb67..55cef8b 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -318,7 +318,11 @@ void QDeclarativeText::setText(const QString &n) if (d->richText) { if (isComponentComplete()) { d->ensureDoc(); +#ifndef QT_NO_TEXTHTMLPARSER d->doc->setHtml(n); +#else + d->doc->setPlainText(n); +#endif } } @@ -605,7 +609,11 @@ void QDeclarativeText::setTextFormat(TextFormat format) } else if (!wasRich && d->richText) { if (isComponentComplete()) { d->ensureDoc(); +#ifndef QT_NO_TEXTHTMLPARSER d->doc->setHtml(d->text); +#else + d->doc->setPlainText(d->text); +#endif } d->updateLayout(); d->markImgDirty(); @@ -991,7 +999,11 @@ void QDeclarativeText::reloadWithResources() Q_D(QDeclarativeText); if (!d->richText) return; +#ifndef QT_NO_TEXTHTMLPARSER d->doc->setHtml(d->text); +#else + d->doc->setPlainText(d->text); +#endif d->updateLayout(); d->markImgDirty(); } @@ -1121,7 +1133,11 @@ void QDeclarativeText::componentComplete() if (d->dirty) { if (d->richText) { d->ensureDoc(); +#ifndef QT_NO_TEXTHTMLPARSER d->doc->setHtml(d->text); +#else + d->doc->setPlainText(d->text); +#endif } d->updateLayout(); d->dirty = false; diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 9ccb8d2..15cdb05 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -89,6 +89,13 @@ TextEdit { A particular look-and-feel might use smooth scrolling (eg. using SmoothedFollow), might have a visible scrollbar, or a scrollbar that fades in to show location, etc. + Clipboard support is provided by the cut(), copy(), and paste() functions, and the selection can + be handled in a traditional "mouse" mechanism by setting selectByMouse, or handled completely + from QML by manipulating selectionStart and selectionEnd, or using selectAll() or selectWord(). + + You can translate between cursor positions (characters from the start of the document) and pixel + points using positionAt() and positionToRectangle(). + \sa Text */ @@ -120,9 +127,11 @@ QString QDeclarativeTextEdit::text() const { Q_D(const QDeclarativeTextEdit); +#ifndef QT_NO_TEXTHTMLPARSER if (d->richText) return d->document->toHtml(); else +#endif return d->document->toPlainText(); } @@ -253,7 +262,11 @@ void QDeclarativeTextEdit::setText(const QString &text) d->text = text; d->richText = d->format == RichText || (d->format == AutoText && Qt::mightBeRichText(text)); if (d->richText) { +#ifndef QT_NO_TEXTHTMLPARSER d->control->setHtml(text); +#else + d->control->setPlainText(text); +#endif } else { d->control->setPlainText(text); } @@ -318,7 +331,11 @@ void QDeclarativeTextEdit::setTextFormat(TextFormat format) d->control->setPlainText(d->text); updateSize(); } else if (!wasRich && d->richText) { +#ifndef QT_NO_TEXTHTMLPARSER d->control->setHtml(d->text); +#else + d->control->setPlainText(d->text); +#endif updateSize(); } d->format = format; @@ -531,6 +548,70 @@ qreal QDeclarativeTextEdit::paintedHeight() const return implicitHeight(); } +/*! + \qmlmethod rectangle TextEdit::positionToRectangle(position) + + Returns the rectangle at the given \a position in the text. The x, y, + and height properties correspond to the cursor that would describe + that position. +*/ +QRectF QDeclarativeTextEdit::positionToRectangle(int pos) const +{ + Q_D(const QDeclarativeTextEdit); + QTextCursor c(d->document); + c.setPosition(pos); + return d->control->cursorRect(c); + +} + +/*! + \qmlmethod int TextEdit::positionAt(x,y) + + Returns the text position closest to pixel position (\a x,\a y). + + Position 0 is before the first character, position 1 is after the first character + but before the second, and so on until position text.length, which is after all characters. +*/ +int QDeclarativeTextEdit::positionAt(int x, int y) const +{ + Q_D(const QDeclarativeTextEdit); + int r = d->document->documentLayout()->hitTest(QPoint(x,y-d->yoff), Qt::FuzzyHit); + return r; +} + +/*! + \qmlmethod int TextEdit::moveCursorSeletion(int pos) + + Moves the cursor to \a position and updates the selection accordingly. + (To only move the cursor, set the \l cursorPosition property.) + + When this method is called it additionally sets either the + selectionStart or the selectionEnd (whichever was at the previous cursor position) + to the specified position. This allows you to easily extend and contract the selected + text range. + + For example, take this sequence of calls: + + \code + cursorPosition = 5 + moveCursorSelection(9) + moveCursorSelection(7) + \endcode + + This moves the cursor to position 5, extend the selection end from 5 to 9 + and then retract the selection end from 9 to 7, leaving the text from position 5 to 7 + selected (the 6th and 7th characters). +*/ +void QDeclarativeTextEdit::moveCursorSelection(int pos) +{ + //Note that this is the same as setCursorPosition but with the KeepAnchor flag set + Q_D(QDeclarativeTextEdit); + QTextCursor cursor = d->control->textCursor(); + if (cursor.position() == pos) + return; + cursor.setPosition(pos, QTextCursor::KeepAnchor); + d->control->setTextCursor(cursor); +} /*! \qmlproperty bool TextEdit::cursorVisible @@ -956,6 +1037,51 @@ void QDeclarativeTextEdit::selectAll() } /*! + Causes the word closest to the current cursor position to be selected. +*/ +void QDeclarativeTextEdit::selectWord() +{ + Q_D(QDeclarativeTextEdit); + QTextCursor c = d->control->textCursor(); + c.select(QTextCursor::WordUnderCursor); + d->control->setTextCursor(c); +} + +/*! + \qmlmethod TextEdit::cut() + + Moves the currently selected text to the system clipboard. +*/ +void QDeclarativeTextEdit::cut() +{ + Q_D(QDeclarativeTextEdit); + d->control->cut(); +} + +/*! + \qmlmethod TextEdit::copy() + + Copies the currently selected text to the system clipboard. +*/ +void QDeclarativeTextEdit::copy() +{ + Q_D(QDeclarativeTextEdit); + d->control->copy(); +} + +/*! + \qmlmethod TextEdit::paste() + + Relaces the currently selected text by the contents of the system clipboard. +*/ +void QDeclarativeTextEdit::paste() +{ + Q_D(QDeclarativeTextEdit); + d->control->paste(); +} + + +/*! \overload Handles the given mouse \a event. */ diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h index 47174f4..a83b3db 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h @@ -198,6 +198,10 @@ public: qreal paintedWidth() const; qreal paintedHeight() const; + Q_INVOKABLE QRectF positionToRectangle(int) const; + Q_INVOKABLE int positionAt(int x, int y) const; + Q_INVOKABLE void moveCursorSelection(int pos); + Q_SIGNALS: void textChanged(const QString &); void paintedSizeChanged(); @@ -225,6 +229,10 @@ Q_SIGNALS: public Q_SLOTS: void selectAll(); + void selectWord(); + void cut(); + void copy(); + void paste(); private Q_SLOTS: void updateImgCache(const QRectF &rect); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 9c70ea9..ea958ef 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -648,6 +648,7 @@ void QDeclarativeTextInput::setAutoScroll(bool b) \sa acceptableInput, inputMask */ +#ifndef QT_NO_VALIDATOR QValidator* QDeclarativeTextInput::validator() const { Q_D(const QDeclarativeTextInput); @@ -669,6 +670,7 @@ void QDeclarativeTextInput::setValidator(QValidator* v) emit validatorChanged(); } +#endif // QT_NO_VALIDATOR /*! \qmlproperty string TextInput::inputMask @@ -833,7 +835,7 @@ void QDeclarativeTextInput::moveCursor() } /*! - \qmlmethod int TextInput::xToPosition(int x) + \qmlmethod int TextInput::positionAt(int x) This function returns the character position at x pixels from the left of the textInput. Position 0 is before the @@ -843,7 +845,7 @@ void QDeclarativeTextInput::moveCursor() This means that for all x values before the first character this function returns 0, and for all x values after the last character this function returns text.length. */ -int QDeclarativeTextInput::xToPosition(int x) +int QDeclarativeTextInput::positionAt(int x) { Q_D(const QDeclarativeTextInput); return d->control->xToPos(x - d->hscroll); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h index 438293a..9d58f13 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h @@ -79,7 +79,9 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextInput : public QDeclarativePaintedIte Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged) Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength NOTIFY maximumLengthChanged) +#ifndef QT_NO_VALIDATOR Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged) +#endif Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged) Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints) @@ -110,7 +112,7 @@ public: }; //Auxilliary functions needed to control the TextInput from QML - Q_INVOKABLE int xToPosition(int x); + Q_INVOKABLE int positionAt(int x); Q_INVOKABLE void moveCursorSelection(int pos); Q_INVOKABLE void openSoftwareInputPanel(); @@ -156,9 +158,10 @@ public: int maxLength() const; void setMaxLength(int ml); +#ifndef QT_NO_VALIDATOR QValidator * validator() const; void setValidator(QValidator* v); - +#endif QString inputMask() const; void setInputMask(const QString &im); @@ -248,10 +251,12 @@ private: QT_END_NAMESPACE QML_DECLARE_TYPE(QDeclarativeTextInput) +#ifndef QT_NO_VALIDATOR QML_DECLARE_TYPE(QValidator) QML_DECLARE_TYPE(QIntValidator) QML_DECLARE_TYPE(QDoubleValidator) QML_DECLARE_TYPE(QRegExpValidator) +#endif QT_END_HEADER diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index d27aced..80a1093 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -240,6 +240,7 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop, if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: color expected")); } break; +#ifndef QT_NO_TEXTDATE case QVariant::Date: { bool ok; @@ -261,6 +262,7 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop, if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: datetime expected")); } break; +#endif // QT_NO_TEXTDATE case QVariant::Point: case QVariant::PointF: { @@ -414,6 +416,7 @@ void QDeclarativeCompiler::genLiteralAssignment(const QMetaProperty &prop, instr.storeColor.value = c.rgba(); } break; +#ifndef QT_NO_TEXTDATE case QVariant::Date: { QDate d = QDeclarativeStringConverters::dateFromString(string); @@ -447,6 +450,7 @@ void QDeclarativeCompiler::genLiteralAssignment(const QMetaProperty &prop, instr.storeDateTime.valueIndex = index; } break; +#endif // QT_NO_TEXTDATE case QVariant::Point: case QVariant::PointF: { diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 2dc2d2d..9847079 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -53,7 +53,7 @@ #include "private/qdeclarativebinding_p_p.h" #include "private/qdeclarativeglobal_p.h" #include "private/qdeclarativescriptparser_p.h" -#include "private/qdeclarativedebugtiming_p.h" +#include "private/qdeclarativedebugtrace_p.h" #include <QStack> #include <QStringList> @@ -696,7 +696,8 @@ QDeclarativeComponentPrivate::beginCreate(QDeclarativeContextData *context, cons bool isRoot = !ep->inBeginCreate; if (isRoot) - QDeclarativeDebugTiming::startRange(QDeclarativeDebugTiming::Creating); + QDeclarativeDebugTrace::startRange(QDeclarativeDebugTrace::Creating); + QDeclarativeDebugTrace::rangeData(QDeclarativeDebugTrace::Creating, cc->url); QDeclarativeContextData *ctxt = new QDeclarativeContextData; ctxt->isInternal = true; @@ -867,7 +868,7 @@ void QDeclarativeComponentPrivate::completeCreate() QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); complete(ep, &state); - QDeclarativeDebugTiming::endRange(QDeclarativeDebugTiming::Creating); + QDeclarativeDebugTrace::endRange(QDeclarativeDebugTrace::Creating); } } diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 8679e76..2f2ee08 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -284,10 +284,12 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr qtObject.setProperty(QLatin1String("tint"), newFunction(QDeclarativeEnginePrivate::tint, 2)); } +#ifndef QT_NO_TEXTDATE //date/time formatting qtObject.setProperty(QLatin1String("formatDate"),newFunction(QDeclarativeEnginePrivate::formatDate, 2)); qtObject.setProperty(QLatin1String("formatTime"),newFunction(QDeclarativeEnginePrivate::formatTime, 2)); qtObject.setProperty(QLatin1String("formatDateTime"),newFunction(QDeclarativeEnginePrivate::formatDateTime, 2)); +#endif //misc methods qtObject.setProperty(QLatin1String("openUrlExternally"),newFunction(QDeclarativeEnginePrivate::desktopOpenUrl, 1)); @@ -1219,6 +1221,7 @@ QScriptValue QDeclarativeEnginePrivate::vector3d(QScriptContext *ctxt, QScriptEn \qmlmethod string Qt::formatDate(datetime date, variant format) Returns the string representation of \c date, formatted according to \c format. */ +#ifndef QT_NO_TEXTDATE QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptEngine*engine) { int argCount = ctxt->argumentCount(); @@ -1356,6 +1359,7 @@ QScriptValue QDeclarativeEnginePrivate::formatDateTime(QScriptContext*ctxt, QScr } return engine->newVariant(qVariantFromValue(date.toString(enumFormat))); } +#endif // QT_NO_TEXTDATE /*! \qmlmethod color Qt::rgba(real red, real green, real blue, real alpha) diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 804476c..3269e98 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -302,10 +302,11 @@ public: static QScriptValue consoleLog(QScriptContext*, QScriptEngine*); static QScriptValue quit(QScriptContext*, QScriptEngine*); +#ifndef QT_NO_TEXTDATE static QScriptValue formatDate(QScriptContext*, QScriptEngine*); static QScriptValue formatTime(QScriptContext*, QScriptEngine*); static QScriptValue formatDateTime(QScriptContext*, QScriptEngine*); - +#endif static QScriptEngine *getScriptEngine(QDeclarativeEngine *e) { return &e->d_func()->scriptEngine; } static QDeclarativeEngine *getEngine(QScriptEngine *e) { return static_cast<QDeclarativeScriptEngine*>(e)->p->q_func(); } static QDeclarativeEnginePrivate *get(QDeclarativeEngine *e) { return e->d_func(); } diff --git a/src/declarative/qml/qdeclarativeinfo.h b/src/declarative/qml/qdeclarativeinfo.h index 2ac28f4..b41abd8 100644 --- a/src/declarative/qml/qdeclarativeinfo.h +++ b/src/declarative/qml/qdeclarativeinfo.h @@ -81,7 +81,9 @@ public: inline QDeclarativeInfo &operator<<(const void * t) { QDebug::operator<<(t); return *this; } inline QDeclarativeInfo &operator<<(QTextStreamFunction f) { QDebug::operator<<(f); return *this; } inline QDeclarativeInfo &operator<<(QTextStreamManipulator m) { QDebug::operator<<(m); return *this; } +#ifndef QT_NO_DEBUG_STREAM inline QDeclarativeInfo &operator<<(const QUrl &t) { static_cast<QDebug &>(*this) << t; return *this; } +#endif private: friend Q_DECLARATIVE_EXPORT QDeclarativeInfo qmlInfo(const QObject *me); diff --git a/src/declarative/qml/qdeclarativeinstruction.cpp b/src/declarative/qml/qdeclarativeinstruction.cpp index b86d082..0f7b09d 100644 --- a/src/declarative/qml/qdeclarativeinstruction.cpp +++ b/src/declarative/qml/qdeclarativeinstruction.cpp @@ -49,6 +49,10 @@ QT_BEGIN_NAMESPACE void QDeclarativeCompiledData::dump(QDeclarativeInstruction *instr, int idx) { +#ifdef QT_NO_DEBUG_STREAM + Q_UNUSED(instr) + Q_UNUSED(idx) +#else QByteArray lineNumber = QByteArray::number(instr->line); if (instr->line == (unsigned short)-1) lineNumber = "NA"; @@ -217,6 +221,7 @@ void QDeclarativeCompiledData::dump(QDeclarativeInstruction *instr, int idx) qWarning().nospace() << idx << "\t\t" << line << "\t" << "XXX UNKOWN INSTRUCTION" << "\t" << instr->type; break; } +#endif // QT_NO_DEBUG_STREAM } QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativestringconverters.cpp b/src/declarative/qml/qdeclarativestringconverters.cpp index bbcc00b..8bd2cf1 100644 --- a/src/declarative/qml/qdeclarativestringconverters.cpp +++ b/src/declarative/qml/qdeclarativestringconverters.cpp @@ -106,12 +106,14 @@ QVariant QDeclarativeStringConverters::variantFromString(const QString &s, int p return QVariant(uint(qRound(s.toDouble(ok)))); case QMetaType::QColor: return QVariant::fromValue(colorFromString(s, ok)); +#ifndef QT_NO_TEXTDATE case QMetaType::QDate: return QVariant::fromValue(dateFromString(s, ok)); case QMetaType::QTime: return QVariant::fromValue(timeFromString(s, ok)); case QMetaType::QDateTime: return QVariant::fromValue(dateTimeFromString(s, ok)); +#endif // QT_NO_TEXTDATE case QMetaType::QPointF: return QVariant::fromValue(pointFFromString(s, ok)); case QMetaType::QPoint: @@ -150,6 +152,7 @@ QColor QDeclarativeStringConverters::colorFromString(const QString &s, bool *ok) } } +#ifndef QT_NO_TEXTDATE QDate QDeclarativeStringConverters::dateFromString(const QString &s, bool *ok) { QDate d = QDate::fromString(s, Qt::ISODate); @@ -170,6 +173,7 @@ QDateTime QDeclarativeStringConverters::dateTimeFromString(const QString &s, boo if (ok) *ok = d.isValid(); return d; } +#endif // QT_NO_TEXTDATE //expects input of "x,y" QPointF QDeclarativeStringConverters::pointFFromString(const QString &s, bool *ok) diff --git a/src/declarative/qml/qdeclarativestringconverters_p.h b/src/declarative/qml/qdeclarativestringconverters_p.h index 97f72fc..842d1b3 100644 --- a/src/declarative/qml/qdeclarativestringconverters_p.h +++ b/src/declarative/qml/qdeclarativestringconverters_p.h @@ -73,9 +73,11 @@ namespace QDeclarativeStringConverters QVariant Q_DECLARATIVE_EXPORT variantFromString(const QString &, int preferredType, bool *ok = 0); QColor Q_DECLARATIVE_EXPORT colorFromString(const QString &, bool *ok = 0); +#ifndef QT_NO_TEXTDATE QDate Q_DECLARATIVE_EXPORT dateFromString(const QString &, bool *ok = 0); QTime Q_DECLARATIVE_EXPORT timeFromString(const QString &, bool *ok = 0); QDateTime Q_DECLARATIVE_EXPORT dateTimeFromString(const QString &, bool *ok = 0); +#endif QPointF Q_DECLARATIVE_EXPORT pointFFromString(const QString &, bool *ok = 0); QSizeF Q_DECLARATIVE_EXPORT sizeFFromString(const QString &, bool *ok = 0); QRectF Q_DECLARATIVE_EXPORT rectFFromString(const QString &, bool *ok = 0); diff --git a/src/declarative/util/qdeclarativestate.cpp b/src/declarative/util/qdeclarativestate.cpp index b5f7900..dc2b2cc 100644 --- a/src/declarative/util/qdeclarativestate.cpp +++ b/src/declarative/util/qdeclarativestate.cpp @@ -486,6 +486,7 @@ void QDeclarativeState::apply(QDeclarativeStateGroup *group, QDeclarativeTransit // All the local reverts now become part of the ongoing revertList d->revertList << additionalReverts; +#ifndef QT_NO_DEBUG_STREAM // Output for debugging if (stateChangeDebug()) { foreach(const QDeclarativeAction &action, applyList) { @@ -497,6 +498,7 @@ void QDeclarativeState::apply(QDeclarativeStateGroup *group, QDeclarativeTransit << "To:" << action.toValue; } } +#endif d->transitionManager.transition(applyList, trans); } diff --git a/src/declarative/util/qdeclarativetransitionmanager.cpp b/src/declarative/util/qdeclarativetransitionmanager.cpp index 368d484..9f198e4 100644 --- a/src/declarative/util/qdeclarativetransitionmanager.cpp +++ b/src/declarative/util/qdeclarativetransitionmanager.cpp @@ -233,6 +233,7 @@ void QDeclarativeTransitionManager::transition(const QList<QDeclarativeAction> & action.property.write(action.toValue); } } +#ifndef QT_NO_DEBUG_STREAM if (stateChangeDebug()) { foreach(const QDeclarativeAction &action, applyList) { if (action.event) @@ -243,6 +244,7 @@ void QDeclarativeTransitionManager::transition(const QList<QDeclarativeAction> & << "To:" << action.toValue; } } +#endif if (!transition) d->applyBindings(); } diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp index d2dab76..6059ad6 100644 --- a/src/declarative/util/qdeclarativeview.cpp +++ b/src/declarative/util/qdeclarativeview.cpp @@ -48,7 +48,7 @@ #include <qdeclarativeglobal_p.h> #include <qdeclarativeguard_p.h> -#include <private/qdeclarativedebugtiming_p.h> +#include <private/qdeclarativedebugtrace_p.h> #include <qscriptvalueiterator.h> #include <qdebug.h> @@ -93,35 +93,35 @@ QDeclarativeScene::QDeclarativeScene() void QDeclarativeScene::keyPressEvent(QKeyEvent *e) { - QDeclarativeDebugTiming::addEvent(QDeclarativeDebugTiming::Key); + QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Key); QGraphicsScene::keyPressEvent(e); } void QDeclarativeScene::keyReleaseEvent(QKeyEvent *e) { - QDeclarativeDebugTiming::addEvent(QDeclarativeDebugTiming::Key); + QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Key); QGraphicsScene::keyReleaseEvent(e); } void QDeclarativeScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { - QDeclarativeDebugTiming::addEvent(QDeclarativeDebugTiming::Mouse); + QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Mouse); QGraphicsScene::mouseMoveEvent(e); } void QDeclarativeScene::mousePressEvent(QGraphicsSceneMouseEvent *e) { - QDeclarativeDebugTiming::addEvent(QDeclarativeDebugTiming::Mouse); + QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Mouse); QGraphicsScene::mousePressEvent(e); } void QDeclarativeScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { - QDeclarativeDebugTiming::addEvent(QDeclarativeDebugTiming::Mouse); + QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Mouse); QGraphicsScene::mouseReleaseEvent(e); } @@ -675,8 +675,8 @@ void QDeclarativeView::paintEvent(QPaintEvent *event) { Q_D(QDeclarativeView); - QDeclarativeDebugTiming::addEvent(QDeclarativeDebugTiming::FramePaint); - QDeclarativeDebugTiming::startRange(QDeclarativeDebugTiming::Painting); + QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::FramePaint); + QDeclarativeDebugTrace::startRange(QDeclarativeDebugTrace::Painting); int time = 0; if (frameRateDebug()) @@ -684,7 +684,7 @@ void QDeclarativeView::paintEvent(QPaintEvent *event) QGraphicsView::paintEvent(event); - QDeclarativeDebugTiming::endRange(QDeclarativeDebugTiming::Painting); + QDeclarativeDebugTrace::endRange(QDeclarativeDebugTrace::Painting); if (frameRateDebug()) qDebug() << "paintEvent:" << d->frameTimer.elapsed() << "time since last frame:" << time; diff --git a/src/gui/kernel/qdrag.cpp b/src/gui/kernel/qdrag.cpp index b57615c..77f8fc0 100644 --- a/src/gui/kernel/qdrag.cpp +++ b/src/gui/kernel/qdrag.cpp @@ -253,7 +253,9 @@ Qt::DropAction QDrag::exec(Qt::DropActions supportedActions) can take some time, but this function does not block the event loop. Other events are still delivered to the application while the operation is performed. On Windows, the Qt event loop is - blocked while during the operation. + blocked during the operation. However, QDrag::exec() on + Windows causes processEvents() to be called frequently to keep the GUI responsive. + If any loops or operations are called while a drag operation is active, it will block the drag operation. */ Qt::DropAction QDrag::exec(Qt::DropActions supportedActions, Qt::DropAction defaultDropAction) diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index ce7915d..3f67408 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -858,7 +858,8 @@ QRectF QTextLayout::boundingRect() const const QScriptLine &si = d->lines[i]; xmin = qMin(xmin, si.x); ymin = qMin(ymin, si.y); - xmax = qMax(xmax, si.x+qMax(si.width, si.textWidth)); + QFixed lineWidth = si.width < QFIXED_MAX ? qMax(si.width, si.textWidth) : si.textWidth; + xmax = qMax(xmax, si.x+lineWidth); // ### shouldn't the ascent be used in ymin??? ymax = qMax(ymax, si.y+si.height()); } diff --git a/src/imports/folderlistmodel/plugin.cpp b/src/imports/folderlistmodel/plugin.cpp index 555df3c..1ec6106 100644 --- a/src/imports/folderlistmodel/plugin.cpp +++ b/src/imports/folderlistmodel/plugin.cpp @@ -53,7 +53,9 @@ public: virtual void registerTypes(const char *uri) { Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.folderlistmodel")); +#ifndef QT_NO_DIRMODEL qmlRegisterType<QDeclarativeFolderListModel>(uri,1,0,"FolderListModel"); +#endif } }; //![class decl] diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp index fccb9d4..9cf81ca 100644 --- a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp @@ -45,6 +45,8 @@ #include <QDebug> #include <qdeclarativecontext.h> +#ifndef QT_NO_DIRMODEL + QT_BEGIN_NAMESPACE class QDeclarativeFolderListModelPrivate @@ -397,3 +399,5 @@ void QDeclarativeFolderListModel::setShowOnlyReadable(bool on) //![code] QT_END_NAMESPACE + +#endif // QT_NO_DIRMODEL diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h index ea7d701..1bab5f84 100644 --- a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h @@ -47,6 +47,8 @@ #include <QUrl> #include <QAbstractListModel> +#ifndef QT_NO_DIRMODEL + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -152,4 +154,6 @@ QML_DECLARE_TYPE(QDeclarativeFolderListModel) QT_END_HEADER +#endif // QT_NO_DIRMODEL + #endif // QDECLARATIVEFOLDERLISTMODEL_H diff --git a/src/plugins/bearer/symbian/qnetworksession_impl.cpp b/src/plugins/bearer/symbian/qnetworksession_impl.cpp index 3cd18fb..e08d135 100644 --- a/src/plugins/bearer/symbian/qnetworksession_impl.cpp +++ b/src/plugins/bearer/symbian/qnetworksession_impl.cpp @@ -122,19 +122,10 @@ void QNetworkSessionPrivateImpl::configurationRemoved(QNetworkConfigurationPriva if (!publicConfig.isValid()) return; - SymbianNetworkConfigurationPrivate *symbianConfig = toSymbianConfig(config); - - symbianConfig->mutex.lock(); - TUint32 configNumericId = symbianConfig->numericId; - symbianConfig->mutex.unlock(); - - symbianConfig = toSymbianConfig(privateConfiguration(publicConfig)); - - symbianConfig->mutex.lock(); - TUint32 publicNumericId = symbianConfig->numericId; - symbianConfig->mutex.unlock(); + TUint32 publicNumericId = + toSymbianConfig(privateConfiguration(publicConfig))->numericIdentifier(); - if (configNumericId == publicNumericId) { + if (toSymbianConfig(config)->numericIdentifier() == publicNumericId) { #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG qDebug() << "QNS this : " << QString::number((uint)this) << " - " << "configurationRemoved IAP: " << QString::number(publicNumericId) << " : going to State: Invalid"; @@ -380,13 +371,11 @@ void QNetworkSessionPrivateImpl::open() SymbianNetworkConfigurationPrivate *symbianConfig = toSymbianConfig(privateConfiguration(publicConfig)); - QMutexLocker configLocker(&symbianConfig->mutex); - - if (connInfo().iIapId == symbianConfig->numericId) { + if (connInfo().iIapId == symbianConfig->numericIdentifier()) { if (iConnection.Attach(connInfo, RConnection::EAttachTypeNormal) == KErrNone) { activeConfig = publicConfig; #ifndef QT_NO_NETWORKINTERFACE - activeInterface = interface(symbianConfig->numericId); + activeInterface = interface(symbianConfig->numericIdentifier()); #endif connected = ETrue; startTime = QDateTime::currentDateTime(); @@ -416,9 +405,7 @@ void QNetworkSessionPrivateImpl::open() TConnPrefList pref; TExtendedConnPref prefs; - symbianConfig->mutex.lock(); - prefs.SetIapId(symbianConfig->numericId); - symbianConfig->mutex.unlock(); + prefs.SetIapId(symbianConfig->numericIdentifier()); if (iConnectInBackground) { prefs.SetNoteBehaviour( TExtendedConnPref::ENoteBehaviourConnSilent ); } @@ -427,9 +414,7 @@ void QNetworkSessionPrivateImpl::open() TCommDbConnPref pref; pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); - symbianConfig->mutex.lock(); - pref.SetIapId(symbianConfig->numericId); - symbianConfig->mutex.unlock(); + pref.SetIapId(symbianConfig->numericIdentifier()); #endif iConnection.Start(pref, iStatus); if (!IsActive()) { @@ -444,17 +429,13 @@ void QNetworkSessionPrivateImpl::open() #ifdef OCC_FUNCTIONALITY_AVAILABLE TConnPrefList snapPref; TExtendedConnPref prefs; - symbianConfig->mutex.lock(); - prefs.SetSnapId(symbianConfig->numericId); - symbianConfig->mutex.unlock(); + prefs.SetSnapId(symbianConfig->numericIdentifier()); if (iConnectInBackground) { prefs.SetNoteBehaviour( TExtendedConnPref::ENoteBehaviourConnSilent ); } snapPref.AppendL(&prefs); #else - symbianConfig->mutex.lock(); - TConnSnapPref snapPref(symbianConfig->numericId); - symbianConfig->mutex.unlock(); + TConnSnapPref snapPref(symbianConfig->numericIdentifier()); #endif iConnection.Start(snapPref, iStatus); if (!IsActive()) { @@ -592,10 +573,8 @@ void QNetworkSessionPrivateImpl::stop() SymbianNetworkConfigurationPrivate *symbianConfig = toSymbianConfig(privateConfiguration(publicConfig)); - QMutexLocker configLocker(&symbianConfig->mutex); - // See if connection Id matches with our Id. If so, stop() it. - if (symbianConfig->connectionId == connectionId) { + if (symbianConfig->connectionIdentifier() == connectionId) { ret = iConnectionMonitor.SetBoolAttribute(connectionId, 0, // subConnectionId don't care KConnectionStop, @@ -715,12 +694,8 @@ void QNetworkSessionPrivateImpl::PreferredCarrierAvailable(TAccessPointInfo aOld SymbianNetworkConfigurationPrivate *symbianConfig = toSymbianConfig(privateConfiguration(configs[i])); - QMutexLocker configLocker(&symbianConfig->mutex); - - if (symbianConfig->numericId == aNewAPInfo.AccessPoint()) { - configLocker.unlock(); + if (symbianConfig->numericIdentifier() == aNewAPInfo.AccessPoint()) emit preferredConfigurationChanged(configs[i], aIsSeamless); - } } } else { migrate(); @@ -854,9 +829,7 @@ quint64 QNetworkSessionPrivateImpl::transferredData(TUint dataType) const SymbianNetworkConfigurationPrivate *symbianConfig = toSymbianConfig(privateConfiguration(configs[i])); - QMutexLocker configLocker(&symbianConfig->mutex); - - if (symbianConfig->numericId == apId) { + if (symbianConfig->numericIdentifier() == apId) { configFound = true; break; } @@ -865,10 +838,8 @@ quint64 QNetworkSessionPrivateImpl::transferredData(TUint dataType) const SymbianNetworkConfigurationPrivate *symbianConfig = toSymbianConfig(privateConfiguration(config)); - symbianConfig->mutex.lock(); - if (symbianConfig->numericId == apId) + if (symbianConfig->numericIdentifier() == apId) configFound = true; - symbianConfig->mutex.unlock(); } if (configFound) { TUint tData; @@ -908,8 +879,7 @@ QNetworkConfiguration QNetworkSessionPrivateImpl::activeConfiguration(TUint32 ia SymbianNetworkConfigurationPrivate *childConfig = toSymbianConfig(privateConfiguration(children[i])); - QMutexLocker childLocker(&childConfig->mutex); - if (childConfig->numericId == iapId) + if (childConfig->numericIdentifier() == iapId) return children[i]; } @@ -928,15 +898,11 @@ QNetworkConfiguration QNetworkSessionPrivateImpl::activeConfiguration(TUint32 ia SymbianNetworkConfigurationPrivate *symbianConfig = toSymbianConfig(privateConfiguration(pt)); if (symbianConfig) { - QMutexLocker configLocker(&symbianConfig->mutex); - for (int i=0; i < children.count(); i++) { SymbianNetworkConfigurationPrivate *childConfig = toSymbianConfig(privateConfiguration(children[i])); - QMutexLocker childLocker(&childConfig->mutex); - - if (childConfig->mappingName == symbianConfig->mappingName) { + if (childConfig->configMappingName() == symbianConfig->configMappingName()) { return children[i]; } } @@ -1034,15 +1000,13 @@ void QNetworkSessionPrivateImpl::RunL() SymbianNetworkConfigurationPrivate *symbianConfig = toSymbianConfig(privateConfiguration(activeConfig)); - symbianConfig->mutex.lock(); #ifndef QT_NO_NETWORKINTERFACE - activeInterface = interface(symbianConfig->numericId); + activeInterface = interface(symbianConfig->numericIdentifier()); #endif if (publicConfig.type() == QNetworkConfiguration::UserChoice) { serviceConfig = QNetworkConfigurationManager() - .configurationFromIdentifier(symbianConfig->id); + .configurationFromIdentifier(activeConfig.identifier()); } - symbianConfig->mutex.unlock(); startTime = QDateTime::currentDateTime(); @@ -1105,13 +1069,11 @@ bool QNetworkSessionPrivateImpl::newState(QNetworkSession::State newState, TUint newState == QNetworkSession::Connected) { activeConfig = activeConfiguration(accessPointId); +#ifndef QT_NO_NETWORKINTERFACE SymbianNetworkConfigurationPrivate *symbianConfig = toSymbianConfig(privateConfiguration(activeConfig)); -#ifndef QT_NO_NETWORKINTERFACE - symbianConfig->mutex.lock(); - activeInterface = interface(symbianConfig->numericId); - symbianConfig->mutex.unlock(); + activeInterface = interface(symbianConfig->numericIdentifier()); #endif #ifdef SNAP_FUNCTIONALITY_AVAILABLE @@ -1187,10 +1149,7 @@ bool QNetworkSessionPrivateImpl::newState(QNetworkSession::State newState, TUint SymbianNetworkConfigurationPrivate *symbianConfig = toSymbianConfig(privateConfiguration(publicConfig)); - QMutexLocker configLocker(&symbianConfig->mutex); - if (symbianConfig->numericId == accessPointId) { - configLocker.unlock(); - + if (symbianConfig->numericIdentifier() == accessPointId) { state = newState; #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG qDebug() << "QNS this : " << QString::number((uint)this) << " - " << "===> EMIT State changed B to: " << state; @@ -1202,10 +1161,7 @@ bool QNetworkSessionPrivateImpl::newState(QNetworkSession::State newState, TUint SymbianNetworkConfigurationPrivate *symbianConfig = toSymbianConfig(privateConfiguration(activeConfig)); - QMutexLocker configLocker(&symbianConfig->mutex); - if (symbianConfig->numericId == accessPointId) { - configLocker.unlock(); - + if (symbianConfig->numericIdentifier() == accessPointId) { state = newState; #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG qDebug() << "QNS this : " << QString::number((uint)this) << " - " << "===> EMIT State changed C to: " << state; @@ -1219,9 +1175,7 @@ bool QNetworkSessionPrivateImpl::newState(QNetworkSession::State newState, TUint SymbianNetworkConfigurationPrivate *symbianConfig = toSymbianConfig(privateConfiguration(subConfigurations[i])); - QMutexLocker configLocker(&symbianConfig->mutex); - - if (symbianConfig->numericId == accessPointId) { + if (symbianConfig->numericIdentifier() == accessPointId) { if (newState != QNetworkSession::Disconnected) { state = newState; #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG @@ -1234,8 +1188,6 @@ bool QNetworkSessionPrivateImpl::newState(QNetworkSession::State newState, TUint if ((config.state() == QNetworkConfiguration::Defined) || (config.state() == QNetworkConfiguration::Discovered)) { - configLocker.unlock(); - state = newState; #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG qDebug() << "QNS this : " << QString::number((uint)this) << " - " << "===> EMIT State changed E to: " << state; @@ -1271,9 +1223,7 @@ bool QNetworkSessionPrivateImpl::newState(QNetworkSession::State newState, TUint SymbianNetworkConfigurationPrivate *symbianConfig = toSymbianConfig(privateConfiguration(publicConfig)); - symbianConfig->mutex.lock(); - iDeprecatedConnectionId = symbianConfig->connectionId; - symbianConfig->mutex.unlock(); + iDeprecatedConnectionId = symbianConfig->connectionIdentifier(); } return retVal; @@ -1369,7 +1319,11 @@ void QNetworkSessionPrivateImpl::handleSymbianConnectionStatusChange(TInt aConne qDebug() << "QNS this : " << QString::number((uint)this) << " - " << "reporting disconnection to manager."; #endif if (publicConfig.isValid()) { - engine->configurationStateChangeReport(toSymbianConfig(privateConfiguration(publicConfig))->numericId, QNetworkSession::Disconnected); + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(publicConfig)); + + engine->configurationStateChangeReport(symbianConfig->numericIdentifier(), + QNetworkSession::Disconnected); } break; // Unhandled state diff --git a/src/plugins/bearer/symbian/symbianengine.cpp b/src/plugins/bearer/symbian/symbianengine.cpp index cea8b67..8c26cf0 100644 --- a/src/plugins/bearer/symbian/symbianengine.cpp +++ b/src/plugins/bearer/symbian/symbianengine.cpp @@ -115,13 +115,18 @@ QString SymbianNetworkConfigurationPrivate::bearerName() const SymbianEngine::SymbianEngine(QObject *parent) : QBearerEngine(parent), CActive(CActive::EPriorityIdle), iFirstUpdate(true), iInitOk(true), - iIgnoringUpdates(false), iTimeToWait(0), iIgnoreEventLoop(0) + iIgnoringUpdates(false) { +} + +void SymbianEngine::initialize() +{ + QMutexLocker locker(&mutex); + CActiveScheduler::Add(this); // Seed the randomgenerator qsrand(QTime(0,0,0).secsTo(QTime::currentTime()) + QCoreApplication::applicationPid()); - iIgnoreEventLoop = new QEventLoop(this); TRAPD(error, ipCommsDB = CCommsDatabase::NewL(EDatabaseTypeIAP)); if (error != KErrNone) { @@ -132,18 +137,13 @@ SymbianEngine::SymbianEngine(QObject *parent) TRAP_IGNORE(iConnectionMonitor.ConnectL()); TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); -#ifdef SNAP_FUNCTIONALITY_AVAILABLE +#ifdef SNAP_FUNCTIONALITY_AVAILABLE TRAP(error, iCmManager.OpenL()); if (error != KErrNone) { iInitOk = false; return; } #endif -} - -void SymbianEngine::initialize() -{ - QMutexLocker locker(&mutex); SymbianNetworkConfigurationPrivate *cpPriv = new SymbianNetworkConfigurationPrivate; cpPriv->name = "UserChoice"; @@ -238,19 +238,14 @@ void SymbianEngine::requestUpdate() void SymbianEngine::updateConfigurations() { - QMutexLocker locker(&mutex); - - if (!iInitOk) { + if (!iInitOk) return; - } TRAP_IGNORE(updateConfigurationsL()); } void SymbianEngine::updateConfigurationsL() { - QMutexLocker locker(&mutex); - QList<QString> knownConfigs = accessPointConfigurations.keys(); QList<QString> knownSnapConfigs = snapConfigurations.keys(); @@ -276,9 +271,9 @@ void SymbianEngine::updateConfigurationsL() QNetworkConfigurationPrivatePointer ptr(cpPriv); accessPointConfigurations.insert(ptr->id, ptr); - locker.unlock(); + mutex.unlock(); emit configurationAdded(ptr); - locker.relock(); + mutex.lock(); } } CleanupStack::PopAndDestroy(&connectionMethod); @@ -317,9 +312,9 @@ void SymbianEngine::updateConfigurationsL() QNetworkConfigurationPrivatePointer ptr(cpPriv); snapConfigurations.insert(ident, ptr); - locker.unlock(); + mutex.unlock(); emit configurationAdded(ptr); - locker.relock(); + mutex.lock(); CleanupStack::Pop(cpPriv); } @@ -338,34 +333,35 @@ void SymbianEngine::updateConfigurationsL() TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod)); if (error == KErrNone) { QNetworkConfigurationPrivatePointer ptr(cpPriv); - toSymbianConfig(ptr)->serviceNetworkPtr = privSNAP; accessPointConfigurations.insert(ptr->id, ptr); - locker.unlock(); + mutex.unlock(); emit configurationAdded(ptr); - locker.relock(); + mutex.lock(); + QMutexLocker configLocker(&privSNAP->mutex); privSNAP->serviceNetworkMembers.append(ptr); } } else { knownConfigs.removeOne(iface); // Check that IAP can be found from related SNAP's configuration list bool iapFound = false; + QMutexLocker snapConfigLocker(&privSNAP->mutex); for (int i = 0; i < privSNAP->serviceNetworkMembers.count(); i++) { - if (toSymbianConfig(privSNAP->serviceNetworkMembers[i])->numericId == iapId) { + if (toSymbianConfig(privSNAP->serviceNetworkMembers[i])->numericIdentifier() == + iapId) { iapFound = true; break; } } - if (!iapFound) { - toSymbianConfig(priv)->serviceNetworkPtr = privSNAP; + if (!iapFound) privSNAP->serviceNetworkMembers.append(priv); - } } CleanupStack::PopAndDestroy(&connectionMethod); } + QMutexLocker snapConfigLocker(&privSNAP->mutex); if (privSNAP->serviceNetworkMembers.count() > 1) { // Roaming is supported only if SNAP contains more than one IAP privSNAP->roamingSupported = true; @@ -410,17 +406,18 @@ void SymbianEngine::updateConfigurationsL() //remove non existing IAP QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(oldIface); - locker.unlock(); + mutex.unlock(); emit configurationRemoved(ptr); - locker.relock(); + mutex.lock(); // Remove non existing IAP from SNAPs foreach (const QString &iface, snapConfigurations.keys()) { QNetworkConfigurationPrivatePointer ptr2 = snapConfigurations.value(iface); // => Check if one of the IAPs of the SNAP is active + QMutexLocker snapConfigLocker(&ptr2->mutex); for (int i = 0; i < ptr2->serviceNetworkMembers.count(); ++i) { - if (toSymbianConfig(ptr2->serviceNetworkMembers[i])->numericId == - toSymbianConfig(ptr)->numericId) { + if (toSymbianConfig(ptr2->serviceNetworkMembers[i])->numericIdentifier() == + toSymbianConfig(ptr)->numericIdentifier()) { ptr2->serviceNetworkMembers.removeAt(i); break; } @@ -432,18 +429,21 @@ void SymbianEngine::updateConfigurationsL() //remove non existing SNAPs QNetworkConfigurationPrivatePointer ptr = snapConfigurations.take(oldIface); - locker.unlock(); + mutex.unlock(); emit configurationRemoved(ptr); - locker.relock(); + mutex.lock(); } + + // find default configuration. + stopCommsDatabaseNotifications(); + TRAP_IGNORE(defaultConfig = defaultConfigurationL()); + startCommsDatabaseNotifications(); } #ifdef SNAP_FUNCTIONALITY_AVAILABLE SymbianNetworkConfigurationPrivate *SymbianEngine::configFromConnectionMethodL( RCmConnectionMethod& connectionMethod) { - QMutexLocker locker(&mutex); - SymbianNetworkConfigurationPrivate *cpPriv = new SymbianNetworkConfigurationPrivate; CleanupStack::PushL(cpPriv); @@ -526,8 +526,6 @@ SymbianNetworkConfigurationPrivate *SymbianEngine::configFromConnectionMethodL( bool SymbianEngine::readNetworkConfigurationValuesFromCommsDb( TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration) { - QMutexLocker locker(&mutex); - TRAPD(error, readNetworkConfigurationValuesFromCommsDbL(aApId,apNetworkConfiguration)); if (error != KErrNone) { return false; @@ -538,8 +536,6 @@ bool SymbianEngine::readNetworkConfigurationValuesFromCommsDb( void SymbianEngine::readNetworkConfigurationValuesFromCommsDbL( TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration) { - QMutexLocker locker(&mutex); - CApDataHandler* pDataHandler = CApDataHandler::NewLC(*ipCommsDB); CApAccessPointItem* pAPItem = CApAccessPointItem::NewLC(); TBuf<KCommsDbSvrMaxColumnNameLength> name; @@ -602,15 +598,7 @@ QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfiguration() { QMutexLocker locker(&mutex); - QNetworkConfigurationPrivatePointer ptr; - - if (iInitOk) { - stopCommsDatabaseNotifications(); - TRAP_IGNORE(ptr = defaultConfigurationL()); - startCommsDatabaseNotifications(); - } - - return ptr; + return defaultConfig; } QStringList SymbianEngine::accessPointConfigurationIdentifiers() @@ -622,8 +610,6 @@ QStringList SymbianEngine::accessPointConfigurationIdentifiers() QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfigurationL() { - QMutexLocker locker(&mutex); - QNetworkConfigurationPrivatePointer ptr; #ifdef SNAP_FUNCTIONALITY_AVAILABLE @@ -639,18 +625,18 @@ QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfigurationL() } #endif - if (!ptr || !ptr->isValid) { - QString iface = QString::number(qHash(KUserChoiceIAPId)); - ptr = userChoiceConfigurations.value(iface); + if (ptr) { + QMutexLocker configLocker(&ptr->mutex); + if (ptr->isValid) + return ptr; } - - return ptr; + + QString iface = QString::number(qHash(KUserChoiceIAPId)); + return userChoiceConfigurations.value(iface); } void SymbianEngine::updateActiveAccessPoints() { - QMutexLocker locker(&mutex); - bool online = false; QList<QString> inactiveConfigs = accessPointConfigurations.keys(); @@ -681,8 +667,9 @@ void SymbianEngine::updateActiveAccessPoints() online = true; inactiveConfigs.removeOne(ident); - QMutexLocker configLocker(&ptr->mutex); + ptr->mutex.lock(); toSymbianConfig(ptr)->connectionId = connectionId; + ptr->mutex.unlock(); // Configuration is Active changeConfigurationStateTo(ptr, QNetworkConfiguration::Active); @@ -702,16 +689,14 @@ void SymbianEngine::updateActiveAccessPoints() if (iOnline != online) { iOnline = online; - locker.unlock(); + mutex.unlock(); emit this->onlineStateChanged(iOnline); - locker.relock(); + mutex.lock(); } } void SymbianEngine::updateAvailableAccessPoints() { - QMutexLocker locker(&mutex); - if (!ipAccessPointsAvailabilityScanner) { ipAccessPointsAvailabilityScanner = new AccessPointsAvailabilityScanner(*this, iConnectionMonitor); } @@ -723,8 +708,6 @@ void SymbianEngine::updateAvailableAccessPoints() void SymbianEngine::accessPointScanningReady(TBool scanSuccessful, TConnMonIapInfo iapInfo) { - QMutexLocker locker(&mutex); - iUpdateGoingOn = false; if (scanSuccessful) { QList<QString> unavailableConfigs = accessPointConfigurations.keys(); @@ -736,6 +719,8 @@ void SymbianEngine::accessPointScanningReady(TBool scanSuccessful, TConnMonIapIn QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(ident); if (ptr) { unavailableConfigs.removeOne(ident); + + QMutexLocker configLocker(&ptr->mutex); if (ptr->state < QNetworkConfiguration::Active) { // Configuration is either Discovered or Active changeConfigurationStateAtMinTo(ptr, QNetworkConfiguration::Discovered); @@ -757,25 +742,28 @@ void SymbianEngine::accessPointScanningReady(TBool scanSuccessful, TConnMonIapIn if (!iFirstUpdate) { startCommsDatabaseNotifications(); - locker.unlock(); + mutex.unlock(); emit updateCompleted(); - locker.relock(); + mutex.lock(); } } void SymbianEngine::updateStatesToSnaps() { - QMutexLocker locker(&mutex); - // Go through SNAPs and set correct state to SNAPs foreach (const QString &iface, snapConfigurations.keys()) { bool discovered = false; bool active = false; QNetworkConfigurationPrivatePointer ptr = snapConfigurations.value(iface); + + QMutexLocker snapConfigLocker(&ptr->mutex); + // => Check if one of the IAPs of the SNAP is discovered or active // => If one of IAPs is active, also SNAP is active // => If one of IAPs is discovered but none of the IAPs is active, SNAP is discovered for (int i=0; i<ptr->serviceNetworkMembers.count(); i++) { + QMutexLocker configLocker(&ptr->serviceNetworkMembers[i]->mutex); + if ((ptr->serviceNetworkMembers[i]->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { active = true; @@ -798,16 +786,14 @@ void SymbianEngine::updateStatesToSnaps() bool SymbianEngine::changeConfigurationStateTo(QNetworkConfigurationPrivatePointer ptr, QNetworkConfiguration::StateFlags newState) { - QMutexLocker locker(&mutex); - ptr->mutex.lock(); if (newState != ptr->state) { ptr->state = newState; ptr->mutex.unlock(); - locker.unlock(); + mutex.unlock(); emit configurationChanged(ptr); - locker.relock(); + mutex.lock(); return true; } else { @@ -823,16 +809,14 @@ bool SymbianEngine::changeConfigurationStateTo(QNetworkConfigurationPrivatePoint bool SymbianEngine::changeConfigurationStateAtMinTo(QNetworkConfigurationPrivatePointer ptr, QNetworkConfiguration::StateFlags newState) { - QMutexLocker locker(&mutex); - ptr->mutex.lock(); if ((newState | ptr->state) != ptr->state) { ptr->state = (ptr->state | newState); ptr->mutex.unlock(); - locker.unlock(); + mutex.unlock(); emit configurationChanged(ptr); - locker.relock(); + mutex.lock(); return true; } else { @@ -849,16 +833,14 @@ bool SymbianEngine::changeConfigurationStateAtMinTo(QNetworkConfigurationPrivate bool SymbianEngine::changeConfigurationStateAtMaxTo(QNetworkConfigurationPrivatePointer ptr, QNetworkConfiguration::StateFlags newState) { - QMutexLocker locker(&mutex); - ptr->mutex.lock(); if ((newState & ptr->state) != ptr->state) { ptr->state = (newState & ptr->state); ptr->mutex.unlock(); - locker.unlock(); + mutex.unlock(); emit configurationChanged(ptr); - locker.relock(); + mutex.lock(); return true; } else { @@ -869,8 +851,6 @@ bool SymbianEngine::changeConfigurationStateAtMaxTo(QNetworkConfigurationPrivate void SymbianEngine::startCommsDatabaseNotifications() { - QMutexLocker locker(&mutex); - if (!iWaitingCommsDatabaseNotifications) { iWaitingCommsDatabaseNotifications = ETrue; if (!IsActive()) { @@ -883,19 +863,9 @@ void SymbianEngine::startCommsDatabaseNotifications() void SymbianEngine::stopCommsDatabaseNotifications() { - QMutexLocker locker(&mutex); - if (iWaitingCommsDatabaseNotifications) { iWaitingCommsDatabaseNotifications = EFalse; - if (!IsActive()) { - SetActive(); - // Make sure that notifier recorded events will not be returned - // as soon as the client issues the next RequestNotification() request. - ipCommsDB->RequestNotification(iStatus); - ipCommsDB->CancelRequestNotification(); - } else { - ipCommsDB->CancelRequestNotification(); - } + Cancel(); } } @@ -910,46 +880,48 @@ void SymbianEngine::RunL() return; } - if (iStatus != KErrCancel) { - RDbNotifier::TEvent event = STATIC_CAST(RDbNotifier::TEvent, iStatus.Int()); + RDbNotifier::TEvent event = STATIC_CAST(RDbNotifier::TEvent, iStatus.Int()); - switch (event) { - case RDbNotifier::EUnlock: /** All read locks have been removed. */ - case RDbNotifier::ECommit: /** A transaction has been committed. */ - case RDbNotifier::ERollback: /** A transaction has been rolled back */ - case RDbNotifier::ERecover: /** The database has been recovered */ + switch (event) { + case RDbNotifier::EUnlock: /** All read locks have been removed. */ + case RDbNotifier::ECommit: /** A transaction has been committed. */ + case RDbNotifier::ERollback: /** A transaction has been rolled back */ + case RDbNotifier::ERecover: /** The database has been recovered */ #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG - qDebug("QNCM CommsDB event (of type RDbNotifier::TEvent) received: %d", iStatus.Int()); + qDebug("QNCM CommsDB event (of type RDbNotifier::TEvent) received: %d", iStatus.Int()); #endif - iIgnoringUpdates = true; - // Other events than ECommit get lower priority. In practice with those events, - // we delay_before_updating methods, whereas - // with ECommit we _update_before_delaying the reaction to next event. - // Few important notes: 1) listening to only ECommit does not seem to be adequate, - // but updates will be missed. Hence other events are reacted upon too. - // 2) RDbNotifier records the most significant event, and that will be returned once - // we issue new RequestNotification, and hence updates will not be missed even - // when we are 'not reacting to them' for few seconds. - if (event == RDbNotifier::ECommit) { - TRAPD(error, updateConfigurationsL()); - if (error == KErrNone) { - updateStatesToSnaps(); - } - waitRandomTime(); - } else { - waitRandomTime(); - TRAPD(error, updateConfigurationsL()); - if (error == KErrNone) { - updateStatesToSnaps(); - } + iIgnoringUpdates = true; + // Other events than ECommit get lower priority. In practice with those events, + // we delay_before_updating methods, whereas + // with ECommit we _update_before_delaying the reaction to next event. + // Few important notes: 1) listening to only ECommit does not seem to be adequate, + // but updates will be missed. Hence other events are reacted upon too. + // 2) RDbNotifier records the most significant event, and that will be returned once + // we issue new RequestNotification, and hence updates will not be missed even + // when we are 'not reacting to them' for few seconds. + if (event == RDbNotifier::ECommit) { + TRAPD(error, updateConfigurationsL()); + if (error == KErrNone) { + updateStatesToSnaps(); + } + locker.unlock(); + waitRandomTime(); + locker.relock(); + } else { + locker.unlock(); + waitRandomTime(); + locker.relock(); + TRAPD(error, updateConfigurationsL()); + if (error == KErrNone) { + updateStatesToSnaps(); } - iIgnoringUpdates = false; // Wait time done, allow updating again - iWaitingCommsDatabaseNotifications = true; - break; - default: - // Do nothing - break; } + iIgnoringUpdates = false; // Wait time done, allow updating again + iWaitingCommsDatabaseNotifications = true; + break; + default: + // Do nothing + break; } if (iWaitingCommsDatabaseNotifications) { @@ -991,9 +963,11 @@ void SymbianEngine::EventL(const CConnMonEventBase& aEvent) QString ident = QString::number(qHash(apId)); QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(ident); if (ptr) { - QMutexLocker configLocker(&ptr->mutex); + ptr->mutex.lock(); toSymbianConfig(ptr)->connectionId = connectionId; - emit this->configurationStateChanged(toSymbianConfig(ptr)->numericId, connectionId, QNetworkSession::Connecting); + ptr->mutex.unlock(); + emit configurationStateChanged(toSymbianConfig(ptr)->numericIdentifier(), + connectionId, QNetworkSession::Connecting); } } else if (connectionStatus == KLinkLayerOpen) { // Connection has been successfully opened @@ -1006,13 +980,17 @@ void SymbianEngine::EventL(const CConnMonEventBase& aEvent) QString ident = QString::number(qHash(apId)); QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(ident); if (ptr) { - QMutexLocker configLocker(&ptr->mutex); + ptr->mutex.lock(); toSymbianConfig(ptr)->connectionId = connectionId; + ptr->mutex.unlock(); + // Configuration is Active if (changeConfigurationStateTo(ptr, QNetworkConfiguration::Active)) { updateStatesToSnaps(); } - emit this->configurationStateChanged(toSymbianConfig(ptr)->numericId, connectionId, QNetworkSession::Connected); + emit configurationStateChanged(toSymbianConfig(ptr)->numericIdentifier(), + connectionId, QNetworkSession::Connected); + if (!iOnline) { iOnline = true; emit this->onlineStateChanged(iOnline); @@ -1022,8 +1000,8 @@ void SymbianEngine::EventL(const CConnMonEventBase& aEvent) TUint connectionId = realEvent->ConnectionId(); QNetworkConfigurationPrivatePointer ptr = dataByConnectionId(connectionId); if (ptr) { - QMutexLocker configLocker(&ptr->mutex); - emit this->configurationStateChanged(toSymbianConfig(ptr)->numericId, connectionId, QNetworkSession::Closing); + emit configurationStateChanged(toSymbianConfig(ptr)->numericIdentifier(), + connectionId, QNetworkSession::Closing); } } else if (connectionStatus == KLinkLayerClosed || connectionStatus == KConnectionClosed) { @@ -1037,8 +1015,8 @@ void SymbianEngine::EventL(const CConnMonEventBase& aEvent) updateStatesToSnaps(); } - QMutexLocker configLocker(&ptr->mutex); - emit this->configurationStateChanged(toSymbianConfig(ptr)->numericId, connectionId, QNetworkSession::Disconnected); + emit configurationStateChanged(toSymbianConfig(ptr)->numericIdentifier(), + connectionId, QNetworkSession::Disconnected); } bool online = false; @@ -1121,6 +1099,8 @@ void SymbianEngine::EventL(const CConnMonEventBase& aEvent) // manager). Currently only 'Disconnected' state is of interest because it has proven to be troublesome. void SymbianEngine::configurationStateChangeReport(TUint32 accessPointId, QNetworkSession::State newState) { + QMutexLocker locker(&mutex); + #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG qDebug() << "QNCM A session reported state change for IAP ID: " << accessPointId << " whose new state is: " << newState; #endif @@ -1135,10 +1115,11 @@ void SymbianEngine::configurationStateChangeReport(TUint32 accessPointId, QNetwo updateStatesToSnaps(); } - QMutexLocker configLocker(&ptr->mutex); - emit this->configurationStateChanged(toSymbianConfig(ptr)->numericId, - toSymbianConfig(ptr)->connectionId, - QNetworkSession::Disconnected); + locker.unlock(); + emit configurationStateChanged(toSymbianConfig(ptr)->numericIdentifier(), + toSymbianConfig(ptr)->connectionIdentifier(), + QNetworkSession::Disconnected); + locker.relock(); } } break; @@ -1150,28 +1131,23 @@ void SymbianEngine::configurationStateChangeReport(TUint32 accessPointId, QNetwo // Waits for 2..6 seconds. void SymbianEngine::waitRandomTime() { - iTimeToWait = (qAbs(qrand()) % 7) * 1000; - if (iTimeToWait < 2000) { - iTimeToWait = 2000; - } + int iTimeToWait = qMax(2000, (qAbs(qrand()) % 7) * 1000); #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG qDebug("QNCM waiting random time: %d ms", iTimeToWait); #endif - QTimer::singleShot(iTimeToWait, iIgnoreEventLoop, SLOT(quit())); - iIgnoreEventLoop->exec(); + QEventLoop loop; + QTimer::singleShot(iTimeToWait, &loop, SLOT(quit())); + loop.exec(); } QNetworkConfigurationPrivatePointer SymbianEngine::dataByConnectionId(TUint aConnectionId) { - QMutexLocker locker(&mutex); - QNetworkConfiguration item; QHash<QString, QNetworkConfigurationPrivatePointer>::const_iterator i = accessPointConfigurations.constBegin(); while (i != accessPointConfigurations.constEnd()) { QNetworkConfigurationPrivatePointer ptr = i.value(); - QMutexLocker configLocker(&ptr->mutex); - if (toSymbianConfig(ptr)->connectionId == aConnectionId) + if (toSymbianConfig(ptr)->connectionIdentifier() == aConnectionId) return ptr; ++i; @@ -1218,6 +1194,8 @@ void AccessPointsAvailabilityScanner::StartScanning() void AccessPointsAvailabilityScanner::RunL() { + QMutexLocker locker(&iOwner.mutex); + if (iStatus.Int() != KErrNone) { iIapBuf().iCount = 0; iOwner.accessPointScanningReady(false,iIapBuf()); diff --git a/src/plugins/bearer/symbian/symbianengine.h b/src/plugins/bearer/symbian/symbianengine.h index 7d565db..18fd249 100644 --- a/src/plugins/bearer/symbian/symbianengine.h +++ b/src/plugins/bearer/symbian/symbianengine.h @@ -87,7 +87,23 @@ public: QString bearerName() const; - QNetworkConfigurationPrivatePointer serviceNetworkPtr; + inline TUint32 numericIdentifier() const + { + QMutexLocker locker(&mutex); + return numericId; + } + + inline TUint connectionIdentifier() const + { + QMutexLocker locker(&mutex); + return connectionId; + } + + inline QString configMappingName() const + { + QMutexLocker locker(&mutex); + return mappingName; + } QString mappingName; @@ -196,11 +212,11 @@ private: // Data TBool iInitOk; TBool iUpdateGoingOn; TBool iIgnoringUpdates; - TUint iTimeToWait; - QEventLoop* iIgnoreEventLoop; AccessPointsAvailabilityScanner* ipAccessPointsAvailabilityScanner; - + + QNetworkConfigurationPrivatePointer defaultConfig; + friend class QNetworkSessionPrivate; friend class AccessPointsAvailabilityScanner; friend class QNetworkSessionPrivateImpl; diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml new file mode 100644 index 0000000..0273282 --- /dev/null +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml @@ -0,0 +1,74 @@ +import Qt 4.7 + +Item { + id:lineedit + property alias text: textEdit.text + + width: 240 + 11 //Should be set manually in most cases + height: textEdit.height + 11 + + Rectangle{ + color: 'lightsteelblue' + anchors.fill: parent + } + clip: true + Component.onCompleted: textEdit.cursorPosition = 0; + TextEdit{ + id:textEdit + cursorDelegate: Item{ + Rectangle{ + visible: parent.parent.focus + color: "#009BCE" + height: 13 + width: 2 + y: 1 + } + } + property int leftMargin: 6 + property int topMargin: 6 + property int rightMargin: 6 + property int bottomMargin: 6 + x: leftMargin + width: parent.width - leftMargin - rightMargin; + y: 5 + //Below function implements all scrolling logic + onCursorPositionChanged: { + if(cursorRectangle.y < topMargin - textEdit.y){//Cursor went off the front + textEdit.y = topMargin - Math.max(0, cursorRectangle.y); + }else if(cursorRectangle.y > parent.height - topMargin - bottomMargin - textEdit.y){//Cursor went off the end + textEdit.y = topMargin - Math.max(0, cursorRectangle.y - (parent.height - topMargin - bottomMargin)) - cursorRectangle.height; + } + } + + text:"" + horizontalAlignment: TextInput.AlignLeft + wrapMode: TextEdit.WordWrap + font.pixelSize:15 + } + MouseArea{ + //Implements all line edit mouse handling + id: mainMouseArea + anchors.fill: parent; + function translateY(y){ + return y - textEdit.y + } + function translateX(x){ + return x - textEdit.x + } + onPressed: { + textEdit.focus = true; + textEdit.cursorPosition = textEdit.positionAt(translateX(mouse.x), translateY(mouse.y)); + } + onPositionChanged: { + textEdit.moveCursorSelection(textEdit.positionAt(translateX(mouse.x), translateY(mouse.y))); + } + onReleased: { + } + onDoubleClicked: { + textEdit.selectionStart=0; + textEdit.selectionEnd=textEdit.text.length; + } + z: textEdit.z + 1 + } + +} diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/usingMultilineEdit.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/usingMultilineEdit.qml new file mode 100644 index 0000000..47b48d8 --- /dev/null +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/usingMultilineEdit.qml @@ -0,0 +1,13 @@ +import Qt 4.7 + +Rectangle{ + width: 600 + height: 200 + Column{ + MultilineEdit{ + text: 'I am the very model of a modern major general. I\'ve information vegetable, animal and mineral. I know the kings of england and I quote the fights historical - from Marathon to Waterloo in order categorical.'; + width: 182; height: 60; + } + MultilineEdit{text: 'Hello world'} + } +} diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml index 31f24ec..cc0ad3c 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml @@ -50,10 +50,10 @@ Item { } onPressed: { textInp.focus = true; - textInp.cursorPosition = textInp.xToPosition(translateX(mouse.x)); + textInp.cursorPosition = textInp.positionAt(translateX(mouse.x)); } onPositionChanged: { - textInp.moveCursorSelection(textInp.xToPosition(translateX(mouse.x))); + textInp.moveCursorSelection(textInp.positionAt(translateX(mouse.x))); } onReleased: { } diff --git a/tests/auto/qtextlayout/tst_qtextlayout.cpp b/tests/auto/qtextlayout/tst_qtextlayout.cpp index caf9bd3..1a5f493 100644 --- a/tests/auto/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/qtextlayout/tst_qtextlayout.cpp @@ -110,6 +110,8 @@ private slots: void longText(); void widthOfTabs(); void columnWrapWithTabs(); + void boundingRectForUnsetLineWidth(); + void boundingRectForSetLineWidth(); // QTextLine stuff void setNumColumnsWrapAtWordBoundaryOrAnywhere(); @@ -1307,6 +1309,29 @@ void tst_QTextLayout::columnWrapWithTabs() } +void tst_QTextLayout::boundingRectForUnsetLineWidth() +{ + QTextLayout layout("FOOBAR"); + + layout.beginLayout(); + QTextLine line = layout.createLine(); + layout.endLayout(); + + QCOMPARE(layout.boundingRect().width(), line.naturalTextWidth()); +} + +void tst_QTextLayout::boundingRectForSetLineWidth() +{ + QTextLayout layout("FOOBAR"); + + layout.beginLayout(); + QTextLine line = layout.createLine(); + line.setLineWidth(QFIXED_MAX - 1); + layout.endLayout(); + + QCOMPARE(layout.boundingRect().width(), qreal(QFIXED_MAX - 1)); +} + void tst_QTextLayout::lineWidthFromBOM() { const QString string(QChar(0xfeff)); // BYTE ORDER MARK diff --git a/tools/assistant/tools/assistant/doc/images/assistant-assistant.png b/tools/assistant/tools/assistant/doc/images/assistant-assistant.png Binary files differindex b825de0..1ff5cc9 100644 --- a/tools/assistant/tools/assistant/doc/images/assistant-assistant.png +++ b/tools/assistant/tools/assistant/doc/images/assistant-assistant.png diff --git a/tools/porting/src/codemodel.h b/tools/porting/src/codemodel.h index cb3088f..04ad178 100644 --- a/tools/porting/src/codemodel.h +++ b/tools/porting/src/codemodel.h @@ -96,7 +96,7 @@ class Collection: public QMultiHash<QByteArray, CollectedType *> { public: void add(CollectedType *collectedItem) - { insert(collectedItem->name(), collectedItem); } + { this->insert(collectedItem->name(), collectedItem); } }; typedef Collection<Scope> ScopeCollection; |