From a74b55ca2c5a67cb273d77e9be39d987e765468e Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 11 Nov 2009 14:44:45 +1000 Subject: Get rid of the extra directory. --- src/declarative/declarative.pro | 1 - src/declarative/extra/extra.pri | 20 - src/declarative/extra/qmlbehavior.cpp | 157 ------ src/declarative/extra/qmlbehavior_p.h | 84 --- src/declarative/extra/qmldatetimeformatter.cpp | 370 ------------- src/declarative/extra/qmldatetimeformatter_p.h | 116 ---- src/declarative/extra/qmlfontloader.cpp | 219 -------- src/declarative/extra/qmlfontloader_p.h | 94 ---- src/declarative/extra/qmlnumberformatter.cpp | 215 -------- src/declarative/extra/qmlnumberformatter_p.h | 92 ---- src/declarative/extra/qmlxmllistmodel.cpp | 727 ------------------------- src/declarative/extra/qmlxmllistmodel_p.h | 134 ----- src/declarative/extra/qnumberformat.cpp | 225 -------- src/declarative/extra/qnumberformat_p.h | 173 ------ src/declarative/util/qmlbehavior.cpp | 157 ++++++ src/declarative/util/qmlbehavior_p.h | 84 +++ src/declarative/util/qmldatetimeformatter.cpp | 370 +++++++++++++ src/declarative/util/qmldatetimeformatter_p.h | 116 ++++ src/declarative/util/qmlfontloader.cpp | 219 ++++++++ src/declarative/util/qmlfontloader_p.h | 94 ++++ src/declarative/util/qmlnumberformatter.cpp | 215 ++++++++ src/declarative/util/qmlnumberformatter_p.h | 92 ++++ src/declarative/util/qmlxmllistmodel.cpp | 727 +++++++++++++++++++++++++ src/declarative/util/qmlxmllistmodel_p.h | 134 +++++ src/declarative/util/qnumberformat.cpp | 225 ++++++++ src/declarative/util/qnumberformat_p.h | 173 ++++++ src/declarative/util/util.pri | 20 +- 27 files changed, 2624 insertions(+), 2629 deletions(-) delete mode 100644 src/declarative/extra/extra.pri delete mode 100644 src/declarative/extra/qmlbehavior.cpp delete mode 100644 src/declarative/extra/qmlbehavior_p.h delete mode 100644 src/declarative/extra/qmldatetimeformatter.cpp delete mode 100644 src/declarative/extra/qmldatetimeformatter_p.h delete mode 100644 src/declarative/extra/qmlfontloader.cpp delete mode 100644 src/declarative/extra/qmlfontloader_p.h delete mode 100644 src/declarative/extra/qmlnumberformatter.cpp delete mode 100644 src/declarative/extra/qmlnumberformatter_p.h delete mode 100644 src/declarative/extra/qmlxmllistmodel.cpp delete mode 100644 src/declarative/extra/qmlxmllistmodel_p.h delete mode 100644 src/declarative/extra/qnumberformat.cpp delete mode 100644 src/declarative/extra/qnumberformat_p.h create mode 100644 src/declarative/util/qmlbehavior.cpp create mode 100644 src/declarative/util/qmlbehavior_p.h create mode 100644 src/declarative/util/qmldatetimeformatter.cpp create mode 100644 src/declarative/util/qmldatetimeformatter_p.h create mode 100644 src/declarative/util/qmlfontloader.cpp create mode 100644 src/declarative/util/qmlfontloader_p.h create mode 100644 src/declarative/util/qmlnumberformatter.cpp create mode 100644 src/declarative/util/qmlnumberformatter_p.h create mode 100644 src/declarative/util/qmlxmllistmodel.cpp create mode 100644 src/declarative/util/qmlxmllistmodel_p.h create mode 100644 src/declarative/util/qnumberformat.cpp create mode 100644 src/declarative/util/qnumberformat_p.h diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index 41fee96..e5e604b 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -19,7 +19,6 @@ include(3rdparty/3rdparty.pri) include(util/util.pri) include(graphicsitems/graphicsitems.pri) include(qml/qml.pri) -include(extra/extra.pri) include(widgets/widgets.pri) include(debugger/debugger.pri) diff --git a/src/declarative/extra/extra.pri b/src/declarative/extra/extra.pri deleted file mode 100644 index 85ff6ea..0000000 --- a/src/declarative/extra/extra.pri +++ /dev/null @@ -1,20 +0,0 @@ -SOURCES += \ - extra/qnumberformat.cpp \ - extra/qmlnumberformatter.cpp \ - extra/qmldatetimeformatter.cpp \ - extra/qmlbehavior.cpp \ - extra/qmlfontloader.cpp - -HEADERS += \ - extra/qnumberformat_p.h \ - extra/qmlnumberformatter_p.h \ - extra/qmldatetimeformatter_p.h \ - extra/qmlbehavior_p.h \ - extra/qmlfontloader_p.h - -contains(QT_CONFIG, xmlpatterns) { - QT+=xmlpatterns - SOURCES += extra/qmlxmllistmodel.cpp - HEADERS += extra/qmlxmllistmodel_p.h -} - diff --git a/src/declarative/extra/qmlbehavior.cpp b/src/declarative/extra/qmlbehavior.cpp deleted file mode 100644 index 8364d8c..0000000 --- a/src/declarative/extra/qmlbehavior.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/**************************************************************************** -** -** 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 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$ -** -****************************************************************************/ - -#include -#include -#include -#include "qmlbehavior_p.h" -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QML_DEFINE_TYPE(Qt,4,6,Behavior,QmlBehavior) - -class QmlBehaviorPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlBehavior) -public: - QmlBehaviorPrivate() : animation(0) {} - - QmlMetaProperty property; - QVariant currentValue; - QmlAbstractAnimation *animation; -}; - -/*! - \qmlclass Behavior QmlBehavior - \brief The Behavior element allows you to specify a default animation for a property change. - - In example below, the rect will use a bounce easing curve over 200 millisecond for any changes to its y property: - \code - Rectangle { - width: 20; height: 20 - color: "#00ff00" - y: 200 //initial value - y: Behavior { - NumberAnimation { - easing: "easeOutBounce(amplitude:100)" - duration: 200 - } - } - } - \endcode -*/ - - -QmlBehavior::QmlBehavior(QObject *parent) - : QObject(*(new QmlBehaviorPrivate), parent) -{ -} - -QmlBehavior::~QmlBehavior() -{ -} - -/*! - \qmlproperty Animation Behavior::animation - \default - - The animation to use when the behavior is triggered. -*/ - -QmlAbstractAnimation *QmlBehavior::animation() -{ - Q_D(QmlBehavior); - return d->animation; -} - -void QmlBehavior::setAnimation(QmlAbstractAnimation *animation) -{ - Q_D(QmlBehavior); - if (d->animation) { - qmlInfo(this) << tr("Can't change the animation assigned to a Behavior."); - return; - } - - d->animation = animation; - if (d->animation) - d->animation->setTarget(d->property); -} - -void QmlBehavior::write(const QVariant &value) -{ - Q_D(QmlBehavior); - if (!d->animation) { - d->property.write(value, QmlMetaProperty::BypassInterceptor | QmlMetaProperty::DontRemoveBinding); - return; - } - - d->currentValue = d->property.read(); - - d->animation->qtAnimation()->stop(); - - QmlStateOperation::ActionList actions; - Action action; - action.property = d->property; - action.fromValue = d->currentValue; - action.toValue = value; - actions << action; - - QList after; - if (d->animation) - d->animation->transition(actions, after, QmlAbstractAnimation::Forward); - d->animation->qtAnimation()->start(); - if (!after.contains(d->property)) - d->property.write(value, QmlMetaProperty::BypassInterceptor | QmlMetaProperty::DontRemoveBinding); -} - -void QmlBehavior::setTarget(const QmlMetaProperty &property) -{ - Q_D(QmlBehavior); - d->property = property; - d->currentValue = property.read(); - if (d->animation) - d->animation->setTarget(property); -} - -QT_END_NAMESPACE diff --git a/src/declarative/extra/qmlbehavior_p.h b/src/declarative/extra/qmlbehavior_p.h deleted file mode 100644 index 9f85f84..0000000 --- a/src/declarative/extra/qmlbehavior_p.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** 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 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$ -** -****************************************************************************/ - -#ifndef QMLBEHAVIOR_H -#define QMLBEHAVIOR_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlAbstractAnimation; -class QmlBehaviorPrivate; -class Q_DECLARATIVE_EXPORT QmlBehavior : public QObject, public QmlPropertyValueInterceptor -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlBehavior) - - Q_INTERFACES(QmlPropertyValueInterceptor) - Q_CLASSINFO("DefaultProperty", "animation") - Q_PROPERTY(QmlAbstractAnimation *animation READ animation WRITE setAnimation) - -public: - QmlBehavior(QObject *parent=0); - ~QmlBehavior(); - - virtual void setTarget(const QmlMetaProperty &); - virtual void write(const QVariant &value); - - QmlAbstractAnimation *animation(); - void setAnimation(QmlAbstractAnimation *); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlBehavior) - -QT_END_HEADER - -#endif // QMLBEHAVIOR_H diff --git a/src/declarative/extra/qmldatetimeformatter.cpp b/src/declarative/extra/qmldatetimeformatter.cpp deleted file mode 100644 index 983287e..0000000 --- a/src/declarative/extra/qmldatetimeformatter.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/**************************************************************************** -** -** 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 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$ -** -****************************************************************************/ - -#include "qmldatetimeformatter_p.h" -#include "private/qobject_p.h" -#include - -QT_BEGIN_NAMESPACE - -//TODO: may need optimisation as the QDateTime member may not be needed? -// be able to set a locale? - -class QmlDateTimeFormatterPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlDateTimeFormatter) -public: - QmlDateTimeFormatterPrivate() : locale(QLocale::system()), longStyle(false), componentComplete(true) {} - - void updateText(); - - QDateTime dateTime; - QDate date; - QTime time; - QLocale locale; - QString dateTimeText; - QString dateText; - QString timeText; - QString dateTimeFormat; //set for convienience? - QString dateFormat; - QString timeFormat; - bool longStyle; - bool componentComplete; -}; - -/*! - \qmlclass DateTimeFormatter QmlDateTimeFormatter - \brief The DateTimeFormatter allows you to control the format of a date string. - - \code - DateTimeFormatter { id: formatter; date: System.date } - Text { text: formatter.dateText } - \endcode - - By default, the text properties (dateText, timeText, and dateTimeText) will return the - date and time using the current system locale's format. -*/ - -/*! - \internal - \class QmlDateTimeFormatter - \ingroup group_utility - \brief The QmlDateTimeFormatter class allows you to format a date string. -*/ - -QmlDateTimeFormatter::QmlDateTimeFormatter(QObject *parent) -: QObject(*(new QmlDateTimeFormatterPrivate), parent) -{ -} - -QmlDateTimeFormatter::~QmlDateTimeFormatter() -{ -} - -/*! - \qmlproperty string DateTimeFormatter::dateText - \qmlproperty string DateTimeFormatter::timeText - \qmlproperty string DateTimeFormatter::dateTimeText - - Formatted text representations of the \c date, \c time, - and \c {date and time}, respectively. - - If there is no explictly specified format the DateTimeFormatter - will use the system locale's default 'short' setting. - - \code - // specify source date (assuming today is February 19, 2009) - DateTimeFormatter { id: formatter; dateTime: Today.date } - - // display the full date and time - Text { text: formatter.dateText } - \endcode - - Would be equivalent to the following for a US English locale: - - \code - // display the date - Text { text: "2/19/09" } - \endcode -*/ -QString QmlDateTimeFormatter::dateTimeText() const -{ - Q_D(const QmlDateTimeFormatter); - return d->dateTimeText; -} - -QString QmlDateTimeFormatter::dateText() const -{ - Q_D(const QmlDateTimeFormatter); - return d->dateText; -} - -QString QmlDateTimeFormatter::timeText() const -{ - Q_D(const QmlDateTimeFormatter); - return d->timeText; -} - -/*! - \qmlproperty date DateTimeFormatter::date - \qmlproperty time DateTimeFormatter::time - \qmlproperty datetime DateTimeFormatter::dateTime - - The source date and time to be used by the formatter. - - \code - // setting the date and time - DateTimeFormatter { date: System.date; time: System.time } - \endcode - - For convienience it is possible to set the datetime property to set both the date and the time. - \code - // setting the datetime - DateTimeFormatter { dateTime: System.dateTime } - \endcode - - There can only be one instance of date and time per formatter; if date, time, and dateTime are all - set the actual date and time used is not guaranteed. - - \note If no date is set, dateTimeText will be just the date; - If no time is set, the dateTimeText will be just the time. - -*/ -QDate QmlDateTimeFormatter::date() const -{ - Q_D(const QmlDateTimeFormatter); - return d->date; -} - -QTime QmlDateTimeFormatter::time() const -{ - Q_D(const QmlDateTimeFormatter); - return d->time; -} - -QDateTime QmlDateTimeFormatter::dateTime() const -{ - Q_D(const QmlDateTimeFormatter); - return d->dateTime; -} - -/*! - \qmlproperty string DateTimeFormatter::dateFormat - \qmlproperty string DateTimeFormatter::timeFormat - \qmlproperty string DateTimeFormatter::dateTimeFormat - - Specifies a custom format which the DateTime Formatter can use. - - If there is no explictly specified format the DateTimeFormatter - will use the system locale's default 'short' setting. - - The text's format may be modified by setting: - \list - \i \c dateFormat - \i \c timeFormat - \i \c dateTimeFormat - \endlist - - If only the format for date is defined, the time and dateTime formats will be defined - as the system locale default and likewise for the others. - - Syntax for the format is based on the QDateTime::toString() formatting options. - - \code - // Format the date such that the dateText is: '1997-12-12' - DateTimeFormatter { id: formatter; dateTime: Today.dateTime; formatDate: "yyyy-MM-d" } - \endcode - - Assigning an empty string to a particular format will reset it. -*/ -QString QmlDateTimeFormatter::dateTimeFormat() const -{ - Q_D(const QmlDateTimeFormatter); - return d->dateTimeFormat; -} - -QString QmlDateTimeFormatter::dateFormat() const -{ - Q_D(const QmlDateTimeFormatter); - return d->dateFormat; -} - -QString QmlDateTimeFormatter::timeFormat() const -{ - Q_D(const QmlDateTimeFormatter); - return d->timeFormat; -} - -/*! - \qmlproperty bool DateTimeFormatter::longStyle - - This property causes the formatter to use the system locale's long format rather than short format - by default. - - This setting is off by default. -*/ -bool QmlDateTimeFormatter::longStyle() const -{ - Q_D(const QmlDateTimeFormatter); - return d->longStyle; -} - -void QmlDateTimeFormatter::setDateTime(const QDateTime &dateTime) -{ - Q_D(QmlDateTimeFormatter); - if (d->dateTime == dateTime) - return; - d->dateTime = dateTime; - d->date = d->dateTime.date(); - d->time = d->dateTime.time(); - d->updateText(); -} - -void QmlDateTimeFormatter::setTime(const QTime &time) -{ - Q_D(QmlDateTimeFormatter); - if (d->dateTime.time() == time) - return; - d->time = time; - d->dateTime.setTime(time); - d->updateText(); -} - -void QmlDateTimeFormatter::setDate(const QDate &date) -{ - Q_D(QmlDateTimeFormatter); - if (d->dateTime.date() == date) - return; - d->date = date; - bool clearTime = d->dateTime.time().isValid() ? false : true; //because setting date generates default time - d->dateTime.setDate(date); - if (clearTime) - d->dateTime.setTime(QTime()); - d->updateText(); -} - -//DateTime formatting may be a combination of date and time? -void QmlDateTimeFormatter::setDateTimeFormat(const QString &format) -{ - Q_D(QmlDateTimeFormatter); - //no format checking - d->dateTimeFormat = format; - d->updateText(); -} - -void QmlDateTimeFormatter::setDateFormat(const QString &format) -{ - Q_D(QmlDateTimeFormatter); - //no format checking - d->dateFormat = format; - d->updateText(); -} - -void QmlDateTimeFormatter::setTimeFormat(const QString &format) -{ - Q_D(QmlDateTimeFormatter); - //no format checking - d->timeFormat = format; - d->updateText(); -} - -void QmlDateTimeFormatter::setLongStyle(bool longStyle) -{ - Q_D(QmlDateTimeFormatter); - d->longStyle = longStyle; - d->updateText(); -} - -void QmlDateTimeFormatterPrivate::updateText() -{ - Q_Q(QmlDateTimeFormatter); - if (!componentComplete) - return; - - QString str; - QString str1; - QString str2; - - Qt::DateFormat defaultFormat = longStyle ? Qt::SystemLocaleLongDate : Qt::SystemLocaleShortDate; - - if (dateFormat.isEmpty()) - str1 = date.toString(defaultFormat); - else - str1 = date.toString(dateFormat); - - if (timeFormat.isEmpty()) - str2 = time.toString(defaultFormat); - else - str2 = time.toString(timeFormat); - - if (dateTimeFormat.isEmpty()) - str = dateTime.toString(defaultFormat); - //else if (!formatTime.isEmpty() && !formatDate.isEmpty()) - // str = str1 + QLatin1Char(' ') + str2; - else - str = dateTime.toString(dateTimeFormat); - - if (dateTimeText == str && dateText == str1 && timeText == str2) - return; - - dateTimeText = str; - dateText = str1; - timeText = str2; - - emit q->textChanged(); -} - -void QmlDateTimeFormatter::classBegin() -{ - Q_D(QmlDateTimeFormatter); - d->componentComplete = false; -} - -void QmlDateTimeFormatter::componentComplete() -{ - Q_D(QmlDateTimeFormatter); - d->componentComplete = true; - d->updateText(); -} - -QML_DEFINE_TYPE(Qt,4,6,DateTimeFormatter,QmlDateTimeFormatter) - -QT_END_NAMESPACE diff --git a/src/declarative/extra/qmldatetimeformatter_p.h b/src/declarative/extra/qmldatetimeformatter_p.h deleted file mode 100644 index e350f96..0000000 --- a/src/declarative/extra/qmldatetimeformatter_p.h +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** 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 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$ -** -****************************************************************************/ - -#ifndef QMLDATETIMEFORMATTER_H -#define QMLDATETIMEFORMATTER_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlDateTimeFormatterPrivate; -class Q_DECLARATIVE_EXPORT QmlDateTimeFormatter : public QObject, public QmlParserStatus -{ - Q_OBJECT - Q_INTERFACES(QmlParserStatus) - - Q_PROPERTY(QString dateText READ dateText NOTIFY textChanged) - Q_PROPERTY(QString timeText READ timeText NOTIFY textChanged) - Q_PROPERTY(QString dateTimeText READ dateTimeText NOTIFY textChanged) - Q_PROPERTY(QDate date READ date WRITE setDate) - Q_PROPERTY(QTime time READ time WRITE setTime) - Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime) - Q_PROPERTY(QString dateFormat READ dateFormat WRITE setDateFormat) - Q_PROPERTY(QString timeFormat READ timeFormat WRITE setTimeFormat) - Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat) - Q_PROPERTY(bool longStyle READ longStyle WRITE setLongStyle) -public: - QmlDateTimeFormatter(QObject *parent=0); - ~QmlDateTimeFormatter(); - - QString dateTimeText() const; - QString dateText() const; - QString timeText() const; - - QDate date() const; - void setDate(const QDate &); - - QTime time() const; - void setTime(const QTime &); - - QDateTime dateTime() const; - void setDateTime(const QDateTime &); - - QString dateTimeFormat() const; - void setDateTimeFormat(const QString &); - - QString dateFormat() const; - void setDateFormat(const QString &); - - QString timeFormat() const; - void setTimeFormat(const QString &); - - bool longStyle() const; - void setLongStyle(bool); - - virtual void classBegin(); - virtual void componentComplete(); - -Q_SIGNALS: - void textChanged(); - -private: - Q_DISABLE_COPY(QmlDateTimeFormatter) - Q_DECLARE_PRIVATE(QmlDateTimeFormatter) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlDateTimeFormatter) - -QT_END_HEADER - -#endif diff --git a/src/declarative/extra/qmlfontloader.cpp b/src/declarative/extra/qmlfontloader.cpp deleted file mode 100644 index 36ee1bb..0000000 --- a/src/declarative/extra/qmlfontloader.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/**************************************************************************** -** -** 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 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$ -** -****************************************************************************/ - -#include "private/qobject_p.h" -#include "qmlfontloader_p.h" -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QmlFontLoaderPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlFontLoader) - -public: - QmlFontLoaderPrivate() : reply(0), status(QmlFontLoader::Null) {} - - void addFontToDatabase(const QByteArray &); - - QUrl url; - QString name; - QNetworkReply *reply; - QmlFontLoader::Status status; -}; - -QML_DEFINE_TYPE(Qt,4,6,FontLoader,QmlFontLoader) - -/*! - \qmlclass FontLoader QmlFontLoader - \ingroup group_utility - \brief This item allows using fonts by name or url. - - Example: - \qml - FontLoader { id: fixedFont; name: "Courier" } - FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" } - - Text { text: "Fixed-size font"; font.family: fixedFont.name } - Text { text: "Fancy font"; font.family: webFont.name } - \endqml -*/ -QmlFontLoader::QmlFontLoader(QObject *parent) - : QObject(*(new QmlFontLoaderPrivate), parent) -{ -} - -QmlFontLoader::~QmlFontLoader() -{ -} - -static QString toLocalFileOrQrc(const QUrl& url) -{ - QString r = url.toLocalFile(); - if (r.isEmpty() && url.scheme() == QLatin1String("qrc")) - r = QLatin1Char(':') + url.path(); - return r; -} - - -/*! - \qmlproperty url FontLoader::source - The url of the font to load. -*/ -QUrl QmlFontLoader::source() const -{ - Q_D(const QmlFontLoader); - return d->url; -} - -void QmlFontLoader::setSource(const QUrl &url) -{ - Q_D(QmlFontLoader); - if (url == d->url) - return; - d->url = qmlContext(this)->resolvedUrl(url); - - d->status = Loading; - emit statusChanged(); -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - QString lf = toLocalFileOrQrc(d->url); - if (!lf.isEmpty()) { - QFile file(lf); - file.open(QIODevice::ReadOnly); - QByteArray ba = file.readAll(); - d->addFontToDatabase(ba); - } else -#endif - { - QNetworkRequest req(d->url); - d->reply = qmlEngine(this)->networkAccessManager()->get(req); - QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(replyFinished())); - } -} - -/*! - \qmlproperty string FontLoader::name - - This property holds the name of the font family. - It is set automatically when a font is loaded using the \c url property. - - Use this to set the \c font.family property of a \c Text item. - - Example: - \qml - FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" } - Text { text: "Fancy font"; font.family: webFont.name } - \endqml -*/ -QString QmlFontLoader::name() const -{ - Q_D(const QmlFontLoader); - return d->name; -} - -void QmlFontLoader::setName(const QString &name) -{ - Q_D(QmlFontLoader); - if (d->name == name ) - return; - d->name = name; - emit nameChanged(); - d->status = Ready; - emit statusChanged(); -} - -/*! - \qmlproperty enum FontLoader::status - - This property holds the status of font loading. It can be one of: - \list - \o Null - no font has been set - \o Ready - the font has been loaded - \o Loading - the font is currently being loaded - \o Error - an error occurred while loading the font - \endlist -*/ -QmlFontLoader::Status QmlFontLoader::status() const -{ - Q_D(const QmlFontLoader); - return d->status; -} - -void QmlFontLoader::replyFinished() -{ - Q_D(QmlFontLoader); - if (d->reply) { - if (!d->reply->error()) { - QByteArray ba = d->reply->readAll(); - d->addFontToDatabase(ba); - } else { - d->status = Error; - emit statusChanged(); - } - d->reply->deleteLater(); - d->reply = 0; - } -} - -void QmlFontLoaderPrivate::addFontToDatabase(const QByteArray &ba) -{ - Q_Q(QmlFontLoader); - - int id = QFontDatabase::addApplicationFontFromData(ba); - if (id != -1) { - name = QFontDatabase::applicationFontFamilies(id).at(0); - emit q->nameChanged(); - status = QmlFontLoader::Ready; - } else { - status = QmlFontLoader::Error; - qWarning() << "Cannot load font:" << url; - } - emit q->statusChanged(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/extra/qmlfontloader_p.h b/src/declarative/extra/qmlfontloader_p.h deleted file mode 100644 index d02a181..0000000 --- a/src/declarative/extra/qmlfontloader_p.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** 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 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$ -** -****************************************************************************/ - -#ifndef QMLFONTLOADER_H -#define QMLFONTLOADER_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlFontLoaderPrivate; -class Q_DECLARATIVE_EXPORT QmlFontLoader : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlFontLoader) - Q_ENUMS(Status) - - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - -public: - enum Status { Null = 0, Ready, Loading, Error }; - - QmlFontLoader(QObject *parent = 0); - ~QmlFontLoader(); - - QUrl source() const; - void setSource(const QUrl &url); - - QString name() const; - void setName(const QString &name); - - Status status() const; - -private Q_SLOTS: - void replyFinished(); - -Q_SIGNALS: - void nameChanged(); - void statusChanged(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlFontLoader) - -QT_END_HEADER - -#endif // QMLFONTLOADER_H - diff --git a/src/declarative/extra/qmlnumberformatter.cpp b/src/declarative/extra/qmlnumberformatter.cpp deleted file mode 100644 index b09be5b..0000000 --- a/src/declarative/extra/qmlnumberformatter.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/**************************************************************************** -** -** 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 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$ -** -****************************************************************************/ - -#include "qmlnumberformatter_p.h" -#include "private/qobject_p.h" - -QT_BEGIN_NAMESPACE - -//TODO: set locale -// docs -// this is a wrapper around qnumberformat (test integration) -// if number or format haven't been explictly set, text should be an empty string - -class QmlNumberFormatterPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlNumberFormatter) -public: - QmlNumberFormatterPrivate() : locale(QLocale::system()), number(0), componentComplete(true) {} - - void updateText(); - - QLocale locale; - QString format; - QNumberFormat numberFormat; - QString text; - qreal number; - bool componentComplete; -}; -/*! - \qmlclass NumberFormatter - \brief The NumberFormatter allows you to control the format of a number string. - - The format property documentation has more details on how the format can be manipulated. - - In the following example, the text element will display the text "1,234.57". - \code - NumberFormatter { id: formatter; number: 1234.5678; format: "##,##0.##" } - Text { text: formatter.text } - \endcode - - */ -/*! - \internal - \class QmlNumberFormatter - \ingroup group_utility - \brief The QmlNumberFormatter class allows you to format a number to a particular string format/locale specific number format. -*/ - -QmlNumberFormatter::QmlNumberFormatter(QObject *parent) -: QObject(*(new QmlNumberFormatterPrivate), parent) -{ -} - -QmlNumberFormatter::~QmlNumberFormatter() -{ -} - -/*! - \qmlproperty string NumberFormatter::text - - The number in the specified format. -
- If no format is specified the text will be empty. -*/ - -QString QmlNumberFormatter::text() const -{ - Q_D(const QmlNumberFormatter); - return d->text; -} - -/*! - \qmlproperty real NumberFormatter::number - - A single point precision number. (Doubles are not yet supported) - -*/ -qreal QmlNumberFormatter::number() const -{ - Q_D(const QmlNumberFormatter); - return d->number; -} - -/*! - \qmlproperty string NumberFormatter::format - - The particular format the number will adhere to during the conversion to text. -
- The format syntax follows a style similar to the Unicode Standard (UTS35). - - The table below shows the characters, patterns that can be used in the format. - - - - - - - - -
Character Meaning
# Any digit(s), zero shows as absent (for leading/trailing zeroes)
0 Implicit digit. Zero will show in the case that the input number is too small.
. Decimal separator. Output decimal seperator will be dependant on system locale.
, Grouping separator. The number of digits (either #, or 0) between the grouping separator and the decimal (or the rightmost digit) will determine the groupingSize)
other Any other character will be taken as a string literal and placed directly into the output string
- - Invalid formats will not guarantee a meaningful text output.
- - \note Input numbers that are too long for the given format will be rounded dependent on precison based on the position of the decimal point - - The following table illustrates the output text created by applying some examples of numeric formats to the formatter. - - - - - - - - - - - - -
Format Number Output
### 123456 123456
000 123456 123456
###### 1234 1234
000000 1234 001234
##,##0.## 1234.456 1,234.46 (for US locale)
1 234,46 (for FR locale)
000000,000.# 123456 000,123,456 (for US locale)
000 123 456 (for FR locale)
0.0### 0.999997 1.0
(000) 000 - 000 12345678 (012) 345 - 678
#A1212A
- -*/ -QString QmlNumberFormatter::format() const -{ - Q_D(const QmlNumberFormatter); - return d->format; -} - -void QmlNumberFormatter::setNumber(const qreal &number) -{ - Q_D(QmlNumberFormatter); - if (d->number == number) - return; - d->number = number; - d->updateText(); -} - -void QmlNumberFormatter::setFormat(const QString &format) -{ - Q_D(QmlNumberFormatter); - //no format checking - if (format.isEmpty()) - d->format = QString::null; - else - d->format = format; - d->updateText(); -} - -void QmlNumberFormatterPrivate::updateText() -{ - Q_Q(QmlNumberFormatter); - if (!componentComplete) - return; - - QNumberFormat tempFormat; - tempFormat.setFormat(format); - tempFormat.setNumber(number); - - text = tempFormat.text(); - - emit q->textChanged(); -} - -void QmlNumberFormatter::classBegin() -{ - Q_D(QmlNumberFormatter); - d->componentComplete = false; -} - -void QmlNumberFormatter::componentComplete() -{ - Q_D(QmlNumberFormatter); - d->componentComplete = true; - d->updateText(); -} -QML_DEFINE_TYPE(Qt,4,6,NumberFormatter,QmlNumberFormatter); - -QT_END_NAMESPACE diff --git a/src/declarative/extra/qmlnumberformatter_p.h b/src/declarative/extra/qmlnumberformatter_p.h deleted file mode 100644 index 0036cb9..0000000 --- a/src/declarative/extra/qmlnumberformatter_p.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** 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 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$ -** -****************************************************************************/ - -#ifndef QMLNUMBERFORMATTER_H -#define QMLNUMBERFORMATTER_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlNumberFormatterPrivate; -class Q_DECLARATIVE_EXPORT QmlNumberFormatter : public QObject, public QmlParserStatus -{ - Q_OBJECT - Q_INTERFACES(QmlParserStatus) - - Q_PROPERTY(QString text READ text NOTIFY textChanged) - Q_PROPERTY(QString format READ format WRITE setFormat) - Q_PROPERTY(qreal number READ number WRITE setNumber) -public: - QmlNumberFormatter(QObject *parent=0); - ~QmlNumberFormatter(); - - QString text() const; - - qreal number() const; - void setNumber(const qreal &); - - QString format() const; - void setFormat(const QString &); - - virtual void classBegin(); - virtual void componentComplete(); - -Q_SIGNALS: - void textChanged(); - -private: - Q_DISABLE_COPY(QmlNumberFormatter) - Q_DECLARE_PRIVATE(QmlNumberFormatter) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlNumberFormatter) - -QT_END_HEADER - -#endif diff --git a/src/declarative/extra/qmlxmllistmodel.cpp b/src/declarative/extra/qmlxmllistmodel.cpp deleted file mode 100644 index 3d90b44..0000000 --- a/src/declarative/extra/qmlxmllistmodel.cpp +++ /dev/null @@ -1,727 +0,0 @@ -/**************************************************************************** -** -** 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 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$ -** -****************************************************************************/ - -#include "qmlxmllistmodel_p.h" -#include "private/qobject_p.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QML_DEFINE_TYPE(Qt,4,6,XmlRole,QmlXmlListModelRole) -QML_DEFINE_TYPE(Qt,4,6,XmlListModel,QmlXmlListModel) - -/*! - \qmlclass XmlRole QmlXmlListModelRole - \brief The XmlRole element allows you to specify a role for an XmlListModel. -*/ - -/*! - \qmlproperty string XmlRole::name - The name for the role. This name is used to access the model data for this role from Qml. - - \qml - XmlRole { name: "title"; query: "title/string()" } - - ... - - Component { - id: myDelegate - Text { text: title } - } - \endqml -*/ - -/*! - \qmlproperty string XmlRole::query - The relative XPath query for this role. The query should not start with a '/' (i.e. it must be - relative). - - \qml - XmlRole { name: "title"; query: "title/string()" } - \endqml -*/ - -class Q_DECLARATIVE_EXPORT QmlXmlListModelRole : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QString query READ query WRITE setQuery) - -public: - QmlXmlListModelRole() {} - ~QmlXmlListModelRole() {} - - QString name() const { return m_name; } - void setName(const QString &name) { m_name = name; } - - QString query() const { return m_query; } - void setQuery(const QString &query) - { - if (query.startsWith(QLatin1Char('/'))) { - qmlInfo(this) << tr("An XmlRole query must not start with '/'"); - return; - } - m_query = query; - } - - bool isValid() { - return !m_name.isEmpty() && !m_query.isEmpty(); - } - -private: - QString m_name; - QString m_query; -}; - -QML_DECLARE_TYPE(QmlXmlListModelRole) - -class QmlXmlListModelPrivate; -struct QmlXmlRoleList : public QmlConcreteList -{ - QmlXmlRoleList(QmlXmlListModelPrivate *p) - : model(p) {} - virtual void append(QmlXmlListModelRole *role); - //XXX clear, removeAt, and insert need to invalidate any cached data (in data table) as well - // (and the model should emit the appropriate signals) - virtual void clear(); - virtual void removeAt(int i); - virtual void insert(int i, QmlXmlListModelRole *role); - - QmlXmlListModelPrivate *model; -}; - -class QmlXmlQuery : public QThread -{ - Q_OBJECT -public: - QmlXmlQuery(QObject *parent=0) - : QThread(parent), m_quit(false), m_restart(false), m_abort(false), m_queryId(0) { - } - ~QmlXmlQuery() { - m_mutex.lock(); - m_quit = true; - m_condition.wakeOne(); - m_mutex.unlock(); - - wait(); - } - - void abort() { - QMutexLocker locker(&m_mutex); - m_abort = true; - } - - int doQuery(QString query, QString namespaces, QByteArray data, QmlXmlRoleList *roleObjects) { - QMutexLocker locker(&m_mutex); - m_modelData.clear(); - m_size = 0; - m_data = data; - m_query = QLatin1String("doc($src)") + query; - m_namespaces = namespaces; - m_roleObjects = roleObjects; - if (!isRunning()) { - m_abort = false; - start(); - } else { - m_restart = true; - m_condition.wakeOne(); - } - m_queryId++; - return m_queryId; - } - - QList > modelData() { - QMutexLocker locker(&m_mutex); - return m_modelData; - } - -Q_SIGNALS: - void queryCompleted(int queryId, int size); - -protected: - void run() { - while (!m_quit) { - m_mutex.lock(); - int queryId = m_queryId; - doQueryJob(); - if (m_size > 0) - doSubQueryJob(); - m_data.clear(); // no longer needed - m_mutex.unlock(); - - m_mutex.lock(); - if (!m_abort && m_size > 0) - emit queryCompleted(queryId, m_size); - if (!m_restart) - m_condition.wait(&m_mutex); - m_abort = false; - m_restart = false; - m_mutex.unlock(); - } - } - -private: - void doQueryJob(); - void doSubQueryJob(); - -private: - QMutex m_mutex; - QWaitCondition m_condition; - bool m_quit; - bool m_restart; - bool m_abort; - QByteArray m_data; - QString m_query; - QString m_namespaces; - QString m_prefix; - int m_size; - int m_queryId; - const QmlXmlRoleList *m_roleObjects; - QList > m_modelData; -}; - -void QmlXmlQuery::doQueryJob() -{ - QString r; - QXmlQuery query; - QBuffer buffer(&m_data); - buffer.open(QIODevice::ReadOnly); - query.bindVariable(QLatin1String("src"), &buffer); - query.setQuery(m_namespaces + m_query); - query.evaluateTo(&r); - - //qDebug() << r; - - //always need a single root element - QByteArray xml = "\n" + r.toUtf8() + ""; - QBuffer b(&xml); - b.open(QIODevice::ReadOnly); - //qDebug() << xml; - - QString namespaces = QLatin1String("declare namespace dummy=\"http://qtsotware.com/dummy\";\n") + m_namespaces; - QString prefix = QLatin1String("doc($inputDocument)/dummy:items") + - m_query.mid(m_query.lastIndexOf(QLatin1Char('/'))); - - //figure out how many items we are dealing with - int count = -1; - { - QXmlResultItems result; - QXmlQuery countquery; - countquery.bindVariable(QLatin1String("inputDocument"), &b); - countquery.setQuery(namespaces + QLatin1String("count(") + prefix + QLatin1String(")")); - countquery.evaluateTo(&result); - QXmlItem item(result.next()); - if (item.isAtomicValue()) - count = item.toAtomicValue().toInt(); - } - //qDebug() << count; - - m_prefix = namespaces + prefix + QLatin1String("/"); - m_data = xml; - if (count > 0) - m_size = count; -} - -void QmlXmlQuery::doSubQueryJob() -{ - m_modelData.clear(); - - QBuffer b(&m_data); - b.open(QIODevice::ReadOnly); - - QXmlQuery subquery; - subquery.bindVariable(QLatin1String("inputDocument"), &b); - - //### we might be able to condense even further (query for everything in one go) - for (int i = 0; i < m_roleObjects->size(); ++i) { - QmlXmlListModelRole *role = m_roleObjects->at(i); - if (!role->isValid()) { - QList resultList; - for (int j = 0; j < m_size; ++j) - resultList << QVariant(); - m_modelData << resultList; - continue; - } - subquery.setQuery(m_prefix + QLatin1String("(let $v := ") + role->query() + QLatin1String(" return if ($v) then ") + role->query() + QLatin1String(" else \"\")")); - QXmlResultItems output3; - subquery.evaluateTo(&output3); - QXmlItem item(output3.next()); - QList resultList; - while (!item.isNull()) { - resultList << item.toAtomicValue(); //### we used to trim strings - item = output3.next(); - } - //### should warn here if things have gone wrong. - while (resultList.count() < m_size) - resultList << QVariant(); - m_modelData << resultList; - b.seek(0); - } - - //XXX this method is much slower, but would work better for incremental loading - /*for (int j = 0; j < m_size; ++j) { - QList resultList; - for (int i = 0; i < m_roleObjects->size(); ++i) { - QmlXmlListModelRole *role = m_roleObjects->at(i); - subquery.setQuery(m_prefix.arg(j+1) + role->query()); - if (role->isStringList()) { - QStringList data; - subquery.evaluateTo(&data); - resultList << QVariant(data); - //qDebug() << data; - } else { - QString s; - subquery.evaluateTo(&s); - if (role->isCData()) { - //un-escape - s.replace(QLatin1String("<"), QLatin1String("<")); - s.replace(QLatin1String(">"), QLatin1String(">")); - s.replace(QLatin1String("&"), QLatin1String("&")); - } - resultList << s.trimmed(); - //qDebug() << s; - } - b.seek(0); - } - m_modelData << resultList; - }*/ -} - - -//TODO: error handling (currently quite fragile) -// profile doQuery and doSubquery -// support complex/nested objects? -// how do we handle data updates (like rss feed -- usually items inserted at beginning) - - -class QmlXmlListModelPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlXmlListModel) -public: - QmlXmlListModelPrivate() - : isComponentComplete(true), size(-1), highestRole(Qt::UserRole) - , reply(0), status(QmlXmlListModel::Null), progress(0.0) - , queryId(-1), roleObjects(this) {} - - bool isComponentComplete; - QUrl src; - QString xml; - QString query; - QString namespaces; - int size; - QList roles; - QStringList roleNames; - int highestRole; - QNetworkReply *reply; - QmlXmlListModel::Status status; - qreal progress; - QmlXmlQuery qmlXmlQuery; - int queryId; - QmlXmlRoleList roleObjects; - QList > data; -}; - - -void QmlXmlRoleList::append(QmlXmlListModelRole *role) { - QmlConcreteList::append(role); - model->roles << model->highestRole; - model->roleNames << role->name(); - ++model->highestRole; -} - -//XXX clear, removeAt, and insert need to invalidate any cached data (in data table) as well -// (and the model should emit the appropriate signals) -void QmlXmlRoleList::clear() -{ - model->roles.clear(); - model->roleNames.clear(); - QmlConcreteList::clear(); -} - -void QmlXmlRoleList::removeAt(int i) -{ - model->roles.removeAt(i); - model->roleNames.removeAt(i); - QmlConcreteList::removeAt(i); -} - -//### we should enforce unique role names -void QmlXmlRoleList::insert(int i, QmlXmlListModelRole *role) -{ - QmlConcreteList::insert(i, role); - model->roles.insert(i, model->highestRole); - model->roleNames.insert(i, role->name()); - ++model->highestRole; -} - -/*! - \class QmlXmlListModel - \internal -*/ - -/*! - \qmlclass XmlListModel QmlXmlListModel - \brief The XmlListModel element allows you to specify a model using XPath expressions. - - XmlListModel allows you to construct a model from XML data that can then be used as a data source - for the view classes (ListView, PathView, GridView) and any other classes that interact with model - data (like Repeater). - - The following is an example of a model containing news from a Yahoo RSS feed: - \qml - XmlListModel { - id: feedModel - source: "http://rss.news.yahoo.com/rss/oceania" - query: "/rss/channel/item" - XmlRole { name: "title"; query: "title/string()" } - XmlRole { name: "link"; query: "link/string()" } - XmlRole { name: "description"; query: "description/string()" } - } - \endqml - \note The model is currently static, so the above is really just a snapshot of an RSS feed. To force a - reload of the entire model, you can call the reload function. -*/ - -QmlXmlListModel::QmlXmlListModel(QObject *parent) - : QListModelInterface(*(new QmlXmlListModelPrivate), parent) -{ - Q_D(QmlXmlListModel); - connect(&d->qmlXmlQuery, SIGNAL(queryCompleted(int,int)), - this, SLOT(queryCompleted(int,int))); -} - -QmlXmlListModel::~QmlXmlListModel() -{ -} - -/*! - \qmlproperty list XmlListModel::roles - - The roles to make available for this model. -*/ -QmlList *QmlXmlListModel::roleObjects() -{ - Q_D(QmlXmlListModel); - return &d->roleObjects; -} - -QHash QmlXmlListModel::data(int index, const QList &roles) const -{ - Q_D(const QmlXmlListModel); - QHash rv; - for (int i = 0; i < roles.size(); ++i) { - int role = roles.at(i); - int roleIndex = d->roles.indexOf(role); - rv.insert(role, roleIndex == -1 ? QVariant() : d->data.at(roleIndex).at(index)); - } - return rv; -} - -/*! - \qmlproperty int XmlListModel::count - The number of data entries in the model. -*/ -int QmlXmlListModel::count() const -{ - Q_D(const QmlXmlListModel); - return d->size; -} - -QList QmlXmlListModel::roles() const -{ - Q_D(const QmlXmlListModel); - return d->roles; -} - -QString QmlXmlListModel::toString(int role) const -{ - Q_D(const QmlXmlListModel); - int index = d->roles.indexOf(role); - if (index == -1) - return QString(); - return d->roleNames.at(index); -} - -/*! - \qmlproperty url XmlListModel::source - The location of the XML data source. - - If both source and xml are set, xml will be used. -*/ -QUrl QmlXmlListModel::source() const -{ - Q_D(const QmlXmlListModel); - return d->src; -} - -void QmlXmlListModel::setSource(const QUrl &src) -{ - Q_D(QmlXmlListModel); - if (d->src != src) { - d->src = src; - reload(); - } -} - -/*! - \qmlproperty string XmlListModel::xml - This property holds XML text set directly. - - The text is assumed to be UTF-8 encoded. - - If both source and xml are set, xml will be used. -*/ -QString QmlXmlListModel::xml() const -{ - Q_D(const QmlXmlListModel); - return d->xml; -} - -void QmlXmlListModel::setXml(const QString &xml) -{ - Q_D(QmlXmlListModel); - d->xml = xml; - reload(); -} - -/*! - \qmlproperty url XmlListModel::query - An absolute XPath query representing the base query for the model items. The query should start with - a '/' or '//'. -*/ -QString QmlXmlListModel::query() const -{ - Q_D(const QmlXmlListModel); - return d->query; -} - -void QmlXmlListModel::setQuery(const QString &query) -{ - Q_D(QmlXmlListModel); - if (!query.startsWith(QLatin1Char('/'))) { - qmlInfo(this) << tr("An XmlListModel query must start with '/' or \"//\""); - return; - } - - if (d->query != query) { - d->query = query; - reload(); - } -} - -/*! - \qmlproperty string XmlListModel::namespaceDeclarations - A set of declarations for the namespaces used in the query. -*/ -QString QmlXmlListModel::namespaceDeclarations() const -{ - Q_D(const QmlXmlListModel); - return d->namespaces; -} - -void QmlXmlListModel::setNamespaceDeclarations(const QString &declarations) -{ - Q_D(QmlXmlListModel); - if (d->namespaces != declarations) { - d->namespaces = declarations; - reload(); - } -} - -/*! - \qmlproperty enum XmlListModel::status - - This property holds the status of data source loading. It can be one of: - \list - \o Null - no data source has been set - \o Ready - nthe data source has been loaded - \o Loading - the data source is currently being loaded - \o Error - an error occurred while loading the data source - \endlist - - \sa progress - -*/ -QmlXmlListModel::Status QmlXmlListModel::status() const -{ - Q_D(const QmlXmlListModel); - return d->status; -} - -/*! - \qmlproperty real XmlListModel::progress - - This property holds the progress of data source loading, from 0.0 (nothing loaded) - to 1.0 (finished). - - \sa status -*/ -qreal QmlXmlListModel::progress() const -{ - Q_D(const QmlXmlListModel); - return d->progress; -} - -void QmlXmlListModel::classBegin() -{ - Q_D(QmlXmlListModel); - d->isComponentComplete = false; -} - -void QmlXmlListModel::componentComplete() -{ - Q_D(QmlXmlListModel); - d->isComponentComplete = true; - reload(); -} - -/*! - \qmlmethod XmlListModel::reload() - - Reloads the model. All the existing model data will be removed, and the model - will be rebuilt from scratch. -*/ -void QmlXmlListModel::reload() -{ - Q_D(QmlXmlListModel); - - if (!d->isComponentComplete) - return; - - d->qmlXmlQuery.abort(); - d->queryId = -1; - - //clear existing data - int count = d->size; - d->size = 0; - d->data.clear(); - if (count > 0) - emit itemsRemoved(0, count); - - if (d->src.isEmpty() && d->xml.isEmpty()) - return; - - if (d->reply) { - d->reply->abort(); - d->reply->deleteLater(); - d->reply = 0; - } - - if (!d->xml.isEmpty()) { - d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects); - d->progress = 1.0; - d->status = Ready; - emit progressChanged(d->progress); - emit statusChanged(d->status); - return; - } - - d->progress = 0.0; - d->status = Loading; - emit progressChanged(d->progress); - emit statusChanged(d->status); - - QNetworkRequest req(d->src); - d->reply = qmlContext(this)->engine()->networkAccessManager()->get(req); - QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(requestFinished())); - QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), - this, SLOT(requestProgress(qint64,qint64))); -} - -void QmlXmlListModel::requestFinished() -{ - Q_D(QmlXmlListModel); - if (d->reply->error() != QNetworkReply::NoError) { - disconnect(d->reply, 0, this, 0); - d->reply->deleteLater(); - d->reply = 0; - d->status = Error; - } else { - d->status = Ready; - QByteArray data = d->reply->readAll(); - d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, data, &d->roleObjects); - disconnect(d->reply, 0, this, 0); - d->reply->deleteLater(); - d->reply = 0; - } - d->progress = 1.0; - emit progressChanged(d->progress); - emit statusChanged(d->status); -} - -void QmlXmlListModel::requestProgress(qint64 received, qint64 total) -{ - Q_D(QmlXmlListModel); - if (d->status == Loading && total > 0) { - d->progress = qreal(received)/total; - emit progressChanged(d->progress); - } -} - -void QmlXmlListModel::queryCompleted(int id, int size) -{ - Q_D(QmlXmlListModel); - if (id != d->queryId) - return; - d->size = size; - if (size > 0) { - d->data = d->qmlXmlQuery.modelData(); - emit itemsInserted(0, d->size); - emit countChanged(); - } -} - -QT_END_NAMESPACE - -#include "qmlxmllistmodel.moc" diff --git a/src/declarative/extra/qmlxmllistmodel_p.h b/src/declarative/extra/qmlxmllistmodel_p.h deleted file mode 100644 index 18bf9d2..0000000 --- a/src/declarative/extra/qmlxmllistmodel_p.h +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** 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 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$ -** -****************************************************************************/ - -#ifndef QMLXMLLISTMODEL_H -#define QMLXMLLISTMODEL_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlContext; - -class QmlXmlListModelRole; - -class QmlXmlListModelPrivate; -class Q_DECLARATIVE_EXPORT QmlXmlListModel : public QListModelInterface, public QmlParserStatus -{ - Q_OBJECT - Q_INTERFACES(QmlParserStatus) - Q_ENUMS(Status) - - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - Q_PROPERTY(QUrl source READ source WRITE setSource) - Q_PROPERTY(QString xml READ xml WRITE setXml) - Q_PROPERTY(QString query READ query WRITE setQuery) - Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations) - Q_PROPERTY(QmlList *roles READ roleObjects) - Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_CLASSINFO("DefaultProperty", "roles") - -public: - QmlXmlListModel(QObject *parent = 0); - ~QmlXmlListModel(); - - virtual QHash data(int index, const QList &roles = (QList())) const; - virtual int count() const; - virtual QList roles() const; - virtual QString toString(int role) const; - - QmlList *roleObjects(); - - QUrl source() const; - void setSource(const QUrl&); - - QString xml() const; - void setXml(const QString&); - - QString query() const; - void setQuery(const QString&); - - QString namespaceDeclarations() const; - void setNamespaceDeclarations(const QString&); - - enum Status { Null, Ready, Loading, Error }; - Status status() const; - qreal progress() const; - - virtual void classBegin(); - virtual void componentComplete(); - -Q_SIGNALS: - void statusChanged(Status); - void progressChanged(qreal progress); - void countChanged(); - -public Q_SLOTS: - // ### need to use/expose Expiry to guess when to call this? - // ### property to auto-call this on reasonable Expiry? - // ### LastModified/Age also useful to guess. - // ### Probably also applies to other network-requesting types. - void reload(); - -private Q_SLOTS: - void requestFinished(); - void requestProgress(qint64,qint64); - void queryCompleted(int,int); - -private: - Q_DECLARE_PRIVATE(QmlXmlListModel) - Q_DISABLE_COPY(QmlXmlListModel) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlXmlListModel) - -QT_END_HEADER - -#endif // QMLXMLLISTMODEL_H diff --git a/src/declarative/extra/qnumberformat.cpp b/src/declarative/extra/qnumberformat.cpp deleted file mode 100644 index c6a03e9..0000000 --- a/src/declarative/extra/qnumberformat.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/**************************************************************************** -** -** 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 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$ -** -****************************************************************************/ - -#include "qnumberformat_p.h" - -QT_BEGIN_NAMESPACE - -QML_DEFINE_NOCREATE_TYPE(QNumberFormat) - -QNumberFormat::QNumberFormat(QObject *parent) : QObject(parent), _number(0), _type(Decimal), - _groupingSize(0) -{ - _locale = QLocale::system(); - _groupingSeparator = _locale.groupSeparator(); - _decimalSeparator = _locale.decimalPoint(); - _currencySymbol = QLatin1Char('$'); -} - -QNumberFormat::~QNumberFormat() -{ - -} - -void QNumberFormat::updateText() -{ - QTime t; - t.start(); - static int totalTime; - - handleFormat(); - - totalTime += t.elapsed(); - emit textChanged(); -} - -void QNumberFormat::handleFormat() -{ - // ### is extremely messy - if (_format.isEmpty()) { - _text = QString(QLatin1String("%1")).arg(_number, -1, 'f', -1); - return; - } - - QString inputString; - - // ### possible to use the following parsed data in the future - - int remainingLength = _format.size(); - int currentIndex = _format.size()-1; - - int maxDigits = 0; - int minDigits = 0; - int decimalLength = 0; - - while (remainingLength > 0) { - switch(_format.at(currentIndex).unicode()) { - case ',': - if (decimalLength && !_groupingSize) - setGroupingSize(maxDigits - decimalLength); - else if (!_groupingSize) - setGroupingSize(maxDigits); - break; - case '.': - if (!decimalLength) - decimalLength = maxDigits; - break; - case '0': - minDigits++; - case '#': - maxDigits++; - break; - default: - break; - } - currentIndex--; - remainingLength--; - } - - // round given the decimal length/precision - inputString = QString(QLatin1String("%1")).arg(_number, -1, 'f', decimalLength); - - QStringList parts = inputString.split(QLatin1Char('.')); - QStringList formatParts = _format.split(QLatin1Char('.')); - - if (formatParts.size() > 2 || parts.size() > 2 ) - return; - - QString formatInt = formatParts.at(0); - - QString formatDec; - if (formatParts.size() == 2) - formatDec = formatParts.at(1); - - QString integer = parts.at(0); - - QString decimal; - if (parts.size() == 2) - decimal = parts.at(1); - - QString outputDecimal = formatDecimal(formatDec, decimal); - QString outputInteger = formatInteger(formatInt, integer); - - // insert separators - if (_groupingSize) { - unsigned int count = 0; - for (int i = outputInteger.size()-1; i > 0; i--) { - if (outputInteger.at(i).digitValue() >= 0) { - if (count == _groupingSize - 1) { - count = 0; - outputInteger.insert(i, _groupingSeparator); - } - else - count++; - } - } - } - if (!outputDecimal.isEmpty()) - _text = outputInteger + _decimalSeparator + outputDecimal; - else - _text = outputInteger; -} - -QString QNumberFormat::formatInteger(const QString &formatInt, const QString &integer) -{ - if (formatInt.isEmpty() || integer.isEmpty()) - return QString(); - - QString outputInteger; - int formatIndex = formatInt.size()-1; - - //easier for carry? - for (int index= integer.size()-1; index >= 0; index--) { - if (formatIndex < 0) { - outputInteger.push_front(integer.at(index)); - } - else { - switch(formatInt.at(formatIndex).unicode()) { - case '0': - if (index > integer.size()-1) { - outputInteger.push_front(QLatin1Char('0')); - break; - } - case '#': - outputInteger.push_front(integer.at(index)); - break; - case ',': - index++; - break; - default: - outputInteger.push_front(formatInt.at(formatIndex)); - index++; - break; - } - formatIndex--; - } - } - while (formatIndex >= 0) { - if (formatInt.at(formatIndex).unicode() != '#' && formatInt.at(formatIndex).unicode() != ',') - outputInteger.push_front(formatInt.at(formatIndex)); - formatIndex--; - } - return outputInteger; -} - -QString QNumberFormat::formatDecimal(const QString &formatDec, const QString &decimal) -{ - QString outputDecimal; - - // up to max 6 decimal places - for (int index=formatDec.size()-1; index >= 0; index--) { - switch(formatDec.at(index).unicode()) { - case '0': - outputDecimal.push_front(decimal.at(index)); - break; - case '#': - if (decimal.at(index) != QLatin1Char('0') || outputDecimal.size() > 0) - outputDecimal.push_front(decimal.at(index)); - break; - default: - outputDecimal.push_front(formatDec.at(index)); - break; - } - } - return outputDecimal; -} - -QT_END_NAMESPACE diff --git a/src/declarative/extra/qnumberformat_p.h b/src/declarative/extra/qnumberformat_p.h deleted file mode 100644 index 1a7b8e4..0000000 --- a/src/declarative/extra/qnumberformat_p.h +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** -** -** 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 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$ -** -****************************************************************************/ - -#ifndef NUMBERFORMAT_H -#define NUMBERFORMAT_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -// TODO -// be able to set Locale, instead of default system for dynamic formatting -// add currency support -// add additional syntax, extend to format scientific, percentiles, significant digits etc - - -class QNumberFormat : public QObject -{ - Q_OBJECT - Q_ENUMS(NumberType) -public: - QNumberFormat(QObject *parent=0); - ~QNumberFormat(); - - enum NumberType { - Percent, - Scientific, - Currency, - Decimal - }; - - //external property, only visible - Q_PROPERTY(QString text READ text NOTIFY textChanged) - - //mutatable properties to modify the output (text) - Q_PROPERTY(qreal number READ number WRITE setNumber) - Q_PROPERTY(QString format READ format WRITE setFormat) - Q_PROPERTY(QLocale locale READ locale WRITE setLocale) - - //Format specific settings - Q_PROPERTY(unsigned short groupingSeparator READ groupingSeparator WRITE setGroupingSeparator) - Q_PROPERTY(unsigned short decimalSeperator READ decimalSeparator WRITE setDecimalSeparator) - Q_PROPERTY(unsigned int groupingSize READ groupingSize WRITE setGroupingSize) - Q_PROPERTY(unsigned short currencySymbol READ currencySymbol WRITE setCurrencySymbol) - - - QString text() const { return _text; } - - qreal number() const { return _number; } - void setNumber(qreal n) { - if (_number == n) - return; - _number = n; - updateText(); - } - - QString format() const { return _format; } - void setFormat(const QString &format) { - if (format.isEmpty()) - _format = QString::null; - else if (_format == format) - return; - - _format = format; - updateText(); - } - - QLocale locale() const { return _locale; } - void setLocale(const QLocale &locale) { _locale = locale; updateText(); } - - //Do we deal with unicode standard? or create our own - // ### since this is the backend for the number conversions, we will use the unicode - // the front-end will handle the QChar/QString -> short int - - unsigned short groupingSeparator() { return _groupingSeparator.unicode(); } - void setGroupingSeparator(unsigned short unicodeSymbol) - { - _groupingSeparator = QChar(unicodeSymbol); - } - - unsigned short decimalSeparator() { return _decimalSeparator.unicode(); } - void setDecimalSeparator(unsigned short unicodeSymbol) - { - _decimalSeparator = QChar(unicodeSymbol); - } - - unsigned short currencySymbol() { return _currencySymbol.unicode(); } - void setCurrencySymbol(unsigned short unicodeSymbol) - { - _currencySymbol = QChar(unicodeSymbol); - } - - unsigned int groupingSize() { return _groupingSize; } - void setGroupingSize(unsigned int size) - { - _groupingSize = size; - } - -Q_SIGNALS: - void textChanged(); - -private: - void updateText(); - void handleFormat(); - QString formatInteger(const QString &formatInt, const QString &integer); - QString formatDecimal(const QString &formatDec, const QString &decimal); - - qreal _number; - NumberType _type; - QChar _groupingSeparator; - QChar _decimalSeparator; - QChar _currencySymbol; - unsigned int _groupingSize; - - QLocale _locale; - QString _format; - - // only hooked member at the moment - QString _text; - -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QNumberFormat) - -QT_END_HEADER - -#endif diff --git a/src/declarative/util/qmlbehavior.cpp b/src/declarative/util/qmlbehavior.cpp new file mode 100644 index 0000000..8364d8c --- /dev/null +++ b/src/declarative/util/qmlbehavior.cpp @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** 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 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$ +** +****************************************************************************/ + +#include +#include +#include +#include "qmlbehavior_p.h" +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,Behavior,QmlBehavior) + +class QmlBehaviorPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlBehavior) +public: + QmlBehaviorPrivate() : animation(0) {} + + QmlMetaProperty property; + QVariant currentValue; + QmlAbstractAnimation *animation; +}; + +/*! + \qmlclass Behavior QmlBehavior + \brief The Behavior element allows you to specify a default animation for a property change. + + In example below, the rect will use a bounce easing curve over 200 millisecond for any changes to its y property: + \code + Rectangle { + width: 20; height: 20 + color: "#00ff00" + y: 200 //initial value + y: Behavior { + NumberAnimation { + easing: "easeOutBounce(amplitude:100)" + duration: 200 + } + } + } + \endcode +*/ + + +QmlBehavior::QmlBehavior(QObject *parent) + : QObject(*(new QmlBehaviorPrivate), parent) +{ +} + +QmlBehavior::~QmlBehavior() +{ +} + +/*! + \qmlproperty Animation Behavior::animation + \default + + The animation to use when the behavior is triggered. +*/ + +QmlAbstractAnimation *QmlBehavior::animation() +{ + Q_D(QmlBehavior); + return d->animation; +} + +void QmlBehavior::setAnimation(QmlAbstractAnimation *animation) +{ + Q_D(QmlBehavior); + if (d->animation) { + qmlInfo(this) << tr("Can't change the animation assigned to a Behavior."); + return; + } + + d->animation = animation; + if (d->animation) + d->animation->setTarget(d->property); +} + +void QmlBehavior::write(const QVariant &value) +{ + Q_D(QmlBehavior); + if (!d->animation) { + d->property.write(value, QmlMetaProperty::BypassInterceptor | QmlMetaProperty::DontRemoveBinding); + return; + } + + d->currentValue = d->property.read(); + + d->animation->qtAnimation()->stop(); + + QmlStateOperation::ActionList actions; + Action action; + action.property = d->property; + action.fromValue = d->currentValue; + action.toValue = value; + actions << action; + + QList after; + if (d->animation) + d->animation->transition(actions, after, QmlAbstractAnimation::Forward); + d->animation->qtAnimation()->start(); + if (!after.contains(d->property)) + d->property.write(value, QmlMetaProperty::BypassInterceptor | QmlMetaProperty::DontRemoveBinding); +} + +void QmlBehavior::setTarget(const QmlMetaProperty &property) +{ + Q_D(QmlBehavior); + d->property = property; + d->currentValue = property.read(); + if (d->animation) + d->animation->setTarget(property); +} + +QT_END_NAMESPACE diff --git a/src/declarative/util/qmlbehavior_p.h b/src/declarative/util/qmlbehavior_p.h new file mode 100644 index 0000000..9f85f84 --- /dev/null +++ b/src/declarative/util/qmlbehavior_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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 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$ +** +****************************************************************************/ + +#ifndef QMLBEHAVIOR_H +#define QMLBEHAVIOR_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlAbstractAnimation; +class QmlBehaviorPrivate; +class Q_DECLARATIVE_EXPORT QmlBehavior : public QObject, public QmlPropertyValueInterceptor +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlBehavior) + + Q_INTERFACES(QmlPropertyValueInterceptor) + Q_CLASSINFO("DefaultProperty", "animation") + Q_PROPERTY(QmlAbstractAnimation *animation READ animation WRITE setAnimation) + +public: + QmlBehavior(QObject *parent=0); + ~QmlBehavior(); + + virtual void setTarget(const QmlMetaProperty &); + virtual void write(const QVariant &value); + + QmlAbstractAnimation *animation(); + void setAnimation(QmlAbstractAnimation *); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlBehavior) + +QT_END_HEADER + +#endif // QMLBEHAVIOR_H diff --git a/src/declarative/util/qmldatetimeformatter.cpp b/src/declarative/util/qmldatetimeformatter.cpp new file mode 100644 index 0000000..983287e --- /dev/null +++ b/src/declarative/util/qmldatetimeformatter.cpp @@ -0,0 +1,370 @@ +/**************************************************************************** +** +** 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 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$ +** +****************************************************************************/ + +#include "qmldatetimeformatter_p.h" +#include "private/qobject_p.h" +#include + +QT_BEGIN_NAMESPACE + +//TODO: may need optimisation as the QDateTime member may not be needed? +// be able to set a locale? + +class QmlDateTimeFormatterPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlDateTimeFormatter) +public: + QmlDateTimeFormatterPrivate() : locale(QLocale::system()), longStyle(false), componentComplete(true) {} + + void updateText(); + + QDateTime dateTime; + QDate date; + QTime time; + QLocale locale; + QString dateTimeText; + QString dateText; + QString timeText; + QString dateTimeFormat; //set for convienience? + QString dateFormat; + QString timeFormat; + bool longStyle; + bool componentComplete; +}; + +/*! + \qmlclass DateTimeFormatter QmlDateTimeFormatter + \brief The DateTimeFormatter allows you to control the format of a date string. + + \code + DateTimeFormatter { id: formatter; date: System.date } + Text { text: formatter.dateText } + \endcode + + By default, the text properties (dateText, timeText, and dateTimeText) will return the + date and time using the current system locale's format. +*/ + +/*! + \internal + \class QmlDateTimeFormatter + \ingroup group_utility + \brief The QmlDateTimeFormatter class allows you to format a date string. +*/ + +QmlDateTimeFormatter::QmlDateTimeFormatter(QObject *parent) +: QObject(*(new QmlDateTimeFormatterPrivate), parent) +{ +} + +QmlDateTimeFormatter::~QmlDateTimeFormatter() +{ +} + +/*! + \qmlproperty string DateTimeFormatter::dateText + \qmlproperty string DateTimeFormatter::timeText + \qmlproperty string DateTimeFormatter::dateTimeText + + Formatted text representations of the \c date, \c time, + and \c {date and time}, respectively. + + If there is no explictly specified format the DateTimeFormatter + will use the system locale's default 'short' setting. + + \code + // specify source date (assuming today is February 19, 2009) + DateTimeFormatter { id: formatter; dateTime: Today.date } + + // display the full date and time + Text { text: formatter.dateText } + \endcode + + Would be equivalent to the following for a US English locale: + + \code + // display the date + Text { text: "2/19/09" } + \endcode +*/ +QString QmlDateTimeFormatter::dateTimeText() const +{ + Q_D(const QmlDateTimeFormatter); + return d->dateTimeText; +} + +QString QmlDateTimeFormatter::dateText() const +{ + Q_D(const QmlDateTimeFormatter); + return d->dateText; +} + +QString QmlDateTimeFormatter::timeText() const +{ + Q_D(const QmlDateTimeFormatter); + return d->timeText; +} + +/*! + \qmlproperty date DateTimeFormatter::date + \qmlproperty time DateTimeFormatter::time + \qmlproperty datetime DateTimeFormatter::dateTime + + The source date and time to be used by the formatter. + + \code + // setting the date and time + DateTimeFormatter { date: System.date; time: System.time } + \endcode + + For convienience it is possible to set the datetime property to set both the date and the time. + \code + // setting the datetime + DateTimeFormatter { dateTime: System.dateTime } + \endcode + + There can only be one instance of date and time per formatter; if date, time, and dateTime are all + set the actual date and time used is not guaranteed. + + \note If no date is set, dateTimeText will be just the date; + If no time is set, the dateTimeText will be just the time. + +*/ +QDate QmlDateTimeFormatter::date() const +{ + Q_D(const QmlDateTimeFormatter); + return d->date; +} + +QTime QmlDateTimeFormatter::time() const +{ + Q_D(const QmlDateTimeFormatter); + return d->time; +} + +QDateTime QmlDateTimeFormatter::dateTime() const +{ + Q_D(const QmlDateTimeFormatter); + return d->dateTime; +} + +/*! + \qmlproperty string DateTimeFormatter::dateFormat + \qmlproperty string DateTimeFormatter::timeFormat + \qmlproperty string DateTimeFormatter::dateTimeFormat + + Specifies a custom format which the DateTime Formatter can use. + + If there is no explictly specified format the DateTimeFormatter + will use the system locale's default 'short' setting. + + The text's format may be modified by setting: + \list + \i \c dateFormat + \i \c timeFormat + \i \c dateTimeFormat + \endlist + + If only the format for date is defined, the time and dateTime formats will be defined + as the system locale default and likewise for the others. + + Syntax for the format is based on the QDateTime::toString() formatting options. + + \code + // Format the date such that the dateText is: '1997-12-12' + DateTimeFormatter { id: formatter; dateTime: Today.dateTime; formatDate: "yyyy-MM-d" } + \endcode + + Assigning an empty string to a particular format will reset it. +*/ +QString QmlDateTimeFormatter::dateTimeFormat() const +{ + Q_D(const QmlDateTimeFormatter); + return d->dateTimeFormat; +} + +QString QmlDateTimeFormatter::dateFormat() const +{ + Q_D(const QmlDateTimeFormatter); + return d->dateFormat; +} + +QString QmlDateTimeFormatter::timeFormat() const +{ + Q_D(const QmlDateTimeFormatter); + return d->timeFormat; +} + +/*! + \qmlproperty bool DateTimeFormatter::longStyle + + This property causes the formatter to use the system locale's long format rather than short format + by default. + + This setting is off by default. +*/ +bool QmlDateTimeFormatter::longStyle() const +{ + Q_D(const QmlDateTimeFormatter); + return d->longStyle; +} + +void QmlDateTimeFormatter::setDateTime(const QDateTime &dateTime) +{ + Q_D(QmlDateTimeFormatter); + if (d->dateTime == dateTime) + return; + d->dateTime = dateTime; + d->date = d->dateTime.date(); + d->time = d->dateTime.time(); + d->updateText(); +} + +void QmlDateTimeFormatter::setTime(const QTime &time) +{ + Q_D(QmlDateTimeFormatter); + if (d->dateTime.time() == time) + return; + d->time = time; + d->dateTime.setTime(time); + d->updateText(); +} + +void QmlDateTimeFormatter::setDate(const QDate &date) +{ + Q_D(QmlDateTimeFormatter); + if (d->dateTime.date() == date) + return; + d->date = date; + bool clearTime = d->dateTime.time().isValid() ? false : true; //because setting date generates default time + d->dateTime.setDate(date); + if (clearTime) + d->dateTime.setTime(QTime()); + d->updateText(); +} + +//DateTime formatting may be a combination of date and time? +void QmlDateTimeFormatter::setDateTimeFormat(const QString &format) +{ + Q_D(QmlDateTimeFormatter); + //no format checking + d->dateTimeFormat = format; + d->updateText(); +} + +void QmlDateTimeFormatter::setDateFormat(const QString &format) +{ + Q_D(QmlDateTimeFormatter); + //no format checking + d->dateFormat = format; + d->updateText(); +} + +void QmlDateTimeFormatter::setTimeFormat(const QString &format) +{ + Q_D(QmlDateTimeFormatter); + //no format checking + d->timeFormat = format; + d->updateText(); +} + +void QmlDateTimeFormatter::setLongStyle(bool longStyle) +{ + Q_D(QmlDateTimeFormatter); + d->longStyle = longStyle; + d->updateText(); +} + +void QmlDateTimeFormatterPrivate::updateText() +{ + Q_Q(QmlDateTimeFormatter); + if (!componentComplete) + return; + + QString str; + QString str1; + QString str2; + + Qt::DateFormat defaultFormat = longStyle ? Qt::SystemLocaleLongDate : Qt::SystemLocaleShortDate; + + if (dateFormat.isEmpty()) + str1 = date.toString(defaultFormat); + else + str1 = date.toString(dateFormat); + + if (timeFormat.isEmpty()) + str2 = time.toString(defaultFormat); + else + str2 = time.toString(timeFormat); + + if (dateTimeFormat.isEmpty()) + str = dateTime.toString(defaultFormat); + //else if (!formatTime.isEmpty() && !formatDate.isEmpty()) + // str = str1 + QLatin1Char(' ') + str2; + else + str = dateTime.toString(dateTimeFormat); + + if (dateTimeText == str && dateText == str1 && timeText == str2) + return; + + dateTimeText = str; + dateText = str1; + timeText = str2; + + emit q->textChanged(); +} + +void QmlDateTimeFormatter::classBegin() +{ + Q_D(QmlDateTimeFormatter); + d->componentComplete = false; +} + +void QmlDateTimeFormatter::componentComplete() +{ + Q_D(QmlDateTimeFormatter); + d->componentComplete = true; + d->updateText(); +} + +QML_DEFINE_TYPE(Qt,4,6,DateTimeFormatter,QmlDateTimeFormatter) + +QT_END_NAMESPACE diff --git a/src/declarative/util/qmldatetimeformatter_p.h b/src/declarative/util/qmldatetimeformatter_p.h new file mode 100644 index 0000000..e350f96 --- /dev/null +++ b/src/declarative/util/qmldatetimeformatter_p.h @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** 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 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$ +** +****************************************************************************/ + +#ifndef QMLDATETIMEFORMATTER_H +#define QMLDATETIMEFORMATTER_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlDateTimeFormatterPrivate; +class Q_DECLARATIVE_EXPORT QmlDateTimeFormatter : public QObject, public QmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QmlParserStatus) + + Q_PROPERTY(QString dateText READ dateText NOTIFY textChanged) + Q_PROPERTY(QString timeText READ timeText NOTIFY textChanged) + Q_PROPERTY(QString dateTimeText READ dateTimeText NOTIFY textChanged) + Q_PROPERTY(QDate date READ date WRITE setDate) + Q_PROPERTY(QTime time READ time WRITE setTime) + Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime) + Q_PROPERTY(QString dateFormat READ dateFormat WRITE setDateFormat) + Q_PROPERTY(QString timeFormat READ timeFormat WRITE setTimeFormat) + Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat) + Q_PROPERTY(bool longStyle READ longStyle WRITE setLongStyle) +public: + QmlDateTimeFormatter(QObject *parent=0); + ~QmlDateTimeFormatter(); + + QString dateTimeText() const; + QString dateText() const; + QString timeText() const; + + QDate date() const; + void setDate(const QDate &); + + QTime time() const; + void setTime(const QTime &); + + QDateTime dateTime() const; + void setDateTime(const QDateTime &); + + QString dateTimeFormat() const; + void setDateTimeFormat(const QString &); + + QString dateFormat() const; + void setDateFormat(const QString &); + + QString timeFormat() const; + void setTimeFormat(const QString &); + + bool longStyle() const; + void setLongStyle(bool); + + virtual void classBegin(); + virtual void componentComplete(); + +Q_SIGNALS: + void textChanged(); + +private: + Q_DISABLE_COPY(QmlDateTimeFormatter) + Q_DECLARE_PRIVATE(QmlDateTimeFormatter) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlDateTimeFormatter) + +QT_END_HEADER + +#endif diff --git a/src/declarative/util/qmlfontloader.cpp b/src/declarative/util/qmlfontloader.cpp new file mode 100644 index 0000000..36ee1bb --- /dev/null +++ b/src/declarative/util/qmlfontloader.cpp @@ -0,0 +1,219 @@ +/**************************************************************************** +** +** 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 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$ +** +****************************************************************************/ + +#include "private/qobject_p.h" +#include "qmlfontloader_p.h" +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QmlFontLoaderPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlFontLoader) + +public: + QmlFontLoaderPrivate() : reply(0), status(QmlFontLoader::Null) {} + + void addFontToDatabase(const QByteArray &); + + QUrl url; + QString name; + QNetworkReply *reply; + QmlFontLoader::Status status; +}; + +QML_DEFINE_TYPE(Qt,4,6,FontLoader,QmlFontLoader) + +/*! + \qmlclass FontLoader QmlFontLoader + \ingroup group_utility + \brief This item allows using fonts by name or url. + + Example: + \qml + FontLoader { id: fixedFont; name: "Courier" } + FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" } + + Text { text: "Fixed-size font"; font.family: fixedFont.name } + Text { text: "Fancy font"; font.family: webFont.name } + \endqml +*/ +QmlFontLoader::QmlFontLoader(QObject *parent) + : QObject(*(new QmlFontLoaderPrivate), parent) +{ +} + +QmlFontLoader::~QmlFontLoader() +{ +} + +static QString toLocalFileOrQrc(const QUrl& url) +{ + QString r = url.toLocalFile(); + if (r.isEmpty() && url.scheme() == QLatin1String("qrc")) + r = QLatin1Char(':') + url.path(); + return r; +} + + +/*! + \qmlproperty url FontLoader::source + The url of the font to load. +*/ +QUrl QmlFontLoader::source() const +{ + Q_D(const QmlFontLoader); + return d->url; +} + +void QmlFontLoader::setSource(const QUrl &url) +{ + Q_D(QmlFontLoader); + if (url == d->url) + return; + d->url = qmlContext(this)->resolvedUrl(url); + + d->status = Loading; + emit statusChanged(); +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + QString lf = toLocalFileOrQrc(d->url); + if (!lf.isEmpty()) { + QFile file(lf); + file.open(QIODevice::ReadOnly); + QByteArray ba = file.readAll(); + d->addFontToDatabase(ba); + } else +#endif + { + QNetworkRequest req(d->url); + d->reply = qmlEngine(this)->networkAccessManager()->get(req); + QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(replyFinished())); + } +} + +/*! + \qmlproperty string FontLoader::name + + This property holds the name of the font family. + It is set automatically when a font is loaded using the \c url property. + + Use this to set the \c font.family property of a \c Text item. + + Example: + \qml + FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" } + Text { text: "Fancy font"; font.family: webFont.name } + \endqml +*/ +QString QmlFontLoader::name() const +{ + Q_D(const QmlFontLoader); + return d->name; +} + +void QmlFontLoader::setName(const QString &name) +{ + Q_D(QmlFontLoader); + if (d->name == name ) + return; + d->name = name; + emit nameChanged(); + d->status = Ready; + emit statusChanged(); +} + +/*! + \qmlproperty enum FontLoader::status + + This property holds the status of font loading. It can be one of: + \list + \o Null - no font has been set + \o Ready - the font has been loaded + \o Loading - the font is currently being loaded + \o Error - an error occurred while loading the font + \endlist +*/ +QmlFontLoader::Status QmlFontLoader::status() const +{ + Q_D(const QmlFontLoader); + return d->status; +} + +void QmlFontLoader::replyFinished() +{ + Q_D(QmlFontLoader); + if (d->reply) { + if (!d->reply->error()) { + QByteArray ba = d->reply->readAll(); + d->addFontToDatabase(ba); + } else { + d->status = Error; + emit statusChanged(); + } + d->reply->deleteLater(); + d->reply = 0; + } +} + +void QmlFontLoaderPrivate::addFontToDatabase(const QByteArray &ba) +{ + Q_Q(QmlFontLoader); + + int id = QFontDatabase::addApplicationFontFromData(ba); + if (id != -1) { + name = QFontDatabase::applicationFontFamilies(id).at(0); + emit q->nameChanged(); + status = QmlFontLoader::Ready; + } else { + status = QmlFontLoader::Error; + qWarning() << "Cannot load font:" << url; + } + emit q->statusChanged(); +} + +QT_END_NAMESPACE diff --git a/src/declarative/util/qmlfontloader_p.h b/src/declarative/util/qmlfontloader_p.h new file mode 100644 index 0000000..d02a181 --- /dev/null +++ b/src/declarative/util/qmlfontloader_p.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** 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 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$ +** +****************************************************************************/ + +#ifndef QMLFONTLOADER_H +#define QMLFONTLOADER_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlFontLoaderPrivate; +class Q_DECLARATIVE_EXPORT QmlFontLoader : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlFontLoader) + Q_ENUMS(Status) + + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + +public: + enum Status { Null = 0, Ready, Loading, Error }; + + QmlFontLoader(QObject *parent = 0); + ~QmlFontLoader(); + + QUrl source() const; + void setSource(const QUrl &url); + + QString name() const; + void setName(const QString &name); + + Status status() const; + +private Q_SLOTS: + void replyFinished(); + +Q_SIGNALS: + void nameChanged(); + void statusChanged(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlFontLoader) + +QT_END_HEADER + +#endif // QMLFONTLOADER_H + diff --git a/src/declarative/util/qmlnumberformatter.cpp b/src/declarative/util/qmlnumberformatter.cpp new file mode 100644 index 0000000..b09be5b --- /dev/null +++ b/src/declarative/util/qmlnumberformatter.cpp @@ -0,0 +1,215 @@ +/**************************************************************************** +** +** 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 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$ +** +****************************************************************************/ + +#include "qmlnumberformatter_p.h" +#include "private/qobject_p.h" + +QT_BEGIN_NAMESPACE + +//TODO: set locale +// docs +// this is a wrapper around qnumberformat (test integration) +// if number or format haven't been explictly set, text should be an empty string + +class QmlNumberFormatterPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlNumberFormatter) +public: + QmlNumberFormatterPrivate() : locale(QLocale::system()), number(0), componentComplete(true) {} + + void updateText(); + + QLocale locale; + QString format; + QNumberFormat numberFormat; + QString text; + qreal number; + bool componentComplete; +}; +/*! + \qmlclass NumberFormatter + \brief The NumberFormatter allows you to control the format of a number string. + + The format property documentation has more details on how the format can be manipulated. + + In the following example, the text element will display the text "1,234.57". + \code + NumberFormatter { id: formatter; number: 1234.5678; format: "##,##0.##" } + Text { text: formatter.text } + \endcode + + */ +/*! + \internal + \class QmlNumberFormatter + \ingroup group_utility + \brief The QmlNumberFormatter class allows you to format a number to a particular string format/locale specific number format. +*/ + +QmlNumberFormatter::QmlNumberFormatter(QObject *parent) +: QObject(*(new QmlNumberFormatterPrivate), parent) +{ +} + +QmlNumberFormatter::~QmlNumberFormatter() +{ +} + +/*! + \qmlproperty string NumberFormatter::text + + The number in the specified format. +
+ If no format is specified the text will be empty. +*/ + +QString QmlNumberFormatter::text() const +{ + Q_D(const QmlNumberFormatter); + return d->text; +} + +/*! + \qmlproperty real NumberFormatter::number + + A single point precision number. (Doubles are not yet supported) + +*/ +qreal QmlNumberFormatter::number() const +{ + Q_D(const QmlNumberFormatter); + return d->number; +} + +/*! + \qmlproperty string NumberFormatter::format + + The particular format the number will adhere to during the conversion to text. +
+ The format syntax follows a style similar to the Unicode Standard (UTS35). + + The table below shows the characters, patterns that can be used in the format. + + + + + + + + +
Character Meaning
# Any digit(s), zero shows as absent (for leading/trailing zeroes)
0 Implicit digit. Zero will show in the case that the input number is too small.
. Decimal separator. Output decimal seperator will be dependant on system locale.
, Grouping separator. The number of digits (either #, or 0) between the grouping separator and the decimal (or the rightmost digit) will determine the groupingSize)
other Any other character will be taken as a string literal and placed directly into the output string
+ + Invalid formats will not guarantee a meaningful text output.
+ + \note Input numbers that are too long for the given format will be rounded dependent on precison based on the position of the decimal point + + The following table illustrates the output text created by applying some examples of numeric formats to the formatter. + + + + + + + + + + + + +
Format Number Output
### 123456 123456
000 123456 123456
###### 1234 1234
000000 1234 001234
##,##0.## 1234.456 1,234.46 (for US locale)
1 234,46 (for FR locale)
000000,000.# 123456 000,123,456 (for US locale)
000 123 456 (for FR locale)
0.0### 0.999997 1.0
(000) 000 - 000 12345678 (012) 345 - 678
#A1212A
+ +*/ +QString QmlNumberFormatter::format() const +{ + Q_D(const QmlNumberFormatter); + return d->format; +} + +void QmlNumberFormatter::setNumber(const qreal &number) +{ + Q_D(QmlNumberFormatter); + if (d->number == number) + return; + d->number = number; + d->updateText(); +} + +void QmlNumberFormatter::setFormat(const QString &format) +{ + Q_D(QmlNumberFormatter); + //no format checking + if (format.isEmpty()) + d->format = QString::null; + else + d->format = format; + d->updateText(); +} + +void QmlNumberFormatterPrivate::updateText() +{ + Q_Q(QmlNumberFormatter); + if (!componentComplete) + return; + + QNumberFormat tempFormat; + tempFormat.setFormat(format); + tempFormat.setNumber(number); + + text = tempFormat.text(); + + emit q->textChanged(); +} + +void QmlNumberFormatter::classBegin() +{ + Q_D(QmlNumberFormatter); + d->componentComplete = false; +} + +void QmlNumberFormatter::componentComplete() +{ + Q_D(QmlNumberFormatter); + d->componentComplete = true; + d->updateText(); +} +QML_DEFINE_TYPE(Qt,4,6,NumberFormatter,QmlNumberFormatter); + +QT_END_NAMESPACE diff --git a/src/declarative/util/qmlnumberformatter_p.h b/src/declarative/util/qmlnumberformatter_p.h new file mode 100644 index 0000000..0036cb9 --- /dev/null +++ b/src/declarative/util/qmlnumberformatter_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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 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$ +** +****************************************************************************/ + +#ifndef QMLNUMBERFORMATTER_H +#define QMLNUMBERFORMATTER_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlNumberFormatterPrivate; +class Q_DECLARATIVE_EXPORT QmlNumberFormatter : public QObject, public QmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QmlParserStatus) + + Q_PROPERTY(QString text READ text NOTIFY textChanged) + Q_PROPERTY(QString format READ format WRITE setFormat) + Q_PROPERTY(qreal number READ number WRITE setNumber) +public: + QmlNumberFormatter(QObject *parent=0); + ~QmlNumberFormatter(); + + QString text() const; + + qreal number() const; + void setNumber(const qreal &); + + QString format() const; + void setFormat(const QString &); + + virtual void classBegin(); + virtual void componentComplete(); + +Q_SIGNALS: + void textChanged(); + +private: + Q_DISABLE_COPY(QmlNumberFormatter) + Q_DECLARE_PRIVATE(QmlNumberFormatter) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlNumberFormatter) + +QT_END_HEADER + +#endif diff --git a/src/declarative/util/qmlxmllistmodel.cpp b/src/declarative/util/qmlxmllistmodel.cpp new file mode 100644 index 0000000..3d90b44 --- /dev/null +++ b/src/declarative/util/qmlxmllistmodel.cpp @@ -0,0 +1,727 @@ +/**************************************************************************** +** +** 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 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$ +** +****************************************************************************/ + +#include "qmlxmllistmodel_p.h" +#include "private/qobject_p.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,XmlRole,QmlXmlListModelRole) +QML_DEFINE_TYPE(Qt,4,6,XmlListModel,QmlXmlListModel) + +/*! + \qmlclass XmlRole QmlXmlListModelRole + \brief The XmlRole element allows you to specify a role for an XmlListModel. +*/ + +/*! + \qmlproperty string XmlRole::name + The name for the role. This name is used to access the model data for this role from Qml. + + \qml + XmlRole { name: "title"; query: "title/string()" } + + ... + + Component { + id: myDelegate + Text { text: title } + } + \endqml +*/ + +/*! + \qmlproperty string XmlRole::query + The relative XPath query for this role. The query should not start with a '/' (i.e. it must be + relative). + + \qml + XmlRole { name: "title"; query: "title/string()" } + \endqml +*/ + +class Q_DECLARATIVE_EXPORT QmlXmlListModelRole : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString query READ query WRITE setQuery) + +public: + QmlXmlListModelRole() {} + ~QmlXmlListModelRole() {} + + QString name() const { return m_name; } + void setName(const QString &name) { m_name = name; } + + QString query() const { return m_query; } + void setQuery(const QString &query) + { + if (query.startsWith(QLatin1Char('/'))) { + qmlInfo(this) << tr("An XmlRole query must not start with '/'"); + return; + } + m_query = query; + } + + bool isValid() { + return !m_name.isEmpty() && !m_query.isEmpty(); + } + +private: + QString m_name; + QString m_query; +}; + +QML_DECLARE_TYPE(QmlXmlListModelRole) + +class QmlXmlListModelPrivate; +struct QmlXmlRoleList : public QmlConcreteList +{ + QmlXmlRoleList(QmlXmlListModelPrivate *p) + : model(p) {} + virtual void append(QmlXmlListModelRole *role); + //XXX clear, removeAt, and insert need to invalidate any cached data (in data table) as well + // (and the model should emit the appropriate signals) + virtual void clear(); + virtual void removeAt(int i); + virtual void insert(int i, QmlXmlListModelRole *role); + + QmlXmlListModelPrivate *model; +}; + +class QmlXmlQuery : public QThread +{ + Q_OBJECT +public: + QmlXmlQuery(QObject *parent=0) + : QThread(parent), m_quit(false), m_restart(false), m_abort(false), m_queryId(0) { + } + ~QmlXmlQuery() { + m_mutex.lock(); + m_quit = true; + m_condition.wakeOne(); + m_mutex.unlock(); + + wait(); + } + + void abort() { + QMutexLocker locker(&m_mutex); + m_abort = true; + } + + int doQuery(QString query, QString namespaces, QByteArray data, QmlXmlRoleList *roleObjects) { + QMutexLocker locker(&m_mutex); + m_modelData.clear(); + m_size = 0; + m_data = data; + m_query = QLatin1String("doc($src)") + query; + m_namespaces = namespaces; + m_roleObjects = roleObjects; + if (!isRunning()) { + m_abort = false; + start(); + } else { + m_restart = true; + m_condition.wakeOne(); + } + m_queryId++; + return m_queryId; + } + + QList > modelData() { + QMutexLocker locker(&m_mutex); + return m_modelData; + } + +Q_SIGNALS: + void queryCompleted(int queryId, int size); + +protected: + void run() { + while (!m_quit) { + m_mutex.lock(); + int queryId = m_queryId; + doQueryJob(); + if (m_size > 0) + doSubQueryJob(); + m_data.clear(); // no longer needed + m_mutex.unlock(); + + m_mutex.lock(); + if (!m_abort && m_size > 0) + emit queryCompleted(queryId, m_size); + if (!m_restart) + m_condition.wait(&m_mutex); + m_abort = false; + m_restart = false; + m_mutex.unlock(); + } + } + +private: + void doQueryJob(); + void doSubQueryJob(); + +private: + QMutex m_mutex; + QWaitCondition m_condition; + bool m_quit; + bool m_restart; + bool m_abort; + QByteArray m_data; + QString m_query; + QString m_namespaces; + QString m_prefix; + int m_size; + int m_queryId; + const QmlXmlRoleList *m_roleObjects; + QList > m_modelData; +}; + +void QmlXmlQuery::doQueryJob() +{ + QString r; + QXmlQuery query; + QBuffer buffer(&m_data); + buffer.open(QIODevice::ReadOnly); + query.bindVariable(QLatin1String("src"), &buffer); + query.setQuery(m_namespaces + m_query); + query.evaluateTo(&r); + + //qDebug() << r; + + //always need a single root element + QByteArray xml = "\n" + r.toUtf8() + ""; + QBuffer b(&xml); + b.open(QIODevice::ReadOnly); + //qDebug() << xml; + + QString namespaces = QLatin1String("declare namespace dummy=\"http://qtsotware.com/dummy\";\n") + m_namespaces; + QString prefix = QLatin1String("doc($inputDocument)/dummy:items") + + m_query.mid(m_query.lastIndexOf(QLatin1Char('/'))); + + //figure out how many items we are dealing with + int count = -1; + { + QXmlResultItems result; + QXmlQuery countquery; + countquery.bindVariable(QLatin1String("inputDocument"), &b); + countquery.setQuery(namespaces + QLatin1String("count(") + prefix + QLatin1String(")")); + countquery.evaluateTo(&result); + QXmlItem item(result.next()); + if (item.isAtomicValue()) + count = item.toAtomicValue().toInt(); + } + //qDebug() << count; + + m_prefix = namespaces + prefix + QLatin1String("/"); + m_data = xml; + if (count > 0) + m_size = count; +} + +void QmlXmlQuery::doSubQueryJob() +{ + m_modelData.clear(); + + QBuffer b(&m_data); + b.open(QIODevice::ReadOnly); + + QXmlQuery subquery; + subquery.bindVariable(QLatin1String("inputDocument"), &b); + + //### we might be able to condense even further (query for everything in one go) + for (int i = 0; i < m_roleObjects->size(); ++i) { + QmlXmlListModelRole *role = m_roleObjects->at(i); + if (!role->isValid()) { + QList resultList; + for (int j = 0; j < m_size; ++j) + resultList << QVariant(); + m_modelData << resultList; + continue; + } + subquery.setQuery(m_prefix + QLatin1String("(let $v := ") + role->query() + QLatin1String(" return if ($v) then ") + role->query() + QLatin1String(" else \"\")")); + QXmlResultItems output3; + subquery.evaluateTo(&output3); + QXmlItem item(output3.next()); + QList resultList; + while (!item.isNull()) { + resultList << item.toAtomicValue(); //### we used to trim strings + item = output3.next(); + } + //### should warn here if things have gone wrong. + while (resultList.count() < m_size) + resultList << QVariant(); + m_modelData << resultList; + b.seek(0); + } + + //XXX this method is much slower, but would work better for incremental loading + /*for (int j = 0; j < m_size; ++j) { + QList resultList; + for (int i = 0; i < m_roleObjects->size(); ++i) { + QmlXmlListModelRole *role = m_roleObjects->at(i); + subquery.setQuery(m_prefix.arg(j+1) + role->query()); + if (role->isStringList()) { + QStringList data; + subquery.evaluateTo(&data); + resultList << QVariant(data); + //qDebug() << data; + } else { + QString s; + subquery.evaluateTo(&s); + if (role->isCData()) { + //un-escape + s.replace(QLatin1String("<"), QLatin1String("<")); + s.replace(QLatin1String(">"), QLatin1String(">")); + s.replace(QLatin1String("&"), QLatin1String("&")); + } + resultList << s.trimmed(); + //qDebug() << s; + } + b.seek(0); + } + m_modelData << resultList; + }*/ +} + + +//TODO: error handling (currently quite fragile) +// profile doQuery and doSubquery +// support complex/nested objects? +// how do we handle data updates (like rss feed -- usually items inserted at beginning) + + +class QmlXmlListModelPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlXmlListModel) +public: + QmlXmlListModelPrivate() + : isComponentComplete(true), size(-1), highestRole(Qt::UserRole) + , reply(0), status(QmlXmlListModel::Null), progress(0.0) + , queryId(-1), roleObjects(this) {} + + bool isComponentComplete; + QUrl src; + QString xml; + QString query; + QString namespaces; + int size; + QList roles; + QStringList roleNames; + int highestRole; + QNetworkReply *reply; + QmlXmlListModel::Status status; + qreal progress; + QmlXmlQuery qmlXmlQuery; + int queryId; + QmlXmlRoleList roleObjects; + QList > data; +}; + + +void QmlXmlRoleList::append(QmlXmlListModelRole *role) { + QmlConcreteList::append(role); + model->roles << model->highestRole; + model->roleNames << role->name(); + ++model->highestRole; +} + +//XXX clear, removeAt, and insert need to invalidate any cached data (in data table) as well +// (and the model should emit the appropriate signals) +void QmlXmlRoleList::clear() +{ + model->roles.clear(); + model->roleNames.clear(); + QmlConcreteList::clear(); +} + +void QmlXmlRoleList::removeAt(int i) +{ + model->roles.removeAt(i); + model->roleNames.removeAt(i); + QmlConcreteList::removeAt(i); +} + +//### we should enforce unique role names +void QmlXmlRoleList::insert(int i, QmlXmlListModelRole *role) +{ + QmlConcreteList::insert(i, role); + model->roles.insert(i, model->highestRole); + model->roleNames.insert(i, role->name()); + ++model->highestRole; +} + +/*! + \class QmlXmlListModel + \internal +*/ + +/*! + \qmlclass XmlListModel QmlXmlListModel + \brief The XmlListModel element allows you to specify a model using XPath expressions. + + XmlListModel allows you to construct a model from XML data that can then be used as a data source + for the view classes (ListView, PathView, GridView) and any other classes that interact with model + data (like Repeater). + + The following is an example of a model containing news from a Yahoo RSS feed: + \qml + XmlListModel { + id: feedModel + source: "http://rss.news.yahoo.com/rss/oceania" + query: "/rss/channel/item" + XmlRole { name: "title"; query: "title/string()" } + XmlRole { name: "link"; query: "link/string()" } + XmlRole { name: "description"; query: "description/string()" } + } + \endqml + \note The model is currently static, so the above is really just a snapshot of an RSS feed. To force a + reload of the entire model, you can call the reload function. +*/ + +QmlXmlListModel::QmlXmlListModel(QObject *parent) + : QListModelInterface(*(new QmlXmlListModelPrivate), parent) +{ + Q_D(QmlXmlListModel); + connect(&d->qmlXmlQuery, SIGNAL(queryCompleted(int,int)), + this, SLOT(queryCompleted(int,int))); +} + +QmlXmlListModel::~QmlXmlListModel() +{ +} + +/*! + \qmlproperty list XmlListModel::roles + + The roles to make available for this model. +*/ +QmlList *QmlXmlListModel::roleObjects() +{ + Q_D(QmlXmlListModel); + return &d->roleObjects; +} + +QHash QmlXmlListModel::data(int index, const QList &roles) const +{ + Q_D(const QmlXmlListModel); + QHash rv; + for (int i = 0; i < roles.size(); ++i) { + int role = roles.at(i); + int roleIndex = d->roles.indexOf(role); + rv.insert(role, roleIndex == -1 ? QVariant() : d->data.at(roleIndex).at(index)); + } + return rv; +} + +/*! + \qmlproperty int XmlListModel::count + The number of data entries in the model. +*/ +int QmlXmlListModel::count() const +{ + Q_D(const QmlXmlListModel); + return d->size; +} + +QList QmlXmlListModel::roles() const +{ + Q_D(const QmlXmlListModel); + return d->roles; +} + +QString QmlXmlListModel::toString(int role) const +{ + Q_D(const QmlXmlListModel); + int index = d->roles.indexOf(role); + if (index == -1) + return QString(); + return d->roleNames.at(index); +} + +/*! + \qmlproperty url XmlListModel::source + The location of the XML data source. + + If both source and xml are set, xml will be used. +*/ +QUrl QmlXmlListModel::source() const +{ + Q_D(const QmlXmlListModel); + return d->src; +} + +void QmlXmlListModel::setSource(const QUrl &src) +{ + Q_D(QmlXmlListModel); + if (d->src != src) { + d->src = src; + reload(); + } +} + +/*! + \qmlproperty string XmlListModel::xml + This property holds XML text set directly. + + The text is assumed to be UTF-8 encoded. + + If both source and xml are set, xml will be used. +*/ +QString QmlXmlListModel::xml() const +{ + Q_D(const QmlXmlListModel); + return d->xml; +} + +void QmlXmlListModel::setXml(const QString &xml) +{ + Q_D(QmlXmlListModel); + d->xml = xml; + reload(); +} + +/*! + \qmlproperty url XmlListModel::query + An absolute XPath query representing the base query for the model items. The query should start with + a '/' or '//'. +*/ +QString QmlXmlListModel::query() const +{ + Q_D(const QmlXmlListModel); + return d->query; +} + +void QmlXmlListModel::setQuery(const QString &query) +{ + Q_D(QmlXmlListModel); + if (!query.startsWith(QLatin1Char('/'))) { + qmlInfo(this) << tr("An XmlListModel query must start with '/' or \"//\""); + return; + } + + if (d->query != query) { + d->query = query; + reload(); + } +} + +/*! + \qmlproperty string XmlListModel::namespaceDeclarations + A set of declarations for the namespaces used in the query. +*/ +QString QmlXmlListModel::namespaceDeclarations() const +{ + Q_D(const QmlXmlListModel); + return d->namespaces; +} + +void QmlXmlListModel::setNamespaceDeclarations(const QString &declarations) +{ + Q_D(QmlXmlListModel); + if (d->namespaces != declarations) { + d->namespaces = declarations; + reload(); + } +} + +/*! + \qmlproperty enum XmlListModel::status + + This property holds the status of data source loading. It can be one of: + \list + \o Null - no data source has been set + \o Ready - nthe data source has been loaded + \o Loading - the data source is currently being loaded + \o Error - an error occurred while loading the data source + \endlist + + \sa progress + +*/ +QmlXmlListModel::Status QmlXmlListModel::status() const +{ + Q_D(const QmlXmlListModel); + return d->status; +} + +/*! + \qmlproperty real XmlListModel::progress + + This property holds the progress of data source loading, from 0.0 (nothing loaded) + to 1.0 (finished). + + \sa status +*/ +qreal QmlXmlListModel::progress() const +{ + Q_D(const QmlXmlListModel); + return d->progress; +} + +void QmlXmlListModel::classBegin() +{ + Q_D(QmlXmlListModel); + d->isComponentComplete = false; +} + +void QmlXmlListModel::componentComplete() +{ + Q_D(QmlXmlListModel); + d->isComponentComplete = true; + reload(); +} + +/*! + \qmlmethod XmlListModel::reload() + + Reloads the model. All the existing model data will be removed, and the model + will be rebuilt from scratch. +*/ +void QmlXmlListModel::reload() +{ + Q_D(QmlXmlListModel); + + if (!d->isComponentComplete) + return; + + d->qmlXmlQuery.abort(); + d->queryId = -1; + + //clear existing data + int count = d->size; + d->size = 0; + d->data.clear(); + if (count > 0) + emit itemsRemoved(0, count); + + if (d->src.isEmpty() && d->xml.isEmpty()) + return; + + if (d->reply) { + d->reply->abort(); + d->reply->deleteLater(); + d->reply = 0; + } + + if (!d->xml.isEmpty()) { + d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects); + d->progress = 1.0; + d->status = Ready; + emit progressChanged(d->progress); + emit statusChanged(d->status); + return; + } + + d->progress = 0.0; + d->status = Loading; + emit progressChanged(d->progress); + emit statusChanged(d->status); + + QNetworkRequest req(d->src); + d->reply = qmlContext(this)->engine()->networkAccessManager()->get(req); + QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(requestFinished())); + QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), + this, SLOT(requestProgress(qint64,qint64))); +} + +void QmlXmlListModel::requestFinished() +{ + Q_D(QmlXmlListModel); + if (d->reply->error() != QNetworkReply::NoError) { + disconnect(d->reply, 0, this, 0); + d->reply->deleteLater(); + d->reply = 0; + d->status = Error; + } else { + d->status = Ready; + QByteArray data = d->reply->readAll(); + d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, data, &d->roleObjects); + disconnect(d->reply, 0, this, 0); + d->reply->deleteLater(); + d->reply = 0; + } + d->progress = 1.0; + emit progressChanged(d->progress); + emit statusChanged(d->status); +} + +void QmlXmlListModel::requestProgress(qint64 received, qint64 total) +{ + Q_D(QmlXmlListModel); + if (d->status == Loading && total > 0) { + d->progress = qreal(received)/total; + emit progressChanged(d->progress); + } +} + +void QmlXmlListModel::queryCompleted(int id, int size) +{ + Q_D(QmlXmlListModel); + if (id != d->queryId) + return; + d->size = size; + if (size > 0) { + d->data = d->qmlXmlQuery.modelData(); + emit itemsInserted(0, d->size); + emit countChanged(); + } +} + +QT_END_NAMESPACE + +#include "qmlxmllistmodel.moc" diff --git a/src/declarative/util/qmlxmllistmodel_p.h b/src/declarative/util/qmlxmllistmodel_p.h new file mode 100644 index 0000000..18bf9d2 --- /dev/null +++ b/src/declarative/util/qmlxmllistmodel_p.h @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** 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 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$ +** +****************************************************************************/ + +#ifndef QMLXMLLISTMODEL_H +#define QMLXMLLISTMODEL_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlContext; + +class QmlXmlListModelRole; + +class QmlXmlListModelPrivate; +class Q_DECLARATIVE_EXPORT QmlXmlListModel : public QListModelInterface, public QmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QmlParserStatus) + Q_ENUMS(Status) + + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) + Q_PROPERTY(QUrl source READ source WRITE setSource) + Q_PROPERTY(QString xml READ xml WRITE setXml) + Q_PROPERTY(QString query READ query WRITE setQuery) + Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations) + Q_PROPERTY(QmlList *roles READ roleObjects) + Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_CLASSINFO("DefaultProperty", "roles") + +public: + QmlXmlListModel(QObject *parent = 0); + ~QmlXmlListModel(); + + virtual QHash data(int index, const QList &roles = (QList())) const; + virtual int count() const; + virtual QList roles() const; + virtual QString toString(int role) const; + + QmlList *roleObjects(); + + QUrl source() const; + void setSource(const QUrl&); + + QString xml() const; + void setXml(const QString&); + + QString query() const; + void setQuery(const QString&); + + QString namespaceDeclarations() const; + void setNamespaceDeclarations(const QString&); + + enum Status { Null, Ready, Loading, Error }; + Status status() const; + qreal progress() const; + + virtual void classBegin(); + virtual void componentComplete(); + +Q_SIGNALS: + void statusChanged(Status); + void progressChanged(qreal progress); + void countChanged(); + +public Q_SLOTS: + // ### need to use/expose Expiry to guess when to call this? + // ### property to auto-call this on reasonable Expiry? + // ### LastModified/Age also useful to guess. + // ### Probably also applies to other network-requesting types. + void reload(); + +private Q_SLOTS: + void requestFinished(); + void requestProgress(qint64,qint64); + void queryCompleted(int,int); + +private: + Q_DECLARE_PRIVATE(QmlXmlListModel) + Q_DISABLE_COPY(QmlXmlListModel) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlXmlListModel) + +QT_END_HEADER + +#endif // QMLXMLLISTMODEL_H diff --git a/src/declarative/util/qnumberformat.cpp b/src/declarative/util/qnumberformat.cpp new file mode 100644 index 0000000..c6a03e9 --- /dev/null +++ b/src/declarative/util/qnumberformat.cpp @@ -0,0 +1,225 @@ +/**************************************************************************** +** +** 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 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$ +** +****************************************************************************/ + +#include "qnumberformat_p.h" + +QT_BEGIN_NAMESPACE + +QML_DEFINE_NOCREATE_TYPE(QNumberFormat) + +QNumberFormat::QNumberFormat(QObject *parent) : QObject(parent), _number(0), _type(Decimal), + _groupingSize(0) +{ + _locale = QLocale::system(); + _groupingSeparator = _locale.groupSeparator(); + _decimalSeparator = _locale.decimalPoint(); + _currencySymbol = QLatin1Char('$'); +} + +QNumberFormat::~QNumberFormat() +{ + +} + +void QNumberFormat::updateText() +{ + QTime t; + t.start(); + static int totalTime; + + handleFormat(); + + totalTime += t.elapsed(); + emit textChanged(); +} + +void QNumberFormat::handleFormat() +{ + // ### is extremely messy + if (_format.isEmpty()) { + _text = QString(QLatin1String("%1")).arg(_number, -1, 'f', -1); + return; + } + + QString inputString; + + // ### possible to use the following parsed data in the future + + int remainingLength = _format.size(); + int currentIndex = _format.size()-1; + + int maxDigits = 0; + int minDigits = 0; + int decimalLength = 0; + + while (remainingLength > 0) { + switch(_format.at(currentIndex).unicode()) { + case ',': + if (decimalLength && !_groupingSize) + setGroupingSize(maxDigits - decimalLength); + else if (!_groupingSize) + setGroupingSize(maxDigits); + break; + case '.': + if (!decimalLength) + decimalLength = maxDigits; + break; + case '0': + minDigits++; + case '#': + maxDigits++; + break; + default: + break; + } + currentIndex--; + remainingLength--; + } + + // round given the decimal length/precision + inputString = QString(QLatin1String("%1")).arg(_number, -1, 'f', decimalLength); + + QStringList parts = inputString.split(QLatin1Char('.')); + QStringList formatParts = _format.split(QLatin1Char('.')); + + if (formatParts.size() > 2 || parts.size() > 2 ) + return; + + QString formatInt = formatParts.at(0); + + QString formatDec; + if (formatParts.size() == 2) + formatDec = formatParts.at(1); + + QString integer = parts.at(0); + + QString decimal; + if (parts.size() == 2) + decimal = parts.at(1); + + QString outputDecimal = formatDecimal(formatDec, decimal); + QString outputInteger = formatInteger(formatInt, integer); + + // insert separators + if (_groupingSize) { + unsigned int count = 0; + for (int i = outputInteger.size()-1; i > 0; i--) { + if (outputInteger.at(i).digitValue() >= 0) { + if (count == _groupingSize - 1) { + count = 0; + outputInteger.insert(i, _groupingSeparator); + } + else + count++; + } + } + } + if (!outputDecimal.isEmpty()) + _text = outputInteger + _decimalSeparator + outputDecimal; + else + _text = outputInteger; +} + +QString QNumberFormat::formatInteger(const QString &formatInt, const QString &integer) +{ + if (formatInt.isEmpty() || integer.isEmpty()) + return QString(); + + QString outputInteger; + int formatIndex = formatInt.size()-1; + + //easier for carry? + for (int index= integer.size()-1; index >= 0; index--) { + if (formatIndex < 0) { + outputInteger.push_front(integer.at(index)); + } + else { + switch(formatInt.at(formatIndex).unicode()) { + case '0': + if (index > integer.size()-1) { + outputInteger.push_front(QLatin1Char('0')); + break; + } + case '#': + outputInteger.push_front(integer.at(index)); + break; + case ',': + index++; + break; + default: + outputInteger.push_front(formatInt.at(formatIndex)); + index++; + break; + } + formatIndex--; + } + } + while (formatIndex >= 0) { + if (formatInt.at(formatIndex).unicode() != '#' && formatInt.at(formatIndex).unicode() != ',') + outputInteger.push_front(formatInt.at(formatIndex)); + formatIndex--; + } + return outputInteger; +} + +QString QNumberFormat::formatDecimal(const QString &formatDec, const QString &decimal) +{ + QString outputDecimal; + + // up to max 6 decimal places + for (int index=formatDec.size()-1; index >= 0; index--) { + switch(formatDec.at(index).unicode()) { + case '0': + outputDecimal.push_front(decimal.at(index)); + break; + case '#': + if (decimal.at(index) != QLatin1Char('0') || outputDecimal.size() > 0) + outputDecimal.push_front(decimal.at(index)); + break; + default: + outputDecimal.push_front(formatDec.at(index)); + break; + } + } + return outputDecimal; +} + +QT_END_NAMESPACE diff --git a/src/declarative/util/qnumberformat_p.h b/src/declarative/util/qnumberformat_p.h new file mode 100644 index 0000000..1a7b8e4 --- /dev/null +++ b/src/declarative/util/qnumberformat_p.h @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** 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 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$ +** +****************************************************************************/ + +#ifndef NUMBERFORMAT_H +#define NUMBERFORMAT_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +// TODO +// be able to set Locale, instead of default system for dynamic formatting +// add currency support +// add additional syntax, extend to format scientific, percentiles, significant digits etc + + +class QNumberFormat : public QObject +{ + Q_OBJECT + Q_ENUMS(NumberType) +public: + QNumberFormat(QObject *parent=0); + ~QNumberFormat(); + + enum NumberType { + Percent, + Scientific, + Currency, + Decimal + }; + + //external property, only visible + Q_PROPERTY(QString text READ text NOTIFY textChanged) + + //mutatable properties to modify the output (text) + Q_PROPERTY(qreal number READ number WRITE setNumber) + Q_PROPERTY(QString format READ format WRITE setFormat) + Q_PROPERTY(QLocale locale READ locale WRITE setLocale) + + //Format specific settings + Q_PROPERTY(unsigned short groupingSeparator READ groupingSeparator WRITE setGroupingSeparator) + Q_PROPERTY(unsigned short decimalSeperator READ decimalSeparator WRITE setDecimalSeparator) + Q_PROPERTY(unsigned int groupingSize READ groupingSize WRITE setGroupingSize) + Q_PROPERTY(unsigned short currencySymbol READ currencySymbol WRITE setCurrencySymbol) + + + QString text() const { return _text; } + + qreal number() const { return _number; } + void setNumber(qreal n) { + if (_number == n) + return; + _number = n; + updateText(); + } + + QString format() const { return _format; } + void setFormat(const QString &format) { + if (format.isEmpty()) + _format = QString::null; + else if (_format == format) + return; + + _format = format; + updateText(); + } + + QLocale locale() const { return _locale; } + void setLocale(const QLocale &locale) { _locale = locale; updateText(); } + + //Do we deal with unicode standard? or create our own + // ### since this is the backend for the number conversions, we will use the unicode + // the front-end will handle the QChar/QString -> short int + + unsigned short groupingSeparator() { return _groupingSeparator.unicode(); } + void setGroupingSeparator(unsigned short unicodeSymbol) + { + _groupingSeparator = QChar(unicodeSymbol); + } + + unsigned short decimalSeparator() { return _decimalSeparator.unicode(); } + void setDecimalSeparator(unsigned short unicodeSymbol) + { + _decimalSeparator = QChar(unicodeSymbol); + } + + unsigned short currencySymbol() { return _currencySymbol.unicode(); } + void setCurrencySymbol(unsigned short unicodeSymbol) + { + _currencySymbol = QChar(unicodeSymbol); + } + + unsigned int groupingSize() { return _groupingSize; } + void setGroupingSize(unsigned int size) + { + _groupingSize = size; + } + +Q_SIGNALS: + void textChanged(); + +private: + void updateText(); + void handleFormat(); + QString formatInteger(const QString &formatInt, const QString &integer); + QString formatDecimal(const QString &formatDec, const QString &decimal); + + qreal _number; + NumberType _type; + QChar _groupingSeparator; + QChar _decimalSeparator; + QChar _currencySymbol; + unsigned int _groupingSize; + + QLocale _locale; + QString _format; + + // only hooked member at the moment + QString _text; + +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QNumberFormat) + +QT_END_HEADER + +#endif diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index f955ef6..4223f4e 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -21,7 +21,12 @@ SOURCES += \ util/qmltimer.cpp \ util/qmlbind.cpp \ util/qmlpropertymap.cpp \ - util/qmlpixmapcache.cpp + util/qmlpixmapcache.cpp \ + util/qnumberformat.cpp \ + util/qmlnumberformatter.cpp \ + util/qmldatetimeformatter.cpp \ + util/qmlbehavior.cpp \ + util/qmlfontloader.cpp HEADERS += \ util/qmlview.h \ @@ -49,4 +54,15 @@ HEADERS += \ util/qmltimer_p.h \ util/qmlbind_p.h \ util/qmlpropertymap_p.h \ - util/qmlpixmapcache_p.h + util/qmlpixmapcache_p.h \ + util/qnumberformat_p.h \ + util/qmlnumberformatter_p.h \ + util/qmldatetimeformatter_p.h \ + util/qmlbehavior_p.h \ + util/qmlfontloader_p.h + +contains(QT_CONFIG, xmlpatterns) { + QT+=xmlpatterns + SOURCES += util/qmlxmllistmodel.cpp + HEADERS += util/qmlxmllistmodel_p.h +} -- cgit v0.12