From bef4438eea6fc44ef81c63772e10d2390586d16c Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 22 Apr 2009 15:43:08 +1000 Subject: Fix merge error. --- src/corelib/kernel/qvariant_p.h | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index 727a390..074575b 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -91,13 +91,36 @@ inline T *v_cast(QVariant::Private *d, T * = 0) #endif + +//a simple template that avoids to allocate 2 memory chunks when creating a QVariant +template class QVariantPrivateSharedEx : public QVariant::PrivateShared +{ +public: + QVariantPrivateSharedEx() : QVariant::PrivateShared(&m_t) { } + QVariantPrivateSharedEx(const T&t) : QVariant::PrivateShared(&m_t), m_t(t) { } + +private: + T m_t; +}; + // constructs a new variant if copy is 0, otherwise copy-constructs template +inline void v_construct(QVariant::Private *x, const T &t) +{ + if (sizeof(T) > sizeof(QVariant::Private::Data)) { + x->data.shared = new QVariantPrivateSharedEx(t); + x->is_shared = true; + } else { + new (&x->data.ptr) T(t); + } +} + +template inline void v_construct(QVariant::Private *x, const void *copy, T * = 0) { if (sizeof(T) > sizeof(QVariant::Private::Data)) { - x->data.shared = copy ? new QVariant::PrivateShared(new T(*static_cast(copy))) - : new QVariant::PrivateShared(new T); + x->data.shared = copy ? new QVariantPrivateSharedEx(*static_cast(copy)) + : new QVariantPrivateSharedEx; x->is_shared = true; } else { if (copy) @@ -111,12 +134,15 @@ inline void v_construct(QVariant::Private *x, const void *copy, T * = 0) template inline void v_clear(QVariant::Private *d, T* = 0) { + if (sizeof(T) > sizeof(QVariant::Private::Data)) { - delete v_cast(d); - delete d->data.shared; + //now we need to cast + //because QVariant::PrivateShared doesn't have a virtual destructor + delete static_cast*>(d->data.shared); } else { v_cast(d)->~T(); } + } QT_END_NAMESPACE -- cgit v0.12 From a1458a0426caa71bab4527ca079c3004bb2b5abd Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 22 Apr 2009 16:55:04 +1000 Subject: Make compile I've temporarily commented out the body of qguivariantanimation.cpp so we can compile. --- src/declarative/util/qmlanimation.cpp | 4 ++-- src/gui/animation/qguivariantanimation.cpp | 4 ++-- src/opengl/opengl.pro | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 803f2b2..729d53a 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -323,8 +323,8 @@ void QmlAbstractAnimation::setRepeat(bool r) return; d->repeat = r; - int ic = r ? -1 : 1; - qtAnimation()->setIterationCount(ic); + int lc = r ? -1 : 1; + qtAnimation()->setLoopCount(lc); emit repeatChanged(r); } diff --git a/src/gui/animation/qguivariantanimation.cpp b/src/gui/animation/qguivariantanimation.cpp index 46ba251..fab377a 100644 --- a/src/gui/animation/qguivariantanimation.cpp +++ b/src/gui/animation/qguivariantanimation.cpp @@ -41,7 +41,7 @@ #ifndef QT_NO_ANIMATION -QT_BEGIN_NAMESPACE +/*QT_BEGIN_NAMESPACE #ifdef QT_EXPERIMENTAL_SOLUTION # include "qvariantanimation.h" @@ -74,6 +74,6 @@ static int qUnregisterGuiGetInterpolator() } Q_DESTRUCTOR_FUNCTION(qUnregisterGuiGetInterpolator) -QT_END_NAMESPACE +QT_END_NAMESPACE*/ #endif //QT_NO_ANIMATION diff --git a/src/opengl/opengl.pro b/src/opengl/opengl.pro index f9fa0d0..ad75a5f 100644 --- a/src/opengl/opengl.pro +++ b/src/opengl/opengl.pro @@ -25,7 +25,6 @@ HEADERS += qgl.h \ qglcolormap.h \ qglpixelbuffer.h \ qglframebufferobject.h \ - qglpixmapfilter_p.h \ qglshaderprogram.h SOURCES += qgl.cpp \ @@ -33,11 +32,10 @@ SOURCES += qgl.cpp \ qglpixelbuffer.cpp \ qglframebufferobject.cpp \ qglextensions.cpp \ - qglpixmapfilter.cpp \ qglshaderprogram.cpp !contains(QT_CONFIG, opengles2) { - HEADERS += qpaintengine_opengl_p.h qglpixmapfilter_p.h + HEADERS += qpaintengine_opengl_p.h qglpixmapfilter_p.h SOURCES += qpaintengine_opengl.cpp qglpixmapfilter.cpp } -- cgit v0.12 From 6504e06561b9127eb6179b5a5deb8f6cd1fff491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Tue, 21 Apr 2009 12:06:22 +0200 Subject: Fixes for solution package. --- bin/snapshot | 122 ++++++++++++++--------- examples/animation/animatedtiles/main.cpp | 1 + examples/animation/sub-attaq/boat.cpp | 1 + examples/animation/sub-attaq/boat.h | 2 +- examples/animation/sub-attaq/qanimationstate.cpp | 3 +- examples/animation/sub-attaq/submarine.cpp | 9 +- src/gui/animation/qguivariantanimation.cpp | 5 +- 7 files changed, 89 insertions(+), 54 deletions(-) diff --git a/bin/snapshot b/bin/snapshot index 783d15c..b9a64e1 100644 --- a/bin/snapshot +++ b/bin/snapshot @@ -14,6 +14,40 @@ use strict; my $targetPath = ""; my $qtdir = $ENV{"QTDIR"}; +my @class_renames = ( + "QAbstractAnimation", + "QAnimationGroup", + "QParallelAnimationGroup", + "QSequentialAnimationGroup", + "QEasingCurve", + "QVariantAnimation", + "QPropertyAnimation", + "QItemAnimation", + "QPauseAnimation", + "QAbstractState", + "QAbstractStateGroup", + "QAbstractTransition", + "QActionState", + "QEventTransition", + "QFinalState", + "QHistoryState", + "QParallelStateGroup", + "QSignalEvent", + "QSignalTransition", + "QState", + "QStateAction", + "QStateInvokeMethodAction", + "QStateFinishedEvent", + "QStateFinishedTransition", + "QStateMachine", + "QTransition", + "QMouseEventTransition", + "QBasicMouseEventTransition", + "QKeyEventTransition", + "QBasicKeyEventTransition", + "QGraphicsWidget", + "QBoundEvent"); + my @files = ( "3rdparty/easing/easing.cpp", "corelib/tools/qeasingcurve.h", @@ -40,6 +74,8 @@ my @files = ( "corelib/animation/qsequentialanimationgroup.h", "corelib/animation/qsequentialanimationgroup_p.h", "gui/animation/qguivariantanimation.cpp", + "gui/animation/animation.pri", + "corelib/statemachine/statemachine.pri", "corelib/statemachine/qabstractstate.cpp", "corelib/statemachine/qabstractstate.h", @@ -110,13 +146,13 @@ open(OXML, "> " . $projectXML) || die "Could not open $projectXML for writing (n print "COPYING SOURCES...\n"; foreach my $files(@files) { - copyFile("$qtdir/src/$files","$targetPath/src"); + copyFile("$qtdir/src/$files","$targetPath/src", 1); } -copyFile("$qtdir/doc/src/animation.qdoc","$targetPath/doc"); -copyFile("$qtdir/doc/src/statemachine.qdoc","$targetPath/doc"); -copyFile("$qtdir/src/3rdparty/easing/legal.qdoc","$targetPath/doc"); +copyFile("$qtdir/doc/src/animation.qdoc","$targetPath/doc", 0); +copyFile("$qtdir/doc/src/statemachine.qdoc","$targetPath/doc", 0); +copyFile("$qtdir/src/3rdparty/easing/legal.qdoc","$targetPath/doc", 0); -copyFile("$qtdir/doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp","$targetPath/doc/src/snippets/code"); +copyFile("$qtdir/doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp","$targetPath/doc/src/snippets/code", 0); my %animation_examples = ( @@ -150,7 +186,9 @@ my %animation_examples = ( "mainwindow.cpp", "mainwindow.h", "pics/scalable/*", - "pics/big/*", + "pics/big/*.png", + "pics/big/explosion/boat/*", + "pics/big/explosion/submarine/*", "pics/small/*", "pics/welcome/*", "pixmapitem.cpp", @@ -161,8 +199,11 @@ my %animation_examples = ( "submarine_p.h", "states.cpp", "states.h", + "qanimationstate.cpp", + "qanimationstate.h", "torpedo.cpp", - "torpedo.h"], + "torpedo.h", + "data.xml"], "stickman" => ["stickman.pro", "main.cpp", "animation.cpp", @@ -175,6 +216,7 @@ my %animation_examples = ( "node.h", "stickman.cpp", "stickman.h", + "editor/*", "animations/chilling", "animations/dancing", "animations/dead", @@ -193,7 +235,7 @@ for $exDir ( keys %animation_examples ) { my $glob = 0; if (index($ex_file,"/") > 0) { my($basefile, $fullPath) = fileparse("$targetPath/examples/$exDir/$ex_file"); - if ($basefile eq "*") { + if (index($basefile, "*") >= 0) { $glob = 1; } mkpath "$fullPath", 0777 unless(-e "$fullPath"); @@ -209,20 +251,25 @@ for $exDir ( keys %animation_examples ) { if ($glob eq 1) { my @globFiles = < $qtdir/examples/animation/$exDir/$ex_file >; foreach my $globFile(@globFiles) { - copyFile("$globFile", "$copyTargetPath"); + copyFile("$globFile", "$copyTargetPath", 0); } } else { - copyFile("$qtdir/examples/animation/$exDir/$ex_file", "$copyTargetPath"); + copyFile("$qtdir/examples/animation/$exDir/$ex_file", "$copyTargetPath", 0); } } } close OXML; print("Finished!"); + + ###################################################################### # Syntax: copyFile(gitfile, destinationPath) # Params: gitfile, string, filename to create duplicate for # destinationPath, string, destination name of duplicate +# autoRename, int, 0: Don't rename +# 1: The file should be renamed to have the "qt" prefix +# # # Purpose: Copies to the solutions area. # Returns: -- @@ -230,7 +277,7 @@ print("Finished!"); ###################################################################### sub copyFile { - my ($gitfile, $destinationPath) = @_; + my ($gitfile, $destinationPath, $autoRename) = @_; # Bi-directional synchronization open( I, "< " . $gitfile ) || die "Could not open $gitfile for reading"; local $/; @@ -239,44 +286,20 @@ sub copyFile my ($baseFileName, $path, $ext) = fileparse($gitfile, qr/\.[^.]*/); if ($ext eq ".h" or $ext eq ".cpp" or $ext eq ".qdoc") { # both public and private classes - $filecontents =~s/QAbstractAnimation/QtAbstractAnimation/g; - $filecontents =~s/QAnimationGroup/QtAnimationGroup/g; - $filecontents =~s/QParallelAnimationGroup/QtParallelAnimationGroup/g; - $filecontents =~s/QSequentialAnimationGroup/QtSequentialAnimationGroup/g; - $filecontents =~s/QEasingCurve/QtEasingCurve/g; - $filecontents =~s/QVariantAnimation/QtVariantAnimation/g; - $filecontents =~s/QPropertyAnimation/QtPropertyAnimation/g; - $filecontents =~s/QItemAnimation/QtItemAnimation/g; - $filecontents =~s/QPauseAnimation/QtPauseAnimation/g; - $filecontents =~s/QAbstractState/QtAbstractState/g; - $filecontents =~s/QAbstractStateGroup/QtAbstractStateGroup/g; - $filecontents =~s/QAbstractTransition/QtAbstractTransition/g; - $filecontents =~s/QActionState/QtActionState/g; - $filecontents =~s/QEventTransition/QtEventTransition/g; - $filecontents =~s/QFinalState/QtFinalState/g; - $filecontents =~s/QHistoryState/QtHistoryState/g; - $filecontents =~s/QParallelStateGroup/QtParallelStateGroup/g; - $filecontents =~s/QSignalEvent/QtSignalEvent/g; - $filecontents =~s/QSignalTransition/QtSignalTransition/g; - $filecontents =~s/QState/QtState/g; - $filecontents =~s/QStateAction/QtStateAction/g; - $filecontents =~s/QStateInvokeMethodAction/QtStateInvokeMethodAction/g; - $filecontents =~s/QStateFinishedEvent/QtStateFinishedEvent/g; - $filecontents =~s/QStateFinishedTransition/QtStateFinishedTransition/g; - $filecontents =~s/QStateMachine/QtStateMachine/g; - $filecontents =~s/QActionTransition/QtActionTransition/g; - $filecontents =~s/QMouseEventTransition/QtMouseEventTransition/g; - $filecontents =~s/QKeyEventTransition/QtKeyEventTransition/g; - $filecontents =~s/QGraphicsWidget/QtGraphicsWidget/g; + foreach my $qtClass(@class_renames) { + my $solutionClass = $qtClass; + $solutionClass =~s/^Q/Qt/g; + $filecontents =~s/$qtClass/$solutionClass/g; + my $qtFilename = lc($qtClass); + my $solutionFilename = lc($solutionClass); + $filecontents =~s/(#\s*include\s+["])$qtFilename/${1}$solutionFilename/g; + } + $filecontents =~s/Q_CORE_EXPORT/Q_ANIMATION_EXPORT/g; $filecontents =~s/Q_GUI_EXPORT/Q_ANIMATION_EXPORT/g; - $filecontents =~s/QBoundEvent/QtBoundEvent/g; - $filecontents =~s/class Q_GUI_EXPORT/class/g; $filecontents =~s/class Q_AUTOTEST_EXPORT/class/g; - $filecontents =~s/(#\s*include\s+["])q/${1}qt/g; - # moc stuff $filecontents =~s/(#\s*include\s+["])moc_q/${1}moc_qt/g; @@ -300,7 +323,14 @@ sub copyFile if (index($gitfile, "gui/statemachine") >= 0) { $baseFileName = "gui_statemachine"; } - + } + if ($baseFileName eq "animation") { + if (index($gitfile, "corelib/animation") >= 0) { + $baseFileName = "corelib_animation"; + } + if (index($gitfile, "gui/animation") >= 0) { + $baseFileName = "gui_animation"; + } } } @@ -312,7 +342,7 @@ sub copyFile mkpath $destinationPath, 0777 unless(-e "$destinationPath"); - if ($ext eq ".h" or $ext eq ".cpp" or $ext eq ".qdoc") { + if ($autoRename eq 1 and ($ext eq ".h" or $ext eq ".cpp" or $ext eq ".qdoc")) { $baseFileName =~s/^q/qt/g; } my $targetFile = "$destinationPath/$baseFileName$ext"; diff --git a/examples/animation/animatedtiles/main.cpp b/examples/animation/animatedtiles/main.cpp index cfaa4ce..9b0b0a5 100644 --- a/examples/animation/animatedtiles/main.cpp +++ b/examples/animation/animatedtiles/main.cpp @@ -7,6 +7,7 @@ # include "qgraphicswidget.h" # include "qparallelanimationgroup.h" # include "qpropertyanimation.h" +# include "qsignaltransition.h" #else #include #endif diff --git a/examples/animation/sub-attaq/boat.cpp b/examples/animation/sub-attaq/boat.cpp index 633e1b1..5721485 100644 --- a/examples/animation/sub-attaq/boat.cpp +++ b/examples/animation/sub-attaq/boat.cpp @@ -56,6 +56,7 @@ # include "qhistorystate.h" # include "qfinalstate.h" # include "qstate.h" +# include "qpauseanimation.h" #include "qsequentialanimationgroup.h" #else #include diff --git a/examples/animation/sub-attaq/boat.h b/examples/animation/sub-attaq/boat.h index 4c4a737..b8d5772 100644 --- a/examples/animation/sub-attaq/boat.h +++ b/examples/animation/sub-attaq/boat.h @@ -49,7 +49,7 @@ #include #if defined(QT_EXPERIMENTAL_SOLUTION) -# include "qgraphicswidget.h" +# include "qtgraphicswidget.h" #else # include #endif diff --git a/examples/animation/sub-attaq/qanimationstate.cpp b/examples/animation/sub-attaq/qanimationstate.cpp index 70285a8..3659657 100644 --- a/examples/animation/sub-attaq/qanimationstate.cpp +++ b/examples/animation/sub-attaq/qanimationstate.cpp @@ -43,11 +43,12 @@ #if defined(QT_EXPERIMENTAL_SOLUTION) # include "qstate.h" +# include "qstate_p.h" #else # include +# include #endif -#include QT_BEGIN_NAMESPACE diff --git a/examples/animation/sub-attaq/submarine.cpp b/examples/animation/sub-attaq/submarine.cpp index e64ffdd..555617c 100644 --- a/examples/animation/sub-attaq/submarine.cpp +++ b/examples/animation/sub-attaq/submarine.cpp @@ -50,10 +50,11 @@ #include "qanimationstate.h" #if defined(QT_EXPERIMENTAL_SOLUTION) -#include "qpropertyanimation.h" -#include "qstatemachine.h" -#include "qfinalstate.h" -#include "qsequentialanimationgroup.h" +# include "qpropertyanimation.h" +# include "qstatemachine.h" +# include "qfinalstate.h" +# include "qsequentialanimationgroup.h" +# include "qpauseanimation.h" #else #include #include diff --git a/src/gui/animation/qguivariantanimation.cpp b/src/gui/animation/qguivariantanimation.cpp index 46ba251..ed18caa 100644 --- a/src/gui/animation/qguivariantanimation.cpp +++ b/src/gui/animation/qguivariantanimation.cpp @@ -41,8 +41,6 @@ #ifndef QT_NO_ANIMATION -QT_BEGIN_NAMESPACE - #ifdef QT_EXPERIMENTAL_SOLUTION # include "qvariantanimation.h" # include "qvariantanimation_p.h" @@ -51,6 +49,9 @@ QT_BEGIN_NAMESPACE #include #endif +#include + +QT_BEGIN_NAMESPACE template<> Q_INLINE_TEMPLATE QColor _q_interpolate(const QColor &f,const QColor &t, qreal progress) { -- cgit v0.12 From ebda84cd06faaf440a096bda7966fa795ca86318 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Tue, 21 Apr 2009 15:39:37 +0200 Subject: Fixes QPropertyAnimation's default start value update condition The default start value is updated when the animation changes from Stopped to Running state. Reviewed-by: Jan-Arve --- src/corelib/animation/qpropertyanimation.cpp | 22 +++++++++++++++------- src/corelib/animation/qvariantanimation_p.h | 14 +------------- .../qpropertyanimation/tst_qpropertyanimation.cpp | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp index edcabaa..9a0c5bc 100644 --- a/src/corelib/animation/qpropertyanimation.cpp +++ b/src/corelib/animation/qpropertyanimation.cpp @@ -49,7 +49,7 @@ by itself as a simple animation class, or as part of more complex animations through QAnimationGroup. - The most common way to use QPropertyAnimation is to construct an instance + The most common way to use QPropertyAnimation is to construct an instance of it by passing a pointer to a QObject or a QWidget, and the name of the property you would like to animate to QPropertyAnimation's constructor. @@ -220,11 +220,20 @@ void QPropertyAnimation::updateCurrentValue(const QVariant &value) /*! \reimp + + If the startValue is not defined when the state of the animation changes from Stopped to Running, + the current property value is used as the initial value for the animation. */ void QPropertyAnimation::updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState) { Q_D(QPropertyAnimation); + + if (!d->target) { + qWarning("QPropertyAnimation::updateState: Changing state of an animation without target"); + return; + } + QVariantAnimation::updateState(oldState, newState); QMutexLocker locker(guardHashLock()); QPropertyAnimationHash * hash = _q_runningAnimations(); @@ -235,20 +244,19 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State oldState, if (oldAnim) { // try to stop the top level group QAbstractAnimation *current = oldAnim; - while(current->group() && current->state() != Stopped) current = current->group(); + while (current->group() && current->state() != Stopped) + current = current->group(); current->stop(); } hash->insert(key, this); - // Initialize start value - // ### review this line below, d->atEnd() ? - // ### avoid entering a state where start value is not set - if (d->target && (d->atBeginning() || d->atEnd())) { + + // update the default start value + if (oldState == Stopped) { d->setDefaultStartValue(d->target->property(d->propertyName.constData())); } } else if (hash->value(key) == this) { hash->remove(key); } - } #include "moc_qpropertyanimation.cpp" diff --git a/src/corelib/animation/qvariantanimation_p.h b/src/corelib/animation/qvariantanimation_p.h index 66910c1..14a3ef6 100644 --- a/src/corelib/animation/qvariantanimation_p.h +++ b/src/corelib/animation/qvariantanimation_p.h @@ -88,18 +88,6 @@ public: return q->d_func(); } - - //some helper functions - bool atBeginning() const - { - return currentTime == 0; - } - - bool atEnd() const - { - return currentTime == duration && currentLoop == (loopCount - 1); - } - void setDefaultStartValue(const QVariant &value); int duration; @@ -109,7 +97,7 @@ public: QVariant currentValue; QVariant defaultStartValue; bool hasStartValue; - + //this is used to keep track of the KeyValue interval in which we currently are struct { diff --git a/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp index 437c862..f0deab5 100644 --- a/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp +++ b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp @@ -84,6 +84,7 @@ private slots: void deletion3(); void duration0(); void noStartValue(); + void noStartValueWithLoop(); void startWhenAnotherIsRunning(); void easingcurve_data(); void easingcurve(); @@ -416,6 +417,27 @@ void tst_QPropertyAnimation::noStartValue() QCOMPARE(o.values.last(), 420); } +void tst_QPropertyAnimation::noStartValueWithLoop() +{ + StartValueTester o; + o.setProperty("ole", 42); + o.values.clear(); + + QPropertyAnimation a(&o, "ole"); + a.setEndValue(420); + a.setDuration(250); + a.setLoopCount(2); + a.start(); + + a.setCurrentTime(250); + QCOMPARE(o.values.first(), 42); + QCOMPARE(a.currentValue().toInt(), 42); + QCOMPARE(o.values.last(), 42); + + a.setCurrentTime(500); + QCOMPARE(a.currentValue().toInt(), 420); +} + void tst_QPropertyAnimation::startWhenAnotherIsRunning() { StartValueTester o; -- cgit v0.12 From 0e8b82bc7b9b0d88e8cc4a4d293851795d35950a Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 23 Apr 2009 10:07:02 +1000 Subject: Fix sefaults introduced by merge. For now, use kinetic-animations' version of the qvariant changes, as the ones in master cause segfaults. --- src/corelib/kernel/qvariant.cpp | 99 +++++++++++++++++++++++------------------ src/corelib/kernel/qvariant.h | 17 +------ src/corelib/kernel/qvariant_p.h | 43 ++++++++---------- 3 files changed, 76 insertions(+), 83 deletions(-) diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index ea66658..b4427c0 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -71,6 +71,27 @@ QT_BEGIN_NAMESPACE # define FLT_DIG 6 #endif + +static const void *constDataHelper(const QVariant::Private &d) +{ + switch (d.type) { + case QVariant::Int: + return &d.data.i; + case QVariant::UInt: + return &d.data.u; + case QVariant::Bool: + return &d.data.b; + case QVariant::LongLong: + return &d.data.ll; + case QVariant::ULongLong: + return &d.data.ull; + case QVariant::Double: + return &d.data.d; + default: + return d.is_shared ? d.data.shared->ptr : reinterpret_cast(&d.data.ptr); + } +} + static void construct(QVariant::Private *x, const void *copy) { x->is_shared = false; @@ -158,9 +179,6 @@ static void construct(QVariant::Private *x, const void *copy) case QVariant::Double: x->data.d = copy ? *static_cast(copy) : 0.0; break; - case QMetaType::Float: - x->data.f = copy ? *static_cast(copy) : 0.0f; - break; case QVariant::LongLong: x->data.ll = copy ? *static_cast(copy) : Q_INT64_C(0); break; @@ -256,7 +274,6 @@ static void clear(QVariant::Private *d) case QVariant::LongLong: case QVariant::ULongLong: case QVariant::Double: - case QMetaType::Float: break; case QVariant::Invalid: case QVariant::UserType: @@ -474,7 +491,7 @@ static qlonglong qMetaTypeNumber(const QVariant::Private *d) case QMetaType::Long: return qlonglong(*static_cast(d->data.shared->ptr)); case QMetaType::Float: - return qRound64(d->data.f); + return qRound64(*static_cast(d->data.shared->ptr)); case QVariant::Double: return qRound64(d->data.d); } @@ -611,7 +628,7 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, *str = QString::number(qMetaTypeUNumber(d)); break; case QMetaType::Float: - *str = QString::number(d->data.f, 'g', FLT_DIG); + *str = QString::number(*static_cast(d->data.shared->ptr), 'g', FLT_DIG); break; case QVariant::Double: *str = QString::number(d->data.d, 'g', DBL_DIG); @@ -782,7 +799,7 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, *ba = QByteArray::number(d->data.d, 'g', DBL_DIG); break; case QMetaType::Float: - *ba = QByteArray::number(d->data.f, 'g', FLT_DIG); + *ba = QByteArray::number(*static_cast(d->data.shared->ptr), 'g', FLT_DIG); break; case QMetaType::Char: case QMetaType::UChar: @@ -884,7 +901,7 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, *f = double(d->data.b); break; case QMetaType::Float: - *f = double(d->data.f); + *f = *static_cast(d->data.shared->ptr); break; case QVariant::LongLong: case QVariant::Int: @@ -1338,7 +1355,7 @@ void QVariant::create(int type, const void *copy) QVariant::~QVariant() { - if (d.type > Char && d.type != QMetaType::Float && (!d.is_shared || !d.data.shared->ref.deref())) + if (d.type > Char && (!d.is_shared || !d.data.shared->ref.deref())) handler->clear(&d); } @@ -1354,7 +1371,7 @@ QVariant::QVariant(const QVariant &p) { if (d.is_shared) { d.data.shared->ref.ref(); - } else if (p.d.type > Char && p.d.type != QMetaType::Float) { + } else if (p.d.type > Char) { handler->construct(&d, p.constData()); d.is_null = p.d.is_null; } @@ -1548,12 +1565,6 @@ QVariant::QVariant(const char *val) */ /*! - \fn QVariant::QVariant(float val) - - Constructs a new variant with a floating point value, \a val. -*/ - -/*! \fn QVariant::QVariant(const QList &val) Constructs a new variant with a list value, \a val. @@ -1608,44 +1619,44 @@ QVariant::QVariant(double val) { d.is_null = false; d.type = Double; d.data.d = val; } QVariant::QVariant(const QByteArray &val) -{ d.is_null = false; d.type = ByteArray; v_construct(&d, val); } +{ create(ByteArray, &val); } QVariant::QVariant(const QBitArray &val) -{ d.is_null = false; d.type = BitArray; v_construct(&d, val); } +{ create(BitArray, &val); } QVariant::QVariant(const QString &val) -{ d.is_null = false; d.type = String; v_construct(&d, val); } +{ create(String, &val); } QVariant::QVariant(const QChar &val) -{ d.is_null = false; d.type = Char; v_construct(&d, val); } +{ create (Char, &val); } QVariant::QVariant(const QLatin1String &val) -{ QString str(val); d.is_null = false; d.type = String; v_construct(&d, str); } +{ QString str(val); create(String, &str); } QVariant::QVariant(const QStringList &val) -{ d.is_null = false; d.type = StringList; v_construct(&d, val); } +{ create(StringList, &val); } QVariant::QVariant(const QDate &val) -{ d.is_null = false; d.type = Date; v_construct(&d, val); } +{ create(Date, &val); } QVariant::QVariant(const QTime &val) -{ d.is_null = false; d.type = Time; v_construct(&d, val); } +{ create(Time, &val); } QVariant::QVariant(const QDateTime &val) -{ d.is_null = false; d.type = DateTime; v_construct(&d, val); } +{ create(DateTime, &val); } QVariant::QVariant(const QList &list) -{ d.is_null = false; d.type = List; v_construct(&d, list); } +{ create(List, &list); } QVariant::QVariant(const QMap &map) -{ d.is_null = false; d.type = Map; v_construct(&d, map); } +{ create(Map, &map); } QVariant::QVariant(const QHash &hash) -{ d.is_null = false; d.type = Hash; v_construct(&d, hash); } +{ create(Hash, &hash); } #ifndef QT_NO_GEOM_VARIANT -QVariant::QVariant(const QPoint &pt) { d.is_null = false; d.type = Point; v_construct(&d, pt); } -QVariant::QVariant(const QPointF &pt) { d.is_null = false; d.type = PointF; v_construct(&d, pt); } -QVariant::QVariant(const QRectF &r) { d.is_null = false; d.type = RectF; v_construct(&d, r); } -QVariant::QVariant(const QLineF &l) { d.is_null = false; d.type = LineF; v_construct(&d, l); } -QVariant::QVariant(const QLine &l) { d.is_null = false; d.type = Line; v_construct(&d, l); } -QVariant::QVariant(const QRect &r) { d.is_null = false; d.type = Rect; v_construct(&d, r); } -QVariant::QVariant(const QSize &s) { d.is_null = false; d.type = Size; v_construct(&d, s); } -QVariant::QVariant(const QSizeF &s) { d.is_null = false; d.type = SizeF; v_construct(&d, s); } +QVariant::QVariant(const QPoint &pt) { create(Point, &pt); } +QVariant::QVariant(const QPointF &pt) { create (PointF, &pt); } +QVariant::QVariant(const QRectF &r) { create (RectF, &r); } +QVariant::QVariant(const QLineF &l) { create (LineF, &l); } +QVariant::QVariant(const QLine &l) { create (Line, &l); } +QVariant::QVariant(const QRect &r) { create(Rect, &r); } +QVariant::QVariant(const QSize &s) { create(Size, &s); } +QVariant::QVariant(const QSizeF &s) { create(SizeF, &s); } #endif -QVariant::QVariant(const QUrl &u) { d.is_null = false; d.type = Url; v_construct(&d, u); } -QVariant::QVariant(const QLocale &l) { d.is_null = false; d.type = Locale; v_construct(&d, l); } +QVariant::QVariant(const QUrl &u) { create(Url, &u); } +QVariant::QVariant(const QLocale &l) { create(Locale, &l); } #ifndef QT_NO_REGEXP -QVariant::QVariant(const QRegExp ®Exp) { d.is_null = false; d.type = RegExp; v_construct(&d, regExp); } +QVariant::QVariant(const QRegExp ®Exp) { create(RegExp, ®Exp); } #endif QVariant::QVariant(Qt::GlobalColor color) { create(62, &color); } @@ -1710,7 +1721,7 @@ QVariant& QVariant::operator=(const QVariant &variant) if (variant.d.is_shared) { variant.d.data.shared->ref.ref(); d = variant.d; - } else if (variant.d.type > Char && variant.d.type != QMetaType::Float) { + } else if (variant.d.type > Char) { d.type = variant.d.type; handler->construct(&d, variant.constData()); d.is_null = variant.d.is_null; @@ -1896,7 +1907,7 @@ void QVariant::load(QDataStream &s) } // const cast is safe since we operate on a newly constructed variant - if (!QMetaType::load(s, d.type, const_cast(constData()))) { + if (!QMetaType::load(s, d.type, const_cast(constDataHelper(d)))) { s.setStatus(QDataStream::ReadCorruptData); qWarning("QVariant::load: unable to load type %d.", d.type); } @@ -1936,7 +1947,7 @@ void QVariant::save(QDataStream &s) const return; } - if (!QMetaType::save(s, d.type, constData())) { + if (!QMetaType::save(s, d.type, constDataHelper(d))) { Q_ASSERT_X(false, "QVariant::save", "Invalid type to save"); qWarning("QVariant::save: unable to save type %d.", d.type); } @@ -2715,7 +2726,7 @@ bool QVariant::cmp(const QVariant &v) const const void *QVariant::constData() const { - return d.is_shared ? d.data.shared->ptr : reinterpret_cast(&d.data.ptr); + return constDataHelper(d); } /*! @@ -2728,7 +2739,7 @@ const void *QVariant::constData() const void* QVariant::data() { detach(); - return const_cast(constData()); + return const_cast(constDataHelper(d)); } diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index d73fcbc..580b101 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -128,7 +128,7 @@ class Q_CORE_EXPORT QVariant LineF = 24, Point = 25, PointF = 26, - RegExp = 27, + RegExp = 27, Hash = 28, LastCoreType = Hash, @@ -181,7 +181,6 @@ class Q_CORE_EXPORT QVariant QVariant(qulonglong ull); QVariant(bool b); QVariant(double d); - QVariant(float f) { d.is_null = false; d.type = QMetaType::Float; d.data.f = f; } #ifndef QT_NO_CAST_FROM_ASCII QT_ASCII_CAST_WARN_CONSTRUCTOR QVariant(const char *str); #endif @@ -350,7 +349,6 @@ class Q_CORE_EXPORT QVariant uint u; bool b; double d; - float f; qlonglong ll; qulonglong ull; void *ptr; @@ -445,18 +443,7 @@ inline QVariant qVariantFromValue(const QVariant &t) { return t; } template inline void qVariantSetValue(QVariant &v, const T &t) { - //if possible we reuse the current QVariant private - const int type = qMetaTypeId(reinterpret_cast(0)); - QVariant::Private &d = v.data_ptr(); - if (type <= int(QVariant::Char) || (type == d.type && v.isDetached())) { - d.type = type; - T *old = reinterpret_cast(d.is_shared ? d.data.shared->ptr : &d.data.ptr); - if (QTypeInfo::isComplex) - old->~T(); - new (old) T(t); //call the copy constructor - } else { - v = QVariant(type, &t); - } + v = QVariant(qMetaTypeId(reinterpret_cast(0)), &t); } inline QVariant::QVariant() {} diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index 074575b..0764fe3 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -60,6 +60,8 @@ QT_BEGIN_NAMESPACE +extern Q_CORE_EXPORT const QVariant::Handler *qExtendedVariantHandler; + #ifdef Q_CC_SUN // Sun CC picks the wrong overload, so introduce awful hack template @@ -68,7 +70,7 @@ inline T *v_cast(const QVariant::Private *nd, T * = 0) QVariant::Private *d = const_cast(nd); return ((sizeof(T) > sizeof(QVariant::Private::Data)) ? static_cast(d->data.shared->ptr) - : static_cast(static_cast(&d->data.c))); + : reinterpret_cast(&d->data.c)); } #else // every other compiler in this world @@ -78,7 +80,7 @@ inline const T *v_cast(const QVariant::Private *d, T * = 0) { return ((sizeof(T) > sizeof(QVariant::Private::Data)) ? static_cast(d->data.shared->ptr) - : static_cast(static_cast(&d->data.c))); + : reinterpret_cast(&d->data.c)); } template @@ -86,17 +88,15 @@ inline T *v_cast(QVariant::Private *d, T * = 0) { return ((sizeof(T) > sizeof(QVariant::Private::Data)) ? static_cast(d->data.shared->ptr) - : static_cast(static_cast(&d->data.c))); + : reinterpret_cast(&d->data.c)); } #endif - -//a simple template that avoids to allocate 2 memory chunks when creating a QVariant +//a simple template that avoids to allocate 2 buffers when creating a QVariant template class QVariantPrivateSharedEx : public QVariant::PrivateShared { public: - QVariantPrivateSharedEx() : QVariant::PrivateShared(&m_t) { } QVariantPrivateSharedEx(const T&t) : QVariant::PrivateShared(&m_t), m_t(t) { } private: @@ -105,12 +105,14 @@ private: // constructs a new variant if copy is 0, otherwise copy-constructs template -inline void v_construct(QVariant::Private *x, const T &t) +inline void v_construct(QVariant::Private *x, const T& t) { + x->type = qMetaTypeId(reinterpret_cast(0)); if (sizeof(T) > sizeof(QVariant::Private::Data)) { x->data.shared = new QVariantPrivateSharedEx(t); x->is_shared = true; } else { + x->is_shared = false; new (&x->data.ptr) T(t); } } @@ -118,31 +120,24 @@ inline void v_construct(QVariant::Private *x, const T &t) template inline void v_construct(QVariant::Private *x, const void *copy, T * = 0) { - if (sizeof(T) > sizeof(QVariant::Private::Data)) { - x->data.shared = copy ? new QVariantPrivateSharedEx(*static_cast(copy)) - : new QVariantPrivateSharedEx; - x->is_shared = true; + if (copy) { + v_construct(x, *reinterpret_cast(copy)); } else { - if (copy) - new (&x->data.ptr) T(*static_cast(copy)); - else - new (&x->data.ptr) T; + T t; + v_construct(x, t); } } + // deletes the internal structures template inline void v_clear(QVariant::Private *d, T* = 0) { - - if (sizeof(T) > sizeof(QVariant::Private::Data)) { - //now we need to cast - //because QVariant::PrivateShared doesn't have a virtual destructor - delete static_cast*>(d->data.shared); - } else { - v_cast(d)->~T(); - } - + //now we need to call the destructor in any case + //because QVariant::PrivateShared doesn't have a virtual destructor + v_cast(d)->~T(); + if (sizeof(T) > sizeof(QVariant::Private::Data)) + delete d->data.shared; } QT_END_NAMESPACE -- cgit v0.12 From 5377045c74c65aeb18d169bcd4a165417c0f4c02 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 23 Apr 2009 10:23:41 +1000 Subject: Allow method text of recipe example to scroll --- .../declarative/listview/content/pics/moreDown.png | Bin 0 -> 217 bytes .../declarative/listview/content/pics/moreUp.png | Bin 0 -> 212 bytes examples/declarative/listview/recipes.qml | 34 +++++++++++---------- 3 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 examples/declarative/listview/content/pics/moreDown.png create mode 100644 examples/declarative/listview/content/pics/moreUp.png diff --git a/examples/declarative/listview/content/pics/moreDown.png b/examples/declarative/listview/content/pics/moreDown.png new file mode 100644 index 0000000..31a35d5 Binary files /dev/null and b/examples/declarative/listview/content/pics/moreDown.png differ diff --git a/examples/declarative/listview/content/pics/moreUp.png b/examples/declarative/listview/content/pics/moreUp.png new file mode 100644 index 0000000..fefb9c9 Binary files /dev/null and b/examples/declarative/listview/content/pics/moreUp.png differ diff --git a/examples/declarative/listview/recipes.qml b/examples/declarative/listview/recipes.qml index 7d32532..6826b78 100644 --- a/examples/declarative/listview/recipes.qml +++ b/examples/declarative/listview/recipes.qml @@ -1,6 +1,6 @@ - + - + - - - - - - - - - - - - + + + + + + - + + + + + + + + + @@ -57,7 +60,6 @@ - -- cgit v0.12