From 462456192424082ccc5ccc7238a751f92521ddcf Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 4 Sep 2009 18:39:06 +1000 Subject: Doc --- src/declarative/QmlChanges.txt | 1 + src/declarative/fx/qfxitem.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index b24f6fe..7dda5cc 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -31,6 +31,7 @@ ParentChangeAction -> ParentAction VisualModel -> VisualDataModel Renamed properties: +Item: contents -> childrenRect MouseRegion: xmin -> minimumX MouseRegion: xmax -> maximumX MouseRegion: ymin -> minimumY diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index d28f531..073d5d9 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -235,10 +235,10 @@ QFxContents::QFxContents() : m_x(0), m_y(0), m_width(0), m_height(0) } /*! - \qmlproperty qreal Item::childrenRect.x - \qmlproperty qreal Item::childrenRect.y - \qmlproperty qreal Item::childrenRect.width - \qmlproperty qreal Item::childrenRect.height + \qmlproperty real Item::childrenRect.x + \qmlproperty real Item::childrenRect.y + \qmlproperty real Item::childrenRect.width + \qmlproperty real Item::childrenRect.height The childrenRect properties allow an item access to the geometry of its children. This property is useful if you have an item that needs to be -- cgit v0.12 From 4bb098ed9449bd3b2798000bc5394bda98c9165f Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Tue, 8 Sep 2009 10:19:40 +1000 Subject: Convert QGLFramebufferObjectFormat to use implicit sharing Reviewed-by: Sarah Smith --- src/opengl/qglframebufferobject.cpp | 71 +++++++++++++++++++++++++++++-------- src/opengl/qglframebufferobject.h | 4 ++- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp index c53ed3a..452f155 100644 --- a/src/opengl/qglframebufferobject.cpp +++ b/src/opengl/qglframebufferobject.cpp @@ -74,9 +74,34 @@ extern QImage qt_gl_read_framebuffer(const QSize&, bool, bool); } \ } +#ifndef QT_OPENGL_ES +#define DEFAULT_FORMAT GL_RGBA8 +#else +#define DEFAULT_FORMAT GL_RGBA +#endif + class QGLFramebufferObjectFormatPrivate { public: + QGLFramebufferObjectFormatPrivate() + : ref(1), + samples(0), + attachment(QGLFramebufferObject::NoAttachment), + target(GL_TEXTURE_2D), + internal_format(DEFAULT_FORMAT) + { + } + QGLFramebufferObjectFormatPrivate + (const QGLFramebufferObjectFormatPrivate *other) + : ref(1), + samples(other->samples), + attachment(other->attachment), + target(other->target), + internal_format(other->internal_format) + { + } + + QAtomicInt ref; int samples; QGLFramebufferObject::Attachment attachment; GLenum target; @@ -109,6 +134,20 @@ public: */ /*! + \internal +*/ +void QGLFramebufferObjectFormat::detach() +{ + if (d->ref != 1) { + QGLFramebufferObjectFormatPrivate *newd + = new QGLFramebufferObjectFormatPrivate(d); + if (!d->ref.deref()) + delete d; + d = newd; + } +} + +/*! Creates a QGLFramebufferObjectFormat object for specifying the format of an OpenGL framebuffer object. @@ -118,19 +157,9 @@ public: \sa samples(), attachment(), target(), internalTextureFormat() */ -#ifndef QT_OPENGL_ES -#define DEFAULT_FORMAT GL_RGBA8 -#else -#define DEFAULT_FORMAT GL_RGBA -#endif - QGLFramebufferObjectFormat::QGLFramebufferObjectFormat() { d = new QGLFramebufferObjectFormatPrivate; - d->samples = 0; - d->attachment = QGLFramebufferObject::NoAttachment; - d->target = GL_TEXTURE_2D; - d->internal_format = DEFAULT_FORMAT; } /*! @@ -139,8 +168,8 @@ QGLFramebufferObjectFormat::QGLFramebufferObjectFormat() QGLFramebufferObjectFormat::QGLFramebufferObjectFormat(const QGLFramebufferObjectFormat &other) { - d = new QGLFramebufferObjectFormatPrivate; - *d = *other.d; + d = other.d; + d->ref.ref(); } /*! @@ -149,7 +178,12 @@ QGLFramebufferObjectFormat::QGLFramebufferObjectFormat(const QGLFramebufferObjec QGLFramebufferObjectFormat &QGLFramebufferObjectFormat::operator=(const QGLFramebufferObjectFormat &other) { - *d = *other.d; + if (d != other.d) { + other.d->ref.ref(); + if (!d->ref.deref()) + delete d; + d = other.d; + } return *this; } @@ -158,7 +192,8 @@ QGLFramebufferObjectFormat &QGLFramebufferObjectFormat::operator=(const QGLFrame */ QGLFramebufferObjectFormat::~QGLFramebufferObjectFormat() { - delete d; + if (!d->ref.deref()) + delete d; } /*! @@ -176,6 +211,7 @@ QGLFramebufferObjectFormat::~QGLFramebufferObjectFormat() */ void QGLFramebufferObjectFormat::setSamples(int samples) { + detach(); d->samples = samples; } @@ -197,6 +233,7 @@ int QGLFramebufferObjectFormat::samples() const */ void QGLFramebufferObjectFormat::setAttachment(QGLFramebufferObject::Attachment attachment) { + detach(); d->attachment = attachment; } @@ -219,6 +256,7 @@ QGLFramebufferObject::Attachment QGLFramebufferObjectFormat::attachment() const */ void QGLFramebufferObjectFormat::setTextureTarget(GLenum target) { + detach(); d->target = target; } @@ -242,6 +280,7 @@ GLenum QGLFramebufferObjectFormat::textureTarget() const */ void QGLFramebufferObjectFormat::setInternalTextureFormat(GLenum internalTextureFormat) { + detach(); d->internal_format = internalTextureFormat; } @@ -260,12 +299,14 @@ GLenum QGLFramebufferObjectFormat::internalTextureFormat() const /*! \internal */ void QGLFramebufferObjectFormat::setTextureTarget(QMacCompatGLenum target) { + detach(); d->target = target; } /*! \internal */ void QGLFramebufferObjectFormat::setInternalTextureFormat(QMacCompatGLenum internalTextureFormat) { + detach(); d->internal_format = internalTextureFormat; } #endif @@ -871,7 +912,7 @@ QSize QGLFramebufferObject::size() const /*! Returns the format of this framebuffer object. */ -const QGLFramebufferObjectFormat &QGLFramebufferObject::format() const +QGLFramebufferObjectFormat QGLFramebufferObject::format() const { Q_D(const QGLFramebufferObject); return d->format; diff --git a/src/opengl/qglframebufferobject.h b/src/opengl/qglframebufferobject.h index ec1ae7d..6c1c0be 100644 --- a/src/opengl/qglframebufferobject.h +++ b/src/opengl/qglframebufferobject.h @@ -93,7 +93,7 @@ public: virtual ~QGLFramebufferObject(); - const QGLFramebufferObjectFormat &format() const; + QGLFramebufferObjectFormat format() const; bool isValid() const; bool isBound() const; @@ -161,6 +161,8 @@ public: private: QGLFramebufferObjectFormatPrivate *d; + + void detach(); }; QT_END_NAMESPACE -- cgit v0.12 From fa2cd481324d65d754d77f4fb3a99cc394fdba78 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 8 Sep 2009 11:10:47 +1000 Subject: Fix leaks. --- src/declarative/fx/qfxpathview.cpp | 3 +++ src/declarative/qml/qmlcompositetypemanager.cpp | 1 + src/declarative/qml/qmlmetatype.cpp | 1 + src/declarative/util/qfxview.cpp | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp index 469e9f3..62f9db0 100644 --- a/src/declarative/fx/qfxpathview.cpp +++ b/src/declarative/fx/qfxpathview.cpp @@ -128,6 +128,9 @@ QFxPathView::QFxPathView(QFxPathViewPrivate &dd, QFxItem *parent) QFxPathView::~QFxPathView() { + Q_D(QFxPathView); + if (d->ownModel) + delete d->model; } /*! diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index bcfbcc8..a99cff0 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -87,6 +87,7 @@ QmlComponent *QmlCompositeTypeData::toComponent(QmlEngine *engine) QmlCompiledData *cc = toCompiledComponent(engine); if (cc) { component = new QmlComponent(engine, cc, -1, -1, 0); + cc->release(); } else { component = new QmlComponent(engine, 0); component->d_func()->url = imports.baseUrl(); diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp index ac89d28..14d85ff 100644 --- a/src/declarative/qml/qmlmetatype.cpp +++ b/src/declarative/qml/qmlmetatype.cpp @@ -197,6 +197,7 @@ QmlType::QmlType(int type, int listType, int qmlListType, QmlType::~QmlType() { + delete d->m_customParser; delete d; } diff --git a/src/declarative/util/qfxview.cpp b/src/declarative/util/qfxview.cpp index 9291e1a..2a38cda 100644 --- a/src/declarative/util/qfxview.cpp +++ b/src/declarative/util/qfxview.cpp @@ -222,7 +222,7 @@ void QFxView::execute() if (d->qml.isEmpty()) { d->component = new QmlComponent(&d->engine, d->source, this); } else { - d->component = new QmlComponent(&d->engine, d->qml.toUtf8(), d->source); + d->component = new QmlComponent(&d->engine, d->qml.toUtf8(), d->source, this); } if (!d->component->isLoading()) { -- cgit v0.12 From 7b7e776d9042fa34a17db3189af99efb7494d070 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Tue, 8 Sep 2009 11:36:52 +1000 Subject: Make the matrix and viewport logic in renderText() a bit better The original renderText() was using the highly unportable (to OpenGL/ES) glGetDoublev() and glGetIntegerv() functions. Reviewed-by: Sarah Smith --- src/opengl/qgl.cpp | 187 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 137 insertions(+), 50 deletions(-) diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 9e0c5f8..49dc8a2 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -63,6 +63,7 @@ #include "qpixmap.h" #include "qimage.h" +#include "qmatrix4x4.h" #include "qgl_p.h" #if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) @@ -251,46 +252,24 @@ QGLSignalProxy *QGLSignalProxy::instance() \sa QGLContext, QGLWidget */ -static inline void transform_point(GLdouble out[4], const GLdouble m[16], const GLdouble in[4]) +static inline void qgluProject + (qreal objx, qreal objy, qreal objz, + const QMatrix4x4& model, const QMatrix4x4& proj, const GLint viewport[4], + GLfloat *winx, GLfloat *winy, GLfloat* winz) { -#define M(row,col) m[col*4+row] - out[0] = - M(0, 0) * in[0] + M(0, 1) * in[1] + M(0, 2) * in[2] + M(0, 3) * in[3]; - out[1] = - M(1, 0) * in[0] + M(1, 1) * in[1] + M(1, 2) * in[2] + M(1, 3) * in[3]; - out[2] = - M(2, 0) * in[0] + M(2, 1) * in[1] + M(2, 2) * in[2] + M(2, 3) * in[3]; - out[3] = - M(3, 0) * in[0] + M(3, 1) * in[1] + M(3, 2) * in[2] + M(3, 3) * in[3]; -#undef M -} - -static inline GLint qgluProject(GLdouble objx, GLdouble objy, GLdouble objz, - const GLdouble model[16], const GLdouble proj[16], - const GLint viewport[4], - GLdouble * winx, GLdouble * winy, GLdouble * winz) -{ - GLdouble in[4], out[4]; - - in[0] = objx; - in[1] = objy; - in[2] = objz; - in[3] = 1.0; - transform_point(out, model, in); - transform_point(in, proj, out); + QVector4D transformed = proj.map(model.map(QVector4D(objx, objy, objz, 1))); - if (in[3] == 0.0) - return GL_FALSE; + qreal w = transformed.w(); + if (w == 0.0f) + w = 1.0f; // Just in case! - in[0] /= in[3]; - in[1] /= in[3]; - in[2] /= in[3]; + qreal x = transformed.x() / w; + qreal y = transformed.y() / w; - *winx = viewport[0] + (1 + in[0]) * viewport[2] / 2; - *winy = viewport[1] + (1 + in[1]) * viewport[3] / 2; + *winx = viewport[0] + (1 + x) * viewport[2] / 2; + *winy = viewport[1] + (1 + y) * viewport[3] / 2; - *winz = (1 + in[2]) / 2; - return GL_TRUE; + *winz = (1 + transformed.z() / w) / 2; } /*! @@ -4113,6 +4092,30 @@ static void qt_gl_draw_text(QPainter *p, int x, int y, const QString &str, p->setFont(old_font); } +#if defined(GL_OES_VERSION_1_0) && !defined(GL_OES_VERSION_1_1) + +// OpenGL/ES 1.0 cannot fetch viewports from the GL server. +// We therefore create a default viewport to simulate the fetch. + +static void qt_gl_get_viewport(GLint *view, int deviceWidth, int deviceHeight) +{ + view[0] = 0; + view[1] = 0; + view[2] = deviceWidth; + view[3] = deviceHeight; +} + +#else + +static void qt_gl_get_viewport(GLint *view, int deviceWidth, int deviceHeight) +{ + Q_UNUSED(deviceWidth); + Q_UNUSED(deviceHeight); + glGetIntegerv(GL_VIEWPORT, view); +} + +#endif + /*! Renders the string \a str into the GL context of this widget. @@ -4138,13 +4141,19 @@ void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font, GLint view[4]; #ifndef QT_OPENGL_ES bool use_scissor_testing = glIsEnabled(GL_SCISSOR_TEST); - if (!use_scissor_testing) - glGetIntegerv(GL_VIEWPORT, &view[0]); #else bool use_scissor_testing = false; #endif int width = d->glcx->device()->width(); int height = d->glcx->device()->height(); + if (!use_scissor_testing) { + qt_gl_get_viewport(&view[0], width, height); + } else { + view[0] = 0; + view[1] = 0; + view[2] = width; + view[3] = height; + } bool auto_swap = autoBufferSwap(); QPaintEngine *engine = paintEngine(); @@ -4216,12 +4225,95 @@ void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font, #endif } +#if defined(QT_OPENGL_ES_2) || \ + (defined(GL_OES_VERSION_1_0) && !defined(GL_OES_VERSION_1_1)) + +// OpenGL/ES 1.0 cannot fetch matrices from the GL server. +// OpenGL/ES 2.0 does not use fixed-function matrices at all. +// We therefore create some default matrices to simulate the fetch. + +static QMatrix4x4 qt_gl_projection_matrix(int deviceWidth, int deviceHeight) +{ + QMatrix4x4 m; + m.ortho(0, deviceWidth, deviceHeight, 0, -1, 1); + return m; +} + +static QMatrix4x4 qt_gl_modelview_matrix(void) +{ + return QMatrix4x4(); +} + +#else // !QT_OPENGL_ES_2 + +static QMatrix4x4 qt_gl_fetch_matrix(GLenum type) +{ + QMatrix4x4 matrix; +#if defined(QT_OPENGL_ES_1_CL) + GLfixed mat[16]; + glGetFixedv(type, mat); + qreal *m = matrix.data(); + for (int index = 0; index < 16; ++index) + m[index] = vt2f(mat[index]); +#else + if (sizeof(qreal) == sizeof(GLfloat)) { + glGetFloatv(type, reinterpret_cast(matrix.data())); +#if !defined(QT_OPENGL_ES) + } else if (sizeof(qreal) == sizeof(GLdouble)) { + glGetDoublev(type, reinterpret_cast(matrix.data())); +#endif + } else { + GLfloat mat[16]; + glGetFloatv(type, mat); + qreal *m = matrix.data(); + for (int index = 0; index < 16; ++index) + m[index] = mat[index]; + } +#endif + matrix.inferSpecialType(); + return matrix; +} + +static QMatrix4x4 qt_gl_projection_matrix(int deviceWidth, int deviceHeight) +{ + Q_UNUSED(deviceWidth); + Q_UNUSED(deviceHeight); + return qt_gl_fetch_matrix(GL_PROJECTION_MATRIX); +} + +static QMatrix4x4 qt_gl_modelview_matrix(void) +{ + return qt_gl_fetch_matrix(GL_MODELVIEW_MATRIX); +} + +#endif // !QT_OPENGL_ES_2 + /*! \overload \a x, \a y and \a z are specified in scene or object coordinates relative to the currently set projection and model matrices. This can be useful if you want to annotate models with text labels and have the labels move with the model as it is rotated etc. + + This function fetches the modelview matrix, projection matrix, and + current viewport from the GL server to map (\a x, \a y, \a z) + into window co-ordinates. This entails several round-trips to the GL + server which will probably impact performance. + + Fetching the modelview and projection matrices is not supported + under OpenGL/ES 1.0 and OpenGL/ES 2.0 so a default orthographic + projection will be used to map the co-ordinates on those platforms. + This probably will not give results that are consistent with desktop + and OpenGL/ES 1.1 systems. Fetching the viewport is not supported + under OpenGL/ES 1.0, so the full device will be used as the viewport. + + This function is deprecated because it is non-portable. It is + recommended that the application map the co-ordinates itself using + application-provided matrix data that reflects the desired + transformation. Then use QPainter::drawText() to draw \a str at + the mapped position. + + \sa QMatrix4x4 */ void QGLWidget::renderText(double x, double y, double z, const QString &str, const QFont &font, int) { @@ -4233,16 +4325,15 @@ void QGLWidget::renderText(double x, double y, double z, const QString &str, con int width = d->glcx->device()->width(); int height = d->glcx->device()->height(); - GLdouble model[4][4], proj[4][4]; + + QMatrix4x4 model = qt_gl_modelview_matrix(); + QMatrix4x4 proj = qt_gl_projection_matrix(width, height); GLint view[4]; -#ifndef QT_OPENGL_ES - glGetDoublev(GL_MODELVIEW_MATRIX, &model[0][0]); - glGetDoublev(GL_PROJECTION_MATRIX, &proj[0][0]); - glGetIntegerv(GL_VIEWPORT, &view[0]); -#endif - GLdouble win_x = 0, win_y = 0, win_z = 0; - qgluProject(x, y, z, &model[0][0], &proj[0][0], &view[0], - &win_x, &win_y, &win_z); + qt_gl_get_viewport(view, width, height); + + GLfloat win_x = 0, win_y = 0, win_z = 0; + qgluProject(qreal(x), qreal(y), qreal(z), + model, proj, &view[0], &win_x, &win_y, &win_z); win_y = height - win_y; // y is inverted QPaintEngine *engine = paintEngine(); @@ -4295,11 +4386,7 @@ void QGLWidget::renderText(double x, double y, double z, const QString &str, con glEnable(GL_ALPHA_TEST); if (use_depth_testing) glEnable(GL_DEPTH_TEST); -#ifndef QT_OPENGL_ES - glTranslated(0, 0, -win_z); -#else glTranslatef(0, 0, -win_z); -#endif #endif // !defined(QT_OPENGL_ES_2) qt_gl_draw_text(p, qRound(win_x), qRound(win_y), str, font); -- cgit v0.12 From ea19e075c7eb34a6a7979fa3cfb2dcc838d33c11 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Tue, 8 Sep 2009 11:43:41 +1000 Subject: Texture format must be GL_RGB when pixel type is GL_UNSIGNED_SHORT_5_6_5 QImage::Format_RGB16 textures were broken on some OpenGL/ES 1.1 systems because the "format" was set to GL_RGBA and the "texture_format" was set to GL_RGB, with a pixel type of GL_UNSIGNED_SHORT_5_6_5. OpenGL/ES 1.1, ES 2.0, and desktop GL all require the two format parameters to glTexImage2D() to be GL_RGB if the pixel type is GL_UNSIGNED_SHORT_5_6_5. Reviewed-by: Sarah Smith --- src/opengl/qgl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 49dc8a2..087902b 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -2052,6 +2052,7 @@ QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, G case QImage::Format_RGB16: pixel_type = GL_UNSIGNED_SHORT_5_6_5; texture_format = GL_RGB; + format = GL_RGB; break; case QImage::Format_RGB32: if (format == GL_RGBA) -- cgit v0.12 From 79ad2c1d4f5205245c929be1c0db2c678d185038 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Tue, 8 Sep 2009 12:23:31 +1000 Subject: Port examples/opengl/textures to OpenGL/ES 1.1 Reviewed-by: Sarah Smith --- examples/opengl/opengl.pro | 3 ++ examples/opengl/textures/glwidget.cpp | 74 ++++++++++++++++++++--------------- examples/opengl/textures/glwidget.h | 8 ++-- examples/opengl/textures/window.cpp | 4 +- 4 files changed, 51 insertions(+), 38 deletions(-) diff --git a/examples/opengl/opengl.pro b/examples/opengl/opengl.pro index 567eb7b..b86e0ba 100644 --- a/examples/opengl/opengl.pro +++ b/examples/opengl/opengl.pro @@ -5,6 +5,9 @@ contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles1cl)|contains(QT_CONF SUBDIRS = hellogl_es2 } else { SUBDIRS = hellogl_es + !contains(QT_CONFIG, opengles1cl) { + SUBDIRS += textures + } } } else { SUBDIRS = 2dpainting \ diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp index cfb99b0..9c6d5ea 100644 --- a/examples/opengl/textures/glwidget.cpp +++ b/examples/opengl/textures/glwidget.cpp @@ -42,12 +42,17 @@ #include #include -#include - #include "glwidget.h" -GLuint GLWidget::sharedObject = 0; -int GLWidget::refCount = 0; +class CubeObject +{ +public: + GLuint textures[6]; + QVector vertices; + QVector texCoords; + + void draw(); +}; GLWidget::GLWidget(QWidget *parent, QGLWidget *shareWidget) : QGLWidget(parent, shareWidget) @@ -56,14 +61,12 @@ GLWidget::GLWidget(QWidget *parent, QGLWidget *shareWidget) xRot = 0; yRot = 0; zRot = 0; + cube = 0; } GLWidget::~GLWidget() { - if (--refCount == 0) { - makeCurrent(); - glDeleteLists(sharedObject, 1); - } + delete cube; } QSize GLWidget::minimumSizeHint() const @@ -92,9 +95,7 @@ void GLWidget::setClearColor(const QColor &color) void GLWidget::initializeGL() { - if (!sharedObject) - sharedObject = makeObject(); - ++refCount; + makeObject(); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); @@ -106,11 +107,11 @@ void GLWidget::paintGL() qglClearColor(clearColor); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - glTranslated(0.0, 0.0, -10.0); - glRotated(xRot / 16.0, 1.0, 0.0, 0.0); - glRotated(yRot / 16.0, 0.0, 1.0, 0.0); - glRotated(zRot / 16.0, 0.0, 0.0, 1.0); - glCallList(sharedObject); + glTranslatef(0.0f, 0.0f, -10.0f); + glRotatef(xRot / 16.0f, 1.0f, 0.0f, 0.0f); + glRotatef(yRot / 16.0f, 0.0f, 1.0f, 0.0f); + glRotatef(zRot / 16.0f, 0.0f, 0.0f, 1.0f); + cube->draw(); } void GLWidget::resizeGL(int width, int height) @@ -120,7 +121,11 @@ void GLWidget::resizeGL(int width, int height) glMatrixMode(GL_PROJECTION); glLoadIdentity(); +#ifndef QT_OPENGL_ES glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); +#else + glOrthof(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); +#endif glMatrixMode(GL_MODELVIEW); } @@ -147,7 +152,7 @@ void GLWidget::mouseReleaseEvent(QMouseEvent * /* event */) emit clicked(); } -GLuint GLWidget::makeObject() +void GLWidget::makeObject() { static const int coords[6][4][3] = { { { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } }, @@ -158,25 +163,32 @@ GLuint GLWidget::makeObject() { { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } } }; + cube = new CubeObject(); - GLuint textures[6]; - for (int j=0; j < 6; ++j) - textures[j] = bindTexture(QPixmap(QString(":/images/side%1.png").arg(j + 1)), - GL_TEXTURE_2D); + for (int j=0; j < 6; ++j) { + cube->textures[j] = bindTexture + (QPixmap(QString(":/images/side%1.png").arg(j + 1)), GL_TEXTURE_2D); + } - GLuint list = glGenLists(1); - glNewList(list, GL_COMPILE); for (int i = 0; i < 6; ++i) { - glBindTexture(GL_TEXTURE_2D, textures[i]); - glBegin(GL_QUADS); for (int j = 0; j < 4; ++j) { - glTexCoord2d(j == 0 || j == 3, j == 0 || j == 1); - glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], - 0.2 * coords[i][j][2]); + cube->texCoords.append + (QVector2D(j == 0 || j == 3, j == 0 || j == 1)); + cube->vertices.append + (QVector3D(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], + 0.2 * coords[i][j][2])); } - glEnd(); } +} - glEndList(); - return list; +void CubeObject::draw() +{ + glVertexPointer(3, GL_FLOAT, 0, vertices.constData()); + glTexCoordPointer(2, GL_FLOAT, 0, texCoords.constData()); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + for (int i = 0; i < 6; ++i) { + glBindTexture(GL_TEXTURE_2D, textures[i]); + glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4); + } } diff --git a/examples/opengl/textures/glwidget.h b/examples/opengl/textures/glwidget.h index 68be8bc..f793d6d 100644 --- a/examples/opengl/textures/glwidget.h +++ b/examples/opengl/textures/glwidget.h @@ -44,6 +44,8 @@ #include +class CubeObject; + class GLWidget : public QGLWidget { Q_OBJECT @@ -69,16 +71,14 @@ protected: void mouseReleaseEvent(QMouseEvent *event); private: - GLuint makeObject(); + void makeObject(); QColor clearColor; QPoint lastPos; int xRot; int yRot; int zRot; - - static GLuint sharedObject; - static int refCount; + CubeObject *cube; }; #endif diff --git a/examples/opengl/textures/window.cpp b/examples/opengl/textures/window.cpp index ea64512..9bd7931 100644 --- a/examples/opengl/textures/window.cpp +++ b/examples/opengl/textures/window.cpp @@ -48,8 +48,6 @@ Window::Window() { QGridLayout *mainLayout = new QGridLayout; - glWidgets[0][0] = 0; - for (int i = 0; i < NumRows; ++i) { for (int j = 0; j < NumColumns; ++j) { QColor clearColor; @@ -57,7 +55,7 @@ Window::Window() / (NumRows * NumColumns - 1), 255, 63); - glWidgets[i][j] = new GLWidget(0, glWidgets[0][0]); + glWidgets[i][j] = new GLWidget(0, 0); glWidgets[i][j]->setClearColor(clearColor); glWidgets[i][j]->rotateBy(+42 * 16, +42 * 16, -21 * 16); mainLayout->addWidget(glWidgets[i][j], i, j); -- cgit v0.12 From 2ed2632acec45ce4979ce21a0fe93d286a16613c Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Tue, 8 Sep 2009 13:00:43 +1000 Subject: Add operator== and != to QGLFramebufferObjectFormat Reviewed-by: Sarah Smith --- src/opengl/qglframebufferobject.cpp | 28 +++++++++++++++++++++ src/opengl/qglframebufferobject.h | 3 +++ src/opengl/qpixmapdata_gl.cpp | 7 +----- tests/auto/qgl/tst_qgl.cpp | 49 +++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 6 deletions(-) diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp index 452f155..9990586 100644 --- a/src/opengl/qglframebufferobject.cpp +++ b/src/opengl/qglframebufferobject.cpp @@ -100,6 +100,13 @@ public: internal_format(other->internal_format) { } + bool equals(const QGLFramebufferObjectFormatPrivate *other) + { + return samples == other->samples && + attachment == other->attachment && + target == other->target && + internal_format == other->internal_format; + } QAtomicInt ref; int samples; @@ -311,6 +318,27 @@ void QGLFramebufferObjectFormat::setInternalTextureFormat(QMacCompatGLenum inter } #endif +/*! + Returns true if all the options of this framebuffer object format + are the same as \a other; otherwise returns false. +*/ +bool QGLFramebufferObjectFormat::operator==(const QGLFramebufferObjectFormat& other) const +{ + if (d == other.d) + return true; + else + return d->equals(other.d); +} + +/*! + Returns false if all the options of this framebuffer object format + are the same as \a other; otherwise returns true. +*/ +bool QGLFramebufferObjectFormat::operator!=(const QGLFramebufferObjectFormat& other) const +{ + return !(*this == other); +} + class QGLFramebufferObjectPrivate { public: diff --git a/src/opengl/qglframebufferobject.h b/src/opengl/qglframebufferobject.h index 6c1c0be..2778ec5 100644 --- a/src/opengl/qglframebufferobject.h +++ b/src/opengl/qglframebufferobject.h @@ -159,6 +159,9 @@ public: void setInternalTextureFormat(QMacCompatGLenum internalTextureFormat); #endif + bool operator==(const QGLFramebufferObjectFormat& other) const; + bool operator!=(const QGLFramebufferObjectFormat& other) const; + private: QGLFramebufferObjectFormatPrivate *d; diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp index d63d2ad..a394716 100644 --- a/src/opengl/qpixmapdata_gl.cpp +++ b/src/opengl/qpixmapdata_gl.cpp @@ -80,12 +80,7 @@ QGLFramebufferObject *QGLFramebufferObjectPool::acquire(const QSize &requestSize for (int i = 0; !chosen && i < m_fbos.size(); ++i) { QGLFramebufferObject *fbo = m_fbos.at(i); - QGLFramebufferObjectFormat format = fbo->format(); - if (format.samples() == requestFormat.samples() - && format.attachment() == requestFormat.attachment() - && format.textureTarget() == requestFormat.textureTarget() - && format.internalTextureFormat() == requestFormat.internalTextureFormat()) - { + if (fbo->format() == requestFormat) { // choose the fbo with a matching format and the closest size if (!candidate || areaDiff(requestSize, candidate) > areaDiff(requestSize, fbo)) candidate = fbo; diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp index 650c1ca..43f4227 100644 --- a/tests/auto/qgl/tst_qgl.cpp +++ b/tests/auto/qgl/tst_qgl.cpp @@ -1432,6 +1432,55 @@ void tst_QGL::fboFormat() QVERIFY(format1.attachment() == QGLFramebufferObject::CombinedDepthStencil); QCOMPARE(int(format1.textureTarget()), int(GL_TEXTURE_3D)); QCOMPARE(int(format1.internalTextureFormat()), int(GL_RGB16)); + + // operator== and operator!= for QGLFramebufferObjectFormat. + QGLFramebufferObjectFormat format1c; + QGLFramebufferObjectFormat format2c; + + QVERIFY(format1c == format2c); + QVERIFY(!(format1c != format2c)); + format1c.setSamples(8); + QVERIFY(!(format1c == format2c)); + QVERIFY(format1c != format2c); + format2c.setSamples(8); + QVERIFY(format1c == format2c); + QVERIFY(!(format1c != format2c)); + + format1c.setAttachment(QGLFramebufferObject::CombinedDepthStencil); + QVERIFY(!(format1c == format2c)); + QVERIFY(format1c != format2c); + format2c.setAttachment(QGLFramebufferObject::CombinedDepthStencil); + QVERIFY(format1c == format2c); + QVERIFY(!(format1c != format2c)); + + format1c.setTextureTarget(GL_TEXTURE_3D); + QVERIFY(!(format1c == format2c)); + QVERIFY(format1c != format2c); + format2c.setTextureTarget(GL_TEXTURE_3D); + QVERIFY(format1c == format2c); + QVERIFY(!(format1c != format2c)); + + format1c.setInternalTextureFormat(GL_RGB16); + QVERIFY(!(format1c == format2c)); + QVERIFY(format1c != format2c); + format2c.setInternalTextureFormat(GL_RGB16); + QVERIFY(format1c == format2c); + QVERIFY(!(format1c != format2c)); + + QGLFramebufferObjectFormat format3c(format1c); + QGLFramebufferObjectFormat format4c; + QVERIFY(format1c == format3c); + QVERIFY(!(format1c != format3c)); + format3c.setInternalTextureFormat(DEFAULT_FORMAT); + QVERIFY(!(format1c == format3c)); + QVERIFY(format1c != format3c); + + format4c = format1c; + QVERIFY(format1c == format4c); + QVERIFY(!(format1c != format4c)); + format4c.setInternalTextureFormat(DEFAULT_FORMAT); + QVERIFY(!(format1c == format4c)); + QVERIFY(format1c != format4c); } QTEST_MAIN(tst_QGL) -- cgit v0.12 From 28ccffc53df374f7b890510f481e2dae2e01ed74 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 8 Sep 2009 13:40:13 +1000 Subject: Dynamic QmlListModel Reveals a number of bugs in ListView (and probably others). Basic ugly example for now. --- examples/declarative/listview/dynamic.qml | 91 ++++++++++++++++++++++ .../declarative/qmlparser/listItemDeleteSelf.qml | 38 +++++++++ 2 files changed, 129 insertions(+) create mode 100644 examples/declarative/listview/dynamic.qml create mode 100644 tests/auto/declarative/qmlparser/listItemDeleteSelf.qml diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml new file mode 100644 index 0000000..58ce4b4 --- /dev/null +++ b/examples/declarative/listview/dynamic.qml @@ -0,0 +1,91 @@ +import Qt 4.6 + +Item { + width: 300 + height: 300 + + ListModel { + id: FruitModel + ListElement { + name: "Apple" + cost: 2.45 + } + ListElement { + name: "Banana" + cost: 1.95 + } + ListElement { + name: "Cumquat" + cost: 3.25 + } + ListElement { + name: "Durian" + cost: 9.95 + } + ListElement { + name: "Elderberry" + cost: 0.05 + } + ListElement { + name: "Fig" + cost: 0.25 + } + } + + Component { + id: FruitDelegate + Item { + width: parent.width; height: 35 + Text { font.pixelSize: 24; text: name } + Text { font.pixelSize: 24; text: '$'+Number(cost).toFixed(2); anchors.right: ItemButtons.left } + Row { + id: ItemButtons + anchors.right: parent.right + width: childrenRect.width + Image { source: "content/pics/add.png" + MouseRegion { anchors.fill: parent; onClicked: FruitModel.set(index,"cost",Number(cost)+0.25) } + } + Image { source: "content/pics/del.png" + MouseRegion { anchors.fill: parent; onClicked: FruitModel.set(index,"cost",Number(cost)-0.25) } + } + Image { source: "content/pics/trash.png" + MouseRegion { anchors.fill: parent; onClicked: FruitModel.remove(index) } + } + Column { + width: childrenRect.width + Image { source: "content/pics/moreUp.png" + MouseRegion { anchors.fill: parent; onClicked: FruitModel.move(index,index-1,1) } + } + Image { source: "content/pics/moreDown.png" + MouseRegion { anchors.fill: parent; onClicked: FruitModel.move(index,index+1,1) } + } + } + } + } + } + + ListView { + model: FruitModel + delegate: FruitDelegate + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: Buttons.top + } + + Row { + width: childrenRect.width + height: childrenRect.height + anchors.bottom: parent.bottom + id: Buttons + Image { source: "content/pics/add.png" + MouseRegion { anchors.fill: parent; onClicked: FruitModel.append({"name":"Pizza", "cost":5.95}) } + } + Image { source: "content/pics/add.png" + MouseRegion { anchors.fill: parent; onClicked: FruitModel.insert(0,{"name":"Pizza", "cost":5.95}) } + } + Image { source: "content/pics/trash.png" + MouseRegion { anchors.fill: parent; onClicked: FruitModel.clear() } + } + } +} diff --git a/tests/auto/declarative/qmlparser/listItemDeleteSelf.qml b/tests/auto/declarative/qmlparser/listItemDeleteSelf.qml new file mode 100644 index 0000000..fa2e831 --- /dev/null +++ b/tests/auto/declarative/qmlparser/listItemDeleteSelf.qml @@ -0,0 +1,38 @@ +import Qt 4.6 + +Item { + ListModel { + id: FruitModel + ListElement { + name: "Apple" + cost: 2.45 + } + ListElement { + name: "Orange" + cost: 3.25 + } + ListElement { + name: "Banana" + cost: 1.95 + } + } + + Component { + id: FruitDelegate + Item { + width: 200; height: 50 + Text { text: name } + Text { text: '$'+cost; anchors.right: parent.right } + MouseRegion { + anchors.fill: parent + onClicked: FruitModel.remove(index) + } + } + } + + ListView { + model: FruitModel + delegate: FruitDelegate + anchors.fill: parent + } +} -- cgit v0.12 From b74d10c45c3ff21c2d87871aebf0869d45b0f555 Mon Sep 17 00:00:00 2001 From: Kurt Korbatits Date: Tue, 8 Sep 2009 14:10:56 +1000 Subject: QAudioDeviceInfo::deviceList() wasn't working correctly if no audio device. The default was being added even when no audio devices were available. Change so that the default device is only added if there is at least one audio device. Reviewed-by:Bill King --- src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp index d8d974f..5de5c27 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp @@ -341,8 +341,6 @@ QList QAudioDeviceInfoPrivate::deviceList(QAudio::Mode mode) QList devices; - devices.append("default"); - if(mode == QAudio::AudioOutput) { WAVEOUTCAPS woc; unsigned long iNumDevs,i; @@ -365,6 +363,9 @@ QList QAudioDeviceInfoPrivate::deviceList(QAudio::Mode mode) } } + if(devices.count() > 0) + devices.append("default"); + return devices; } -- cgit v0.12 From 54e80dbed696909fd0a59f1837d1ca6bf5c76c37 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 8 Sep 2009 15:06:28 +1000 Subject: Missed icons. --- examples/declarative/listview/content/pics/add.png | Bin 0 -> 1577 bytes examples/declarative/listview/content/pics/del.png | Bin 0 -> 1661 bytes examples/declarative/listview/content/pics/trash.png | Bin 0 -> 989 bytes 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 examples/declarative/listview/content/pics/add.png create mode 100644 examples/declarative/listview/content/pics/del.png create mode 100644 examples/declarative/listview/content/pics/trash.png diff --git a/examples/declarative/listview/content/pics/add.png b/examples/declarative/listview/content/pics/add.png new file mode 100644 index 0000000..f29d84b Binary files /dev/null and b/examples/declarative/listview/content/pics/add.png differ diff --git a/examples/declarative/listview/content/pics/del.png b/examples/declarative/listview/content/pics/del.png new file mode 100644 index 0000000..1d753a3 Binary files /dev/null and b/examples/declarative/listview/content/pics/del.png differ diff --git a/examples/declarative/listview/content/pics/trash.png b/examples/declarative/listview/content/pics/trash.png new file mode 100644 index 0000000..2042595 Binary files /dev/null and b/examples/declarative/listview/content/pics/trash.png differ -- cgit v0.12 From 94267bb148fe4c991a10d4aa4c01373821d9216e Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 8 Sep 2009 15:08:54 +1000 Subject: Rest of change 28ccffc53df374f7b890510f481e2dae2e01ed74 --- src/declarative/fx/qfxvisualitemmodel.cpp | 19 ++- src/declarative/util/qmllistmodel.cpp | 271 +++++++++++++++++++++++++++++- src/declarative/util/qmllistmodel.h | 8 + 3 files changed, 288 insertions(+), 10 deletions(-) diff --git a/src/declarative/fx/qfxvisualitemmodel.cpp b/src/declarative/fx/qfxvisualitemmodel.cpp index 82bec09..cac8b8d 100644 --- a/src/declarative/fx/qfxvisualitemmodel.cpp +++ b/src/declarative/fx/qfxvisualitemmodel.cpp @@ -243,6 +243,16 @@ public: QmlContext *m_context; QList m_roles; QHash m_roleNames; + void ensureRoles() { + if (m_roles.isEmpty()) { + if (m_listModelInterface) { + m_roles = m_listModelInterface->roles(); + for (int ii = 0; ii < m_roles.count(); ++ii) + m_roleNames.insert(m_roles.at(ii), + m_listModelInterface->toString(m_roles.at(ii))); + } + } + } struct ObjectRef { ObjectRef(QObject *object=0) : obj(object), ref(1) {} @@ -375,6 +385,7 @@ int QFxVisualDataModelDataMetaObject::createProperty(const char *name, const cha return QmlOpenMetaObject::createProperty(name, type); } else { const QLatin1String sname(name); + data->m_model->ensureRoles(); for (QHash::ConstIterator iter = data->m_model->m_roleNames.begin(); iter != data->m_model->m_roleNames.end(); ++iter) { @@ -397,6 +408,7 @@ QFxVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuilder &pro && data->m_model->m_modelList) { return data->m_model->m_modelList->at(data->m_index); } else if (data->m_model->m_listModelInterface) { + data->m_model->ensureRoles(); for (QHash::ConstIterator iter = data->m_model->m_roleNames.begin(); iter != data->m_model->m_roleNames.end(); ++iter) { @@ -410,6 +422,7 @@ QFxVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuilder &pro } } } else if (data->m_model->m_abstractItemModel) { + data->m_model->ensureRoles(); for (QHash::ConstIterator iter = data->m_model->m_roleNames.begin(); iter != data->m_model->m_roleNames.end(); ++iter) { @@ -560,12 +573,6 @@ void QFxVisualDataModel::setModel(const QVariant &model) if (object && (d->m_listModelInterface = qobject_cast(object))) { d->m_roles.clear(); d->m_roleNames.clear(); - if (d->m_listModelInterface) { - d->m_roles = d->m_listModelInterface->roles(); - for (int ii = 0; ii < d->m_roles.count(); ++ii) - d->m_roleNames.insert(d->m_roles.at(ii), - d->m_listModelInterface->toString(d->m_roles.at(ii))); - } QObject::connect(d->m_listModelInterface, SIGNAL(itemsChanged(int,int,QList)), this, SLOT(_q_itemsChanged(int,int,QList))); diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index 0d9ea94..a5ae60f 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -72,7 +72,9 @@ struct ListModelData \qmlclass ListModel \brief The ListModel element defines a free-form list data source. - The ListModel is a simple hierarchy of elements containing data roles. + The ListModel is a simple hierarchy of elements containing data roles. The contents can + be defined dynamically, or explicitly in QML: + For example: \code @@ -166,6 +168,29 @@ struct ListModelData } \endcode + The content of a ListModel may be created and modified using the clear(), + append(), and set() methods. For example: + + \code + Component { + id: FruitDelegate + Item { + width: 200; height: 50 + Text { text: name } + Text { text: '$'+cost; anchors.right: parent.right } + + // Double the price when clicked. + MouseRegion { + anchors.fill: parent + onClicked: FruitModel.set(index, "cost", cost*2) + } + } + } + \endcode + + When creating content dynamically, note that the set of available properties cannot be changed + except by first clearing the model - whatever properties are first added are then the + only permitted properties in the model. */ class ModelObject : public QObject @@ -189,7 +214,6 @@ struct ModelNode { ModelNode(); ~ModelNode(); - QString className; QList values; QHash properties; @@ -214,6 +238,19 @@ struct ModelNode return objectCache; } + void setProperty(const QString& prop, const QVariant& val) { + QHash::const_iterator it = properties.find(prop); + if (it != properties.end()) { + (*it)->values[0] = val; + } else { + ModelNode *n = new ModelNode; + n->values << val; + properties.insert(prop,n); + } + if (objectCache) + objectCache->setValue(prop.toLatin1(), val); + } + QmlListModel *modelCache; ModelObject *objectCache; }; @@ -235,7 +272,7 @@ QmlListModel::~QmlListModel() void QmlListModel::checkRoles() const { - if (_rolesOk) + if (_rolesOk || !_root) return; for (int ii = 0; ii < _root->values.count(); ++ii) { @@ -341,6 +378,232 @@ int QmlListModel::count() const return _root->values.count(); } +/*! + \qmlmethod ListModel::clear() + + Deletes all content from the model. The properties are cleared such that + different properties may be set on subsequent additions. + + \sa append() remove() +*/ +void QmlListModel::clear() +{ + int cleared = count(); + _rolesOk = false; + delete _root; + _root = 0; + roleStrings.clear(); + emit itemsRemoved(0,cleared); +} + +/*! + \qmlmethod ListModel::remove(int index) + + Deletes the content at \a index from the model. + + \sa clear() +*/ +void QmlListModel::remove(int index) +{ + if (_root) { + ModelNode *node = qvariant_cast(_root->values.at(index)); + _root->values.remove(index); + if (node) + delete node; + emit itemsRemoved(index,1); + } +} + +/*! + \qmlmethod ListModel::insert(index,dict) + + Adds a new item to the list model at position \a index, with the + values in \a dict. + + \code + FruitModel.insert(2, {"cost": 5.95, "name":"Pizza"}) + \endcode + + If \a index is not in the list, sufficient empty items are + added to the list. + + \sa set() append() +*/ +void QmlListModel::insert(int index, const QVariantMap& valuemap) +{ + if (!_root) + _root = new ModelNode; + if (index >= _root->values.count()) { + set(index,valuemap); + return; + } + ModelNode *mn = new ModelNode; + for (QVariantMap::const_iterator it=valuemap.begin(); it!=valuemap.end(); ++it) { + addRole(it.key()); + ModelNode *value = new ModelNode; + value->values << it.value(); + mn->properties.insert(it.key(),value); + } + _root->values.insert(index,qVariantFromValue(mn)); + emit itemsInserted(index,1); +} + +/*! + \qmlmethod ListModel::move(from,to,n) + + Moves \a n items \a from one position \a to another. + + The from and to ranges must exist; for example, to move the first 3 items + to the end of the list: + + \code + FruitModel.move(0,FruitModel.count-3,3) + \endcode + + \sa append() +*/ +void QmlListModel::move(int from, int to, int n) +{ + if (from+n > count() || to+n > count() || n==0 || from==to) + return; + if (from > to) { + // Only move forwards - flip if backwards moving + int tfrom = from; + int tto = to; + from = tto; + to = tto+n; + n = tfrom-tto; + } + if (n==1) { + _root->values.move(from,to); + } else { + QList replaced; + int i=0; + QVariantList::const_iterator it=_root->values.begin(); it += from+n; + for (; ivalues.begin(); it += from; + for (; ivalues.begin(); t += from; + for (; f != replaced.end(); ++f, ++t) + *t = *f; + } + emit itemsMoved(from,to,n); +} + +/*! + \qmlmethod ListModel::append(dict) + + Adds a new item to the end of the list model, with the + values in \a dict. + + \code + FruitModel.append({"cost": 5.95, "name":"Pizza"}) + \endcode + + \sa set() remove() +*/ +void QmlListModel::append(const QVariantMap& valuemap) +{ + if (!_root) + _root = new ModelNode; + ModelNode *mn = new ModelNode; + for (QVariantMap::const_iterator it=valuemap.begin(); it!=valuemap.end(); ++it) { + addRole(it.key()); + ModelNode *value = new ModelNode; + value->values << it.value(); + mn->properties.insert(it.key(),value); + } + _root->values << qVariantFromValue(mn); + emit itemsInserted(count()-1,1); +} + +/*! + \qmlmethod ListModel::set(index,dict) + + Changes the item at \a index in the list model to the + values in \a dict. + + \code + FruitModel.set(3, {"cost": 5.95, "name":"Pizza"}) + \endcode + + If \a index is not in the list, sufficient empty items are + added to the list. + + \sa append() +*/ +void QmlListModel::set(int index, const QVariantMap& valuemap) +{ + if (!_root) + _root = new ModelNode; + int initialcount = _root->values.count(); + while (index > _root->values.count()) + _root->values.append(qVariantFromValue(new ModelNode)); + if (index == _root->values.count()) + append(valuemap); + else { + ModelNode *node = qvariant_cast(_root->values.at(index)); + QList roles; + for (QVariantMap::const_iterator it=valuemap.begin(); it!=valuemap.end(); ++it) { + node->setProperty(it.key(),it.value()); + int r = roleStrings.indexOf(it.key()); + if (r<0) { + r = roleStrings.count(); + roleStrings << it.key(); + } + roles.append(r); + } + if (initialcount < index) { + emit itemsInserted(initialcount,index-initialcount+1); + } else { + emit itemsChanged(index,1,roles); + } + } +} + +/*! + \qmlmethod ListModel::set(index,property,value) + + Changes the \a property of the item at \a index in the list model to \a value. + + \code + FruitModel.set(3, "cost", 5.95) + \endcode + + If \a index is not in the list, sufficient empty items are + added to the list. + + \sa append() +*/ +void QmlListModel::set(int index, const QString& property, const QVariant& value) +{ + if (!_root) + _root = new ModelNode; + int initialcount = _root->values.count(); + while (index >= _root->values.count()) + _root->values.append(qVariantFromValue(new ModelNode)); + ModelNode *node = qvariant_cast(_root->values.at(index)); + int r = roleStrings.indexOf(property); + if (r<0) { + r = roleStrings.count(); + roleStrings << property; + } + QList roles; + roles.append(r); + + if (node) + node->setProperty(property,value); + if (initialcount < index) + emit itemsInserted(initialcount,index-initialcount+1); + else + emit itemsChanged(index,1,roles); +} + + class QmlListModelParser : public QmlCustomParser { public: @@ -518,7 +781,7 @@ static void dump(ModelNode *node, int ind) for (int ii = 0; ii < node->values.count(); ++ii) { ModelNode *subNode = qvariant_cast(node->values.at(ii)); if (subNode) { - qWarning().nospace() << indent << "Sub-node " << ii << ": class " << subNode->className; + qWarning().nospace() << indent << "Sub-node " << ii; dump(subNode, ind + 1); } else { qWarning().nospace() << indent << "Sub-node " << ii << ": " << node->values.at(ii).toString(); diff --git a/src/declarative/util/qmllistmodel.h b/src/declarative/util/qmllistmodel.h index 39edbe4..8bef347 100644 --- a/src/declarative/util/qmllistmodel.h +++ b/src/declarative/util/qmllistmodel.h @@ -72,6 +72,14 @@ public: virtual int count() const; virtual QHash data(int index, const QList &roles = (QList())) const; + Q_INVOKABLE void clear(); + Q_INVOKABLE void remove(int index); + Q_INVOKABLE void append(const QVariantMap& valuemap); + Q_INVOKABLE void insert(int index, const QVariantMap& valuemap); + Q_INVOKABLE void set(int index, const QVariantMap& valuemap); + Q_INVOKABLE void set(int index, const QString& property, const QVariant& value); + Q_INVOKABLE void move(int from, int to, int count); + private: QVariant valueForNode(ModelNode *) const; mutable QStringList roleStrings; -- cgit v0.12 From 22e8dd8653281ebf79fc7fc0061b225c8daf2977 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 8 Sep 2009 15:15:12 +1000 Subject: Fixed some focus-related tst_qlineedit failures. There are many places where the test assumes that a widget gets focus after some fixed timeout. Change it to block until the widget really gets focus. --- tests/auto/qlineedit/tst_qlineedit.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/auto/qlineedit/tst_qlineedit.cpp b/tests/auto/qlineedit/tst_qlineedit.cpp index 6bbdf5d..47f0730 100644 --- a/tests/auto/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/qlineedit/tst_qlineedit.cpp @@ -343,6 +343,7 @@ void tst_QLineEdit::initTestCase() // to be safe and avoid failing setFocus with window managers qt_x11_wait_for_window_manager(testWidget); #endif + QTRY_VERIFY(testWidget->hasFocus()); changed_count = 0; edited_count = 0; @@ -1601,8 +1602,7 @@ void tst_QLineEdit::passwordEchoOnEdit() testWidget->setEchoMode(QLineEdit::PasswordEchoOnEdit); testWidget->setFocus(); testWidget->raise(); - QTest::qWait(250); - QVERIFY(testWidget->hasFocus()); + QTRY_VERIFY(testWidget->hasFocus()); QTest::keyPress(testWidget, '0'); QTest::keyPress(testWidget, '1'); @@ -1614,6 +1614,7 @@ void tst_QLineEdit::passwordEchoOnEdit() QVERIFY(!testWidget->hasFocus()); QCOMPARE(testWidget->displayText(), QString(5, fillChar)); testWidget->setFocus(); + QTRY_VERIFY(testWidget->hasFocus()); QCOMPARE(testWidget->displayText(), QString(5, fillChar)); QTest::keyPress(testWidget, '0'); @@ -3397,7 +3398,7 @@ void tst_QLineEdit::task210502_caseInsensitiveInlineCompletion() qt_x11_wait_for_window_manager(&lineEdit); #endif lineEdit.setFocus(); - QTest::qWait(200); + QTRY_VERIFY(lineEdit.hasFocus()); QTest::keyPress(&lineEdit, 'a'); QTest::keyPress(&lineEdit, Qt::Key_Return); QCOMPARE(lineEdit.text(), completion); @@ -3491,7 +3492,7 @@ void tst_QLineEdit::task241436_passwordEchoOnEditRestoreEchoMode() testWidget->setEchoMode(QLineEdit::PasswordEchoOnEdit); testWidget->setFocus(); - QTest::qWait(250); + QTRY_VERIFY(testWidget->hasFocus()); QTest::keyPress(testWidget, '0'); QCOMPARE(testWidget->displayText(), QString("0")); -- cgit v0.12 From b9a924a1e77faeeba595d0619afb14e8fdbb2dd4 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 8 Sep 2009 15:25:32 +1000 Subject: Current Item was moved twice when an item was inserted before it. --- src/declarative/fx/qfxlistview.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index c24610f..6c0a83e 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -1507,7 +1507,8 @@ void QFxListView::itemsInserted(int modelIndex, int count) // Update the indexes of the following visible items. for (; index < d->visibleItems.count(); ++index) { FxListItem *listItem = d->visibleItems.at(index); - listItem->setPosition(listItem->position() + (pos - initialPos)); + if (listItem->item != d->currentItem->item) + listItem->setPosition(listItem->position() + (pos - initialPos)); if (listItem->index != -1) listItem->index += count; } -- cgit v0.12 From 5305831c3b0d58a61efadc1c1d3ce9ce4d6e8c77 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 8 Sep 2009 15:30:04 +1000 Subject: Doc --- doc/src/declarative/pics/qml-context-object.png | Bin 0 -> 23602 bytes doc/src/declarative/pics/qml-context-tree.png | Bin 0 -> 10337 bytes doc/src/declarative/pics/qml-context.png | Bin 0 -> 61465 bytes doc/src/declarative/qmlformat.qdoc | 175 ++++++++++++++++++++---- doc/src/declarative/qtdeclarative.qdoc | 2 +- 5 files changed, 149 insertions(+), 28 deletions(-) create mode 100644 doc/src/declarative/pics/qml-context-object.png create mode 100644 doc/src/declarative/pics/qml-context-tree.png create mode 100644 doc/src/declarative/pics/qml-context.png diff --git a/doc/src/declarative/pics/qml-context-object.png b/doc/src/declarative/pics/qml-context-object.png new file mode 100644 index 0000000..1b91aff Binary files /dev/null and b/doc/src/declarative/pics/qml-context-object.png differ diff --git a/doc/src/declarative/pics/qml-context-tree.png b/doc/src/declarative/pics/qml-context-tree.png new file mode 100644 index 0000000..6bba5f4 Binary files /dev/null and b/doc/src/declarative/pics/qml-context-tree.png differ diff --git a/doc/src/declarative/pics/qml-context.png b/doc/src/declarative/pics/qml-context.png new file mode 100644 index 0000000..bdf2ecd Binary files /dev/null and b/doc/src/declarative/pics/qml-context.png differ diff --git a/doc/src/declarative/qmlformat.qdoc b/doc/src/declarative/qmlformat.qdoc index 9cfebf0..5013ee7 100644 --- a/doc/src/declarative/qmlformat.qdoc +++ b/doc/src/declarative/qmlformat.qdoc @@ -16,21 +16,148 @@ Much of a QML file consists of valid ECMAScript \e {Statement}s. Except where c by ECMAScript, C++ or QObject prevented it, the syntactic extensions introduced by QML are designed to look similar and fit well with existing ECMAScript syntax and concepts. +\section1 QML engine + +The \l {QmlEngine}{QML engine} executes a \l {QmlComponent}{QML document} in a +\l {QmlContext}{QML context} to produce a \l {QObject}{QML object}. A single QML +document may be executed in one or many contexts to produce many QML objects. A single +QML document may be executed many times in the same context to produce many QML objects. + +The QML engine provides the environment in which QML documents, contexts and objects +exist. It must exist before any of these structures can be created. If the engine is removed, +existing documents, contexts and objects are invalidated, but not destroyed. An invalid + +\list +\i \e {QML document} can no longer be used to create QML objects. +\i \e {QML context} can no longer host QML objects, new context properties cannot be added +and existing context properties cannot be modified. +\i \e {QML object} will no longer evaluate bindings or scripts. +\endlist + +A QML document is a block of QML source code. QML documents generally correspond to files stored +on a disk or network resource, but can be constructed directly from text data. Syntactically a QML +document is self contained; QML does \bold {not} have a preprocessor that modifies the document +before presentation to the compiler. Type references within a QML document are resolved based +exclusively on the import statements present in the document. + +A simple QML document looks like this: + +\table +\row +\o +\code +import Qt 4.6 + +Rectangle { + id: MyRect + width: 100; height: 100 + color: background +} +\endcode +\endtable + +To instantiate a QML object, a QML document is executed in a QML context. QML contexts are used by +programmers to pass data to a QML document. QML documents may include property bindings or +ECMAScript blocks that can contain variable references that need to be resolved. Each property +binding and ECMAScript block has an associated QML context that is used to resolve these references +that is determined by the QML context in which the document is executed. The example document above +contains one variable reference, \c background. + +Each QML context defines a scope for variable resolution and each may define local, named context +properties. A QML context may also have a \l {QmlContext::addDefaultObject()}{default object}, +which is an object whose properties are searched \e after the context properties when resolving a +variable name. QML contexts form a tree, starting from a root context that is provided by the QML +engine. When resolving variable references, the QML contexts are searched starting from the +QML objects containing context upwards towards the root context. + +Consider the following QML context tree. If the example QML document is executed in \c Context1, +the \c background variable will resolve to \c Context1's context property. If the document is +executed in \c Context2, the \c background variable will resolve to the root context's context +property. + +\image qml-context-tree.png + +While QML contexts can be created explicitly by the programmer to pass data into QML objects, +the QML engine also creates a new implicit QML context for every object it instantiates. +Property bindings and ECMAScript blocks in the document are associated with this QML engine +created context. Object ids that are defined in the document are added as context properties, and +their value is set to reference the appropriate object, and the instantiated QML object is set as +the context's default object. The following diagram shows the result of executing a simple QML +document. + +\image qml-context-object.png + +The blue rectangle in the diagram represents a property binding. Associated with each property +binding is the QML context to which it belongs, the object property to which it is bound and a +\e {scope object}. The scope object is usually, but not always, the object to which the bound +property belongs. The context properties, context default objects and the scope object are all +involved when resolving a variable name in a binding. The following psuedo code describes the +alogithm used: + +\table +\row +\o +\code +if (scopeObject.hasProperty(name)) + return scopeObject.property(name) + +foreach (context in contextChain) { + if (context.hasContextProperty(name) + return context.contextProperty(name) + + if (context.defaultObject.hasProperty(name)) + return context.defaultObject.property(name) +} +\endcode +\endtable + +QML supports two categories of types: \e builtin types and \e composite types. Builtin types are +those written in C++ and registered with the QML engine. Builtin types form the most basic +building blocks of QML. Composite types are constructed by composing other builtin or composite +types, property bindings and ECMAScript blocks together into a brand new type using the QML +language. Using a composite type is identical to using a builtin type. + +For example, Qt 4.6 includes a builtin type called \c Image that shows a bitmap image. The +\c Image type has \c width and \c height properties that control the size of the displayed image. +A simple composite type, that will be called \c SquareImage can be built that adds a \c size +property that sets both the width and the height. + +\table +\row +\o +\code +import Qt 4.6 +Image { + property int size + width: size + height: size +} +\endcode +\endtable + +To the QML engine, a composite type is just another QML document. When a composite type is +used the engine instantiates it just as it would any other document - by creating a new implicit +QML context and the object tree described by the document. The diagram below shows the +\c SquareImage composite type used from within another QML document. When instantiated, the +\c SquareImage object is created in its own QML context. Any property bindings sepecified in the +\c SquareImage composite type document are associated with this context. Property bindings created +in the outer document, however, are associated with its context, even those that are applied to the +created \c SquareImage object. That is, the \c size, \c source, \c width and \c height property +bindings all share a common \e {scope object}, but are owned by two different QML contexts. The +difference in containing context results in the \c Root variable resolving differently in the +different property bindings. + +\image qml-context.png + +\section1 Syntax + \section2 Commenting The commenting rules in QML are the same as for ECMAScript. Both \e {MultiLineComment} blocks and \e {SingleLineComment}'s are supported. -\section1 Definitions - -\e {QML interpreter}: QmlEngine - -\e {QML execution context}: QmlContext +\section2 QML Document -\e {inherited characteristic} - -\section1 QML Document - -\section2 Syntax +\section3 Syntax \e {QMLDocument} \bold {:} @@ -69,22 +196,16 @@ The commenting rules in QML are the same as for ECMAScript. Both \e {MultiLineC \e {DecimalLiteral} \bold {but not} with \e {ExponentPart} \endquotation -\section2 Semantics - -A QML document is the unit in which QML code may be passed to the QML interpreter. A QML document -is syntactically self contained. QML documents are evaluated by the QML interpreter in a QML -execution context to produce a single instantiated object of the type specified by -\e {QMLObjectDefinition}. +\section3 Semantics The \e {QMLImportList} is used to statically resolve type references used within the enclosing -QML document. The import list is \bold {not} an \e {inherited characteristic}; its scope of -influence is limited to structures logically contained by the document. +QML document. An import statement is used to bring a set of types into scope for a QML document. -\section1 Object Definition +\section2 Object Definition -\section2 Syntax +\section3 Syntax \e {QMLObjectDefinition} \bold {:} \quotation @@ -125,11 +246,11 @@ An import statement is used to bring a set of types into scope for a QML documen \endquotation -\section2 Semantics +\section3 Semantics -\section1 Object Extension +\section2 Object Extension -\section2 Syntax +\section3 Syntax \e {QMLObjectExtensionDefinition} \bold {:} \quotation @@ -171,14 +292,14 @@ An import statement is used to bring a set of types into scope for a QML documen \quotation \e {FunctionDeclaration} \bold {but not} \e {Identifier} \sub {opt} \endquotation -\section2 Semantics +\section3 Semantics -\section1 Binding Expression +\section2 Binding Expression -\section2 Syntax +\section3 Syntax \e {QMLBindingExpression} \bold {:} -\section2 Semantics +\section3 Semantics */ diff --git a/doc/src/declarative/qtdeclarative.qdoc b/doc/src/declarative/qtdeclarative.qdoc index 1b7644c..460819a 100644 --- a/doc/src/declarative/qtdeclarative.qdoc +++ b/doc/src/declarative/qtdeclarative.qdoc @@ -80,7 +80,7 @@ QML Reference: \list - \o \l {QML Format} + \o \l {QML Format Reference} \o \l {elements}{QML Elements} \endlist -- cgit v0.12 From a5b44447698afea24a5a691e4df852428a75d366 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 8 Sep 2009 16:48:01 +1000 Subject: Don't use qt3support methods --- src/declarative/util/qmllistmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index a5ae60f..5b7d2bb 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -407,7 +407,7 @@ void QmlListModel::remove(int index) { if (_root) { ModelNode *node = qvariant_cast(_root->values.at(index)); - _root->values.remove(index); + _root->values.removeAt(index); if (node) delete node; emit itemsRemoved(index,1); -- cgit v0.12 From 74fd14a305ce7402890de1919c3a27ac4d1cbf38 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 8 Sep 2009 09:28:41 +0200 Subject: Doc: keypad navigation is supported on Windows CE Reviewed-by: thartman --- src/gui/kernel/qapplication.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 327f5ce..bc8ed96 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -4687,7 +4687,11 @@ void QApplicationPrivate::emitLastWindowClosed() If \a enable is true, Qt::Key_Up and Qt::Key_Down are used to change focus. - This feature is available in Qt for Embedded Linux only. + This feature is available in Qt for Embedded Linux and Windows CE only. + + \note On Windows CE this feature is disabled by default for touch device + mkspecs. To enable keypad navigation, build Qt with + QT_KEYPAD_NAVIGATION defined. \sa keypadNavigationEnabled() */ @@ -4700,7 +4704,11 @@ void QApplication::setKeypadNavigationEnabled(bool enable) Returns true if Qt is set to use keypad navigation; otherwise returns false. The default is false. - This feature is available in Qt for Embedded Linux only. + This feature is available in Qt for Embedded Linux and Windows CE only. + + \note On Windows CE this feature is disabled by default for touch device + mkspecs. To enable keypad navigation, build Qt with + QT_KEYPAD_NAVIGATION defined. \sa setKeypadNavigationEnabled() */ -- cgit v0.12 From 790d6d4dda03314cccf4cad0bf32d9d8c3da4980 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Tue, 8 Sep 2009 10:12:22 +0200 Subject: make JavaScriptCore compile on platforms with case-insensitive file system There's a clash between "TypeInfo.h" and a standard header "typeinfo.h" that's included from a place we don't control. The fix is to rename "TypeInfo.h" to "JSTypeInfo.h". Reviewed-by: Simon Hausmann --- .../webkit/JavaScriptCore/JavaScriptCore.gypi | 2 +- .../webkit/JavaScriptCore/runtime/JSTypeInfo.h | 72 ++++++++++++++++++++++ .../webkit/JavaScriptCore/runtime/Structure.h | 2 +- .../webkit/JavaScriptCore/runtime/TypeInfo.h | 72 ---------------------- 4 files changed, 74 insertions(+), 74 deletions(-) create mode 100644 src/3rdparty/webkit/JavaScriptCore/runtime/JSTypeInfo.h delete mode 100644 src/3rdparty/webkit/JavaScriptCore/runtime/TypeInfo.h diff --git a/src/3rdparty/webkit/JavaScriptCore/JavaScriptCore.gypi b/src/3rdparty/webkit/JavaScriptCore/JavaScriptCore.gypi index 2d69c7d..5a75ab7 100644 --- a/src/3rdparty/webkit/JavaScriptCore/JavaScriptCore.gypi +++ b/src/3rdparty/webkit/JavaScriptCore/JavaScriptCore.gypi @@ -323,7 +323,7 @@ 'runtime/TimeoutChecker.cpp', 'runtime/TimeoutChecker.h', 'runtime/Tracing.h', - 'runtime/TypeInfo.h', + 'runtime/JSTypeInfo.h', 'runtime/UString.cpp', 'runtime/UString.h', 'wrec/CharacterClass.cpp', diff --git a/src/3rdparty/webkit/JavaScriptCore/runtime/JSTypeInfo.h b/src/3rdparty/webkit/JavaScriptCore/runtime/JSTypeInfo.h new file mode 100644 index 0000000..bea188b --- /dev/null +++ b/src/3rdparty/webkit/JavaScriptCore/runtime/JSTypeInfo.h @@ -0,0 +1,72 @@ +// -*- mode: c++; c-basic-offset: 4 -*- +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSTypeInfo_h +#define JSTypeInfo_h + +#include "JSType.h" + +namespace JSC { + + // WebCore uses MasqueradesAsUndefined to make document.all and style.filter undetectable. + static const unsigned MasqueradesAsUndefined = 1; + static const unsigned ImplementsHasInstance = 1 << 1; + static const unsigned OverridesHasInstance = 1 << 2; + static const unsigned ImplementsDefaultHasInstance = 1 << 3; + static const unsigned NeedsThisConversion = 1 << 4; + static const unsigned HasStandardGetOwnPropertySlot = 1 << 5; + + class TypeInfo { + friend class JIT; + public: + TypeInfo(JSType type, unsigned flags = 0) + : m_type(type) + { + // ImplementsDefaultHasInstance means (ImplementsHasInstance & !OverridesHasInstance) + if ((flags & (ImplementsHasInstance | OverridesHasInstance)) == ImplementsHasInstance) + m_flags = flags | ImplementsDefaultHasInstance; + else + m_flags = flags; + } + + JSType type() const { return m_type; } + + bool masqueradesAsUndefined() const { return m_flags & MasqueradesAsUndefined; } + bool implementsHasInstance() const { return m_flags & ImplementsHasInstance; } + bool overridesHasInstance() const { return m_flags & OverridesHasInstance; } + bool needsThisConversion() const { return m_flags & NeedsThisConversion; } + bool hasStandardGetOwnPropertySlot() const { return m_flags & HasStandardGetOwnPropertySlot; } + + unsigned flags() const { return m_flags; } + + private: + JSType m_type; + unsigned m_flags; + }; + +} + +#endif // JSTypeInfo_h diff --git a/src/3rdparty/webkit/JavaScriptCore/runtime/Structure.h b/src/3rdparty/webkit/JavaScriptCore/runtime/Structure.h index dcd4e50..ca4552b 100644 --- a/src/3rdparty/webkit/JavaScriptCore/runtime/Structure.h +++ b/src/3rdparty/webkit/JavaScriptCore/runtime/Structure.h @@ -31,7 +31,7 @@ #include "JSValue.h" #include "PropertyMapHashTable.h" #include "StructureTransitionTable.h" -#include "TypeInfo.h" +#include "JSTypeInfo.h" #include "UString.h" #include #include diff --git a/src/3rdparty/webkit/JavaScriptCore/runtime/TypeInfo.h b/src/3rdparty/webkit/JavaScriptCore/runtime/TypeInfo.h deleted file mode 100644 index 70aeed3..0000000 --- a/src/3rdparty/webkit/JavaScriptCore/runtime/TypeInfo.h +++ /dev/null @@ -1,72 +0,0 @@ -// -*- mode: c++; c-basic-offset: 4 -*- -/* - * Copyright (C) 2008 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef TypeInfo_h -#define TypeInfo_h - -#include "JSType.h" - -namespace JSC { - - // WebCore uses MasqueradesAsUndefined to make document.all and style.filter undetectable. - static const unsigned MasqueradesAsUndefined = 1; - static const unsigned ImplementsHasInstance = 1 << 1; - static const unsigned OverridesHasInstance = 1 << 2; - static const unsigned ImplementsDefaultHasInstance = 1 << 3; - static const unsigned NeedsThisConversion = 1 << 4; - static const unsigned HasStandardGetOwnPropertySlot = 1 << 5; - - class TypeInfo { - friend class JIT; - public: - TypeInfo(JSType type, unsigned flags = 0) - : m_type(type) - { - // ImplementsDefaultHasInstance means (ImplementsHasInstance & !OverridesHasInstance) - if ((flags & (ImplementsHasInstance | OverridesHasInstance)) == ImplementsHasInstance) - m_flags = flags | ImplementsDefaultHasInstance; - else - m_flags = flags; - } - - JSType type() const { return m_type; } - - bool masqueradesAsUndefined() const { return m_flags & MasqueradesAsUndefined; } - bool implementsHasInstance() const { return m_flags & ImplementsHasInstance; } - bool overridesHasInstance() const { return m_flags & OverridesHasInstance; } - bool needsThisConversion() const { return m_flags & NeedsThisConversion; } - bool hasStandardGetOwnPropertySlot() const { return m_flags & HasStandardGetOwnPropertySlot; } - - unsigned flags() const { return m_flags; } - - private: - JSType m_type; - unsigned m_flags; - }; - -} - -#endif // TypeInfo_h -- cgit v0.12 From 9bd7e50a5aa6258a58979a22250ce264b69d4ee2 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 7 Sep 2009 11:29:23 +0200 Subject: use a single qplatformdefs.h for all Windows CE mkspecs Additionally, mkspecs/wince.conf was moved to mkspecs/common/wince/qmake.conf The common qplatformdefs.h is also in that directory. Task-number: 259850 Reviewed-by: mauricek --- mkspecs/common/wince.conf | 90 -------------- mkspecs/common/wince/qmake.conf | 90 ++++++++++++++ mkspecs/common/wince/qplatformdefs.h | 131 +++++++++++++++++++++ mkspecs/wince50standard-armv4i-msvc2005/qmake.conf | 2 +- .../qplatformdefs.h | 90 +------------- .../qplatformdefs.h | 2 +- mkspecs/wince50standard-mipsii-msvc2005/qmake.conf | 2 +- .../qplatformdefs.h | 90 +------------- .../qplatformdefs.h | 2 +- mkspecs/wince50standard-mipsiv-msvc2005/qmake.conf | 2 +- .../qplatformdefs.h | 90 +------------- .../qplatformdefs.h | 2 +- mkspecs/wince50standard-sh4-msvc2005/qmake.conf | 2 +- .../wince50standard-sh4-msvc2005/qplatformdefs.h | 90 +------------- .../wince50standard-sh4-msvc2008/qplatformdefs.h | 2 +- mkspecs/wince50standard-x86-msvc2005/qmake.conf | 2 +- .../wince50standard-x86-msvc2005/qplatformdefs.h | 90 +------------- .../wince50standard-x86-msvc2008/qplatformdefs.h | 2 +- .../qplatformdefs.h | 90 +------------- mkspecs/wincewm50pocket-msvc2005/qmake.conf | 2 +- mkspecs/wincewm50pocket-msvc2005/qplatformdefs.h | 90 +------------- mkspecs/wincewm50pocket-msvc2008/qplatformdefs.h | 2 +- mkspecs/wincewm50smart-msvc2005/qmake.conf | 2 +- mkspecs/wincewm50smart-msvc2005/qplatformdefs.h | 90 +------------- mkspecs/wincewm50smart-msvc2008/qplatformdefs.h | 2 +- .../wincewm60professional-msvc2005/qplatformdefs.h | 90 +------------- .../wincewm60professional-msvc2008/qplatformdefs.h | 2 +- mkspecs/wincewm60standard-msvc2005/qplatformdefs.h | 90 +------------- mkspecs/wincewm60standard-msvc2008/qplatformdefs.h | 2 +- .../wincewm65professional-msvc2005/qplatformdefs.h | 3 +- .../wincewm65professional-msvc2008/qplatformdefs.h | 2 +- 31 files changed, 250 insertions(+), 998 deletions(-) delete mode 100644 mkspecs/common/wince.conf create mode 100644 mkspecs/common/wince/qmake.conf create mode 100644 mkspecs/common/wince/qplatformdefs.h diff --git a/mkspecs/common/wince.conf b/mkspecs/common/wince.conf deleted file mode 100644 index d6e4ba7..0000000 --- a/mkspecs/common/wince.conf +++ /dev/null @@ -1,90 +0,0 @@ -# -# qmake configuration for common Windows CE -# - -MAKEFILE_GENERATOR = MSVC.NET -TEMPLATE = app -QT += core gui -CONFIG += qt warn_on release incremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe - -DEFINES += UNDER_CE WINCE _WINDOWS _UNICODE UNICODE _WIN32 QT_NO_PRINTER QT_NO_PRINTDIALOG - -QMAKE_COMPILER_DEFINES += _MSC_VER=1400 - -QMAKE_CC = cl -QMAKE_LEX = flex -QMAKE_LEXFLAGS = -QMAKE_YACC = byacc -QMAKE_YACCFLAGS = -d -QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t- -QMAKE_CFLAGS_WARN_ON = -W3 -QMAKE_CFLAGS_WARN_OFF = -W0 -QMAKE_CFLAGS_RELEASE = -O2 -MD -QMAKE_CFLAGS_LTCG = -GL -QMAKE_CFLAGS_DEBUG = -DDEBUG -D_DEBUG -Zi -MDd -QMAKE_CFLAGS_YACC = - -# Uncomment the following lines to reduce library sizes -# with potential cost of performance -# QMAKE_CFLAGS += -Os -# QMAKE_CFLAGS_RELEASE += -Os - -QMAKE_CXX = $$QMAKE_CC -QMAKE_CXXFLAGS = $$QMAKE_CFLAGS -QMAKE_CXXFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON -w34100 -w34189 -QMAKE_CXXFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF -QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE -QMAKE_CXXFLAGS_DEBUG = $$QMAKE_CFLAGS_DEBUG -QMAKE_CXXFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG -QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC -QMAKE_CXXFLAGS_STL_ON = -EHsc -QMAKE_CXXFLAGS_STL_OFF = -QMAKE_CXXFLAGS_RTTI_ON = -GR -QMAKE_CXXFLAGS_RTTI_OFF = -QMAKE_CXXFLAGS_EXCEPTIONS_ON = -EHsc -QMAKE_CXXFLAGS_EXCEPTIONS_OFF = -EHs-c- - -QMAKE_INCDIR = -QMAKE_INCDIR_QT = $$[QT_INSTALL_HEADERS] -QMAKE_LIBDIR_QT = $$[QT_INSTALL_LIBS] - -QMAKE_RUN_CC = $(CC) -c $(CFLAGS) $(INCPATH) -Fo$obj $src -QMAKE_RUN_CC_IMP = $(CC) -c $(CFLAGS) $(INCPATH) -Fo$@ $< -QMAKE_RUN_CC_IMP_BATCH = $(CC) -c $(CFLAGS) $(INCPATH) -Fo$@ @<< -QMAKE_RUN_CXX = $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fo$obj $src -QMAKE_RUN_CXX_IMP = $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fo$@ $< -QMAKE_RUN_CXX_IMP_BATCH = $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fo$@ @<< - -QMAKE_LINK = link -QMAKE_LFLAGS = /NOLOGO /NODEFAULTLIB:OLDNAMES.LIB -QMAKE_LFLAGS_RELEASE = /INCREMENTAL:NO -QMAKE_LFLAGS_DEBUG = /DEBUG -QMAKE_LFLAGS_LTCG = /LTCG -QMAKE_LIBS_NETWORK = ws2.lib -QMAKE_LIBS_OPENGL = -QMAKE_LIBS_COMPAT = - -QMAKE_LIBS_QT_ENTRY = -lqtmain - -QMAKE_MOC = $$[QT_INSTALL_BINS]\moc.exe -QMAKE_UIC = $$[QT_INSTALL_BINS]\uic.exe -QMAKE_IDC = $$[QT_INSTALL_BINS]\idc.exe - -QMAKE_IDL = midl -QMAKE_LIB = lib -QMAKE_RC = rc - -QMAKE_ZIP = zip -r -9 - -QMAKE_COPY = copy /y -QMAKE_COPY_DIR = xcopy /s /q /y /i -QMAKE_MOVE = move -QMAKE_DEL_FILE = del -QMAKE_DEL_DIR = rmdir -QMAKE_CHK_DIR_EXISTS = if not exist -QMAKE_MKDIR = mkdir - -VCPROJ_EXTENSION = .vcproj -VCSOLUTION_EXTENSION = .sln -VCPROJ_KEYWORD = Qt4VSv1.0 -load(qt_config) diff --git a/mkspecs/common/wince/qmake.conf b/mkspecs/common/wince/qmake.conf new file mode 100644 index 0000000..d6e4ba7 --- /dev/null +++ b/mkspecs/common/wince/qmake.conf @@ -0,0 +1,90 @@ +# +# qmake configuration for common Windows CE +# + +MAKEFILE_GENERATOR = MSVC.NET +TEMPLATE = app +QT += core gui +CONFIG += qt warn_on release incremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe + +DEFINES += UNDER_CE WINCE _WINDOWS _UNICODE UNICODE _WIN32 QT_NO_PRINTER QT_NO_PRINTDIALOG + +QMAKE_COMPILER_DEFINES += _MSC_VER=1400 + +QMAKE_CC = cl +QMAKE_LEX = flex +QMAKE_LEXFLAGS = +QMAKE_YACC = byacc +QMAKE_YACCFLAGS = -d +QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t- +QMAKE_CFLAGS_WARN_ON = -W3 +QMAKE_CFLAGS_WARN_OFF = -W0 +QMAKE_CFLAGS_RELEASE = -O2 -MD +QMAKE_CFLAGS_LTCG = -GL +QMAKE_CFLAGS_DEBUG = -DDEBUG -D_DEBUG -Zi -MDd +QMAKE_CFLAGS_YACC = + +# Uncomment the following lines to reduce library sizes +# with potential cost of performance +# QMAKE_CFLAGS += -Os +# QMAKE_CFLAGS_RELEASE += -Os + +QMAKE_CXX = $$QMAKE_CC +QMAKE_CXXFLAGS = $$QMAKE_CFLAGS +QMAKE_CXXFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON -w34100 -w34189 +QMAKE_CXXFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF +QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE +QMAKE_CXXFLAGS_DEBUG = $$QMAKE_CFLAGS_DEBUG +QMAKE_CXXFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG +QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC +QMAKE_CXXFLAGS_STL_ON = -EHsc +QMAKE_CXXFLAGS_STL_OFF = +QMAKE_CXXFLAGS_RTTI_ON = -GR +QMAKE_CXXFLAGS_RTTI_OFF = +QMAKE_CXXFLAGS_EXCEPTIONS_ON = -EHsc +QMAKE_CXXFLAGS_EXCEPTIONS_OFF = -EHs-c- + +QMAKE_INCDIR = +QMAKE_INCDIR_QT = $$[QT_INSTALL_HEADERS] +QMAKE_LIBDIR_QT = $$[QT_INSTALL_LIBS] + +QMAKE_RUN_CC = $(CC) -c $(CFLAGS) $(INCPATH) -Fo$obj $src +QMAKE_RUN_CC_IMP = $(CC) -c $(CFLAGS) $(INCPATH) -Fo$@ $< +QMAKE_RUN_CC_IMP_BATCH = $(CC) -c $(CFLAGS) $(INCPATH) -Fo$@ @<< +QMAKE_RUN_CXX = $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fo$obj $src +QMAKE_RUN_CXX_IMP = $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fo$@ $< +QMAKE_RUN_CXX_IMP_BATCH = $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fo$@ @<< + +QMAKE_LINK = link +QMAKE_LFLAGS = /NOLOGO /NODEFAULTLIB:OLDNAMES.LIB +QMAKE_LFLAGS_RELEASE = /INCREMENTAL:NO +QMAKE_LFLAGS_DEBUG = /DEBUG +QMAKE_LFLAGS_LTCG = /LTCG +QMAKE_LIBS_NETWORK = ws2.lib +QMAKE_LIBS_OPENGL = +QMAKE_LIBS_COMPAT = + +QMAKE_LIBS_QT_ENTRY = -lqtmain + +QMAKE_MOC = $$[QT_INSTALL_BINS]\moc.exe +QMAKE_UIC = $$[QT_INSTALL_BINS]\uic.exe +QMAKE_IDC = $$[QT_INSTALL_BINS]\idc.exe + +QMAKE_IDL = midl +QMAKE_LIB = lib +QMAKE_RC = rc + +QMAKE_ZIP = zip -r -9 + +QMAKE_COPY = copy /y +QMAKE_COPY_DIR = xcopy /s /q /y /i +QMAKE_MOVE = move +QMAKE_DEL_FILE = del +QMAKE_DEL_DIR = rmdir +QMAKE_CHK_DIR_EXISTS = if not exist +QMAKE_MKDIR = mkdir + +VCPROJ_EXTENSION = .vcproj +VCSOLUTION_EXTENSION = .sln +VCPROJ_KEYWORD = Qt4VSv1.0 +load(qt_config) diff --git a/mkspecs/common/wince/qplatformdefs.h b/mkspecs/common/wince/qplatformdefs.h new file mode 100644 index 0000000..4e67948 --- /dev/null +++ b/mkspecs/common/wince/qplatformdefs.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake spec 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 QPLATFORMDEFS_H +#define QPLATFORMDEFS_H + +#ifdef UNICODE +#ifndef _UNICODE +#define _UNICODE +#endif +#endif + +// Get Qt defines/settings + +#include "qglobal.h" +#include "qfunctions_wince.h" + +#define _POSIX_ +#include +#undef _POSIX_ + +#include +#include +#include +#include + +#define Q_FS_FAT +#ifdef QT_LARGEFILE_SUPPORT +#define QT_STATBUF struct _stati64 // non-ANSI defs +#define QT_STATBUF4TSTAT struct _stati64 // non-ANSI defs +#define QT_STAT ::_stati64 +#define QT_FSTAT ::_fstati64 +#else +#define QT_STATBUF struct stat // non-ANSI defs +#define QT_STATBUF4TSTAT struct stat // non-ANSI defs +#define QT_STAT ::qt_wince_stat +#define QT_FSTAT ::qt_wince__fstat +#endif +#define QT_STAT_REG _S_IFREG +#define QT_STAT_DIR _S_IFDIR +#define QT_STAT_MASK _S_IFMT +#if defined(_S_IFLNK) +# define QT_STAT_LNK _S_IFLNK +#endif +#define QT_FILENO ::qt_wince___fileno +#define QT_OPEN ::qt_wince_open +#define QT_CLOSE ::qt_wince__close +#ifdef QT_LARGEFILE_SUPPORT +#define QT_LSEEK ::_lseeki64 +#define QT_TSTAT ::_tstati64 +#else +#define QT_LSEEK ::qt_wince__lseek +#define QT_TSTAT ::_tstat +#endif +#define QT_READ ::qt_wince__read +#define QT_WRITE ::qt_wince__write +#define QT_ACCESS ::qt_wince__access +#define QT_GETCWD ::_getcwd +#define QT_CHDIR ::_chdir +#define QT_MKDIR ::qt_wince__mkdir +#define QT_RMDIR ::qt_wince__rmdir +#define QT_OPEN_RDONLY _O_RDONLY +#define QT_OPEN_WRONLY _O_WRONLY +#define QT_OPEN_RDWR _O_RDWR +#define QT_OPEN_CREAT _O_CREAT +#define QT_OPEN_TRUNC _O_TRUNC +#define QT_OPEN_APPEND _O_APPEND +# define QT_OPEN_TEXT _O_TEXT +# define QT_OPEN_BINARY _O_BINARY + +#define QT_FOPEN ::fopen +#define QT_FSEEK ::fseek +#define QT_FTELL ::ftell +#define QT_FGETPOS ::fgetpos +#define QT_FSETPOS ::fsetpos +#define QT_FPOS_T fpos_t +#define QT_OFF_T long + +#define QT_SIGNAL_ARGS int + +#define QT_VSNPRINTF(buffer, count, format, arg) \ + _vsnprintf(buffer, count, format, arg) + +#define QT_SNPRINTF ::_snprintf + +# define F_OK 0 +# define X_OK 1 +# define W_OK 2 +# define R_OK 4 + +typedef int mode_t; + +#endif // QPLATFORMDEFS_H diff --git a/mkspecs/wince50standard-armv4i-msvc2005/qmake.conf b/mkspecs/wince50standard-armv4i-msvc2005/qmake.conf index 45ebcf7..28ca6a6 100644 --- a/mkspecs/wince50standard-armv4i-msvc2005/qmake.conf +++ b/mkspecs/wince50standard-armv4i-msvc2005/qmake.conf @@ -3,7 +3,7 @@ # # Written for Microsoft VC2005.NET with Standard SDK for WindowsCE 5.0 (ARMV4I) # -include(../common/wince.conf) +include(../common/wince/qmake.conf) CE_SDK = STANDARDSDK_500 CE_ARCH = ARMV4I diff --git a/mkspecs/wince50standard-armv4i-msvc2005/qplatformdefs.h b/mkspecs/wince50standard-armv4i-msvc2005/qplatformdefs.h index 4e67948..cda4ff4 100644 --- a/mkspecs/wince50standard-armv4i-msvc2005/qplatformdefs.h +++ b/mkspecs/wince50standard-armv4i-msvc2005/qplatformdefs.h @@ -39,93 +39,5 @@ ** ****************************************************************************/ -#ifndef QPLATFORMDEFS_H -#define QPLATFORMDEFS_H +#include "../common/wince/qplatformdefs.h" -#ifdef UNICODE -#ifndef _UNICODE -#define _UNICODE -#endif -#endif - -// Get Qt defines/settings - -#include "qglobal.h" -#include "qfunctions_wince.h" - -#define _POSIX_ -#include -#undef _POSIX_ - -#include -#include -#include -#include - -#define Q_FS_FAT -#ifdef QT_LARGEFILE_SUPPORT -#define QT_STATBUF struct _stati64 // non-ANSI defs -#define QT_STATBUF4TSTAT struct _stati64 // non-ANSI defs -#define QT_STAT ::_stati64 -#define QT_FSTAT ::_fstati64 -#else -#define QT_STATBUF struct stat // non-ANSI defs -#define QT_STATBUF4TSTAT struct stat // non-ANSI defs -#define QT_STAT ::qt_wince_stat -#define QT_FSTAT ::qt_wince__fstat -#endif -#define QT_STAT_REG _S_IFREG -#define QT_STAT_DIR _S_IFDIR -#define QT_STAT_MASK _S_IFMT -#if defined(_S_IFLNK) -# define QT_STAT_LNK _S_IFLNK -#endif -#define QT_FILENO ::qt_wince___fileno -#define QT_OPEN ::qt_wince_open -#define QT_CLOSE ::qt_wince__close -#ifdef QT_LARGEFILE_SUPPORT -#define QT_LSEEK ::_lseeki64 -#define QT_TSTAT ::_tstati64 -#else -#define QT_LSEEK ::qt_wince__lseek -#define QT_TSTAT ::_tstat -#endif -#define QT_READ ::qt_wince__read -#define QT_WRITE ::qt_wince__write -#define QT_ACCESS ::qt_wince__access -#define QT_GETCWD ::_getcwd -#define QT_CHDIR ::_chdir -#define QT_MKDIR ::qt_wince__mkdir -#define QT_RMDIR ::qt_wince__rmdir -#define QT_OPEN_RDONLY _O_RDONLY -#define QT_OPEN_WRONLY _O_WRONLY -#define QT_OPEN_RDWR _O_RDWR -#define QT_OPEN_CREAT _O_CREAT -#define QT_OPEN_TRUNC _O_TRUNC -#define QT_OPEN_APPEND _O_APPEND -# define QT_OPEN_TEXT _O_TEXT -# define QT_OPEN_BINARY _O_BINARY - -#define QT_FOPEN ::fopen -#define QT_FSEEK ::fseek -#define QT_FTELL ::ftell -#define QT_FGETPOS ::fgetpos -#define QT_FSETPOS ::fsetpos -#define QT_FPOS_T fpos_t -#define QT_OFF_T long - -#define QT_SIGNAL_ARGS int - -#define QT_VSNPRINTF(buffer, count, format, arg) \ - _vsnprintf(buffer, count, format, arg) - -#define QT_SNPRINTF ::_snprintf - -# define F_OK 0 -# define X_OK 1 -# define W_OK 2 -# define R_OK 4 - -typedef int mode_t; - -#endif // QPLATFORMDEFS_H diff --git a/mkspecs/wince50standard-armv4i-msvc2008/qplatformdefs.h b/mkspecs/wince50standard-armv4i-msvc2008/qplatformdefs.h index f775941..cda4ff4 100644 --- a/mkspecs/wince50standard-armv4i-msvc2008/qplatformdefs.h +++ b/mkspecs/wince50standard-armv4i-msvc2008/qplatformdefs.h @@ -39,5 +39,5 @@ ** ****************************************************************************/ -#include "../wince50standard-armv4i-msvc2005/qplatformdefs.h" +#include "../common/wince/qplatformdefs.h" diff --git a/mkspecs/wince50standard-mipsii-msvc2005/qmake.conf b/mkspecs/wince50standard-mipsii-msvc2005/qmake.conf index 7d765de..0cc1ab0 100644 --- a/mkspecs/wince50standard-mipsii-msvc2005/qmake.conf +++ b/mkspecs/wince50standard-mipsii-msvc2005/qmake.conf @@ -3,7 +3,7 @@ # # Written for Microsoft VC2005.NET with Standard SDK for WindowsCE 5.0 (MIPSII) # -include(../common/wince.conf) +include(../common/wince/qmake.conf) CE_SDK = STANDARDSDK_500 CE_ARCH = MIPSII diff --git a/mkspecs/wince50standard-mipsii-msvc2005/qplatformdefs.h b/mkspecs/wince50standard-mipsii-msvc2005/qplatformdefs.h index 4e67948..cda4ff4 100644 --- a/mkspecs/wince50standard-mipsii-msvc2005/qplatformdefs.h +++ b/mkspecs/wince50standard-mipsii-msvc2005/qplatformdefs.h @@ -39,93 +39,5 @@ ** ****************************************************************************/ -#ifndef QPLATFORMDEFS_H -#define QPLATFORMDEFS_H +#include "../common/wince/qplatformdefs.h" -#ifdef UNICODE -#ifndef _UNICODE -#define _UNICODE -#endif -#endif - -// Get Qt defines/settings - -#include "qglobal.h" -#include "qfunctions_wince.h" - -#define _POSIX_ -#include -#undef _POSIX_ - -#include -#include -#include -#include - -#define Q_FS_FAT -#ifdef QT_LARGEFILE_SUPPORT -#define QT_STATBUF struct _stati64 // non-ANSI defs -#define QT_STATBUF4TSTAT struct _stati64 // non-ANSI defs -#define QT_STAT ::_stati64 -#define QT_FSTAT ::_fstati64 -#else -#define QT_STATBUF struct stat // non-ANSI defs -#define QT_STATBUF4TSTAT struct stat // non-ANSI defs -#define QT_STAT ::qt_wince_stat -#define QT_FSTAT ::qt_wince__fstat -#endif -#define QT_STAT_REG _S_IFREG -#define QT_STAT_DIR _S_IFDIR -#define QT_STAT_MASK _S_IFMT -#if defined(_S_IFLNK) -# define QT_STAT_LNK _S_IFLNK -#endif -#define QT_FILENO ::qt_wince___fileno -#define QT_OPEN ::qt_wince_open -#define QT_CLOSE ::qt_wince__close -#ifdef QT_LARGEFILE_SUPPORT -#define QT_LSEEK ::_lseeki64 -#define QT_TSTAT ::_tstati64 -#else -#define QT_LSEEK ::qt_wince__lseek -#define QT_TSTAT ::_tstat -#endif -#define QT_READ ::qt_wince__read -#define QT_WRITE ::qt_wince__write -#define QT_ACCESS ::qt_wince__access -#define QT_GETCWD ::_getcwd -#define QT_CHDIR ::_chdir -#define QT_MKDIR ::qt_wince__mkdir -#define QT_RMDIR ::qt_wince__rmdir -#define QT_OPEN_RDONLY _O_RDONLY -#define QT_OPEN_WRONLY _O_WRONLY -#define QT_OPEN_RDWR _O_RDWR -#define QT_OPEN_CREAT _O_CREAT -#define QT_OPEN_TRUNC _O_TRUNC -#define QT_OPEN_APPEND _O_APPEND -# define QT_OPEN_TEXT _O_TEXT -# define QT_OPEN_BINARY _O_BINARY - -#define QT_FOPEN ::fopen -#define QT_FSEEK ::fseek -#define QT_FTELL ::ftell -#define QT_FGETPOS ::fgetpos -#define QT_FSETPOS ::fsetpos -#define QT_FPOS_T fpos_t -#define QT_OFF_T long - -#define QT_SIGNAL_ARGS int - -#define QT_VSNPRINTF(buffer, count, format, arg) \ - _vsnprintf(buffer, count, format, arg) - -#define QT_SNPRINTF ::_snprintf - -# define F_OK 0 -# define X_OK 1 -# define W_OK 2 -# define R_OK 4 - -typedef int mode_t; - -#endif // QPLATFORMDEFS_H diff --git a/mkspecs/wince50standard-mipsii-msvc2008/qplatformdefs.h b/mkspecs/wince50standard-mipsii-msvc2008/qplatformdefs.h index 319d49a..cda4ff4 100644 --- a/mkspecs/wince50standard-mipsii-msvc2008/qplatformdefs.h +++ b/mkspecs/wince50standard-mipsii-msvc2008/qplatformdefs.h @@ -39,5 +39,5 @@ ** ****************************************************************************/ -#include "../wince50standard-mipsii-msvc2005/qplatformdefs.h" +#include "../common/wince/qplatformdefs.h" diff --git a/mkspecs/wince50standard-mipsiv-msvc2005/qmake.conf b/mkspecs/wince50standard-mipsiv-msvc2005/qmake.conf index 4750d88..a22505c 100644 --- a/mkspecs/wince50standard-mipsiv-msvc2005/qmake.conf +++ b/mkspecs/wince50standard-mipsiv-msvc2005/qmake.conf @@ -3,7 +3,7 @@ # # Written for Microsoft VC2005.NET with Standard SDK for WindowsCE 5.0 (MIPSIV) # -include(../common/wince.conf) +include(../common/wince/qmake.conf) CE_SDK = STANDARDSDK_500 CE_ARCH = MIPSIV diff --git a/mkspecs/wince50standard-mipsiv-msvc2005/qplatformdefs.h b/mkspecs/wince50standard-mipsiv-msvc2005/qplatformdefs.h index 4e67948..cda4ff4 100644 --- a/mkspecs/wince50standard-mipsiv-msvc2005/qplatformdefs.h +++ b/mkspecs/wince50standard-mipsiv-msvc2005/qplatformdefs.h @@ -39,93 +39,5 @@ ** ****************************************************************************/ -#ifndef QPLATFORMDEFS_H -#define QPLATFORMDEFS_H +#include "../common/wince/qplatformdefs.h" -#ifdef UNICODE -#ifndef _UNICODE -#define _UNICODE -#endif -#endif - -// Get Qt defines/settings - -#include "qglobal.h" -#include "qfunctions_wince.h" - -#define _POSIX_ -#include -#undef _POSIX_ - -#include -#include -#include -#include - -#define Q_FS_FAT -#ifdef QT_LARGEFILE_SUPPORT -#define QT_STATBUF struct _stati64 // non-ANSI defs -#define QT_STATBUF4TSTAT struct _stati64 // non-ANSI defs -#define QT_STAT ::_stati64 -#define QT_FSTAT ::_fstati64 -#else -#define QT_STATBUF struct stat // non-ANSI defs -#define QT_STATBUF4TSTAT struct stat // non-ANSI defs -#define QT_STAT ::qt_wince_stat -#define QT_FSTAT ::qt_wince__fstat -#endif -#define QT_STAT_REG _S_IFREG -#define QT_STAT_DIR _S_IFDIR -#define QT_STAT_MASK _S_IFMT -#if defined(_S_IFLNK) -# define QT_STAT_LNK _S_IFLNK -#endif -#define QT_FILENO ::qt_wince___fileno -#define QT_OPEN ::qt_wince_open -#define QT_CLOSE ::qt_wince__close -#ifdef QT_LARGEFILE_SUPPORT -#define QT_LSEEK ::_lseeki64 -#define QT_TSTAT ::_tstati64 -#else -#define QT_LSEEK ::qt_wince__lseek -#define QT_TSTAT ::_tstat -#endif -#define QT_READ ::qt_wince__read -#define QT_WRITE ::qt_wince__write -#define QT_ACCESS ::qt_wince__access -#define QT_GETCWD ::_getcwd -#define QT_CHDIR ::_chdir -#define QT_MKDIR ::qt_wince__mkdir -#define QT_RMDIR ::qt_wince__rmdir -#define QT_OPEN_RDONLY _O_RDONLY -#define QT_OPEN_WRONLY _O_WRONLY -#define QT_OPEN_RDWR _O_RDWR -#define QT_OPEN_CREAT _O_CREAT -#define QT_OPEN_TRUNC _O_TRUNC -#define QT_OPEN_APPEND _O_APPEND -# define QT_OPEN_TEXT _O_TEXT -# define QT_OPEN_BINARY _O_BINARY - -#define QT_FOPEN ::fopen -#define QT_FSEEK ::fseek -#define QT_FTELL ::ftell -#define QT_FGETPOS ::fgetpos -#define QT_FSETPOS ::fsetpos -#define QT_FPOS_T fpos_t -#define QT_OFF_T long - -#define QT_SIGNAL_ARGS int - -#define QT_VSNPRINTF(buffer, count, format, arg) \ - _vsnprintf(buffer, count, format, arg) - -#define QT_SNPRINTF ::_snprintf - -# define F_OK 0 -# define X_OK 1 -# define W_OK 2 -# define R_OK 4 - -typedef int mode_t; - -#endif // QPLATFORMDEFS_H diff --git a/mkspecs/wince50standard-mipsiv-msvc2008/qplatformdefs.h b/mkspecs/wince50standard-mipsiv-msvc2008/qplatformdefs.h index 9a6f3ed..cda4ff4 100644 --- a/mkspecs/wince50standard-mipsiv-msvc2008/qplatformdefs.h +++ b/mkspecs/wince50standard-mipsiv-msvc2008/qplatformdefs.h @@ -39,5 +39,5 @@ ** ****************************************************************************/ -#include "../wince50standard-mipsiv-msvc2005/qplatformdefs.h" +#include "../common/wince/qplatformdefs.h" diff --git a/mkspecs/wince50standard-sh4-msvc2005/qmake.conf b/mkspecs/wince50standard-sh4-msvc2005/qmake.conf index aa420f2..1ee8950 100644 --- a/mkspecs/wince50standard-sh4-msvc2005/qmake.conf +++ b/mkspecs/wince50standard-sh4-msvc2005/qmake.conf @@ -3,7 +3,7 @@ # # Written for Microsoft VC2005.NET with Standard SDK for WindowsCE 5.0 (SH4) # -include(../common/wince.conf) +include(../common/wince/qmake.conf) CE_SDK = STANDARDSDK_500 CE_ARCH = SH4 diff --git a/mkspecs/wince50standard-sh4-msvc2005/qplatformdefs.h b/mkspecs/wince50standard-sh4-msvc2005/qplatformdefs.h index 4e67948..cda4ff4 100644 --- a/mkspecs/wince50standard-sh4-msvc2005/qplatformdefs.h +++ b/mkspecs/wince50standard-sh4-msvc2005/qplatformdefs.h @@ -39,93 +39,5 @@ ** ****************************************************************************/ -#ifndef QPLATFORMDEFS_H -#define QPLATFORMDEFS_H +#include "../common/wince/qplatformdefs.h" -#ifdef UNICODE -#ifndef _UNICODE -#define _UNICODE -#endif -#endif - -// Get Qt defines/settings - -#include "qglobal.h" -#include "qfunctions_wince.h" - -#define _POSIX_ -#include -#undef _POSIX_ - -#include -#include -#include -#include - -#define Q_FS_FAT -#ifdef QT_LARGEFILE_SUPPORT -#define QT_STATBUF struct _stati64 // non-ANSI defs -#define QT_STATBUF4TSTAT struct _stati64 // non-ANSI defs -#define QT_STAT ::_stati64 -#define QT_FSTAT ::_fstati64 -#else -#define QT_STATBUF struct stat // non-ANSI defs -#define QT_STATBUF4TSTAT struct stat // non-ANSI defs -#define QT_STAT ::qt_wince_stat -#define QT_FSTAT ::qt_wince__fstat -#endif -#define QT_STAT_REG _S_IFREG -#define QT_STAT_DIR _S_IFDIR -#define QT_STAT_MASK _S_IFMT -#if defined(_S_IFLNK) -# define QT_STAT_LNK _S_IFLNK -#endif -#define QT_FILENO ::qt_wince___fileno -#define QT_OPEN ::qt_wince_open -#define QT_CLOSE ::qt_wince__close -#ifdef QT_LARGEFILE_SUPPORT -#define QT_LSEEK ::_lseeki64 -#define QT_TSTAT ::_tstati64 -#else -#define QT_LSEEK ::qt_wince__lseek -#define QT_TSTAT ::_tstat -#endif -#define QT_READ ::qt_wince__read -#define QT_WRITE ::qt_wince__write -#define QT_ACCESS ::qt_wince__access -#define QT_GETCWD ::_getcwd -#define QT_CHDIR ::_chdir -#define QT_MKDIR ::qt_wince__mkdir -#define QT_RMDIR ::qt_wince__rmdir -#define QT_OPEN_RDONLY _O_RDONLY -#define QT_OPEN_WRONLY _O_WRONLY -#define QT_OPEN_RDWR _O_RDWR -#define QT_OPEN_CREAT _O_CREAT -#define QT_OPEN_TRUNC _O_TRUNC -#define QT_OPEN_APPEND _O_APPEND -# define QT_OPEN_TEXT _O_TEXT -# define QT_OPEN_BINARY _O_BINARY - -#define QT_FOPEN ::fopen -#define QT_FSEEK ::fseek -#define QT_FTELL ::ftell -#define QT_FGETPOS ::fgetpos -#define QT_FSETPOS ::fsetpos -#define QT_FPOS_T fpos_t -#define QT_OFF_T long - -#define QT_SIGNAL_ARGS int - -#define QT_VSNPRINTF(buffer, count, format, arg) \ - _vsnprintf(buffer, count, format, arg) - -#define QT_SNPRINTF ::_snprintf - -# define F_OK 0 -# define X_OK 1 -# define W_OK 2 -# define R_OK 4 - -typedef int mode_t; - -#endif // QPLATFORMDEFS_H diff --git a/mkspecs/wince50standard-sh4-msvc2008/qplatformdefs.h b/mkspecs/wince50standard-sh4-msvc2008/qplatformdefs.h index 88ca7ab..cda4ff4 100644 --- a/mkspecs/wince50standard-sh4-msvc2008/qplatformdefs.h +++ b/mkspecs/wince50standard-sh4-msvc2008/qplatformdefs.h @@ -39,5 +39,5 @@ ** ****************************************************************************/ -#include "../wince50standard-sh4-msvc2005/qplatformdefs.h" +#include "../common/wince/qplatformdefs.h" diff --git a/mkspecs/wince50standard-x86-msvc2005/qmake.conf b/mkspecs/wince50standard-x86-msvc2005/qmake.conf index 13bcc9f..2fa7556 100644 --- a/mkspecs/wince50standard-x86-msvc2005/qmake.conf +++ b/mkspecs/wince50standard-x86-msvc2005/qmake.conf @@ -3,7 +3,7 @@ # # Written for Microsoft VC2005.NET with Standard SDK for WindowsCE 5.0 (x86) # -include(../common/wince.conf) +include(../common/wince/qmake.conf) CE_SDK = STANDARDSDK_500 CE_ARCH = x86 diff --git a/mkspecs/wince50standard-x86-msvc2005/qplatformdefs.h b/mkspecs/wince50standard-x86-msvc2005/qplatformdefs.h index 4e67948..cda4ff4 100644 --- a/mkspecs/wince50standard-x86-msvc2005/qplatformdefs.h +++ b/mkspecs/wince50standard-x86-msvc2005/qplatformdefs.h @@ -39,93 +39,5 @@ ** ****************************************************************************/ -#ifndef QPLATFORMDEFS_H -#define QPLATFORMDEFS_H +#include "../common/wince/qplatformdefs.h" -#ifdef UNICODE -#ifndef _UNICODE -#define _UNICODE -#endif -#endif - -// Get Qt defines/settings - -#include "qglobal.h" -#include "qfunctions_wince.h" - -#define _POSIX_ -#include -#undef _POSIX_ - -#include -#include -#include -#include - -#define Q_FS_FAT -#ifdef QT_LARGEFILE_SUPPORT -#define QT_STATBUF struct _stati64 // non-ANSI defs -#define QT_STATBUF4TSTAT struct _stati64 // non-ANSI defs -#define QT_STAT ::_stati64 -#define QT_FSTAT ::_fstati64 -#else -#define QT_STATBUF struct stat // non-ANSI defs -#define QT_STATBUF4TSTAT struct stat // non-ANSI defs -#define QT_STAT ::qt_wince_stat -#define QT_FSTAT ::qt_wince__fstat -#endif -#define QT_STAT_REG _S_IFREG -#define QT_STAT_DIR _S_IFDIR -#define QT_STAT_MASK _S_IFMT -#if defined(_S_IFLNK) -# define QT_STAT_LNK _S_IFLNK -#endif -#define QT_FILENO ::qt_wince___fileno -#define QT_OPEN ::qt_wince_open -#define QT_CLOSE ::qt_wince__close -#ifdef QT_LARGEFILE_SUPPORT -#define QT_LSEEK ::_lseeki64 -#define QT_TSTAT ::_tstati64 -#else -#define QT_LSEEK ::qt_wince__lseek -#define QT_TSTAT ::_tstat -#endif -#define QT_READ ::qt_wince__read -#define QT_WRITE ::qt_wince__write -#define QT_ACCESS ::qt_wince__access -#define QT_GETCWD ::_getcwd -#define QT_CHDIR ::_chdir -#define QT_MKDIR ::qt_wince__mkdir -#define QT_RMDIR ::qt_wince__rmdir -#define QT_OPEN_RDONLY _O_RDONLY -#define QT_OPEN_WRONLY _O_WRONLY -#define QT_OPEN_RDWR _O_RDWR -#define QT_OPEN_CREAT _O_CREAT -#define QT_OPEN_TRUNC _O_TRUNC -#define QT_OPEN_APPEND _O_APPEND -# define QT_OPEN_TEXT _O_TEXT -# define QT_OPEN_BINARY _O_BINARY - -#define QT_FOPEN ::fopen -#define QT_FSEEK ::fseek -#define QT_FTELL ::ftell -#define QT_FGETPOS ::fgetpos -#define QT_FSETPOS ::fsetpos -#define QT_FPOS_T fpos_t -#define QT_OFF_T long - -#define QT_SIGNAL_ARGS int - -#define QT_VSNPRINTF(buffer, count, format, arg) \ - _vsnprintf(buffer, count, format, arg) - -#define QT_SNPRINTF ::_snprintf - -# define F_OK 0 -# define X_OK 1 -# define W_OK 2 -# define R_OK 4 - -typedef int mode_t; - -#endif // QPLATFORMDEFS_H diff --git a/mkspecs/wince50standard-x86-msvc2008/qplatformdefs.h b/mkspecs/wince50standard-x86-msvc2008/qplatformdefs.h index 76dc923..cda4ff4 100644 --- a/mkspecs/wince50standard-x86-msvc2008/qplatformdefs.h +++ b/mkspecs/wince50standard-x86-msvc2008/qplatformdefs.h @@ -39,5 +39,5 @@ ** ****************************************************************************/ -#include "../wince50standard-x86-msvc2005/qplatformdefs.h" +#include "../common/wince/qplatformdefs.h" diff --git a/mkspecs/wince60standard-armv4i-msvc2005/qplatformdefs.h b/mkspecs/wince60standard-armv4i-msvc2005/qplatformdefs.h index 4e67948..cda4ff4 100644 --- a/mkspecs/wince60standard-armv4i-msvc2005/qplatformdefs.h +++ b/mkspecs/wince60standard-armv4i-msvc2005/qplatformdefs.h @@ -39,93 +39,5 @@ ** ****************************************************************************/ -#ifndef QPLATFORMDEFS_H -#define QPLATFORMDEFS_H +#include "../common/wince/qplatformdefs.h" -#ifdef UNICODE -#ifndef _UNICODE -#define _UNICODE -#endif -#endif - -// Get Qt defines/settings - -#include "qglobal.h" -#include "qfunctions_wince.h" - -#define _POSIX_ -#include -#undef _POSIX_ - -#include -#include -#include -#include - -#define Q_FS_FAT -#ifdef QT_LARGEFILE_SUPPORT -#define QT_STATBUF struct _stati64 // non-ANSI defs -#define QT_STATBUF4TSTAT struct _stati64 // non-ANSI defs -#define QT_STAT ::_stati64 -#define QT_FSTAT ::_fstati64 -#else -#define QT_STATBUF struct stat // non-ANSI defs -#define QT_STATBUF4TSTAT struct stat // non-ANSI defs -#define QT_STAT ::qt_wince_stat -#define QT_FSTAT ::qt_wince__fstat -#endif -#define QT_STAT_REG _S_IFREG -#define QT_STAT_DIR _S_IFDIR -#define QT_STAT_MASK _S_IFMT -#if defined(_S_IFLNK) -# define QT_STAT_LNK _S_IFLNK -#endif -#define QT_FILENO ::qt_wince___fileno -#define QT_OPEN ::qt_wince_open -#define QT_CLOSE ::qt_wince__close -#ifdef QT_LARGEFILE_SUPPORT -#define QT_LSEEK ::_lseeki64 -#define QT_TSTAT ::_tstati64 -#else -#define QT_LSEEK ::qt_wince__lseek -#define QT_TSTAT ::_tstat -#endif -#define QT_READ ::qt_wince__read -#define QT_WRITE ::qt_wince__write -#define QT_ACCESS ::qt_wince__access -#define QT_GETCWD ::_getcwd -#define QT_CHDIR ::_chdir -#define QT_MKDIR ::qt_wince__mkdir -#define QT_RMDIR ::qt_wince__rmdir -#define QT_OPEN_RDONLY _O_RDONLY -#define QT_OPEN_WRONLY _O_WRONLY -#define QT_OPEN_RDWR _O_RDWR -#define QT_OPEN_CREAT _O_CREAT -#define QT_OPEN_TRUNC _O_TRUNC -#define QT_OPEN_APPEND _O_APPEND -# define QT_OPEN_TEXT _O_TEXT -# define QT_OPEN_BINARY _O_BINARY - -#define QT_FOPEN ::fopen -#define QT_FSEEK ::fseek -#define QT_FTELL ::ftell -#define QT_FGETPOS ::fgetpos -#define QT_FSETPOS ::fsetpos -#define QT_FPOS_T fpos_t -#define QT_OFF_T long - -#define QT_SIGNAL_ARGS int - -#define QT_VSNPRINTF(buffer, count, format, arg) \ - _vsnprintf(buffer, count, format, arg) - -#define QT_SNPRINTF ::_snprintf - -# define F_OK 0 -# define X_OK 1 -# define W_OK 2 -# define R_OK 4 - -typedef int mode_t; - -#endif // QPLATFORMDEFS_H diff --git a/mkspecs/wincewm50pocket-msvc2005/qmake.conf b/mkspecs/wincewm50pocket-msvc2005/qmake.conf index d75d86e..676be5a 100644 --- a/mkspecs/wincewm50pocket-msvc2005/qmake.conf +++ b/mkspecs/wincewm50pocket-msvc2005/qmake.conf @@ -3,7 +3,7 @@ # # Written for Microsoft VC2005.NET with Windows Mobile 5.0 SDK for Pocket PC (ARMV4I) # -include(../common/wince.conf) +include(../common/wince/qmake.conf) CE_SDK = Windows Mobile 5.0 Pocket PC SDK CE_ARCH = ARMV4I diff --git a/mkspecs/wincewm50pocket-msvc2005/qplatformdefs.h b/mkspecs/wincewm50pocket-msvc2005/qplatformdefs.h index 4e67948..cda4ff4 100644 --- a/mkspecs/wincewm50pocket-msvc2005/qplatformdefs.h +++ b/mkspecs/wincewm50pocket-msvc2005/qplatformdefs.h @@ -39,93 +39,5 @@ ** ****************************************************************************/ -#ifndef QPLATFORMDEFS_H -#define QPLATFORMDEFS_H +#include "../common/wince/qplatformdefs.h" -#ifdef UNICODE -#ifndef _UNICODE -#define _UNICODE -#endif -#endif - -// Get Qt defines/settings - -#include "qglobal.h" -#include "qfunctions_wince.h" - -#define _POSIX_ -#include -#undef _POSIX_ - -#include -#include -#include -#include - -#define Q_FS_FAT -#ifdef QT_LARGEFILE_SUPPORT -#define QT_STATBUF struct _stati64 // non-ANSI defs -#define QT_STATBUF4TSTAT struct _stati64 // non-ANSI defs -#define QT_STAT ::_stati64 -#define QT_FSTAT ::_fstati64 -#else -#define QT_STATBUF struct stat // non-ANSI defs -#define QT_STATBUF4TSTAT struct stat // non-ANSI defs -#define QT_STAT ::qt_wince_stat -#define QT_FSTAT ::qt_wince__fstat -#endif -#define QT_STAT_REG _S_IFREG -#define QT_STAT_DIR _S_IFDIR -#define QT_STAT_MASK _S_IFMT -#if defined(_S_IFLNK) -# define QT_STAT_LNK _S_IFLNK -#endif -#define QT_FILENO ::qt_wince___fileno -#define QT_OPEN ::qt_wince_open -#define QT_CLOSE ::qt_wince__close -#ifdef QT_LARGEFILE_SUPPORT -#define QT_LSEEK ::_lseeki64 -#define QT_TSTAT ::_tstati64 -#else -#define QT_LSEEK ::qt_wince__lseek -#define QT_TSTAT ::_tstat -#endif -#define QT_READ ::qt_wince__read -#define QT_WRITE ::qt_wince__write -#define QT_ACCESS ::qt_wince__access -#define QT_GETCWD ::_getcwd -#define QT_CHDIR ::_chdir -#define QT_MKDIR ::qt_wince__mkdir -#define QT_RMDIR ::qt_wince__rmdir -#define QT_OPEN_RDONLY _O_RDONLY -#define QT_OPEN_WRONLY _O_WRONLY -#define QT_OPEN_RDWR _O_RDWR -#define QT_OPEN_CREAT _O_CREAT -#define QT_OPEN_TRUNC _O_TRUNC -#define QT_OPEN_APPEND _O_APPEND -# define QT_OPEN_TEXT _O_TEXT -# define QT_OPEN_BINARY _O_BINARY - -#define QT_FOPEN ::fopen -#define QT_FSEEK ::fseek -#define QT_FTELL ::ftell -#define QT_FGETPOS ::fgetpos -#define QT_FSETPOS ::fsetpos -#define QT_FPOS_T fpos_t -#define QT_OFF_T long - -#define QT_SIGNAL_ARGS int - -#define QT_VSNPRINTF(buffer, count, format, arg) \ - _vsnprintf(buffer, count, format, arg) - -#define QT_SNPRINTF ::_snprintf - -# define F_OK 0 -# define X_OK 1 -# define W_OK 2 -# define R_OK 4 - -typedef int mode_t; - -#endif // QPLATFORMDEFS_H diff --git a/mkspecs/wincewm50pocket-msvc2008/qplatformdefs.h b/mkspecs/wincewm50pocket-msvc2008/qplatformdefs.h index f444562..cda4ff4 100644 --- a/mkspecs/wincewm50pocket-msvc2008/qplatformdefs.h +++ b/mkspecs/wincewm50pocket-msvc2008/qplatformdefs.h @@ -39,5 +39,5 @@ ** ****************************************************************************/ -#include "../wincewm50pocket-msvc2005/qplatformdefs.h" +#include "../common/wince/qplatformdefs.h" diff --git a/mkspecs/wincewm50smart-msvc2005/qmake.conf b/mkspecs/wincewm50smart-msvc2005/qmake.conf index 372b266..c0f09cc 100644 --- a/mkspecs/wincewm50smart-msvc2005/qmake.conf +++ b/mkspecs/wincewm50smart-msvc2005/qmake.conf @@ -3,7 +3,7 @@ # # Written for Microsoft VC2005.NET with Windows Mobile 5.0 SDK for Smartphone (ARMV4I) # -include(../common/wince.conf) +include(../common/wince/qmake.conf) CE_SDK = Windows Mobile 5.0 Smartphone SDK CE_ARCH = ARMV4I diff --git a/mkspecs/wincewm50smart-msvc2005/qplatformdefs.h b/mkspecs/wincewm50smart-msvc2005/qplatformdefs.h index 4e67948..cda4ff4 100644 --- a/mkspecs/wincewm50smart-msvc2005/qplatformdefs.h +++ b/mkspecs/wincewm50smart-msvc2005/qplatformdefs.h @@ -39,93 +39,5 @@ ** ****************************************************************************/ -#ifndef QPLATFORMDEFS_H -#define QPLATFORMDEFS_H +#include "../common/wince/qplatformdefs.h" -#ifdef UNICODE -#ifndef _UNICODE -#define _UNICODE -#endif -#endif - -// Get Qt defines/settings - -#include "qglobal.h" -#include "qfunctions_wince.h" - -#define _POSIX_ -#include -#undef _POSIX_ - -#include -#include -#include -#include - -#define Q_FS_FAT -#ifdef QT_LARGEFILE_SUPPORT -#define QT_STATBUF struct _stati64 // non-ANSI defs -#define QT_STATBUF4TSTAT struct _stati64 // non-ANSI defs -#define QT_STAT ::_stati64 -#define QT_FSTAT ::_fstati64 -#else -#define QT_STATBUF struct stat // non-ANSI defs -#define QT_STATBUF4TSTAT struct stat // non-ANSI defs -#define QT_STAT ::qt_wince_stat -#define QT_FSTAT ::qt_wince__fstat -#endif -#define QT_STAT_REG _S_IFREG -#define QT_STAT_DIR _S_IFDIR -#define QT_STAT_MASK _S_IFMT -#if defined(_S_IFLNK) -# define QT_STAT_LNK _S_IFLNK -#endif -#define QT_FILENO ::qt_wince___fileno -#define QT_OPEN ::qt_wince_open -#define QT_CLOSE ::qt_wince__close -#ifdef QT_LARGEFILE_SUPPORT -#define QT_LSEEK ::_lseeki64 -#define QT_TSTAT ::_tstati64 -#else -#define QT_LSEEK ::qt_wince__lseek -#define QT_TSTAT ::_tstat -#endif -#define QT_READ ::qt_wince__read -#define QT_WRITE ::qt_wince__write -#define QT_ACCESS ::qt_wince__access -#define QT_GETCWD ::_getcwd -#define QT_CHDIR ::_chdir -#define QT_MKDIR ::qt_wince__mkdir -#define QT_RMDIR ::qt_wince__rmdir -#define QT_OPEN_RDONLY _O_RDONLY -#define QT_OPEN_WRONLY _O_WRONLY -#define QT_OPEN_RDWR _O_RDWR -#define QT_OPEN_CREAT _O_CREAT -#define QT_OPEN_TRUNC _O_TRUNC -#define QT_OPEN_APPEND _O_APPEND -# define QT_OPEN_TEXT _O_TEXT -# define QT_OPEN_BINARY _O_BINARY - -#define QT_FOPEN ::fopen -#define QT_FSEEK ::fseek -#define QT_FTELL ::ftell -#define QT_FGETPOS ::fgetpos -#define QT_FSETPOS ::fsetpos -#define QT_FPOS_T fpos_t -#define QT_OFF_T long - -#define QT_SIGNAL_ARGS int - -#define QT_VSNPRINTF(buffer, count, format, arg) \ - _vsnprintf(buffer, count, format, arg) - -#define QT_SNPRINTF ::_snprintf - -# define F_OK 0 -# define X_OK 1 -# define W_OK 2 -# define R_OK 4 - -typedef int mode_t; - -#endif // QPLATFORMDEFS_H diff --git a/mkspecs/wincewm50smart-msvc2008/qplatformdefs.h b/mkspecs/wincewm50smart-msvc2008/qplatformdefs.h index 37c8f62..cda4ff4 100644 --- a/mkspecs/wincewm50smart-msvc2008/qplatformdefs.h +++ b/mkspecs/wincewm50smart-msvc2008/qplatformdefs.h @@ -39,5 +39,5 @@ ** ****************************************************************************/ -#include "../wincewm50smart-msvc2005/qplatformdefs.h" +#include "../common/wince/qplatformdefs.h" diff --git a/mkspecs/wincewm60professional-msvc2005/qplatformdefs.h b/mkspecs/wincewm60professional-msvc2005/qplatformdefs.h index 4e67948..cda4ff4 100644 --- a/mkspecs/wincewm60professional-msvc2005/qplatformdefs.h +++ b/mkspecs/wincewm60professional-msvc2005/qplatformdefs.h @@ -39,93 +39,5 @@ ** ****************************************************************************/ -#ifndef QPLATFORMDEFS_H -#define QPLATFORMDEFS_H +#include "../common/wince/qplatformdefs.h" -#ifdef UNICODE -#ifndef _UNICODE -#define _UNICODE -#endif -#endif - -// Get Qt defines/settings - -#include "qglobal.h" -#include "qfunctions_wince.h" - -#define _POSIX_ -#include -#undef _POSIX_ - -#include -#include -#include -#include - -#define Q_FS_FAT -#ifdef QT_LARGEFILE_SUPPORT -#define QT_STATBUF struct _stati64 // non-ANSI defs -#define QT_STATBUF4TSTAT struct _stati64 // non-ANSI defs -#define QT_STAT ::_stati64 -#define QT_FSTAT ::_fstati64 -#else -#define QT_STATBUF struct stat // non-ANSI defs -#define QT_STATBUF4TSTAT struct stat // non-ANSI defs -#define QT_STAT ::qt_wince_stat -#define QT_FSTAT ::qt_wince__fstat -#endif -#define QT_STAT_REG _S_IFREG -#define QT_STAT_DIR _S_IFDIR -#define QT_STAT_MASK _S_IFMT -#if defined(_S_IFLNK) -# define QT_STAT_LNK _S_IFLNK -#endif -#define QT_FILENO ::qt_wince___fileno -#define QT_OPEN ::qt_wince_open -#define QT_CLOSE ::qt_wince__close -#ifdef QT_LARGEFILE_SUPPORT -#define QT_LSEEK ::_lseeki64 -#define QT_TSTAT ::_tstati64 -#else -#define QT_LSEEK ::qt_wince__lseek -#define QT_TSTAT ::_tstat -#endif -#define QT_READ ::qt_wince__read -#define QT_WRITE ::qt_wince__write -#define QT_ACCESS ::qt_wince__access -#define QT_GETCWD ::_getcwd -#define QT_CHDIR ::_chdir -#define QT_MKDIR ::qt_wince__mkdir -#define QT_RMDIR ::qt_wince__rmdir -#define QT_OPEN_RDONLY _O_RDONLY -#define QT_OPEN_WRONLY _O_WRONLY -#define QT_OPEN_RDWR _O_RDWR -#define QT_OPEN_CREAT _O_CREAT -#define QT_OPEN_TRUNC _O_TRUNC -#define QT_OPEN_APPEND _O_APPEND -# define QT_OPEN_TEXT _O_TEXT -# define QT_OPEN_BINARY _O_BINARY - -#define QT_FOPEN ::fopen -#define QT_FSEEK ::fseek -#define QT_FTELL ::ftell -#define QT_FGETPOS ::fgetpos -#define QT_FSETPOS ::fsetpos -#define QT_FPOS_T fpos_t -#define QT_OFF_T long - -#define QT_SIGNAL_ARGS int - -#define QT_VSNPRINTF(buffer, count, format, arg) \ - _vsnprintf(buffer, count, format, arg) - -#define QT_SNPRINTF ::_snprintf - -# define F_OK 0 -# define X_OK 1 -# define W_OK 2 -# define R_OK 4 - -typedef int mode_t; - -#endif // QPLATFORMDEFS_H diff --git a/mkspecs/wincewm60professional-msvc2008/qplatformdefs.h b/mkspecs/wincewm60professional-msvc2008/qplatformdefs.h index a0737ae..cda4ff4 100644 --- a/mkspecs/wincewm60professional-msvc2008/qplatformdefs.h +++ b/mkspecs/wincewm60professional-msvc2008/qplatformdefs.h @@ -39,5 +39,5 @@ ** ****************************************************************************/ -#include "../wincewm60professional-msvc2005/qplatformdefs.h" +#include "../common/wince/qplatformdefs.h" diff --git a/mkspecs/wincewm60standard-msvc2005/qplatformdefs.h b/mkspecs/wincewm60standard-msvc2005/qplatformdefs.h index 4e67948..cda4ff4 100644 --- a/mkspecs/wincewm60standard-msvc2005/qplatformdefs.h +++ b/mkspecs/wincewm60standard-msvc2005/qplatformdefs.h @@ -39,93 +39,5 @@ ** ****************************************************************************/ -#ifndef QPLATFORMDEFS_H -#define QPLATFORMDEFS_H +#include "../common/wince/qplatformdefs.h" -#ifdef UNICODE -#ifndef _UNICODE -#define _UNICODE -#endif -#endif - -// Get Qt defines/settings - -#include "qglobal.h" -#include "qfunctions_wince.h" - -#define _POSIX_ -#include -#undef _POSIX_ - -#include -#include -#include -#include - -#define Q_FS_FAT -#ifdef QT_LARGEFILE_SUPPORT -#define QT_STATBUF struct _stati64 // non-ANSI defs -#define QT_STATBUF4TSTAT struct _stati64 // non-ANSI defs -#define QT_STAT ::_stati64 -#define QT_FSTAT ::_fstati64 -#else -#define QT_STATBUF struct stat // non-ANSI defs -#define QT_STATBUF4TSTAT struct stat // non-ANSI defs -#define QT_STAT ::qt_wince_stat -#define QT_FSTAT ::qt_wince__fstat -#endif -#define QT_STAT_REG _S_IFREG -#define QT_STAT_DIR _S_IFDIR -#define QT_STAT_MASK _S_IFMT -#if defined(_S_IFLNK) -# define QT_STAT_LNK _S_IFLNK -#endif -#define QT_FILENO ::qt_wince___fileno -#define QT_OPEN ::qt_wince_open -#define QT_CLOSE ::qt_wince__close -#ifdef QT_LARGEFILE_SUPPORT -#define QT_LSEEK ::_lseeki64 -#define QT_TSTAT ::_tstati64 -#else -#define QT_LSEEK ::qt_wince__lseek -#define QT_TSTAT ::_tstat -#endif -#define QT_READ ::qt_wince__read -#define QT_WRITE ::qt_wince__write -#define QT_ACCESS ::qt_wince__access -#define QT_GETCWD ::_getcwd -#define QT_CHDIR ::_chdir -#define QT_MKDIR ::qt_wince__mkdir -#define QT_RMDIR ::qt_wince__rmdir -#define QT_OPEN_RDONLY _O_RDONLY -#define QT_OPEN_WRONLY _O_WRONLY -#define QT_OPEN_RDWR _O_RDWR -#define QT_OPEN_CREAT _O_CREAT -#define QT_OPEN_TRUNC _O_TRUNC -#define QT_OPEN_APPEND _O_APPEND -# define QT_OPEN_TEXT _O_TEXT -# define QT_OPEN_BINARY _O_BINARY - -#define QT_FOPEN ::fopen -#define QT_FSEEK ::fseek -#define QT_FTELL ::ftell -#define QT_FGETPOS ::fgetpos -#define QT_FSETPOS ::fsetpos -#define QT_FPOS_T fpos_t -#define QT_OFF_T long - -#define QT_SIGNAL_ARGS int - -#define QT_VSNPRINTF(buffer, count, format, arg) \ - _vsnprintf(buffer, count, format, arg) - -#define QT_SNPRINTF ::_snprintf - -# define F_OK 0 -# define X_OK 1 -# define W_OK 2 -# define R_OK 4 - -typedef int mode_t; - -#endif // QPLATFORMDEFS_H diff --git a/mkspecs/wincewm60standard-msvc2008/qplatformdefs.h b/mkspecs/wincewm60standard-msvc2008/qplatformdefs.h index 819f150..cda4ff4 100644 --- a/mkspecs/wincewm60standard-msvc2008/qplatformdefs.h +++ b/mkspecs/wincewm60standard-msvc2008/qplatformdefs.h @@ -39,5 +39,5 @@ ** ****************************************************************************/ -#include "../wincewm60standard-msvc2005/qplatformdefs.h" +#include "../common/wince/qplatformdefs.h" diff --git a/mkspecs/wincewm65professional-msvc2005/qplatformdefs.h b/mkspecs/wincewm65professional-msvc2005/qplatformdefs.h index c3270e2..cda4ff4 100644 --- a/mkspecs/wincewm65professional-msvc2005/qplatformdefs.h +++ b/mkspecs/wincewm65professional-msvc2005/qplatformdefs.h @@ -39,4 +39,5 @@ ** ****************************************************************************/ -#include "../wincewm60professional-msvc2005/qplatformdefs.h" +#include "../common/wince/qplatformdefs.h" + diff --git a/mkspecs/wincewm65professional-msvc2008/qplatformdefs.h b/mkspecs/wincewm65professional-msvc2008/qplatformdefs.h index 35219d0..cda4ff4 100644 --- a/mkspecs/wincewm65professional-msvc2008/qplatformdefs.h +++ b/mkspecs/wincewm65professional-msvc2008/qplatformdefs.h @@ -39,5 +39,5 @@ ** ****************************************************************************/ -#include "../wincewm65professional-msvc2005/qplatformdefs.h" +#include "../common/wince/qplatformdefs.h" -- cgit v0.12 From 593172d298258c9dac13340ec712afc1473d5f34 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 8 Sep 2009 10:18:13 +0200 Subject: mkspec wince60standard-x86-msvc2005 added This is a mkspec template for creating x86 Windows CE 6 mkspecs. Task-number: 259850 Reviewed-by: mauricek --- mkspecs/wince60standard-armv4i-msvc2005/qmake.conf | 79 ++-------------------- mkspecs/wince60standard-x86-msvc2005/qmake.conf | 27 ++++++++ .../wince60standard-x86-msvc2005/qplatformdefs.h | 43 ++++++++++++ 3 files changed, 76 insertions(+), 73 deletions(-) create mode 100644 mkspecs/wince60standard-x86-msvc2005/qmake.conf create mode 100644 mkspecs/wince60standard-x86-msvc2005/qplatformdefs.h diff --git a/mkspecs/wince60standard-armv4i-msvc2005/qmake.conf b/mkspecs/wince60standard-armv4i-msvc2005/qmake.conf index 6386141..3bb18af 100644 --- a/mkspecs/wince60standard-armv4i-msvc2005/qmake.conf +++ b/mkspecs/wince60standard-armv4i-msvc2005/qmake.conf @@ -1,65 +1,20 @@ # # qmake configuration for wince-msvc2005 # -# Written for Microsoft VC2005.NET with Standard SDK for WindowsCE 6.0 (ARMV4I) +# Written for Microsoft VS 2005 for WindowsCE 6.0 (ARMV4I) +# This is just a template for creating Windows CE 6 mkspecs. # -MAKEFILE_GENERATOR = MSVC.NET -TEMPLATE = app -CONFIG += qt warn_on release incremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe -QT += core gui -CE_SDK = STANDARDSDK_600 -CE_ARCH = ARMV4I - -DEFINES += UNDER_CE WINCE _WINDOWS _UNICODE UNICODE STANDARDSHELL_UI_MODEL _WIN32_WCE=0x600 $$CE_ARCH _ARMV4I_ armv4i _ARM_ ARM _M_ARM ARM _WIN32 __arm__ Q_OS_WINCE_STD QT_NO_PRINTER QT_NO_PRINTDIALOG - -QMAKE_COMPILER_DEFINES += _MSC_VER=1400 - -QMAKE_CC = cl -QMAKE_LEX = flex -QMAKE_LEXFLAGS = -QMAKE_YACC = byacc -QMAKE_YACCFLAGS = -d -QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t- -QRarch4T -QRinterwork-return -QMAKE_CFLAGS_WARN_ON = -W3 -QMAKE_CFLAGS_WARN_OFF = -W0 -QMAKE_CFLAGS_RELEASE = -O2 -GL -MD -QMAKE_CFLAGS_DEBUG = -DDEBUG -D_DEBUG -Zi -MDd -QMAKE_CFLAGS_YACC = - -QMAKE_CXX = $$QMAKE_CC -QMAKE_CXXFLAGS = $$QMAKE_CFLAGS -QMAKE_CXXFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON -w34100 -w34189 -QMAKE_CXXFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF -QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE -QMAKE_CXXFLAGS_DEBUG = $$QMAKE_CFLAGS_DEBUG -QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC -QMAKE_CXXFLAGS_STL_ON = -EHsc -QMAKE_CXXFLAGS_STL_OFF = -QMAKE_CXXFLAGS_RTTI_ON = -GR -QMAKE_CXXFLAGS_RTTI_OFF = -QMAKE_CXXFLAGS_EXCEPTIONS_ON = -EHsc -QMAKE_CXXFLAGS_EXCEPTIONS_OFF = +include(../common/wince/qmake.conf) -QMAKE_INCDIR = -QMAKE_INCDIR_QT = $$[QT_INSTALL_HEADERS] -QMAKE_LIBDIR_QT = $$[QT_INSTALL_LIBS] +CE_SDK = STANDARDSDK_600 # replace with actual SDK name +CE_ARCH = ARMV4I -QMAKE_RUN_CC = $(CC) -c $(CFLAGS) $(INCPATH) -Fo$obj $src -QMAKE_RUN_CC_IMP = $(CC) -c $(CFLAGS) $(INCPATH) -Fo$@ $< -QMAKE_RUN_CC_IMP_BATCH = $(CC) -c $(CFLAGS) $(INCPATH) -Fo$@ @<< -QMAKE_RUN_CXX = $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fo$obj $src -QMAKE_RUN_CXX_IMP = $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fo$@ $< -QMAKE_RUN_CXX_IMP_BATCH = $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fo$@ @<< +DEFINES += STANDARDSHELL_UI_MODEL _WIN32_WCE=0x600 $$CE_ARCH _ARMV4I_ armv4i _ARM_ ARM _M_ARM ARM _WIN32 __arm__ -QMAKE_LINK = link -QMAKE_LFLAGS = /NOLOGO /NODEFAULTLIB:OLDNAMES.LIB -QMAKE_LFLAGS_RELEASE = /LTCG /INCREMENTAL:NO -QMAKE_LFLAGS_DEBUG = /DEBUG QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:WINDOWSCE,6.00 /MACHINE:THUMB /ENTRY:mainACRTStartup QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWSCE,6.00 /MACHINE:THUMB QMAKE_LFLAGS_DLL = /SUBSYSTEM:WINDOWSCE,6.00 /MACHINE:THUMB /DLL /SAFESEH:NO -QMAKE_LIBFLAGS = $$QMAKE_LFLAGS_WINDOWS QMAKE_LIBFLAGS_RELEASE = /LTCG QMAKE_LIBS = corelibc.lib coredll.lib QMAKE_LIBS_CORE = libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib @@ -68,27 +23,5 @@ QMAKE_LIBS_NETWORK = ws2.lib $$QMAKE_LIBS_GUI QMAKE_LIBS_OPENGL = QMAKE_LIBS_COMPAT = -QMAKE_LIBS_QT_ENTRY = -lqtmain - -QMAKE_MOC = $$[QT_INSTALL_BINS]\moc.exe -QMAKE_UIC = $$[QT_INSTALL_BINS]\uic.exe -QMAKE_IDC = $$[QT_INSTALL_BINS]\idc.exe - -QMAKE_IDL = midl -QMAKE_LIB = lib QMAKE_RC = rc /DUNDER_CE=600 /D_WIN32_WCE=0x600 -QMAKE_ZIP = zip -r -9 - -QMAKE_COPY = copy /y -QMAKE_COPY_DIR = xcopy /s /q /y /i -QMAKE_MOVE = move -QMAKE_DEL_FILE = del -QMAKE_DEL_DIR = rmdir -QMAKE_CHK_DIR_EXISTS = if not exist -QMAKE_MKDIR = mkdir - -VCPROJ_EXTENSION = .vcproj -VCSOLUTION_EXTENSION = .sln -VCPROJ_KEYWORD = Qt4VSv1.0 -load(qt_config) diff --git a/mkspecs/wince60standard-x86-msvc2005/qmake.conf b/mkspecs/wince60standard-x86-msvc2005/qmake.conf new file mode 100644 index 0000000..2896c69 --- /dev/null +++ b/mkspecs/wince60standard-x86-msvc2005/qmake.conf @@ -0,0 +1,27 @@ +# +# qmake configuration for wince-msvc2005 +# +# Written for Microsoft VS 2005 for WindowsCE 6.0 (x86) +# This is just a template for creating Windows CE 6 mkspecs. +# + +include(../common/wince/qmake.conf) + +CE_SDK = STANDARDSDK_600 # replace with actual SDK name +CE_ARCH = x86 + +DEFINES += STANDARDSHELL_UI_MODEL _WIN32_WCE=0x600 $$CE_ARCH _X86_ _M_IX86 + +QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:WINDOWSCE,6.00 /MACHINE:X86 /ENTRY:mainACRTStartup +QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWSCE,6.00 /MACHINE:X86 +QMAKE_LFLAGS_DLL = /SUBSYSTEM:WINDOWSCE,6.00 /MACHINE:X86 /DLL /SAFESEH:NO +QMAKE_LIBFLAGS_RELEASE = /LTCG +QMAKE_LIBS = corelibc.lib coredll.lib +QMAKE_LIBS_CORE = corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib +QMAKE_LIBS_GUI = ceshell.lib ole32.lib $$QMAKE_LIBS_CORE +QMAKE_LIBS_NETWORK = ws2.lib $$QMAKE_LIBS_GUI +QMAKE_LIBS_OPENGL = +QMAKE_LIBS_COMPAT = + +QMAKE_RC = rc /DUNDER_CE=600 /D_WIN32_WCE=0x600 + diff --git a/mkspecs/wince60standard-x86-msvc2005/qplatformdefs.h b/mkspecs/wince60standard-x86-msvc2005/qplatformdefs.h new file mode 100644 index 0000000..cda4ff4 --- /dev/null +++ b/mkspecs/wince60standard-x86-msvc2005/qplatformdefs.h @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake spec 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 "../common/wince/qplatformdefs.h" + -- cgit v0.12 From 115d2c10b56228fbcdab5a8506c24d7b4745d95c Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Mon, 7 Sep 2009 16:46:47 +0200 Subject: Tests: Do not execute network tests at all if DNS setup is broken. Reviewed-by: Jesper --- tests/auto/network-settings.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h index 144f7b3..6ffb6f4 100644 --- a/tests/auto/network-settings.h +++ b/tests/auto/network-settings.h @@ -328,3 +328,18 @@ QByteArray QtNetworkSettings::imapExpectedReplySsl; #else #define Q_SET_DEFAULT_IAP #endif + + +class QtNetworkSettingsInitializerCode { +public: + QtNetworkSettingsInitializerCode() { + QHostInfo testServerResult = QHostInfo::fromName(QtNetworkSettings::serverName()); + if (testServerResult.error() != QHostInfo::NoError) { + qWarning() << "Could not lookup" << QtNetworkSettings::serverName(); + qWarning() << "Please configure the test environment!"; + qWarning() << "See /etc/hosts or network-settings.h"; + qFatal("Exiting"); + } + } +}; +QtNetworkSettingsInitializerCode qtNetworkSettingsInitializer; -- cgit v0.12 From deff8fcf0ed060b949c3ec0fa0ec4bd81c253825 Mon Sep 17 00:00:00 2001 From: mae Date: Tue, 8 Sep 2009 10:45:27 +0200 Subject: Fix autotest The piece table test relied on previous automatic edit command grouping. The grouping now has to be enforced explicitely with beginEditGroup()/endEditGroup() --- tests/auto/qtextpiecetable/tst_qtextpiecetable.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/auto/qtextpiecetable/tst_qtextpiecetable.cpp b/tests/auto/qtextpiecetable/tst_qtextpiecetable.cpp index 6f8dd2b..61f4456 100644 --- a/tests/auto/qtextpiecetable/tst_qtextpiecetable.cpp +++ b/tests/auto/qtextpiecetable/tst_qtextpiecetable.cpp @@ -772,7 +772,9 @@ void tst_QTextPieceTable::blockRemoval1() QVERIFY(table->blocksFind(6).position() == 5); QVERIFY(table->blocksFind(11).position() == 10); + table->beginEditBlock(); table->remove(5, 5); + table->endEditBlock(); QVERIFY(table->blocksFind(4).blockFormat() == QTextBlockFormat()); QVERIFY(table->blocksFind(5).blockFormat() == fmt2); QVERIFY(table->blocksFind(4).position() == 0); @@ -864,7 +866,10 @@ void tst_QTextPieceTable::blockRemoval3() QVERIFY(table->blocksFind(6).position() == 5); QVERIFY(table->blocksFind(11).position() == 10); + table->beginEditBlock(); table->remove(3, 4); + table->endEditBlock(); + QVERIFY(table->blocksFind(1).blockFormat() == QTextBlockFormat()); QVERIFY(table->blocksFind(5).blockFormat() == QTextBlockFormat()); QVERIFY(table->blocksFind(1).position() == 0); @@ -958,7 +963,10 @@ void tst_QTextPieceTable::blockRemoval5() QVERIFY(table->blocksFind(6).position() == 5); QVERIFY(table->blocksFind(11).position() == 10); + table->beginEditBlock(); table->remove(3, 8); + table->endEditBlock(); + QVERIFY(table->blocksFind(0).blockFormat() == QTextBlockFormat()); QVERIFY(table->blocksFind(5).blockFormat() == QTextBlockFormat()); QVERIFY(table->blocksFind(1).position() == 0); -- cgit v0.12 From fa889cf4b80868249c70715275069eb150b597cc Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 8 Sep 2009 10:45:57 +0200 Subject: Try to make test more robust. By using QTRY_{COMPARE,VERIFY} instead of waiting an arbitrary amount of time waiting for the window manager to do his job. Also use QApplication::setActiveWindow which seems to be more robust then QWidget::activateWindow --- tests/auto/qabstractbutton/tst_qabstractbutton.cpp | 5 +-- tests/auto/qbuttongroup/tst_qbuttongroup.cpp | 8 ++--- tests/auto/qcompleter/tst_qcompleter.cpp | 10 ++++-- tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp | 7 ++-- tests/auto/qfocusevent/tst_qfocusevent.cpp | 25 +++++++------ tests/auto/qgridlayout/tst_qgridlayout.cpp | 11 +++--- tests/auto/qgroupbox/tst_qgroupbox.cpp | 6 ++-- tests/auto/qitemdelegate/tst_qitemdelegate.cpp | 9 ++--- tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp | 42 ++++++++++++---------- tests/auto/qmenu/tst_qmenu.cpp | 14 +++++--- tests/auto/qpushbutton/tst_qpushbutton.cpp | 8 +++-- tests/auto/qspinbox/tst_qspinbox.cpp | 20 ++++++----- tests/auto/qstackedlayout/tst_qstackedlayout.cpp | 13 ++++--- tests/auto/qtableview/tst_qtableview.cpp | 25 +++++++------ tests/auto/qtextbrowser/tst_qtextbrowser.cpp | 6 +++- tests/auto/qtreeview/tst_qtreeview.cpp | 5 +-- 16 files changed, 130 insertions(+), 84 deletions(-) diff --git a/tests/auto/qabstractbutton/tst_qabstractbutton.cpp b/tests/auto/qabstractbutton/tst_qabstractbutton.cpp index de2d9f4..7ee52ad 100644 --- a/tests/auto/qabstractbutton/tst_qabstractbutton.cpp +++ b/tests/auto/qabstractbutton/tst_qabstractbutton.cpp @@ -550,6 +550,7 @@ void tst_QAbstractButton::setShortcut() { QKeySequence seq( Qt::Key_A ); testWidget->setShortcut( seq ); + QApplication::setActiveWindow(testWidget); // must be active to get shortcuts for (int i = 0; !testWidget->isActiveWindow() && i < 100; ++i) { @@ -557,8 +558,8 @@ void tst_QAbstractButton::setShortcut() QApplication::instance()->processEvents(); QTest::qWait(100); } - QVERIFY(testWidget->isActiveWindow()); - + QVERIFY(testWidget->isActiveWindow()); + QTest::keyClick( testWidget, 'A' ); QTest::qWait(300); // Animate click takes time QCOMPARE(click_count, (uint)1); diff --git a/tests/auto/qbuttongroup/tst_qbuttongroup.cpp b/tests/auto/qbuttongroup/tst_qbuttongroup.cpp index f49568d..82969b9 100644 --- a/tests/auto/qbuttongroup/tst_qbuttongroup.cpp +++ b/tests/auto/qbuttongroup/tst_qbuttongroup.cpp @@ -100,7 +100,7 @@ private slots: #if QT_VERSION >= 0x040600 void autoIncrementId(); #endif - + void task209485_removeFromGroupInEventHandler_data(); void task209485_removeFromGroupInEventHandler(); }; @@ -333,12 +333,12 @@ void tst_QButtonGroup::testSignals() QCOMPARE(clickedSpy.count(), 1); QCOMPARE(clickedIdSpy.count(), 1); - - int expectedId = -1; + + int expectedId = -1; #if QT_VERSION >= 0x040600 expectedId = -2; #endif - + QVERIFY(clickedIdSpy.takeFirst().at(0).toInt() == expectedId); QCOMPARE(pressedSpy.count(), 1); QCOMPARE(pressedIdSpy.count(), 1); diff --git a/tests/auto/qcompleter/tst_qcompleter.cpp b/tests/auto/qcompleter/tst_qcompleter.cpp index 928d826..7eefb26 100644 --- a/tests/auto/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/qcompleter/tst_qcompleter.cpp @@ -1025,6 +1025,7 @@ void tst_QCompleter::multipleWidgets() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&window); #endif + QApplication::setActiveWindow(&window); QTest::qWait(50); QTRY_VERIFY(qApp->focusWidget() == comboBox); comboBox->lineEdit()->setText("it"); @@ -1058,6 +1059,7 @@ void tst_QCompleter::focusIn() window.show(); QTest::qWait(100); window.activateWindow(); + QApplication::setActiveWindow(&window); QTest::qWait(100); QTRY_COMPARE(qApp->activeWindow(), &window); @@ -1322,8 +1324,10 @@ void tst_QCompleter::task253125_lineEditCompletion() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&edit); #endif + QTest::qWait(10); + QApplication::setActiveWindow(&edit); + QTRY_COMPARE(QApplication::activeWindow(), &edit); - QTest::qWait(100); QTest::keyClick(&edit, 'i'); QCOMPARE(edit.completer()->currentCompletion(), QString("iota")); QTest::keyClick(edit.completer()->popup(), Qt::Key_Down); @@ -1358,7 +1362,9 @@ void tst_QCompleter::task247560_keyboardNavigation() qt_x11_wait_for_window_manager(&edit); #endif - QTest::qWait(100); + QTest::qWait(10); + QApplication::setActiveWindow(&edit); + QTRY_COMPARE(QApplication::activeWindow(), &edit); QTest::keyClick(&edit, 'r'); QTest::keyClick(edit.completer()->popup(), Qt::Key_Down); diff --git a/tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp b/tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp index 6162be0..aa3ccb7 100644 --- a/tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp +++ b/tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp @@ -52,6 +52,9 @@ #include #include + +#include "../../shared/util.h" + //TESTED_CLASS= //TESTED_FILES=gui/widgets/qspinbox.h gui/widgets/qspinbox.cpp gui/widgets/qabstractspinbox.cpp gui/widgets/qabstractspinbox_p.h gui/widgets/qabstractspinbox.h @@ -772,8 +775,8 @@ void tst_QDoubleSpinBox::editingFinished() layout->addWidget(box2); testFocusWidget->show(); - QTest::qWait(100); - QVERIFY(box->isActiveWindow()); + QTest::qWait(10); + QTRY_VERIFY(box->isActiveWindow()); box->setFocus(); QSignalSpy editingFinishedSpy1(box, SIGNAL(editingFinished())); diff --git a/tests/auto/qfocusevent/tst_qfocusevent.cpp b/tests/auto/qfocusevent/tst_qfocusevent.cpp index 662f115..5ad78de 100644 --- a/tests/auto/qfocusevent/tst_qfocusevent.cpp +++ b/tests/auto/qfocusevent/tst_qfocusevent.cpp @@ -56,6 +56,8 @@ #include #include +#include "../../shared/util.h" + QT_FORWARD_DECLARE_CLASS(QWidget) //TESTED_CLASS= @@ -168,6 +170,7 @@ void tst_QFocusEvent::initWidget() { // On X11 we have to ensure the event was processed before doing any checking, on Windows // this is processed straight away. + QApplication::setActiveWindow(childFocusWidgetOne); for (int i = 0; i < 1000; ++i) { if (childFocusWidgetOne->isActiveWindow() && childFocusWidgetOne->hasFocus()) @@ -243,9 +246,9 @@ void tst_QFocusEvent::checkReason_BackTab() // Now test the backtab key QTest::keyClick( childFocusWidgetOne, Qt::Key_Backtab ); - QTest::qWait(2000); + QTest::qWait(200); - QVERIFY(childFocusWidgetOne->focusOutEventRecieved); + QTRY_VERIFY(childFocusWidgetOne->focusOutEventRecieved); QVERIFY(childFocusWidgetTwo->focusInEventRecieved); QVERIFY(childFocusWidgetOne->focusOutEventLostFocus); QVERIFY(childFocusWidgetTwo->focusInEventGotFocus); @@ -265,9 +268,9 @@ void tst_QFocusEvent::checkReason_Popup() Q3PopupMenu* popupMenu = new Q3PopupMenu( testFocusWidget ); popupMenu->insertItem( "Test" ); popupMenu->popup( QPoint(0,0) ); - QTest::qWait(500); + QTest::qWait(50); - QVERIFY(childFocusWidgetOne->focusOutEventLostFocus); + QTRY_VERIFY(childFocusWidgetOne->focusOutEventLostFocus); QVERIFY( childFocusWidgetOne->hasFocus() ); QVERIFY( !childFocusWidgetOne->focusInEventRecieved ); @@ -290,11 +293,11 @@ void tst_QFocusEvent::checkReason_Popup() QMenu* popupMenu = new QMenu( testFocusWidget ); popupMenu->addMenu( "Test" ); popupMenu->popup( QPoint(0,0) ); - QTest::qWait(500); + QTest::qWait(50); - QVERIFY(childFocusWidgetOne->focusOutEventLostFocus); + QTRY_VERIFY(childFocusWidgetOne->focusOutEventLostFocus); - QVERIFY( childFocusWidgetOne->hasFocus() ); + QTRY_VERIFY( childFocusWidgetOne->hasFocus() ); QVERIFY( !childFocusWidgetOne->focusInEventRecieved ); QVERIFY( childFocusWidgetOne->focusOutEventRecieved ); QVERIFY( !childFocusWidgetTwo->focusInEventRecieved ); @@ -368,13 +371,13 @@ void tst_QFocusEvent::checkReason_focusWidget() QLineEdit edit1; QLineEdit edit2; - QVBoxLayout outerLayout; + QVBoxLayout outerLayout; outerLayout.addWidget(&frame1); outerLayout.addWidget(&frame2); window1.setLayout(&outerLayout); - - QVBoxLayout leftLayout; - QVBoxLayout rightLayout; + + QVBoxLayout leftLayout; + QVBoxLayout rightLayout; leftLayout.addWidget(&edit1); rightLayout.addWidget(&edit2); frame1.setLayout(&leftLayout); diff --git a/tests/auto/qgridlayout/tst_qgridlayout.cpp b/tests/auto/qgridlayout/tst_qgridlayout.cpp index 13d79b1..590bafa 100644 --- a/tests/auto/qgridlayout/tst_qgridlayout.cpp +++ b/tests/auto/qgridlayout/tst_qgridlayout.cpp @@ -51,6 +51,8 @@ #include #include +#include "../../shared/util.h" + //TESTED_CLASS= //TESTED_FILES=gui/kernel/qlayout.cpp gui/kernel/qlayout.h @@ -788,8 +790,8 @@ void tst_QGridLayout::minMaxSize_data() QTest::addColumn("fixedSize"); //input and expected output QTest::addColumn("sizeinfos"); - - QTest::newRow("3x1 grid, extend to minimumSize") << QString() << 3 << 1 + + QTest::newRow("3x1 grid, extend to minimumSize") << QString() << 3 << 1 << int(QSizePolicy::Minimum) << QSize(152, 50) << (SizeInfoList() << SizeInfo(QRect(10, 10, 43, 30), QSize( 75, 75), QSize(0,0)) << SizeInfo(QRect(10 + 45, 10, 43, 30), QSize(75, 75), QSize( 0, 0)) @@ -917,13 +919,14 @@ void tst_QGridLayout::minMaxSize() #if defined(Q_WS_X11) qt_x11_wait_for_window_manager(m_toplevel); // wait for the show #endif + QTest::qWait(20); m_toplevel->adjustSize(); - QTest::qWait(200); // wait for the implicit adjustSize + QTest::qWait(20); // wait for the implicit adjustSize // If the following fails we might have to wait longer. // If that does not help there is likely a problem with the implicit adjustSize in show() if (!fixedSize.isValid()) { // Note that this can fail if the desktop has large fonts on windows. - QCOMPARE(m_toplevel->size(), m_toplevel->sizeHint()); + QTRY_COMPARE(m_toplevel->size(), m_toplevel->sizeHint()); } // We are relying on the order here... for (int pi = 0; pi < sizehinters.count(); ++pi) { diff --git a/tests/auto/qgroupbox/tst_qgroupbox.cpp b/tests/auto/qgroupbox/tst_qgroupbox.cpp index 94b70e6..7346700 100644 --- a/tests/auto/qgroupbox/tst_qgroupbox.cpp +++ b/tests/auto/qgroupbox/tst_qgroupbox.cpp @@ -49,6 +49,8 @@ #include "qgroupbox.h" +#include "../../shared/util.h" + //TESTED_CLASS= //TESTED_FILES= @@ -81,7 +83,7 @@ private slots: void toggledVsClicked(); void childrenAreDisabled(); void propagateFocus(); - + private: bool checked; qint64 timeStamp; @@ -467,7 +469,7 @@ void tst_QGroupBox::propagateFocus() box.show(); box.setFocus(); QTest::qWait(250); - QCOMPARE(qApp->focusWidget(), static_cast(&lineEdit)); + QTRY_COMPARE(qApp->focusWidget(), static_cast(&lineEdit)); } QTEST_MAIN(tst_QGroupBox) diff --git a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp index 1ef77c0..9871da3 100644 --- a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp @@ -63,6 +63,8 @@ #include #include +#include "../../shared/util.h" + Q_DECLARE_METATYPE(QAbstractItemDelegate::EndEditHint) //TESTED_CLASS= @@ -862,6 +864,8 @@ void tst_QItemDelegate::decoration() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&table); #endif + QApplication::setActiveWindow(&table); + QTRY_COMPARE(QApplication::activeWindow(), &table); QVariant value; switch ((QVariant::Type)type) { @@ -1164,10 +1168,7 @@ void tst_QItemDelegate::task257859_finalizeEdit() QDialog dialog; QTimer::singleShot(100, &dialog, SLOT(close())); dialog.exec(); - - QTest::qWait(100); - - QVERIFY(!editor); + QTRY_VERIFY(!editor); } diff --git a/tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp b/tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp index 78ba46b..4d5160b 100644 --- a/tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp +++ b/tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp @@ -63,6 +63,9 @@ #include #endif +#include "../../shared/util.h" + + QT_BEGIN_NAMESPACE #if defined(Q_WS_X11) extern void qt_x11_wait_for_window_manager(QWidget *w); @@ -1004,15 +1007,16 @@ void tst_QMdiSubWindow::setSystemMenu() qt_x11_wait_for_window_manager(&mainWindow); #endif - QVERIFY(subWindow->isVisible()); - QPoint globalPopupPos = subWindow->mapToGlobal(subWindow->contentsRect().topLeft()); + QTRY_VERIFY(subWindow->isVisible()); + QPoint globalPopupPos; // Show system menu QVERIFY(!qApp->activePopupWidget()); subWindow->showSystemMenu(); - QTest::qWait(250); - QCOMPARE(qApp->activePopupWidget(), qobject_cast(systemMenu)); - QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); + QTest::qWait(25); + QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast(systemMenu)); + QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), + (globalPopupPos = subWindow->mapToGlobal(subWindow->contentsRect().topLeft())) ); systemMenu->hide(); QVERIFY(!qApp->activePopupWidget()); @@ -1034,9 +1038,9 @@ void tst_QMdiSubWindow::setSystemMenu() // Show the new system menu QVERIFY(!qApp->activePopupWidget()); subWindow->showSystemMenu(); - QTest::qWait(250); - QCOMPARE(qApp->activePopupWidget(), qobject_cast(systemMenu)); - QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); + QTest::qWait(25); + QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast(systemMenu)); + QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); systemMenu->hide(); QVERIFY(!qApp->activePopupWidget()); @@ -1048,12 +1052,12 @@ void tst_QMdiSubWindow::setSystemMenu() QWidget *menuLabel = subWindow->maximizedSystemMenuIconWidget(); QVERIFY(menuLabel); subWindow->showSystemMenu(); - QTest::qWait(250); - QCOMPARE(qApp->activePopupWidget(), qobject_cast(systemMenu)); - globalPopupPos = menuLabel->mapToGlobal(QPoint(0, menuLabel->y() + menuLabel->height())); - QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); + QTest::qWait(25); + QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast(systemMenu)); + QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), + (globalPopupPos = menuLabel->mapToGlobal(QPoint(0, menuLabel->y() + menuLabel->height())))); systemMenu->hide(); - QVERIFY(!qApp->activePopupWidget()); + QTRY_VERIFY(!qApp->activePopupWidget()); subWindow->showNormal(); #endif @@ -1064,11 +1068,11 @@ void tst_QMdiSubWindow::setSystemMenu() subWindow->showSystemMenu(); QTest::qWait(250); - QCOMPARE(qApp->activePopupWidget(), qobject_cast(systemMenu)); + QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast(systemMenu)); // + QPoint(1, 0) because topRight() == QPoint(left() + width() -1, top()) globalPopupPos = subWindow->mapToGlobal(subWindow->contentsRect().topRight()) + QPoint(1, 0); globalPopupPos -= QPoint(systemMenu->sizeHint().width(), 0); - QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); + QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); systemMenu->hide(); QVERIFY(!qApp->activePopupWidget()); @@ -1081,10 +1085,10 @@ void tst_QMdiSubWindow::setSystemMenu() QVERIFY(menuLabel); subWindow->showSystemMenu(); QTest::qWait(250); - QCOMPARE(qApp->activePopupWidget(), qobject_cast(systemMenu)); + QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast(systemMenu)); globalPopupPos = menuLabel->mapToGlobal(QPoint(menuLabel->width(), menuLabel->y() + menuLabel->height())); globalPopupPos -= QPoint(systemMenu->sizeHint().width(), 0); - QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); + QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); #endif delete systemMenu; @@ -1902,7 +1906,7 @@ void tst_QMdiSubWindow::task_182852() mainWindow.show(); mainWindow.menuBar()->setVisible(true); qApp->setActiveWindow(&mainWindow); - + QString originalWindowTitle = QString::fromLatin1("MainWindow - [foo]"); mainWindow.setWindowTitle(originalWindowTitle); @@ -1917,7 +1921,7 @@ void tst_QMdiSubWindow::task_182852() window->showMaximized(); qApp->processEvents(); QVERIFY(window->isMaximized()); - + QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]") .arg(originalWindowTitle, window->widget()->windowTitle())); diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp index ab8dd48..4a4231a 100644 --- a/tests/auto/qmenu/tst_qmenu.cpp +++ b/tests/auto/qmenu/tst_qmenu.cpp @@ -55,6 +55,9 @@ #include #include #include + +#include "../../shared/util.h" + //TESTED_CLASS= //TESTED_FILES= @@ -437,15 +440,16 @@ void tst_QMenu::overrideMenuAction() m->addAction(aQuit); w.show(); - QTest::qWait(200); + w.setFocus(); + QTRY_VERIFY(w.hasFocus()); //test of the action inside the menu QTest::keyClick(&w, Qt::Key_X, Qt::ControlModifier); - QCOMPARE(activated, aQuit); + QTRY_COMPARE(activated, aQuit); //test if the menu still pops out QTest::keyClick(&w, Qt::Key_F, Qt::AltModifier); - QVERIFY(m->isVisible()); + QTRY_VERIFY(m->isVisible()); delete aFileMenu; @@ -703,12 +707,12 @@ void tst_QMenu::task250673_activeMultiColumnSubMenuPosition() }; QMenu sub; - + if (sub.style()->styleHint(QStyle::SH_Menu_Scrollable, 0, &sub)) { //the style prevents the menus from getting columns QSKIP("the style doesn't support multiple columns, it makes the menu scrollable", SkipSingle); } - + sub.addAction("Sub-Item1"); QAction *subAction = sub.addAction("Sub-Item2"); diff --git a/tests/auto/qpushbutton/tst_qpushbutton.cpp b/tests/auto/qpushbutton/tst_qpushbutton.cpp index 5059578..2013258 100644 --- a/tests/auto/qpushbutton/tst_qpushbutton.cpp +++ b/tests/auto/qpushbutton/tst_qpushbutton.cpp @@ -54,6 +54,8 @@ #include #include +#include "../../shared/util.h" + Q_DECLARE_METATYPE(QPushButton*) //TESTED_CLASS= @@ -413,6 +415,7 @@ void tst_QPushButton::setAccel() // The shortcut will not be activated unless the button is in a active // window and has focus + QApplication::setActiveWindow(testWidget); testWidget->setFocus(); for (int i = 0; !testWidget->isActiveWindow() && i < 1000; ++i) { testWidget->activateWindow(); @@ -421,8 +424,8 @@ void tst_QPushButton::setAccel() } QVERIFY(testWidget->isActiveWindow()); QTest::keyClick( testWidget, 'A', Qt::AltModifier ); - QTest::qWait( 500 ); - QVERIFY( click_count == 1 ); + QTest::qWait( 50 ); + QTRY_VERIFY( click_count == 1 ); QVERIFY( press_count == 1 ); QVERIFY( release_count == 1 ); QVERIFY( toggle_count == 0 ); @@ -430,6 +433,7 @@ void tst_QPushButton::setAccel() // wait 200 ms because setAccel uses animateClick. // if we don't wait this may screw up a next test. QTest::qWait(200); + QTRY_VERIFY( !testWidget->isDown() ); } void tst_QPushButton::animateClick() diff --git a/tests/auto/qspinbox/tst_qspinbox.cpp b/tests/auto/qspinbox/tst_qspinbox.cpp index 73d25a2..f4d70d1 100644 --- a/tests/auto/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/qspinbox/tst_qspinbox.cpp @@ -140,7 +140,7 @@ private slots: void removeAll(); void startWithDash(); void undoRedo(); - + void specialValue(); void textFromValue(); @@ -750,11 +750,13 @@ void tst_QSpinBox::editingFinished() QSpinBox *box2 = new QSpinBox(testFocusWidget); layout->addWidget(box2); + testFocusWidget->show(); + QApplication::setActiveWindow(testFocusWidget); box->activateWindow(); - QTest::qWait(1000);//qApp->processEvents(); + QTest::qWait(100);//qApp->processEvents(); box->setFocus(); - QTRY_VERIFY(qApp->focusWidget() == box); + QTRY_COMPARE(qApp->focusWidget(), box); QSignalSpy editingFinishedSpy1(box, SIGNAL(editingFinished())); QSignalSpy editingFinishedSpy2(box2, SIGNAL(editingFinished())); @@ -910,7 +912,7 @@ void tst_QSpinBox::undoRedo() void tst_QSpinBox::specialValue() { QString specialText="foo"; - + QWidget topWidget; QVBoxLayout layout(&topWidget); SpinBox spin(&topWidget); @@ -937,7 +939,7 @@ void tst_QSpinBox::specialValue() QCOMPARE(spin.text(), QString("0")); QTest::keyClick(&spin, Qt::Key_Return); QCOMPARE(spin.text(), specialText); - + spin.setValue(50); QTest::keyClick(&spin, Qt::Key_Return); QTest::keyClick(&spin, '0'); @@ -987,17 +989,17 @@ void tst_QSpinBox::sizeHint() QVERIFY(spinBox->sizeHintRequests > 0); // Suffix - spinBox->sizeHintRequests = 0; + spinBox->sizeHintRequests = 0; spinBox->setSuffix(QLatin1String("abcdefghij")); qApp->processEvents(); - QVERIFY(spinBox->sizeHintRequests > 0); + QVERIFY(spinBox->sizeHintRequests > 0); // Range - spinBox->sizeHintRequests = 0; + spinBox->sizeHintRequests = 0; spinBox->setRange(0, 1234567890); spinBox->setValue(spinBox->maximum()); qApp->processEvents(); - QVERIFY(spinBox->sizeHintRequests > 0); + QVERIFY(spinBox->sizeHintRequests > 0); } QTEST_MAIN(tst_QSpinBox) diff --git a/tests/auto/qstackedlayout/tst_qstackedlayout.cpp b/tests/auto/qstackedlayout/tst_qstackedlayout.cpp index c6a30a5..481ee2c 100644 --- a/tests/auto/qstackedlayout/tst_qstackedlayout.cpp +++ b/tests/auto/qstackedlayout/tst_qstackedlayout.cpp @@ -47,6 +47,8 @@ #include #include +#include "../../shared/util.h" + //TESTED_CLASS= //TESTED_FILES=gui/kernel/qlayout.cpp gui/kernel/qlayout.h @@ -149,7 +151,7 @@ void tst_QStackedLayout::testCase() QStackedLayout onStack(testWidget); QStackedLayout *testLayout = &onStack; testWidget->setLayout(testLayout); - + QSignalSpy spy(testLayout,SIGNAL(currentChanged(int))); // Nothing in layout @@ -350,12 +352,15 @@ void tst_QStackedLayout::keepFocusAfterSetCurrent() stackLayout->setCurrentIndex(0); + testWidget->show(); + QTest::qWait(25); + QApplication::setActiveWindow(testWidget); + edit1->setFocus(); - QTest::qWait(250); edit1->activateWindow(); - QTest::qWait(100); + QTest::qWait(25); - QVERIFY(edit1->hasFocus()); + QTRY_VERIFY(edit1->hasFocus()); stackLayout->setCurrentIndex(1); QVERIFY(!edit1->hasFocus()); diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp index 6fe2963..51d0e33 100644 --- a/tests/auto/qtableview/tst_qtableview.cpp +++ b/tests/auto/qtableview/tst_qtableview.cpp @@ -2334,8 +2334,10 @@ void tst_QTableView::scrollTo() QtTestTableView view; view.show(); - view.resize(columnWidth * 2, rowHeight * 2); + QSize forcedSize(columnWidth * 2, rowHeight * 2); + view.resize(forcedSize); QTest::qWait(0); + QTRY_COMPARE(view.size(), forcedSize); view.setModel(&model); view.setSpan(row, column, rowSpan, columnSpan); @@ -2910,6 +2912,7 @@ void tst_QTableView::tabFocus() window.setFocus(); QTest::qWait(100); window.activateWindow(); + QApplication::setActiveWindow(&window); QTest::qWait(100); qApp->processEvents(); @@ -2926,43 +2929,43 @@ void tst_QTableView::tabFocus() for (int i = 0; i < 2; ++i) { // tab to view QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); - QVERIFY(!window.hasFocus()); + QTRY_VERIFY(!window.hasFocus()); QVERIFY(view->hasFocus()); QVERIFY(!edit->hasFocus()); // tab to edit QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); + QTRY_VERIFY(edit->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!view->hasFocus()); - QVERIFY(edit->hasFocus()); } // backtab to view QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTRY_VERIFY(view->hasFocus()); QVERIFY(!window.hasFocus()); - QVERIFY(view->hasFocus()); QVERIFY(!edit->hasFocus()); // backtab to edit QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTRY_VERIFY(edit->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!view->hasFocus()); - QVERIFY(edit->hasFocus()); QStandardItemModel *model = new QStandardItemModel; view->setModel(model); // backtab to view QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTRY_VERIFY(view->hasFocus()); QVERIFY(!window.hasFocus()); - QVERIFY(view->hasFocus()); QVERIFY(!edit->hasFocus()); // backtab to edit QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTRY_VERIFY(edit->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!view->hasFocus()); - QVERIFY(edit->hasFocus()); model->insertRow(0, new QStandardItem("Hei")); model->insertRow(0, new QStandardItem("Hei")); @@ -2970,8 +2973,8 @@ void tst_QTableView::tabFocus() // backtab to view QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTRY_VERIFY(view->hasFocus()); QVERIFY(!window.hasFocus()); - QVERIFY(view->hasFocus()); QVERIFY(!edit->hasFocus()); // backtab to edit doesn't work @@ -2984,14 +2987,14 @@ void tst_QTableView::tabFocus() // backtab to edit QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTRY_VERIFY(edit->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!view->hasFocus()); - QVERIFY(edit->hasFocus()); QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); - QVERIFY(view->hasFocus()); + QTRY_VERIFY(view->hasFocus()); QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); - QVERIFY(edit->hasFocus()); + QTRY_VERIFY(edit->hasFocus()); delete model; } diff --git a/tests/auto/qtextbrowser/tst_qtextbrowser.cpp b/tests/auto/qtextbrowser/tst_qtextbrowser.cpp index 0311900..966e9c9 100644 --- a/tests/auto/qtextbrowser/tst_qtextbrowser.cpp +++ b/tests/auto/qtextbrowser/tst_qtextbrowser.cpp @@ -49,6 +49,8 @@ #include #include +#include "../../shared/util.h" + //TESTED_CLASS= //TESTED_FILES= @@ -64,9 +66,11 @@ public: #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(this); #endif + QApplication::setActiveWindow(this); activateWindow(); setFocus(); - QTest::qWait(100); + QTest::qWait(50); + QTRY_VERIFY(hasFocus()); } virtual QVariant loadResource(int type, const QUrl &name); diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index fae4b26..f42d5f6 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -3354,7 +3354,7 @@ void tst_QTreeView::task246536_scrollbarsNotWorking() o.count = 0; tree.verticalScrollBar()->setValue(50); QTest::qWait(100); - QVERIFY(o.count > 0); + QTRY_VERIFY(o.count > 0); } void tst_QTreeView::task250683_wrongSectionSize() @@ -3404,8 +3404,9 @@ void tst_QTreeView::task239271_addRowsWithFirstColumnHidden() QStandardItem sub1("sub1"), sub11("sub11"); root0.appendRow(QList() << &sub1 << &sub11); - QTest::qWait(200); + QTest::qWait(20); //items in the 2nd column should have been painted + QTRY_VERIFY(!delegate.paintedIndexes.isEmpty()); QVERIFY(delegate.paintedIndexes.contains(sub00.index())); QVERIFY(delegate.paintedIndexes.contains(sub11.index())); } -- cgit v0.12 From 8a12dd9ab4cb026591a6d9672d147ec4eb54a651 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 8 Sep 2009 10:48:36 +0200 Subject: Fix crash on QGraphicsItem destruction related to focus handling (redone) Reset the dangling subFocusItem pointer in ~QGraphicsItem, after all the child items have been deleted. This replaces commit d724c91a0ae. Reviewed-by: Thomas Hartmann --- src/gui/graphicsview/qgraphicsitem.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 8bd3648..73ea75e 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -930,7 +930,7 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent) } QGraphicsItem *lastSubFocusItem = subFocusItem; - if (subFocusItem && !inDestructor) { + if (subFocusItem) { // Update the child focus chain; when reparenting an item that has a // focus child, ensure that that focus child clears its focus child // chain from our parents before it's reparented. @@ -1204,6 +1204,8 @@ QGraphicsItem::~QGraphicsItem() Q_ASSERT(d_ptr->children.isEmpty()); } + d_ptr->subFocusItem = 0; + if (d_ptr->scene) { d_ptr->scene->d_func()->removeItemHelper(this); } else { -- cgit v0.12 From 914e331be160347a031cef131ac1cbc0a6787be0 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 8 Sep 2009 11:24:14 +0200 Subject: Compilefix for win32 Reviewed-by: Kai Koehne --- src/declarative/qml/qmetaobjectbuilder_p.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/declarative/qml/qmetaobjectbuilder_p.h b/src/declarative/qml/qmetaobjectbuilder_p.h index d503163..c0b7426 100644 --- a/src/declarative/qml/qmetaobjectbuilder_p.h +++ b/src/declarative/qml/qmetaobjectbuilder_p.h @@ -68,7 +68,7 @@ class QMetaPropertyBuilderPrivate; class QMetaEnumBuilder; class QMetaEnumBuilderPrivate; -class Q_CORE_EXPORT QMetaObjectBuilder +class Q_DECLARATIVE_EXPORT QMetaObjectBuilder { public: enum AddMember @@ -189,7 +189,7 @@ private: friend class QMetaEnumBuilder; }; -class Q_CORE_EXPORT QMetaMethodBuilder +class Q_DECLARATIVE_EXPORT QMetaMethodBuilder { public: QMetaMethodBuilder() : _mobj(0), _index(0) {} @@ -227,7 +227,7 @@ private: QMetaMethodBuilderPrivate *d_func() const; }; -class Q_CORE_EXPORT QMetaPropertyBuilder +class Q_DECLARATIVE_EXPORT QMetaPropertyBuilder { public: QMetaPropertyBuilder() : _mobj(0), _index(0) {} @@ -278,7 +278,7 @@ private: QMetaPropertyBuilderPrivate *d_func() const; }; -class Q_CORE_EXPORT QMetaEnumBuilder +class Q_DECLARATIVE_EXPORT QMetaEnumBuilder { public: QMetaEnumBuilder() : _mobj(0), _index(0) {} -- cgit v0.12 From 2075cb4fc05dc077db1bb9437dd0fcf75605fe9c Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Tue, 8 Sep 2009 12:31:10 +0200 Subject: doc: Fixed several qdoc errors. That's the last of them... for now. --- doc/src/frameworks-technologies/gestures.qdoc | 8 ++++---- src/gui/kernel/qstandardgestures.cpp | 6 ++++++ src/gui/painting/qpaintengine.cpp | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/doc/src/frameworks-technologies/gestures.qdoc b/doc/src/frameworks-technologies/gestures.qdoc index 317bb31..7929331 100644 --- a/doc/src/frameworks-technologies/gestures.qdoc +++ b/doc/src/frameworks-technologies/gestures.qdoc @@ -81,7 +81,7 @@ \table \header \o New State \o Description \o QGesture Actions on Entering this State - \row \o Qt::NoGesture \o Initial value \o emit \l {QGesture::cancelled()}{cancelled()} + \row \o Qt::NoGesture \o Initial value \o emit \l {QGesture::canceled()}{canceled()} \row \o Qt::GestureStarted \o A continuous gesture has started \o emit \l{QGesture::started()}{started()} and emit \l{QGesture::triggered()}{triggered()} \row \o Qt::GestureUpdated \o A gesture continues \o emit \l{QGesture::triggered()}{triggered()} \row \o Qt::GestureFinished \o A gesture has finished. \o emit \l{QGesture::finished()}{finished()} @@ -130,13 +130,13 @@ then the gesture is considered to have finished whether or not the appropriate touch or mouse event has occurred. Also if a large jump in the position of the event occurs, as calculated by the \l {QPoint::manhattanLength()}{manhattanLength()} - call, then the gesture is cancelled by calling \l{QGesture::reset()}{reset()} + call, then the gesture is canceled by calling \l{QGesture::reset()}{reset()} which tidies up and uses \l{QGesture::updateState()}{updateState()} to - change state to NoGesture which will result in the \l{QGesture::cancelled()}{cancelled()} + change state to NoGesture which will result in the \l{QGesture::canceled()}{canceled()} signal being emitted by the recognizer. ImageWidget handles the signals by connecting the slots to the signals, - although \c cancelled() is not connected here. + although \c canceled() is not connected here. \snippet doc/src/snippets/gestures/imageviewer/imagewidget.cpp imagewidget-connect diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index 8e76715..b3e137d 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -535,6 +535,12 @@ void QPinchGesture::reset() QGesture::reset(); } +/*! \enum QPinchGesture::WhatChange + \value ScaleFactorChanged + \value RotationAngleChanged + \value CenterPointChanged +*/ + /*! \property QPinchGesture::whatChanged diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp index f442788..42da637 100644 --- a/src/gui/painting/qpaintengine.cpp +++ b/src/gui/painting/qpaintengine.cpp @@ -386,6 +386,7 @@ void QPaintEngine::drawPolygon(const QPoint *points, int pointCount, PolygonDraw \value User First user type ID \value MaxUser Last user type ID \value OpenGL2 + \value PaintBuffer */ /*! -- cgit v0.12 From 9a90fcca3e9a9a49cee228054017ff7d15645082 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Thu, 3 Sep 2009 13:41:19 +0200 Subject: Animations of redocking widgets are broken The problem is that when starting an animation, we delay it by starting a 0-timer. That doesn't work on windows while dragging a native window. Task-number: 260772 Reviewed-by: prasanth --- src/corelib/animation/qabstractanimation.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index e1b8509..31f0841 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -157,6 +157,19 @@ #define DEFAULT_TIMER_INTERVAL 16 +#ifdef Q_WS_WIN + /// Fix for Qt 4.7 + //on windows if you're currently dragging a widget an inner eventloop was started by the system + //to make sure that this timer is getting fired, we need to make sure to use the system timers + //that will send a WM_TIMER event. We do that by settings the timer interval to 11 + //It is 11 because QEventDispatcherWin32Private::registerTimer specifically checks if the interval + //is greater than 10 to determine if it should use a system timer (or the multimedia timer). +#define STARTSTOP_TIMER_DELAY 11 +#else +#define STARTSTOP_TIMER_DELAY 0 +#endif + + QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QThreadStorage, unifiedTimer) @@ -217,7 +230,7 @@ void QUnifiedTimer::registerAnimation(QAbstractAnimation *animation) if (animations.contains(animation) || animationsToStart.contains(animation)) return; animationsToStart << animation; - startStopAnimationTimer.start(0, this); // we delay the check if we should start/stop the global timer + startStopAnimationTimer.start(STARTSTOP_TIMER_DELAY, this); // we delay the check if we should start/stop the global timer } void QUnifiedTimer::unregisterAnimation(QAbstractAnimation *animation) @@ -233,7 +246,7 @@ void QUnifiedTimer::unregisterAnimation(QAbstractAnimation *animation) } else { animationsToStart.removeOne(animation); } - startStopAnimationTimer.start(0, this); // we delay the check if we should start/stop the global timer + startStopAnimationTimer.start(STARTSTOP_TIMER_DELAY, this); // we delay the check if we should start/stop the global timer } -- cgit v0.12 From 9d9b7f53750dce2da88d7d11d312b4b36250b5c5 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 8 Sep 2009 12:59:44 +0200 Subject: Fixes a regression in QListView in 4.6 regarding the selection In icon mode, if you click on the viewport (with extended selection), the selection should be cleared when you release the mouse button. Reviewed-by: ogoffart --- src/gui/itemviews/qabstractitemview.cpp | 4 ++++ tests/auto/qlistview/tst_qlistview.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 52529ff..99e9aeb 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -1661,6 +1661,10 @@ void QAbstractItemView::mouseReleaseEvent(QMouseEvent *event) EditTrigger trigger = (selectedClicked ? SelectedClicked : NoEditTriggers); bool edited = edit(index, trigger, event); + //in the case the user presses on no item we might decide to clear the selection + if (d->selectionModel && !index.isValid()) + d->selectionModel->select(QModelIndex(), selectionCommand(index, event)); + setState(NoState); if (click) { diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp index 2be1a03..2831747 100644 --- a/tests/auto/qlistview/tst_qlistview.cpp +++ b/tests/auto/qlistview/tst_qlistview.cpp @@ -113,6 +113,7 @@ private slots: void task254449_draggingItemToNegativeCoordinates(); void keyboardSearch(); void shiftSelectionWithNonUniformItemSizes(); + void clickOnViewportClearsSelection(); }; // Testing get/set functions @@ -1733,5 +1734,34 @@ void tst_QListView::shiftSelectionWithNonUniformItemSizes() } } +void tst_QListView::clickOnViewportClearsSelection() +{ + QStringList items; + items << "Text1"; + QStringListModel model(items); + QListView view; + view.setModel(&model); + view.setSelectionMode(QListView::ExtendedSelection); + + view.selectAll(); + QModelIndex index = model.index(0); + QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1); + QVERIFY(view.selectionModel()->isSelected(index)); + + //we try to click outside of the index + const QPoint point = view.visualRect(index).bottomRight() + QPoint(10,10); + + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, point); + //at this point, the selection shouldn't have changed + QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1); + QVERIFY(view.selectionModel()->isSelected(index)); + + QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, point); + //now the selection should be cleared + QVERIFY(!view.selectionModel()->hasSelection()); + +} + + QTEST_MAIN(tst_QListView) #include "tst_qlistview.moc" -- cgit v0.12 From a9572a07f1512fe1266629632e5c4f1613abeb8d Mon Sep 17 00:00:00 2001 From: Adriano Rezende Date: Tue, 8 Sep 2009 13:15:49 +0200 Subject: Fixed QLineEdit to correctly adjust the horizontal scrolling The widget needs to use the naturalTextWidth to adjust the horizontal scrolling, otherwise it will not fit correctly the text in the visible area when resized. Merge-request: 1410 Reviewed-by: Alan Alpert --- src/gui/widgets/qlinecontrol_p.h | 6 ++++++ src/gui/widgets/qlineedit.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qlinecontrol_p.h b/src/gui/widgets/qlinecontrol_p.h index a81f138..f46abf1 100644 --- a/src/gui/widgets/qlinecontrol_p.h +++ b/src/gui/widgets/qlinecontrol_p.h @@ -109,6 +109,7 @@ public: int width() const; int height() const; int ascent() const; + qreal naturalTextWidth() const; void setSelection(int start, int length); @@ -410,6 +411,11 @@ inline int QLineControl::width() const return qRound(m_textLayout.lineAt(0).width()) + 1; } +inline qreal QLineControl::naturalTextWidth() const +{ + return m_textLayout.lineAt(0).naturalTextWidth(); +} + inline int QLineControl::height() const { return qRound(m_textLayout.lineAt(0).height()) + 1; diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp index 3065c7f..9571860 100644 --- a/src/gui/widgets/qlineedit.cpp +++ b/src/gui/widgets/qlineedit.cpp @@ -1808,7 +1808,7 @@ void QLineEdit::paintEvent(QPaintEvent *) // (cix). int minLB = qMax(0, -fm.minLeftBearing()); int minRB = qMax(0, -fm.minRightBearing()); - int widthUsed = d->control->width() + minRB; + int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB; if ((minLB + widthUsed) <= lineRect.width()) { // text fits in lineRect; use hscroll for alignment switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) { -- cgit v0.12 From 0399ace27c7441b4454911da3aaa4ea17b931b99 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 8 Sep 2009 21:36:42 +1000 Subject: Add license header. Reviewed-by: Trust Me --- .../src_corelib_statemachine_qstatemachine.cpp | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp b/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp index 128799f..8933ef3 100644 --- a/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp +++ b/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** 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 test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the 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$ +** +****************************************************************************/ + //! [simple state machine] QPushButton button; -- cgit v0.12 From beea786c9d1362b1fb12fdff209b842e21ef9cf8 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 8 Sep 2009 14:45:09 +0300 Subject: Fixed resolving absolute paths in Symbian. Fixed resolving absolute path using QFileInfo for paths that were relative but contained the drive letter (e.g. "c:my.dll"). Absolute paths should now be properly cleaned in Symbian, too. Task-number: 255326 Reviewed-by: Janne Anttila --- src/corelib/io/qfsfileengine_unix.cpp | 23 ++++++++++++++++++----- tests/auto/qfileinfo/tst_qfileinfo.cpp | 14 +++++++++++--- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 50b4af7..80ccda3 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -865,15 +865,22 @@ QString QFSFileEngine::fileName(FileName file) const QString ret; if (!isRelativePathSymbian(d->filePath)) { if (d->filePath.size() > 2 && d->filePath.at(1) == QLatin1Char(':') - && d->filePath.at(2) != slashChar || // It's a drive-relative path, so Z:a.txt -> Z:\currentpath\a.txt - d->filePath.startsWith(slashChar) // It's a absolute path to the current drive, so \a.txt -> Z:\a.txt - ) { - ret = QString(QDir::currentPath().left(2) + QDir::fromNativeSeparators(d->filePath)); + && d->filePath.at(2) != slashChar){ + // It's a drive-relative path, so C:a.txt -> C:/currentpath/a.txt, + // or if it's different drive than current, Z:a.txt -> Z:/a.txt + QString currentPath = QDir::currentPath(); + if (0 == currentPath.left(1).compare(d->filePath.left(1), Qt::CaseInsensitive)) + ret = currentPath + slashChar + d->filePath.mid(2); + else + ret = d->filePath.left(2) + slashChar + d->filePath.mid(2); + } else if (d->filePath.startsWith(slashChar)) { + // It's a absolute path to the current drive, so /a.txt -> C:/a.txt + ret = QDir::currentPath().left(2) + d->filePath; } else { ret = d->filePath; } } else { - ret = QDir::cleanPath(QDir::currentPath() + slashChar + d->filePath); + ret = QDir::currentPath() + slashChar + d->filePath; } // The path should be absolute at this point. @@ -889,6 +896,12 @@ QString QFSFileEngine::fileName(FileName file) const ret[0] = ret.at(0).toUpper(); } + // Clean up the path + bool isDir = ret.endsWith(slashChar); + ret = QDir::cleanPath(ret); + if (isDir) + ret += slashChar; + if (file == AbsolutePathName) { int slash = ret.lastIndexOf(slashChar); if (slash < 0) diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp index d951a86..076934c 100644 --- a/tests/auto/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp @@ -411,6 +411,10 @@ void tst_QFileInfo::absolutePath_data() QString drivePrefix; #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) drivePrefix = QDir::currentPath().left(2); + + // Make sure drive-relative paths return correct absolute paths (task 255326) + QTest::newRow("c:my.dll") << "c:my.dll" << QDir::currentPath() << "my.dll"; + QTest::newRow("x:my.dll") << "x:my.dll" << "X:/" << "my.dll"; #endif QTest::newRow("0") << "/machine/share/dir1/" << drivePrefix + "/machine/share/dir1" << ""; QTest::newRow("1") << "/machine/share/dir1" << drivePrefix + "/machine/share" << "dir1"; @@ -449,6 +453,10 @@ void tst_QFileInfo::absFilePath_data() curr.remove(0, 2); // Make it a absolute path with no drive specifier: \depot\qt-4.2\tests\auto\qfileinfo QTest::newRow(".") << curr << QDir::currentPath(); QTest::newRow("absFilePath") << "c:\\home\\andy\\tmp.txt" << "C:/home/andy/tmp.txt"; + + // Make sure drive-relative paths return correct absolute paths (task 255326) + QTest::newRow("c:my.dll") << "c:temp/my.dll" << QDir::currentPath() + "/temp/my.dll"; + QTest::newRow("x:my.dll") << "x:temp/my.dll" << "X:/temp/my.dll"; #else QTest::newRow("absFilePath") << "/home/andy/tmp.txt" << "/home/andy/tmp.txt"; #endif @@ -1052,19 +1060,19 @@ void tst_QFileInfo::isHidden_data() QFile file(hiddenFileName); if (file.open(QIODevice::WriteOnly)) { QTextStream t(&file); - t << "foobar"; + t << "foobar"; } else { qWarning("Failed to create hidden file"); } QFile file2(notHiddenFileName); if (file2.open(QIODevice::WriteOnly)) { QTextStream t(&file); - t << "foobar"; + t << "foobar"; } else { qWarning("Failed to create non-hidden file"); } } - + RFs rfs; TInt err = rfs.Connect(); if (err == KErrNone) { -- cgit v0.12 From 039e178ae3dff6761627de9b3fa790a64afb7bee Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 8 Sep 2009 13:49:01 +0200 Subject: Make tst_qmdiarea more robust --- tests/auto/qmdiarea/tst_qmdiarea.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/auto/qmdiarea/tst_qmdiarea.cpp b/tests/auto/qmdiarea/tst_qmdiarea.cpp index 65dab48..246410d 100644 --- a/tests/auto/qmdiarea/tst_qmdiarea.cpp +++ b/tests/auto/qmdiarea/tst_qmdiarea.cpp @@ -62,6 +62,8 @@ #endif #include +#include "../../shared/util.h" + static const Qt::WindowFlags DefaultWindowFlags = Qt::SubWindow | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint; @@ -467,7 +469,7 @@ void tst_QMdiArea::subWindowActivated2() qt_x11_wait_for_window_manager(&mdiArea); #endif - QCOMPARE(spy.count(), 5); + QTRY_COMPARE(spy.count(), 5); QCOMPARE(mdiArea.activeSubWindow(), mdiArea.subWindowList().back()); spy.clear(); @@ -493,7 +495,7 @@ void tst_QMdiArea::subWindowActivated2() qt_x11_wait_for_window_manager(&mdiArea); #endif QTest::qWait(100); - QCOMPARE(spy.count(), 1); + QTRY_COMPARE(spy.count(), 1); QVERIFY(!mdiArea.activeSubWindow()); QCOMPARE(mdiArea.currentSubWindow(), activeSubWindow); spy.clear(); @@ -503,7 +505,7 @@ void tst_QMdiArea::subWindowActivated2() qt_x11_wait_for_window_manager(&mdiArea); #endif QTest::qWait(100); - QCOMPARE(spy.count(), 1); + QTRY_COMPARE(spy.count(), 1); QCOMPARE(mdiArea.activeSubWindow(), activeSubWindow); spy.clear(); @@ -516,14 +518,14 @@ void tst_QMdiArea::subWindowActivated2() if (!macHasAccessToWindowsServer()) QEXPECT_FAIL("", "showMinimized doesn't really minimize if you don't have access to the server", Abort); #endif - QTest::qWait(100); + QTest::qWait(10); #if defined(Q_WS_QWS) QEXPECT_FAIL("", "task 168682", Abort); #endif #ifdef Q_OS_WINCE QSKIP("Not fixed yet. See Task 197453", SkipAll); #endif - QCOMPARE(spy.count(), 1); + QTRY_COMPARE(spy.count(), 1); QVERIFY(!mdiArea.activeSubWindow()); QCOMPARE(mdiArea.currentSubWindow(), activeSubWindow); spy.clear(); @@ -533,7 +535,7 @@ void tst_QMdiArea::subWindowActivated2() qt_x11_wait_for_window_manager(&mdiArea); #endif QTest::qWait(100); - QCOMPARE(spy.count(), 1); + QTRY_COMPARE(spy.count(), 1); QCOMPARE(mdiArea.activeSubWindow(), activeSubWindow); spy.clear(); } @@ -1734,6 +1736,7 @@ void tst_QMdiArea::tileSubWindows() qt_x11_wait_for_window_manager(&workspace); #endif qApp->processEvents(); + QTRY_COMPARE(workspace.size(), QSize(350, 150)); const QSize minSize(300, 100); foreach (QMdiSubWindow *subWindow, workspace.subWindowList()) @@ -1885,7 +1888,7 @@ void tst_QMdiArea::resizeMaximizedChildWindows() workspace.resize(workspaceSize + QSize(increment, increment)); QTest::qWait(100); qApp->processEvents(); - QCOMPARE(workspace.size(), workspaceSize + QSize(increment, increment)); + QTRY_COMPARE(workspace.size(), workspaceSize + QSize(increment, increment)); QCOMPARE(window->size(), windowSize + QSize(increment, increment)); workspaceSize = workspace.size(); } -- cgit v0.12 From 89982a2c1678f2c42c9abf1021b35ed45004278c Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 8 Sep 2009 13:48:13 +0200 Subject: fix major memory leak in JavaScriptCore RegisterFile on Windows CE On Widows CE we must decommit all committed pages before we release them. See VirtualFree documentation. Desktop Windows behaves much smoother in this situation. Reviewed-by: ariya --- src/3rdparty/webkit/JavaScriptCore/interpreter/RegisterFile.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/3rdparty/webkit/JavaScriptCore/interpreter/RegisterFile.cpp b/src/3rdparty/webkit/JavaScriptCore/interpreter/RegisterFile.cpp index 29a13ca..de5175e 100644 --- a/src/3rdparty/webkit/JavaScriptCore/interpreter/RegisterFile.cpp +++ b/src/3rdparty/webkit/JavaScriptCore/interpreter/RegisterFile.cpp @@ -36,6 +36,9 @@ RegisterFile::~RegisterFile() #if HAVE(MMAP) munmap(reinterpret_cast(m_buffer), ((m_max - m_start) + m_maxGlobals) * sizeof(Register)); #elif HAVE(VIRTUALALLOC) +#if PLATFORM(WINCE) + VirtualFree(m_buffer, DWORD(m_commitEnd) - DWORD(m_buffer), MEM_DECOMMIT); +#endif VirtualFree(m_buffer, 0, MEM_RELEASE); #else fastFree(m_buffer); -- cgit v0.12 From b8e6f86ed8b27504f22da2167cb6aa9ecf829a71 Mon Sep 17 00:00:00 2001 From: Jedrzej Nowacki Date: Tue, 8 Sep 2009 14:03:05 +0200 Subject: QScriptDebuggerBackend crash fix. QScriptDebuggerBackend::contextCount() method was trying to count number of context push & pop and result was not equal to elements count in QScriptDebuggerBackend::contextIds() list. Patch change QScriptDebuggerBackend::contextCount() to call count() on ids list. Task-number: 260719 Reviewed-by: Kent Hansen --- src/scripttools/debugging/qscriptdebuggerbackend.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/scripttools/debugging/qscriptdebuggerbackend.cpp b/src/scripttools/debugging/qscriptdebuggerbackend.cpp index 2efff04..feaea63 100644 --- a/src/scripttools/debugging/qscriptdebuggerbackend.cpp +++ b/src/scripttools/debugging/qscriptdebuggerbackend.cpp @@ -805,13 +805,7 @@ int QScriptDebuggerBackend::contextCount() const { if (!engine()) return 0; - int count = 0; - QScriptContext *ctx = engine()->currentContext(); - while (ctx) { - ++count; - ctx = ctx->parentContext(); - } - return count; + return contextIds().count(); } /*! -- cgit v0.12 From 512a265f760c9207b94d7ba61cef9316b23cf4e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Tue, 8 Sep 2009 14:32:30 +0200 Subject: Added a public function to enforce usage og the old GL engine. Some applications that uses a mix of OpenGL and QPainter code may not work correctly with the new GL 2 engine (e.g. the composition demo). The same is most likely also true for user apps, therefore we need a way to enforce the usage of the old GL 1 engine for the sake of compatibility. Task-number: 260872 Reviewed-by: Samuel --- demos/composition/main.cpp | 6 ++++ dist/changes-4.6.0 | 11 ++++++-- src/opengl/qgl.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++ src/opengl/qgl.h | 3 ++ src/opengl/qgl_p.h | 10 +------ 5 files changed, 87 insertions(+), 11 deletions(-) diff --git a/demos/composition/main.cpp b/demos/composition/main.cpp index 3a959a9..fe142ad 100644 --- a/demos/composition/main.cpp +++ b/demos/composition/main.cpp @@ -42,11 +42,17 @@ #include "composition.h" #include +#ifdef QT_OPENGL_SUPPORT +#include +#endif int main(int argc, char **argv) { // Q_INIT_RESOURCE(deform); +#ifdef QT_OPENGL_SUPPORT + QGL::setPreferredPaintEngine(QPaintEngine::OpenGL); +#endif QApplication app(argc, argv); CompositionWidget compWidget(0); diff --git a/dist/changes-4.6.0 b/dist/changes-4.6.0 index ca984ac..f9984d3 100644 --- a/dist/changes-4.6.0 +++ b/dist/changes-4.6.0 @@ -54,8 +54,15 @@ information about a particular change. this is that Nokia focuses on OpenGL for desktop hardware accelerated rendering. - - When mixing OpenGL and QPainter calls you need to surround your custom - OpenGL calls with QPainter::beginNativePainting() and + - The default engine used to draw onto OpenGL buffers has changed in + Qt 4.6. The QPaintEngine::OpenGL2 engine is now used as the default + engine. This *may* cause compatibility problems for applications + that use a mix of QPainter and native OpenGL calls to draw into a GL + buffer. Use the QGL::setPreferredPaintEngine() function to enforce + usage of the old GL paint engine. + + - When mixing OpenGL and QPainter calls you need to surround your + custom OpenGL calls with QPainter::beginNativePainting() and QPainter::endNativePainting(). This is to ensure that the paint engine flushes any pending drawing and sets up the GL modelview/projection matrices properly before you can issue custom diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 087902b..02bb8f9 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -141,6 +141,48 @@ QGLSignalProxy *QGLSignalProxy::instance() return theSignalProxy(); } + +class QGLEngineSelector +{ +public: + QGLEngineSelector() : engineType(QPaintEngine::MaxUser) { } + + void setPreferredPaintEngine(QPaintEngine::Type type) { + if (type == QPaintEngine::OpenGL || type == QPaintEngine::OpenGL2) + engineType = type; + } + + QPaintEngine::Type preferredPaintEngine() { + if (engineType == QPaintEngine::MaxUser) { + // No user-set engine - use the defaults +#if defined(QT_OPENGL_ES_2) + engineType = QPaintEngine::OpenGL2; +#else + // We can't do this in the constructor for this object because it + // needs to be called *before* the QApplication constructor + if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0) + && qgetenv("QT_GL_USE_OPENGL1ENGINE").isEmpty()) + engineType = QPaintEngine::OpenGL2; + else + engineType = QPaintEngine::OpenGL; +#endif + } + return engineType; + } + +private: + QPaintEngine::Type engineType; +}; + +Q_GLOBAL_STATIC(QGLEngineSelector, qgl_engine_selector) + + +bool qt_gl_preferGL2Engine() +{ + return qgl_engine_selector()->preferredPaintEngine() == QPaintEngine::OpenGL2; +} + + /*! \namespace QGL \inmodule QtOpenGL @@ -181,6 +223,32 @@ QGLSignalProxy *QGLSignalProxy::instance() \sa {Sample Buffers Example} */ +/*! + \fn void QGL::setPreferredPaintEngine(QPaintEngine::Type engineType) + + \since 4.6 + + Sets the preferred OpenGL paint engine that is used to draw onto + QGLWidgets, QGLPixelBuffers and QGLFrameBufferObjects with QPainter + in Qt. + + The \a engineType parameter specifies which of the GL engines to + use. Only \c QPaintEngine::OpenGL and \c QPaintEngine::OpenGL2 are + valid parameters to this function. All other values are ignored. + + By default, the \c QPaintEngine::OpenGL2 engine is used if GL/GLES + version 2.0 is available, otherwise \c QPaintEngine::OpenGL is + used. + + \warning This function must be called before the QApplication + constructor is called. +*/ +void QGL::setPreferredPaintEngine(QPaintEngine::Type engineType) +{ + qgl_engine_selector()->setPreferredPaintEngine(engineType); +} + + /***************************************************************************** QGLFormat implementation *****************************************************************************/ diff --git a/src/opengl/qgl.h b/src/opengl/qgl.h index daac760..b110665 100644 --- a/src/opengl/qgl.h +++ b/src/opengl/qgl.h @@ -43,6 +43,7 @@ #define QGL_H #include +#include #include #include #include @@ -130,6 +131,8 @@ class QGLContextPrivate; // Namespace class: namespace QGL { + Q_OPENGL_EXPORT void setPreferredPaintEngine(QPaintEngine::Type engineType); + enum FormatOption { DoubleBuffer = 0x0001, DepthBuffer = 0x0002, diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index d4b7597..f8158a0 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -519,15 +519,7 @@ extern QPaintEngine* qt_qgl_paint_engine(); extern EGLDisplay qt_qgl_egl_display(); #endif -inline bool qt_gl_preferGL2Engine() -{ -#if defined(QT_OPENGL_ES_2) - return true; -#else - return (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0) - && qgetenv("QT_GL_USE_OPENGL1ENGINE").isEmpty(); -#endif -} +bool qt_gl_preferGL2Engine(); inline GLenum qt_gl_preferredTextureFormat() { -- cgit v0.12 From 20a61e1cf39ee66cf0880c6f8f36634115cf610e Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Tue, 8 Sep 2009 14:35:42 +0200 Subject: Fix QWS autotests after S60 integration Reviewed-by: trustme --- tests/auto/qmultiscreen/qmultiscreen.pro | 1 - tests/auto/qtransformedscreen/qtransformedscreen.pro | 1 - tests/auto/qwsembedwidget/qwsembedwidget.pro | 1 - tests/auto/qwsinputmethod/qwsinputmethod.pro | 1 - tests/auto/qwswindowsystem/qwswindowsystem.pro | 1 - 5 files changed, 5 deletions(-) diff --git a/tests/auto/qmultiscreen/qmultiscreen.pro b/tests/auto/qmultiscreen/qmultiscreen.pro index 4e92a65..30666d7 100644 --- a/tests/auto/qmultiscreen/qmultiscreen.pro +++ b/tests/auto/qmultiscreen/qmultiscreen.pro @@ -1,6 +1,5 @@ load(qttest_p4) SOURCES += tst_qmultiscreen.cpp -QT = core requires(embedded) diff --git a/tests/auto/qtransformedscreen/qtransformedscreen.pro b/tests/auto/qtransformedscreen/qtransformedscreen.pro index 39e3700..6914054 100644 --- a/tests/auto/qtransformedscreen/qtransformedscreen.pro +++ b/tests/auto/qtransformedscreen/qtransformedscreen.pro @@ -1,6 +1,5 @@ load(qttest_p4) SOURCES += tst_qtransformedscreen.cpp -QT = core embedded:!contains(gfx-drivers, transformed) { LIBS += ../../../plugins/gfxdrivers/libqgfxtransformed.so diff --git a/tests/auto/qwsembedwidget/qwsembedwidget.pro b/tests/auto/qwsembedwidget/qwsembedwidget.pro index bd3c32c..c34212b 100644 --- a/tests/auto/qwsembedwidget/qwsembedwidget.pro +++ b/tests/auto/qwsembedwidget/qwsembedwidget.pro @@ -1,3 +1,2 @@ load(qttest_p4) SOURCES += tst_qwsembedwidget.cpp -QT = core diff --git a/tests/auto/qwsinputmethod/qwsinputmethod.pro b/tests/auto/qwsinputmethod/qwsinputmethod.pro index 69cce78..d549de0 100644 --- a/tests/auto/qwsinputmethod/qwsinputmethod.pro +++ b/tests/auto/qwsinputmethod/qwsinputmethod.pro @@ -1,3 +1,2 @@ load(qttest_p4) SOURCES += tst_qwsinputmethod.cpp -QT = core diff --git a/tests/auto/qwswindowsystem/qwswindowsystem.pro b/tests/auto/qwswindowsystem/qwswindowsystem.pro index 49466ee..ee33935 100644 --- a/tests/auto/qwswindowsystem/qwswindowsystem.pro +++ b/tests/auto/qwswindowsystem/qwswindowsystem.pro @@ -1,3 +1,2 @@ load(qttest_p4) SOURCES += tst_qwswindowsystem.cpp -QT = core -- cgit v0.12 From 69e5a3fce4d355822367dc1a17179a364111632e Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Tue, 8 Sep 2009 15:00:35 +0200 Subject: network-settings.h: Compile fix relating to some tests Reviewed-by: TrustMe --- tests/auto/network-settings.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h index 6ffb6f4..40178fb 100644 --- a/tests/auto/network-settings.h +++ b/tests/auto/network-settings.h @@ -40,9 +40,7 @@ ****************************************************************************/ #include -#ifdef QT_NETWORK_LIB #include -#endif #ifdef Q_OS_SYMBIAN -- cgit v0.12 From 7c9dc76f67fd662077f3f28f3f9313e2a07987d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Tue, 8 Sep 2009 15:07:38 +0200 Subject: Fixed usage of QMargins in QStyleSheetStyle The order of the parameters to the QMargins constructor changed in commit 758f4735bcae034ac25730e53bb371df3b7d6e8a. Reviewed-by: Alessandro Portale --- src/gui/styles/qstylesheetstyle.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index 3d8dec6..b1fd415 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -1130,10 +1130,10 @@ void QRenderRule::drawBorderImage(QPainter *p, const QRect& rect) const QStyleSheetBorderImageData *borderImageData = border()->borderImage(); const int *targetBorders = border()->borders; const int *sourceBorders = borderImageData->cuts; - QMargins sourceMargins(sourceBorders[TopEdge], sourceBorders[LeftEdge], - sourceBorders[BottomEdge], sourceBorders[RightEdge]); - QMargins targetMargins(targetBorders[TopEdge], targetBorders[LeftEdge], - targetBorders[BottomEdge], targetBorders[RightEdge]); + QMargins sourceMargins(sourceBorders[LeftEdge], sourceBorders[TopEdge], + sourceBorders[RightEdge], sourceBorders[BottomEdge]); + QMargins targetMargins(targetBorders[LeftEdge], targetBorders[TopEdge], + targetBorders[RightEdge], targetBorders[BottomEdge]); bool wasSmoothPixmapTransform = p->renderHints() & QPainter::SmoothPixmapTransform; p->setRenderHint(QPainter::SmoothPixmapTransform); -- cgit v0.12 From 38b5e603ede02cfabba6ac845793cc4d28f484db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Tue, 8 Sep 2009 15:19:17 +0200 Subject: Doc: fixing a QFileInfo snippet type Task-number: 258371 --- doc/src/snippets/code/src_corelib_io_qfileinfo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp b/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp index f01757a..d2096cf 100644 --- a/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp +++ b/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp @@ -72,9 +72,9 @@ info1.size(); // returns 743 info1.symLinkTarget(); // returns "C:/Pretty++/untabify" QFileInfo info2(info1.symLinkTarget()); -info1.isSymLink(); // returns false -info1.absoluteFilePath(); // returns "C:/Pretty++/untabify" -info1.size(); // returns 63942 +info2.isSymLink(); // returns false +info2.absoluteFilePath(); // returns "C:/Pretty++/untabify" +info2.size(); // returns 63942 #endif //! [1] -- cgit v0.12 From 7731e5f7d33d3ec251299c7651e777d7e0054573 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 8 Sep 2009 15:43:43 +0200 Subject: Added an option to the lexer to tell the engine of all comments in a QML file. --- src/declarative/qml/parser/qmljs.g | 1 + src/declarative/qml/parser/qmljsastfwd_p.h | 4 ++-- src/declarative/qml/parser/qmljsengine_p.cpp | 6 ++++++ src/declarative/qml/parser/qmljsengine_p.h | 4 ++++ src/declarative/qml/parser/qmljslexer.cpp | 16 +++++++++++++--- src/declarative/qml/parser/qmljslexer_p.h | 3 ++- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/declarative/qml/parser/qmljs.g b/src/declarative/qml/parser/qmljs.g index b0ef866..4ed75e8 100644 --- a/src/declarative/qml/parser/qmljs.g +++ b/src/declarative/qml/parser/qmljs.g @@ -80,6 +80,7 @@ %token T_DEBUGGER "debugger" %token T_RESERVED_WORD "reserved word" %token T_MULTILINE_STRING_LITERAL "multiline string literal" +%token T_COMMENT "comment" --- context keywords. %token T_PUBLIC "public" diff --git a/src/declarative/qml/parser/qmljsastfwd_p.h b/src/declarative/qml/parser/qmljsastfwd_p.h index f79cfc2..a6fee1d 100644 --- a/src/declarative/qml/parser/qmljsastfwd_p.h +++ b/src/declarative/qml/parser/qmljsastfwd_p.h @@ -62,9 +62,9 @@ namespace QmlJS { namespace AST { class SourceLocation { public: - SourceLocation(quint32 offset = 0, quint32 length = 0) + SourceLocation(quint32 offset = 0, quint32 length = 0, quint32 line = 0, quint32 column = 0) : offset(offset), length(length), - startLine(0), startColumn(0) + startLine(line), startColumn(column) { } bool isValid() const { return length != 0; } diff --git a/src/declarative/qml/parser/qmljsengine_p.cpp b/src/declarative/qml/parser/qmljsengine_p.cpp index 02d9b9c..eab8944 100644 --- a/src/declarative/qml/parser/qmljsengine_p.cpp +++ b/src/declarative/qml/parser/qmljsengine_p.cpp @@ -178,6 +178,12 @@ Engine::~Engine() QSet Engine::literals() const { return _literals; } +void Engine::addComment(int pos, int len, int line, int col) +{ if (len > 0) _comments.append(QmlJS::AST::SourceLocation(pos, len, line, col)); } + +QList Engine::comments() const +{ return _comments; } + NameId *Engine::intern(const QChar *u, int s) { return const_cast(&*_literals.insert(NameId(u, s))); } diff --git a/src/declarative/qml/parser/qmljsengine_p.h b/src/declarative/qml/parser/qmljsengine_p.h index 5aea983..877fff2 100644 --- a/src/declarative/qml/parser/qmljsengine_p.h +++ b/src/declarative/qml/parser/qmljsengine_p.h @@ -143,6 +143,7 @@ class Engine Lexer *_lexer; NodePool *_nodePool; QSet _literals; + QList _comments; public: Engine(); @@ -150,6 +151,9 @@ public: QSet literals() const; + void addComment(int pos, int len, int line, int col); + QList comments() const; + NameId *intern(const QChar *u, int s); static QString toString(NameId *id); diff --git a/src/declarative/qml/parser/qmljslexer.cpp b/src/declarative/qml/parser/qmljslexer.cpp index 9da6ec0..3be1710 100644 --- a/src/declarative/qml/parser/qmljslexer.cpp +++ b/src/declarative/qml/parser/qmljslexer.cpp @@ -43,6 +43,8 @@ #include "config.h" #endif +#include + #include "qmljsengine_p.h" #include "qmljslexer_p.h" #include "qmljsgrammar_p.h" @@ -71,7 +73,7 @@ extern double integerFromString(const char *buf, int size, int radix); using namespace QmlJS; -Lexer::Lexer(Engine *eng) +Lexer::Lexer(Engine *eng, bool tokenizeComments) : driver(eng), yylineno(0), done(false), @@ -94,8 +96,9 @@ Lexer::Lexer(Engine *eng) check_reserved(true), parenthesesState(IgnoreParentheses), parenthesesCount(0), - prohibitAutomaticSemicolon(false) -{ + prohibitAutomaticSemicolon(false), + tokenizeComments(tokenizeComments) +{qDebug()<<"--- new lexer"; driver->setLexer(this); // allocate space for read buffers buffer8 = new char[size8]; @@ -647,22 +650,29 @@ int Lexer::lex() setDone(Other); } else state = Start; + qDebug() << "--- state is InSingleLineComment @" << startlineno << ":"<addComment(startpos, tokenLength(), startlineno, startcolumn); } else if (current == 0) { + driver->addComment(startpos, tokenLength(), startlineno, startcolumn); setDone(Eof); } + break; case InMultiLineComment: if (current == 0) { setDone(Bad); err = UnclosedComment; errmsg = QLatin1String("Unclosed comment at end of file"); + driver->addComment(startpos, tokenLength(), startlineno, startcolumn); } else if (isLineTerminator()) { shiftWindowsLineBreak(); yylineno++; } else if (current == '*' && next1 == '/') { state = Start; shift(1); + driver->addComment(startpos, tokenLength(), startlineno, startcolumn); } + break; case InIdentifier: if (isIdentLetter(current) || isDecimalDigit(current)) { diff --git a/src/declarative/qml/parser/qmljslexer_p.h b/src/declarative/qml/parser/qmljslexer_p.h index 5817868..6cca45d 100644 --- a/src/declarative/qml/parser/qmljslexer_p.h +++ b/src/declarative/qml/parser/qmljslexer_p.h @@ -67,7 +67,7 @@ class NameId; class Lexer { public: - Lexer(Engine *eng); + Lexer(Engine *eng, bool tokenizeComments = false); ~Lexer(); void setCode(const QString &c, int lineno); @@ -239,6 +239,7 @@ private: ParenthesesState parenthesesState; int parenthesesCount; bool prohibitAutomaticSemicolon; + bool tokenizeComments; }; } // namespace QmlJS -- cgit v0.12 From 6180d5cb66a98efa7c181ef51ef4a209b68c4234 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Tue, 8 Sep 2009 15:46:13 +0200 Subject: Revert "network-settings.h: Compile fix relating to some tests" This reverts commit 69e5a3fce4d355822367dc1a17179a364111632e. --- tests/auto/network-settings.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h index 40178fb..6ffb6f4 100644 --- a/tests/auto/network-settings.h +++ b/tests/auto/network-settings.h @@ -40,7 +40,9 @@ ****************************************************************************/ #include +#ifdef QT_NETWORK_LIB #include +#endif #ifdef Q_OS_SYMBIAN -- cgit v0.12 From 97fad21de75f2753cc9804f5924074b7b0d99262 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Tue, 8 Sep 2009 15:51:40 +0200 Subject: network-settings.h: Check for DNS setup only when needed --- tests/auto/network-settings.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h index 6ffb6f4..a770f8e 100644 --- a/tests/auto/network-settings.h +++ b/tests/auto/network-settings.h @@ -329,7 +329,7 @@ QByteArray QtNetworkSettings::imapExpectedReplySsl; #define Q_SET_DEFAULT_IAP #endif - +#ifdef QT_NETWORK_LIB class QtNetworkSettingsInitializerCode { public: QtNetworkSettingsInitializerCode() { @@ -343,3 +343,4 @@ public: } }; QtNetworkSettingsInitializerCode qtNetworkSettingsInitializer; +#endif -- cgit v0.12 From e31047fd3afd10e7d2d457b1a1bd4ee9bd48979a Mon Sep 17 00:00:00 2001 From: mread Date: Tue, 8 Sep 2009 14:36:38 +0100 Subject: exception safety fix for QList::operator+= (const QList&) The refactoring of current++ and src++ out of the new line makes the code easier to understand but it also seems to be significant at least in the ::isComplex case. I suspect that the ordering increment operations vs throw from new is not well defined, or not implemented as you might hope (with the ++ happening very last). The changes in the catch blocks mean that it deletes the created objects, rather than trying with the first failed object. The test code has been updated with a +=(Container) test, and to force testing of both static and moveable types. Reviewed-by: Harald Fernengel --- src/corelib/tools/qlist.h | 19 ++-- .../tst_exceptionsafety_objects.cpp | 117 ++++++++++++++++----- 2 files changed, 104 insertions(+), 32 deletions(-) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index c2bdbee..f316fec 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -367,21 +367,26 @@ Q_INLINE_TEMPLATE void QList::node_copy(Node *from, Node *to, Node *src) if (QTypeInfo::isLarge || QTypeInfo::isStatic) { QT_TRY { while(current != to) { - (current++)->v = new T(*reinterpret_cast((src++)->v)); + current->v = new T(*reinterpret_cast(src->v)); + ++current; + ++src; } } QT_CATCH(...) { - while (current != from) - delete reinterpret_cast(current--); + while (current-- != from) + delete reinterpret_cast(current->v); QT_RETHROW; } } else if (QTypeInfo::isComplex) { QT_TRY { - while(current != to) - new (current++) T(*reinterpret_cast(src++)); + while(current != to) { + new (current) T(*reinterpret_cast(src)); + ++current; + ++src; + } } QT_CATCH(...) { - while (current != from) - (reinterpret_cast(current--))->~T(); + while (current-- != from) + (reinterpret_cast(current))->~T(); QT_RETHROW; } } else { diff --git a/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp b/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp index 075fa01..46d5b9d 100644 --- a/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp +++ b/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp @@ -462,22 +462,62 @@ struct Integer int Integer::instanceCount = 0; -template class Container> +struct IntegerMoveable + { + IntegerMoveable(int value = 42) + : val(value) + { + delete new int; + ++instanceCount; + } + + IntegerMoveable(const IntegerMoveable &other) + : val(other.val) + { + delete new int; + ++instanceCount; + } + + IntegerMoveable &operator=(const IntegerMoveable &other) + { + delete new int; + val = other.val; + return *this; + } + + ~IntegerMoveable() + { + --instanceCount; + } + + int value() const + { + return val; + } + + int val; + static int instanceCount; + }; + +int IntegerMoveable::instanceCount = 0; +Q_DECLARE_TYPEINFO(IntegerMoveable, Q_MOVABLE_TYPE); + +template class Container > void containerInsertTest(QObject*) { - Container container; + Container container; // insert an item in an empty container try { container.insert(container.begin(), 41); } catch (...) { QVERIFY(container.isEmpty()); - QCOMPARE(Integer::instanceCount, 0); + QCOMPARE(T::instanceCount, 0); return; } QCOMPARE(container.size(), 1); - QCOMPARE(Integer::instanceCount, 1); + QCOMPARE(T::instanceCount, 1); // insert an item before another item try { @@ -485,11 +525,11 @@ void containerInsertTest(QObject*) } catch (...) { QCOMPARE(container.size(), 1); QCOMPARE(container.first().value(), 41); - QCOMPARE(Integer::instanceCount, 1); + QCOMPARE(T::instanceCount, 1); return; } - QCOMPARE(Integer::instanceCount, 2); + QCOMPARE(T::instanceCount, 2); // insert an item in between try { @@ -498,24 +538,24 @@ void containerInsertTest(QObject*) QCOMPARE(container.size(), 2); QCOMPARE(container.first().value(), 41); QCOMPARE((container.begin() + 1)->value(), 42); - QCOMPARE(Integer::instanceCount, 2); + QCOMPARE(T::instanceCount, 2); return; } - QCOMPARE(Integer::instanceCount, 3); + QCOMPARE(T::instanceCount, 3); } -template class Container> +template class Container> void containerAppendTest(QObject*) { - Container container; + Container container; // append to an empty container try { container.append(42); } catch (...) { QCOMPARE(container.size(), 0); - QCOMPARE(Integer::instanceCount, 0); + QCOMPARE(T::instanceCount, 0); return; } @@ -525,15 +565,38 @@ void containerAppendTest(QObject*) } catch (...) { QCOMPARE(container.size(), 1); QCOMPARE(container.first().value(), 42); - QCOMPARE(Integer::instanceCount, 1); + QCOMPARE(T::instanceCount, 1); return; } + + Container container2; + + try { + container2.append(44); + } catch (...) { + // don't care + return; + } + QCOMPARE(T::instanceCount, 3); + + // append another container with one item + try { + container += container2; + } catch (...) { + QCOMPARE(container.size(), 2); + QCOMPARE(container.first().value(), 42); + QCOMPARE((container.begin() + 1)->value(), 43); + QCOMPARE(T::instanceCount, 3); + return; + } + + QCOMPARE(T::instanceCount, 4); } -template class Container> +template class Container> void containerEraseTest(QObject*) { - Container container; + Container container; try { container.append(42); @@ -548,7 +611,7 @@ void containerEraseTest(QObject*) // sanity checks QCOMPARE(container.size(), 5); - QCOMPARE(Integer::instanceCount, 5); + QCOMPARE(T::instanceCount, 5); // delete the first one try { @@ -556,20 +619,20 @@ void containerEraseTest(QObject*) } catch (...) { QCOMPARE(container.size(), 5); QCOMPARE(container.first().value(), 42); - QCOMPARE(Integer::instanceCount, 5); + QCOMPARE(T::instanceCount, 5); return; } QCOMPARE(container.size(), 4); QCOMPARE(container.first().value(), 43); - QCOMPARE(Integer::instanceCount, 4); + QCOMPARE(T::instanceCount, 4); // delete the last one try { container.erase(container.end() - 1); } catch (...) { QCOMPARE(container.size(), 4); - QCOMPARE(Integer::instanceCount, 4); + QCOMPARE(T::instanceCount, 4); return; } @@ -577,7 +640,7 @@ void containerEraseTest(QObject*) QCOMPARE(container.first().value(), 43); QCOMPARE((container.begin() + 1)->value(), 44); QCOMPARE((container.begin() + 2)->value(), 45); - QCOMPARE(Integer::instanceCount, 3); + QCOMPARE(T::instanceCount, 3); // delete the middle one try { @@ -587,14 +650,14 @@ void containerEraseTest(QObject*) QCOMPARE(container.first().value(), 43); QCOMPARE((container.begin() + 1)->value(), 44); QCOMPARE((container.begin() + 2)->value(), 45); - QCOMPARE(Integer::instanceCount, 3); + QCOMPARE(T::instanceCount, 3); return; } QCOMPARE(container.size(), 2); QCOMPARE(container.first().value(), 43); QCOMPARE((container.begin() + 1)->value(), 45); - QCOMPARE(Integer::instanceCount, 2); + QCOMPARE(T::instanceCount, 2); } template class Container> @@ -602,9 +665,12 @@ static void containerData() { QTest::addColumn("testFunction"); - QTest::newRow("insert") << static_cast(containerInsertTest); - QTest::newRow("append") << static_cast(containerAppendTest); - QTest::newRow("erase") << static_cast(containerEraseTest); + QTest::newRow("insert static") << static_cast(containerInsertTest); + QTest::newRow("append static") << static_cast(containerAppendTest); + QTest::newRow("erase static") << static_cast(containerEraseTest); + QTest::newRow("insert moveable") << static_cast(containerInsertTest); + QTest::newRow("append moveable") << static_cast(containerAppendTest); + QTest::newRow("erase moveable") << static_cast(containerEraseTest); } void tst_ExceptionSafetyObjects::vector_data() @@ -616,7 +682,8 @@ void tst_ExceptionSafetyObjects::vector() { QFETCH(TestFunction, testFunction); - if (QLatin1String(QTest::currentDataTag()) == QLatin1String("insert")) + if (QLatin1String(QTest::currentDataTag()) == QLatin1String("insert static") + || QLatin1String(QTest::currentDataTag()) == QLatin1String("insert moveable")) QSKIP("QVector::insert is currently not strongly exception safe", SkipSingle); doOOMTest(testFunction, 0); -- cgit v0.12 From 7499d6c71a6579968189386e1e06e2479c1a6747 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 8 Sep 2009 15:58:24 +0200 Subject: tst_qbytearray: set SRCDIR to ./ on Windows CE Reviewed-by: thartman --- tests/auto/qbytearray/qbytearray.pro | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/auto/qbytearray/qbytearray.pro b/tests/auto/qbytearray/qbytearray.pro index d14534b..a0c143e 100644 --- a/tests/auto/qbytearray/qbytearray.pro +++ b/tests/auto/qbytearray/qbytearray.pro @@ -4,16 +4,17 @@ SOURCES += tst_qbytearray.cpp QT = core -wince*|symbian: { +wince*|symbian { addFile.sources = rfc3252.txt addFile.path = . DEPLOYMENT += addFile } -wince: { - DEFINES += SRCDIR=\\\"\\\" -} symbian: { +wince* { + DEFINES += SRCDIR=\\\"./\\\" +} else:symbian { TARGET.EPOCHEAPSIZE="0x100 0x800000" } else { - DEFINES += SRCDIR=\\\"$$PWD/\\\" + DEFINES += SRCDIR=\\\"$$PWD/\\\" } + -- cgit v0.12 From 5364fd96a72c89b281f0540da909fe64d0575ccf Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 8 Sep 2009 16:41:51 +0200 Subject: Take right bearing of glyphs into account when doing text layout To support correctly breaking text and calculating the bounding rect of text that has a right bearing (like italic text), we need to take the bearing into account when doing the layout. We add the bearing when checking whether we need to break the text, and we add it to the natural width of the text whenever we've finished a text line, so that we get the correct bounding rectangle. This patch only takes the last glyph's bearing into account. The theoretically correct approach would be to take all bearings into account and use the one which gives the longest text width. However, in practice the bearing of the glyph will not be great enough for it to span over several other glyphs. Also refactored a little to make the code simpler. Task-number: 176401 Reviewed-by: Simon Hausmann --- src/gui/text/qtextlayout.cpp | 155 ++++++++++++++++++++++++++++--------------- 1 file changed, 101 insertions(+), 54 deletions(-) diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index b150f50..60e5296 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1589,27 +1589,54 @@ void QTextLine::setNumColumns(int numColumns, qreal alignmentWidth) #define LB_DEBUG if (0) qDebug #endif -static inline bool checkFullOtherwiseExtend(QScriptLine &line, QScriptLine &tmpData, QScriptLine &spaceData, - int glyphCount, int maxGlyphs, QFixed &minw, bool manualWrap, - QFixed softHyphenWidth = QFixed()) -{ +namespace { + + struct LineBreakHelper + { + LineBreakHelper() : glyphCount(0), maxGlyphs(0), manualWrap(false) {} + + QScriptLine tmpData; + QScriptLine spaceData; + + int glyphCount; + int maxGlyphs; + + QFixed minw; + QFixed softHyphenWidth; + QFixed rightBearing; + + bool manualWrap; + + bool checkFullOtherwiseExtend(QScriptLine &line); + }; + +inline bool LineBreakHelper::checkFullOtherwiseExtend(QScriptLine &line) +{ LB_DEBUG("possible break width %f, spacew=%f", tmpData.textWidth.toReal(), spaceData.textWidth.toReal()); - if (line.length && !manualWrap && - (line.textWidth + tmpData.textWidth + spaceData.textWidth + softHyphenWidth > line.width || glyphCount > maxGlyphs)) + + QFixed newWidth = line.textWidth + tmpData.textWidth + spaceData.textWidth + softHyphenWidth + rightBearing; + if (line.length && !manualWrap && (newWidth > line.width || glyphCount > maxGlyphs)) return true; + minw = qMax(minw, tmpData.textWidth); line += tmpData; line.textWidth += spaceData.textWidth; + line.length += spaceData.length; tmpData.textWidth = 0; tmpData.length = 0; spaceData.textWidth = 0; spaceData.length = 0; + return false; } +} // anonymous namespace + + static inline void addNextCluster(int &pos, int end, QScriptLine &line, int &glyphCount, - const QScriptItem ¤t, const unsigned short *logClusters, const QGlyphLayout &glyphs) + const QScriptItem ¤t, const unsigned short *logClusters, + const QGlyphLayout &glyphs) { int glyphPosition = logClusters[pos]; do { // got to the first next cluster @@ -1642,9 +1669,13 @@ void QTextLine::layout_helper(int maxGlyphs) Q_ASSERT(line.from < eng->layoutData->string.length()); + LineBreakHelper lbh; + + lbh.maxGlyphs = maxGlyphs; + QTextOption::WrapMode wrapMode = eng->option.wrapMode(); bool breakany = (wrapMode == QTextOption::WrapAnywhere); - bool manualWrap = (wrapMode == QTextOption::ManualWrap || wrapMode == QTextOption::NoWrap); + lbh.manualWrap = (wrapMode == QTextOption::ManualWrap || wrapMode == QTextOption::NoWrap); // #### binary search! int item = -1; @@ -1654,12 +1685,7 @@ void QTextLine::layout_helper(int maxGlyphs) break; } - QFixed minw = 0; - int glyphCount = 0; - LB_DEBUG("from: %d: item=%d, total %d, width available %f", line.from, newItem, eng->layoutData->items.size(), line.width.toReal()); - QScriptLine tmpData; - QScriptLine spaceData; Qt::Alignment alignment = eng->option.alignment(); @@ -1668,7 +1694,10 @@ void QTextLine::layout_helper(int maxGlyphs) int end = 0; QGlyphLayout glyphs; const unsigned short *logClusters = eng->layoutData->logClustersPtr; + while (newItem < eng->layoutData->items.size()) { + lbh.rightBearing = 0; + lbh.softHyphenWidth = 0; if (newItem != item) { item = newItem; const QScriptItem ¤t = eng->layoutData->items[item]; @@ -1683,57 +1712,60 @@ void QTextLine::layout_helper(int maxGlyphs) } const QScriptItem ¤t = eng->layoutData->items[item]; - tmpData.ascent = qMax(tmpData.ascent, current.ascent); - tmpData.descent = qMax(tmpData.descent, current.descent); + lbh.tmpData.ascent = qMax(lbh.tmpData.ascent, current.ascent); + lbh.tmpData.descent = qMax(lbh.tmpData.descent, current.descent); if (current.analysis.flags == QScriptAnalysis::Tab && (alignment & (Qt::AlignLeft | Qt::AlignRight | Qt::AlignCenter | Qt::AlignJustify))) { - if (checkFullOtherwiseExtend(line, tmpData, spaceData, glyphCount, maxGlyphs, minw, manualWrap)) + if (lbh.checkFullOtherwiseExtend(line)) goto found; - QFixed x = line.x + line.textWidth + tmpData.textWidth + spaceData.textWidth; - spaceData.textWidth += eng->calculateTabWidth(item, x); - spaceData.length++; + QFixed x = line.x + line.textWidth + lbh.tmpData.textWidth + lbh.spaceData.textWidth; + lbh.spaceData.textWidth += eng->calculateTabWidth(item, x); + lbh.spaceData.length++; newItem = item + 1; - ++glyphCount; - if (checkFullOtherwiseExtend(line, tmpData, spaceData, glyphCount, maxGlyphs, minw, manualWrap)) + ++lbh.glyphCount; + if (lbh.checkFullOtherwiseExtend(line)) goto found; } else if (current.analysis.flags == QScriptAnalysis::LineOrParagraphSeparator) { // if the line consists only of the line separator make sure // we have a sane height - if (!line.length && !tmpData.length) + if (!line.length && !lbh.tmpData.length) line.setDefaultHeight(eng); if (eng->option.flags() & QTextOption::ShowLineAndParagraphSeparators) { - addNextCluster(pos, end, tmpData, glyphCount, current, logClusters, glyphs); + addNextCluster(pos, end, lbh.tmpData, lbh.glyphCount, + current, logClusters, glyphs); } else { - tmpData.length++; + lbh.tmpData.length++; } - line += tmpData; + line += lbh.tmpData; goto found; } else if (current.analysis.flags == QScriptAnalysis::Object) { - tmpData.length++; + lbh.tmpData.length++; QTextFormat format = eng->formats()->format(eng->formatIndex(&eng->layoutData->items[item])); if (eng->block.docHandle()) eng->docLayout()->positionInlineObject(QTextInlineObject(item, eng), eng->block.position() + current.position, format); - tmpData.textWidth += current.width; + lbh.tmpData.textWidth += current.width; newItem = item + 1; - ++glyphCount; - if (checkFullOtherwiseExtend(line, tmpData, spaceData, glyphCount, maxGlyphs, minw, manualWrap)) + ++lbh.glyphCount; + if (lbh.checkFullOtherwiseExtend(line)) goto found; } else if (attributes[pos].whiteSpace) { while (pos < end && attributes[pos].whiteSpace) - addNextCluster(pos, end, spaceData, glyphCount, current, logClusters, glyphs); + addNextCluster(pos, end, lbh.spaceData, lbh.glyphCount, + current, logClusters, glyphs); - if (!manualWrap && spaceData.textWidth > line.width) { - spaceData.textWidth = line.width; // ignore spaces that fall out of the line. + if (!lbh.manualWrap && lbh.spaceData.textWidth > line.width) { + lbh.spaceData.textWidth = line.width; // ignore spaces that fall out of the line. goto found; } } else { bool sb_or_ws = false; do { - addNextCluster(pos, end, tmpData, glyphCount, current, logClusters, glyphs); + addNextCluster(pos, end, lbh.tmpData, lbh.glyphCount, + current, logClusters, glyphs); if (attributes[pos].whiteSpace || attributes[pos-1].lineBreakType != HB_NoBreak) { sb_or_ws = true; @@ -1742,9 +1774,8 @@ void QTextLine::layout_helper(int maxGlyphs) break; } } while (pos < end); - minw = qMax(tmpData.textWidth, minw); + lbh.minw = qMax(lbh.tmpData.textWidth, lbh.minw); - QFixed softHyphenWidth; if (pos && attributes[pos - 1].lineBreakType == HB_SoftHyphen) { // if we are splitting up a word because of // a soft hyphen then we ... @@ -1763,16 +1794,29 @@ void QTextLine::layout_helper(int maxGlyphs) // and thus become invisible again. // if (line.length) - softHyphenWidth = glyphs.advances_x[logClusters[pos - 1]]; + lbh.softHyphenWidth = glyphs.advances_x[logClusters[pos - 1]]; else if (breakany) - tmpData.textWidth += glyphs.advances_x[logClusters[pos - 1]]; + lbh.tmpData.textWidth += glyphs.advances_x[logClusters[pos - 1]]; } - if ((sb_or_ws|breakany) - && checkFullOtherwiseExtend(line, tmpData, spaceData, glyphCount, maxGlyphs, minw, manualWrap, softHyphenWidth)) { + // The actual width of the text needs to take the right bearing into account. The + // right bearing is left-ward, which means that if the rightmost pixel is to the right + // of the advance of the glyph, the bearing will be negative. We flip the sign + // for the code to be more readable. Logic borrowed from qfontmetrics.cpp. + if (pos) { + QFontEngine *fontEngine = eng->fontEngine(current); + glyph_t glyph = glyphs.glyphs[logClusters[pos - 1]]; + glyph_metrics_t gi = fontEngine->boundingBox(glyph); + lbh.rightBearing = -qRound(gi.xoff - gi.x - gi.width); + } + + if ((sb_or_ws|breakany) && lbh.checkFullOtherwiseExtend(line)) { if (!breakany) { - line.textWidth += softHyphenWidth; + line.textWidth += lbh.softHyphenWidth; } + + line.textWidth += lbh.rightBearing; + goto found; } } @@ -1780,45 +1824,48 @@ void QTextLine::layout_helper(int maxGlyphs) newItem = item + 1; } LB_DEBUG("reached end of line"); - checkFullOtherwiseExtend(line, tmpData, spaceData, glyphCount, maxGlyphs, minw, manualWrap); -found: + lbh.checkFullOtherwiseExtend(line); + line.textWidth += lbh.rightBearing; + +found: if (line.length == 0) { LB_DEBUG("no break available in line, adding temp: length %d, width %f, space: length %d, width %f", - tmpData.length, tmpData.textWidth.toReal(), spaceData.length, spaceData.textWidth.toReal()); - line += tmpData; + lbh.tmpData.length, lbh.tmpData.textWidth.toReal(), + lbh.spaceData.length, lbh.spaceData.textWidth.toReal()); + line += lbh.tmpData; } LB_DEBUG("line length = %d, ascent=%f, descent=%f, textWidth=%f (spacew=%f)", line.length, line.ascent.toReal(), - line.descent.toReal(), line.textWidth.toReal(), spaceData.width.toReal()); + line.descent.toReal(), line.textWidth.toReal(), lbh.spaceData.width.toReal()); LB_DEBUG(" : '%s'", eng->layoutData->string.mid(line.from, line.length).toUtf8().data()); - if (manualWrap) { + if (lbh.manualWrap) { eng->minWidth = qMax(eng->minWidth, line.textWidth); eng->maxWidth = qMax(eng->maxWidth, line.textWidth); } else { - eng->minWidth = qMax(eng->minWidth, minw); + eng->minWidth = qMax(eng->minWidth, lbh.minw); eng->maxWidth += line.textWidth; } if (line.textWidth > 0 && item < eng->layoutData->items.size()) - eng->maxWidth += spaceData.textWidth; + eng->maxWidth += lbh.spaceData.textWidth; if (eng->option.flags() & QTextOption::IncludeTrailingSpaces) - line.textWidth += spaceData.textWidth; - line.length += spaceData.length; - if (spaceData.length) + line.textWidth += lbh.spaceData.textWidth; + line.length += lbh.spaceData.length; + if (lbh.spaceData.length) line.hasTrailingSpaces = true; line.justified = false; line.gridfitted = false; if (eng->option.wrapMode() == QTextOption::WrapAtWordBoundaryOrAnywhere) { - if ((maxGlyphs != INT_MAX && glyphCount > maxGlyphs) - || (maxGlyphs == INT_MAX && line.textWidth > line.width)) { + if ((lbh.maxGlyphs != INT_MAX && lbh.glyphCount > lbh.maxGlyphs) + || (lbh.maxGlyphs == INT_MAX && line.textWidth > line.width)) { eng->option.setWrapMode(QTextOption::WrapAnywhere); line.length = 0; line.textWidth = 0; - layout_helper(maxGlyphs); + layout_helper(lbh.maxGlyphs); eng->option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); } } -- cgit v0.12 From 10563ce08c79c88c762d463ec7b008524d1c1a67 Mon Sep 17 00:00:00 2001 From: Geir Vattekar Date: Tue, 8 Sep 2009 16:54:55 +0200 Subject: Doc: Fixed bug in style sheet syntax documentation. Task-number: 234366 Reviewed-by: Trust Me --- doc/src/widgets-and-layouts/stylesheet.qdoc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/src/widgets-and-layouts/stylesheet.qdoc b/doc/src/widgets-and-layouts/stylesheet.qdoc index 354050d..c137d6a 100644 --- a/doc/src/widgets-and-layouts/stylesheet.qdoc +++ b/doc/src/widgets-and-layouts/stylesheet.qdoc @@ -230,9 +230,11 @@ \o \c{QPushButton[flat="false"]} \o Matches instances of QPushButton that are not \l{QPushButton::}{flat}. You may use this selector to test - for any Qt property specified using Q_PROPERTY(). In - addition, the special \c class property is supported, for - the name of the class. + for any Qt \l{Qt's Property System}{property} that supports + QVariant::toString() (see the \l{QVariant::}{toString()} + function documentation for details). In addition, the + special \c class property is supported, for the name of the + class. This selector may also be used to test dynamic properties. For more information on customization using dynamic properties, -- cgit v0.12 From 5a3d0e73121e191fe2f1337ac8f6761c35868b66 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Tue, 8 Sep 2009 17:24:37 +0200 Subject: Fix crash when instantiating multiple QApplications on QWS Copy variable initialization/cleanup code from X11 Reviewed-by: Tom --- src/gui/kernel/qapplication_qws.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gui/kernel/qapplication_qws.cpp b/src/gui/kernel/qapplication_qws.cpp index e3bd786..ba2e6a6 100644 --- a/src/gui/kernel/qapplication_qws.cpp +++ b/src/gui/kernel/qapplication_qws.cpp @@ -2202,6 +2202,8 @@ void qt_init(QApplicationPrivate *priv, int type) mouse_double_click_distance = read_int_env_var("QWS_DBLCLICK_DISTANCE", 5); + priv->inputContext = 0; + int flags = 0; char *p; int argc = priv->argc; @@ -2361,6 +2363,11 @@ void qt_cleanup() delete mouseInWidget; mouseInWidget = 0; + +#if !defined(QT_NO_IM) + delete QApplicationPrivate::inputContext; + QApplicationPrivate::inputContext = 0; +#endif } -- cgit v0.12 From 7c59abc1883a24e54ac3bb2193acc2cac5ad416a Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Thu, 27 Aug 2009 16:08:20 +0200 Subject: Replace QGLDrawable with a new QGLPaintDevice This patch adds a new abstract base class which inherits from QPaintDevice called QGLPaintDevice. This base class will contain everything the GL paint engines need to know about the surface they are drawing onto. As such, new surfaces can be targeted by the GL paint engines without having to modify QtOpenGL. This is very useful for plugins, specifically QGraphicsSystem plugins. To unify things a little, the GL paint engines will use the same QGLPaintDevice API to render into existing target surfaces (QGLWidget, QGLPixelBuffer & QGLFrameBufferObject). Ideally we'd make QGLPaintDevice a common ancestor for these surfaces, but obviously that wil break B/C. This patch only implements QGLWidget using the new interface. Rendering to other surfaces will be fixed in following patches. --- src/corelib/global/qnamespace.h | 3 +- .../gl2paintengineex/qpaintengineex_opengl2.cpp | 65 +++---- .../gl2paintengineex/qpaintengineex_opengl2_p.h | 3 +- src/opengl/opengl.pro | 6 +- src/opengl/qgl.cpp | 5 +- src/opengl/qgl.h | 2 + src/opengl/qgl_p.h | 7 +- src/opengl/qgl_x11.cpp | 3 +- src/opengl/qglpaintdevice.cpp | 192 +++++++++++++++++++++ src/opengl/qglpaintdevice_p.h | 168 ++++++++++++++++++ src/opengl/qpaintengine_opengl.cpp | 113 ++++++------ 11 files changed, 483 insertions(+), 84 deletions(-) create mode 100644 src/opengl/qglpaintdevice.cpp create mode 100644 src/opengl/qglpaintdevice_p.h diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 8f34e30..93de911 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1655,7 +1655,8 @@ public: FramebufferObject = 0x07, // GL framebuffer object CustomRaster = 0x08, MacQuartz = 0x09, - PaintBuffer = 0x0a + PaintBuffer = 0x0a, + OpenGL = 0x0b }; enum RelayoutType { RelayoutNormal, diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index e24539b..8fee83d 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -710,7 +710,7 @@ void QGL2PaintEngineEx::beginNativePainting() { mtx.dx(), mtx.dy(), 0, mtx.m33() } }; - const QSize sz = d->drawable.size(); + const QSize sz = d->device->size(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -1308,21 +1308,28 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) Q_D(QGL2PaintEngineEx); // qDebug("QGL2PaintEngineEx::begin()"); - d->drawable.setDevice(pdev); - d->ctx = d->drawable.context(); + if (pdev->devType() == QInternal::OpenGL) + d->device = static_cast(pdev); + else + d->device = QGLPaintDevice::getDevice(pdev); + + if (!d->device) + return false; + + d->ctx = d->device->context(); if (d->ctx->d_ptr->active_engine) { QGL2PaintEngineEx *engine = static_cast(d->ctx->d_ptr->active_engine); QGL2PaintEngineExPrivate *p = static_cast(engine->d_ptr.data()); p->transferMode(BrushDrawingMode); - p->drawable.doneCurrent(); + p->device->context()->doneCurrent(); } d->ctx->d_ptr->active_engine = this; d->last_created_state = 0; - d->drawable.makeCurrent(); - QSize sz = d->drawable.size(); + d->device->beginPaint(); + QSize sz = d->device->size(); d->width = sz.width(); d->height = sz.height(); d->mode = BrushDrawingMode; @@ -1358,28 +1365,29 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) glDisable(GL_MULTISAMPLE); #endif - QGLPixmapData *source = d->drawable.copyOnBegin(); - if (d->drawable.context()->d_func()->clear_on_painter_begin && d->drawable.autoFillBackground()) { - if (d->drawable.hasTransparentBackground()) +// QGLPixmapData *source = d->drawable.copyOnBegin(); + if (d->ctx->d_func()->clear_on_painter_begin && d->device->autoFillBackground()) { + if (d->device->hasTransparentBackground()) glClearColor(0.0, 0.0, 0.0, 0.0); else { - const QColor &c = d->drawable.backgroundColor(); + const QColor &c = d->device->backgroundColor(); float alpha = c.alphaF(); glClearColor(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha); } glClear(GL_COLOR_BUFFER_BIT); - } else if (source) { - QGLContext *ctx = d->ctx; - - d->transferMode(ImageDrawingMode); - - glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); - source->bind(false); - - QRect rect(0, 0, source->width(), source->height()); - d->updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false); - d->drawTexture(QRectF(rect), QRectF(rect), rect.size(), true); } +// else if (source) { +// QGLContext *ctx = d->ctx; +// +// d->transferMode(ImageDrawingMode); +// +// glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); +// source->bind(false); +// +// QRect rect(0, 0, source->width(), source->height()); +// d->updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false); +// d->drawTexture(QRectF(rect), QRectF(rect), rect.size(), true); +// } d->systemStateChanged(); return true; @@ -1394,14 +1402,15 @@ bool QGL2PaintEngineEx::end() if (engine && engine->isActive()) { QGL2PaintEngineExPrivate *p = static_cast(engine->d_ptr.data()); p->transferMode(BrushDrawingMode); - p->drawable.doneCurrent(); + p->device->context()->doneCurrent(); } - d->drawable.makeCurrent(); + d->device->context()->makeCurrent(); } glUseProgram(0); d->transferMode(BrushDrawingMode); - d->drawable.swapBuffers(); + d->device->endPaint(); + #if defined(Q_WS_X11) // On some (probably all) drivers, deleting an X pixmap which has been bound to a texture // before calling glFinish/swapBuffers renders garbage. Presumably this is because X deletes @@ -1410,7 +1419,6 @@ bool QGL2PaintEngineEx::end() // them here, after swapBuffers, where they can be safely deleted. ctx->d_func()->boundPixmaps.clear(); #endif - d->drawable.doneCurrent(); d->ctx->d_ptr->active_engine = 0; d->resetGLState(); @@ -1431,15 +1439,14 @@ void QGL2PaintEngineEx::ensureActive() if (engine && engine->isActive()) { QGL2PaintEngineExPrivate *p = static_cast(engine->d_ptr.data()); p->transferMode(BrushDrawingMode); - p->drawable.doneCurrent(); + p->device->context()->doneCurrent(); } - d->drawable.context()->makeCurrent(); - d->drawable.makeCurrent(); + d->device->context()->makeCurrent(); ctx->d_ptr->active_engine = this; d->needsSync = true; } else { - d->drawable.context()->makeCurrent(); + d->device->context()->makeCurrent(); } if (d->needsSync) { diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h index cb23b11..2fbee1b 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h @@ -58,6 +58,7 @@ #include #include #include +#include enum EngineMode { ImageDrawingMode, @@ -199,7 +200,7 @@ public: static QGLEngineShaderManager* shaderManagerForEngine(QGL2PaintEngineEx *engine) { return engine->d_func()->shaderManager; } QGL2PaintEngineEx* q; - QGLDrawable drawable; + QGLPaintDevice* device; int width, height; QGLContext *ctx; EngineMode mode; diff --git a/src/opengl/opengl.pro b/src/opengl/opengl.pro index 560d31f..2aefe41 100644 --- a/src/opengl/opengl.pro +++ b/src/opengl/opengl.pro @@ -22,13 +22,17 @@ HEADERS += qgl.h \ qglpixelbuffer.h \ qglpixelbuffer_p.h \ qglframebufferobject.h \ - qglextensions_p.h + qglextensions_p.h \ + qglpaintdevice_p.h \ + SOURCES += qgl.cpp \ qglcolormap.cpp \ qglpixelbuffer.cpp \ qglframebufferobject.cpp \ qglextensions.cpp \ + qglpaintdevice.cpp \ + !contains(QT_CONFIG, opengles2) { HEADERS += qpaintengine_opengl_p.h diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 02bb8f9..ad54298 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -4815,6 +4815,8 @@ void QGLWidgetPrivate::initContext(QGLContext *context, const QGLWidget* shareWi { Q_Q(QGLWidget); + glDevice.setWidget(q); + QGLExtensions::init(); glcx = 0; autoSwap = true; @@ -4850,6 +4852,7 @@ Q_OPENGL_EXPORT const QString qt_gl_library_name() } #endif +#if 0 void QGLDrawable::setDevice(QPaintDevice *pdev) { wasBound = false; @@ -5084,7 +5087,7 @@ bool QGLDrawable::autoFillBackground() const else return false; } - +#endif bool QGLShareRegister::checkSharing(const QGLContext *context1, const QGLContext *context2) { bool sharing = (context1 && context2 && context1->d_ptr->group == context2->d_ptr->group); diff --git a/src/opengl/qgl.h b/src/opengl/qgl.h index b110665..46efe23 100644 --- a/src/opengl/qgl.h +++ b/src/opengl/qgl.h @@ -542,6 +542,8 @@ private: friend class QGLContext; friend class QGLOverlayWidget; friend class QOpenGLPaintEngine; + friend class QGLPaintDevice; + friend class QGLWidgetGLPaintDevice; }; diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index f8158a0..03532c8 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -62,6 +62,7 @@ #include "QtCore/qatomic.h" #include "private/qwidget_p.h" #include "qcache.h" +#include "qglpaintdevice_p.h" #ifndef QT_OPENGL_ES_1_CL #define q_vertexType float @@ -189,7 +190,8 @@ public: bool renderCxPm(QPixmap *pixmap); void cleanupColormaps(); - QGLContext *glcx; + QGLContext *glcx; // ### Keep for compatability with QGLDrawable (if that gets left in) + QGLWidgetGLPaintDevice glDevice; bool autoSwap; QGLColormap cmap; @@ -337,6 +339,7 @@ Q_SIGNALS: void aboutToDestroyContext(const QGLContext *context); }; +#if 0 class QGLPixelBuffer; class QGLFramebufferObject; class QWSGLWindowSurface; @@ -388,6 +391,8 @@ private: int previous_fbo; }; +#endif + // GL extension definitions class QGLExtensions { public: diff --git a/src/opengl/qgl_x11.cpp b/src/opengl/qgl_x11.cpp index 81985cd..5da128d 100644 --- a/src/opengl/qgl_x11.cpp +++ b/src/opengl/qgl_x11.cpp @@ -41,6 +41,7 @@ #include "qgl.h" #include "qgl_p.h" +#include "qglpaintdevice_p.h" #include "qmap.h" #include "qapplication.h" @@ -1307,7 +1308,7 @@ void QGLWidget::setContext(QGLContext *context, d->glcx->doneCurrent(); QGLContext* oldcx = d->glcx; d->glcx = context; - + d->glDevice.setContext(context); // ### Do this for all platforms if (parentWidget()) { // force creation of delay-created widgets diff --git a/src/opengl/qglpaintdevice.cpp b/src/opengl/qglpaintdevice.cpp new file mode 100644 index 0000000..f7bd2a3 --- /dev/null +++ b/src/opengl/qglpaintdevice.cpp @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenGL module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +QGLPaintDevice::QGLPaintDevice() + : m_context(0) +{ +} + +QGLPaintDevice::~QGLPaintDevice() +{ +} + +//extern QPaintEngine* qt_gl_engine(); // in qgl.cpp +//extern QPaintEngine* qt_gl_2_engine(); // in qgl.cpp + +//inline bool qt_gl_preferGL2Engine() +//{ +//#if defined(QT_OPENGL_ES_2) +// return true; +//#else +// return (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0) +// && qgetenv("QT_GL_USE_OPENGL1ENGINE").isEmpty(); +//#endif +//} + +//QPaintEngine* QGLPaintDevice::paintEngine() const +//{ +//#if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_1_CL) +// return qt_gl_engine(); +//#elif defined(QT_OPENGL_ES_2) +// return qt_gl_2_engine(); +//#else +// if (!qt_gl_preferGL2Engine()) +// return qt_gl_engine(); +// else +// return qt_gl_2_engine(); +//#endif +//} + +void QGLPaintDevice::beginPaint() +{ + m_context->makeCurrent(); +} + +void QGLPaintDevice::endPaint() +{ +} + +QColor QGLPaintDevice::backgroundColor() const +{ + return QColor(); +} + +bool QGLPaintDevice::autoFillBackground() const +{ + return false; +} + +bool QGLPaintDevice::hasTransparentBackground() const +{ + return false; +} + +QGLContext* QGLPaintDevice::context() const +{ + return m_context; +} + +QGLFormat QGLPaintDevice::format() const +{ + return m_context->format(); +} + +QSize QGLPaintDevice::size() const +{ + return QSize(); +} + +void QGLPaintDevice::setContext(QGLContext* c) +{ + m_context = c; +} + + + +QGLWidgetGLPaintDevice::QGLWidgetGLPaintDevice() +{ +} + +QPaintEngine* QGLWidgetGLPaintDevice::paintEngine() const +{ + return glWidget->paintEngine(); +} + +QColor QGLWidgetGLPaintDevice::backgroundColor() const +{ + return glWidget->palette().brush(glWidget->backgroundRole()).color(); +} + +bool QGLWidgetGLPaintDevice::autoFillBackground() const +{ + return glWidget->autoFillBackground(); +} + +bool QGLWidgetGLPaintDevice::hasTransparentBackground() const +{ + return glWidget->testAttribute(Qt::WA_TranslucentBackground); +} + +void QGLWidgetGLPaintDevice::setWidget(QGLWidget* w) +{ + glWidget = w; +} + +//void QGLWidgetGLPaintDevice::beginPaint() +//{ +// glWidget->makeCurrent(); +//} + +void QGLWidgetGLPaintDevice::endPaint() +{ + if (glWidget->autoBufferSwap()) + glWidget->swapBuffers(); +} + + +QSize QGLWidgetGLPaintDevice::size() const +{ + return glWidget->size(); +} + +// returns the QGLPaintDevice for the given QPaintDevice +QGLPaintDevice* QGLPaintDevice::getDevice(QPaintDevice* pd) +{ + QGLPaintDevice* glpd = 0; + + switch(pd->devType()) { + case QInternal::Widget: + // Should not be called on a non-gl widget: + Q_ASSERT(qobject_cast(static_cast(pd))); + glpd = &(static_cast(pd)->d_func()->glDevice); + break; + default: + qWarning("QGLPaintDevice::getDevice() - Unknown device type %d", pd->devType()); + break; + } + + return glpd; +} + + diff --git a/src/opengl/qglpaintdevice_p.h b/src/opengl/qglpaintdevice_p.h new file mode 100644 index 0000000..ad680a9 --- /dev/null +++ b/src/opengl/qglpaintdevice_p.h @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenGL module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGLPAINTDEVICE_P_H +#define QGLPAINTDEVICE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the QtOpenGL module. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +class QGLPaintDevice : public QPaintDevice +{ +public: + QGLPaintDevice(); + virtual ~QGLPaintDevice(); + + virtual void beginPaint(); + virtual void endPaint(); + + virtual QColor backgroundColor() const; + virtual bool autoFillBackground() const; + virtual bool hasTransparentBackground() const; + + // inline these? + QGLContext* context() const; + QGLFormat format() const; + virtual QSize size() const; + + // returns the QGLPaintDevice for the given QPaintDevice + static QGLPaintDevice* getDevice(QPaintDevice*); + +protected: + // Inline? + void setContext(QGLContext* c); + +private: + QGLContext* m_context; +}; + + +// Wraps a QGLWidget +class QGLWidget; +class QGLWidgetGLPaintDevice : public QGLPaintDevice +{ +public: + QGLWidgetGLPaintDevice(); + + virtual QPaintEngine* paintEngine() const; + + virtual QColor backgroundColor() const; + virtual bool autoFillBackground() const; + virtual bool hasTransparentBackground() const; + + // QGLWidgets need to do swapBufers in endPaint: + virtual void endPaint(); + virtual QSize size() const; + + void setWidget(QGLWidget*); + +private: + friend class QGLWidget; + QGLWidget *glWidget; +}; + + + +/* +Replaces: + +class QGLPixelBuffer; +class QGLFramebufferObject; +class QWSGLWindowSurface; +class QGLWindowSurface; +class QGLPixmapData; +class QGLDrawable { +public: + QGLDrawable() : widget(0), buffer(0), fbo(0) +#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)) + , wsurf(0) +#endif +#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) + , pixmapData(0) +#endif + {} + void setDevice(QPaintDevice *pdev); + void swapBuffers(); + void makeCurrent(); + void doneCurrent(); + QSize size() const; + QGLFormat format() const; + GLuint bindTexture(const QImage &image, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA); + GLuint bindTexture(const QPixmap &pixmap, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA); + QColor backgroundColor() const; + QGLContext *context() const; + bool autoFillBackground() const; + bool hasTransparentBackground() const; + +#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) + QGLPixmapData *copyOnBegin() const; +#endif + +private: + bool wasBound; + QGLWidget *widget; + QGLPixelBuffer *buffer; + QGLFramebufferObject *fbo; +#ifdef Q_WS_QWS + QWSGLWindowSurface *wsurf; +#elif !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) + QGLWindowSurface *wsurf; +#endif + +#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) + QGLPixmapData *pixmapData; +#endif + int previous_fbo; +}; +*/ + +#endif // QGLPAINTDEVICE_P_H diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp index bf4d4b9..634067d 100644 --- a/src/opengl/qpaintengine_opengl.cpp +++ b/src/opengl/qpaintengine_opengl.cpp @@ -49,6 +49,7 @@ #include "qbrush.h" #include "qgl.h" #include +#include #include #include "qmap.h" #include @@ -75,7 +76,7 @@ #include "qgl_cl_p.h" #endif -#define QGL_FUNC_CONTEXT QGLContext *ctx = const_cast(drawable.context()); +#define QGL_FUNC_CONTEXT QGLContext *ctx = const_cast(device->context()); #include #include "qpaintengine_opengl_p.h" @@ -286,7 +287,8 @@ public Q_SLOTS: } private: - QGLDrawable drawable; +// QGLDrawable drawable; + QGLPaintDevice* device; QGLFramebufferObject *offscreen; QGLContext *ctx; @@ -305,7 +307,13 @@ private: inline void QGLOffscreen::setDevice(QPaintDevice *pdev) { - drawable.setDevice(pdev); + if (pdev->devType() == QInternal::OpenGL) + device = static_cast(pdev); + else + device = QGLPaintDevice::getDevice(pdev); + + if (!device) + return; drawable_fbo = (pdev->devType() == QInternal::FramebufferObject); } @@ -329,12 +337,12 @@ void QGLOffscreen::initialize() activated = true; initialized = true; - int dim = qMax(2048, static_cast(qt_next_power_of_two(qMax(drawable.size().width(), drawable.size().height())))); + int dim = qMax(2048, static_cast(qt_next_power_of_two(qMax(device->size().width(), device->size().height())))); - bool shared_context = qgl_share_reg()->checkSharing(drawable.context(), ctx); + bool shared_context = qgl_share_reg()->checkSharing(device->context(), ctx); bool would_fail = last_failed_size.isValid() && - (drawable.size().width() >= last_failed_size.width() || - drawable.size().height() >= last_failed_size.height()); + (device->size().width() >= last_failed_size.width() || + device->size().height() >= last_failed_size.height()); bool needs_refresh = dim > mask_dim || !shared_context; if (needs_refresh && !would_fail) { @@ -348,13 +356,13 @@ void QGLOffscreen::initialize() delete offscreen; offscreen = 0; mask_dim = 0; - last_failed_size = drawable.size(); + last_failed_size = device->size(); } } qt_mask_texture_cache()->setOffscreenSize(offscreenSize()); - qt_mask_texture_cache()->setDrawableSize(drawable.size()); - ctx = drawable.context(); + qt_mask_texture_cache()->setDrawableSize(device->size()); + ctx = device->context(); #endif } @@ -428,11 +436,11 @@ inline void QGLOffscreen::release() DEBUG_ONCE_STR("QGLOffscreen: releasing offscreen"); if (drawable_fbo) - drawable.makeCurrent(); + device->context()->makeCurrent(); //### else offscreen->release(); - QSize sz(drawable.size()); + QSize sz(device->size()); glViewport(0, 0, sz.width(), sz.height()); glMatrixMode(GL_PROJECTION); @@ -455,7 +463,7 @@ inline bool QGLOffscreen::isBound() const inline QSize QGLOffscreen::drawableSize() const { - return drawable.size(); + return device->size(); } inline QSize QGLOffscreen::offscreenSize() const @@ -757,7 +765,8 @@ public: GLubyte pen_color[4]; GLubyte brush_color[4]; QTransform::TransformationType txop; - QGLDrawable drawable; +// QGLDrawable drawable; + QGLPaintDevice* device; QGLOffscreen offscreen; qreal inverseScale; @@ -1167,7 +1176,7 @@ void QOpenGLPaintEnginePrivate::createGradientPaletteTexture(const QGradient& g) #ifdef QT_OPENGL_ES //### Q_UNUSED(g); #else - GLuint texId = qt_opengl_gradient_cache()->getBuffer(g, opacity, drawable.context()); + GLuint texId = qt_opengl_gradient_cache()->getBuffer(g, opacity, device->context()); glBindTexture(GL_TEXTURE_1D, texId); grad_palette = texId; if (g.spread() == QGradient::RepeatSpread || g.type() == QGradient::ConicalGradient) @@ -1236,12 +1245,19 @@ bool QOpenGLPaintEngine::begin(QPaintDevice *pdev) { Q_D(QOpenGLPaintEngine); - d->drawable.setDevice(pdev); + if (pdev->devType() == QInternal::OpenGL) + d->device = static_cast(pdev); + else + d->device = QGLPaintDevice::getDevice(pdev); + + if (!d->device) + return false; + d->offscreen.setDevice(pdev); d->has_fast_pen = false; d->inverseScale = 1; d->opacity = 1; - d->drawable.makeCurrent(); + d->device->beginPaint(); d->matrix = QTransform(); d->has_antialiasing = false; d->high_quality_antialiasing = false; @@ -1256,7 +1272,7 @@ bool QOpenGLPaintEngine::begin(QPaintDevice *pdev) bool has_frag_program = (QGLExtensions::glExtensions & QGLExtensions::FragmentProgram) && (pdev->devType() != QInternal::Pixmap); - QGLContext *ctx = const_cast(d->drawable.context()); + QGLContext *ctx = const_cast(d->device->context()); if (!ctx) { qWarning() << "QOpenGLPaintEngine: paint device doesn't have a valid GL context."; return false; @@ -1265,9 +1281,9 @@ bool QOpenGLPaintEngine::begin(QPaintDevice *pdev) if (has_frag_program) has_frag_program = qt_resolve_frag_program_extensions(ctx) && qt_resolve_version_1_3_functions(ctx); - d->use_stencil_method = d->drawable.format().stencil() + d->use_stencil_method = d->device->format().stencil() && (QGLExtensions::glExtensions & QGLExtensions::StencilWrap); - if (d->drawable.format().directRendering() + if (d->device->format().directRendering() && (d->use_stencil_method && QGLExtensions::glExtensions & QGLExtensions::StencilTwoSide)) d->has_stencil_face_ext = qt_resolve_stencil_face_extension(ctx); @@ -1333,12 +1349,12 @@ bool QOpenGLPaintEngine::begin(QPaintDevice *pdev) d->offscreen.begin(); - if (d->drawable.context()->d_func()->clear_on_painter_begin && d->drawable.autoFillBackground()) { + if (d->device->context()->d_func()->clear_on_painter_begin && d->device->autoFillBackground()) { - if (d->drawable.hasTransparentBackground()) + if (d->device->hasTransparentBackground()) glClearColor(0.0, 0.0, 0.0, 0.0); else { - const QColor &c = d->drawable.backgroundColor(); + const QColor &c = d->device->backgroundColor(); glClearColor(c.redF(), c.greenF(), c.blueF(), 1.0); } @@ -1349,7 +1365,7 @@ bool QOpenGLPaintEngine::begin(QPaintDevice *pdev) glClear(clearBits); } - QSize sz(d->drawable.size()); + QSize sz(d->device->size()); glViewport(0, 0, sz.width(), sz.height()); // XXX (Embedded): We need a solution for GLWidgets that draw in a part or a bigger surface... glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -1366,7 +1382,7 @@ bool QOpenGLPaintEngine::begin(QPaintDevice *pdev) #ifdef QT_OPENGL_ES d->max_texture_size = ctx->d_func()->maxTextureSize(); #else - bool shared_ctx = qgl_share_reg()->checkSharing(d->drawable.context(), d->shader_ctx); + bool shared_ctx = qgl_share_reg()->checkSharing(d->device->context(), d->shader_ctx); if (shared_ctx) { d->max_texture_size = d->shader_ctx->d_func()->maxTextureSize(); @@ -1382,7 +1398,7 @@ bool QOpenGLPaintEngine::begin(QPaintDevice *pdev) glDeleteTextures(1, &d->drawable_texture); ctx->makeCurrent(); } - d->shader_ctx = d->drawable.context(); + d->shader_ctx = d->device->context(); glGenTextures(1, &d->grad_palette); qt_mask_texture_cache()->clearCache(); @@ -1417,7 +1433,7 @@ bool QOpenGLPaintEngine::end() Q_D(QOpenGLPaintEngine); d->flushDrawQueue(); d->offscreen.end(); - QGLContext *ctx = const_cast(d->drawable.context()); + QGLContext *ctx = const_cast(d->device->context()); if (!ctx->d_ptr->internal_context) { glMatrixMode(GL_TEXTURE); glPopMatrix(); @@ -1434,8 +1450,7 @@ bool QOpenGLPaintEngine::end() glPopClientAttrib(); } #endif - d->drawable.swapBuffers(); - d->drawable.doneCurrent(); + d->device->endPaint(); qt_mask_texture_cache()->maintainCache(); return true; @@ -1961,7 +1976,7 @@ void QOpenGLPaintEnginePrivate::fillVertexArray(Qt::FillRule fillRule) const int left = rect.left(); const int width = rect.width(); - const int bottom = drawable.size().height() - (rect.bottom() + 1); + const int bottom = device->size().height() - (rect.bottom() + 1); const int height = rect.height(); glScissor(left, bottom, width, height); @@ -2242,7 +2257,7 @@ void QOpenGLPaintEnginePrivate::updateDepthClip() const int left = fastClip.left(); const int width = fastClip.width(); - const int bottom = drawable.size().height() - (fastClip.bottom() + 1); + const int bottom = device->size().height() - (fastClip.bottom() + 1); const int height = fastClip.height(); glScissor(left, bottom, width, height); @@ -2325,7 +2340,7 @@ void QOpenGLPaintEngine::updateClipRegion(const QRegion &clipRegion, Qt::ClipOpe // clipping is only supported when a stencil or depth buffer is // available - if (!d->drawable.format().depth()) + if (!d->device->format().depth()) return; d->use_system_clip = false; @@ -2362,7 +2377,7 @@ void QOpenGLPaintEngine::updateClipRegion(const QRegion &clipRegion, Qt::ClipOpe path.addRect(untransformedRects[0]); path = d->matrix.map(path); - if (path.contains(QRectF(QPointF(), d->drawable.size()))) + if (path.contains(QRectF(QPointF(), d->device->size()))) isScreenClip = true; } } @@ -3369,7 +3384,7 @@ void QOpenGLPaintEnginePrivate::drawOffscreenPath(const QPainterPath &path) disableClipping(); - GLuint program = qt_gl_program_cache()->getProgram(drawable.context(), + GLuint program = qt_gl_program_cache()->getProgram(device->context(), FRAGMENT_PROGRAM_MASK_TRAPEZOID_AA, 0, true); QGLPathMaskGenerator maskGenerator(path, matrix, offscreen, program); addItem(qt_mask_texture_cache()->getMask(maskGenerator, this)); @@ -3506,7 +3521,7 @@ void QOpenGLPaintEngine::drawRects(const QRectF *rects, int rectCount) if (d->has_brush) { d->disableClipping(); - GLuint program = qt_gl_program_cache()->getProgram(d->drawable.context(), + GLuint program = qt_gl_program_cache()->getProgram(d->device->context(), FRAGMENT_PROGRAM_MASK_TRAPEZOID_AA, 0, true); if (d->matrix.type() >= QTransform::TxProject) { @@ -3916,7 +3931,7 @@ void QOpenGLPaintEnginePrivate::strokeLines(const QPainterPath &path) qreal penWidth = cpen.widthF(); - GLuint program = qt_gl_program_cache()->getProgram(drawable.context(), + GLuint program = qt_gl_program_cache()->getProgram(device->context(), FRAGMENT_PROGRAM_MASK_TRAPEZOID_AA, 0, true); QGLLineMaskGenerator maskGenerator(path, matrix, penWidth == 0 ? 1.0 : penWidth, offscreen, program); @@ -4302,7 +4317,7 @@ void QOpenGLPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QR else { GLenum target = qt_gl_preferredTextureTarget(); d->flushDrawQueue(); - d->drawable.bindTexture(pm, target); + d->device->context()->bindTexture(pm, target); drawTextureRect(pm.width(), pm.height(), r, sr, target); } } @@ -4336,9 +4351,9 @@ void QOpenGLPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pm, con d->flushDrawQueue(); if (scaled.isNull()) - d->drawable.bindTexture(pm); + d->device->context()->bindTexture(pm); else - d->drawable.bindTexture(scaled); + d->device->context()->bindTexture(scaled); updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, d->use_smooth_pixmap_transform); #ifndef QT_OPENGL_ES @@ -4404,7 +4419,7 @@ void QOpenGLPaintEngine::drawImage(const QRectF &r, const QImage &image, const Q else { GLenum target = qt_gl_preferredTextureTarget(); d->flushDrawQueue(); - d->drawable.bindTexture(image, target); + d->device->context()->bindTexture(image, target); drawTextureRect(image.width(), image.height(), r, sr, target); } } @@ -4871,7 +4886,7 @@ void QOpenGLPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textIte ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); // make sure the glyphs we want to draw are in the cache - qt_glyph_cache()->cacheGlyphs(d->drawable.context(), ti, glyphs); + qt_glyph_cache()->cacheGlyphs(d->device->context(), ti, glyphs); d->setGradientOps(Qt::SolidPattern, QRectF()); // turns off gradient ops qt_glColor4ubv(d->pen_color); @@ -4949,7 +4964,7 @@ void QOpenGLPaintEngine::drawEllipse(const QRectF &rect) glPushMatrix(); glLoadIdentity(); - GLuint program = qt_gl_program_cache()->getProgram(d->drawable.context(), + GLuint program = qt_gl_program_cache()->getProgram(d->device->context(), FRAGMENT_PROGRAM_MASK_ELLIPSE_AA, 0, true); QGLEllipseMaskGenerator maskGenerator(rect, d->matrix, @@ -5084,10 +5099,10 @@ void QOpenGLPaintEnginePrivate::copyDrawable(const QRectF &rect) QRectF screen_rect = rect.adjusted(-1, -1, 1, 1); int left = qMax(0, static_cast(screen_rect.left())); - int width = qMin(drawable.size().width() - left, static_cast(screen_rect.width()) + 1); + int width = qMin(device->size().width() - left, static_cast(screen_rect.width()) + 1); - int bottom = qMax(0, static_cast(drawable.size().height() - screen_rect.bottom())); - int height = qMin(drawable.size().height() - bottom, static_cast(screen_rect.height()) + 1); + int bottom = qMax(0, static_cast(device->size().height() - screen_rect.bottom())); + int height = qMin(device->size().height() - bottom, static_cast(screen_rect.height()) + 1); glBindTexture(GL_TEXTURE_2D, drawable_texture); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, left, bottom, left, bottom, width, height); @@ -5181,9 +5196,9 @@ void QOpenGLPaintEnginePrivate::composite(GLuint primitive, const q_vertexType * glActiveTexture(GL_TEXTURE0 + brush_texture_location); if (current_style == Qt::TexturePattern) - drawable.bindTexture(cbrush.textureImage()); + device->context()->bindTexture(cbrush.textureImage()); else - drawable.bindTexture(qt_imageForBrush(current_style, true)); + device->context()->bindTexture(qt_imageForBrush(current_style, true)); updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, use_smooth_pixmap_transform); } @@ -5191,7 +5206,7 @@ void QOpenGLPaintEnginePrivate::composite(GLuint primitive, const q_vertexType * glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray); glEnable(GL_FRAGMENT_PROGRAM_ARB); - GLuint program = qt_gl_program_cache()->getProgram(drawable.context(), + GLuint program = qt_gl_program_cache()->getProgram(device->context(), fragment_brush, fragment_composition_mode, false); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, program); @@ -5263,7 +5278,7 @@ void QOpenGLPaintEnginePrivate::drawItem(const QDrawQueueItem &item) setGradientOps(item.brush, item.location.screen_rect); composite(item.location.screen_rect, item.location.rect.topLeft() - item.location.screen_rect.topLeft() - - QPoint(0, offscreen.offscreenSize().height() - drawable.size().height())); + - QPoint(0, offscreen.offscreenSize().height() - device->size().height())); } void QOpenGLPaintEnginePrivate::flushDrawQueue() -- cgit v0.12 From b7963df603a315136b32297b861f089c0cd49acd Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Mon, 31 Aug 2009 13:28:14 +0200 Subject: Make QGLPixelBuffer work again using new QGLPaintDevice API Add a new QGLPBufferGLPaintDevice implementation which allows the GL engines to target QGLPixelBuffers again. --- src/opengl/qglpaintdevice.cpp | 7 ++++++- src/opengl/qglpixelbuffer.cpp | 8 ++++++++ src/opengl/qglpixelbuffer.h | 2 ++ src/opengl/qglpixelbuffer_p.h | 13 +++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/opengl/qglpaintdevice.cpp b/src/opengl/qglpaintdevice.cpp index f7bd2a3..9815add 100644 --- a/src/opengl/qglpaintdevice.cpp +++ b/src/opengl/qglpaintdevice.cpp @@ -41,6 +41,7 @@ #include #include +#include QGLPaintDevice::QGLPaintDevice() : m_context(0) @@ -85,11 +86,12 @@ void QGLPaintDevice::beginPaint() void QGLPaintDevice::endPaint() { + glFlush(); } QColor QGLPaintDevice::backgroundColor() const { - return QColor(); + return QApplication::palette().brush(QPalette::Background).color(); } bool QGLPaintDevice::autoFillBackground() const @@ -181,6 +183,9 @@ QGLPaintDevice* QGLPaintDevice::getDevice(QPaintDevice* pd) Q_ASSERT(qobject_cast(static_cast(pd))); glpd = &(static_cast(pd)->d_func()->glDevice); break; + case QInternal::Pbuffer: + glpd = &(static_cast(pd)->d_func()->glDevice); + break; default: qWarning("QGLPaintDevice::getDevice() - Unknown device type %d", pd->devType()); break; diff --git a/src/opengl/qglpixelbuffer.cpp b/src/opengl/qglpixelbuffer.cpp index f082ff0..f7cb3cc 100644 --- a/src/opengl/qglpixelbuffer.cpp +++ b/src/opengl/qglpixelbuffer.cpp @@ -100,6 +100,13 @@ void qgl_cleanup_glyph_cache(QGLContext *) {} extern QImage qt_gl_read_framebuffer(const QSize&, bool, bool); + +void QGLPBufferGLPaintDevice::setPBuffer(QGLPixelBuffer* pb) +{ + pbuf = pb; + setContext(pb->d_func()->qctx); +} + void QGLPixelBufferPrivate::common_init(const QSize &size, const QGLFormat &format, QGLWidget *shareWidget) { Q_Q(QGLPixelBuffer); @@ -115,6 +122,7 @@ void QGLPixelBufferPrivate::common_init(const QSize &size, const QGLFormat &form shareWidget->d_func()->glcx->d_func()->sharing = true; } + glDevice.setPBuffer(q); qctx->d_func()->paintDevice = q; qctx->d_func()->valid = true; #if defined(Q_WS_WIN) && !defined(QT_OPENGL_ES) diff --git a/src/opengl/qglpixelbuffer.h b/src/opengl/qglpixelbuffer.h index 5e81ea3..fe313a6 100644 --- a/src/opengl/qglpixelbuffer.h +++ b/src/opengl/qglpixelbuffer.h @@ -110,6 +110,8 @@ private: QScopedPointer d_ptr; friend class QGLDrawable; friend class QGLWindowSurface; + friend class QGLPaintDevice; + friend class QGLPBufferGLPaintDevice; }; QT_END_NAMESPACE diff --git a/src/opengl/qglpixelbuffer_p.h b/src/opengl/qglpixelbuffer_p.h index 74cb330..e24d1ea 100644 --- a/src/opengl/qglpixelbuffer_p.h +++ b/src/opengl/qglpixelbuffer_p.h @@ -58,6 +58,7 @@ QT_BEGIN_NAMESPACE QT_BEGIN_INCLUDE_NAMESPACE #include "QtOpenGL/qglpixelbuffer.h" #include +#include #if defined(Q_WS_X11) && !defined(QT_OPENGL_ES) #include @@ -135,6 +136,17 @@ QT_END_INCLUDE_NAMESPACE class QEglContext; + +class QGLPBufferGLPaintDevice : public QGLPaintDevice +{ +public: + virtual QPaintEngine* paintEngine() const {return pbuf->paintEngine();} + virtual QSize size() const {return pbuf->size();} + void setPBuffer(QGLPixelBuffer* pb); +private: + QGLPixelBuffer* pbuf; +}; + class QGLPixelBufferPrivate { Q_DECLARE_PUBLIC(QGLPixelBuffer) public: @@ -154,6 +166,7 @@ public: QGLPixelBuffer *q_ptr; bool invalid; QGLContext *qctx; + QGLPBufferGLPaintDevice glDevice; QGLFormat format; QGLFormat req_format; -- cgit v0.12 From e8b5bfa8a86b2d7c79aabcc4566f740f0a9afe7c Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Tue, 1 Sep 2009 15:52:44 +0200 Subject: Make QGLFramebufferObject work again using new QGLPaintDevice API This patch also refactors QGL2PaintEngineEx::ensureActive() and the logic which handles multiple paint engines rendering to the same QGLContext. In a nut-shell: * QGLPaintDevice::beginPaint() stores the currently bound FBO * QGLPaintDevice::ensureActiveTarget() makes sure that GL rendering will end up in the paint device (I.e. the right context is current and the right FBO is bound). If a different context or FBO was bound, it is _not_ remembered. * QGLPaintDevice::endPaint() restores whatever FBO was bound when beginPaint() was called. This logic allows interleaved painter rendering to multiple FBOs and contexts to work as expected. It also allows a stacked begin/end to work properly when it's mixed with native GL rendering (as far as current render target is concerened. GL state clobbering is obviously a different topic). QGLPaintDevice::context() also had to be made virtual as there's no good place to call setContext. This might be possible to change in the future though. Finally, to make this work, QGLFramebufferObjectPrivate had to be moved into it's own private header. --- .../gl2paintengineex/qpaintengineex_opengl2.cpp | 28 +--- src/opengl/opengl.pro | 1 + src/opengl/qgl.h | 4 +- src/opengl/qgl_x11.cpp | 2 +- src/opengl/qglframebufferobject.cpp | 113 ++++++--------- src/opengl/qglframebufferobject.h | 4 +- src/opengl/qglframebufferobject_p.h | 151 +++++++++++++++++++++ src/opengl/qglpaintdevice.cpp | 82 +++++------ src/opengl/qglpaintdevice_p.h | 10 +- src/opengl/qglpixelbuffer.cpp | 12 +- src/opengl/qglpixelbuffer_p.h | 2 + 11 files changed, 257 insertions(+), 152 deletions(-) create mode 100644 src/opengl/qglframebufferobject_p.h diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 8fee83d..fcfd818 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1318,13 +1318,6 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) d->ctx = d->device->context(); - if (d->ctx->d_ptr->active_engine) { - QGL2PaintEngineEx *engine = static_cast(d->ctx->d_ptr->active_engine); - QGL2PaintEngineExPrivate *p = static_cast(engine->d_ptr.data()); - p->transferMode(BrushDrawingMode); - p->device->context()->doneCurrent(); - } - d->ctx->d_ptr->active_engine = this; d->last_created_state = 0; @@ -1397,15 +1390,6 @@ bool QGL2PaintEngineEx::end() { Q_D(QGL2PaintEngineEx); QGLContext *ctx = d->ctx; - if (ctx->d_ptr->active_engine != this) { - QGL2PaintEngineEx *engine = static_cast(ctx->d_ptr->active_engine); - if (engine && engine->isActive()) { - QGL2PaintEngineExPrivate *p = static_cast(engine->d_ptr.data()); - p->transferMode(BrushDrawingMode); - p->device->context()->doneCurrent(); - } - d->device->context()->makeCurrent(); - } glUseProgram(0); d->transferMode(BrushDrawingMode); @@ -1435,20 +1419,12 @@ void QGL2PaintEngineEx::ensureActive() QGLContext *ctx = d->ctx; if (isActive() && ctx->d_ptr->active_engine != this) { - QGL2PaintEngineEx *engine = static_cast(ctx->d_ptr->active_engine); - if (engine && engine->isActive()) { - QGL2PaintEngineExPrivate *p = static_cast(engine->d_ptr.data()); - p->transferMode(BrushDrawingMode); - p->device->context()->doneCurrent(); - } - d->device->context()->makeCurrent(); - ctx->d_ptr->active_engine = this; d->needsSync = true; - } else { - d->device->context()->makeCurrent(); } + d->device->ensureActiveTarget(); + if (d->needsSync) { glViewport(0, 0, d->width, d->height); glDepthMask(false); diff --git a/src/opengl/opengl.pro b/src/opengl/opengl.pro index 2aefe41..d479c2e 100644 --- a/src/opengl/opengl.pro +++ b/src/opengl/opengl.pro @@ -22,6 +22,7 @@ HEADERS += qgl.h \ qglpixelbuffer.h \ qglpixelbuffer_p.h \ qglframebufferobject.h \ + qglframebufferobject_p.h \ qglextensions_p.h \ qglpaintdevice_p.h \ diff --git a/src/opengl/qgl.h b/src/opengl/qgl.h index 46efe23..ce50c58 100644 --- a/src/opengl/qgl.h +++ b/src/opengl/qgl.h @@ -385,7 +385,7 @@ private: friend class QGLPixelBuffer; friend class QGLPixelBufferPrivate; friend class QGLWidget; - friend class QGLDrawable; +// friend class QGLDrawable; friend class QGLWidgetPrivate; friend class QGLGlyphCache; friend class QOpenGLPaintEngine; @@ -407,6 +407,8 @@ private: #endif friend class QGLFramebufferObject; friend class QGLFramebufferObjectPrivate; + friend class QGLFBOGLPaintDevice; + friend class QGLPaintDevice; private: Q_DISABLE_COPY(QGLContext) }; diff --git a/src/opengl/qgl_x11.cpp b/src/opengl/qgl_x11.cpp index 5da128d..fc29264 100644 --- a/src/opengl/qgl_x11.cpp +++ b/src/opengl/qgl_x11.cpp @@ -1308,7 +1308,7 @@ void QGLWidget::setContext(QGLContext *context, d->glcx->doneCurrent(); QGLContext* oldcx = d->glcx; d->glcx = context; - d->glDevice.setContext(context); // ### Do this for all platforms +// d->glDevice.setContext(context); // ### Do this for all platforms if (parentWidget()) { // force creation of delay-created widgets diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp index 9990586..f60eb62 100644 --- a/src/opengl/qglframebufferobject.cpp +++ b/src/opengl/qglframebufferobject.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qglframebufferobject.h" +#include "qglframebufferobject_p.h" #include #include @@ -74,47 +75,6 @@ extern QImage qt_gl_read_framebuffer(const QSize&, bool, bool); } \ } -#ifndef QT_OPENGL_ES -#define DEFAULT_FORMAT GL_RGBA8 -#else -#define DEFAULT_FORMAT GL_RGBA -#endif - -class QGLFramebufferObjectFormatPrivate -{ -public: - QGLFramebufferObjectFormatPrivate() - : ref(1), - samples(0), - attachment(QGLFramebufferObject::NoAttachment), - target(GL_TEXTURE_2D), - internal_format(DEFAULT_FORMAT) - { - } - QGLFramebufferObjectFormatPrivate - (const QGLFramebufferObjectFormatPrivate *other) - : ref(1), - samples(other->samples), - attachment(other->attachment), - target(other->target), - internal_format(other->internal_format) - { - } - bool equals(const QGLFramebufferObjectFormatPrivate *other) - { - return samples == other->samples && - attachment == other->attachment && - target == other->target && - internal_format == other->internal_format; - } - - QAtomicInt ref; - int samples; - QGLFramebufferObject::Attachment attachment; - GLenum target; - GLenum internal_format; -}; - /*! \class QGLFramebufferObjectFormat \brief The QGLFramebufferObjectFormat class specifies the format of an OpenGL @@ -339,28 +299,32 @@ bool QGLFramebufferObjectFormat::operator!=(const QGLFramebufferObjectFormat& ot return !(*this == other); } -class QGLFramebufferObjectPrivate +void QGLFBOGLPaintDevice::ensureActiveTarget() +{ + QGLContext* ctx = const_cast(QGLContext::currentContext()); + Q_ASSERT(ctx); + const GLuint fboId = fbo->d_func()->fbo; + if (ctx->d_func()->current_fbo != fboId) { + ctx->d_func()->current_fbo = fboId; + glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId); + } +} + +void QGLFBOGLPaintDevice::beginPaint() +{ + // We let QFBO track the previously bound FBO rather than doing it + // ourselves here. This has the advantage that begin/release & bind/end + // work as expected. + wasBound = fbo->isBound(); + if (!wasBound) + fbo->bind(); +} + +void QGLFBOGLPaintDevice::endPaint() { -public: - QGLFramebufferObjectPrivate() : depth_stencil_buffer(0), valid(false), ctx(0), previous_fbo(0), engine(0) {} - ~QGLFramebufferObjectPrivate() {} - - void init(const QSize& sz, QGLFramebufferObject::Attachment attachment, - GLenum internal_format, GLenum texture_target, GLint samples = 0); - bool checkFramebufferStatus() const; - GLuint texture; - GLuint fbo; - GLuint depth_stencil_buffer; - GLuint color_buffer; - GLenum target; - QSize size; - QGLFramebufferObjectFormat format; - uint valid : 1; - QGLFramebufferObject::Attachment fbo_attachment; - QGLContextGroup *ctx; // for Windows extension ptrs - GLuint previous_fbo; - mutable QPaintEngine *engine; -}; + if (!wasBound) + fbo->release(); +} bool QGLFramebufferObjectPrivate::checkFramebufferStatus() const { @@ -406,11 +370,13 @@ bool QGLFramebufferObjectPrivate::checkFramebufferStatus() const return false; } -void QGLFramebufferObjectPrivate::init(const QSize &sz, QGLFramebufferObject::Attachment attachment, +void QGLFramebufferObjectPrivate::init(QGLFramebufferObject *q, const QSize &sz, + QGLFramebufferObject::Attachment attachment, GLenum texture_target, GLenum internal_format, GLint samples) { QGLContext *currentContext = const_cast(QGLContext::currentContext()); ctx = QGLContextPrivate::contextGroup(currentContext); + glDevice.setFBO(q); bool ext_detected = (QGLExtensions::glExtensions & QGLExtensions::FramebufferObject); if (!ext_detected || (ext_detected && !qt_resolve_framebufferobject_extensions(currentContext))) return; @@ -669,7 +635,8 @@ QGLFramebufferObject::QGLFramebufferObject(const QSize &size, GLenum target) : d_ptr(new QGLFramebufferObjectPrivate) { Q_D(QGLFramebufferObject); - d->init(size, NoAttachment, target, DEFAULT_FORMAT); + d->glDevice.setFBO(this); + d->init(this, size, NoAttachment, target, DEFAULT_FORMAT); } #ifdef Q_MAC_COMPAT_GL_FUNCTIONS @@ -693,7 +660,7 @@ QGLFramebufferObject::QGLFramebufferObject(int width, int height, GLenum target) : d_ptr(new QGLFramebufferObjectPrivate) { Q_D(QGLFramebufferObject); - d->init(QSize(width, height), NoAttachment, target, DEFAULT_FORMAT); + d->init(this, QSize(width, height), NoAttachment, target, DEFAULT_FORMAT); } /*! \overload @@ -706,7 +673,8 @@ QGLFramebufferObject::QGLFramebufferObject(const QSize &size, const QGLFramebuff : d_ptr(new QGLFramebufferObjectPrivate) { Q_D(QGLFramebufferObject); - d->init(size, format.attachment(), format.textureTarget(), format.internalTextureFormat(), format.samples()); + d->init(this, size, format.attachment(), format.textureTarget(), format.internalTextureFormat(), + format.samples()); } /*! \overload @@ -719,7 +687,8 @@ QGLFramebufferObject::QGLFramebufferObject(int width, int height, const QGLFrame : d_ptr(new QGLFramebufferObjectPrivate) { Q_D(QGLFramebufferObject); - d->init(QSize(width, height), format.attachment(), format.textureTarget(), format.internalTextureFormat(), format.samples()); + d->init(this, QSize(width, height), format.attachment(), format.textureTarget(), + format.internalTextureFormat(), format.samples()); } #ifdef Q_MAC_COMPAT_GL_FUNCTIONS @@ -728,7 +697,7 @@ QGLFramebufferObject::QGLFramebufferObject(int width, int height, QMacCompatGLen : d_ptr(new QGLFramebufferObjectPrivate) { Q_D(QGLFramebufferObject); - d->init(QSize(width, height), NoAttachment, target, DEFAULT_FORMAT); + d->init(this, QSize(width, height), NoAttachment, target, DEFAULT_FORMAT); } #endif @@ -749,7 +718,7 @@ QGLFramebufferObject::QGLFramebufferObject(int width, int height, Attachment att : d_ptr(new QGLFramebufferObjectPrivate) { Q_D(QGLFramebufferObject); - d->init(QSize(width, height), attachment, target, internal_format); + d->init(this, QSize(width, height), attachment, target, internal_format); } #ifdef Q_MAC_COMPAT_GL_FUNCTIONS @@ -759,7 +728,7 @@ QGLFramebufferObject::QGLFramebufferObject(int width, int height, Attachment att : d_ptr(new QGLFramebufferObjectPrivate) { Q_D(QGLFramebufferObject); - d->init(QSize(width, height), attachment, target, internal_format); + d->init(this, QSize(width, height), attachment, target, internal_format); } #endif @@ -780,7 +749,7 @@ QGLFramebufferObject::QGLFramebufferObject(const QSize &size, Attachment attachm : d_ptr(new QGLFramebufferObjectPrivate) { Q_D(QGLFramebufferObject); - d->init(size, attachment, target, internal_format); + d->init(this, size, attachment, target, internal_format); } #ifdef Q_MAC_COMPAT_GL_FUNCTIONS @@ -790,7 +759,7 @@ QGLFramebufferObject::QGLFramebufferObject(const QSize &size, Attachment attachm : d_ptr(new QGLFramebufferObjectPrivate) { Q_D(QGLFramebufferObject); - d->init(size, attachment, target, internal_format); + d->init(this, size, attachment, target, internal_format); } #endif diff --git a/src/opengl/qglframebufferobject.h b/src/opengl/qglframebufferobject.h index 2778ec5..29b1f97 100644 --- a/src/opengl/qglframebufferobject.h +++ b/src/opengl/qglframebufferobject.h @@ -130,7 +130,9 @@ protected: private: Q_DISABLE_COPY(QGLFramebufferObject) QScopedPointer d_ptr; - friend class QGLDrawable; +// friend class QGLDrawable; + friend class QGLPaintDevice; + friend class QGLFBOGLPaintDevice; }; class QGLFramebufferObjectFormatPrivate; diff --git a/src/opengl/qglframebufferobject_p.h b/src/opengl/qglframebufferobject_p.h new file mode 100644 index 0000000..65fcf54 --- /dev/null +++ b/src/opengl/qglframebufferobject_p.h @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenGL 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 QGLFRAMEBUFFEROBJECT_P_H +#define QGLFRAMEBUFFEROBJECT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the QLibrary class. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +QT_BEGIN_INCLUDE_NAMESPACE + +#include +#include +#include + +QT_END_INCLUDE_NAMESPACE + +#ifndef QT_OPENGL_ES +#define DEFAULT_FORMAT GL_RGBA8 +#else +#define DEFAULT_FORMAT GL_RGBA +#endif + +class QGLFramebufferObjectFormatPrivate +{ +public: + QGLFramebufferObjectFormatPrivate() + : ref(1), + samples(0), + attachment(QGLFramebufferObject::NoAttachment), + target(GL_TEXTURE_2D), + internal_format(DEFAULT_FORMAT) + { + } + QGLFramebufferObjectFormatPrivate + (const QGLFramebufferObjectFormatPrivate *other) + : ref(1), + samples(other->samples), + attachment(other->attachment), + target(other->target), + internal_format(other->internal_format) + { + } + bool equals(const QGLFramebufferObjectFormatPrivate *other) + { + return samples == other->samples && + attachment == other->attachment && + target == other->target && + internal_format == other->internal_format; + } + + QAtomicInt ref; + int samples; + QGLFramebufferObject::Attachment attachment; + GLenum target; + GLenum internal_format; +}; + +class QGLFBOGLPaintDevice : public QGLPaintDevice +{ +public: + virtual QPaintEngine* paintEngine() const {return fbo->paintEngine();} + virtual QSize size() const {return fbo->size();} + virtual QGLContext* context() const {return const_cast(QGLContext::currentContext());} + void setFBO(QGLFramebufferObject* f) {fbo = f; } + virtual void ensureActiveTarget(); + virtual void beginPaint(); + virtual void endPaint(); + +private: + bool wasBound; + QGLFramebufferObject* fbo; +}; + +class QGLFramebufferObjectPrivate +{ +public: + QGLFramebufferObjectPrivate() : depth_stencil_buffer(0), valid(false), ctx(0), previous_fbo(0), engine(0) {} + ~QGLFramebufferObjectPrivate() {} + + void init(QGLFramebufferObject *q, const QSize& sz, + QGLFramebufferObject::Attachment attachment, + GLenum internal_format, GLenum texture_target, GLint samples = 0); + bool checkFramebufferStatus() const; + GLuint texture; + GLuint fbo; + GLuint depth_stencil_buffer; + GLuint color_buffer; + GLenum target; + QSize size; + QGLFramebufferObjectFormat format; + uint valid : 1; + QGLFramebufferObject::Attachment fbo_attachment; + QGLContextGroup *ctx; // for Windows extension ptrs + GLuint previous_fbo; + mutable QPaintEngine *engine; + QGLFBOGLPaintDevice glDevice; +}; + + +QT_END_NAMESPACE + +#endif // QGLFRAMEBUFFEROBJECT_P_H diff --git a/src/opengl/qglpaintdevice.cpp b/src/opengl/qglpaintdevice.cpp index 9815add..51f9627 100644 --- a/src/opengl/qglpaintdevice.cpp +++ b/src/opengl/qglpaintdevice.cpp @@ -42,9 +42,9 @@ #include #include #include +#include QGLPaintDevice::QGLPaintDevice() - : m_context(0) { } @@ -52,41 +52,38 @@ QGLPaintDevice::~QGLPaintDevice() { } -//extern QPaintEngine* qt_gl_engine(); // in qgl.cpp -//extern QPaintEngine* qt_gl_2_engine(); // in qgl.cpp - -//inline bool qt_gl_preferGL2Engine() -//{ -//#if defined(QT_OPENGL_ES_2) -// return true; -//#else -// return (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0) -// && qgetenv("QT_GL_USE_OPENGL1ENGINE").isEmpty(); -//#endif -//} - -//QPaintEngine* QGLPaintDevice::paintEngine() const -//{ -//#if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_1_CL) -// return qt_gl_engine(); -//#elif defined(QT_OPENGL_ES_2) -// return qt_gl_2_engine(); -//#else -// if (!qt_gl_preferGL2Engine()) -// return qt_gl_engine(); -// else -// return qt_gl_2_engine(); -//#endif -//} void QGLPaintDevice::beginPaint() { - m_context->makeCurrent(); + // Record the currently bound FBO so we can restore it again + // in endPaint() + QGLContext *ctx = context(); + ctx->makeCurrent(); + m_previousFBO = ctx->d_func()->current_fbo; + if (m_previousFBO != 0) { + ctx->d_ptr->current_fbo = 0; + glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + } +} + +void QGLPaintDevice::ensureActiveTarget() +{ + QGLContext* ctx = context(); + if (ctx != QGLContext::currentContext()) + ctx->makeCurrent(); + + if (ctx->d_ptr->current_fbo != 0) + glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); } void QGLPaintDevice::endPaint() { - glFlush(); + // Make sure the FBO bound at beginPaint is re-bound again here: + QGLContext *ctx = context(); + if (m_previousFBO != ctx->d_func()->current_fbo) { + ctx->d_ptr->current_fbo = m_previousFBO; + glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_previousFBO); + } } QColor QGLPaintDevice::backgroundColor() const @@ -104,14 +101,9 @@ bool QGLPaintDevice::hasTransparentBackground() const return false; } -QGLContext* QGLPaintDevice::context() const -{ - return m_context; -} - QGLFormat QGLPaintDevice::format() const { - return m_context->format(); + return context()->format(); } QSize QGLPaintDevice::size() const @@ -119,12 +111,6 @@ QSize QGLPaintDevice::size() const return QSize(); } -void QGLPaintDevice::setContext(QGLContext* c) -{ - m_context = c; -} - - QGLWidgetGLPaintDevice::QGLWidgetGLPaintDevice() { @@ -155,15 +141,11 @@ void QGLWidgetGLPaintDevice::setWidget(QGLWidget* w) glWidget = w; } -//void QGLWidgetGLPaintDevice::beginPaint() -//{ -// glWidget->makeCurrent(); -//} - void QGLWidgetGLPaintDevice::endPaint() { if (glWidget->autoBufferSwap()) glWidget->swapBuffers(); + QGLPaintDevice::endPaint(); } @@ -172,6 +154,11 @@ QSize QGLWidgetGLPaintDevice::size() const return glWidget->size(); } +QGLContext* QGLWidgetGLPaintDevice::context() const +{ + return const_cast(glWidget->context()); +} + // returns the QGLPaintDevice for the given QPaintDevice QGLPaintDevice* QGLPaintDevice::getDevice(QPaintDevice* pd) { @@ -186,6 +173,9 @@ QGLPaintDevice* QGLPaintDevice::getDevice(QPaintDevice* pd) case QInternal::Pbuffer: glpd = &(static_cast(pd)->d_func()->glDevice); break; + case QInternal::FramebufferObject: + glpd = &(static_cast(pd)->d_func()->glDevice); + break; default: qWarning("QGLPaintDevice::getDevice() - Unknown device type %d", pd->devType()); break; diff --git a/src/opengl/qglpaintdevice_p.h b/src/opengl/qglpaintdevice_p.h index ad680a9..c5fa626 100644 --- a/src/opengl/qglpaintdevice_p.h +++ b/src/opengl/qglpaintdevice_p.h @@ -63,14 +63,14 @@ public: virtual ~QGLPaintDevice(); virtual void beginPaint(); + virtual void ensureActiveTarget(); virtual void endPaint(); virtual QColor backgroundColor() const; virtual bool autoFillBackground() const; virtual bool hasTransparentBackground() const; - // inline these? - QGLContext* context() const; + virtual QGLContext* context() const = 0; QGLFormat format() const; virtual QSize size() const; @@ -79,10 +79,11 @@ public: protected: // Inline? - void setContext(QGLContext* c); +// void setContext(QGLContext* c); private: - QGLContext* m_context; +// QGLContext* m_context; + GLuint m_previousFBO; }; @@ -102,6 +103,7 @@ public: // QGLWidgets need to do swapBufers in endPaint: virtual void endPaint(); virtual QSize size() const; + virtual QGLContext* context() const; void setWidget(QGLWidget*); diff --git a/src/opengl/qglpixelbuffer.cpp b/src/opengl/qglpixelbuffer.cpp index f7cb3cc..45ab3bc 100644 --- a/src/opengl/qglpixelbuffer.cpp +++ b/src/opengl/qglpixelbuffer.cpp @@ -101,10 +101,20 @@ void qgl_cleanup_glyph_cache(QGLContext *) {} extern QImage qt_gl_read_framebuffer(const QSize&, bool, bool); +QGLContext* QGLPBufferGLPaintDevice::context() const +{ + return pbuf->d_func()->qctx; +} + +void QGLPBufferGLPaintDevice::endPaint() { + glFlush(); + QGLPaintDevice::endPaint(); +} + void QGLPBufferGLPaintDevice::setPBuffer(QGLPixelBuffer* pb) { pbuf = pb; - setContext(pb->d_func()->qctx); +// setContext(pb->d_func()->qctx); } void QGLPixelBufferPrivate::common_init(const QSize &size, const QGLFormat &format, QGLWidget *shareWidget) diff --git a/src/opengl/qglpixelbuffer_p.h b/src/opengl/qglpixelbuffer_p.h index e24d1ea..96d41d7 100644 --- a/src/opengl/qglpixelbuffer_p.h +++ b/src/opengl/qglpixelbuffer_p.h @@ -142,6 +142,8 @@ class QGLPBufferGLPaintDevice : public QGLPaintDevice public: virtual QPaintEngine* paintEngine() const {return pbuf->paintEngine();} virtual QSize size() const {return pbuf->size();} + virtual QGLContext* context() const; + virtual void endPaint(); void setPBuffer(QGLPixelBuffer* pb); private: QGLPixelBuffer* pbuf; -- cgit v0.12 From 4feed48fdd738ed99cba86a4214e238a3e7275ed Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Mon, 7 Sep 2009 10:58:31 +0200 Subject: Move buffer clear out of the paint engine and into the QGLPaintDevices Previously, the paint engine cleared the surface's buffers in begin. This logic really belongs in QGLPaintDevice::beginPaint as not all paint devices will want this behaviour (in fact most don't). This also makes QGLPaintDevice API much simpler as the virtual getters for the clear color, etc. can be removed. It's much cleaner this way. The only possible problem is with the GL1 engine, which also cleared the accumulation & depth buffers in begin. However, the engine will also clear the depth buffer later as part of it's clipping logic. It also doesn't use the accumulation buffer, so clearing it seems unnessisary. --- .../gl2paintengineex/qpaintengineex_opengl2.cpp | 12 +--- src/opengl/qgl.cpp | 9 ++- src/opengl/qgl_p.h | 4 +- src/opengl/qglpaintdevice.cpp | 64 ++++++++++++++-------- src/opengl/qglpaintdevice_p.h | 16 ++++-- src/opengl/qpaintengine_opengl.cpp | 16 ------ 6 files changed, 58 insertions(+), 63 deletions(-) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index fcfd818..c280803 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1359,17 +1359,7 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) #endif // QGLPixmapData *source = d->drawable.copyOnBegin(); - if (d->ctx->d_func()->clear_on_painter_begin && d->device->autoFillBackground()) { - if (d->device->hasTransparentBackground()) - glClearColor(0.0, 0.0, 0.0, 0.0); - else { - const QColor &c = d->device->backgroundColor(); - float alpha = c.alphaF(); - glClearColor(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha); - } - glClear(GL_COLOR_BUFFER_BIT); - } -// else if (source) { +// if (source) { // QGLContext *ctx = d->ctx; // // d->transferMode(ImageDrawingMode); diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index ad54298..8ad9860 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -1399,7 +1399,6 @@ void QGLContextPrivate::init(QPaintDevice *dev, const QGLFormat &format) crWin = false; initDone = false; sharing = false; - clear_on_painter_begin = true; max_texture_size = -1; version_flags_cached = false; version_flags = QGLFormat::OpenGL_Version_None; @@ -4254,7 +4253,7 @@ void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font, } else { setAutoBufferSwap(false); // disable glClear() as a result of QPainter::begin() - d->glcx->d_func()->clear_on_painter_begin = false; + d->disable_clear_on_painter_begin = true; if (engine->type() == QPaintEngine::OpenGL2) { qt_save_gl_state(); #ifndef QT_OPENGL_ES_2 @@ -4284,7 +4283,7 @@ void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font, p->end(); delete p; setAutoBufferSwap(auto_swap); - d->glcx->d_func()->clear_on_painter_begin = true; + d->disable_clear_on_painter_begin = false; if (engine->type() == QPaintEngine::OpenGL2) qt_restore_gl_state(); } @@ -4427,7 +4426,7 @@ void QGLWidget::renderText(double x, double y, double z, const QString &str, con } else { setAutoBufferSwap(false); // disable glClear() as a result of QPainter::begin() - d->glcx->d_func()->clear_on_painter_begin = false; + d->disable_clear_on_painter_begin = true; if (engine->type() == QPaintEngine::OpenGL2) qt_save_gl_state(); p = new QPainter(this); @@ -4467,7 +4466,7 @@ void QGLWidget::renderText(double x, double y, double z, const QString &str, con if (engine->type() == QPaintEngine::OpenGL2) qt_restore_gl_state(); setAutoBufferSwap(auto_swap); - d->glcx->d_func()->clear_on_painter_begin = true; + d->disable_clear_on_painter_begin = false; } #ifndef QT_OPENGL_ES if (engine->type() == QPaintEngine::OpenGL2) diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index 03532c8..e86b843 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -175,6 +175,7 @@ class QGLWidgetPrivate : public QWidgetPrivate Q_DECLARE_PUBLIC(QGLWidget) public: QGLWidgetPrivate() : QWidgetPrivate() + , disable_clear_on_painter_begin(false) #ifdef Q_WS_QWS , wsurf(0) #endif @@ -197,6 +198,8 @@ public: QGLColormap cmap; QMap displayListCache; + bool disable_clear_on_painter_begin; + #if defined(Q_WS_WIN) void updateColormap(); QGLContext *olcx; @@ -295,7 +298,6 @@ public: uint sharing : 1; uint initDone : 1; uint crWin : 1; - uint clear_on_painter_begin : 1; uint internal_context : 1; uint version_flags_cached : 1; QPaintDevice *paintDevice; diff --git a/src/opengl/qglpaintdevice.cpp b/src/opengl/qglpaintdevice.cpp index 51f9627..4f000ba 100644 --- a/src/opengl/qglpaintdevice.cpp +++ b/src/opengl/qglpaintdevice.cpp @@ -86,20 +86,20 @@ void QGLPaintDevice::endPaint() } } -QColor QGLPaintDevice::backgroundColor() const -{ - return QApplication::palette().brush(QPalette::Background).color(); -} +//QColor QGLPaintDevice::backgroundColor() const +//{ +// return QApplication::palette().brush(QPalette::Background).color(); +//} -bool QGLPaintDevice::autoFillBackground() const -{ - return false; -} +//bool QGLPaintDevice::autoFillBackground() const +//{ +// return false; +//} -bool QGLPaintDevice::hasTransparentBackground() const -{ - return false; -} +//bool QGLPaintDevice::hasTransparentBackground() const +//{ +// return false; +//} QGLFormat QGLPaintDevice::format() const { @@ -112,6 +112,7 @@ QSize QGLPaintDevice::size() const } + QGLWidgetGLPaintDevice::QGLWidgetGLPaintDevice() { } @@ -121,26 +122,41 @@ QPaintEngine* QGLWidgetGLPaintDevice::paintEngine() const return glWidget->paintEngine(); } -QColor QGLWidgetGLPaintDevice::backgroundColor() const -{ - return glWidget->palette().brush(glWidget->backgroundRole()).color(); -} +//QColor QGLWidgetGLPaintDevice::backgroundColor() const +//{ +// return glWidget->palette().brush(glWidget->backgroundRole()).color(); +//} -bool QGLWidgetGLPaintDevice::autoFillBackground() const -{ - return glWidget->autoFillBackground(); -} +//bool QGLWidgetGLPaintDevice::autoFillBackground() const +//{ +// return glWidget->autoFillBackground(); +//} -bool QGLWidgetGLPaintDevice::hasTransparentBackground() const -{ - return glWidget->testAttribute(Qt::WA_TranslucentBackground); -} +//bool QGLWidgetGLPaintDevice::hasTransparentBackground() const +//{ +// return glWidget->testAttribute(Qt::WA_TranslucentBackground); +//} void QGLWidgetGLPaintDevice::setWidget(QGLWidget* w) { glWidget = w; } +void QGLWidgetGLPaintDevice::beginPaint() +{ + QGLPaintDevice::beginPaint(); + if (!glWidget->d_func()->disable_clear_on_painter_begin && glWidget->autoFillBackground()) { + if (glWidget->testAttribute(Qt::WA_TranslucentBackground)) + glClearColor(0.0, 0.0, 0.0, 0.0); + else { + const QColor &c = glWidget->palette().brush(glWidget->backgroundRole()).color(); + float alpha = c.alphaF(); + glClearColor(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha); + } + glClear(GL_COLOR_BUFFER_BIT); + } +} + void QGLWidgetGLPaintDevice::endPaint() { if (glWidget->autoBufferSwap()) diff --git a/src/opengl/qglpaintdevice_p.h b/src/opengl/qglpaintdevice_p.h index c5fa626..6d34b1b 100644 --- a/src/opengl/qglpaintdevice_p.h +++ b/src/opengl/qglpaintdevice_p.h @@ -66,9 +66,11 @@ public: virtual void ensureActiveTarget(); virtual void endPaint(); - virtual QColor backgroundColor() const; - virtual bool autoFillBackground() const; - virtual bool hasTransparentBackground() const; +// virtual void clearOnBegin() const; +// virtual QColor clearColor() const; +// virtual QColor backgroundColor() const; +// virtual bool autoFillBackground() const; +// virtual bool hasTransparentBackground() const; virtual QGLContext* context() const = 0; QGLFormat format() const; @@ -96,11 +98,13 @@ public: virtual QPaintEngine* paintEngine() const; - virtual QColor backgroundColor() const; - virtual bool autoFillBackground() const; - virtual bool hasTransparentBackground() const; +// virtual void clearOnBegin() const; +// virtual QColor clearColor() const; +// virtual bool autoFillBackground() const; +// virtual bool hasTransparentBackground() const; // QGLWidgets need to do swapBufers in endPaint: + virtual void beginPaint(); virtual void endPaint(); virtual QSize size() const; virtual QGLContext* context() const; diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp index 634067d..36a0081 100644 --- a/src/opengl/qpaintengine_opengl.cpp +++ b/src/opengl/qpaintengine_opengl.cpp @@ -1349,22 +1349,6 @@ bool QOpenGLPaintEngine::begin(QPaintDevice *pdev) d->offscreen.begin(); - if (d->device->context()->d_func()->clear_on_painter_begin && d->device->autoFillBackground()) { - - if (d->device->hasTransparentBackground()) - glClearColor(0.0, 0.0, 0.0, 0.0); - else { - const QColor &c = d->device->backgroundColor(); - glClearColor(c.redF(), c.greenF(), c.blueF(), 1.0); - } - - GLbitfield clearBits = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT; -#ifndef QT_OPENGL_ES - clearBits |= GL_ACCUM_BUFFER_BIT; -#endif - glClear(clearBits); - } - QSize sz(d->device->size()); glViewport(0, 0, sz.width(), sz.height()); // XXX (Embedded): We need a solution for GLWidgets that draw in a part or a bigger surface... glMatrixMode(GL_PROJECTION); -- cgit v0.12 From e3e7cf545116c194bd5cfe79b28ea37c8bf78219 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Mon, 7 Sep 2009 17:10:35 +0200 Subject: Make QGLWindowSurface use new QGLPaintDevice API --- src/gui/kernel/qwidget.h | 1 + src/opengl/qglpaintdevice.cpp | 9 +++--- src/opengl/qglpaintdevice_p.h | 4 ++- src/opengl/qwindowsurface_gl.cpp | 65 ++++++++++++++++++++++++++-------------- src/opengl/qwindowsurface_gl_p.h | 19 ++++++++---- 5 files changed, 65 insertions(+), 33 deletions(-) diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index 284558f..bd30cad 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -731,6 +731,7 @@ private: friend class QGLContext; friend class QGLWidget; friend class QGLWindowSurface; + friend class QGLWindowSurfaceGLPaintDevice; friend class QVGWindowSurface; friend class QX11PaintEngine; friend class QWin32PaintEngine; diff --git a/src/opengl/qglpaintdevice.cpp b/src/opengl/qglpaintdevice.cpp index 4f000ba..4cdeb76 100644 --- a/src/opengl/qglpaintdevice.cpp +++ b/src/opengl/qglpaintdevice.cpp @@ -43,6 +43,7 @@ #include #include #include +#include QGLPaintDevice::QGLPaintDevice() { @@ -106,10 +107,10 @@ QGLFormat QGLPaintDevice::format() const return context()->format(); } -QSize QGLPaintDevice::size() const -{ - return QSize(); -} +//QSize QGLPaintDevice::size() const +//{ +// return QSize(); +//} diff --git a/src/opengl/qglpaintdevice_p.h b/src/opengl/qglpaintdevice_p.h index 6d34b1b..b0e8826 100644 --- a/src/opengl/qglpaintdevice_p.h +++ b/src/opengl/qglpaintdevice_p.h @@ -62,6 +62,8 @@ public: QGLPaintDevice(); virtual ~QGLPaintDevice(); + int devType() const {return QInternal::OpenGL;} + virtual void beginPaint(); virtual void ensureActiveTarget(); virtual void endPaint(); @@ -74,7 +76,7 @@ public: virtual QGLContext* context() const = 0; QGLFormat format() const; - virtual QSize size() const; + virtual QSize size() const = 0; // returns the QGLPaintDevice for the given QPaintDevice static QGLPaintDevice* getDevice(QPaintDevice*); diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp index a85b9ae..3a6ed06 100644 --- a/src/opengl/qwindowsurface_gl.cpp +++ b/src/opengl/qwindowsurface_gl.cpp @@ -229,6 +229,7 @@ QGLWidget* qt_gl_share_widget() return _qt_gl_share_widget()->shareWidget(); } + struct QGLWindowSurfacePrivate { QGLFramebufferObject *fbo; @@ -248,10 +249,49 @@ struct QGLWindowSurfacePrivate QSize size; QList buffers; + QGLWindowSurfaceGLPaintDevice glDevice; + QGLWindowSurface* q_ptr; }; QGLFormat QGLWindowSurface::surfaceFormat; +void QGLWindowSurfaceGLPaintDevice::endPaint() +{ + glFlush(); + QGLPaintDevice::endPaint(); +} + +QSize QGLWindowSurfaceGLPaintDevice::size() const +{ + return d->size; +} + +QGLContext* QGLWindowSurfaceGLPaintDevice::context() const +{ + return d->ctx; +} + + +int QGLWindowSurfaceGLPaintDevice::metric(PaintDeviceMetric m) const +{ + return d->q_ptr->window()->metric(m); +} + +Q_GLOBAL_STATIC(QGL2PaintEngineEx, qt_gl_window_surface_2_engine) + +#if !defined (QT_OPENGL_ES_2) +Q_GLOBAL_STATIC(QOpenGLPaintEngine, qt_gl_window_surface_engine) +#endif + +QPaintEngine *QGLWindowSurfaceGLPaintDevice::paintEngine() const +{ +#if !defined(QT_OPENGL_ES_2) + if (!qt_gl_preferGL2Engine()) + return qt_gl_window_surface_engine(); +#endif + return qt_gl_window_surface_2_engine(); +} + QGLWindowSurface::QGLWindowSurface(QWidget *window) : QWindowSurface(window), d_ptr(new QGLWindowSurfacePrivate) { @@ -263,6 +303,8 @@ QGLWindowSurface::QGLWindowSurface(QWidget *window) d_ptr->tried_fbo = false; d_ptr->tried_pb = false; d_ptr->destructive_swap_buffers = qgetenv("QT_GL_SWAPBUFFER_PRESERVE").isNull(); + d_ptr->glDevice.d = d_ptr; + d_ptr->q_ptr = this; } QGLWindowSurface::~QGLWindowSurface() @@ -320,27 +362,6 @@ void QGLWindowSurface::hijackWindow(QWidget *widget) qDebug() << "hijackWindow() context created for" << widget << d_ptr->contexts.size(); } -Q_GLOBAL_STATIC(QGL2PaintEngineEx, qt_gl_window_surface_2_engine) - -#if !defined (QT_OPENGL_ES_2) -Q_GLOBAL_STATIC(QOpenGLPaintEngine, qt_gl_window_surface_engine) -#endif - -/*! \reimp */ -QPaintEngine *QGLWindowSurface::paintEngine() const -{ -#if !defined(QT_OPENGL_ES_2) - if (!qt_gl_preferGL2Engine()) - return qt_gl_window_surface_engine(); -#endif - return qt_gl_window_surface_2_engine(); -} - -int QGLWindowSurface::metric(PaintDeviceMetric m) const -{ - return window()->metric(m); -} - QGLContext *QGLWindowSurface::context() const { return d_ptr->ctx; @@ -354,7 +375,7 @@ QPaintDevice *QGLWindowSurface::paintDevice() return d_ptr->pb; if (d_ptr->ctx) - return this; + return &d_ptr->glDevice; QGLContext *ctx = reinterpret_cast(window()->d_func()->extraData()->glContext); ctx->makeCurrent(); diff --git a/src/opengl/qwindowsurface_gl_p.h b/src/opengl/qwindowsurface_gl_p.h index ad583b2..7b18f2e 100644 --- a/src/opengl/qwindowsurface_gl_p.h +++ b/src/opengl/qwindowsurface_gl_p.h @@ -56,6 +56,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -65,7 +66,18 @@ class QRegion; class QWidget; struct QGLWindowSurfacePrivate; -class QGLWindowSurface : public QObject, public QWindowSurface, public QPaintDevice +class QGLWindowSurfaceGLPaintDevice : public QGLPaintDevice +{ +public: + QPaintEngine* paintEngine() const; + void endPaint(); + QSize size() const; + int metric(PaintDeviceMetric m) const; + QGLContext* context() const; + QGLWindowSurfacePrivate* d; +}; + +class QGLWindowSurface : public QObject, public QWindowSurface // , public QPaintDevice { Q_OBJECT public: @@ -87,11 +99,6 @@ public: static QGLFormat surfaceFormat; - QPaintEngine *paintEngine() const; - -protected: - int metric(PaintDeviceMetric metric) const; - private slots: void deleted(QObject *object); -- cgit v0.12 From 31d8058a32a1d2d2d6bc1ba3d48f5a382d7b87a7 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Tue, 8 Sep 2009 15:09:00 +0200 Subject: Make QGLPixmapData work with the new QGLPaintDevice API This patch changes the ordering of QGL2PaintEngine::begin a bit because QGLPixmapData needs to use the paint engine's drawTexture method within beginPaint(). Also, this initialises needsSync to true and removes the setState call. So now all the state initialisation is done in ensureActive rather than begin. --- .../gl2paintengineex/qpaintengineex_opengl2.cpp | 24 +---- src/opengl/qglframebufferobject.cpp | 9 ++ src/opengl/qglframebufferobject_p.h | 3 +- src/opengl/qglpaintdevice.cpp | 29 ++++-- src/opengl/qglpaintdevice_p.h | 4 +- src/opengl/qpixmapdata_gl.cpp | 116 ++++++++++++++------- src/opengl/qpixmapdata_gl_p.h | 52 +++++---- 7 files changed, 152 insertions(+), 85 deletions(-) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index c280803..e028e63 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1321,7 +1321,6 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) d->ctx->d_ptr->active_engine = this; d->last_created_state = 0; - d->device->beginPaint(); QSize sz = d->device->size(); d->width = sz.width(); d->height = sz.height(); @@ -1333,8 +1332,6 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) d->shaderManager = new QGLEngineShaderManager(d->ctx); - glViewport(0, 0, d->width, d->height); - d->brushTextureDirty = true; d->brushUniformsDirty = true; d->matrixDirty = true; @@ -1343,10 +1340,12 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) d->simpleShaderDepthUniformDirty = true; d->depthUniformDirty = true; d->opacityUniformDirty = true; - d->needsSync = false; - + d->needsSync = true; d->use_system_clip = !systemClip().isEmpty(); + + d->device->beginPaint(); + if (!d->inRenderText) { glDisable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); @@ -1358,21 +1357,6 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) glDisable(GL_MULTISAMPLE); #endif -// QGLPixmapData *source = d->drawable.copyOnBegin(); -// if (source) { -// QGLContext *ctx = d->ctx; -// -// d->transferMode(ImageDrawingMode); -// -// glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); -// source->bind(false); -// -// QRect rect(0, 0, source->width(), source->height()); -// d->updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false); -// d->drawTexture(QRectF(rect), QRectF(rect), rect.size(), true); -// } - - d->systemStateChanged(); return true; } diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp index f60eb62..9dbf5c8 100644 --- a/src/opengl/qglframebufferobject.cpp +++ b/src/opengl/qglframebufferobject.cpp @@ -299,6 +299,12 @@ bool QGLFramebufferObjectFormat::operator!=(const QGLFramebufferObjectFormat& ot return !(*this == other); } +void QGLFBOGLPaintDevice::setFBO(QGLFramebufferObject* f) +{ + fbo = f; + m_thisFBO = fbo->d_func()->fbo; // This shouldn't be needed +} + void QGLFBOGLPaintDevice::ensureActiveTarget() { QGLContext* ctx = const_cast(QGLContext::currentContext()); @@ -377,6 +383,7 @@ void QGLFramebufferObjectPrivate::init(QGLFramebufferObject *q, const QSize &sz, QGLContext *currentContext = const_cast(QGLContext::currentContext()); ctx = QGLContextPrivate::contextGroup(currentContext); glDevice.setFBO(q); + bool ext_detected = (QGLExtensions::glExtensions & QGLExtensions::FramebufferObject); if (!ext_detected || (ext_detected && !qt_resolve_framebufferobject_extensions(currentContext))) return; @@ -389,6 +396,8 @@ void QGLFramebufferObjectPrivate::init(QGLFramebufferObject *q, const QSize &sz, glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER_EXT, fbo); + glDevice.setFBO(q); + QT_CHECK_GLERROR(); // init texture if (samples == 0) { diff --git a/src/opengl/qglframebufferobject_p.h b/src/opengl/qglframebufferobject_p.h index 65fcf54..58e6505 100644 --- a/src/opengl/qglframebufferobject_p.h +++ b/src/opengl/qglframebufferobject_p.h @@ -110,11 +110,12 @@ public: virtual QPaintEngine* paintEngine() const {return fbo->paintEngine();} virtual QSize size() const {return fbo->size();} virtual QGLContext* context() const {return const_cast(QGLContext::currentContext());} - void setFBO(QGLFramebufferObject* f) {fbo = f; } virtual void ensureActiveTarget(); virtual void beginPaint(); virtual void endPaint(); + void setFBO(QGLFramebufferObject* f); + private: bool wasBound; QGLFramebufferObject* fbo; diff --git a/src/opengl/qglpaintdevice.cpp b/src/opengl/qglpaintdevice.cpp index 4cdeb76..15ea217 100644 --- a/src/opengl/qglpaintdevice.cpp +++ b/src/opengl/qglpaintdevice.cpp @@ -44,8 +44,10 @@ #include #include #include +#include QGLPaintDevice::QGLPaintDevice() + : m_thisFBO(0) { } @@ -56,14 +58,17 @@ QGLPaintDevice::~QGLPaintDevice() void QGLPaintDevice::beginPaint() { - // Record the currently bound FBO so we can restore it again - // in endPaint() + // Make sure our context is the current one: QGLContext *ctx = context(); - ctx->makeCurrent(); + if (ctx != QGLContext::currentContext()) + ctx->makeCurrent(); + + // Record the currently bound FBO so we can restore it again + // in endPaint() and bind this device's FBO m_previousFBO = ctx->d_func()->current_fbo; - if (m_previousFBO != 0) { - ctx->d_ptr->current_fbo = 0; - glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + if (m_previousFBO != m_thisFBO) { + ctx->d_ptr->current_fbo = m_thisFBO; + glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_thisFBO); } } @@ -73,8 +78,10 @@ void QGLPaintDevice::ensureActiveTarget() if (ctx != QGLContext::currentContext()) ctx->makeCurrent(); - if (ctx->d_ptr->current_fbo != 0) - glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + if (ctx->d_ptr->current_fbo != m_thisFBO) { + ctx->d_ptr->current_fbo = m_thisFBO; + glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_thisFBO); + } } void QGLPaintDevice::endPaint() @@ -193,6 +200,12 @@ QGLPaintDevice* QGLPaintDevice::getDevice(QPaintDevice* pd) case QInternal::FramebufferObject: glpd = &(static_cast(pd)->d_func()->glDevice); break; + case QInternal::Pixmap: { + QPixmapData* pmd = static_cast(pd)->pixmapData(); + Q_ASSERT(pmd->classId() == QPixmapData::OpenGLClass); + glpd = static_cast(pmd)->glDevice(); + break; + } default: qWarning("QGLPaintDevice::getDevice() - Unknown device type %d", pd->devType()); break; diff --git a/src/opengl/qglpaintdevice_p.h b/src/opengl/qglpaintdevice_p.h index b0e8826..a175b8c 100644 --- a/src/opengl/qglpaintdevice_p.h +++ b/src/opengl/qglpaintdevice_p.h @@ -84,10 +84,10 @@ public: protected: // Inline? // void setContext(QGLContext* c); - + GLuint m_previousFBO; + GLuint m_thisFBO; private: // QGLContext* m_context; - GLuint m_previousFBO; }; diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp index a394716..ae616a8 100644 --- a/src/opengl/qpixmapdata_gl.cpp +++ b/src/opengl/qpixmapdata_gl.cpp @@ -127,6 +127,76 @@ void QGLFramebufferObjectPool::release(QGLFramebufferObject *fbo) m_fbos << fbo; } + +QPaintEngine* QGLPixmapGLPaintDevice::paintEngine() const +{ + return data->paintEngine(); +} + +void QGLPixmapGLPaintDevice::beginPaint() +{ + if (!data->isValid()) + return; + + // QGLPaintDevice::beginPaint will store the current binding and replace + // it with m_thisFBO: + m_thisFBO = data->m_renderFbo->handle(); + QGLPaintDevice::beginPaint(); + + Q_ASSERT(data->paintEngine()->type() == QPaintEngine::OpenGL2); + + // QPixmap::fill() is deferred until now, where we actually need to do the fill: + if (data->needsFill()) { + const QColor &c = data->fillColor(); + float alpha = c.alphaF(); + glClearColor(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha); + glClear(GL_COLOR_BUFFER_BIT); + } + else if (!data->isUninitialized()) { + // If the pixmap (GL Texture) has valid content (it has been + // uploaded from an image or rendered into before), we need to + // copy it from the texture to the render FBO. + + // Pass false to tell bind to _not_ copy the FBO into the texture! + GLuint texId = data->bind(false); + + QGL2PaintEngineEx* pe = static_cast(data->paintEngine()); + QRect rect(0, 0, data->width(), data->height()); + pe->drawTexture(QRectF(rect), texId, rect.size(), QRectF(rect)); + } +} + +void QGLPixmapGLPaintDevice::endPaint() +{ + if (!data->isValid()) + return; + + data->copyBackFromRenderFbo(false); + + data->m_renderFbo->release(); + qgl_fbo_pool()->release(data->m_renderFbo); + data->m_renderFbo = 0; + + // Base's endPaint will restore the previous FBO binding + QGLPaintDevice::endPaint(); +} + +QGLContext* QGLPixmapGLPaintDevice::context() const +{ + data->ensureCreated(); + return data->m_ctx; +} + +QSize QGLPixmapGLPaintDevice::size() const +{ + return data->size(); +} + +void QGLPixmapGLPaintDevice::setPixmapData(QGLPixmapData* d) +{ + data = d; +} + static int qt_gl_pixmap_serial = 0; QGLPixmapData::QGLPixmapData(PixelType type) @@ -139,6 +209,7 @@ QGLPixmapData::QGLPixmapData(PixelType type) , m_hasAlpha(false) { setSerialNumber(++qt_gl_pixmap_serial); + m_glDevice.setPixmapData(this); } QGLPixmapData::~QGLPixmapData() @@ -232,11 +303,6 @@ void QGLPixmapData::ensureCreated() const m_texture.options &= ~QGLContext::MemoryManagedBindOption; } -QGLFramebufferObject *QGLPixmapData::fbo() const -{ - return m_renderFbo; -} - void QGLPixmapData::fromImage(const QImage &image, Qt::ImageConversionFlags) { @@ -412,31 +478,6 @@ void QGLPixmapData::copyBackFromRenderFbo(bool keepCurrentFboBound) const glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo); } -void QGLPixmapData::swapBuffers() -{ - if (!isValid()) - return; - - copyBackFromRenderFbo(false); - m_renderFbo->release(); - - qgl_fbo_pool()->release(m_renderFbo); - - m_renderFbo = 0; -} - -void QGLPixmapData::makeCurrent() -{ - if (isValid() && m_renderFbo) - m_renderFbo->bind(); -} - -void QGLPixmapData::doneCurrent() -{ - if (isValid() && m_renderFbo) - m_renderFbo->release(); -} - bool QGLPixmapData::useFramebufferObjects() { return QGLFramebufferObject::hasOpenGLFramebufferObjects() @@ -485,6 +526,10 @@ QPaintEngine* QGLPixmapData::paintEngine() const return m_source.paintEngine(); } + +// If copyBack is true, bind will copy the contents of the render +// FBO to the texture (which is not bound to the texture, as it's +// a multisample FBO). GLuint QGLPixmapData::bind(bool copyBack) const { if (m_renderFbo && copyBack) { @@ -504,12 +549,6 @@ GLuint QGLPixmapData::bind(bool copyBack) const return id; } -GLuint QGLPixmapData::textureId() const -{ - ensureCreated(); - return m_texture.id; -} - QGLTexture* QGLPixmapData::texture() const { return &m_texture; @@ -548,4 +587,9 @@ int QGLPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const } } +QGLPaintDevice *QGLPixmapData::glDevice() const +{ + return &m_glDevice; +} + QT_END_NAMESPACE diff --git a/src/opengl/qpixmapdata_gl_p.h b/src/opengl/qpixmapdata_gl_p.h index ab1ff47..31ae7c7 100644 --- a/src/opengl/qpixmapdata_gl_p.h +++ b/src/opengl/qpixmapdata_gl_p.h @@ -57,12 +57,14 @@ #include "qgl.h" #include "private/qpixmapdata_p.h" +#include "private/qglpaintdevice_p.h" QT_BEGIN_NAMESPACE class QPaintEngine; class QGLFramebufferObject; class QGLFramebufferObjectFormat; +class QGLPixmapData; class QGLFramebufferObjectPool { @@ -76,31 +78,50 @@ private: QGLFramebufferObjectPool* qgl_fbo_pool(); + +class QGLPixmapGLPaintDevice : public QGLPaintDevice +{ +public: + QPaintEngine* paintEngine() const; + + void beginPaint(); + void endPaint(); + QGLContext* context() const; + QSize size() const; + + void setPixmapData(QGLPixmapData*); +private: + QGLPixmapData *data; +}; + + class QGLPixmapData : public QPixmapData { public: QGLPixmapData(PixelType type); ~QGLPixmapData(); - bool isValid() const; - + // Re-implemented from QPixmapData: void resize(int width, int height); - void fromImage(const QImage &image, - Qt::ImageConversionFlags flags); + void fromImage(const QImage &image, Qt::ImageConversionFlags flags); void copy(const QPixmapData *data, const QRect &rect); - bool scroll(int dx, int dy, const QRect &rect); - void fill(const QColor &color); bool hasAlphaChannel() const; QImage toImage() const; QPaintEngine *paintEngine() const; + int metric(QPaintDevice::PaintDeviceMetric metric) const; + // For accessing as a target: + QGLPaintDevice *glDevice() const; + + // For accessing as a source: + bool isValidContext(const QGLContext *ctx) const; GLuint bind(bool copyBack = true) const; - GLuint textureId() const; QGLTexture *texture() const; - bool isValidContext(const QGLContext *ctx) const; +private: + bool isValid() const; void ensureCreated() const; @@ -109,22 +130,13 @@ public: bool needsFill() const { return m_hasFillColor; } QColor fillColor() const { return m_fillColor; } - QSize size() const { return QSize(w, h); } - - QGLFramebufferObject *fbo() const; - void makeCurrent(); - void doneCurrent(); - void swapBuffers(); -protected: - int metric(QPaintDevice::PaintDeviceMetric metric) const; - -private: QGLPixmapData(const QGLPixmapData &other); QGLPixmapData &operator=(const QGLPixmapData &other); void copyBackFromRenderFbo(bool keepCurrentFboBound) const; + QSize size() const { return QSize(w, h); } static bool useFramebufferObjects(); @@ -145,6 +157,10 @@ private: mutable bool m_hasFillColor; mutable bool m_hasAlpha; + + mutable QGLPixmapGLPaintDevice m_glDevice; + + friend class QGLPixmapGLPaintDevice; }; QT_END_NAMESPACE -- cgit v0.12 From f6f099e33773e5739ef89681bc97a1a91ff168c8 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Tue, 8 Sep 2009 18:03:00 +0200 Subject: Cleanup of QGLPaintDevice before it goes in This is the last patch in the QGLPaintDevice series. Although previous patches have not been reviewed individually, Samuel's reviewed QGLPaintDevice API and all the changes as the code stands with this patch. Reviewed-by: Samuel --- src/opengl/qgl.cpp | 237 ------------------------------------- src/opengl/qgl.h | 1 - src/opengl/qgl_p.h | 56 +-------- src/opengl/qgl_x11.cpp | 2 - src/opengl/qglframebufferobject.h | 1 - src/opengl/qglpaintdevice.cpp | 66 +++-------- src/opengl/qglpaintdevice_p.h | 100 +++------------- src/opengl/qglpixelbuffer.cpp | 1 - src/opengl/qpaintengine_opengl.cpp | 4 +- 9 files changed, 38 insertions(+), 430 deletions(-) diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 8ad9860..a0b2d3a 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -4851,243 +4851,6 @@ Q_OPENGL_EXPORT const QString qt_gl_library_name() } #endif -#if 0 -void QGLDrawable::setDevice(QPaintDevice *pdev) -{ - wasBound = false; - widget = 0; - buffer = 0; - fbo = 0; -#ifdef Q_WS_QWS - wsurf = 0; -#endif - -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - if (pdev->devType() == QInternal::Pixmap) { - QPixmapData *data = static_cast(pdev)->pixmapData(); - Q_ASSERT(data->classId() == QPixmapData::OpenGLClass); - pixmapData = static_cast(data); - - fbo = pixmapData->fbo(); - } -#else - Q_ASSERT(pdev->devType() != QInternal::Pixmap); -#endif - - if (pdev->devType() == QInternal::Widget) - widget = static_cast(pdev); - else if (pdev->devType() == QInternal::Pbuffer) - buffer = static_cast(pdev); - else if (pdev->devType() == QInternal::FramebufferObject) - fbo = static_cast(pdev); -#ifdef Q_WS_QWS - else if (pdev->devType() == QInternal::UnknownDevice) - wsurf = static_cast(pdev)->windowSurface(); -#elif !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - else if (pdev->devType() == QInternal::UnknownDevice) - wsurf = static_cast(pdev); -#endif -} - -void QGLDrawable::swapBuffers() -{ - if (widget) { - if (widget->autoBufferSwap()) - widget->swapBuffers(); -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - } else if (pixmapData) { - pixmapData->swapBuffers(); -#endif - } else { - glFlush(); - } -} - -void QGLDrawable::makeCurrent() -{ - previous_fbo = 0; -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - if (!pixmapData && !fbo) { -#else - if (!fbo) { -#endif - QGLContext *ctx = context(); - previous_fbo = ctx->d_ptr->current_fbo; - ctx->d_ptr->current_fbo = 0; - if (previous_fbo) - glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); - } - - if (widget) - widget->makeCurrent(); -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - else if (pixmapData) - pixmapData->makeCurrent(); -#endif - else if (buffer) - buffer->makeCurrent(); -#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)) - else if (wsurf) - wsurf->context()->makeCurrent(); -#endif - else if (fbo) { - wasBound = fbo->isBound(); - if (!wasBound) - fbo->bind(); - } -} - -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) -QGLPixmapData *QGLDrawable::copyOnBegin() const -{ - if (!pixmapData || pixmapData->isUninitialized()) - return 0; - return pixmapData; -} -#endif - -void QGLDrawable::doneCurrent() -{ -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - if (pixmapData) { - pixmapData->doneCurrent(); - return; - } -#endif - - if (previous_fbo) { - QGLContext *ctx = context(); - ctx->d_ptr->current_fbo = previous_fbo; - glBindFramebuffer(GL_FRAMEBUFFER_EXT, previous_fbo); - } - - if (fbo && !wasBound) - fbo->release(); -} - -QSize QGLDrawable::size() const -{ - if (widget) { - return QSize(widget->d_func()->glcx->device()->width(), - widget->d_func()->glcx->device()->height()); -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - } else if (pixmapData) { - return pixmapData->size(); -#endif - } else if (buffer) { - return buffer->size(); - } else if (fbo) { - return fbo->size(); - } -#ifdef Q_WS_QWS - else if (wsurf) - return wsurf->window()->frameSize(); -#elif !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - else if (wsurf) - return QSize(wsurf->width(), wsurf->height()); -#endif - return QSize(); -} - -QGLFormat QGLDrawable::format() const -{ - if (widget) - return widget->format(); - else if (buffer) - return buffer->format(); -#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)) - else if (wsurf) - return wsurf->context()->format(); -#endif - else if (fbo && QGLContext::currentContext()) { - QGLFormat fmt = QGLContext::currentContext()->format(); - fmt.setStencil(fbo->attachment() == QGLFramebufferObject::CombinedDepthStencil); - fmt.setDepth(fbo->attachment() != QGLFramebufferObject::NoAttachment); - return fmt; - } - - return QGLFormat(); -} - -GLuint QGLDrawable::bindTexture(const QImage &image, GLenum target, GLint format, - QGLContext::BindOptions options) -{ - QGLTexture *texture = 0; - options |= QGLContext::MemoryManagedBindOption; - if (widget) - texture = widget->d_func()->glcx->d_func()->bindTexture(image, target, format, options); - else if (buffer) - texture = buffer->d_func()->qctx->d_func()->bindTexture(image, target, format, options); - else if (fbo && QGLContext::currentContext()) - texture = const_cast(QGLContext::currentContext())->d_func()->bindTexture(image, target, format, options); -#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)) - else if (wsurf) - texture = wsurf->context()->d_func()->bindTexture(image, target, format, options); -#endif - return texture->id; -} - -GLuint QGLDrawable::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, - QGLContext::BindOptions options) -{ - QGLTexture *texture = 0; - if (widget) - texture = widget->d_func()->glcx->d_func()->bindTexture(pixmap, target, format, options); - else if (buffer) - texture = buffer->d_func()->qctx->d_func()->bindTexture(pixmap, target, format, options); - else if (fbo && QGLContext::currentContext()) - texture = const_cast(QGLContext::currentContext())->d_func()->bindTexture(pixmap, target, format, options); -#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)) - else if (wsurf) - texture = wsurf->context()->d_func()->bindTexture(pixmap, target, format, options); -#endif - return texture->id; -} - -QColor QGLDrawable::backgroundColor() const -{ - if (widget) - return widget->palette().brush(widget->backgroundRole()).color(); -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - else if (pixmapData) - return pixmapData->fillColor(); -#endif - return QApplication::palette().brush(QPalette::Background).color(); -} - -bool QGLDrawable::hasTransparentBackground() const -{ - return widget && widget->testAttribute(Qt::WA_TranslucentBackground); -} - -QGLContext *QGLDrawable::context() const -{ - if (widget) - return widget->d_func()->glcx; - else if (buffer) - return buffer->d_func()->qctx; - else if (fbo) - return const_cast(QGLContext::currentContext()); -#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)) - else if (wsurf) - return wsurf->context(); -#endif - return 0; -} - -bool QGLDrawable::autoFillBackground() const -{ - if (widget) - return widget->autoFillBackground(); -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - else if (pixmapData) - return pixmapData->needsFill(); -#endif - else - return false; -} -#endif - bool QGLShareRegister::checkSharing(const QGLContext *context1, const QGLContext *context2) { bool sharing = (context1 && context2 && context1->d_ptr->group == context2->d_ptr->group); return sharing; diff --git a/src/opengl/qgl.h b/src/opengl/qgl.h index ce50c58..151c7c4 100644 --- a/src/opengl/qgl.h +++ b/src/opengl/qgl.h @@ -385,7 +385,6 @@ private: friend class QGLPixelBuffer; friend class QGLPixelBufferPrivate; friend class QGLWidget; -// friend class QGLDrawable; friend class QGLWidgetPrivate; friend class QGLGlyphCache; friend class QOpenGLPaintEngine; diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index e86b843..b10d5da 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -191,7 +191,7 @@ public: bool renderCxPm(QPixmap *pixmap); void cleanupColormaps(); - QGLContext *glcx; // ### Keep for compatability with QGLDrawable (if that gets left in) + QGLContext *glcx; QGLWidgetGLPaintDevice glDevice; bool autoSwap; @@ -341,60 +341,6 @@ Q_SIGNALS: void aboutToDestroyContext(const QGLContext *context); }; -#if 0 -class QGLPixelBuffer; -class QGLFramebufferObject; -class QWSGLWindowSurface; -class QGLWindowSurface; -class QGLPixmapData; -class QGLDrawable { -public: - QGLDrawable() : widget(0), buffer(0), fbo(0) -#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)) - , wsurf(0) -#endif -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - , pixmapData(0) -#endif - {} - void setDevice(QPaintDevice *pdev); - void swapBuffers(); - void makeCurrent(); - void doneCurrent(); - QSize size() const; - QGLFormat format() const; - GLuint bindTexture(const QImage &image, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA, - QGLContext::BindOptions = QGLContext::InternalBindOption); - GLuint bindTexture(const QPixmap &pixmap, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA, - QGLContext::BindOptions = QGLContext::InternalBindOption); - QColor backgroundColor() const; - QGLContext *context() const; - bool autoFillBackground() const; - bool hasTransparentBackground() const; - -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - QGLPixmapData *copyOnBegin() const; -#endif - -private: - bool wasBound; - QGLWidget *widget; - QGLPixelBuffer *buffer; - QGLFramebufferObject *fbo; -#ifdef Q_WS_QWS - QWSGLWindowSurface *wsurf; -#elif !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - QGLWindowSurface *wsurf; -#endif - -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - QGLPixmapData *pixmapData; -#endif - int previous_fbo; -}; - -#endif - // GL extension definitions class QGLExtensions { public: diff --git a/src/opengl/qgl_x11.cpp b/src/opengl/qgl_x11.cpp index fc29264..a7376b2 100644 --- a/src/opengl/qgl_x11.cpp +++ b/src/opengl/qgl_x11.cpp @@ -41,7 +41,6 @@ #include "qgl.h" #include "qgl_p.h" -#include "qglpaintdevice_p.h" #include "qmap.h" #include "qapplication.h" @@ -1308,7 +1307,6 @@ void QGLWidget::setContext(QGLContext *context, d->glcx->doneCurrent(); QGLContext* oldcx = d->glcx; d->glcx = context; -// d->glDevice.setContext(context); // ### Do this for all platforms if (parentWidget()) { // force creation of delay-created widgets diff --git a/src/opengl/qglframebufferobject.h b/src/opengl/qglframebufferobject.h index 29b1f97..6efbb73 100644 --- a/src/opengl/qglframebufferobject.h +++ b/src/opengl/qglframebufferobject.h @@ -130,7 +130,6 @@ protected: private: Q_DISABLE_COPY(QGLFramebufferObject) QScopedPointer d_ptr; -// friend class QGLDrawable; friend class QGLPaintDevice; friend class QGLFBOGLPaintDevice; }; diff --git a/src/opengl/qglpaintdevice.cpp b/src/opengl/qglpaintdevice.cpp index 15ea217..a89b884 100644 --- a/src/opengl/qglpaintdevice.cpp +++ b/src/opengl/qglpaintdevice.cpp @@ -9,8 +9,8 @@ ** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. +** 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 @@ -21,20 +21,20 @@ ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** 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. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** ** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -46,6 +46,8 @@ #include #include +QT_BEGIN_NAMESPACE + QGLPaintDevice::QGLPaintDevice() : m_thisFBO(0) { @@ -94,33 +96,16 @@ void QGLPaintDevice::endPaint() } } -//QColor QGLPaintDevice::backgroundColor() const -//{ -// return QApplication::palette().brush(QPalette::Background).color(); -//} - -//bool QGLPaintDevice::autoFillBackground() const -//{ -// return false; -//} - -//bool QGLPaintDevice::hasTransparentBackground() const -//{ -// return false; -//} - QGLFormat QGLPaintDevice::format() const { return context()->format(); } -//QSize QGLPaintDevice::size() const -//{ -// return QSize(); -//} +////////////////// QGLWidgetGLPaintDevice ////////////////// + QGLWidgetGLPaintDevice::QGLWidgetGLPaintDevice() { } @@ -130,21 +115,6 @@ QPaintEngine* QGLWidgetGLPaintDevice::paintEngine() const return glWidget->paintEngine(); } -//QColor QGLWidgetGLPaintDevice::backgroundColor() const -//{ -// return glWidget->palette().brush(glWidget->backgroundRole()).color(); -//} - -//bool QGLWidgetGLPaintDevice::autoFillBackground() const -//{ -// return glWidget->autoFillBackground(); -//} - -//bool QGLWidgetGLPaintDevice::hasTransparentBackground() const -//{ -// return glWidget->testAttribute(Qt::WA_TranslucentBackground); -//} - void QGLWidgetGLPaintDevice::setWidget(QGLWidget* w) { glWidget = w; @@ -214,4 +184,4 @@ QGLPaintDevice* QGLPaintDevice::getDevice(QPaintDevice* pd) return glpd; } - +QT_END_NAMESPACE diff --git a/src/opengl/qglpaintdevice_p.h b/src/opengl/qglpaintdevice_p.h index a175b8c..32a1275 100644 --- a/src/opengl/qglpaintdevice_p.h +++ b/src/opengl/qglpaintdevice_p.h @@ -9,8 +9,8 @@ ** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. +** 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 @@ -21,20 +21,20 @@ ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** 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. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** ** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -53,9 +53,13 @@ // We mean it. // + #include #include + +QT_BEGIN_NAMESPACE + class QGLPaintDevice : public QPaintDevice { public: @@ -68,12 +72,6 @@ public: virtual void ensureActiveTarget(); virtual void endPaint(); -// virtual void clearOnBegin() const; -// virtual QColor clearColor() const; -// virtual QColor backgroundColor() const; -// virtual bool autoFillBackground() const; -// virtual bool hasTransparentBackground() const; - virtual QGLContext* context() const = 0; QGLFormat format() const; virtual QSize size() const = 0; @@ -82,12 +80,8 @@ public: static QGLPaintDevice* getDevice(QPaintDevice*); protected: - // Inline? -// void setContext(QGLContext* c); GLuint m_previousFBO; GLuint m_thisFBO; -private: -// QGLContext* m_context; }; @@ -100,11 +94,6 @@ public: virtual QPaintEngine* paintEngine() const; -// virtual void clearOnBegin() const; -// virtual QColor clearColor() const; -// virtual bool autoFillBackground() const; -// virtual bool hasTransparentBackground() const; - // QGLWidgets need to do swapBufers in endPaint: virtual void beginPaint(); virtual void endPaint(); @@ -118,59 +107,6 @@ private: QGLWidget *glWidget; }; - - -/* -Replaces: - -class QGLPixelBuffer; -class QGLFramebufferObject; -class QWSGLWindowSurface; -class QGLWindowSurface; -class QGLPixmapData; -class QGLDrawable { -public: - QGLDrawable() : widget(0), buffer(0), fbo(0) -#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)) - , wsurf(0) -#endif -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - , pixmapData(0) -#endif - {} - void setDevice(QPaintDevice *pdev); - void swapBuffers(); - void makeCurrent(); - void doneCurrent(); - QSize size() const; - QGLFormat format() const; - GLuint bindTexture(const QImage &image, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA); - GLuint bindTexture(const QPixmap &pixmap, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA); - QColor backgroundColor() const; - QGLContext *context() const; - bool autoFillBackground() const; - bool hasTransparentBackground() const; - -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - QGLPixmapData *copyOnBegin() const; -#endif - -private: - bool wasBound; - QGLWidget *widget; - QGLPixelBuffer *buffer; - QGLFramebufferObject *fbo; -#ifdef Q_WS_QWS - QWSGLWindowSurface *wsurf; -#elif !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - QGLWindowSurface *wsurf; -#endif - -#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) - QGLPixmapData *pixmapData; -#endif - int previous_fbo; -}; -*/ +QT_END_NAMESPACE #endif // QGLPAINTDEVICE_P_H diff --git a/src/opengl/qglpixelbuffer.cpp b/src/opengl/qglpixelbuffer.cpp index 45ab3bc..b6a919c 100644 --- a/src/opengl/qglpixelbuffer.cpp +++ b/src/opengl/qglpixelbuffer.cpp @@ -114,7 +114,6 @@ void QGLPBufferGLPaintDevice::endPaint() { void QGLPBufferGLPaintDevice::setPBuffer(QGLPixelBuffer* pb) { pbuf = pb; -// setContext(pb->d_func()->qctx); } void QGLPixelBufferPrivate::common_init(const QSize &size, const QGLFormat &format, QGLWidget *shareWidget) diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp index 36a0081..34fff10 100644 --- a/src/opengl/qpaintengine_opengl.cpp +++ b/src/opengl/qpaintengine_opengl.cpp @@ -287,7 +287,6 @@ public Q_SLOTS: } private: -// QGLDrawable drawable; QGLPaintDevice* device; QGLFramebufferObject *offscreen; @@ -436,7 +435,7 @@ inline void QGLOffscreen::release() DEBUG_ONCE_STR("QGLOffscreen: releasing offscreen"); if (drawable_fbo) - device->context()->makeCurrent(); //### + device->ensureActiveTarget(); //### else offscreen->release(); @@ -765,7 +764,6 @@ public: GLubyte pen_color[4]; GLubyte brush_color[4]; QTransform::TransformationType txop; -// QGLDrawable drawable; QGLPaintDevice* device; QGLOffscreen offscreen; -- cgit v0.12 From eeb31d201371c5e0a118d5d89616e0ed092c836b Mon Sep 17 00:00:00 2001 From: David Boddie Date: Tue, 8 Sep 2009 19:05:52 +0200 Subject: Doc: A timeline's current value is not reset when the duration changes. Task-number: 219152 Reviewed-by: Trust Me --- src/corelib/tools/qtimeline.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/corelib/tools/qtimeline.cpp b/src/corelib/tools/qtimeline.cpp index 052c456..28ec963 100644 --- a/src/corelib/tools/qtimeline.cpp +++ b/src/corelib/tools/qtimeline.cpp @@ -388,6 +388,10 @@ void QTimeLine::setDirection(Direction direction) By default, this value is 1000 (i.e., 1 second), but you can change this by either passing a duration to QTimeLine's constructor, or by calling setDuration(). The duration must be larger than 0. + + \note Changing the duration does not cause the current time to be reset + to zero or the new duration. You also need to call setCurrentTime() with + the desired value. */ int QTimeLine::duration() const { -- cgit v0.12 From 83335faff7f33808b8253fa64f5d59e0f5fe0836 Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Tue, 8 Sep 2009 11:16:54 -0700 Subject: memset DFBWindowDescription to 0 This makes debugging easier. Reviewed-by: TrustMe --- src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp index b1ffe69..82c2f81 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp @@ -127,6 +127,8 @@ void QDirectFBWindowSurface::createWindow(const QRect &rect) qFatal("QDirectFBWindowSurface: Unable to get primary display layer!"); DFBWindowDescription description; + memset(&description, 0, sizeof(DFBWindowDescription)); + description.caps = DWCAPS_NODECORATION|DWCAPS_DOUBLEBUFFER; description.flags = DWDESC_CAPS|DWDESC_SURFACE_CAPS|DWDESC_PIXELFORMAT|DWDESC_HEIGHT|DWDESC_WIDTH|DWDESC_POSX|DWDESC_POSY; -- cgit v0.12 From 381c17536c4fdf1a7fc3ee47c7d1d29cdce4b1f2 Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Tue, 8 Sep 2009 12:04:48 -0700 Subject: Fix define in QDirectFBScreen It's QT_NO_DIRECTFB.*, not QT_DIRECTFB_NO.* Reviewed-by: TrustMe --- src/plugins/gfxdrivers/directfb/qdirectfbscreen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h index 46d06ef..5955f27 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h @@ -66,7 +66,7 @@ QT_MODULE(Gui) #if !defined QT_DIRECTFB_IMAGECACHE && !defined QT_NO_DIRECTFB_IMAGECACHE #define QT_NO_DIRECTFB_IMAGECACHE #endif -#if !defined QT_DIRECTFB_NO_IMAGEPROVIDER && !defined QT_DIRECTFB_IMAGEPROVIDER +#if !defined QT_NO_DIRECTFB_IMAGEPROVIDER && !defined QT_DIRECTFB_IMAGEPROVIDER #define QT_DIRECTFB_IMAGEPROVIDER #endif #if !defined QT_DIRECTFB_IMAGEPROVIDER_KEEPALIVE && !defined QT_NO_DIRECTFB_IMAGEPROVIDER_KEEPALIVE -- cgit v0.12 From d0b29a5238def992bf7946d5c3eb36129b0cc44b Mon Sep 17 00:00:00 2001 From: Bill King Date: Wed, 9 Sep 2009 08:21:47 +1000 Subject: Fixes "Out of heap space" error when compiling on some setups. The original fix was for "out of stack space" due to to low a value, this one is for too high a value. --- demos/boxes/boxes.pro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demos/boxes/boxes.pro b/demos/boxes/boxes.pro index 59c9132..4963fb9 100644 --- a/demos/boxes/boxes.pro +++ b/demos/boxes/boxes.pro @@ -44,6 +44,6 @@ wince*: { win32-msvc* { QMAKE_CXXFLAGS -= -Zm200 QMAKE_CFLAGS -= -Zm200 - QMAKE_CXXFLAGS += -Zm1200 - QMAKE_CFLAGS += -Zm1200 + QMAKE_CXXFLAGS += -Zm500 + QMAKE_CFLAGS += -Zm500 } -- cgit v0.12 From f52dc5bf1e885c9a4d226c2484249e7d9faf0a99 Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Tue, 8 Sep 2009 10:20:36 -0700 Subject: Fix QDirectFBPixmapData::fromImage This fix should optimize pixmap loading on most platforms and also fixes a bug on a certain hardware where the alpha channel of an image was not retained upon loading it. This patch also takes care of handling dithering better in QDirectFBPixmapData::fromImage(). Reviewed-by: Donald Carr --- .../gfxdrivers/directfb/qdirectfbpixmap.cpp | 36 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp index 6550683..f88055e 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp @@ -330,17 +330,17 @@ bool QDirectFBPixmapData::fromDataBufferDescription(const DFBDataBufferDescripti #endif -void QDirectFBPixmapData::fromImage(const QImage &image, +void QDirectFBPixmapData::fromImage(const QImage &img, Qt::ImageConversionFlags flags) { - if (image.depth() == 1) { - fromImage(image.convertToFormat(screen->alphaPixmapFormat()), flags); + if (img.depth() == 1) { + fromImage(img.convertToFormat(screen->alphaPixmapFormat()), flags); return; } - if (image.hasAlphaChannel() + if (img.hasAlphaChannel() #ifndef QT_NO_DIRECTFB_OPAQUE_DETECTION - && (flags & Qt::NoOpaqueDetection || QDirectFBPixmapData::hasAlphaChannel(image)) + && (flags & Qt::NoOpaqueDetection || QDirectFBPixmapData::hasAlphaChannel(img)) #endif ) { alpha = true; @@ -349,13 +349,37 @@ void QDirectFBPixmapData::fromImage(const QImage &image, alpha = false; imageFormat = screen->pixelFormat(); } + QImage image; + if (flags != Qt::AutoColor) { + image = img.convertToFormat(imageFormat, flags); + flags = Qt::AutoColor; + } else { + image = img; + } + + IDirectFBSurface *imageSurface = screen->createDFBSurface(image, image.format(), QDirectFBScreen::DontTrackSurface); + if (!imageSurface) { + qWarning("QDirectFBPixmapData::fromImage()"); + invalidate(); + return; + } - dfbSurface = screen->createDFBSurface(image, imageFormat, QDirectFBScreen::TrackSurface|QDirectFBScreen::NoPreallocated); + dfbSurface = screen->createDFBSurface(image.size(), imageFormat, QDirectFBScreen::TrackSurface); if (!dfbSurface) { qWarning("QDirectFBPixmapData::fromImage()"); invalidate(); return; } + + if (image.hasAlphaChannel()) { + dfbSurface->Clear(dfbSurface, 0, 0, 0, 0); + dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_BLEND_ALPHACHANNEL); + } else { + dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX); + } + dfbSurface->Blit(dfbSurface, imageSurface, 0, 0, 0); + imageSurface->Release(imageSurface); + w = image.width(); h = image.height(); is_null = (w <= 0 || h <= 0); -- cgit v0.12 From cce03d9a3c95dd81c31003e0a96c5bb3dca6f0c0 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Sep 2009 08:44:59 +1000 Subject: Don't add newlines in rewriter as it messes up error reporting. --- src/declarative/qml/qmlrewrite.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qmlrewrite.cpp b/src/declarative/qml/qmlrewrite.cpp index 3f35160..5166c96 100644 --- a/src/declarative/qml/qmlrewrite.cpp +++ b/src/declarative/qml/qmlrewrite.cpp @@ -73,8 +73,8 @@ QString RewriteBinding::rewrite(QString code, unsigned position, unsigned startOfStatement = node->firstSourceLocation().begin() - _position; unsigned endOfStatement = node->lastSourceLocation().end() - _position; - _writer->replace(startOfStatement, 0, QLatin1String("(function() {\n")); - _writer->replace(endOfStatement, 0, QLatin1String("\n})")); + _writer->replace(startOfStatement, 0, QLatin1String("(function() { ")); + _writer->replace(endOfStatement, 0, QLatin1String(" })")); w.write(&code); -- cgit v0.12 From 0f1ad0fb5bc5d601a4379eefe14a60c0b9fc6454 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Sep 2009 11:12:21 +1000 Subject: Make sure animations convert between float and double when needed. --- src/declarative/util/qmlanimation.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 6047d4a..3edbc5f 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -1442,8 +1442,7 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParallelAnimation,QmlParallelAni void QmlPropertyAnimationPrivate::convertVariant(QVariant &variant, int type) { if (variant.type() != QVariant::String) { - if ((uint)type < QVariant::UserType) - variant.convert((QVariant::Type)type); + variant.convert((QVariant::Type)type); return; } -- cgit v0.12 From d9fadadd4f78a5be9deca1da26be7d86f4da338c Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Sep 2009 11:15:35 +1000 Subject: Remove debug. --- src/declarative/qml/parser/qmljslexer.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/declarative/qml/parser/qmljslexer.cpp b/src/declarative/qml/parser/qmljslexer.cpp index 3be1710..f302733 100644 --- a/src/declarative/qml/parser/qmljslexer.cpp +++ b/src/declarative/qml/parser/qmljslexer.cpp @@ -43,8 +43,6 @@ #include "config.h" #endif -#include - #include "qmljsengine_p.h" #include "qmljslexer_p.h" #include "qmljsgrammar_p.h" @@ -98,7 +96,7 @@ Lexer::Lexer(Engine *eng, bool tokenizeComments) parenthesesCount(0), prohibitAutomaticSemicolon(false), tokenizeComments(tokenizeComments) -{qDebug()<<"--- new lexer"; +{ driver->setLexer(this); // allocate space for read buffers buffer8 = new char[size8]; @@ -650,7 +648,6 @@ int Lexer::lex() setDone(Other); } else state = Start; - qDebug() << "--- state is InSingleLineComment @" << startlineno << ":"<addComment(startpos, tokenLength(), startlineno, startcolumn); } else if (current == 0) { driver->addComment(startpos, tokenLength(), startlineno, startcolumn); -- cgit v0.12 From 80bd5e0206314155e8542520b4ec2fc5d9416e0e Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 9 Sep 2009 11:36:21 +1000 Subject: Some changes to repeater seem to have been missed. Found the old names in some pre-review code, which I had to update. --- src/declarative/QmlChanges.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 9bf4b10..db1c73a 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -59,6 +59,8 @@ WebView: status -> statusText WebView: mouseX -> clickX (parameter to onDoubleClick) WebView: mouseY -> clickY (parameter to onDoubleClick) WebView: cacheSize -> pixelCacheSize +Repeater: component -> delegate +Repeater: dataSource -> model Additions: MouseRegion: add "acceptedButtons" property -- cgit v0.12 From a626641fafcf5f3a2e904cd0679f62ee70e19f4e Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 9 Sep 2009 11:37:49 +1000 Subject: Positioners now implictly have the height and width of the childrenRect Also removed the now uneccesary height and width bindings from the twitter demo login screen. --- demos/declarative/twitter/content/AuthView.qml | 8 +++----- src/declarative/fx/qfxpositioners.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/demos/declarative/twitter/content/AuthView.qml b/demos/declarative/twitter/content/AuthView.qml index 7d0d865..febee94 100644 --- a/demos/declarative/twitter/content/AuthView.qml +++ b/demos/declarative/twitter/content/AuthView.qml @@ -5,10 +5,9 @@ import "../../flickr/mobile" Item { id: wrapper Column { - width: childrenRect.width; height:childrenRect.height; anchors.centerIn: parent + anchors.centerIn: parent spacing: 20 Row{ - width: childrenRect.width; height:childrenRect.height; spacing: 4 Text { width: 100 @@ -39,7 +38,6 @@ Item { } } Row{ - width: childrenRect.width; height:childrenRect.height; spacing: 4 Text { width: 100 @@ -65,8 +63,8 @@ Item { } } Item{ - width: childrenRect.width; anchors.horizontalCenter: parent.horizontalCenter - height: childrenRect.height + width: childrenRect.width; height:childrenRect.height; + anchors.horizontalCenter: parent.horizontalCenter Button { x: 10 width: 100 diff --git a/src/declarative/fx/qfxpositioners.cpp b/src/declarative/fx/qfxpositioners.cpp index bad4944..e4500aa 100644 --- a/src/declarative/fx/qfxpositioners.cpp +++ b/src/declarative/fx/qfxpositioners.cpp @@ -251,6 +251,18 @@ void QFxBasePositioner::prePositioning() d->_animated.clear(); doPositioning(); finishApplyTransitions(); + //Set implicit size to the size of its children + //###To keep this valid, do we need to update on pos change as well? + qreal h = 0.0f; + qreal w = 0.0f; + foreach(QFxItem *child, d->_items){ + if(!child->isVisible() || child->opacity() <= 0) + continue; + h = qMax(h, child->y() + child->height()); + w = qMax(w, child->x() + child->width()); + } + setImplicitHeight(h); + setImplicitWidth(w); } void QFxBasePositioner::applyTransition(const QList >& changes, QFxItem* target, QmlStateOperation::ActionList &actions) -- cgit v0.12 From c253b86a77e8228479fec21c7237a54103ab95ee Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 9 Sep 2009 11:57:09 +1000 Subject: TextInput bug fixes -Cursor is now visible when at the end of the line -Left and Right key events are now ignored if it is at the end of the line. --- src/declarative/fx/qfxtextinput.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxtextinput.cpp b/src/declarative/fx/qfxtextinput.cpp index 4dd29cd..39a0187 100644 --- a/src/declarative/fx/qfxtextinput.cpp +++ b/src/declarative/fx/qfxtextinput.cpp @@ -480,6 +480,13 @@ void QFxTextInput::focusChanged(bool hasFocus) void QFxTextInput::keyPressEvent(QKeyEvent* ev) { Q_D(QFxTextInput); + if((d->control->cursor() == 0 && ev->key() == Qt::Key_Left) + || (d->control->cursor() == d->control->text().length() + && ev->key() == Qt::Key_Right)){ + //ignore moving off the end + ev->ignore(); + return; + } d->control->processKeyEvent(ev); if (!ev->isAccepted()) QFxPaintedItem::keyPressEvent(ev); @@ -500,6 +507,7 @@ bool QFxTextInput::event(QEvent* ev) Q_D(QFxTextInput); //Anything we don't deal with ourselves, pass to the control switch(ev->type()){ + case QEvent::KeyPress: case QEvent::GraphicsSceneMousePress: break; default: @@ -645,7 +653,8 @@ void QFxTextInput::updateSize() setImplicitHeight(d->control->height()); //d->control->width() is max width, not current width QFontMetrics fm = QFontMetrics(d->font); - setImplicitWidth(fm.boundingRect(d->control->text()).width()+1); + setImplicitWidth(fm.width(d->control->text())+1); + //setImplicitWidth(d->control->naturalWidth());//### This fn should be coming into 4.6 shortly, and might be faster setContentsSize(QSize(width(), height())); } -- cgit v0.12 From a8db74459f4d155990e140bdf32e01985d6383a9 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 9 Sep 2009 13:06:27 +1000 Subject: API review for ListView and GridView --- src/declarative/fx/qfxgridview.h | 4 ++-- src/declarative/fx/qfxlistview.h | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h index 4f2146d..c93b031 100644 --- a/src/declarative/fx/qfxgridview.h +++ b/src/declarative/fx/qfxgridview.h @@ -61,14 +61,14 @@ class Q_DECLARATIVE_EXPORT QFxGridView : public QFxFlickable Q_CLASSINFO("DefaultProperty", "delegate") Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QFxItem *current READ currentItem NOTIFY currentIndexChanged) + Q_PROPERTY(QFxItem *current READ currentItem NOTIFY currentIndexChanged) //### currentItem Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) Q_PROPERTY(Flow flow READ flow WRITE setFlow) Q_PROPERTY(bool wrap READ isWrapEnabled WRITE setWrapEnabled) Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) - Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellSizeChanged) + Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellSizeChanged) //### columnCount, rowCount Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellSizeChanged) public: diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index dbab57b..7a2c6d4 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -50,6 +50,11 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) +//### get rid of z = index and set known z-value (1 for items, 0 for highlight) +//### incrementCurrentIndex(), decrementCurrentIndex() slots +//### default Keys.OnUp/DownPressed handler + + class QFxVisualModel; class QFxListViewAttached; class QFxListViewPrivate; @@ -61,17 +66,17 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_ENUMS(CurrentItemPositioning) Q_PROPERTY(QVariant model READ model WRITE setModel) Q_CLASSINFO("DefaultProperty", "delegate") - Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) //### what happens if delegate is not a QFxItem? Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QFxItem *current READ currentItem NOTIFY currentIndexChanged) + Q_PROPERTY(QFxItem *current READ currentItem NOTIFY currentIndexChanged) //### currentItem Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) - Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) - Q_PROPERTY(CurrentItemPositioning currentItemPositioning READ currentItemPositioning WRITE setCurrentItemPositioning) + Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) //### highlightFollowsCurrentItem + Q_PROPERTY(CurrentItemPositioning currentItemPositioning READ currentItemPositioning WRITE setCurrentItemPositioning) //### mode Q_PROPERTY(int snapPosition READ snapPosition WRITE setSnapPosition) - Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) + Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) //### qreal Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) - Q_PROPERTY(bool wrap READ isWrapEnabled WRITE setWrapEnabled) + Q_PROPERTY(bool wrap READ isWrapEnabled WRITE setWrapEnabled) //### keyNavigationWraps, stops at end when held Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) Q_PROPERTY(QString sectionExpression READ sectionExpression WRITE setSectionExpression NOTIFY sectionExpressionChanged) Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged) @@ -98,6 +103,11 @@ public: bool autoHighlight() const; void setAutoHighlight(bool); + //### QSpan preferredHighlightRange + //### bool strictlyEnforceHighlightRange + + //### don't jump around unnecessarily + //### fix highlight for snapAuto enum CurrentItemPositioning { Free, Snap, SnapAuto }; CurrentItemPositioning currentItemPositioning() const; void setCurrentItemPositioning(CurrentItemPositioning mode); -- cgit v0.12 From 14e787b7e5abc1d665ba0e0229f60525283b1e38 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 9 Sep 2009 14:12:45 +1000 Subject: Modifying ListModel from JS: work for structured data too. --- examples/declarative/listview/dynamic.qml | 48 ++++++++++++++++++-- src/declarative/util/qmllistmodel.cpp | 75 ++++++++++++++++++++++--------- src/declarative/util/qmllistmodel.h | 8 ++-- 3 files changed, 104 insertions(+), 27 deletions(-) diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml index 58ce4b4..5111cec 100644 --- a/examples/declarative/listview/dynamic.qml +++ b/examples/declarative/listview/dynamic.qml @@ -2,42 +2,74 @@ import Qt 4.6 Item { width: 300 - height: 300 + height: 500 ListModel { id: FruitModel ListElement { name: "Apple" cost: 2.45 + attributes: [ + ListElement { description: "Core" }, + ListElement { description: "Deciduous" } + ] } ListElement { name: "Banana" cost: 1.95 + attributes: [ + ListElement { description: "Tropical" }, + ListElement { description: "Seedless" } + ] } ListElement { name: "Cumquat" cost: 3.25 + types: [ "Small", "Smaller" ] + attributes: [ + ListElement { description: "Citrus" } + ] } ListElement { name: "Durian" cost: 9.95 + attributes: [ + ListElement { description: "Tropical" }, + ListElement { description: "Smelly" } + ] } ListElement { name: "Elderberry" cost: 0.05 + attributes: [ + ListElement { description: "Berry" } + ] } ListElement { name: "Fig" cost: 0.25 + attributes: [ + ListElement { description: "Flower" } + ] } } Component { id: FruitDelegate Item { - width: parent.width; height: 35 - Text { font.pixelSize: 24; text: name } + width: parent.width; height: 55 + Text { id: Label; font.pixelSize: 24; text: name } Text { font.pixelSize: 24; text: '$'+Number(cost).toFixed(2); anchors.right: ItemButtons.left } + Row { + anchors.top: Label.bottom + spacing: 5 + Repeater { + model: attributes + Component { + Text { text: description } + } + } + } Row { id: ItemButtons anchors.right: parent.right @@ -79,7 +111,15 @@ Item { anchors.bottom: parent.bottom id: Buttons Image { source: "content/pics/add.png" - MouseRegion { anchors.fill: parent; onClicked: FruitModel.append({"name":"Pizza", "cost":5.95}) } + MouseRegion { anchors.fill: parent; + onClicked: { + FruitModel.append({ + "name":"Pizza", + "cost":5.95, + "attributes":[{"description": "Supreme"},{"description": "Margarita"}] + }) + } + } } Image { source: "content/pics/add.png" MouseRegion { anchors.fill: parent; onClicked: FruitModel.insert(0,{"name":"Pizza", "cost":5.95}) } diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index a5ae60f..dc6b02b 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -47,6 +47,7 @@ #include "qmlopenmetaobject.h" #include #include "qmllistmodel.h" +#include Q_DECLARE_METATYPE(QListModelInterface *) @@ -68,6 +69,8 @@ struct ListModelData ListInstruction *instructions() const { return (ListInstruction *)((char *)this + sizeof(ListModelData)); } }; +static void dump(ModelNode *node, int ind); + /*! \qmlclass ListModel \brief The ListModel element defines a free-form list data source. @@ -140,7 +143,7 @@ struct ListModelData name: "Banana" cost: 1.95 attributes: [ - ListElement { description: "Tropical" } + ListElement { description: "Tropical" }, ListElement { description: "Seedless" } ] } @@ -238,6 +241,42 @@ struct ModelNode return objectCache; } + void setListValue(const QScriptValue& valuelist) { + QScriptValueIterator it(valuelist); + values.clear(); + while (it.hasNext()) { + it.next(); + ModelNode *value = new ModelNode; + QScriptValue v = it.value(); + if (v.isArray()) { + value->setListValue(v); + } else if (v.isObject()) { + value->setObjectValue(v); + } else { + value->values << v.toVariant(); + } + values.append(qVariantFromValue(value)); + + } + } + + void setObjectValue(const QScriptValue& valuemap) { + QScriptValueIterator it(valuemap); + while (it.hasNext()) { + it.next(); + ModelNode *value = new ModelNode; + QScriptValue v = it.value(); + if (v.isArray()) { + value->setListValue(v); + } else if (v.isObject()) { + value->setObjectValue(v); + } else { + value->values << v.toVariant(); + } + properties.insert(it.name(),value); + } + } + void setProperty(const QString& prop, const QVariant& val) { QHash::const_iterator it = properties.find(prop); if (it != properties.end()) { @@ -429,7 +468,7 @@ void QmlListModel::remove(int index) \sa set() append() */ -void QmlListModel::insert(int index, const QVariantMap& valuemap) +void QmlListModel::insert(int index, const QScriptValue& valuemap) { if (!_root) _root = new ModelNode; @@ -438,12 +477,7 @@ void QmlListModel::insert(int index, const QVariantMap& valuemap) return; } ModelNode *mn = new ModelNode; - for (QVariantMap::const_iterator it=valuemap.begin(); it!=valuemap.end(); ++it) { - addRole(it.key()); - ModelNode *value = new ModelNode; - value->values << it.value(); - mn->properties.insert(it.key(),value); - } + mn->setObjectValue(valuemap); _root->values.insert(index,qVariantFromValue(mn)); emit itemsInserted(index,1); } @@ -506,17 +540,16 @@ void QmlListModel::move(int from, int to, int n) \sa set() remove() */ -void QmlListModel::append(const QVariantMap& valuemap) +void QmlListModel::append(const QScriptValue& valuemap) { + if (!valuemap.isObject()) { + qWarning("ListModel::append: value is not an object"); + return; + } if (!_root) _root = new ModelNode; ModelNode *mn = new ModelNode; - for (QVariantMap::const_iterator it=valuemap.begin(); it!=valuemap.end(); ++it) { - addRole(it.key()); - ModelNode *value = new ModelNode; - value->values << it.value(); - mn->properties.insert(it.key(),value); - } + mn->setObjectValue(valuemap); _root->values << qVariantFromValue(mn); emit itemsInserted(count()-1,1); } @@ -536,7 +569,7 @@ void QmlListModel::append(const QVariantMap& valuemap) \sa append() */ -void QmlListModel::set(int index, const QVariantMap& valuemap) +void QmlListModel::set(int index, const QScriptValue& valuemap) { if (!_root) _root = new ModelNode; @@ -548,12 +581,14 @@ void QmlListModel::set(int index, const QVariantMap& valuemap) else { ModelNode *node = qvariant_cast(_root->values.at(index)); QList roles; - for (QVariantMap::const_iterator it=valuemap.begin(); it!=valuemap.end(); ++it) { - node->setProperty(it.key(),it.value()); - int r = roleStrings.indexOf(it.key()); + node->setObjectValue(valuemap); + QScriptValueIterator it(valuemap); + while (it.hasNext()) { + it.next(); + int r = roleStrings.indexOf(it.name()); if (r<0) { r = roleStrings.count(); - roleStrings << it.key(); + roleStrings << it.name(); } roles.append(r); } diff --git a/src/declarative/util/qmllistmodel.h b/src/declarative/util/qmllistmodel.h index 8bef347..7bb94cf 100644 --- a/src/declarative/util/qmllistmodel.h +++ b/src/declarative/util/qmllistmodel.h @@ -50,6 +50,8 @@ #include #include #include +#include + QT_BEGIN_HEADER @@ -74,9 +76,9 @@ public: Q_INVOKABLE void clear(); Q_INVOKABLE void remove(int index); - Q_INVOKABLE void append(const QVariantMap& valuemap); - Q_INVOKABLE void insert(int index, const QVariantMap& valuemap); - Q_INVOKABLE void set(int index, const QVariantMap& valuemap); + Q_INVOKABLE void append(const QScriptValue&); + Q_INVOKABLE void insert(int index, const QScriptValue&); + Q_INVOKABLE void set(int index, const QScriptValue&); Q_INVOKABLE void set(int index, const QString& property, const QVariant& value); Q_INVOKABLE void move(int from, int to, int count); -- cgit v0.12 From a9f368a5e61d1e2a73010353e66810a9b3bf7157 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 9 Sep 2009 14:19:44 +1000 Subject: Fix bug with keypad navigation Navigation test now passes. --- src/declarative/fx/qfxtextinput.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/declarative/fx/qfxtextinput.cpp b/src/declarative/fx/qfxtextinput.cpp index 39a0187..6bd793b 100644 --- a/src/declarative/fx/qfxtextinput.cpp +++ b/src/declarative/fx/qfxtextinput.cpp @@ -483,11 +483,11 @@ void QFxTextInput::keyPressEvent(QKeyEvent* ev) if((d->control->cursor() == 0 && ev->key() == Qt::Key_Left) || (d->control->cursor() == d->control->text().length() && ev->key() == Qt::Key_Right)){ - //ignore moving off the end + //ignore when moving off the end ev->ignore(); - return; + }else{ + d->control->processKeyEvent(ev); } - d->control->processKeyEvent(ev); if (!ev->isAccepted()) QFxPaintedItem::keyPressEvent(ev); } -- cgit v0.12 From ed8e89eaddca1c508151ef5913f0d383d3071b99 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 9 Sep 2009 14:43:26 +1000 Subject: Fix destruction of ModelNodes (fix crash-on-exit). --- src/declarative/util/qmllistmodel.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index 82942f6..8e5ea9c 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -200,7 +200,7 @@ class ModelObject : public QObject { Q_OBJECT public: - ModelObject(ModelNode *); + ModelObject(); void setValue(const QByteArray &name, const QVariant &val) { @@ -208,8 +208,6 @@ public: } private: - ModelNode *_node; - bool _haveProperties; QmlOpenMetaObject *_mo; }; @@ -231,7 +229,7 @@ struct ModelNode ModelObject *object() { if (!objectCache) { - objectCache = new ModelObject(this); + objectCache = new ModelObject(); QHash::iterator it; for (it = properties.begin(); it != properties.end(); ++it) { if (!(*it)->values.isEmpty()) @@ -294,8 +292,8 @@ struct ModelNode ModelObject *objectCache; }; -ModelObject::ModelObject(ModelNode *node) -: _node(node), _haveProperties(false), _mo(new QmlOpenMetaObject(this)) +ModelObject::ModelObject() +: _mo(new QmlOpenMetaObject(this)) { } @@ -841,7 +839,8 @@ ModelNode::~ModelNode() ModelNode *node = qvariant_cast(values.at(ii)); if (node) { delete node; node = 0; } } - if (modelCache) { delete modelCache; modelCache = 0; } + if (modelCache) { modelCache->_root = 0/* ==this */; delete modelCache; modelCache = 0; } + if (objectCache) { delete objectCache; } } QT_END_NAMESPACE -- cgit v0.12 From d2f5a32ff6c06e6a1cad9772f89d4b042eb0c9ef Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 9 Sep 2009 15:01:35 +1000 Subject: Fix up some of the tests Update to work with the latest changes, like 'import Qt 4.6'. Tests affected: DateTimeFormatter Layouts (Positioners) ListView (Still not passing) --- .../datetimeformatter/tst_datetimeformatter.cpp | 14 +++- .../auto/declarative/layouts/data/grid-spacing.qml | 20 +++--- tests/auto/declarative/layouts/data/grid.qml | 20 +++--- .../layouts/data/horizontal-spacing.qml | 12 ++-- tests/auto/declarative/layouts/data/horizontal.qml | 12 ++-- .../declarative/layouts/data/vertical-spacing.qml | 12 ++-- tests/auto/declarative/layouts/data/vertical.qml | 12 ++-- tests/auto/declarative/layouts/tst_layouts.cpp | 76 +++++++--------------- tests/auto/declarative/listview/data/listview.qml | 4 ++ tests/auto/declarative/listview/tst_listview.cpp | 28 ++++---- 10 files changed, 96 insertions(+), 114 deletions(-) diff --git a/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp b/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp index 67cff02..556912e 100644 --- a/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp +++ b/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp @@ -2,6 +2,7 @@ #include #include #include +#include class tst_datetimeformatter : public QObject { @@ -18,8 +19,11 @@ private slots: void tst_datetimeformatter::date() { QmlEngine engine; - QmlComponent formatterComponent(&engine, "DateTimeFormatter { date: \"2008-12-24\" }"); + QmlComponent formatterComponent(&engine, QByteArray("import Qt 4.6\n DateTimeFormatter { date: \"2008-12-24\" }"), + QUrl("file://")); QmlDateTimeFormatter *formatter = qobject_cast(formatterComponent.create()); + if(formatterComponent.isError()) + qDebug() << formatterComponent.errors(); QVERIFY(formatter != 0); QDate date(2008,12,24); @@ -38,8 +42,10 @@ void tst_datetimeformatter::date() void tst_datetimeformatter::time() { QmlEngine engine; - QmlComponent formatterComponent(&engine, "DateTimeFormatter { time: \"14:15:38.200\" }"); + QmlComponent formatterComponent(&engine, "import Qt 4.6\n DateTimeFormatter { time: \"14:15:38.200\" }", QUrl("file://")); QmlDateTimeFormatter *formatter = qobject_cast(formatterComponent.create()); + if(formatterComponent.isError()) + qDebug() << formatterComponent.errors(); QVERIFY(formatter != 0); QTime time(14,15,38,200); @@ -64,8 +70,10 @@ void tst_datetimeformatter::time() void tst_datetimeformatter::dateTime() { QmlEngine engine; - QmlComponent formatterComponent(&engine, "DateTimeFormatter { dateTime: \"1978-03-04T09:13:54\" }"); + QmlComponent formatterComponent(&engine, "import Qt 4.6\n DateTimeFormatter { dateTime: \"1978-03-04T09:13:54\" }", QUrl("file://")); QmlDateTimeFormatter *formatter = qobject_cast(formatterComponent.create()); + if(formatterComponent.isError()) + qDebug() << formatterComponent.errors(); QVERIFY(formatter != 0); QDateTime dateTime(QDate(1978,03,04),QTime(9,13,54)); diff --git a/tests/auto/declarative/layouts/data/grid-spacing.qml b/tests/auto/declarative/layouts/data/grid-spacing.qml index f9ae204..5b4a30d 100644 --- a/tests/auto/declarative/layouts/data/grid-spacing.qml +++ b/tests/auto/declarative/layouts/data/grid-spacing.qml @@ -6,32 +6,32 @@ Item { Grid { columns: 3 spacing: 4 - Rect { - id: one + Rectangle { + objectName: "one" color: "red" width: 50 height: 50 } - Rect { - id: two + Rectangle { + objectName: "two" color: "green" width: 20 height: 50 } - Rect { - id: three + Rectangle { + objectName: "three" color: "blue" width: 50 height: 20 } - Rect { - id: four + Rectangle { + objectName: "four" color: "cyan" width: 50 height: 50 } - Rect { - id: five + Rectangle { + objectName: "five" color: "magenta" width: 10 height: 10 diff --git a/tests/auto/declarative/layouts/data/grid.qml b/tests/auto/declarative/layouts/data/grid.qml index 3861f63..830df6a 100644 --- a/tests/auto/declarative/layouts/data/grid.qml +++ b/tests/auto/declarative/layouts/data/grid.qml @@ -5,32 +5,32 @@ Item { height: 480 Grid { columns: 3 - Rect { - id: one + Rectangle { + objectName: "one" color: "red" width: 50 height: 50 } - Rect { - id: two + Rectangle { + objectName: "two" color: "green" width: 20 height: 50 } - Rect { - id: three + Rectangle { + objectName: "three" color: "blue" width: 50 height: 20 } - Rect { - id: four + Rectangle { + objectName: "four" color: "cyan" width: 50 height: 50 } - Rect { - id: five + Rectangle { + objectName: "five" color: "magenta" width: 10 height: 10 diff --git a/tests/auto/declarative/layouts/data/horizontal-spacing.qml b/tests/auto/declarative/layouts/data/horizontal-spacing.qml index 8594ee6..32bf775 100644 --- a/tests/auto/declarative/layouts/data/horizontal-spacing.qml +++ b/tests/auto/declarative/layouts/data/horizontal-spacing.qml @@ -5,20 +5,20 @@ Item { height: 480 Row { spacing: 10 - Rect { - id: one + Rectangle { + objectName: "one" color: "red" width: 50 height: 50 } - Rect { - id: two + Rectangle { + objectName: "two" color: "red" width: 20 height: 10 } - Rect { - id: three + Rectangle { + objectName: "three" color: "red" width: 40 height: 20 diff --git a/tests/auto/declarative/layouts/data/horizontal.qml b/tests/auto/declarative/layouts/data/horizontal.qml index 673e77e..06ae151 100644 --- a/tests/auto/declarative/layouts/data/horizontal.qml +++ b/tests/auto/declarative/layouts/data/horizontal.qml @@ -4,20 +4,20 @@ Item { width: 640 height: 480 Row { - Rect { - id: one + Rectangle { + objectName: "one" color: "red" width: 50 height: 50 } - Rect { - id: two + Rectangle { + objectName: "two" color: "red" width: 20 height: 10 } - Rect { - id: three + Rectangle { + objectName: "three" color: "red" width: 40 height: 20 diff --git a/tests/auto/declarative/layouts/data/vertical-spacing.qml b/tests/auto/declarative/layouts/data/vertical-spacing.qml index 49bd8c6..69a8256 100644 --- a/tests/auto/declarative/layouts/data/vertical-spacing.qml +++ b/tests/auto/declarative/layouts/data/vertical-spacing.qml @@ -5,20 +5,20 @@ Item { height: 480 Column { spacing: 10 - Rect { - id: one + Rectangle { + objectName: "one" color: "red" width: 50 height: 50 } - Rect { - id: two + Rectangle { + objectName: "two" color: "red" width: 20 height: 10 } - Rect { - id: three + Rectangle { + objectName: "three" color: "red" width: 40 height: 20 diff --git a/tests/auto/declarative/layouts/data/vertical.qml b/tests/auto/declarative/layouts/data/vertical.qml index c8d3a11..856c180 100644 --- a/tests/auto/declarative/layouts/data/vertical.qml +++ b/tests/auto/declarative/layouts/data/vertical.qml @@ -4,20 +4,20 @@ Item { width: 640 height: 480 Column { - Rect { - id: one + Rectangle { + objectName: "one" color: "red" width: 50 height: 50 } - Rect { - id: two + Rectangle { + objectName: "two" color: "red" width: 20 height: 10 } - Rect { - id: three + Rectangle { + objectName: "three" color: "red" width: 40 height: 20 diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp index cd4678e..3416b2e 100644 --- a/tests/auto/declarative/layouts/tst_layouts.cpp +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -20,8 +20,6 @@ private slots: private: QFxView *createView(const QString &filename); - template - T *findItem(QFxItem *parent, const QString &id, int index=-1); }; tst_QFxLayouts::tst_QFxLayouts() @@ -35,13 +33,13 @@ void tst_QFxLayouts::test_horizontal() canvas->execute(); qApp->processEvents(); - QFxRect *one = findItem(canvas->root(), "one"); + QFxRect *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QFxRect *two = findItem(canvas->root(), "two"); + QFxRect *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QFxRect *three = findItem(canvas->root(), "three"); + QFxRect *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -59,13 +57,13 @@ void tst_QFxLayouts::test_horizontal_spacing() canvas->execute(); qApp->processEvents(); - QFxRect *one = findItem(canvas->root(), "one"); + QFxRect *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QFxRect *two = findItem(canvas->root(), "two"); + QFxRect *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QFxRect *three = findItem(canvas->root(), "three"); + QFxRect *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -83,13 +81,13 @@ void tst_QFxLayouts::test_vertical() canvas->execute(); qApp->processEvents(); - QFxRect *one = findItem(canvas->root(), "one"); + QFxRect *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QFxRect *two = findItem(canvas->root(), "two"); + QFxRect *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QFxRect *three = findItem(canvas->root(), "three"); + QFxRect *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -107,13 +105,13 @@ void tst_QFxLayouts::test_vertical_spacing() canvas->execute(); qApp->processEvents(); - QFxRect *one = findItem(canvas->root(), "one"); + QFxRect *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QFxRect *two = findItem(canvas->root(), "two"); + QFxRect *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QFxRect *three = findItem(canvas->root(), "three"); + QFxRect *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -131,15 +129,15 @@ void tst_QFxLayouts::test_grid() canvas->execute(); qApp->processEvents(); - QFxRect *one = findItem(canvas->root(), "one"); + QFxRect *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QFxRect *two = findItem(canvas->root(), "two"); + QFxRect *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QFxRect *three = findItem(canvas->root(), "three"); + QFxRect *three = canvas->root()->findChild("three"); QVERIFY(three != 0); - QFxRect *four = findItem(canvas->root(), "four"); + QFxRect *four = canvas->root()->findChild("four"); QVERIFY(four != 0); - QFxRect *five = findItem(canvas->root(), "five"); + QFxRect *five = canvas->root()->findChild("five"); QVERIFY(five != 0); QCOMPARE(one->x(), 0.0); @@ -161,15 +159,15 @@ void tst_QFxLayouts::test_grid_spacing() canvas->execute(); qApp->processEvents(); - QFxRect *one = findItem(canvas->root(), "one"); + QFxRect *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QFxRect *two = findItem(canvas->root(), "two"); + QFxRect *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QFxRect *three = findItem(canvas->root(), "three"); + QFxRect *three = canvas->root()->findChild("three"); QVERIFY(three != 0); - QFxRect *four = findItem(canvas->root(), "four"); + QFxRect *four = canvas->root()->findChild("four"); QVERIFY(four != 0); - QFxRect *five = findItem(canvas->root(), "five"); + QFxRect *five = canvas->root()->findChild("five"); QVERIFY(five != 0); QCOMPARE(one->x(), 0.0); @@ -196,36 +194,6 @@ QFxView *tst_QFxLayouts::createView(const QString &filename) return canvas; } -/* - Find an item with the specified objectName. If index is supplied then the - item must also evaluate the {index} expression equal to index -*/ -template -T *tst_QFxLayouts::findItem(QFxItem *parent, const QString &objectName, int index) -{ - const QMetaObject &mo = T::staticMetaObject; - for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { - QFxItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); - if(!item) - continue; - //qDebug() << item << item->objectName(); - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { - if (index != -1) { - QmlExpression e(qmlContext(item), "index", item); - e.setTrackChange(false); - if (e.value().toInt() == index) - return static_cast(item); - } else { - return static_cast(item); - } - } - item = findItem(item, objectName, index); - if (item) - return static_cast(item); - } - - return 0; -} QTEST_MAIN(tst_QFxLayouts) diff --git a/tests/auto/declarative/listview/data/listview.qml b/tests/auto/declarative/listview/data/listview.qml index 7a3d76f..1a241eb 100644 --- a/tests/auto/declarative/listview/data/listview.qml +++ b/tests/auto/declarative/listview/data/listview.qml @@ -9,6 +9,7 @@ Rectangle { id: Delegate Item { id: wrapper + objectName: "wrapper" height: 20 width: 240 Text { @@ -17,11 +18,13 @@ Rectangle { Text { x: 30 id: textName + objectName: "textName" text: name } Text { x: 120 id: textNumber + objectName: "textNumber" text: number } Text { @@ -33,6 +36,7 @@ Rectangle { ] ListView { id: list + objectName: "list" width: 240 height: 320 model: testModel diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index 8bf9c8a..ebc3053 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -188,7 +188,7 @@ void tst_QFxListView::items() QFxItem *viewport = listview->viewport(); QVERIFY(viewport != 0); - QCOMPARE(viewport->children()->count(), model.count()); // assumes all are visible + QCOMPARE(viewport->childItems().count(), model.count()); // assumes all are visible for (int i = 0; i < model.count(); ++i) { QFxText *name = findItem(viewport, "textName", i); @@ -262,7 +262,7 @@ void tst_QFxListView::inserted() // let transitions settle. QTest::qWait(1000); - QCOMPARE(viewport->children()->count(), model.count()); // assumes all are visible + QCOMPARE(viewport->childItems().count(), model.count()); // assumes all are visible QFxText *name = findItem(viewport, "textName", 1); QVERIFY(name != 0); @@ -282,7 +282,7 @@ void tst_QFxListView::inserted() // let transitions settle. QTest::qWait(1000); - QCOMPARE(viewport->children()->count(), model.count()); // assumes all are visible + QCOMPARE(viewport->childItems().count(), model.count()); // assumes all are visible name = findItem(viewport, "textName", 0); QVERIFY(name != 0); @@ -336,7 +336,7 @@ void tst_QFxListView::removed() QCOMPARE(number->text(), model.number(1)); // Confirm items positioned correctly - for (int i = 0; i < model.count() && i < viewport->children()->count(); ++i) { + for (int i = 0; i < model.count() && i < viewport->childItems().count(); ++i) { QFxItem *item = findItem(viewport, "wrapper", i); QVERIFY(item->y() == i*20); } @@ -355,7 +355,7 @@ void tst_QFxListView::removed() QCOMPARE(number->text(), model.number(0)); // Confirm items positioned correctly - for (int i = 0; i < model.count() && i < viewport->children()->count(); ++i) { + for (int i = 0; i < model.count() && i < viewport->childItems().count(); ++i) { QFxItem *item = findItem(viewport, "wrapper", i); QCOMPARE(item->y(),i*20.0 + 20.0); } @@ -366,13 +366,13 @@ void tst_QFxListView::removed() QTest::qWait(1000); // Confirm items positioned correctly - for (int i = 0; i < model.count() && i < viewport->children()->count(); ++i) { + for (int i = 0; i < model.count() && i < viewport->childItems().count(); ++i) { QFxItem *item = findItem(viewport, "wrapper", i); QCOMPARE(item->y(),i*20.0+20.0); } // Remove items before visible - listview->setYPosition(80); + listview->setViewportY(80); listview->setCurrentIndex(10); model.removeItem(1); // post: top item will be at 40 @@ -385,12 +385,12 @@ void tst_QFxListView::removed() QCOMPARE(item->y(),40+i*20.0); } - listview->setYPosition(40); // That's the top now + listview->setViewportY(40); // That's the top now // let transitions settle. QTest::qWait(1000); // Confirm items positioned correctly - for (int i = 0; i < model.count() && i < viewport->children()->count(); ++i) { + for (int i = 0; i < model.count() && i < viewport->childItems().count(); ++i) { QFxItem *item = findItem(viewport, "wrapper", i); QCOMPARE(item->y(),40+i*20.0); } @@ -459,10 +459,12 @@ template T *tst_QFxListView::findItem(QFxItem *parent, const QString &objectName, int index) { const QMetaObject &mo = T::staticMetaObject; - qDebug() << parent->children()->count() << "children"; - for (int i = 0; i < parent->children()->count(); ++i) { - QFxItem *item = parent->children()->at(i); - qDebug() << "try" << item; + //qDebug() << parent->QGraphicsObject::children().count() << "children"; + for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { + QFxItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { if (index != -1) { QmlExpression e(qmlContext(item), "index", item); -- cgit v0.12 From 7688d668a2a8997d0bc6bac9094d8694e746391b Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 9 Sep 2009 15:02:59 +1000 Subject: Rename QFxItem::children() to QFxItem::fxChildren() No more accidental hiding. Differently named functions for QObject children: children() QGraphicsItem children: childItems() QFxItem children: fxChildren() --- src/declarative/fx/qfxflickable.cpp | 4 ++-- src/declarative/fx/qfxflipable.cpp | 4 ++-- src/declarative/fx/qfxitem.cpp | 4 ++-- src/declarative/fx/qfxitem.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 5fe9617..c227899 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -853,7 +853,7 @@ void QFxFlickablePrivate::data_append(QObject *o) Q_Q(QFxFlickable); QFxItem *i = qobject_cast(o); if (i) - viewport->children()->append(i); + viewport->fxChildren()->append(i); else o->setParent(q); } @@ -884,7 +884,7 @@ QmlList *QFxFlickable::flickableData() QmlList *QFxFlickable::flickableChildren() { Q_D(QFxFlickable); - return d->viewport->children(); + return d->viewport->fxChildren(); } /*! diff --git a/src/declarative/fx/qfxflipable.cpp b/src/declarative/fx/qfxflipable.cpp index 8e56e43..dc5101c 100644 --- a/src/declarative/fx/qfxflipable.cpp +++ b/src/declarative/fx/qfxflipable.cpp @@ -146,7 +146,7 @@ void QFxFlipable::setFront(QFxItem *front) return; } d->front = front; - children()->append(d->front); + fxChildren()->append(d->front); if (Back == d->current) d->front->setOpacity(0.); } @@ -165,7 +165,7 @@ void QFxFlipable::setBack(QFxItem *back) return; } d->back = back; - children()->append(d->back); + fxChildren()->append(d->back); if (Front == d->current) d->back->setOpacity(0.); } diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 3429010..a2c744e 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -1473,7 +1473,7 @@ void QFxItemPrivate::data_append(QObject *o) Q_Q(QFxItem); QFxItem *i = qobject_cast(o); if (i) - q->children()->append(i); + q->fxChildren()->append(i); else resources_append(o); } @@ -2271,7 +2271,7 @@ void QFxItem::focusChanged(bool flag) emit focusChanged(); } -QmlList *QFxItem::children() +QmlList *QFxItem::fxChildren() { Q_D(QFxItem); return &(d->children); diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index 643987d..c6a5311 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -70,7 +70,7 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserSta Q_PROPERTY(QFxItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL) Q_PROPERTY(QmlList *data READ data DESIGNABLE false) - Q_PROPERTY(QmlList* children READ children DESIGNABLE false) + Q_PROPERTY(QmlList* children READ fxChildren DESIGNABLE false) Q_PROPERTY(QmlList* resources READ resources DESIGNABLE false) Q_PROPERTY(QmlList* states READ states DESIGNABLE false) Q_PROPERTY(QmlList* transitions READ transitions DESIGNABLE false) @@ -112,7 +112,7 @@ public: void setParent(QFxItem *parent) { setParentItem(parent); } QmlList *data(); - QmlList *children(); + QmlList *fxChildren(); QmlList *resources(); QFxAnchors *anchors(); -- cgit v0.12 From 6878a0b7c507d21366cacee0a09bafeb81726d82 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 9 Sep 2009 15:14:21 +1000 Subject: Move ComponentInstance functionality into Loader --- demos/declarative/minehunt/minehunt.qml | 4 +- doc/src/declarative/elements.qdoc | 1 - doc/src/tutorials/declarative.qdoc | 2 +- .../tutorials/contacts/2_Reuse/1b/BlueRect.qml | 12 +- examples/declarative/webview/newwindows.qml | 2 +- src/declarative/QmlChanges.txt | 3 + src/declarative/fx/fx.pri | 3 - src/declarative/fx/qfxcomponentinstance.cpp | 149 ------------ src/declarative/fx/qfxcomponentinstance.h | 93 -------- src/declarative/fx/qfxcomponentinstance_p.h | 76 ------ src/declarative/fx/qfxloader.cpp | 258 ++++++++++++++++----- src/declarative/fx/qfxloader.h | 13 +- src/declarative/fx/qfxloader_p.h | 6 +- src/declarative/qml/qmlcomponent.cpp | 5 +- src/declarative/util/qfxperf.cpp | 1 - src/declarative/util/qfxperf_p.h | 1 - tests/auto/declarative/qfxloader/NoResize.qml | 7 + tests/auto/declarative/qfxloader/Rect120x60.qml | 6 + .../declarative/qfxloader/SetSourceComponent.qml | 6 + tests/auto/declarative/qfxloader/SizeToItem.qml | 6 + tests/auto/declarative/qfxloader/SizeToLoader.qml | 7 + tests/auto/declarative/qfxloader/qfxloader.pro | 5 + tests/auto/declarative/qfxloader/tst_qfxloader.cpp | 103 ++++++++ 23 files changed, 373 insertions(+), 396 deletions(-) delete mode 100644 src/declarative/fx/qfxcomponentinstance.cpp delete mode 100644 src/declarative/fx/qfxcomponentinstance.h delete mode 100644 src/declarative/fx/qfxcomponentinstance_p.h create mode 100644 tests/auto/declarative/qfxloader/NoResize.qml create mode 100644 tests/auto/declarative/qfxloader/Rect120x60.qml create mode 100644 tests/auto/declarative/qfxloader/SetSourceComponent.qml create mode 100644 tests/auto/declarative/qfxloader/SizeToItem.qml create mode 100644 tests/auto/declarative/qfxloader/SizeToLoader.qml create mode 100644 tests/auto/declarative/qfxloader/qfxloader.pro create mode 100644 tests/auto/declarative/qfxloader/tst_qfxloader.cpp diff --git a/demos/declarative/minehunt/minehunt.qml b/demos/declarative/minehunt/minehunt.qml index fa169aa..72431af 100644 --- a/demos/declarative/minehunt/minehunt.qml +++ b/demos/declarative/minehunt/minehunt.qml @@ -135,8 +135,8 @@ Item { x: 1 y: 1 Component { - ComponentInstance { - component: tile + Loader { + sourceComponent: tile x: (index - (Math.floor(index/9) * 9)) * 41 y: Math.floor(index/9) * 41 } diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index bfaf4ab..4eda947 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -100,7 +100,6 @@ The following table lists the QML elements provided by the Qt Declarative module \o \l Loader \o \l Repeater \o \l SystemPalette -\o \l ComponentInstance \o \l GraphicsObjectContainer \endlist diff --git a/doc/src/tutorials/declarative.qdoc b/doc/src/tutorials/declarative.qdoc index 7780988..48beabd 100644 --- a/doc/src/tutorials/declarative.qdoc +++ b/doc/src/tutorials/declarative.qdoc @@ -392,7 +392,7 @@ the contact field. There are also two other ways to reuse components in QML. A component - can be reused from within the same QML file using Component and ComponentInstance + can be reused from within the same QML file using Component and Loader elements. The next code snippet produces three red rounded rectangles within a large blue rectangle. diff --git a/examples/declarative/tutorials/contacts/2_Reuse/1b/BlueRect.qml b/examples/declarative/tutorials/contacts/2_Reuse/1b/BlueRect.qml index ec115fe..7bcdf50 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/1b/BlueRect.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/1b/BlueRect.qml @@ -16,18 +16,18 @@ Rectangle { } } ] - ComponentInstance { - component: redRectangle + Loader { + sourceComponent: redRectangle anchors.right: parent.right anchors.top: parent.top } - ComponentInstance { - component: redRectangle + Loader { + sourceComponent: redRectangle anchors.left: parent.left anchors.top: parent.top } - ComponentInstance { - component: redRectangle + Loader { + sourceComponent: redRectangle anchors.left: parent.left anchors.bottom: parent.bottom } diff --git a/examples/declarative/webview/newwindows.qml b/examples/declarative/webview/newwindows.qml index 9ff902e2..57cbf4e 100644 --- a/examples/declarative/webview/newwindows.qml +++ b/examples/declarative/webview/newwindows.qml @@ -24,5 +24,5 @@ Row { } ] width: 500 - ComponentInstance { component: WebViewPage } + Loader { sourceComponent: WebViewPage } } diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 9bf4b10..42a8415 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -67,6 +67,8 @@ MouseRegion: add "pressedButtons" property Timer: add start() and stop() slots WebView: add newWindowComponent and newWindowParent properties Loader: add status() and progress() properties +Loader: add sourceComponent property +Loader: add resizeMode property Deletions: Column/VerticalPositioner: lost "margins" property @@ -74,6 +76,7 @@ Row/HorizontalPositioner: lost "margins" property Grid/Positioner/Layout: lost "margins" property WebView: lost "interactive" property (always true now) Flickable: removed "dragMode" property +ComponentInstance: removed. Replaced by Loader.sourceComponent Other Changes: Drag: axis becomes an enum with values "XAxis", "YAxis", "XandYAxis" diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri index 80a6fdd..cfe78e1 100644 --- a/src/declarative/fx/fx.pri +++ b/src/declarative/fx/fx.pri @@ -1,8 +1,6 @@ HEADERS += \ fx/qfxanchors.h \ fx/qfxanchors_p.h \ - fx/qfxcomponentinstance.h \ - fx/qfxcomponentinstance_p.h \ fx/qfxevents_p.h \ fx/qfxflickable.h \ fx/qfxflickable_p.h \ @@ -49,7 +47,6 @@ HEADERS += \ SOURCES += \ fx/qfxanchors.cpp \ - fx/qfxcomponentinstance.cpp \ fx/qfxevents.cpp \ fx/qfxflickable.cpp \ fx/qfxflipable.cpp \ diff --git a/src/declarative/fx/qfxcomponentinstance.cpp b/src/declarative/fx/qfxcomponentinstance.cpp deleted file mode 100644 index 7a712aa..0000000 --- a/src/declarative/fx/qfxcomponentinstance.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfxcomponentinstance.h" -#include "qfxcomponentinstance_p.h" -#include -#include - - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ComponentInstance,QFxComponentInstance) - -/*! - \internal - \class QFxComponentInstance ComponentInstance - - \brief The QFxComponentInstance class provides a way to instantiate an item from a component. - */ - -/*! - \qmlclass ComponentInstance QFxComponentInstance - \brief The ComponentInstance item allows you to instantiate a \l{Component}. - - \qml - Item { - Component { - id: RedSquare - Rectangle { color: "red"; width: 10; height: 10 } - } - - ComponentInstance { component: RedSquare } - } - \endqml -*/ -QFxComponentInstance::QFxComponentInstance(QFxItem *parent) - : QFxItem(*(new QFxComponentInstancePrivate), parent) -{ -} - -QFxComponentInstance::QFxComponentInstance(QFxComponentInstancePrivate &dd, QFxItem *parent) - : QFxItem(dd, parent) -{ -} - -/*! - \qmlproperty Component QFxComponentInstance::component - - This property holds the component to instantiate. -*/ -QmlComponent *QFxComponentInstance::component() const -{ - Q_D(const QFxComponentInstance); - return d->component; -} - -void QFxComponentInstance::setComponent(QmlComponent *c) -{ - Q_D(QFxComponentInstance); - if (d->component) { - qmlInfo(this) << "component is a write-once property."; - return; - } - d->component = c; - create(); -} - -void QFxComponentInstance::create() -{ - Q_D(QFxComponentInstance); - if (d->component) { - QObject *obj= d->component->create(qmlContext(this)); - if (obj) { - QFxItem *objitem = qobject_cast(obj); - if (objitem) { - d->instance = objitem; - objitem->setParentItem(this); - objitem->setFocus(true); - connect(objitem, SIGNAL(widthChanged()), this, SLOT(updateSize())); - connect(objitem, SIGNAL(heightChanged()), this, SLOT(updateSize())); - updateSize(); - emit instanceChanged(); - } else { - delete obj; - } - } - } -} - -void QFxComponentInstance::updateSize() -{ - QFxItem *i = instance(); - if (i) { - if (!widthValid()) - setImplicitWidth(i->width()); - if (!heightValid()) - setImplicitHeight(i->height()); - } -} - -/*! - \qmlproperty Item QFxComponentInstance::instance - - This property holds the instantiated component. -*/ -QFxItem *QFxComponentInstance::instance() const -{ - Q_D(const QFxComponentInstance); - return d->instance; -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxcomponentinstance.h b/src/declarative/fx/qfxcomponentinstance.h deleted file mode 100644 index b223ca2..0000000 --- a/src/declarative/fx/qfxcomponentinstance.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXCOMPONENTINSTANCE_H -#define QFXCOMPONENTINSTANCE_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -//### remove -//### add component property to Loader - -class QFxComponentInstancePrivate; -class Q_DECLARATIVE_EXPORT QFxComponentInstance : public QFxItem -{ - Q_OBJECT - Q_PROPERTY(QmlComponent *component READ component WRITE setComponent) - Q_PROPERTY(QFxItem *instance READ instance) - Q_CLASSINFO("DefaultProperty", "component") -public: - QFxComponentInstance(QFxItem *parent=0); - - QmlComponent *component() const; - void setComponent(QmlComponent *); - - QFxItem *instance() const; - -Q_SIGNALS: - void instanceChanged(); - -private Q_SLOTS: - void updateSize(); - -private: - void create(); - -protected: - QFxComponentInstance(QFxComponentInstancePrivate &dd, QFxItem *parent); - -private: - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxComponentInstance) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QFxComponentInstance) - -QT_END_HEADER - -#endif // QFXCOMPONENTINSTANCE_H diff --git a/src/declarative/fx/qfxcomponentinstance_p.h b/src/declarative/fx/qfxcomponentinstance_p.h deleted file mode 100644 index defeb74..0000000 --- a/src/declarative/fx/qfxcomponentinstance_p.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXCOMPONENTINSTANCE_P_H -#define QFXCOMPONENTINSTANCE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qfxitem_p.h" - - -QT_BEGIN_NAMESPACE -class QFxComponentInstancePrivate : public QFxItemPrivate -{ - Q_DECLARE_PUBLIC(QFxComponentInstance) - -public: - QFxComponentInstancePrivate() - : component(0), instance(0) - { - } - - QmlComponent *component; - QFxItem *instance; -}; - -QT_END_NAMESPACE - -#endif // QFXCOMPONENTINSTANCE_P_H diff --git a/src/declarative/fx/qfxloader.cpp b/src/declarative/fx/qfxloader.cpp index 869a5b0..783fd61 100644 --- a/src/declarative/fx/qfxloader.cpp +++ b/src/declarative/fx/qfxloader.cpp @@ -45,7 +45,7 @@ QT_BEGIN_NAMESPACE QFxLoaderPrivate::QFxLoaderPrivate() -: item(0), qmlcomp(0) +: item(0), component(0), ownComponent(false), resizeMode(QFxLoader::SizeLoaderToItem) { } @@ -59,9 +59,22 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Loader,QFxLoader) \qmlclass Loader \inherits Item - \brief The Loader item allows you to dynamically load an Item-based - subtree from a QML URL. - */ + \brief The Loader item allows dynamically loading an Item-based + subtree from a QML URL or Component. + + Loader instantiates an item from a component. The component to + instantiate may be specified directly by the \c sourceComponent + property, or loaded from a URL via the \c source property. + + It is also an effective means of delaying the creation of a component + until it is required: + \code + Loader { id: PageLoader } + Rectangle { + MouseRegion { anchors.fill: parent; onClicked: PageLoader.source = "Page1.qml" } + } + \endcode +*/ /*! \internal @@ -86,10 +99,10 @@ QFxLoader::~QFxLoader() /*! \qmlproperty url Loader::source - This property holds the dynamic URL of the QML for the item. + This property holds the URL of the QML component to + instantiate. - This property is used for dynamically loading QML into the - item. + \sa status, progress */ QUrl QFxLoader::source() const { @@ -103,44 +116,98 @@ void QFxLoader::setSource(const QUrl &url) if (d->source == url) return; - if (!d->source.isEmpty()) { - QHash::Iterator iter = d->cachedChildren.find(d->source.toString()); - if (iter != d->cachedChildren.end()) - (*iter)->setOpacity(0.); + if (d->ownComponent) { + delete d->component; + d->component = 0; } - - d->source = url; d->item = 0; - emit itemChanged(); + delete d->item; + d->source = url; if (d->source.isEmpty()) { emit sourceChanged(); emit statusChanged(); emit progressChanged(); + emit itemChanged(); + return; + } + + d->component = new QmlComponent(qmlEngine(this), d->source, this); + d->ownComponent = true; + if (!d->component->isLoading()) { + d->_q_sourceLoaded(); + } else { + connect(d->component, SIGNAL(statusChanged(QmlComponent::Status)), + this, SLOT(_q_sourceLoaded())); + connect(d->component, SIGNAL(progressChanged(qreal)), + this, SIGNAL(progressChanged())); + emit statusChanged(); + emit progressChanged(); + emit sourceChanged(); + emit itemChanged(); + } +} + +/*! + \qmlproperty Component Loader::sourceComponent + The sourceComponent property holds the \l{Component} to instantiate. + + \qml + Item { + Component { + id: RedSquare + Rectangle { color: "red"; width: 10; height: 10 } + } + + Loader { sourceComponent: RedSquare } + Loader { sourceComponent: RedSquare; x: 10 } + } + \endqml + + \sa source +*/ + +QmlComponent *QFxLoader::sourceComponent() const +{ + Q_D(const QFxLoader); + return d->component; +} + +void QFxLoader::setSourceComponent(QmlComponent *comp) +{ + Q_D(QFxLoader); + if (comp == d->component) return; + + d->source = QUrl(); + if (d->ownComponent) { + delete d->component; + d->component = 0; } + delete d->item; + d->item = 0; - QHash::Iterator iter = d->cachedChildren.find(d->source.toString()); - if (iter != d->cachedChildren.end()) { - (*iter)->setOpacity(1.); - d->item = (*iter); + d->component = comp; + d->ownComponent = false; + if (!d->component) { emit sourceChanged(); emit statusChanged(); emit progressChanged(); emit itemChanged(); + return; + } + + if (!d->component->isLoading()) { + d->_q_sourceLoaded(); } else { - d->qmlcomp = - new QmlComponent(qmlEngine(this), d->source, this); - if (!d->qmlcomp->isLoading()) { - d->_q_sourceLoaded(); - } else { - connect(d->qmlcomp, SIGNAL(statusChanged(QmlComponent::Status)), - this, SLOT(_q_sourceLoaded())); - connect(d->qmlcomp, SIGNAL(progressChanged(qreal)), - this, SIGNAL(progressChanged())); - emit statusChanged(); - emit progressChanged(); - } + connect(d->component, SIGNAL(statusChanged(QmlComponent::Status)), + this, SLOT(_q_sourceLoaded())); + connect(d->component, SIGNAL(progressChanged(qreal)), + this, SIGNAL(progressChanged())); + emit progressChanged(); + emit sourceChanged(); + emit statusChanged(); + emit itemChanged(); } } @@ -148,33 +215,39 @@ void QFxLoaderPrivate::_q_sourceLoaded() { Q_Q(QFxLoader); - if (qmlcomp) { + if (component) { QmlContext *ctxt = new QmlContext(qmlContext(q)); ctxt->addDefaultObject(q); - if (!qmlcomp->errors().isEmpty()) { - qWarning() << qmlcomp->errors(); - delete qmlcomp; - qmlcomp = 0; + if (!component->errors().isEmpty()) { + qWarning() << component->errors(); emit q->sourceChanged(); emit q->statusChanged(); emit q->progressChanged(); return; } - QObject *obj = qmlcomp->create(ctxt); - if (!qmlcomp->errors().isEmpty()) - qWarning() << qmlcomp->errors(); - QFxItem *qmlChild = qobject_cast(obj); - if (qmlChild) { - qmlChild->setParentItem(q); - cachedChildren.insert(source.toString(), qmlChild); - item = qmlChild; + + QObject *obj = component->create(ctxt); + if (obj) { + item = qobject_cast(obj); + if (item) { + item->setParentItem(q); +// item->setFocus(true); + QFxItem *resizeItem = 0; + if (resizeMode == QFxLoader::SizeLoaderToItem) + resizeItem = item; + else if (resizeMode == QFxLoader::SizeItemToLoader) + resizeItem = q; + if (resizeItem) { + QObject::connect(resizeItem, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); + QObject::connect(resizeItem, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); + } + _q_updateSize(); + } } else { - delete qmlChild; + delete obj; source = QUrl(); } - delete qmlcomp; - qmlcomp = 0; emit q->sourceChanged(); emit q->statusChanged(); emit q->progressChanged(); @@ -196,6 +269,19 @@ void QFxLoaderPrivate::_q_sourceLoaded() \sa progress */ +QFxLoader::Status QFxLoader::status() const +{ + Q_D(const QFxLoader); + + if (d->component) + return static_cast(d->component->status()); + + if (d->item) + return Ready; + + return d->source.isEmpty() ? Null : Error; +} + /*! \qmlproperty real Loader::progress @@ -204,27 +290,87 @@ void QFxLoaderPrivate::_q_sourceLoaded() \sa status */ -QFxLoader::Status QFxLoader::status() const +qreal QFxLoader::progress() const { Q_D(const QFxLoader); - if (d->qmlcomp) - return static_cast(d->qmlcomp->status()); - if (d->item) - return Ready; + return 1.0; - return d->source.isEmpty() ? Null : Error; + if (d->component) + return d->component->progress(); + + return 0.0; } -qreal QFxLoader::progress() const +/*! + \qmlproperty enum Loader::resizeMode + + This property determines how the Loader or item are resized: + \list + \o NoResize - no item will be resized + \o SizeLoaderToItem - the Loader will be sized to the size of the item, unless the size of the Loader has been otherwise specified. + \o SizeItemToLoader - the item will be sized to the size of the Loader. + \endlist +*/ +QFxLoader::ResizeMode QFxLoader::resizeMode() const { Q_D(const QFxLoader); + return d->resizeMode; +} + +void QFxLoader::setResizeMode(ResizeMode mode) +{ + Q_D(QFxLoader); + if (mode == d->resizeMode) + return; - if (d->qmlcomp) - return d->qmlcomp->progress(); + if (d->item) { + QFxItem *resizeItem = 0; + if (d->resizeMode == SizeLoaderToItem) + resizeItem = d->item; + else if (d->resizeMode == SizeItemToLoader) + resizeItem = this; + if (resizeItem) { + disconnect(resizeItem, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); + disconnect(resizeItem, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); + } + } + + d->resizeMode = mode; + + if (d->item) { + QFxItem *resizeItem = 0; + if (d->resizeMode == SizeLoaderToItem) + resizeItem = d->item; + else if (d->resizeMode == SizeItemToLoader) + resizeItem = this; + if (resizeItem) { + connect(resizeItem, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); + connect(resizeItem, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); + } + } +} - return d->item ? 1.0 : 0.0; +void QFxLoaderPrivate::_q_updateSize() +{ + Q_Q(QFxLoader); + if (!item) + return; + switch (resizeMode) { + case QFxLoader::SizeLoaderToItem: + if (!q->widthValid()) + q->setImplicitWidth(item->width()); + if (!q->heightValid()) + q->setImplicitHeight(item->height()); + break; + case QFxLoader::SizeItemToLoader: + item->setWidth(q->width()); + item->setHeight(q->height()); + break; + default: + break; + } } /*! diff --git a/src/declarative/fx/qfxloader.h b/src/declarative/fx/qfxloader.h index 132c8f4..b967465 100644 --- a/src/declarative/fx/qfxloader.h +++ b/src/declarative/fx/qfxloader.h @@ -55,14 +55,15 @@ class Q_DECLARATIVE_EXPORT QFxLoader : public QFxItem { Q_OBJECT Q_ENUMS(Status) + Q_ENUMS(ResizeMode) Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QmlComponent *sourceComponent READ sourceComponent WRITE setSourceComponent NOTIFY sourceChanged) + Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) Q_PROPERTY(QFxItem *item READ item NOTIFY itemChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) //### sourceItem - //### sourceComponent - //### resizeMode { NoResize, SizeLoaderToItem (default), SizeItemToLoader } public: QFxLoader(QFxItem *parent=0); @@ -71,10 +72,17 @@ public: QUrl source() const; void setSource(const QUrl &); + QmlComponent *sourceComponent() const; + void setSourceComponent(QmlComponent *); + enum Status { Null, Ready, Loading, Error }; Status status() const; qreal progress() const; + enum ResizeMode { NoResize, SizeLoaderToItem, SizeItemToLoader }; + ResizeMode resizeMode() const; + void setResizeMode(ResizeMode mode); + QFxItem *item() const; Q_SIGNALS: @@ -87,6 +95,7 @@ private: Q_DISABLE_COPY(QFxLoader) Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxLoader) Q_PRIVATE_SLOT(d_func(), void _q_sourceLoaded()) + Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxloader_p.h b/src/declarative/fx/qfxloader_p.h index 13f3b53..0700fcd 100644 --- a/src/declarative/fx/qfxloader_p.h +++ b/src/declarative/fx/qfxloader_p.h @@ -69,10 +69,12 @@ public: QUrl source; QFxItem *item; - QmlComponent *qmlcomp; - QHash cachedChildren; + QmlComponent *component; + bool ownComponent; + QFxLoader::ResizeMode resizeMode; void _q_sourceLoaded(); + void _q_updateSize(); }; QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index f291ac0..1c35606 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -91,8 +91,8 @@ Item { height: 10 } } - ComponentInstance { component: RedSquare } - ComponentInstance { component: RedSquare; x: 20 } + Loader { sourceComponent: RedSquare } + Loader { sourceComponent: RedSquare; x: 20 } } \endqml */ @@ -328,6 +328,7 @@ QmlComponent::QmlComponent(QmlEngine *engine, QmlCompiledData *cc, int start, in d->start = start; d->count = count; d->url = cc->url; + d->progress = 1.0; } /*! diff --git a/src/declarative/util/qfxperf.cpp b/src/declarative/util/qfxperf.cpp index 90f639e..739e480 100644 --- a/src/declarative/util/qfxperf.cpp +++ b/src/declarative/util/qfxperf.cpp @@ -58,7 +58,6 @@ Q_DEFINE_PERFORMANCE_LOG(QFxPerf, "QFx") { Q_DEFINE_PERFORMANCE_METRIC(CreateParticle, " QFxParticles: Particle creation") Q_DEFINE_PERFORMANCE_METRIC(ItemComponentComplete, " QFxItem::componentComplete") Q_DEFINE_PERFORMANCE_METRIC(ImageComponentComplete, " QFxImage::componentComplete") - Q_DEFINE_PERFORMANCE_METRIC(ComponentInstanceComponentComplete, " QFxComponentInstance::componentComplete") Q_DEFINE_PERFORMANCE_METRIC(BaseLayoutComponentComplete, " QFxBasePositioner::componentComplete") Q_DEFINE_PERFORMANCE_METRIC(TextComponentComplete, " QFxText::componentComplete") Q_DEFINE_PERFORMANCE_METRIC(QFxText_setText, " QFxText::setText") diff --git a/src/declarative/util/qfxperf_p.h b/src/declarative/util/qfxperf_p.h index a1e38b7..cea7e80 100644 --- a/src/declarative/util/qfxperf_p.h +++ b/src/declarative/util/qfxperf_p.h @@ -77,7 +77,6 @@ Q_DECLARE_PERFORMANCE_LOG(QFxPerf) { Q_DECLARE_PERFORMANCE_METRIC(CreateParticle) Q_DECLARE_PERFORMANCE_METRIC(ItemComponentComplete) Q_DECLARE_PERFORMANCE_METRIC(ImageComponentComplete) - Q_DECLARE_PERFORMANCE_METRIC(ComponentInstanceComponentComplete) Q_DECLARE_PERFORMANCE_METRIC(BaseLayoutComponentComplete) Q_DECLARE_PERFORMANCE_METRIC(TextComponentComplete) Q_DECLARE_PERFORMANCE_METRIC(QFxText_setText) diff --git a/tests/auto/declarative/qfxloader/NoResize.qml b/tests/auto/declarative/qfxloader/NoResize.qml new file mode 100644 index 0000000..cfbb55a --- /dev/null +++ b/tests/auto/declarative/qfxloader/NoResize.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +Loader { + resizeMode: "NoResize" + width: 200; height: 80 + source: "Rect120x60.qml" +} diff --git a/tests/auto/declarative/qfxloader/Rect120x60.qml b/tests/auto/declarative/qfxloader/Rect120x60.qml new file mode 100644 index 0000000..aa4b0c2 --- /dev/null +++ b/tests/auto/declarative/qfxloader/Rect120x60.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Rectangle { + width: 120 + height:60 +} diff --git a/tests/auto/declarative/qfxloader/SetSourceComponent.qml b/tests/auto/declarative/qfxloader/SetSourceComponent.qml new file mode 100644 index 0000000..c5dd7ff --- /dev/null +++ b/tests/auto/declarative/qfxloader/SetSourceComponent.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Item { + Component { id: Comp; Rectangle { width: 120; height: 60 } } + Loader { sourceComponent: Comp } +} diff --git a/tests/auto/declarative/qfxloader/SizeToItem.qml b/tests/auto/declarative/qfxloader/SizeToItem.qml new file mode 100644 index 0000000..b52fa03 --- /dev/null +++ b/tests/auto/declarative/qfxloader/SizeToItem.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Loader { + resizeMode: "SizeLoaderToItem" + source: "Rect120x60.qml" +} diff --git a/tests/auto/declarative/qfxloader/SizeToLoader.qml b/tests/auto/declarative/qfxloader/SizeToLoader.qml new file mode 100644 index 0000000..1a107e1 --- /dev/null +++ b/tests/auto/declarative/qfxloader/SizeToLoader.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +Loader { + resizeMode: "SizeItemToLoader" + width: 200; height: 80 + source: "Rect120x60.qml" +} diff --git a/tests/auto/declarative/qfxloader/qfxloader.pro b/tests/auto/declarative/qfxloader/qfxloader.pro new file mode 100644 index 0000000..643c18c --- /dev/null +++ b/tests/auto/declarative/qfxloader/qfxloader.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +SOURCES += tst_qfxloader.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp new file mode 100644 index 0000000..2109898 --- /dev/null +++ b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include + +class tst_qfxloader : public QObject + +{ + Q_OBJECT +public: + tst_qfxloader(); + +private slots: + void url(); + void component(); + void sizeLoaderToItem(); + void sizeItemToLoader(); + void noResize(); + +private: + QmlEngine engine; +}; + +/* +inline QUrl TEST_FILE(const QString &filename) +{ + QFileInfo fileInfo(__FILE__); + return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath(filename)); +} + +inline QUrl TEST_FILE(const char *filename) +{ + return TEST_FILE(QLatin1String(filename)); +} +*/ + +tst_qfxloader::tst_qfxloader() +{ +} + +void tst_qfxloader::url() +{ + QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"Rect120x60.qml\" }"), QUrl("file://" SRCDIR "/")); + QFxLoader *loader = qobject_cast(component.create()); + QVERIFY(loader != 0); + QVERIFY(loader->item()); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(static_cast(loader)->children().count(), 1); +} + +void tst_qfxloader::component() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/SetSourceComponent.qml")); + QFxItem *item = qobject_cast(component.create()); + QVERIFY(item); + + QFxLoader *loader = qobject_cast(item->QGraphicsObject::children().at(1)); + QVERIFY(loader); + QVERIFY(loader->item()); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(static_cast(loader)->children().count(), 1); +} + +void tst_qfxloader::sizeLoaderToItem() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/SizeToItem.qml")); + QFxLoader *loader = qobject_cast(component.create()); + QVERIFY(loader != 0); + QCOMPARE(loader->width(), 120.0); + QCOMPARE(loader->height(), 60.0); +} + +void tst_qfxloader::sizeItemToLoader() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/SizeToLoader.qml")); + QFxLoader *loader = qobject_cast(component.create()); + QVERIFY(loader != 0); + QCOMPARE(loader->width(), 200.0); + QCOMPARE(loader->height(), 80.0); + + QFxItem *rect = loader->item(); + QVERIFY(rect); + QCOMPARE(rect->width(), 200.0); + QCOMPARE(rect->height(), 80.0); +} + +void tst_qfxloader::noResize() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/NoResize.qml")); + QFxLoader *loader = qobject_cast(component.create()); + QVERIFY(loader != 0); + QCOMPARE(loader->width(), 200.0); + QCOMPARE(loader->height(), 80.0); + + QFxItem *rect = loader->item(); + QVERIFY(rect); + QCOMPARE(rect->width(), 120.0); + QCOMPARE(rect->height(), 60.0); +} + +QTEST_MAIN(tst_qfxloader) + +#include "tst_qfxloader.moc" -- cgit v0.12 From dc4d2b260debda80b8a0d81c9a032050232fdaab Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 9 Sep 2009 15:17:00 +1000 Subject: Doc. --- src/declarative/fx/qfxloader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/declarative/fx/qfxloader.cpp b/src/declarative/fx/qfxloader.cpp index 783fd61..e75ce6d 100644 --- a/src/declarative/fx/qfxloader.cpp +++ b/src/declarative/fx/qfxloader.cpp @@ -312,6 +312,8 @@ qreal QFxLoader::progress() const \o SizeLoaderToItem - the Loader will be sized to the size of the item, unless the size of the Loader has been otherwise specified. \o SizeItemToLoader - the item will be sized to the size of the Loader. \endlist + + The default resizeMode is SizeLoaderToItem. */ QFxLoader::ResizeMode QFxLoader::resizeMode() const { -- cgit v0.12 From bd54370a759db272ce06d2fcdcce3e90c1dd17e8 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 9 Sep 2009 15:13:34 +1000 Subject: Add EaseFollow element --- doc/src/declarative/elements.qdoc | 1 + src/declarative/util/qmleasefollow.cpp | 391 +++++++++++++++++++++++++++++++++ src/declarative/util/qmleasefollow.h | 97 ++++++++ src/declarative/util/qmlfollow.h | 5 +- src/declarative/util/util.pri | 2 + 5 files changed, 493 insertions(+), 3 deletions(-) create mode 100644 src/declarative/util/qmleasefollow.cpp create mode 100644 src/declarative/util/qmleasefollow.h diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index bfaf4ab..47cb19c 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -37,6 +37,7 @@ The following table lists the QML elements provided by the Qt Declarative module \o \l ScriptAction \o \l Transition \o \l Follow +\o \l EaseFollow \o \l Behavior \endlist diff --git a/src/declarative/util/qmleasefollow.cpp b/src/declarative/util/qmleasefollow.cpp new file mode 100644 index 0000000..83dbde7 --- /dev/null +++ b/src/declarative/util/qmleasefollow.cpp @@ -0,0 +1,391 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmleasefollow.h" +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,EaseFollow,QmlEaseFollow); + +class QmlEaseFollowPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlEaseFollow) +public: + QmlEaseFollowPrivate() + : source(0), velocity(200), duration(-1), + reversingMode(QmlEaseFollow::Eased), initialVelocity(0), + initialValue(0), invert(false), trackVelocity(0), clockOffset(0), + lastTick(0), clock(this) + {} + + qreal source; + qreal velocity; + qreal duration; + QmlEaseFollow::ReversingMode reversingMode; + + qreal initialVelocity; + qreal initialValue; + bool invert; + + qreal trackVelocity; + + QmlMetaProperty target; + + int clockOffset; + int lastTick; + void tick(int); + void clockStart(); + void clockStop(); + QTickAnimationProxy clock; + + void restart(); + + // Parameters for use in tick() + qreal a; // Acceleration + qreal tf; // Total time + qreal tp; // Time at which peak velocity occurs + qreal vp; // Velocity at tp + qreal sp; // Displacement at tp + qreal vi; // "Normalized" initialvelocity + bool recalc(); +}; + +bool QmlEaseFollowPrivate::recalc() +{ + qreal s = source - initialValue; + vi = initialVelocity; + + s = (invert?-1.0:1.0) * s; + vi = (invert?-1.0:1.0) * vi; + + if (duration > 0 && velocity > 0) { + tf = s / velocity; + if (tf > (duration / 1000.)) tf = (duration / 1000.); + } else if (duration > 0) { + tf = duration / 1000.; + } else if (velocity > 0) { + tf = s / velocity; + } else { + return false; + } + + qreal c1 = 0.25 * tf * tf; + qreal c2 = 0.5 * vi * tf - s; + qreal c3 = -0.25 * vi * vi; + + qreal a1 = (-c2 + sqrt(c2 * c2 - 4 * c1 * c3)) / (2. * c1); + // qreal a2 = (-c2 - sqrt(c2 * c2 - 4 * c1 * c3)) / (2. * c1); + + qreal tp1 = 0.5 * tf - 0.5 * vi / a1; + // qreal tp2 = 0.5 * tf - 0.5 * vi / a2; + qreal vp1 = a1 * tp1 + vi; + // qreal vp2 = a2 * tp2 + vi; + + qreal sp1 = 0.5 * a1 * tp1 * tp1 + vi * tp1; + // qreal sp2 = 0.5 * a2 * tp2 * tp2 + vi * tp2; + + a = a1; + tp = tp1; + vp = vp1; + sp = sp1; + + return true; +} + +void QmlEaseFollowPrivate::clockStart() +{ + if (clock.state() == QAbstractAnimation::Running) { + clockOffset = lastTick; + return; + } else { + clockOffset = 0; + lastTick = 0; + clock.start(); + } +} + +void QmlEaseFollowPrivate::clockStop() +{ + clockOffset = 0; + lastTick = 0; + clock.stop(); +} + +void QmlEaseFollowPrivate::tick(int t) +{ + lastTick = t; + t -= clockOffset; + + qreal time_seconds = qreal(t) / 1000.; + + if (time_seconds < tp) { + + trackVelocity = vi + time_seconds * a; + trackVelocity = (invert?-1.0:1.0) * trackVelocity; + + qreal value = 0.5 * a * time_seconds * time_seconds + vi * time_seconds; + value = (invert?-1.0:1.0) * value; + target.write(initialValue + value); + + } else if (time_seconds < tf) { + + time_seconds -= tp; + + trackVelocity = vp - time_seconds * a; + trackVelocity = (invert?-1.0:1.0) * trackVelocity; + + qreal value = 0.5 * a * tp * tp + vi * tp + - 0.5 * a * time_seconds * time_seconds + vp * time_seconds; + value = (invert?-1.0:1.0) * value; + + target.write(initialValue + value); + + } else { + + clock.stop(); + + trackVelocity = 0; + target.write(source); + } +} + +/*! + \qmlclass EaseFollow QmlEaseFollow + \brief The EaseFollow element allows a property to smoothly track a value. + + The EaseFollow smoothly animates a property's value to a set target value + using an ease in/out quad easing curve. If the target value changes while + the animation is in progress, the easing curves used to animate to the old + and the new target values are spliced together to avoid any obvious visual + glitches. + + The property animation is configured by setting the velocity at which the + animation should occur, or the duration that the animation should take. + If both a velocity and a duration are specified, the one that results in + the quickest animation is chosen for each change in the target value. + + For example, animating from 0 to 800 will take 4 seconds if a velocity + of 200 is set, will take 8 seconds with a duration of 8000 set, and will + take 4 seconds with both a velocity of 200 and a duration of 8000 set. + Animating from 0 to 20000 will take 10 seconds if a velocity of 200 is set, + will take 8 seconds with a duration of 8000 set, and will take 8 seconds + with both a velocity of 200 and a duration of 8000 set. + + The follow example shows one rectangle tracking the position of another. +\code +import Qt 4.6 + +Rectangle { + width: 800; height: 600; color: "blue" + + Rectangle { + color: "green" + width: 60; height: 60; + x: -5; y: -5; + x: EaseFollow { source: Rect1.x - 5; velocity: 200 } + y: EaseFollow { source: Rect1.y - 5; velocity: 200 } + } + + Rectangle { + id: Rect1 + color: "red" + width: 50; height: 50; + } + + focus: true + Keys.onRightPressed: Rect1.x = Rect1.x + 100 + Keys.onLeftPressed: Rect1.x = Rect1.x - 100 + Keys.onUpPressed: Rect1.y = Rect1.y - 100 + Keys.onDownPressed: Rect1.y = Rect1.y + 100 +} +\endcode +*/ + +QmlEaseFollow::QmlEaseFollow(QObject *parent) +: QObject(*(new QmlEaseFollowPrivate), parent) +{ +} + +QmlEaseFollow::~QmlEaseFollow() +{ +} + +/*! + \qmlproperty qreal EaseFollow::source + This property holds the source value which will be tracked. + + Bind to a property in order to track its changes. +*/ +qreal QmlEaseFollow::sourceValue() const +{ + Q_D(const QmlEaseFollow); + return d->source; +} + +/*! + \qmlproperty enumeration EaseFollow::reversingMode + + Sets how the EaseFollow behaves if an animation diration is reversed. + + If reversing mode is \c Eased, the animation will smoothly decelerate, and + then reverse direction. If the reversing mode is \c Immediate, the + animation will immediately begin accelerating in the reverse direction, + begining with a velocity of 0. If the reversing mode is \c Sync, the + property is immediately set to the target value. +*/ +QmlEaseFollow::ReversingMode QmlEaseFollow::reversingMode() const +{ + Q_D(const QmlEaseFollow); + return d->reversingMode; +} + +void QmlEaseFollow::setReversingMode(ReversingMode m) +{ + Q_D(QmlEaseFollow); + d->reversingMode = m; +} + +void QmlEaseFollowPrivate::restart() +{ + initialValue = target.read().toReal(); + + if (source == initialValue) { + clockStop(); + return; + } + + bool hasReversed = trackVelocity != 0. && + ((trackVelocity > 0) == ((initialValue - source) > 0)); + + if (hasReversed) { + switch (reversingMode) { + default: + case QmlEaseFollow::Eased: + break; + case QmlEaseFollow::Sync: + target.write(source); + return; + case QmlEaseFollow::Immediate: + initialVelocity = 0; + clockStop(); + break; + } + } + + trackVelocity = initialVelocity; + + invert = (source < initialValue); + + if (!recalc()) { + target.write(source); + clockStop(); + return; + } + + clockStart(); +} + +void QmlEaseFollow::setSourceValue(qreal s) +{ + Q_D(QmlEaseFollow); + + d->source = s; + d->initialVelocity = d->trackVelocity; + d->restart(); +} + +/*! + \qmlproperty qreal EaseFollow::duration + + This property holds the animation duration used when tracking the source. + + Setting this to -1 disables the duration value. +*/ +qreal QmlEaseFollow::duration() const +{ + Q_D(const QmlEaseFollow); + return d->duration; +} + +void QmlEaseFollow::setDuration(qreal v) +{ + Q_D(QmlEaseFollow); + d->duration = v; + d->trackVelocity = 0; + + if (d->clock.state() == QAbstractAnimation::Running) + d->restart(); +} + +qreal QmlEaseFollow::velocity() const +{ + Q_D(const QmlEaseFollow); + return d->velocity; +} + +/*! + \qmlproperty qreal EaseFollow::velocity + + This property holds the average velocity allowed when tracking the source. + + Setting this to -1 disables the velocity value. +*/ +void QmlEaseFollow::setVelocity(qreal v) +{ + Q_D(QmlEaseFollow); + d->velocity = v; + d->trackVelocity = 0; + + if (d->clock.state() == QAbstractAnimation::Running) + d->restart(); +} + +void QmlEaseFollow::setTarget(const QmlMetaProperty &t) +{ + Q_D(QmlEaseFollow); + d->target = t; +} + +QT_END_NAMESPACE diff --git a/src/declarative/util/qmleasefollow.h b/src/declarative/util/qmleasefollow.h new file mode 100644 index 0000000..adcb647 --- /dev/null +++ b/src/declarative/util/qmleasefollow.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLEASEFOLLOW_H +#define QMLEASEFOLLOW_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlMetaProperty; +class QmlEaseFollowPrivate; +class Q_DECLARATIVE_EXPORT QmlEaseFollow : public QObject, + public QmlPropertyValueSource +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlEaseFollow) + Q_INTERFACES(QmlPropertyValueSource) + Q_ENUMS(ReversingMode) + + Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue) + Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) + Q_PROPERTY(qreal duration READ duration WRITE setDuration) + Q_PROPERTY(ReversingMode reversingMode READ reversingMode WRITE setReversingMode) + +public: + enum ReversingMode { Eased, Immediate, Sync }; + + QmlEaseFollow(QObject *parent = 0); + ~QmlEaseFollow(); + + ReversingMode reversingMode() const; + void setReversingMode(ReversingMode); + + qreal sourceValue() const; + void setSourceValue(qreal); + + qreal velocity() const; + void setVelocity(qreal); + + qreal duration() const; + void setDuration(qreal); + + virtual void setTarget(const QmlMetaProperty &); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlEaseFollow); + +QT_END_HEADER + +#endif // QMLEASEFOLLOW_H diff --git a/src/declarative/util/qmlfollow.h b/src/declarative/util/qmlfollow.h index 1f6376a..ff34d08 100644 --- a/src/declarative/util/qmlfollow.h +++ b/src/declarative/util/qmlfollow.h @@ -52,13 +52,12 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QmlFollowPrivate; -class Q_DECLARATIVE_EXPORT QmlFollow : public QObject, public QmlPropertyValueSource, - public QmlParserStatus +class Q_DECLARATIVE_EXPORT QmlFollow : public QObject, + public QmlPropertyValueSource { Q_OBJECT Q_DECLARE_PRIVATE(QmlFollow) Q_INTERFACES(QmlPropertyValueSource) - Q_INTERFACES(QmlParserStatus) Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue) Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index f1b599f..a57f69f 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -8,6 +8,7 @@ SOURCES += \ util/qmlanimation.cpp \ util/qmlsystempalette.cpp \ util/qmlfollow.cpp \ + util/qmleasefollow.cpp \ util/qmlstate.cpp\ util/qmltransitionmanager.cpp \ util/qmlstateoperations.cpp \ @@ -33,6 +34,7 @@ HEADERS += \ util/qmlanimation_p.h \ util/qmlsystempalette.h \ util/qmlfollow.h \ + util/qmleasefollow.h \ util/qmlstate.h\ util/qmlstateoperations.h \ util/qmlpropertychanges.h \ -- cgit v0.12 From 543b7355a03a7010ec767dba3f538b96aacc4e89 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 9 Sep 2009 15:44:58 +1000 Subject: Fix more autotests You can now expect autotests to pass (as much as the rest of Qt) Tests updated: NumberFormatter PathView QBindableMap QFxText QFxTextEdit (still fails) Repeater --- .../numberformatter/tst_numberformatter.cpp | 15 +- tests/auto/declarative/pathview/data/pathview.qml | 10 +- tests/auto/declarative/pathview/tst_pathview.cpp | 8 +- .../declarative/qbindablemap/tst_qbindablemap.cpp | 4 +- tests/auto/declarative/qfxtext/tst_qfxtext.cpp | 160 ++++++++++----------- .../declarative/qfxtextedit/data/cursorTest.qml | 6 +- .../declarative/qfxtextedit/tst_qfxtextedit.cpp | 64 ++++----- tests/auto/declarative/repeater/data/repeater.qml | 6 +- tests/auto/declarative/repeater/tst_repeater.cpp | 22 +-- 9 files changed, 156 insertions(+), 139 deletions(-) diff --git a/tests/auto/declarative/numberformatter/tst_numberformatter.cpp b/tests/auto/declarative/numberformatter/tst_numberformatter.cpp index 9a2f4f3..78ec347 100644 --- a/tests/auto/declarative/numberformatter/tst_numberformatter.cpp +++ b/tests/auto/declarative/numberformatter/tst_numberformatter.cpp @@ -166,11 +166,15 @@ void tst_numberformat::number() QFETCH(QString, string); QFETCH(float, number); - QString componentStr = QString("NumberFormatter { number: \"") + string + QString("\" }"); + QString componentStr = QString("import Qt 4.6\nNumberFormatter { number: \"") + string + QString("\" }"); QmlEngine engine; - QmlComponent formatterComponent(&engine, componentStr.toAscii()); + QmlComponent formatterComponent(&engine, componentStr.toAscii(), QUrl("file://")); + if(formatterComponent.isError()) + qDebug() << formatterComponent.errors(); + QVERIFY(formatterComponent.isReady()); QmlNumberFormatter *formatter = qobject_cast(formatterComponent.create()); + QVERIFY(formatterComponent.isReady()); QVERIFY(formatter != 0); QCOMPARE((float)formatter->number(), number); //qDebug() << formatter->format() << formatter->text(); @@ -201,10 +205,13 @@ void tst_numberformat::text() QFETCH(QString, format); QFETCH(QString, text); - QString componentStr = QString("NumberFormatter { number: \"") + string + QString("\"; format: \"") + format + QString("\" }"); + QString componentStr = QString("import Qt 4.6\nNumberFormatter { number: \"") + string + QString("\"; format: \"") + format + QString("\" }"); QmlEngine engine; - QmlComponent formatterComponent(&engine, componentStr.toAscii()); + QmlComponent formatterComponent(&engine, componentStr.toAscii(), QUrl("file://")); + if(formatterComponent.isError()) + qDebug() << formatterComponent.errors(); + QVERIFY(formatterComponent.isReady()); QmlNumberFormatter *formatter = qobject_cast(formatterComponent.create()); QVERIFY(formatter != 0); diff --git a/tests/auto/declarative/pathview/data/pathview.qml b/tests/auto/declarative/pathview/data/pathview.qml index 7040e4c..be5673c 100644 --- a/tests/auto/declarative/pathview/data/pathview.qml +++ b/tests/auto/declarative/pathview/data/pathview.qml @@ -1,14 +1,15 @@ import Qt 4.6 -Rect { +Rectangle { width: 240 height: 320 color: "#ffffff" resources: [ Component { id: Delegate - Rect { + Rectangle { id: wrapper + objectName: "wrapper" height: 20 width: 60 color: "white" @@ -19,11 +20,13 @@ Rect { Text { x: 20 id: textName + objectName: "textName" text: name } Text { x: 40 id: textNumber + objectName: "textNumber" text: number } } @@ -31,11 +34,12 @@ Rect { ] PathView { id: view + objectName: "view" width: 240 height: 320 model: testModel delegate: Delegate - snapPos: 0.01 + snapPosition: 0.01 path: Path { startY: 120 startX: 160 diff --git a/tests/auto/declarative/pathview/tst_pathview.cpp b/tests/auto/declarative/pathview/tst_pathview.cpp index 9cae961..2933323 100644 --- a/tests/auto/declarative/pathview/tst_pathview.cpp +++ b/tests/auto/declarative/pathview/tst_pathview.cpp @@ -117,7 +117,7 @@ void tst_QFxPathView::items() QFxPathView *pathview = findItem(canvas->root(), "view"); QVERIFY(pathview != 0); - QCOMPARE(pathview->children()->count(), model.count()); // assumes all are visible + QCOMPARE(pathview->childItems().count(), model.count()); // assumes all are visible for (int i = 0; i < model.count(); ++i) { QFxText *name = findItem(pathview, "textName", i); @@ -234,8 +234,10 @@ template T *tst_QFxPathView::findItem(QFxItem *parent, const QString &objectName, int index) { const QMetaObject &mo = T::staticMetaObject; - for (int i = 0; i < parent->children()->count(); ++i) { - QFxItem *item = parent->children()->at(i); + for (int i = 0; i < parent->children().count(); ++i) { + QFxItem *item = qobject_cast(parent->children().at(i)); + if(!item) + continue; if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { if (index != -1) { QmlExpression e(qmlContext(item), "index", item); diff --git a/tests/auto/declarative/qbindablemap/tst_qbindablemap.cpp b/tests/auto/declarative/qbindablemap/tst_qbindablemap.cpp index a8046e6..c9c37ab 100644 --- a/tests/auto/declarative/qbindablemap/tst_qbindablemap.cpp +++ b/tests/auto/declarative/qbindablemap/tst_qbindablemap.cpp @@ -59,7 +59,9 @@ void tst_QBindableMap::changed() QmlEngine engine; QmlContext *ctxt = engine.rootContext(); ctxt->setContextProperty(QLatin1String("data"), &map); - QmlComponent component(&engine, "Script { script: \"data.key1 = 'Hello World';\" }"); + QmlComponent component(&engine, "import Qt 4.6\nScript { script: \"data.key1 = 'Hello World';\" }", + QUrl("file://")); + QVERIFY(component.isReady()); component.create(); QCOMPARE(spy.count(), 1); QList arguments = spy.takeFirst(); diff --git a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp index 0eb9f97..cae85a4 100644 --- a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp +++ b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp @@ -19,8 +19,8 @@ private slots: void elide(); // ### these tests may be trivial - void hAlign(); - void vAlign(); + void horizontalAlignment(); + void verticalAlignment(); void font(); void style(); void color(); @@ -29,11 +29,11 @@ private: QStringList standard; QStringList richText; - QStringList hAlignmentStrings; - QStringList vAlignmentStrings; + QStringList horizontalAlignmentmentStrings; + QStringList verticalAlignmentmentStrings; - QList vAlignments; - QList hAlignments; + QList verticalAlignmentments; + QList horizontalAlignmentments; QStringList styleStrings; QList styles; @@ -51,19 +51,19 @@ tst_qfxtext::tst_qfxtext() richText << "the quick brown fox jumped over the lazy dog" << "the quick brown fox
jumped over the lazy dog
"; - hAlignmentStrings << "AlignLeft" + horizontalAlignmentmentStrings << "AlignLeft" << "AlignRight" << "AlignHCenter"; - vAlignmentStrings << "AlignTop" + verticalAlignmentmentStrings << "AlignTop" << "AlignBottom" << "AlignVCenter"; - hAlignments << Qt::AlignLeft + horizontalAlignmentments << Qt::AlignLeft << Qt::AlignRight << Qt::AlignHCenter; - vAlignments << Qt::AlignTop + verticalAlignmentments << Qt::AlignTop << Qt::AlignBottom << Qt::AlignVCenter; @@ -99,7 +99,7 @@ tst_qfxtext::tst_qfxtext() void tst_qfxtext::text() { { - QmlComponent textComponent(&engine, "Text { text: \"\" }"); + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QVERIFY(textObject != 0); @@ -108,8 +108,8 @@ void tst_qfxtext::text() for (int i = 0; i < standard.size(); i++) { - QString componentStr = "Text { text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QVERIFY(textObject != 0); @@ -118,8 +118,8 @@ void tst_qfxtext::text() for (int i = 0; i < richText.size(); i++) { - QString componentStr = "Text { text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QVERIFY(textObject != 0); @@ -132,7 +132,7 @@ void tst_qfxtext::width() { // uses Font metrics to find the width for standard and document to find the width for rich { - QmlComponent textComponent(&engine, "Text { text: \"\" }"); + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 0.); @@ -144,8 +144,8 @@ void tst_qfxtext::width() QFontMetrics fm(f); int metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); - QString componentStr = "Text { text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), qreal(metricWidth)); @@ -159,8 +159,8 @@ void tst_qfxtext::width() int documentWidth = document.idealWidth(); - QString componentStr = "Text { text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), qreal(documentWidth)); @@ -173,7 +173,7 @@ void tst_qfxtext::wrap() // for specified width and wrap set true { - QmlComponent textComponent(&engine, "Text { text: \"\"; wrap: true; width: 300 }"); + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\"; wrap: true; width: 300 }", QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 300.); @@ -181,8 +181,8 @@ void tst_qfxtext::wrap() for (int i = 0; i < standard.size(); i++) { - QString componentStr = "Text { wrap: true; width: 300; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 300; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 300.); @@ -190,8 +190,8 @@ void tst_qfxtext::wrap() for (int i = 0; i < richText.size(); i++) { - QString componentStr = "Text { wrap: true; width: 300; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 300; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 300.); @@ -208,7 +208,7 @@ void tst_qfxtext::elide() // XXX Poor coverage. { - QmlComponent textComponent(&engine, ("Text { text: \"\"; "+elide+" width: 300 }").toLatin1()); + QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 300 }").toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 300.); @@ -216,8 +216,8 @@ void tst_qfxtext::elide() for (int i = 0; i < standard.size(); i++) { - QString componentStr = "Text { "+elide+" width: 300; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 300.); @@ -226,8 +226,8 @@ void tst_qfxtext::elide() // richtext - does nothing for (int i = 0; i < richText.size(); i++) { - QString componentStr = "Text { "+elide+" width: 300; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 300.); @@ -236,61 +236,61 @@ void tst_qfxtext::elide() } //the alignment tests may be trivial o.oa -void tst_qfxtext::hAlign() +void tst_qfxtext::horizontalAlignment() { //test one align each, and then test if two align fails. for (int i = 0; i < standard.size(); i++) { - for (int j=0; j < hAlignmentStrings.size(); j++) + for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) { - QString componentStr = "Text { hAlign: \"" + hAlignmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); - QCOMPARE((int)textObject->hAlign(), (int)hAlignments.at(j)); + QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); } } for (int i = 0; i < richText.size(); i++) { - for (int j=0; j < hAlignmentStrings.size(); j++) + for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) { - QString componentStr = "Text { hAlign: \"" + hAlignmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); - QCOMPARE((int)textObject->hAlign(), (int)hAlignments.at(j)); + QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); } } } -void tst_qfxtext::vAlign() +void tst_qfxtext::verticalAlignment() { //test one align each, and then test if two align fails. for (int i = 0; i < standard.size(); i++) { - for (int j=0; j < vAlignmentStrings.size(); j++) + for (int j=0; j < verticalAlignmentmentStrings.size(); j++) { - QString componentStr = "Text { vAlign: \"" + vAlignmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); - QCOMPARE((int)textObject->vAlign(), (int)vAlignments.at(j)); + QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); } } for (int i = 0; i < richText.size(); i++) { - for (int j=0; j < vAlignmentStrings.size(); j++) + for (int j=0; j < verticalAlignmentmentStrings.size(); j++) { - QString componentStr = "Text { vAlign: \"" + vAlignmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); - QCOMPARE((int)textObject->vAlign(), (int)vAlignments.at(j)); + QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); } } @@ -300,49 +300,49 @@ void tst_qfxtext::font() { //test size, then bold, then italic, then family { - QString componentStr = "Text { font.size: 40; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { font.pointSize: 40; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->font()->size(), qreal(40)); - QCOMPARE(textObject->font()->bold(), false); - QCOMPARE(textObject->font()->italic(), false); + QCOMPARE(textObject->font().pointSize(), 40); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); } { - QString componentStr = "Text { font.bold: true; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { font.bold: true; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->font()->bold(), true); - QCOMPARE(textObject->font()->italic(), false); + QCOMPARE(textObject->font().bold(), true); + QCOMPARE(textObject->font().italic(), false); } { - QString componentStr = "Text { font.italic: true; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { font.italic: true; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->font()->italic(), true); - QCOMPARE(textObject->font()->bold(), false); + QCOMPARE(textObject->font().italic(), true); + QCOMPARE(textObject->font().bold(), false); } - + { - QString componentStr = "Text { font.family: \"Helvetica\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { font.family: \"Helvetica\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->font()->family(), QString("Helvetica")); - QCOMPARE(textObject->font()->bold(), false); - QCOMPARE(textObject->font()->italic(), false); + QCOMPARE(textObject->font().family(), QString("Helvetica")); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); } { - QString componentStr = "Text { font.family: \"\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { font.family: \"\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->font()->family(), QString("")); + QCOMPARE(textObject->font().family(), QString("")); } } @@ -351,8 +351,8 @@ void tst_qfxtext::style() //test style for (int i = 0; i < styles.size(); i++) { - QString componentStr = "Text { style: \"" + styleStrings.at(i) + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE((int)textObject->style(), (int)styles.at(i)); @@ -365,8 +365,8 @@ void tst_qfxtext::color() //test style for (int i = 0; i < colorStrings.size(); i++) { - QString componentStr = "Text { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); @@ -375,8 +375,8 @@ void tst_qfxtext::color() for (int i = 0; i < colorStrings.size(); i++) { - QString componentStr = "Text { styleColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { styleColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(i))); @@ -388,8 +388,8 @@ void tst_qfxtext::color() { for (int j = 0; j < colorStrings.size(); j++) { - QString componentStr = "Text { color: \"" + colorStrings.at(i) + "\"; styleColor: \"" + colorStrings.at(j) + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; styleColor: \"" + colorStrings.at(j) + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); @@ -401,8 +401,8 @@ void tst_qfxtext::color() QColor testColor("#001234"); testColor.setAlpha(170); - QString componentStr = "Text { color: \"" + colorStr + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1()); + QString componentStr = "import Qt 4.6\nText { color: \"" + colorStr + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QFxText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->color(), testColor); diff --git a/tests/auto/declarative/qfxtextedit/data/cursorTest.qml b/tests/auto/declarative/qfxtextedit/data/cursorTest.qml index 25e53d0..e5df8f1 100644 --- a/tests/auto/declarative/qfxtextedit/data/cursorTest.qml +++ b/tests/auto/declarative/qfxtextedit/data/cursorTest.qml @@ -1,8 +1,8 @@ import Qt 4.6 -Rect { width: 300; height: 300; color: "white" - TextEdit { text: "Hello world!"; focusable: true; id: textEditObject - resources: [ Component { id:cursor; Item { id:cursorInstance } } ] +Rectangle { width: 300; height: 300; color: "white" + TextEdit { text: "Hello world!"; id: textEditObject; objectName: "textEditObject" + resources: [ Component { id:cursor; Item { id:cursorInstance; objectName: "cursorInstance" } } ] cursorDelegate: cursor } } diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp index 241dbad..c4fc506 100644 --- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp +++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp @@ -89,7 +89,7 @@ tst_qfxtextedit::tst_qfxtextedit() void tst_qfxtextedit::text() { { - QmlComponent texteditComponent(&engine, "TextEdit { text: \"\" }", QUrl()); + QmlComponent texteditComponent(&engine, "import Qt 4.6\nTextEdit { text: \"\" }", QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); @@ -98,7 +98,7 @@ void tst_qfxtextedit::text() for (int i = 0; i < standard.size(); i++) { - QString componentStr = "TextEdit { text: \"" + standard.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { text: \"" + standard.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -108,7 +108,7 @@ void tst_qfxtextedit::text() for (int i = 0; i < richText.size(); i++) { - QString componentStr = "TextEdit { text: \"" + richText.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { text: \"" + richText.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -126,7 +126,7 @@ void tst_qfxtextedit::width() { // uses Font metrics to find the width for standard and document to find the width for rich { - QmlComponent texteditComponent(&engine, "TextEdit { text: \"\" }", QUrl()); + QmlComponent texteditComponent(&engine, "import Qt 4.6\nTextEdit { text: \"\" }", QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); @@ -139,7 +139,7 @@ void tst_qfxtextedit::width() QFontMetrics fm(f); int metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); - QString componentStr = "TextEdit { text: \"" + standard.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { text: \"" + standard.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -155,7 +155,7 @@ void tst_qfxtextedit::width() int documentWidth = document.idealWidth(); - QString componentStr = "TextEdit { text: \"" + richText.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { text: \"" + richText.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -168,7 +168,7 @@ void tst_qfxtextedit::wrap() { // for specified width and wrap set true { - QmlComponent texteditComponent(&engine, "TextEdit { text: \"\"; wrap: true; width: 300 }", QUrl()); + QmlComponent texteditComponent(&engine, "import Qt 4.6\nTextEdit { text: \"\"; wrap: true; width: 300 }", QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); @@ -177,7 +177,7 @@ void tst_qfxtextedit::wrap() for (int i = 0; i < standard.size(); i++) { - QString componentStr = "TextEdit { wrap: true; width: 300; text: \"" + standard.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { wrap: true; width: 300; text: \"" + standard.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -187,7 +187,7 @@ void tst_qfxtextedit::wrap() for (int i = 0; i < richText.size(); i++) { - QString componentStr = "TextEdit { wrap: true; width: 300; text: \"" + richText.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { wrap: true; width: 300; text: \"" + richText.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -206,7 +206,7 @@ void tst_qfxtextedit::hAlign() { for (int j=0; j < hAlignmentStrings.size(); j++) { - QString componentStr = "TextEdit { hAlign: \"" + hAlignmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { horizontalAlignment: \"" + hAlignmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -219,7 +219,7 @@ void tst_qfxtextedit::hAlign() { for (int j=0; j < hAlignmentStrings.size(); j++) { - QString componentStr = "TextEdit { hAlign: \"" + hAlignmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { horizontalAlignment: \"" + hAlignmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -238,7 +238,7 @@ void tst_qfxtextedit::vAlign() { for (int j=0; j < vAlignmentStrings.size(); j++) { - QString componentStr = "TextEdit { vAlign: \"" + vAlignmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { verticalAlignment: \"" + vAlignmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -251,7 +251,7 @@ void tst_qfxtextedit::vAlign() { for (int j=0; j < vAlignmentStrings.size(); j++) { - QString componentStr = "TextEdit { vAlign: \"" + vAlignmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { verticalAlignment: \"" + vAlignmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -266,54 +266,54 @@ void tst_qfxtextedit::font() { //test size, then bold, then italic, then family { - QString componentStr = "TextEdit { font.size: 40; text: \"Hello World\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { font.pointSize: 40; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); - QCOMPARE(textEditObject->font()->size(), qreal(40)); - QCOMPARE(textEditObject->font()->bold(), false); - QCOMPARE(textEditObject->font()->italic(), false); + QCOMPARE(textEditObject->font().pointSize(), 40); + QCOMPARE(textEditObject->font().bold(), false); + QCOMPARE(textEditObject->font().italic(), false); } { - QString componentStr = "TextEdit { font.bold: true; text: \"Hello World\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { font.bold: true; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); - QCOMPARE(textEditObject->font()->bold(), true); - QCOMPARE(textEditObject->font()->italic(), false); + QCOMPARE(textEditObject->font().bold(), true); + QCOMPARE(textEditObject->font().italic(), false); } { - QString componentStr = "TextEdit { font.italic: true; text: \"Hello World\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { font.italic: true; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); - QCOMPARE(textEditObject->font()->italic(), true); - QCOMPARE(textEditObject->font()->bold(), false); + QCOMPARE(textEditObject->font().italic(), true); + QCOMPARE(textEditObject->font().bold(), false); } { - QString componentStr = "TextEdit { font.family: \"Helvetica\"; text: \"Hello World\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { font.family: \"Helvetica\"; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); - QCOMPARE(textEditObject->font()->family(), QString("Helvetica")); - QCOMPARE(textEditObject->font()->bold(), false); - QCOMPARE(textEditObject->font()->italic(), false); + QCOMPARE(textEditObject->font().family(), QString("Helvetica")); + QCOMPARE(textEditObject->font().bold(), false); + QCOMPARE(textEditObject->font().italic(), false); } { - QString componentStr = "TextEdit { font.family: \"\"; text: \"Hello World\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { font.family: \"\"; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); - QCOMPARE(textEditObject->font()->family(), QString("")); + QCOMPARE(textEditObject->font().family(), QString("")); } } @@ -322,7 +322,7 @@ void tst_qfxtextedit::color() //test style for (int i = 0; i < colorStrings.size(); i++) { - QString componentStr = "TextEdit { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); //qDebug() << "textEditObject: " << textEditObject->color() << "vs. " << QColor(colorStrings.at(i)); @@ -335,7 +335,7 @@ void tst_qfxtextedit::color() QColor testColor("#001234"); testColor.setAlpha(170); - QString componentStr = "TextEdit { color: \"" + colorStr + "\"; text: \"Hello World\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { color: \"" + colorStr + "\"; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -347,7 +347,7 @@ void tst_qfxtextedit::color() void tst_qfxtextedit::selection() { QString testStr = standard[0];//TODO: What should happen for multiline/rich text? - QString componentStr = "TextEdit { text: \""+ testStr +"\"; }"; + QString componentStr = "import Qt 4.6\nTextEdit { text: \""+ testStr +"\"; }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); diff --git a/tests/auto/declarative/repeater/data/repeater.qml b/tests/auto/declarative/repeater/data/repeater.qml index 57b1183..57ba9dc 100644 --- a/tests/auto/declarative/repeater/data/repeater.qml +++ b/tests/auto/declarative/repeater/data/repeater.qml @@ -1,15 +1,17 @@ import Qt 4.6 -Rect { +Rectangle { id: container + objectName: "container" width: 240 height: 320 color: "white" Repeater { id: repeater + objectName: "repeater" width: 240 height: 320 - dataSource: testData + model: testData Component { Text { y: index*20 diff --git a/tests/auto/declarative/repeater/tst_repeater.cpp b/tests/auto/declarative/repeater/tst_repeater.cpp index 0e7c187..08f9154 100644 --- a/tests/auto/declarative/repeater/tst_repeater.cpp +++ b/tests/auto/declarative/repeater/tst_repeater.cpp @@ -17,7 +17,7 @@ private slots: private: QFxView *createView(const QString &filename); template - T *findItem(QFxItem *parent, const QString &id); + T *findItem(QObject *parent, const QString &id); }; tst_QFxRepeater::tst_QFxRepeater() @@ -26,7 +26,7 @@ tst_QFxRepeater::tst_QFxRepeater() void tst_QFxRepeater::stringList() { - QFxView *canvas = createView(SRCDIR "/data/repeater.xml"); + QFxView *canvas = createView(SRCDIR "/data/repeater.qml"); QStringList data; data << "One"; @@ -35,7 +35,7 @@ void tst_QFxRepeater::stringList() data << "Four"; QmlContext *ctxt = canvas->rootContext(); - ctxt->setProperty("testData", data); + ctxt->setContextProperty("testData", data); canvas->execute(); qApp->processEvents(); @@ -46,10 +46,10 @@ void tst_QFxRepeater::stringList() QFxItem *container = findItem(canvas->root(), "container"); QVERIFY(container != 0); - QCOMPARE(container->children()->count(), data.count() + 1); + QCOMPARE(container->childItems().count(), data.count() + 1); - for (int i = 1; i < container->children()->count(); ++i) { - QFxText *name = qobject_cast(container->children()->at(i)); + for (int i = 1; i < container->childItems().count(); ++i) { + QFxText *name = qobject_cast(container->childItems().at(i)); QVERIFY(name != 0); QCOMPARE(name->text(), data.at(i-1)); } @@ -65,20 +65,20 @@ QFxView *tst_QFxRepeater::createView(const QString &filename) QFile file(filename); file.open(QFile::ReadOnly); - QString xml = file.readAll(); - canvas->setQml(xml, filename); + QString qml = file.readAll(); + canvas->setQml(qml, filename); return canvas; } template -T *tst_QFxRepeater::findItem(QFxItem *parent, const QString &objectName) +T *tst_QFxRepeater::findItem(QObject *parent, const QString &objectName) { const QMetaObject &mo = T::staticMetaObject; if (mo.cast(parent) && (objectName.isEmpty() || parent->objectName() == objectName)) return static_cast(parent); - for (int i = 0; i < parent->children()->count(); ++i) { - QFxItem *item = findItem(parent->children()->at(i), objectName); + for (int i = 0; i < parent->children().count(); ++i) { + QFxItem *item = findItem(parent->children().at(i), objectName); if (item) return static_cast(item); } -- cgit v0.12 From ccccc25802bdd0af806c3a1aaa83759b9e6706de Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 9 Sep 2009 15:46:47 +1000 Subject: clearer example --- examples/declarative/listview/dynamic.qml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml index 5111cec..f615c24 100644 --- a/examples/declarative/listview/dynamic.qml +++ b/examples/declarative/listview/dynamic.qml @@ -1,7 +1,7 @@ import Qt 4.6 Item { - width: 300 + width: 320 height: 500 ListModel { @@ -114,15 +114,23 @@ Item { MouseRegion { anchors.fill: parent; onClicked: { FruitModel.append({ - "name":"Pizza", + "name":"Pizza Margarita", "cost":5.95, - "attributes":[{"description": "Supreme"},{"description": "Margarita"}] + "attributes":[{"description": "Cheese"},{"description": "Tomato"}] }) } } } Image { source: "content/pics/add.png" - MouseRegion { anchors.fill: parent; onClicked: FruitModel.insert(0,{"name":"Pizza", "cost":5.95}) } + MouseRegion { anchors.fill: parent; + onClicked: { + FruitModel.insert(0,{ + "name":"Pizza Supreme", + "cost":9.95, + "attributes":[{"description": "Cheese"},{"description": "Tomato"},{"description": "The Works"}] + }) + } + } } Image { source: "content/pics/trash.png" MouseRegion { anchors.fill: parent; onClicked: FruitModel.clear() } -- cgit v0.12 From 4c0abed6af10a2722ad3f1fd352caa3fe673468e Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 9 Sep 2009 15:47:08 +1000 Subject: Don't allow sparse-setting, since not efficient anyway. --- src/declarative/util/qmllistmodel.cpp | 38 +++++++++++++++-------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index 8e5ea9c..f988d81 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -461,8 +461,8 @@ void QmlListModel::remove(int index) FruitModel.insert(2, {"cost": 5.95, "name":"Pizza"}) \endcode - If \a index is not in the list, sufficient empty items are - added to the list. + The \a index must be to an existing item in the list, or one past + the end of the list (equivalent to append). \sa set() append() */ @@ -471,7 +471,8 @@ void QmlListModel::insert(int index, const QScriptValue& valuemap) if (!_root) _root = new ModelNode; if (index >= _root->values.count()) { - set(index,valuemap); + if (index == _root->values.count()) + append(valuemap); return; } ModelNode *mn = new ModelNode; @@ -562,8 +563,7 @@ void QmlListModel::append(const QScriptValue& valuemap) FruitModel.set(3, {"cost": 5.95, "name":"Pizza"}) \endcode - If \a index is not in the list, sufficient empty items are - added to the list. + The \a index must be an element in the list. \sa append() */ @@ -571,9 +571,10 @@ void QmlListModel::set(int index, const QScriptValue& valuemap) { if (!_root) _root = new ModelNode; - int initialcount = _root->values.count(); - while (index > _root->values.count()) - _root->values.append(qVariantFromValue(new ModelNode)); + if ( index >= _root->values.count()) { + qWarning() << "ListModel::set index out of range:" << index; + return; + } if (index == _root->values.count()) append(valuemap); else { @@ -590,11 +591,7 @@ void QmlListModel::set(int index, const QScriptValue& valuemap) } roles.append(r); } - if (initialcount < index) { - emit itemsInserted(initialcount,index-initialcount+1); - } else { - emit itemsChanged(index,1,roles); - } + emit itemsChanged(index,1,roles); } } @@ -607,8 +604,7 @@ void QmlListModel::set(int index, const QScriptValue& valuemap) FruitModel.set(3, "cost", 5.95) \endcode - If \a index is not in the list, sufficient empty items are - added to the list. + The \a index must be an element in the list. \sa append() */ @@ -616,9 +612,10 @@ void QmlListModel::set(int index, const QString& property, const QVariant& value { if (!_root) _root = new ModelNode; - int initialcount = _root->values.count(); - while (index >= _root->values.count()) - _root->values.append(qVariantFromValue(new ModelNode)); + if ( index >= _root->values.count()) { + qWarning() << "ListModel::set index out of range:" << index; + return; + } ModelNode *node = qvariant_cast(_root->values.at(index)); int r = roleStrings.indexOf(property); if (r<0) { @@ -630,10 +627,7 @@ void QmlListModel::set(int index, const QString& property, const QVariant& value if (node) node->setProperty(property,value); - if (initialcount < index) - emit itemsInserted(initialcount,index-initialcount+1); - else - emit itemsChanged(index,1,roles); + emit itemsChanged(index,1,roles); } -- cgit v0.12 From 25bed69b3c643943dac195227d3f3fadc441516c Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 9 Sep 2009 17:48:13 +1000 Subject: Autotest for property aliases --- tests/auto/declarative/qmlparser/Alias.qml | 8 +++ tests/auto/declarative/qmlparser/alias.1.qml | 8 +++ tests/auto/declarative/qmlparser/alias.2.qml | 8 +++ tests/auto/declarative/qmlparser/alias.3.qml | 10 +++ tests/auto/declarative/qmlparser/testtypes.h | 8 ++- tests/auto/declarative/qmlparser/tst_qmlparser.cpp | 71 ++++++++++++++++++++++ 6 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qmlparser/Alias.qml create mode 100644 tests/auto/declarative/qmlparser/alias.1.qml create mode 100644 tests/auto/declarative/qmlparser/alias.2.qml create mode 100644 tests/auto/declarative/qmlparser/alias.3.qml diff --git a/tests/auto/declarative/qmlparser/Alias.qml b/tests/auto/declarative/qmlparser/Alias.qml new file mode 100644 index 0000000..8264e0d --- /dev/null +++ b/tests/auto/declarative/qmlparser/Alias.qml @@ -0,0 +1,8 @@ +import Qt 4.6 + +Object { + id: Root + property int value: 1892 + property alias aliasValue: Root.value +} + diff --git a/tests/auto/declarative/qmlparser/alias.1.qml b/tests/auto/declarative/qmlparser/alias.1.qml new file mode 100644 index 0000000..492d99a --- /dev/null +++ b/tests/auto/declarative/qmlparser/alias.1.qml @@ -0,0 +1,8 @@ +import Test 1.0 +import Qt 4.6 + +Object { + id: Root + property int value: 10 + property alias valueAlias: Root.value +} diff --git a/tests/auto/declarative/qmlparser/alias.2.qml b/tests/auto/declarative/qmlparser/alias.2.qml new file mode 100644 index 0000000..aa4d103 --- /dev/null +++ b/tests/auto/declarative/qmlparser/alias.2.qml @@ -0,0 +1,8 @@ +import Test 1.0 + +MyQmlObject { + id: Root + property alias aliasObject: Root.qmlobjectProperty + + qmlobjectProperty: MyQmlObject { value : 10 } +} diff --git a/tests/auto/declarative/qmlparser/alias.3.qml b/tests/auto/declarative/qmlparser/alias.3.qml new file mode 100644 index 0000000..e25fbae --- /dev/null +++ b/tests/auto/declarative/qmlparser/alias.3.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +Object { + property var other + other: Alias { id: MyAliasObject } + + property alias value: MyAliasObject.aliasValue + property alias value2: MyAliasObject.value +} + diff --git a/tests/auto/declarative/qmlparser/testtypes.h b/tests/auto/declarative/qmlparser/testtypes.h index 3b5d3ae..e3e9aae 100644 --- a/tests/auto/declarative/qmlparser/testtypes.h +++ b/tests/auto/declarative/qmlparser/testtypes.h @@ -59,9 +59,11 @@ class MyQmlObject : public QObject, public MyInterface, public QmlParserStatus Q_PROPERTY(MyInterface *interfaceProperty READ interface WRITE setInterface) Q_PROPERTY(int onLiteralSignal READ onLiteralSignal WRITE setOnLiteralSignal); Q_PROPERTY(MyCustomVariantType customType READ customType WRITE setCustomType); + Q_PROPERTY(MyQmlObject *qmlobjectProperty READ qmlobject WRITE setQmlobject) + Q_INTERFACES(MyInterface QmlParserStatus) public: - MyQmlObject() : m_value(-1), m_interface(0) { qRegisterMetaType("MyCustomVariantType"); } + MyQmlObject() : m_value(-1), m_interface(0), m_qmlobject(0) { qRegisterMetaType("MyCustomVariantType"); } int value() const { return m_value; } void setValue(int v) { m_value = v; } @@ -88,6 +90,9 @@ public: int onLiteralSignal() const { return m_value; } void setOnLiteralSignal(int v) { m_value = v; } + MyQmlObject *qmlobject() const { return m_qmlobject; } + void setQmlobject(MyQmlObject *o) { m_qmlobject = o; } + MyCustomVariantType customType() const { return m_custom; } void setCustomType(const MyCustomVariantType &v) { m_custom = v; } public slots: @@ -100,6 +105,7 @@ private: friend class tst_qmlparser; int m_value; MyInterface *m_interface; + MyQmlObject *m_qmlobject; MyCustomVariantType m_custom; }; QML_DECLARE_TYPE(MyQmlObject); diff --git a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp index e3735e7..93666aa 100644 --- a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp +++ b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp @@ -48,6 +48,7 @@ private slots: void customVariantTypes(); void valueTypes(); void cppnamespace(); + void aliasProperties(); void importsBuiltin_data(); void importsBuiltin(); @@ -517,6 +518,76 @@ void tst_qmlparser::cppnamespace() delete object; } +void tst_qmlparser::aliasProperties() +{ + // Simple "int" alias + { + QmlComponent component(&engine, TEST_FILE("alias.1.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + // Read through alias + QCOMPARE(object->property("valueAlias").toInt(), 10); + object->setProperty("value", QVariant(13)); + QCOMPARE(object->property("valueAlias").toInt(), 13); + + // Write throught alias + object->setProperty("valueAlias", QVariant(19)); + QCOMPARE(object->property("valueAlias").toInt(), 19); + QCOMPARE(object->property("value").toInt(), 19); + + delete object; + } + + // Complex object alias + { + QmlComponent component(&engine, TEST_FILE("alias.2.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + // Read through alias + MyQmlObject *v = + qvariant_cast(object->property("aliasObject")); + QVERIFY(v != 0); + QCOMPARE(v->value(), 10); + + // Write through alias + MyQmlObject *v2 = new MyQmlObject(); + v2->setParent(object); + object->setProperty("aliasObject", qVariantFromValue(v2)); + MyQmlObject *v3 = + qvariant_cast(object->property("aliasObject")); + QVERIFY(v3 != 0); + QCOMPARE(v3, v2); + + delete object; + } + + // Nested aliases + { + QmlComponent component(&engine, TEST_FILE("alias.3.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("value").toInt(), 1892); + QCOMPARE(object->property("value2").toInt(), 1892); + + object->setProperty("value", QVariant(1313)); + QCOMPARE(object->property("value").toInt(), 1313); + QCOMPARE(object->property("value2").toInt(), 1313); + + object->setProperty("value2", QVariant(8080)); + QCOMPARE(object->property("value").toInt(), 8080); + QCOMPARE(object->property("value2").toInt(), 8080); + + delete object; + } + +} + class TestType : public QObject { Q_OBJECT public: -- cgit v0.12 From 23dff035edbda475b987b452570489626b647f30 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 9 Sep 2009 18:57:21 +1000 Subject: Start on QFxTextInput autotests Actually has tests in it now. Not all implemented yet though. --- .../declarative/qfxtextinput/data/navigation.qml | 4 +- .../declarative/qfxtextinput/tst_qfxtextinput.cpp | 291 ++++++++++++++++++++- 2 files changed, 291 insertions(+), 4 deletions(-) diff --git a/tests/auto/declarative/qfxtextinput/data/navigation.qml b/tests/auto/declarative/qfxtextinput/data/navigation.qml index c1a6162..282c52c 100644 --- a/tests/auto/declarative/qfxtextinput/data/navigation.qml +++ b/tests/auto/declarative/qfxtextinput/data/navigation.qml @@ -6,11 +6,11 @@ Rectangle { width: 800; height: 600; color: "blue" Item { - id: FirstItem + id: FirstItem; KeyNavigation.right: Input } - TextInput { id: Input; focus: true; + TextInput { id: Input; focus: true KeyNavigation.left: FirstItem KeyNavigation.right: LastItem KeyNavigation.up: FirstItem diff --git a/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp index 852a868..c883aa3 100644 --- a/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp +++ b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp @@ -1,8 +1,9 @@ #include +#include "../../../shared/util.h" #include #include #include -#include +#include #include class tst_qfxtextinput : public QObject @@ -13,6 +14,17 @@ public: tst_qfxtextinput(); private slots: + void text(); + void width(); + void font(); + void color(); + void selection(); + + void maxLength(); + void masks(); + void validators(); + + void cursorDelegate(); void navigation(); private: @@ -20,10 +32,280 @@ private: QFxView *createView(const QString &filename); QmlEngine engine; + QStringList standard; + QStringList colorStrings; }; tst_qfxtextinput::tst_qfxtextinput() { + standard << "the quick brown fox jumped over the lazy dog" + << "It's supercalifragisiticexpialidocious!" + << "Hello, world!"; + + colorStrings << "aliceblue" + << "antiquewhite" + << "aqua" + << "darkkhaki" + << "darkolivegreen" + << "dimgray" + << "palevioletred" + << "lightsteelblue" + << "#000000" + << "#AAAAAA" + << "#FFFFFF" + << "#2AC05F"; +} + +void tst_qfxtextinput::text() +{ + { + QmlComponent textinputComponent(&engine, "import Qt 4.6\nTextInput { text: \"\" }", QUrl()); + QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + + QVERIFY(textinputObject != 0); + QCOMPARE(textinputObject->text(), QString("")); + } + + for (int i = 0; i < standard.size(); i++) + { + QString componentStr = "import Qt 4.6\nTextInput { text: \"" + standard.at(i) + "\" }"; + QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); + QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + + QVERIFY(textinputObject != 0); + QCOMPARE(textinputObject->text(), standard.at(i)); + } + +} + +void tst_qfxtextinput::width() +{ + // uses Font metrics to find the width for standard + { + QmlComponent textinputComponent(&engine, "import Qt 4.6\nTextInput { text: \"\" }", QUrl()); + QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + + QVERIFY(textinputObject != 0); + QCOMPARE(textinputObject->width(), 1.);//1 for the cursor + } + + for (int i = 0; i < standard.size(); i++) + { + QFont f; + QFontMetrics fm(f); + int metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); + + QString componentStr = "import Qt 4.6\nTextInput { text: \"" + standard.at(i) + "\" }"; + QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); + QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + + QVERIFY(textinputObject != 0); + QCOMPARE(textinputObject->width(), qreal(metricWidth) + 1.);//1 for the cursor + } +} + +void tst_qfxtextinput::font() +{ + //test size, then bold, then italic, then family + { + QString componentStr = "import Qt 4.6\nTextInput { font.pointSize: 40; text: \"Hello World\" }"; + QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); + QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + + QVERIFY(textinputObject != 0); + QCOMPARE(textinputObject->font().pointSize(), 40); + QCOMPARE(textinputObject->font().bold(), false); + QCOMPARE(textinputObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nTextInput { font.bold: true; text: \"Hello World\" }"; + QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); + QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + + QVERIFY(textinputObject != 0); + QCOMPARE(textinputObject->font().bold(), true); + QCOMPARE(textinputObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nTextInput { font.italic: true; text: \"Hello World\" }"; + QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); + QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + + QVERIFY(textinputObject != 0); + QCOMPARE(textinputObject->font().italic(), true); + QCOMPARE(textinputObject->font().bold(), false); + } + + { + QString componentStr = "import Qt 4.6\nTextInput { font.family: \"Helvetica\"; text: \"Hello World\" }"; + QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); + QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + + QVERIFY(textinputObject != 0); + QCOMPARE(textinputObject->font().family(), QString("Helvetica")); + QCOMPARE(textinputObject->font().bold(), false); + QCOMPARE(textinputObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nTextInput { font.family: \"\"; text: \"Hello World\" }"; + QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); + QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + + QVERIFY(textinputObject != 0); + QCOMPARE(textinputObject->font().family(), QString("")); + } +} + +void tst_qfxtextinput::color() +{ + //test style + for (int i = 0; i < colorStrings.size(); i++) + { + QString componentStr = "import Qt 4.6\nTextInput { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; + QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); + QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + //qDebug() << "textinputObject: " << textinputObject->color() << "vs. " << QColor(colorStrings.at(i)); + QVERIFY(textinputObject != 0); + QCOMPARE(textinputObject->color(), QColor(colorStrings.at(i))); + } + + { + QString colorStr = "#AA001234"; + QColor testColor("#001234"); + testColor.setAlpha(170); + + QString componentStr = "import Qt 4.6\nTextInput { color: \"" + colorStr + "\"; text: \"Hello World\" }"; + QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); + QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + + QVERIFY(textinputObject != 0); + QCOMPARE(textinputObject->color(), testColor); + } +} + +void tst_qfxtextinput::selection() +{ + QString testStr = standard[0]; + QString componentStr = "import Qt 4.6\nTextInput { text: \""+ testStr +"\"; }"; + QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); + QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QVERIFY(textinputObject != 0); + + + //Test selection follows cursor + for(int i=0; i<= testStr.size(); i++) { + textinputObject->setCursorPosition(i); + QCOMPARE(textinputObject->cursorPosition(), i); + QCOMPARE(textinputObject->selectionStart(), i); + QCOMPARE(textinputObject->selectionEnd(), i); + QVERIFY(textinputObject->selectedText().isNull()); + } + + textinputObject->setCursorPosition(0); + QVERIFY(textinputObject->cursorPosition() == 0); + QVERIFY(textinputObject->selectionStart() == 0); + QVERIFY(textinputObject->selectionEnd() == 0); + QVERIFY(textinputObject->selectedText().isNull()); + + //Test selection + for(int i=0; i<= testStr.size(); i++) { + textinputObject->setSelectionEnd(i); + QCOMPARE(testStr.mid(0,i), textinputObject->selectedText()); + } + for(int i=0; i<= testStr.size(); i++) { + textinputObject->setSelectionStart(i); + QCOMPARE(testStr.mid(i,testStr.size()-i), textinputObject->selectedText()); + } + + textinputObject->setCursorPosition(0); + QVERIFY(textinputObject->cursorPosition() == 0); + QVERIFY(textinputObject->selectionStart() == 0); + QVERIFY(textinputObject->selectionEnd() == 0); + QVERIFY(textinputObject->selectedText().isNull()); + + for(int i=0; i< testStr.size(); i++) { + textinputObject->setSelectionStart(i); + QCOMPARE(textinputObject->selectionEnd(), i); + QCOMPARE(testStr.mid(i,0), textinputObject->selectedText()); + textinputObject->setSelectionEnd(i+1); + QCOMPARE(textinputObject->selectionStart(), i); + QCOMPARE(testStr.mid(i,1), textinputObject->selectedText()); + } + + for(int i= testStr.size() - 1; i>0; i--) { + textinputObject->setSelectionEnd(i); + QCOMPARE(testStr.mid(i,0), textinputObject->selectedText()); + textinputObject->setSelectionStart(i-1); + QCOMPARE(testStr.mid(i-1,1), textinputObject->selectedText()); + } + + //Test Error Ignoring behaviour + textinputObject->setCursorPosition(0); + QVERIFY(textinputObject->selectedText().isNull()); + textinputObject->setSelectionStart(-10); + QVERIFY(textinputObject->selectedText().isNull()); + textinputObject->setSelectionStart(100); + QVERIFY(textinputObject->selectedText().isNull()); + textinputObject->setSelectionEnd(-10); + QVERIFY(textinputObject->selectedText().isNull()); + textinputObject->setSelectionEnd(100); + QVERIFY(textinputObject->selectedText().isNull()); + textinputObject->setSelectionStart(0); + textinputObject->setSelectionEnd(10); + QVERIFY(textinputObject->selectedText().size() == 10); + textinputObject->setSelectionStart(-10); + QVERIFY(textinputObject->selectedText().size() == 10); + textinputObject->setSelectionStart(100); + QVERIFY(textinputObject->selectedText().size() == 10); + textinputObject->setSelectionEnd(-10); + QVERIFY(textinputObject->selectedText().size() == 10); + textinputObject->setSelectionEnd(100); + QVERIFY(textinputObject->selectedText().size() == 10); +} + +void tst_qfxtextinput::maxLength() +{ + QFxView *canvas = createView(SRCDIR "/data/navigation.qml"); + canvas->execute(); + canvas->show(); + + QVERIFY(canvas->root() != 0); + + QFxItem *input = qobject_cast(qvariant_cast(canvas->root()->property("myInput"))); + + QVERIFY(input != 0); + //TODO: Me +} + +void tst_qfxtextinput::masks() +{ + QFxView *canvas = createView(SRCDIR "/data/navigation.qml"); + canvas->execute(); + canvas->show(); + + QVERIFY(canvas->root() != 0); + + QFxItem *input = qobject_cast(qvariant_cast(canvas->root()->property("myInput"))); + + QVERIFY(input != 0); + //TODO: Me +} + +void tst_qfxtextinput::validators() +{ + QFxView *canvas = createView(SRCDIR "/data/navigation.qml"); + canvas->execute(); + canvas->show(); + + QVERIFY(canvas->root() != 0); + + QFxItem *input = qobject_cast(qvariant_cast(canvas->root()->property("myInput"))); + + QVERIFY(input != 0); + //TODO: Me } /* @@ -41,7 +323,7 @@ void tst_qfxtextinput::navigation() QFxItem *input = qobject_cast(qvariant_cast(canvas->root()->property("myInput"))); QVERIFY(input != 0); - QVERIFY(input->hasFocus() == true); + QTRY_VERIFY(input->hasFocus() == true); simulateKey(canvas, Qt::Key_Left); QVERIFY(input->hasFocus() == false); simulateKey(canvas, Qt::Key_Right); @@ -52,6 +334,11 @@ void tst_qfxtextinput::navigation() QVERIFY(input->hasFocus() == true); } +void tst_qfxtextinput::cursorDelegate() +{ + //TODO:Get the QFxTextInput test passing first +} + void tst_qfxtextinput::simulateKey(QFxView *view, int key) { QKeyEvent press(QKeyEvent::KeyPress, key, 0); -- cgit v0.12 From b581d65a60c6b3a1d505b4cdfcbab1c81e48cee6 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 10 Sep 2009 10:00:09 +1000 Subject: typo --- doc/src/declarative/qmlformat.qdoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/src/declarative/qmlformat.qdoc b/doc/src/declarative/qmlformat.qdoc index 5013ee7..f16adca 100644 --- a/doc/src/declarative/qmlformat.qdoc +++ b/doc/src/declarative/qmlformat.qdoc @@ -91,8 +91,8 @@ The blue rectangle in the diagram represents a property binding. Associated wit binding is the QML context to which it belongs, the object property to which it is bound and a \e {scope object}. The scope object is usually, but not always, the object to which the bound property belongs. The context properties, context default objects and the scope object are all -involved when resolving a variable name in a binding. The following psuedo code describes the -alogithm used: +involved when resolving a variable name in a binding. The following pseudo code describes the +algorithm used: \table \row @@ -139,7 +139,7 @@ To the QML engine, a composite type is just another QML document. When a compos used the engine instantiates it just as it would any other document - by creating a new implicit QML context and the object tree described by the document. The diagram below shows the \c SquareImage composite type used from within another QML document. When instantiated, the -\c SquareImage object is created in its own QML context. Any property bindings sepecified in the +\c SquareImage object is created in its own QML context. Any property bindings specified in the \c SquareImage composite type document are associated with this context. Property bindings created in the outer document, however, are associated with its context, even those that are applied to the created \c SquareImage object. That is, the \c size, \c source, \c width and \c height property -- cgit v0.12 From 932f667eaad727854f6bb48d797874455ed13231 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 9 Sep 2009 20:38:13 +1000 Subject: Support URL resolution from within script blocks --- src/declarative/qml/qmlbinding.cpp | 4 ---- src/declarative/qml/qmlmetaproperty.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp index 39851ff..f9c9561 100644 --- a/src/declarative/qml/qmlbinding.cpp +++ b/src/declarative/qml/qmlbinding.cpp @@ -126,10 +126,6 @@ void QmlBinding::update() value = con(value.toString()); } - if (d->property.propertyType() == QVariant::Url && - (value.type() == QVariant::String || value.type() == QVariant::ByteArray) && !value.isNull()) - value.setValue(context()->resolvedUrl(QUrl(value.toString()))); - if (d->property.propertyType() == QVariant::Vector3D && value.type() == QVariant::String) { value = qVariantFromValue(QmlStringConverters::vector3DFromString(value.toString())); diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index fdba79e..affb93b 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -874,6 +874,31 @@ void QmlMetaPropertyPrivate::writeValueProperty(const QVariant &value) } break; + case QVariant::Url: + { + QUrl u; + if (vt == QVariant::ByteArray) { + u = QUrl(QLatin1String(value.toByteArray())); + found = true; + } else if (QVariant::String) { + u = QUrl(value.toString()); + found = true; + } + + if (context && u.isRelative()) + u = context->baseUrl().resolved(u); + + if (found) { + void *a[1]; + a[0] = &u; + QMetaObject::metacall(object, + QMetaObject::WriteProperty, + coreIdx, a); + } + + } + break; + default: { -- cgit v0.12 From a250db23c96fc1ec47ea4d19d62a19cad7c50b46 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 10 Sep 2009 10:19:33 +1000 Subject: Report custom parse errors verbosely. --- src/declarative/qml/qmlcompiler.cpp | 11 ++--- src/declarative/qml/qmlcustomparser.cpp | 51 +++++++++++++++++++--- src/declarative/qml/qmlcustomparser_p.h | 19 +++++++- src/declarative/qml/qmlcustomparser_p_p.h | 9 ++-- src/declarative/util/qmllistmodel.cpp | 16 ++++--- src/declarative/util/qmlpropertychanges.cpp | 7 +-- .../qmlparser/customParserIdNotAllowed.errors.txt | 1 + .../qmlparser/customParserIdNotAllowed.qml | 5 +++ tests/auto/declarative/qmlparser/tst_qmlparser.cpp | 4 +- 9 files changed, 92 insertions(+), 31 deletions(-) create mode 100644 tests/auto/declarative/qmlparser/customParserIdNotAllowed.errors.txt create mode 100644 tests/auto/declarative/qmlparser/customParserIdNotAllowed.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index b8e9d47..f02dad5 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -761,12 +761,13 @@ bool QmlCompiler::buildObject(Object *obj, const BindingContext &ctxt) // Compile custom parser parts if (isCustomParser && !customProps.isEmpty()) { - // ### Check for failure - bool ok = false; QmlCustomParser *cp = output->types.at(obj->type).type->customParser(); - obj->custom = cp->compile(customProps, &ok); - if(!ok) - COMPILE_EXCEPTION(obj, "Failure compiling custom type"); + cp->clearErrors(); + obj->custom = cp->compile(customProps); + foreach (QmlError err, cp->errors()) { + err.setUrl(output->url); + exceptions << err; + } } return true; diff --git a/src/declarative/qml/qmlcustomparser.cpp b/src/declarative/qml/qmlcustomparser.cpp index b543978..dbcbeb1 100644 --- a/src/declarative/qml/qmlcustomparser.cpp +++ b/src/declarative/qml/qmlcustomparser.cpp @@ -70,7 +70,7 @@ using namespace QmlParser; */ /* - \fn QByteArray QmlCustomParser::compile(QXmlStreamReader& reader, bool *ok) + \fn QByteArray QmlCustomParser::compile(QXmlStreamReader& reader) Upon entry to this function, \a reader is positioned on a QXmlStreamReader::StartElement with the name specified when the @@ -80,7 +80,7 @@ using namespace QmlParser; EndElement matching the initial start element is reached, or until error. - On return, \c *ok indicates success. + Errors must be reported via the error() functions. The returned QByteArray contains data meaningful only to the custom parser; the type engine will pass this same data to @@ -109,6 +109,7 @@ QmlCustomParserNodePrivate::fromObject(QmlParser::Object *root) { QmlCustomParserNode rootNode; rootNode.d->name = root->typeName; + rootNode.d->location = root->location.start; for(QHash::Iterator iter = root->properties.begin(); iter != root->properties.end(); @@ -128,6 +129,7 @@ QmlCustomParserNodePrivate::fromProperty(QmlParser::Property *p) QmlCustomParserProperty prop; prop.d->name = p->name; prop.d->isList = (p->values.count() > 1); + prop.d->location = p->location.start; if (p->value) { QmlCustomParserNode node = fromObject(p->value); @@ -167,6 +169,7 @@ QmlCustomParserNode &QmlCustomParserNode::operator=(const QmlCustomParserNode &o { d->name = other.d->name; d->properties = other.d->properties; + d->location = other.d->location; return *this; } @@ -185,6 +188,11 @@ QList QmlCustomParserNode::properties() const return d->properties; } +QmlParser::Location QmlCustomParserNode::location() const +{ + return d->location; +} + QmlCustomParserProperty::QmlCustomParserProperty() : d(new QmlCustomParserPropertyPrivate) { @@ -201,6 +209,7 @@ QmlCustomParserProperty &QmlCustomParserProperty::operator=(const QmlCustomParse d->name = other.d->name; d->isList = other.d->isList; d->values = other.d->values; + d->location = other.d->location; return *this; } @@ -219,19 +228,49 @@ bool QmlCustomParserProperty::isList() const return d->isList; } +QmlParser::Location QmlCustomParserProperty::location() const +{ + return d->location; +} + QList QmlCustomParserProperty::assignedValues() const { return d->values; } -QByteArray QmlCustomParser::compile(const QList &, bool *ok) +void QmlCustomParser::clearErrors() { - Q_UNUSED(ok); - return QByteArray(); + exceptions.clear(); } -void QmlCustomParser::setCustomData(QObject *, const QByteArray &) +/*! + Reports an error in parsing \a prop, with the given \a description. + + An error is generated referring to the position of \a node in the source file. +*/ +void QmlCustomParser::error(const QmlCustomParserProperty& prop, const QString& description) +{ + QmlError error; + QString exceptionDescription; + error.setLine(prop.location().line); + error.setColumn(prop.location().column); + error.setDescription(description); + exceptions << error; +} + +/*! + Reports an error in parsing \a node, with the given \a description. + + An error is generated referring to the position of \a node in the source file. +*/ +void QmlCustomParser::error(const QmlCustomParserNode& node, const QString& description) { + QmlError error; + QString exceptionDescription; + error.setLine(node.location().line); + error.setColumn(node.location().column); + error.setDescription(description); + exceptions << error; } QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlcustomparser_p.h b/src/declarative/qml/qmlcustomparser_p.h index 74bd15c..5be0680 100644 --- a/src/declarative/qml/qmlcustomparser_p.h +++ b/src/declarative/qml/qmlcustomparser_p.h @@ -57,6 +57,8 @@ #include #include #include +#include +#include QT_BEGIN_HEADER @@ -74,6 +76,7 @@ public: ~QmlCustomParserProperty(); QByteArray name() const; + QmlParser::Location location() const; bool isList() const; // Will be one of QmlParser::Variant, QmlCustomParserProperty or @@ -96,6 +99,7 @@ public: ~QmlCustomParserNode(); QByteArray name() const; + QmlParser::Location location() const; QList properties() const; @@ -109,8 +113,19 @@ class Q_DECLARATIVE_EXPORT QmlCustomParser public: virtual ~QmlCustomParser() {} - virtual QByteArray compile(const QList &, bool *ok); - virtual void setCustomData(QObject *, const QByteArray &); + void clearErrors(); + + virtual QByteArray compile(const QList &)=0; + virtual void setCustomData(QObject *, const QByteArray &)=0; + + QList errors() const { return exceptions; } + +protected: + void error(const QmlCustomParserProperty&, const QString& description); + void error(const QmlCustomParserNode&, const QString& description); + +private: + QList exceptions; }; #define QML_DEFINE_CUSTOM_TYPE(URI, VERSION_MAJ, VERSION_MIN_FROM, VERSION_MAJ_TO, NAME, TYPE, CUSTOMTYPE) \ template<> QmlPrivate::InstanceType QmlPrivate::Define::instance(qmlRegisterCustomType(#URI, VERSION_MAJ, VERSION_MIN_FROM, VERSION_MAJ_TO, #NAME, #TYPE, new CUSTOMTYPE)); diff --git a/src/declarative/qml/qmlcustomparser_p_p.h b/src/declarative/qml/qmlcustomparser_p_p.h index 0011c3b..25023d3 100644 --- a/src/declarative/qml/qmlcustomparser_p_p.h +++ b/src/declarative/qml/qmlcustomparser_p_p.h @@ -55,20 +55,16 @@ #include #include "qmlcustomparser_p.h" +#include "qmlparser_p.h" QT_BEGIN_NAMESPACE -namespace QmlParser -{ - class Object; - class Property; -}; - class QmlCustomParserNodePrivate { public: QByteArray name; QList properties; + QmlParser::Location location; static QmlCustomParserNode fromObject(QmlParser::Object *); static QmlCustomParserProperty fromProperty(QmlParser::Property *); @@ -82,6 +78,7 @@ public: QByteArray name; bool isList; + QmlParser::Location location; QList values; }; diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index f988d81..19499a1 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -634,7 +634,7 @@ void QmlListModel::set(int index, const QString& property, const QVariant& value class QmlListModelParser : public QmlCustomParser { public: - QByteArray compile(const QList &, bool *ok); + QByteArray compile(const QList &); bool compileProperty(const QmlCustomParserProperty &prop, QList &instr, QByteArray &data); void setCustomData(QObject *, const QByteArray &); }; @@ -659,8 +659,14 @@ bool QmlListModelParser::compileProperty(const QmlCustomParserProperty &prop, QL QList props = node.properties(); for(int jj = 0; jj < props.count(); ++jj) { const QmlCustomParserProperty &nodeProp = props.at(jj); - if(nodeProp.name() == "") + if (nodeProp.name() == "") { + error(nodeProp, QLatin1String("Cannot use default property in ListModel")); return false; + } + if (nodeProp.name() == "id") { + error(nodeProp, QLatin1String("Cannot use reserved \"id\" property in ListModel")); + return false; + } ListInstruction li; int ref = data.count(); @@ -706,21 +712,19 @@ bool QmlListModelParser::compileProperty(const QmlCustomParserProperty &prop, QL return true; } -QByteArray QmlListModelParser::compile(const QList &customProps, bool *ok) +QByteArray QmlListModelParser::compile(const QList &customProps) { - *ok = true; QList instr; QByteArray data; for(int ii = 0; ii < customProps.count(); ++ii) { const QmlCustomParserProperty &prop = customProps.at(ii); if(prop.name() != "") { // isn't default property - *ok = false; + error(prop, QLatin1String("Cannot use default property")); return QByteArray(); } if(!compileProperty(prop, instr, data)) { - *ok = false; return QByteArray(); } } diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp index b5e204f..1fe1731 100644 --- a/src/declarative/util/qmlpropertychanges.cpp +++ b/src/declarative/util/qmlpropertychanges.cpp @@ -106,7 +106,7 @@ class QmlPropertyChangesParser : public QmlCustomParser public: void compileList(QList > &list, const QByteArray &pre, const QmlCustomParserProperty &prop); - virtual QByteArray compile(const QList &, bool *ok); + virtual QByteArray compile(const QList &); virtual void setCustomData(QObject *, const QByteArray &); }; @@ -137,11 +137,8 @@ QmlPropertyChangesParser::compileList(QList > &list, } QByteArray -QmlPropertyChangesParser::compile(const QList &props, - bool *ok) +QmlPropertyChangesParser::compile(const QList &props) { - *ok = true; - QList > data; for(int ii = 0; ii < props.count(); ++ii) compileList(data, QByteArray(), props.at(ii)); diff --git a/tests/auto/declarative/qmlparser/customParserIdNotAllowed.errors.txt b/tests/auto/declarative/qmlparser/customParserIdNotAllowed.errors.txt new file mode 100644 index 0000000..d28c0bd --- /dev/null +++ b/tests/auto/declarative/qmlparser/customParserIdNotAllowed.errors.txt @@ -0,0 +1 @@ +4:19:Cannot use reserved "id" property in ListModel diff --git a/tests/auto/declarative/qmlparser/customParserIdNotAllowed.qml b/tests/auto/declarative/qmlparser/customParserIdNotAllowed.qml new file mode 100644 index 0000000..e607768 --- /dev/null +++ b/tests/auto/declarative/qmlparser/customParserIdNotAllowed.qml @@ -0,0 +1,5 @@ +import Qt 4.6 +ListModel { + ListElement { a: 10 } + ListElement { id: Foo; a: 12 } +} diff --git a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp index e3735e7..25dfd27 100644 --- a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp +++ b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp @@ -159,6 +159,8 @@ void tst_qmlparser::errors_data() QTest::newRow("finalOverride") << "finalOverride.qml" << "finalOverride.errors.txt" << false; QTest::newRow("importNamespaceConflict") << "importNamespaceConflict.qml" << "importNamespaceConflict.errors.txt" << false; + + QTest::newRow("customParserIdNotAllowed") << "customParserIdNotAllowed.qml" << "customParserIdNotAllowed.errors.txt" << false; } void tst_qmlparser::errors() @@ -311,7 +313,7 @@ void tst_qmlparser::assignTypeExtremes() QCOMPARE(object->intProperty(), -0x77359400); } -// Tests that custom parser tyeps can be instantiated +// Tests that custom parser types can be instantiated void tst_qmlparser::customParserTypes() { QmlComponent component(&engine, TEST_FILE("customParserTypes.qml")); -- cgit v0.12 From c5369f7168a9e9309514aee9c39e9bfc6813694d Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 10 Sep 2009 10:59:22 +1000 Subject: API Changes Renaming stuff in TextEdit/Input --- src/declarative/QmlChanges.txt | 2 ++ src/declarative/fx/qfxtextedit.cpp | 26 +++++++-------- src/declarative/fx/qfxtextedit.h | 12 +++---- src/declarative/fx/qfxtextedit_p.h | 4 +-- src/declarative/fx/qfxtextinput.cpp | 63 ++++++++++++++++++++++++------------- src/declarative/fx/qfxtextinput.h | 30 ++++++++++++------ src/declarative/fx/qfxtextinput_p.h | 8 +++-- 7 files changed, 89 insertions(+), 56 deletions(-) diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 87873f2..9c68d18 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -38,6 +38,8 @@ MouseRegion: ymin -> minimumY MouseRegion: ymin -> maximumY Text elements: hAlign -> horizontalAlignment Text elements: vAlign -> verticalAlignment +Text elements: highlightColor -> selectionColor +Text elements: highlightedTextColor -> selectedTextColor State: operations -> changes Transition: operations -> animations Transition: fromState -> from diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index c2c418e..72f12cc 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -271,24 +271,24 @@ void QFxTextEdit::setColor(const QColor &color) } /*! - \qmlproperty color TextEdit::highlightColor + \qmlproperty color TextEdit::selectionColor The text highlight color, used behind selections. */ -QColor QFxTextEdit::highlightColor() const +QColor QFxTextEdit::selectionColor() const { Q_D(const QFxTextEdit); - return d->highlightColor; + return d->selectionColor; } -void QFxTextEdit::setHighlightColor(const QColor &color) +void QFxTextEdit::setSelectionColor(const QColor &color) { Q_D(QFxTextEdit); - if (d->highlightColor == color) + if (d->selectionColor == color) return; clearCache(); - d->highlightColor = color; + d->selectionColor = color; QPalette pal = d->control->palette(); pal.setColor(QPalette::Highlight, color); d->control->setPalette(pal); @@ -296,24 +296,24 @@ void QFxTextEdit::setHighlightColor(const QColor &color) } /*! - \qmlproperty color TextEdit::highlightedTextColor + \qmlproperty color TextEdit::selectedTextColor - The highlighted text color, used in selections. + The selected text color, used in selections. */ -QColor QFxTextEdit::highlightedTextColor() const +QColor QFxTextEdit::selectedTextColor() const { Q_D(const QFxTextEdit); - return d->highlightedTextColor; + return d->selectedTextColor; } -void QFxTextEdit::setHighlightedTextColor(const QColor &color) +void QFxTextEdit::setSelectedTextColor(const QColor &color) { Q_D(QFxTextEdit); - if (d->highlightedTextColor == color) + if (d->selectedTextColor == color) return; clearCache(); - d->highlightedTextColor = color; + d->selectedTextColor = color; QPalette pal = d->control->palette(); pal.setColor(QPalette::HighlightedText, color); d->control->setPalette(pal); diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h index 6a10e85..1a5d968 100644 --- a/src/declarative/fx/qfxtextedit.h +++ b/src/declarative/fx/qfxtextedit.h @@ -68,8 +68,8 @@ class Q_DECLARATIVE_EXPORT QFxTextEdit : public QFxPaintedItem Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor) //### selectionColor - Q_PROPERTY(QColor highlightedTextColor READ highlightedTextColor WRITE setHighlightedTextColor) //### selectedTextColor + Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) Q_PROPERTY(QFont font READ font WRITE setFont) Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign) @@ -119,11 +119,11 @@ public: QColor color() const; void setColor(const QColor &c); - QColor highlightColor() const; - void setHighlightColor(const QColor &c); + QColor selectionColor() const; + void setSelectionColor(const QColor &c); - QColor highlightedTextColor() const; - void setHighlightedTextColor(const QColor &c); + QColor selectedTextColor() const; + void setSelectedTextColor(const QColor &c); HAlignment hAlign() const; void setHAlign(HAlignment align); diff --git a/src/declarative/fx/qfxtextedit_p.h b/src/declarative/fx/qfxtextedit_p.h index fb757de..9c73db9 100644 --- a/src/declarative/fx/qfxtextedit_p.h +++ b/src/declarative/fx/qfxtextedit_p.h @@ -84,8 +84,8 @@ public: QString text; QFont font; QColor color; - QColor highlightColor; - QColor highlightedTextColor; + QColor selectionColor; + QColor selectedTextColor; QString style; QColor styleColor; bool imgDirty; diff --git a/src/declarative/fx/qfxtextinput.cpp b/src/declarative/fx/qfxtextinput.cpp index 6bd793b..b6ec109 100644 --- a/src/declarative/fx/qfxtextinput.cpp +++ b/src/declarative/fx/qfxtextinput.cpp @@ -55,6 +55,12 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,QIntValidator,QIntValidator); /*! \qmlclass TextInput The TextInput item allows you to add an editable line of text to a scene. + + TextInput can only display a single line of text, and can only display + plain text. However it can provide addition input constraints on the text. + + Input constraints include setting a QValidator, an input mask, or a + maximum input length. */ QFxTextInput::QFxTextInput(QFxItem* parent) : QFxPaintedItem(*(new QFxTextInputPrivate), parent) @@ -148,44 +154,44 @@ void QFxTextInput::setColor(const QColor &c) /*! - \qmlproperty color TextInput::highlightColor + \qmlproperty color TextInput::selectionColor The text highlight color, used behind selections. */ -QColor QFxTextInput::highlightColor() const +QColor QFxTextInput::selectionColor() const { Q_D(const QFxTextInput); - return d->highlightColor; + return d->selectionColor; } -void QFxTextInput::setHighlightColor(const QColor &color) +void QFxTextInput::setSelectionColor(const QColor &color) { Q_D(QFxTextInput); - if (d->highlightColor == color) + if (d->selectionColor == color) return; - d->highlightColor = color; + d->selectionColor = color; //TODO: implement } /*! - \qmlproperty color TextInput::highlightedTextColor + \qmlproperty color TextInput::selectedTextColor The highlighted text color, used in selections. */ -QColor QFxTextInput::highlightedTextColor() const +QColor QFxTextInput::selectedTextColor() const { Q_D(const QFxTextInput); - return d->highlightedTextColor; + return d->selectedTextColor; } -void QFxTextInput::setHighlightedTextColor(const QColor &color) +void QFxTextInput::setSelectedTextColor(const QColor &color) { Q_D(QFxTextInput); - if (d->highlightedTextColor == color) + if (d->selectedTextColor == color) return; - d->highlightedTextColor = color; + d->selectedTextColor = color; //TODO: implement } @@ -340,6 +346,18 @@ QString QFxTextInput::selectedText() const return d->control->selectedText(); } +bool QFxTextInput::focusOnPress() const +{ + Q_D(const QFxTextInput); + return d->focusOnPress; +} + +void QFxTextInput::setFocusOnPress(bool b) +{ + Q_D(QFxTextInput); + d->focusOnPress = b; +} + QValidator* QFxTextInput::validator() const { Q_D(const QFxTextInput); @@ -375,16 +393,16 @@ bool QFxTextInput::hasAcceptableInput() const return d->control->hasAcceptableInput(); } -uint QFxTextInput::echoMode() const +QFxTextInput::EchoMode QFxTextInput::echoMode() const { Q_D(const QFxTextInput); - return d->control->echoMode(); + return (QFxTextInput::EchoMode)d->control->echoMode(); } -void QFxTextInput::setEchoMode(uint echo) +void QFxTextInput::setEchoMode(QFxTextInput::EchoMode echo) { Q_D(QFxTextInput); - d->control->setEchoMode(echo); + d->control->setEchoMode((uint)echo); } /*! @@ -431,7 +449,7 @@ void QFxTextInputPrivate::startCreatingCursor() q->connect(cursorComponent, SIGNAL(statusChanged(int)), q, SLOT(createCursor())); }else{//isError - qWarning() << "You could really use the error checking for QFxTextInput. We'll implement it soon."; + qWarning() << "You could really use the error checking for QFxTextInput. We'll implement it soon.";//TODO:better error handling } } @@ -446,7 +464,7 @@ void QFxTextInput::createCursor() delete d->cursorItem; d->cursorItem = qobject_cast(d->cursorComponent->create()); if(!d->cursorItem){ - qWarning() << "You could really use the error reporting for QFxTextInput. We'll implement it soon."; + qWarning() << "You could really use the error reporting for QFxTextInput. We'll implement it soon.";//TODO:better error handling return; } @@ -495,11 +513,12 @@ void QFxTextInput::keyPressEvent(QKeyEvent* ev) void QFxTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QFxTextInput); - setFocus(true);//###Should we make 'focusOnPress' be optional like TextEdit? - setCursorVisible(true); - d->focused = true; + if(d->focusOnPress){ + setFocus(true); + setCursorVisible(true); + d->focused = true; + } d->control->processEvent(event); - //event->accept(); } bool QFxTextInput::event(QEvent* ev) diff --git a/src/declarative/fx/qfxtextinput.h b/src/declarative/fx/qfxtextinput.h index 1dca945..bc5bbf4 100644 --- a/src/declarative/fx/qfxtextinput.h +++ b/src/declarative/fx/qfxtextinput.h @@ -62,8 +62,8 @@ class Q_DECLARATIVE_EXPORT QFxTextInput : public QFxPaintedItem Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor) //### selectionColor - Q_PROPERTY(QColor highlightedTextColor READ highlightedTextColor WRITE setHighlightedTextColor) //### selectedTextColor + Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) Q_PROPERTY(QFont font READ font WRITE setFont) Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) @@ -79,13 +79,20 @@ class Q_DECLARATIVE_EXPORT QFxTextInput : public QFxPaintedItem Q_PROPERTY(QValidator* validator READ validator WRITE setValidator) Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask) Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged) - Q_PROPERTY(uint echoMode READ echoMode WRITE setEchoMode) //### enum - //### Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) + Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode) + Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) public: QFxTextInput(QFxItem* parent=0); ~QFxTextInput(); + enum EchoMode {//To match QLineEdit::EchoMode + Normal, + NoEcho, + Password, + PasswordEchoOnEdit + }; + enum HAlignment { AlignLeft = Qt::AlignLeft, AlignRight = Qt::AlignRight, @@ -105,11 +112,11 @@ public: QColor color() const; void setColor(const QColor &c); - QColor highlightColor() const; - void setHighlightColor(const QColor &c); + QColor selectionColor() const; + void setSelectionColor(const QColor &c); - QColor highlightedTextColor() const; - void setHighlightedTextColor(const QColor &c); + QColor selectedTextColor() const; + void setSelectedTextColor(const QColor &c); HAlignment hAlign() const; void setHAlign(HAlignment align); @@ -140,12 +147,15 @@ public: QString inputMask() const; void setInputMask(const QString &im); - uint echoMode() const; - void setEchoMode(uint echo); + EchoMode echoMode() const; + void setEchoMode(EchoMode echo); QmlComponent* cursorDelegate() const; void setCursorDelegate(QmlComponent*); + bool focusOnPress() const; + void setFocusOnPress(bool); + bool hasAcceptableInput() const; void drawContents(QPainter *p,const QRect &r); diff --git a/src/declarative/fx/qfxtextinput_p.h b/src/declarative/fx/qfxtextinput_p.h index b533854..a2b45bb 100644 --- a/src/declarative/fx/qfxtextinput_p.h +++ b/src/declarative/fx/qfxtextinput_p.h @@ -66,7 +66,8 @@ public: QFxTextInputPrivate() : control(new QLineControl(QString())), color((QRgb)0), style(QFxText::Normal), styleColor((QRgb)0), hAlign(QFxTextInput::AlignLeft), - hscroll(0), oldScroll(0), focused(false), cursorVisible(false) + hscroll(0), oldScroll(0), focused(false), focusOnPress(true), + cursorVisible(false) { } @@ -82,8 +83,8 @@ public: QFont font; QColor color; - QColor highlightColor; - QColor highlightedTextColor; + QColor selectionColor; + QColor selectedTextColor; QFxText::TextStyle style; QColor styleColor; QFxTextInput::HAlignment hAlign; @@ -98,6 +99,7 @@ public: int hscroll; int oldScroll; bool focused; + bool focusOnPress; bool cursorVisible; }; -- cgit v0.12 From 7fa2ba45442adb7042ddac0e92f8ea5df4eb5619 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 10 Sep 2009 11:18:45 +1000 Subject: Update demos to work with API changes Affected are flickr and twitter. --- demos/declarative/flickr/common/MediaLineEdit.qml | 2 +- demos/declarative/flickr/mobile/TitleBar.qml | 2 +- demos/declarative/twitter/content/AuthView.qml | 6 +++--- demos/declarative/twitter/content/HomeTitleBar.qml | 2 +- src/declarative/fx/qfxtextinput.h | 1 + 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/demos/declarative/flickr/common/MediaLineEdit.qml b/demos/declarative/flickr/common/MediaLineEdit.qml index 094571f..7599ce6a05 100644 --- a/demos/declarative/flickr/common/MediaLineEdit.qml +++ b/demos/declarative/flickr/common/MediaLineEdit.qml @@ -90,7 +90,7 @@ Item { id: Editor font.bold: true color: "white" - highlightColor: "green" + selectionColor: "green" width: 0 clip: true anchors.left: Label.right diff --git a/demos/declarative/flickr/mobile/TitleBar.qml b/demos/declarative/flickr/mobile/TitleBar.qml index b95452a..13484a2 100644 --- a/demos/declarative/flickr/mobile/TitleBar.qml +++ b/demos/declarative/flickr/mobile/TitleBar.qml @@ -50,7 +50,7 @@ Item { verticalCenter: parent.verticalCenter } cursorVisible: true; font.bold: true - color: "#151515"; highlightColor: "Green" + color: "#151515"; selectionColor: "Green" } Keys.forwardTo: [ (ReturnKey), (Editor)] diff --git a/demos/declarative/twitter/content/AuthView.qml b/demos/declarative/twitter/content/AuthView.qml index febee94..3fe7e7e 100644 --- a/demos/declarative/twitter/content/AuthView.qml +++ b/demos/declarative/twitter/content/AuthView.qml @@ -27,7 +27,7 @@ Item { anchors.centerIn: parent maximumLength:21 font.bold: true - color: "#151515"; highlightColor: "green" + color: "#151515"; selectionColor: "green" Keys.forwardTo: [(tabber), (nameIn)] Item { id: tabber @@ -56,9 +56,9 @@ Item { height: parent.height - 12 anchors.centerIn: parent maximumLength:21 - echoMode: 2 + echoMode: TextInput.Password font.bold: true - color: "#151515"; highlightColor: "green" + color: "#151515"; selectionColor: "green" } } } diff --git a/demos/declarative/twitter/content/HomeTitleBar.qml b/demos/declarative/twitter/content/HomeTitleBar.qml index 9bca2c8..bd3bc2c 100644 --- a/demos/declarative/twitter/content/HomeTitleBar.qml +++ b/demos/declarative/twitter/content/HomeTitleBar.qml @@ -92,7 +92,7 @@ Item { height: parent.height - 8 font.pointSize: 10 wrap:true - color: "#151515"; highlightColor: "green" + color: "#151515"; selectionColor: "green" } Keys.forwardTo: [(ReturnKey), (Editor)] Item { diff --git a/src/declarative/fx/qfxtextinput.h b/src/declarative/fx/qfxtextinput.h index bc5bbf4..4fa4100 100644 --- a/src/declarative/fx/qfxtextinput.h +++ b/src/declarative/fx/qfxtextinput.h @@ -59,6 +59,7 @@ class Q_DECLARATIVE_EXPORT QFxTextInput : public QFxPaintedItem { Q_OBJECT Q_ENUMS(HAlignment) + Q_ENUMS(EchoMode) Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) Q_PROPERTY(QColor color READ color WRITE setColor) -- cgit v0.12 From 8151beb4854341d4819d6d31cee4b9a0666ea36e Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 10 Sep 2009 12:02:11 +1000 Subject: Cursory QFxTextInput documentation. --- src/declarative/fx/qfxtextinput.cpp | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/declarative/fx/qfxtextinput.cpp b/src/declarative/fx/qfxtextinput.cpp index b6ec109..d9da308 100644 --- a/src/declarative/fx/qfxtextinput.cpp +++ b/src/declarative/fx/qfxtextinput.cpp @@ -195,6 +195,21 @@ void QFxTextInput::setSelectedTextColor(const QColor &color) //TODO: implement } +/*! + \qmlproperty enumeration TextInput::horizontalAlignment + + Sets the horizontal alignment of the text within the TextInput item's + width and height. By default, the text is left aligned. + + TextInput does not have vertical alignment, as the natural height is + exactly the height of the single line of text. If you set the height + manually to something larger, TextInput will always be top aligned + vertically. You can use anchors to align it however you want within + another item. + + The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and + \c AlignHCenter. +*/ QFxTextInput::HAlignment QFxTextInput::hAlign() const { Q_D(const QFxTextInput); @@ -346,6 +361,12 @@ QString QFxTextInput::selectedText() const return d->control->selectedText(); } +/*! + \qmlproperty bool TextInput::focusOnPress + + Whether the TextInput should gain focus on a mouse press. By default this is + set to true. +*/ bool QFxTextInput::focusOnPress() const { Q_D(const QFxTextInput); @@ -358,6 +379,16 @@ void QFxTextInput::setFocusOnPress(bool b) d->focusOnPress = b; } +/*! + \qmlproperty QValidator* TextInput::validator + + Allows you to set a QValidator on the TextInput. When a validator is set + the TextInput will only accept input which leaves the text property in + an acceptable or intermediate state. The accepted signal will only be sent + if the text is in an acceptable state when enter is pressed. + + \sa acceptableInput, inputMask +*/ QValidator* QFxTextInput::validator() const { Q_D(const QFxTextInput); @@ -375,6 +406,15 @@ void QFxTextInput::setValidator(QValidator* v) } } +/*! + \qmlproperty string TextInput::inputMask + + Allows you to set an input mask on the TextInput, restricting the allowable + text inputs. See QLineEdit::inputMask for further details, as the exact + same mask strings are used by TextInput. + + \sa acceptableInput, validator +*/ QString QFxTextInput::inputMask() const { Q_D(const QFxTextInput); @@ -387,12 +427,30 @@ void QFxTextInput::setInputMask(const QString &im) d->control->setInputMask(im); } +/*! + \qmlproperty bool TextInput::acceptableInput + + This property is always true unless a validator or input mask has been set. + If a validator or input mask has been set, this property will only be true + if the current text is acceptable to the validator or input mask as a final + string (not as an intermediate string). +*/ bool QFxTextInput::hasAcceptableInput() const { Q_D(const QFxTextInput); return d->control->hasAcceptableInput(); } +/*! + \qmlproperty TextInput.EchoMode TextInput::echoMode + + Specifies how the text should be displayed in the TextInput. + The default is Normal, which displays the text as it is. Other values + are Password, which displays asterixes instead of characters, NoEcho, + which displays nothing, and PasswordEchoOnEdit, which displays all but the + current character as asterixes. + +*/ QFxTextInput::EchoMode QFxTextInput::echoMode() const { Q_D(const QFxTextInput); -- cgit v0.12 From 2c0255521f00a1fd95988161a03c39631350eaba Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 10 Sep 2009 13:21:36 +1000 Subject: Follow renamed to SpringFollow. --- demos/declarative/samegame/content/BoomBlock.qml | 4 +- demos/declarative/webbrowser/webbrowser.qml | 1 + .../declarative/aspectratio/face_fit_animated.qml | 2 +- examples/declarative/clock/Clock.qml | 6 +- examples/declarative/dial/DialLibrary/Dial.qml | 4 +- examples/declarative/follow/follow.qml | 10 +- examples/declarative/follow/pong.qml | 6 +- examples/declarative/listview/highlight.qml | 2 +- examples/declarative/snow/snow.qml | 6 +- examples/declarative/velocity/Day.qml | 2 +- src/declarative/QmlChanges.txt | 1 + src/declarative/fx/qfxgridview.cpp | 16 +- src/declarative/fx/qfxlistview.cpp | 52 ++- src/declarative/fx/qfxlistview.h | 1 + src/declarative/util/qmleasefollow.cpp | 28 +- src/declarative/util/qmleasefollow.h | 4 + src/declarative/util/qmlfollow.cpp | 456 --------------------- src/declarative/util/qmlfollow.h | 113 ----- src/declarative/util/qmlspringfollow.cpp | 456 +++++++++++++++++++++ src/declarative/util/qmlspringfollow.h | 113 +++++ src/declarative/util/util.pri | 4 +- 21 files changed, 676 insertions(+), 611 deletions(-) delete mode 100644 src/declarative/util/qmlfollow.cpp delete mode 100644 src/declarative/util/qmlfollow.h create mode 100644 src/declarative/util/qmlspringfollow.cpp create mode 100644 src/declarative/util/qmlspringfollow.h diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml index 7860cf4..a495cd0 100644 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ b/demos/declarative/samegame/content/BoomBlock.qml @@ -7,8 +7,8 @@ Item { id:block property int targetX: 0 property int targetY: 0 - x: Follow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } - y: Follow { source: targetY; spring: 2; damping: 0.2 } + x: SpringFollow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } + y: SpringFollow { source: targetY; spring: 2; damping: 0.2 } Image { id: img source: { diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index 9a8af29..ae3d048 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -167,6 +167,7 @@ Item { anchors.bottom: Footer.top anchors.left: parent.left anchors.right: parent.right + pressDelay: 200 WebView { id: MyWebView diff --git a/examples/declarative/aspectratio/face_fit_animated.qml b/examples/declarative/aspectratio/face_fit_animated.qml index 2768150..7db1c80 100644 --- a/examples/declarative/aspectratio/face_fit_animated.qml +++ b/examples/declarative/aspectratio/face_fit_animated.qml @@ -16,7 +16,7 @@ Rectangle { source: "pics/face.png" x: (parent.width-width*scale)/2 y: (parent.height-height*scale)/2 - scale: Follow { + scale: SpringFollow { source: Math.max(Math.min(Image.parent.width/Image.width*1.333,Image.parent.height/Image.height), Math.min(Image.parent.width/Image.width,Image.parent.height/Image.height*1.333)) spring: 1 diff --git a/examples/declarative/clock/Clock.qml b/examples/declarative/clock/Clock.qml index e152be3..6064dd4 100644 --- a/examples/declarative/clock/Clock.qml +++ b/examples/declarative/clock/Clock.qml @@ -28,7 +28,7 @@ Item { id: HourRotation origin.x: 4; origin.y: 45 angle: 0 - angle: Follow { + angle: SpringFollow { spring: 2 damping: .2 source: Clock.hours * 50 * 3 + Clock.minutes / 2 @@ -44,7 +44,7 @@ Item { id: MinuteRotation origin.x: 4; origin.y: 70 angle: 0 - angle: Follow { + angle: SpringFollow { spring: 2 damping: .2 source: Clock.minutes * 6 @@ -60,7 +60,7 @@ Item { id: SecondRotation origin.x: 2; origin.y: 60 angle: 0 - angle: Follow { + angle: SpringFollow { spring: 5 damping: .25 modulus: 360 diff --git a/examples/declarative/dial/DialLibrary/Dial.qml b/examples/declarative/dial/DialLibrary/Dial.qml index f53b25e..1a163a8 100644 --- a/examples/declarative/dial/DialLibrary/Dial.qml +++ b/examples/declarative/dial/DialLibrary/Dial.qml @@ -26,8 +26,8 @@ Item { id: NeedleRotation origin.x: 7; origin.y: 65 angle: -130 - angle: Follow { -id: MyFollow + angle: SpringFollow { + id: MyFollow spring: 1.4 damping: .15 source: Math.min(Math.max(-130, Root.value*2.2 - 130), 133) diff --git a/examples/declarative/follow/follow.qml b/examples/declarative/follow/follow.qml index 37dc2e8..1f585e2 100644 --- a/examples/declarative/follow/follow.qml +++ b/examples/declarative/follow/follow.qml @@ -26,7 +26,7 @@ Rectangle { color: "#ff0000" x: Rect.width; width: Rect.width; height: 20 y: 200 - y: Follow { source: Rect.y; velocity: 200 } + y: SpringFollow { source: Rect.y; velocity: 200 } } Text { x: Rect.width; y: 220; text: "Velocity" } @@ -35,13 +35,13 @@ Rectangle { color: "#ff0000" x: Rect.width * 2; width: Rect.width/2; height: 20 y: 200 - y: Follow { source: Rect.y; spring: 1.0; damping: 0.2 } + y: SpringFollow { source: Rect.y; spring: 1.0; damping: 0.2 } } Rectangle { color: "#880000" x: Rect.width * 2.5; width: Rect.width/2; height: 20 y: 200 - y: Follow { source: Rect.y; spring: 1.0; damping: 0.2; mass: 3.0 } // "heavier" object + y: SpringFollow { source: Rect.y; spring: 1.0; damping: 0.2; mass: 3.0 } // "heavier" object } Text { x: Rect.width * 2; y: 220; text: "Spring" } @@ -54,8 +54,8 @@ Rectangle { width: 20; height: 20 radius: 10 color: "#0000ff" - x: Follow { id: "F1"; source: Mouse.mouseX-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } - y: Follow { id: "F2"; source: Mouse.mouseY-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } + x: SpringFollow { id: "F1"; source: Mouse.mouseX-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } + y: SpringFollow { id: "F2"; source: Mouse.mouseY-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } states: [ State { name: "following" diff --git a/examples/declarative/follow/pong.qml b/examples/declarative/follow/pong.qml index 0314bb8..b51c0d0 100644 --- a/examples/declarative/follow/pong.qml +++ b/examples/declarative/follow/pong.qml @@ -25,7 +25,7 @@ Rectangle { } // Make y follow the target y coordinate, with a velocity of 200 - y: Follow { source: Ball.targetY; velocity: 200 } + y: SpringFollow { source: Ball.targetY; velocity: 200 } // Detect the ball hitting the top or bottom of the view and bounce it onYChanged: { @@ -42,7 +42,7 @@ Rectangle { id: LeftBat color: "#00ee00" x: 2; width: 20; height: 90 - y: Follow { + y: SpringFollow { source: Ball.y-45; velocity: 300 enabled: Ball.direction == 'left' } @@ -51,7 +51,7 @@ Rectangle { id: RightBat color: "#00ee00" x: Page.width-22; width: 20; height: 90 - y: Follow { + y: SpringFollow { source: Ball.y-45; velocity: 300 enabled: Ball.direction == 'right' } diff --git a/examples/declarative/listview/highlight.qml b/examples/declarative/listview/highlight.qml index 2bf3a9f..e707ac0 100644 --- a/examples/declarative/listview/highlight.qml +++ b/examples/declarative/listview/highlight.qml @@ -44,7 +44,7 @@ Rectangle { id: PetHighlight Rectangle { width: 200; height: 50; color: "#FFFF88" - y: Follow { source: List1.current.y; spring: 3; damping: 0.1 } + y: SpringFollow { source: List1.current.y; spring: 3; damping: 0.1 } } } ListView { diff --git a/examples/declarative/snow/snow.qml b/examples/declarative/snow/snow.qml index b6781c3..2241c3f 100644 --- a/examples/declarative/snow/snow.qml +++ b/examples/declarative/snow/snow.qml @@ -30,15 +30,15 @@ Rectangle { property bool slowDeform: true property real deform: 0 - deform: Follow { + deform: SpringFollow { id: "DeformFollow"; source: MyLayout.targetDeform; velocity: MyLayout.slowDeform?0.1:2 onSyncChanged: if(inSync) { MyLayout.slowDeform = true; MyLayout.targetDeform = 0; } } ImageBatch { offset: 0; ref: ImagePanel } - x: Follow { source: MyLayout.targetX; velocity: 1000 } - y: Follow { source: -(selectedY + imageHeight / 2); velocity: 500 } + x: SpringFollow { source: MyLayout.targetX; velocity: 1000 } + y: SpringFollow { source: -(selectedY + imageHeight / 2); velocity: 500 } } transform: Rotation { diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index 06d0bd4..4001a3e 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -31,7 +31,7 @@ Rectangle { x: Math.random() * 200 + 100 y: Math.random() * 300 + 50 id: StickyPage - rotation: Follow { + rotation: SpringFollow { source: -Flick.horizontalVelocity / 100 spring: 2.0 damping: 0.1 diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 87873f2..9043421 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -29,6 +29,7 @@ SetPropertyAction -> PropertyAction RunScriptAction -> ScriptAction ParentChangeAction -> ParentAction VisualModel -> VisualDataModel +Follow -> SpringFollow Renamed properties: Item: contents -> childrenRect diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index cccd7a6..dfb04ad 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -41,7 +41,7 @@ #include "qfxvisualitemmodel.h" #include "qlistmodelinterface.h" -#include "qmlfollow.h" +#include "qmleasefollow.h" #include "private/qfxflickable_p.h" #include "qfxgridview.h" @@ -313,8 +313,8 @@ public: enum MovementReason { Other, Key, Mouse }; MovementReason moveReason; int buffer; - QmlFollow *highlightXAnimator; - QmlFollow *highlightYAnimator; + QmlEaseFollow *highlightXAnimator; + QmlEaseFollow *highlightYAnimator; int ownModel : 1; int wrap : 1; @@ -591,15 +591,13 @@ void QFxGridViewPrivate::createHighlight() if (item) { item->setParent(q->viewport()); highlight = new FxGridItem(item, q); - highlightXAnimator = new QmlFollow(q); + highlightXAnimator = new QmlEaseFollow(q); highlightXAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("x"))); - highlightXAnimator->setSpring(3); - highlightXAnimator->setDamping(0.3); + highlightXAnimator->setVelocity(400); highlightXAnimator->setEnabled(autoHighlight); - highlightYAnimator = new QmlFollow(q); + highlightYAnimator = new QmlEaseFollow(q); highlightYAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("y"))); - highlightYAnimator->setSpring(3); - highlightYAnimator->setDamping(0.3); + highlightYAnimator->setVelocity(400); highlightYAnimator->setEnabled(autoHighlight); } else { delete highlightContext; diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 6c0a83e..49de016 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "private/qfxflickable_p.h" -#include "qmlfollow.h" +#include "qmleasefollow.h" #include "qlistmodelinterface.h" #include "qfxvisualitemmodel.h" #include "qfxlistview.h" @@ -381,8 +381,8 @@ public: enum MovementReason { Other, Key, Mouse }; MovementReason moveReason; int buffer; - QmlFollow *highlightPosAnimator; - QmlFollow *highlightSizeAnimator; + QmlEaseFollow *highlightPosAnimator; + QmlEaseFollow *highlightSizeAnimator; QString sectionExpression; QString currentSection; int spacing; @@ -660,15 +660,18 @@ void QFxListViewPrivate::createHighlight() } if (item) { highlight = new FxListItem(item, q); + if (orient == Qt::Vertical) + highlight->item->setHeight(currentItem->item->height()); + else + highlight->item->setWidth(currentItem->item->width()); const QLatin1String posProp(orient == Qt::Vertical ? "y" : "x"); - highlightPosAnimator = new QmlFollow(q); + highlightPosAnimator = new QmlEaseFollow(q); highlightPosAnimator->setTarget(QmlMetaProperty(highlight->item, posProp)); - highlightPosAnimator->setEpsilon(0.25); - highlightPosAnimator->setSpring(2.5); - highlightPosAnimator->setDamping(0.35); + highlightPosAnimator->setVelocity(400); highlightPosAnimator->setEnabled(autoHighlight); const QLatin1String sizeProp(orient == Qt::Vertical ? "height" : "width"); - highlightSizeAnimator = new QmlFollow(q); + highlightSizeAnimator = new QmlEaseFollow(q); + highlightSizeAnimator->setVelocity(400); highlightSizeAnimator->setTarget(QmlMetaProperty(highlight->item, sizeProp)); highlightSizeAnimator->setEnabled(autoHighlight); } @@ -909,6 +912,7 @@ void QFxListView::setModel(const QVariant &model) if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); disconnect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); disconnect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); } @@ -937,6 +941,7 @@ void QFxListView::setModel(const QVariant &model) d->updateCurrent(d->currentIndex); connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); connect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); connect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); refill(); @@ -1635,6 +1640,37 @@ void QFxListView::destroyRemoved() d->layout(); } +void QFxListView::itemsMoved(int from, int to, int count) +{ + qWarning() << "ListView does not support moving in models"; + + Q_D(QFxListView); + int fromCount = count; + int toCount = count; + bool fromVisible = d->mapRangeFromModel(from, fromCount); + bool toVisible = d->mapRangeFromModel(to, toCount); + + if (!fromVisible && !toVisible) { + // The items are outside the visible range. + if (d->visibleItems.count()) + d->visibleIndex = -1; + for (int i = 0; i < d->visibleItems.count(); ++i) { + FxListItem *listItem = d->visibleItems.at(i); + if (listItem->index != -1) { + listItem->index = d->model->indexOf(listItem->item, this); + if (d->visibleIndex < 0) + d->visibleIndex = listItem->index; + } + } + if (d->currentItem) { + d->currentItem->index = d->model->indexOf(d->currentItem->item, this); + d->currentIndex = d->currentItem->index; + } + return; + } + +} + void QFxListView::createdItem(int index, QFxItem *item) { Q_D(QFxListView); diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index dc0b039..829e202 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -155,6 +155,7 @@ private Q_SLOTS: void itemResized(); void itemsInserted(int index, int count); void itemsRemoved(int index, int count); + void itemsMoved(int from, int to, int count); void destroyRemoved(); void createdItem(int index, QFxItem *item); void destroyingItem(QFxItem *item); diff --git a/src/declarative/util/qmleasefollow.cpp b/src/declarative/util/qmleasefollow.cpp index 83dbde7..b58ad14 100644 --- a/src/declarative/util/qmleasefollow.cpp +++ b/src/declarative/util/qmleasefollow.cpp @@ -56,7 +56,7 @@ public: QmlEaseFollowPrivate() : source(0), velocity(200), duration(-1), reversingMode(QmlEaseFollow::Eased), initialVelocity(0), - initialValue(0), invert(false), trackVelocity(0), clockOffset(0), + initialValue(0), invert(false), enabled(true), trackVelocity(0), clockOffset(0), lastTick(0), clock(this) {} @@ -68,6 +68,7 @@ public: qreal initialVelocity; qreal initialValue; bool invert; + bool enabled; qreal trackVelocity; @@ -267,7 +268,7 @@ qreal QmlEaseFollow::sourceValue() const /*! \qmlproperty enumeration EaseFollow::reversingMode - Sets how the EaseFollow behaves if an animation diration is reversed. + Sets how the EaseFollow behaves if an animation direction is reversed. If reversing mode is \c Eased, the animation will smoothly decelerate, and then reverse direction. If the reversing mode is \c Immediate, the @@ -289,6 +290,9 @@ void QmlEaseFollow::setReversingMode(ReversingMode m) void QmlEaseFollowPrivate::restart() { + if (!enabled) + return; + initialValue = target.read().toReal(); if (source == initialValue) { @@ -382,6 +386,26 @@ void QmlEaseFollow::setVelocity(qreal v) d->restart(); } +/*! + \qmlproperty bool EaseFollow::enabled + This property holds whether the target will track the source. +*/ +bool QmlEaseFollow::enabled() const +{ + Q_D(const QmlEaseFollow); + return d->enabled; +} + +void QmlEaseFollow::setEnabled(bool enabled) +{ + Q_D(QmlEaseFollow); + d->enabled = enabled; + if (enabled) + d->restart(); + else + d->clockStop(); +} + void QmlEaseFollow::setTarget(const QmlMetaProperty &t) { Q_D(QmlEaseFollow); diff --git a/src/declarative/util/qmleasefollow.h b/src/declarative/util/qmleasefollow.h index adcb647..8e8c59d 100644 --- a/src/declarative/util/qmleasefollow.h +++ b/src/declarative/util/qmleasefollow.h @@ -66,6 +66,7 @@ class Q_DECLARATIVE_EXPORT QmlEaseFollow : public QObject, Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) Q_PROPERTY(qreal duration READ duration WRITE setDuration) Q_PROPERTY(ReversingMode reversingMode READ reversingMode WRITE setReversingMode) + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) public: enum ReversingMode { Eased, Immediate, Sync }; @@ -85,6 +86,9 @@ public: qreal duration() const; void setDuration(qreal); + bool enabled() const; + void setEnabled(bool enabled); + virtual void setTarget(const QmlMetaProperty &); }; diff --git a/src/declarative/util/qmlfollow.cpp b/src/declarative/util/qmlfollow.cpp deleted file mode 100644 index fe5303f..0000000 --- a/src/declarative/util/qmlfollow.cpp +++ /dev/null @@ -1,456 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include "private/qobject_p.h" -#include "qmlfollow.h" -#include "private/qmlanimation_p.h" - -QT_BEGIN_NAMESPACE - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Follow,QmlFollow) - -class QmlFollowPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlFollow) -public: - QmlFollowPrivate() - : sourceValue(0), maxVelocity(0), lastTime(0) - , mass(1.0), useMass(false), spring(0.), damping(0.), velocity(0), epsilon(0.01) - , modulus(0.0), haveModulus(false), enabled(true), mode(Track), clock(this) {} - - QmlMetaProperty property; - qreal currentValue; - qreal sourceValue; - qreal maxVelocity; - qreal velocityms; - int lastTime; - qreal mass; - bool useMass; - qreal spring; - qreal damping; - qreal velocity; - qreal epsilon; - qreal modulus; - bool haveModulus; - bool enabled; - - enum Mode { - Track, - Velocity, - Spring - }; - Mode mode; - - void tick(int); - void updateMode(); - void start(); - void stop(); - - QTickAnimationProxy clock; -}; - -void QmlFollowPrivate::tick(int time) -{ - Q_Q(QmlFollow); - - int elapsed = time - lastTime; - if (!elapsed) - return; - qreal srcVal = sourceValue; - if (haveModulus) { - currentValue = fmod(currentValue, modulus); - srcVal = fmod(srcVal, modulus); - } - if (mode == Spring) { - if (elapsed < 16) // capped at 62fps. - return; - // Real men solve the spring DEs using RK4. - // We'll do something much simpler which gives a result that looks fine. - int count = elapsed / 16; - for (int i = 0; i < count; ++i) { - qreal diff = srcVal - currentValue; - if (haveModulus && qAbs(diff) > modulus / 2) { - if (diff < 0) - diff += modulus; - else - diff -= modulus; - } - if (useMass) - velocity = velocity + (spring * diff - damping * velocity) / mass; - else - velocity = velocity + spring * diff - damping * velocity; - if (maxVelocity > 0.) { - // limit velocity - if (velocity > maxVelocity) - velocity = maxVelocity; - else if (velocity < -maxVelocity) - velocity = -maxVelocity; - } - currentValue += velocity * 16.0 / 1000.0; - if (haveModulus) { - currentValue = fmod(currentValue, modulus); - if (currentValue < 0.0) - currentValue += modulus; - } - } - if (qAbs(velocity) < epsilon && qAbs(srcVal - currentValue) < epsilon) { - velocity = 0.0; - currentValue = srcVal; - clock.stop(); - } - lastTime = time - (elapsed - count * 16); - } else { - qreal moveBy = elapsed * velocityms; - qreal diff = srcVal - currentValue; - if (haveModulus && qAbs(diff) > modulus / 2) { - if (diff < 0) - diff += modulus; - else - diff -= modulus; - } - if (diff > 0) { - currentValue += moveBy; - if (haveModulus) - currentValue = fmod(currentValue, modulus); - if (currentValue > sourceValue) { - currentValue = sourceValue; - clock.stop(); - } - } else { - currentValue -= moveBy; - if (haveModulus && currentValue < 0.0) - currentValue = fmod(currentValue, modulus) + modulus; - if (currentValue < sourceValue) { - currentValue = sourceValue; - clock.stop(); - } - } - lastTime = time; - } - property.write(currentValue); - emit q->valueChanged(currentValue); - if (clock.state() != QAbstractAnimation::Running) - emit q->syncChanged(); -} - -void QmlFollowPrivate::updateMode() -{ - if (spring == 0. && maxVelocity == 0.) - mode = Track; - else if (spring > 0.) - mode = Spring; - else - mode = Velocity; -} - -void QmlFollowPrivate::start() -{ - if (!enabled) - return; - - Q_Q(QmlFollow); - if (mode == QmlFollowPrivate::Track) { - currentValue = sourceValue; - property.write(currentValue); - } else if (sourceValue != currentValue && clock.state() != QAbstractAnimation::Running) { - lastTime = 0; - currentValue = property.read().toDouble(); - clock.start(); // infinity?? - emit q->syncChanged(); - } -} - -void QmlFollowPrivate::stop() -{ - clock.stop(); -} - -/*! - \qmlclass Follow QmlFollow - \brief The Follow element allows a property to track a value. - - In example below, Rect2 will follow Rect1 moving with a velocity of up to 200: - \code - Rectangle { - id: Rect1 - width: 20; height: 20 - color: "#00ff00" - y: 200 //initial value - y: SequentialAnimation { - running: true - repeat: true - NumberAnimation { - to: 200 - easing: "easeOutBounce(amplitude:100)" - duration: 2000 - } - PauseAnimation { duration: 1000 } - } - } - Rectangle { - id: Rect2 - x: Rect1.width - width: 20; height: 20 - color: "#ff0000" - y: Follow { source: Rect1.y; velocity: 200 } - } - \endcode -*/ - -QmlFollow::QmlFollow(QObject *parent) -: QObject(*(new QmlFollowPrivate),parent) -{ -} - -QmlFollow::~QmlFollow() -{ -} - -void QmlFollow::setTarget(const QmlMetaProperty &property) -{ - Q_D(QmlFollow); - d->property = property; - d->currentValue = property.read().toDouble(); -} - -qreal QmlFollow::sourceValue() const -{ - Q_D(const QmlFollow); - return d->sourceValue; -} - -/*! - \qmlproperty qreal Follow::source - This property holds the source value which will be tracked. - - Bind to a property in order to track its changes. -*/ - -void QmlFollow::setSourceValue(qreal value) -{ - Q_D(QmlFollow); - if (d->sourceValue != value) { - d->sourceValue = value; - d->start(); - } -} - -/*! - \qmlproperty qreal Follow::velocity - This property holds the maximum velocity allowed when tracking the source. -*/ - -qreal QmlFollow::velocity() const -{ - Q_D(const QmlFollow); - return d->maxVelocity; -} - -void QmlFollow::setVelocity(qreal velocity) -{ - Q_D(QmlFollow); - d->maxVelocity = velocity; - d->velocityms = velocity / 1000.0; - d->updateMode(); -} - -/*! - \qmlproperty qreal Follow::spring - This property holds the spring constant - - The spring constant describes how strongly the target is pulled towards the - source. Setting spring to 0 turns off spring tracking. Useful values 0 - 5.0 - - When a spring constant is set and the velocity property is greater than 0, - velocity limits the maximum speed. -*/ -qreal QmlFollow::spring() const -{ - Q_D(const QmlFollow); - return d->spring; -} - -void QmlFollow::setSpring(qreal spring) -{ - Q_D(QmlFollow); - d->spring = spring; - d->updateMode(); -} - -/*! - \qmlproperty qreal Follow::damping - This property holds the spring damping constant - - The damping constant describes how quickly a sprung follower comes to rest. - Useful range is 0 - 1.0 -*/ -qreal QmlFollow::damping() const -{ - Q_D(const QmlFollow); - return d->damping; -} - -void QmlFollow::setDamping(qreal damping) -{ - Q_D(QmlFollow); - if (damping > 1.) - damping = 1.; - - d->damping = damping; -} - - -/*! - \qmlproperty qreal Follow::epsilon - This property holds the spring epsilon - - The epsilon is the rate and amount of change in the value which is close enough - to 0 to be considered equal to zero. This will depend on the usage of the value. - For pixel positions, 0.25 would suffice. For scale, 0.005 will suffice. - - The default is 0.01. Tuning this value can provide small performance improvements. -*/ -qreal QmlFollow::epsilon() const -{ - Q_D(const QmlFollow); - return d->epsilon; -} - -void QmlFollow::setEpsilon(qreal epsilon) -{ - Q_D(QmlFollow); - d->epsilon = epsilon; -} - -/*! - \qmlproperty qreal Follow::modulus - This property holds the modulus value. - - Setting a \a modulus forces the target value to "wrap around" at the modulus. - For example, setting the modulus to 360 will cause a value of 370 to wrap around to 10. -*/ -qreal QmlFollow::modulus() const -{ - Q_D(const QmlFollow); - return d->modulus; -} - -void QmlFollow::setModulus(qreal modulus) -{ - Q_D(QmlFollow); - if (d->modulus != modulus) { - d->haveModulus = modulus != 0.0; - d->modulus = modulus; - emit modulusChanged(); - } -} - -/*! - \qmlproperty qreal Follow::mass - This property holds the "mass" of the property being moved. - - mass is 1.0 by default. Setting a different mass changes the dynamics of - a \l spring follow. -*/ -qreal QmlFollow::mass() const -{ - Q_D(const QmlFollow); - return d->mass; -} - -void QmlFollow::setMass(qreal mass) -{ - Q_D(QmlFollow); - if (d->mass != mass && mass > 0.0) { - d->useMass = mass != 1.0; - d->mass = mass; - emit massChanged(); - } -} - -/*! - \qmlproperty qreal Follow::value - The current value. -*/ - -/*! - \qmlproperty bool Follow::enabled - This property holds whether the target will track the source. -*/ -bool QmlFollow::enabled() const -{ - Q_D(const QmlFollow); - return d->enabled; -} - -void QmlFollow::setEnabled(bool enabled) -{ - Q_D(QmlFollow); - d->enabled = enabled; - if (enabled) - d->start(); - else - d->stop(); -} - -/*! - \qmlproperty bool Follow::inSync - This property is true when target is equal to the source; otherwise - false. If inSync is true the target is not being animated. - - If \l enabled is false then inSync will also be false. -*/ -bool QmlFollow::inSync() const -{ - Q_D(const QmlFollow); - return d->enabled && d->clock.state() != QAbstractAnimation::Running; -} - -qreal QmlFollow::value() const -{ - Q_D(const QmlFollow); - return d->currentValue; -} - -QT_END_NAMESPACE diff --git a/src/declarative/util/qmlfollow.h b/src/declarative/util/qmlfollow.h deleted file mode 100644 index ff34d08..0000000 --- a/src/declarative/util/qmlfollow.h +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLFOLLOW_H -#define QMLFOLLOW_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlFollowPrivate; -class Q_DECLARATIVE_EXPORT QmlFollow : public QObject, - public QmlPropertyValueSource -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlFollow) - Q_INTERFACES(QmlPropertyValueSource) - - Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue) - Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) - Q_PROPERTY(qreal spring READ spring WRITE setSpring) - Q_PROPERTY(qreal damping READ damping WRITE setDamping) - Q_PROPERTY(qreal epsilon READ epsilon WRITE setEpsilon) - Q_PROPERTY(qreal modulus READ modulus WRITE setModulus) - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) - Q_PROPERTY(qreal value READ value NOTIFY valueChanged) - Q_PROPERTY(qreal modulus READ modulus WRITE setModulus NOTIFY modulusChanged) - Q_PROPERTY(qreal mass READ mass WRITE setMass NOTIFY massChanged) - Q_PROPERTY(bool inSync READ inSync NOTIFY syncChanged) - -public: - QmlFollow(QObject *parent=0); - ~QmlFollow(); - - virtual void setTarget(const QmlMetaProperty &); - - qreal sourceValue() const; - void setSourceValue(qreal value); - qreal velocity() const; - void setVelocity(qreal velocity); - qreal spring() const; - void setSpring(qreal spring); - qreal damping() const; - void setDamping(qreal damping); - qreal epsilon() const; - void setEpsilon(qreal epsilon); - qreal mass() const; - void setMass(qreal modulus); - qreal modulus() const; - void setModulus(qreal modulus); - bool enabled() const; - void setEnabled(bool enabled); - bool inSync() const; - - qreal value() const; - -Q_SIGNALS: - void valueChanged(qreal); - void modulusChanged(); - void massChanged(); - void syncChanged(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlFollow) - -QT_END_HEADER - -#endif // QFXFOLLOW_H diff --git a/src/declarative/util/qmlspringfollow.cpp b/src/declarative/util/qmlspringfollow.cpp new file mode 100644 index 0000000..8c902aa --- /dev/null +++ b/src/declarative/util/qmlspringfollow.cpp @@ -0,0 +1,456 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include "private/qobject_p.h" +#include "qmlspringfollow.h" +#include "private/qmlanimation_p.h" + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,SpringFollow,QmlSpringFollow) + +class QmlSpringFollowPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlSpringFollow) +public: + QmlSpringFollowPrivate() + : sourceValue(0), maxVelocity(0), lastTime(0) + , mass(1.0), useMass(false), spring(0.), damping(0.), velocity(0), epsilon(0.01) + , modulus(0.0), haveModulus(false), enabled(true), mode(Track), clock(this) {} + + QmlMetaProperty property; + qreal currentValue; + qreal sourceValue; + qreal maxVelocity; + qreal velocityms; + int lastTime; + qreal mass; + bool useMass; + qreal spring; + qreal damping; + qreal velocity; + qreal epsilon; + qreal modulus; + bool haveModulus; + bool enabled; + + enum Mode { + Track, + Velocity, + Spring + }; + Mode mode; + + void tick(int); + void updateMode(); + void start(); + void stop(); + + QTickAnimationProxy clock; +}; + +void QmlSpringFollowPrivate::tick(int time) +{ + Q_Q(QmlSpringFollow); + + int elapsed = time - lastTime; + if (!elapsed) + return; + qreal srcVal = sourceValue; + if (haveModulus) { + currentValue = fmod(currentValue, modulus); + srcVal = fmod(srcVal, modulus); + } + if (mode == Spring) { + if (elapsed < 16) // capped at 62fps. + return; + // Real men solve the spring DEs using RK4. + // We'll do something much simpler which gives a result that looks fine. + int count = elapsed / 16; + for (int i = 0; i < count; ++i) { + qreal diff = srcVal - currentValue; + if (haveModulus && qAbs(diff) > modulus / 2) { + if (diff < 0) + diff += modulus; + else + diff -= modulus; + } + if (useMass) + velocity = velocity + (spring * diff - damping * velocity) / mass; + else + velocity = velocity + spring * diff - damping * velocity; + if (maxVelocity > 0.) { + // limit velocity + if (velocity > maxVelocity) + velocity = maxVelocity; + else if (velocity < -maxVelocity) + velocity = -maxVelocity; + } + currentValue += velocity * 16.0 / 1000.0; + if (haveModulus) { + currentValue = fmod(currentValue, modulus); + if (currentValue < 0.0) + currentValue += modulus; + } + } + if (qAbs(velocity) < epsilon && qAbs(srcVal - currentValue) < epsilon) { + velocity = 0.0; + currentValue = srcVal; + clock.stop(); + } + lastTime = time - (elapsed - count * 16); + } else { + qreal moveBy = elapsed * velocityms; + qreal diff = srcVal - currentValue; + if (haveModulus && qAbs(diff) > modulus / 2) { + if (diff < 0) + diff += modulus; + else + diff -= modulus; + } + if (diff > 0) { + currentValue += moveBy; + if (haveModulus) + currentValue = fmod(currentValue, modulus); + if (currentValue > sourceValue) { + currentValue = sourceValue; + clock.stop(); + } + } else { + currentValue -= moveBy; + if (haveModulus && currentValue < 0.0) + currentValue = fmod(currentValue, modulus) + modulus; + if (currentValue < sourceValue) { + currentValue = sourceValue; + clock.stop(); + } + } + lastTime = time; + } + property.write(currentValue); + emit q->valueChanged(currentValue); + if (clock.state() != QAbstractAnimation::Running) + emit q->syncChanged(); +} + +void QmlSpringFollowPrivate::updateMode() +{ + if (spring == 0. && maxVelocity == 0.) + mode = Track; + else if (spring > 0.) + mode = Spring; + else + mode = Velocity; +} + +void QmlSpringFollowPrivate::start() +{ + if (!enabled) + return; + + Q_Q(QmlSpringFollow); + if (mode == QmlSpringFollowPrivate::Track) { + currentValue = sourceValue; + property.write(currentValue); + } else if (sourceValue != currentValue && clock.state() != QAbstractAnimation::Running) { + lastTime = 0; + currentValue = property.read().toDouble(); + clock.start(); // infinity?? + emit q->syncChanged(); + } +} + +void QmlSpringFollowPrivate::stop() +{ + clock.stop(); +} + +/*! + \qmlclass SpringFollow QmlSpringFollow + \brief The SpringFollow element allows a property to track a value. + + In example below, Rect2 will follow Rect1 moving with a velocity of up to 200: + \code + Rectangle { + id: Rect1 + width: 20; height: 20 + color: "#00ff00" + y: 200 //initial value + y: SequentialAnimation { + running: true + repeat: true + NumberAnimation { + to: 200 + easing: "easeOutBounce(amplitude:100)" + duration: 2000 + } + PauseAnimation { duration: 1000 } + } + } + Rectangle { + id: Rect2 + x: Rect1.width + width: 20; height: 20 + color: "#ff0000" + y: SpringFollow { source: Rect1.y; velocity: 200 } + } + \endcode +*/ + +QmlSpringFollow::QmlSpringFollow(QObject *parent) +: QObject(*(new QmlSpringFollowPrivate),parent) +{ +} + +QmlSpringFollow::~QmlSpringFollow() +{ +} + +void QmlSpringFollow::setTarget(const QmlMetaProperty &property) +{ + Q_D(QmlSpringFollow); + d->property = property; + d->currentValue = property.read().toDouble(); +} + +qreal QmlSpringFollow::sourceValue() const +{ + Q_D(const QmlSpringFollow); + return d->sourceValue; +} + +/*! + \qmlproperty qreal SpringFollow::source + This property holds the source value which will be tracked. + + Bind to a property in order to track its changes. +*/ + +void QmlSpringFollow::setSourceValue(qreal value) +{ + Q_D(QmlSpringFollow); + if (d->sourceValue != value) { + d->sourceValue = value; + d->start(); + } +} + +/*! + \qmlproperty qreal SpringFollow::velocity + This property holds the maximum velocity allowed when tracking the source. +*/ + +qreal QmlSpringFollow::velocity() const +{ + Q_D(const QmlSpringFollow); + return d->maxVelocity; +} + +void QmlSpringFollow::setVelocity(qreal velocity) +{ + Q_D(QmlSpringFollow); + d->maxVelocity = velocity; + d->velocityms = velocity / 1000.0; + d->updateMode(); +} + +/*! + \qmlproperty qreal SpringFollow::spring + This property holds the spring constant + + The spring constant describes how strongly the target is pulled towards the + source. Setting spring to 0 turns off spring tracking. Useful values 0 - 5.0 + + When a spring constant is set and the velocity property is greater than 0, + velocity limits the maximum speed. +*/ +qreal QmlSpringFollow::spring() const +{ + Q_D(const QmlSpringFollow); + return d->spring; +} + +void QmlSpringFollow::setSpring(qreal spring) +{ + Q_D(QmlSpringFollow); + d->spring = spring; + d->updateMode(); +} + +/*! + \qmlproperty qreal SpringFollow::damping + This property holds the spring damping constant + + The damping constant describes how quickly a sprung follower comes to rest. + Useful range is 0 - 1.0 +*/ +qreal QmlSpringFollow::damping() const +{ + Q_D(const QmlSpringFollow); + return d->damping; +} + +void QmlSpringFollow::setDamping(qreal damping) +{ + Q_D(QmlSpringFollow); + if (damping > 1.) + damping = 1.; + + d->damping = damping; +} + + +/*! + \qmlproperty qreal SpringFollow::epsilon + This property holds the spring epsilon + + The epsilon is the rate and amount of change in the value which is close enough + to 0 to be considered equal to zero. This will depend on the usage of the value. + For pixel positions, 0.25 would suffice. For scale, 0.005 will suffice. + + The default is 0.01. Tuning this value can provide small performance improvements. +*/ +qreal QmlSpringFollow::epsilon() const +{ + Q_D(const QmlSpringFollow); + return d->epsilon; +} + +void QmlSpringFollow::setEpsilon(qreal epsilon) +{ + Q_D(QmlSpringFollow); + d->epsilon = epsilon; +} + +/*! + \qmlproperty qreal SpringFollow::modulus + This property holds the modulus value. + + Setting a \a modulus forces the target value to "wrap around" at the modulus. + For example, setting the modulus to 360 will cause a value of 370 to wrap around to 10. +*/ +qreal QmlSpringFollow::modulus() const +{ + Q_D(const QmlSpringFollow); + return d->modulus; +} + +void QmlSpringFollow::setModulus(qreal modulus) +{ + Q_D(QmlSpringFollow); + if (d->modulus != modulus) { + d->haveModulus = modulus != 0.0; + d->modulus = modulus; + emit modulusChanged(); + } +} + +/*! + \qmlproperty qreal SpringFollow::mass + This property holds the "mass" of the property being moved. + + mass is 1.0 by default. Setting a different mass changes the dynamics of + a \l spring follow. +*/ +qreal QmlSpringFollow::mass() const +{ + Q_D(const QmlSpringFollow); + return d->mass; +} + +void QmlSpringFollow::setMass(qreal mass) +{ + Q_D(QmlSpringFollow); + if (d->mass != mass && mass > 0.0) { + d->useMass = mass != 1.0; + d->mass = mass; + emit massChanged(); + } +} + +/*! + \qmlproperty qreal SpringFollow::value + The current value. +*/ + +/*! + \qmlproperty bool SpringFollow::enabled + This property holds whether the target will track the source. +*/ +bool QmlSpringFollow::enabled() const +{ + Q_D(const QmlSpringFollow); + return d->enabled; +} + +void QmlSpringFollow::setEnabled(bool enabled) +{ + Q_D(QmlSpringFollow); + d->enabled = enabled; + if (enabled) + d->start(); + else + d->stop(); +} + +/*! + \qmlproperty bool SpringFollow::inSync + This property is true when target is equal to the source; otherwise + false. If inSync is true the target is not being animated. + + If \l enabled is false then inSync will also be false. +*/ +bool QmlSpringFollow::inSync() const +{ + Q_D(const QmlSpringFollow); + return d->enabled && d->clock.state() != QAbstractAnimation::Running; +} + +qreal QmlSpringFollow::value() const +{ + Q_D(const QmlSpringFollow); + return d->currentValue; +} + +QT_END_NAMESPACE diff --git a/src/declarative/util/qmlspringfollow.h b/src/declarative/util/qmlspringfollow.h new file mode 100644 index 0000000..1b77861 --- /dev/null +++ b/src/declarative/util/qmlspringfollow.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLFOLLOW_H +#define QMLFOLLOW_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlSpringFollowPrivate; +class Q_DECLARATIVE_EXPORT QmlSpringFollow : public QObject, + public QmlPropertyValueSource +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlSpringFollow) + Q_INTERFACES(QmlPropertyValueSource) + + Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue) + Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) + Q_PROPERTY(qreal spring READ spring WRITE setSpring) + Q_PROPERTY(qreal damping READ damping WRITE setDamping) + Q_PROPERTY(qreal epsilon READ epsilon WRITE setEpsilon) + Q_PROPERTY(qreal modulus READ modulus WRITE setModulus) + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) + Q_PROPERTY(qreal value READ value NOTIFY valueChanged) + Q_PROPERTY(qreal modulus READ modulus WRITE setModulus NOTIFY modulusChanged) + Q_PROPERTY(qreal mass READ mass WRITE setMass NOTIFY massChanged) + Q_PROPERTY(bool inSync READ inSync NOTIFY syncChanged) + +public: + QmlSpringFollow(QObject *parent=0); + ~QmlSpringFollow(); + + virtual void setTarget(const QmlMetaProperty &); + + qreal sourceValue() const; + void setSourceValue(qreal value); + qreal velocity() const; + void setVelocity(qreal velocity); + qreal spring() const; + void setSpring(qreal spring); + qreal damping() const; + void setDamping(qreal damping); + qreal epsilon() const; + void setEpsilon(qreal epsilon); + qreal mass() const; + void setMass(qreal modulus); + qreal modulus() const; + void setModulus(qreal modulus); + bool enabled() const; + void setEnabled(bool enabled); + bool inSync() const; + + qreal value() const; + +Q_SIGNALS: + void valueChanged(qreal); + void modulusChanged(); + void massChanged(); + void syncChanged(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlSpringFollow) + +QT_END_HEADER + +#endif // QFXFOLLOW_H diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index a57f69f..442380a 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -7,7 +7,7 @@ SOURCES += \ util/qmlscript.cpp \ util/qmlanimation.cpp \ util/qmlsystempalette.cpp \ - util/qmlfollow.cpp \ + util/qmlspringfollow.cpp \ util/qmleasefollow.cpp \ util/qmlstate.cpp\ util/qmltransitionmanager.cpp \ @@ -33,7 +33,7 @@ HEADERS += \ util/qmlanimation.h \ util/qmlanimation_p.h \ util/qmlsystempalette.h \ - util/qmlfollow.h \ + util/qmlspringfollow.h \ util/qmleasefollow.h \ util/qmlstate.h\ util/qmlstateoperations.h \ -- cgit v0.12 From 033f7de03ed83cfa68436660e6354cb94452ee25 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 10 Sep 2009 14:29:24 +1000 Subject: Best to delete pointer before zeroing it. --- src/declarative/fx/qfxloader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxloader.cpp b/src/declarative/fx/qfxloader.cpp index e75ce6d..668faa4 100644 --- a/src/declarative/fx/qfxloader.cpp +++ b/src/declarative/fx/qfxloader.cpp @@ -120,8 +120,8 @@ void QFxLoader::setSource(const QUrl &url) delete d->component; d->component = 0; } - d->item = 0; delete d->item; + d->item = 0; d->source = url; if (d->source.isEmpty()) { -- cgit v0.12 From 087f3d86fccb0195e017c6ce8dfca710a94b723b Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 10 Sep 2009 11:53:57 +0200 Subject: Fix extending examples by inserting the appropriate import. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: owolff Reviewed-by: Thorbjørn Lindeijer --- examples/declarative/extending/adding/example.qml | 1 + examples/declarative/extending/attached/example.qml | 1 + examples/declarative/extending/binding/example.qml | 1 + examples/declarative/extending/coercion/example.qml | 1 + examples/declarative/extending/default/example.qml | 1 + examples/declarative/extending/extended/example.qml | 1 + examples/declarative/extending/grouped/example.qml | 1 + examples/declarative/extending/properties/example.qml | 1 + examples/declarative/extending/signal/example.qml | 1 + examples/declarative/extending/valuesource/example.qml | 1 + 10 files changed, 10 insertions(+) diff --git a/examples/declarative/extending/adding/example.qml b/examples/declarative/extending/adding/example.qml index ba7af7a..b8fee26 100644 --- a/examples/declarative/extending/adding/example.qml +++ b/examples/declarative/extending/adding/example.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import People 1.0 // ![0] Person { diff --git a/examples/declarative/extending/attached/example.qml b/examples/declarative/extending/attached/example.qml index 20233f6..6cf3e39 100644 --- a/examples/declarative/extending/attached/example.qml +++ b/examples/declarative/extending/attached/example.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import People 1.0 BirthdayParty { celebrant: Boy { diff --git a/examples/declarative/extending/binding/example.qml b/examples/declarative/extending/binding/example.qml index cedb8bd..7ab0d62 100644 --- a/examples/declarative/extending/binding/example.qml +++ b/examples/declarative/extending/binding/example.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { diff --git a/examples/declarative/extending/coercion/example.qml b/examples/declarative/extending/coercion/example.qml index 5090782..ce2c32d 100644 --- a/examples/declarative/extending/coercion/example.qml +++ b/examples/declarative/extending/coercion/example.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { diff --git a/examples/declarative/extending/default/example.qml b/examples/declarative/extending/default/example.qml index 5fe693a..051a9d2 100644 --- a/examples/declarative/extending/default/example.qml +++ b/examples/declarative/extending/default/example.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { diff --git a/examples/declarative/extending/extended/example.qml b/examples/declarative/extending/extended/example.qml index a276211..8311c8e 100644 --- a/examples/declarative/extending/extended/example.qml +++ b/examples/declarative/extending/extended/example.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import People 1.0 // ![0] QLineEdit { diff --git a/examples/declarative/extending/grouped/example.qml b/examples/declarative/extending/grouped/example.qml index 1be7abe..622e204 100644 --- a/examples/declarative/extending/grouped/example.qml +++ b/examples/declarative/extending/grouped/example.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { diff --git a/examples/declarative/extending/properties/example.qml b/examples/declarative/extending/properties/example.qml index 326105a..976baf2 100644 --- a/examples/declarative/extending/properties/example.qml +++ b/examples/declarative/extending/properties/example.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { diff --git a/examples/declarative/extending/signal/example.qml b/examples/declarative/extending/signal/example.qml index 1cbaab4..dc3a61a 100644 --- a/examples/declarative/extending/signal/example.qml +++ b/examples/declarative/extending/signal/example.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { diff --git a/examples/declarative/extending/valuesource/example.qml b/examples/declarative/extending/valuesource/example.qml index aba2796..c536061 100644 --- a/examples/declarative/extending/valuesource/example.qml +++ b/examples/declarative/extending/valuesource/example.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { -- cgit v0.12 From 754c3ac2598a7c2b0f212f8aa3e281d63be6578e Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 10 Sep 2009 13:10:42 +0200 Subject: Fix QML_DEFINE_EXTENDED_TYPE use in extending/extended example. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Thorbjørn Lindeijer --- examples/declarative/extending/extended/lineedit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/declarative/extending/extended/lineedit.cpp b/examples/declarative/extending/extended/lineedit.cpp index fe4fdc3..f11d22e 100644 --- a/examples/declarative/extending/extended/lineedit.cpp +++ b/examples/declarative/extending/extended/lineedit.cpp @@ -63,4 +63,4 @@ int LineEditExtension::setBottomMargin(int m) } QML_DECLARE_TYPE(QLineEdit); -QML_DEFINE_EXTENDED_TYPE(QLineEdit, QLineEdit, LineEditExtension); +QML_DEFINE_EXTENDED_TYPE(People, 1, 0, 0, QLineEdit, QLineEdit, LineEditExtension); -- cgit v0.12 From 93340b47b14605fb54a6d74f07af8d3c4d6a1777 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 10 Sep 2009 13:12:19 +0200 Subject: Remove unused imports from examples for extending. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Thorbjørn Lindeijer --- examples/declarative/extending/adding/example.qml | 1 - examples/declarative/extending/attached/example.qml | 1 - examples/declarative/extending/binding/example.qml | 1 - examples/declarative/extending/coercion/example.qml | 1 - examples/declarative/extending/default/example.qml | 1 - examples/declarative/extending/extended/example.qml | 1 - examples/declarative/extending/grouped/example.qml | 1 - examples/declarative/extending/properties/example.qml | 1 - examples/declarative/extending/signal/example.qml | 1 - examples/declarative/extending/valuesource/example.qml | 1 - 10 files changed, 10 deletions(-) diff --git a/examples/declarative/extending/adding/example.qml b/examples/declarative/extending/adding/example.qml index b8fee26..c608f94 100644 --- a/examples/declarative/extending/adding/example.qml +++ b/examples/declarative/extending/adding/example.qml @@ -1,4 +1,3 @@ -import Qt 4.6 import People 1.0 // ![0] diff --git a/examples/declarative/extending/attached/example.qml b/examples/declarative/extending/attached/example.qml index 6cf3e39..952eb93 100644 --- a/examples/declarative/extending/attached/example.qml +++ b/examples/declarative/extending/attached/example.qml @@ -1,4 +1,3 @@ -import Qt 4.6 import People 1.0 BirthdayParty { diff --git a/examples/declarative/extending/binding/example.qml b/examples/declarative/extending/binding/example.qml index 7ab0d62..1651b7a 100644 --- a/examples/declarative/extending/binding/example.qml +++ b/examples/declarative/extending/binding/example.qml @@ -1,4 +1,3 @@ -import Qt 4.6 import People 1.0 // ![0] diff --git a/examples/declarative/extending/coercion/example.qml b/examples/declarative/extending/coercion/example.qml index ce2c32d..64d26b0 100644 --- a/examples/declarative/extending/coercion/example.qml +++ b/examples/declarative/extending/coercion/example.qml @@ -1,4 +1,3 @@ -import Qt 4.6 import People 1.0 // ![0] diff --git a/examples/declarative/extending/default/example.qml b/examples/declarative/extending/default/example.qml index 051a9d2..58035f9 100644 --- a/examples/declarative/extending/default/example.qml +++ b/examples/declarative/extending/default/example.qml @@ -1,4 +1,3 @@ -import Qt 4.6 import People 1.0 // ![0] diff --git a/examples/declarative/extending/extended/example.qml b/examples/declarative/extending/extended/example.qml index 8311c8e..985ce20 100644 --- a/examples/declarative/extending/extended/example.qml +++ b/examples/declarative/extending/extended/example.qml @@ -1,4 +1,3 @@ -import Qt 4.6 import People 1.0 // ![0] diff --git a/examples/declarative/extending/grouped/example.qml b/examples/declarative/extending/grouped/example.qml index 622e204..55912ed 100644 --- a/examples/declarative/extending/grouped/example.qml +++ b/examples/declarative/extending/grouped/example.qml @@ -1,4 +1,3 @@ -import Qt 4.6 import People 1.0 // ![0] diff --git a/examples/declarative/extending/properties/example.qml b/examples/declarative/extending/properties/example.qml index 976baf2..9594a84 100644 --- a/examples/declarative/extending/properties/example.qml +++ b/examples/declarative/extending/properties/example.qml @@ -1,4 +1,3 @@ -import Qt 4.6 import People 1.0 // ![0] diff --git a/examples/declarative/extending/signal/example.qml b/examples/declarative/extending/signal/example.qml index dc3a61a..e46bf32 100644 --- a/examples/declarative/extending/signal/example.qml +++ b/examples/declarative/extending/signal/example.qml @@ -1,4 +1,3 @@ -import Qt 4.6 import People 1.0 // ![0] diff --git a/examples/declarative/extending/valuesource/example.qml b/examples/declarative/extending/valuesource/example.qml index c536061..6d47350 100644 --- a/examples/declarative/extending/valuesource/example.qml +++ b/examples/declarative/extending/valuesource/example.qml @@ -1,4 +1,3 @@ -import Qt 4.6 import People 1.0 // ![0] -- cgit v0.12 From abfa26ff5be47edcf38a48bacb4bd310badca09e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 10 Sep 2009 13:37:49 +0200 Subject: Fixed references to QFxPainted, which got replaced by QFxPaintedItem See commit 415708f85341448c6f30bbca6e31e48dbfde72a5, and later renaming of QFxImageItem to QFxPaintedItem in commit d1bb572b9fb5b0286df992c8ae560d91c9dc3388. Also added a table of contents to the QML for C++ Programmers page. --- doc/src/declarative/cppitem.qdoc | 6 +++--- doc/src/declarative/qmlforcpp.qdoc | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/src/declarative/cppitem.qdoc b/doc/src/declarative/cppitem.qdoc index 4543156..38da0fb 100644 --- a/doc/src/declarative/cppitem.qdoc +++ b/doc/src/declarative/cppitem.qdoc @@ -94,7 +94,7 @@ You can create a new type of QML item by: To add a new type, you first must add a new C++ class derived from QFxItem. You may of course extend existing QFxItem subclasses. -One existing subclass is QFxPainted, which provides +One existing subclass is QFxPaintedItem, which provides a simple cached-image painting model. \section2 Reimplementing paint functions @@ -105,11 +105,11 @@ Two alternative painters are available, offering different levels of performance and functionality: QPainter, GLPainter. -You can choose to subclass QFxPainted rather than QFxItem, +You can choose to subclass QFxPaintedItem rather than QFxItem, and then implement the virtual method: \code - void paint(QPainter *painter); + void drawContents(QPainter *painter, const QRect &rect); \endcode This paints into an offscreen pixmap which is then painted to the display (transformed, diff --git a/doc/src/declarative/qmlforcpp.qdoc b/doc/src/declarative/qmlforcpp.qdoc index 5838df7..ab456e5 100644 --- a/doc/src/declarative/qmlforcpp.qdoc +++ b/doc/src/declarative/qmlforcpp.qdoc @@ -15,6 +15,8 @@ either for the first time at startup or subsequently thereafter - the property is automatically updated with the new value. + \tableofcontents + \section1 Loading and using QML Files QmlComponent is used to load a QML file and to create object instances. -- cgit v0.12 From ad96554aa5eae45d256120dbaf840da0bcee2fba Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 11 Sep 2009 08:32:18 +1000 Subject: Implement itemsMoved() in ListView. No animation possible currently. --- src/declarative/fx/qfxlistview.cpp | 78 +++++++++++++++++++++---------- src/declarative/fx/qfxvisualitemmodel.cpp | 19 +++++++- src/declarative/util/qmllistmodel.cpp | 2 +- 3 files changed, 73 insertions(+), 26 deletions(-) diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 49de016..a07b3c0 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -377,7 +377,6 @@ public: QmlComponent *highlightComponent; FxListItem *highlight; FxListItem *trackedItem; - QFxItem *activeItem; //XXX fix enum MovementReason { Other, Key, Mouse }; MovementReason moveReason; int buffer; @@ -1431,9 +1430,7 @@ void QFxListView::itemResized() Q_D(QFxListView); QFxItem *item = qobject_cast(sender()); if (item) { - d->activeItem = item; // Ick - don't delete the sender d->layout(); - d->activeItem = 0; d->fixupPosition(); } } @@ -1642,33 +1639,66 @@ void QFxListView::destroyRemoved() void QFxListView::itemsMoved(int from, int to, int count) { - qWarning() << "ListView does not support moving in models"; - Q_D(QFxListView); - int fromCount = count; - int toCount = count; - bool fromVisible = d->mapRangeFromModel(from, fromCount); - bool toVisible = d->mapRangeFromModel(to, toCount); - - if (!fromVisible && !toVisible) { - // The items are outside the visible range. - if (d->visibleItems.count()) - d->visibleIndex = -1; - for (int i = 0; i < d->visibleItems.count(); ++i) { - FxListItem *listItem = d->visibleItems.at(i); - if (listItem->index != -1) { - listItem->index = d->model->indexOf(listItem->item, this); - if (d->visibleIndex < 0) - d->visibleIndex = listItem->index; + QHash moved; + int moveBy = 0; + + QList::Iterator it = d->visibleItems.begin(); + while (it != d->visibleItems.end()) { + FxListItem *item = *it; + if (item->index >= from && item->index < from + count) { + // take the items that are moving + item->index += (to-from); + moved.insert(item->index, item); + moveBy += item->size(); + it = d->visibleItems.erase(it); + } else { + if (item->index > from && item->index != -1) { + // move everything after the moved items. + item->index -= count; + item->setPosition(item->position()-moveBy); } + ++it; } - if (d->currentItem) { - d->currentItem->index = d->model->indexOf(d->currentItem->item, this); - d->currentIndex = d->currentItem->index; + } + + int remaining = count; + int endIndex = d->visibleIndex; + it = d->visibleItems.begin(); + while (it != d->visibleItems.end()) { + FxListItem *item = *it; + if (remaining && item->index >= to && item->index < to + count) { + // place items in the target position, reusing any existing items + FxListItem *movedItem = moved.take(item->index); + if (!movedItem) + movedItem = d->createItem(item->index); + it = d->visibleItems.insert(it, movedItem); + ++it; + --remaining; + } else { + if (item->index != -1) { + if (item->index >= to) { + // update everything after the moved items. + item->index += count; + } + endIndex = item->index; + } + ++it; } - return; } + // If we have moved items to the end of the visible items + // then add any existing moved items that we have + while (FxListItem *item = moved.take(endIndex+1)) { + d->visibleItems.append(item); + ++endIndex; + } + + // Whatever moved items remain are no longer visible items. + while (moved.count()) + d->releaseItem(moved.take(moved.begin().key())); + + d->layout(); } void QFxListView::createdItem(int index, QFxItem *item) diff --git a/src/declarative/fx/qfxvisualitemmodel.cpp b/src/declarative/fx/qfxvisualitemmodel.cpp index cac8b8d..30879a2 100644 --- a/src/declarative/fx/qfxvisualitemmodel.cpp +++ b/src/declarative/fx/qfxvisualitemmodel.cpp @@ -695,7 +695,8 @@ QFxVisualDataModel::ReleaseFlags QFxVisualDataModel::release(QFxItem *item) if (inPackage) emit destroyingPackage(qobject_cast(obj)); stat |= Destroyed; - delete obj; + obj->setParent(0); + obj->deleteLater(); } else if (!inPackage) { stat |= Referenced; } @@ -916,6 +917,22 @@ void QFxVisualDataModel::_q_itemsMoved(int from, int to, int count) ++iter; } } + for (QHash::Iterator iter = d->m_cache.begin(); + iter != d->m_cache.end(); ) { + + if (iter.key() >= qMin(from,to) && iter.key() < qMax(from+count,to+count)) { + QFxVisualDataModelPrivate::ObjectRef objRef = *iter; + int index = iter.key() + from - to; + iter = d->m_cache.erase(iter); + + items.insert(index, objRef); + + QFxVisualDataModelData *data = d->data(objRef.obj); + data->setIndex(index); + } else { + ++iter; + } + } d->m_cache.unite(items); emit itemsMoved(from, to, count); diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index 19499a1..345bc3b 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -497,7 +497,7 @@ void QmlListModel::insert(int index, const QScriptValue& valuemap) */ void QmlListModel::move(int from, int to, int n) { - if (from+n > count() || to+n > count() || n==0 || from==to) + if (from+n > count() || to+n > count() || n==0 || from==to || from < 0 || to < 0) return; if (from > to) { // Only move forwards - flip if backwards moving -- cgit v0.12 From 804c9ef64085fafe6f12b92e5dd40e595ed3460f Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 11 Sep 2009 10:08:06 +1000 Subject: Handle itemsMoved() in GridView. --- src/declarative/fx/qfxgridview.cpp | 63 ++++++++++++++++++++++++++++++++++++++ src/declarative/fx/qfxgridview.h | 1 + 2 files changed, 64 insertions(+) diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index dfb04ad..f49375a 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -723,6 +723,7 @@ void QFxGridView::setModel(const QVariant &model) if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); disconnect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); disconnect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); } @@ -751,6 +752,7 @@ void QFxGridView::setModel(const QVariant &model) d->updateCurrent(d->currentIndex); connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); connect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); connect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); refill(); @@ -1356,6 +1358,67 @@ void QFxGridView::destroyRemoved() d->layout(); } +void QFxGridView::itemsMoved(int from, int to, int count) +{ + Q_D(QFxGridView); + QHash moved; + + QList::Iterator it = d->visibleItems.begin(); + while (it != d->visibleItems.end()) { + FxGridItem *item = *it; + if (item->index >= from && item->index < from + count) { + // take the items that are moving + item->index += (to-from); + moved.insert(item->index, item); + it = d->visibleItems.erase(it); + } else { + if (item->index > from && item->index != -1) { + // move everything after the moved items. + item->index -= count; + } + ++it; + } + } + + int remaining = count; + int endIndex = d->visibleIndex; + it = d->visibleItems.begin(); + while (it != d->visibleItems.end()) { + FxGridItem *item = *it; + if (remaining && item->index >= to && item->index < to + count) { + // place items in the target position, reusing any existing items + FxGridItem *movedItem = moved.take(item->index); + if (!movedItem) + movedItem = d->createItem(item->index); + it = d->visibleItems.insert(it, movedItem); + ++it; + --remaining; + } else { + if (item->index != -1) { + if (item->index >= to) { + // update everything after the moved items. + item->index += count; + } + endIndex = item->index; + } + ++it; + } + } + + // If we have moved items to the end of the visible items + // then add any existing moved items that we have + while (FxGridItem *item = moved.take(endIndex+1)) { + d->visibleItems.append(item); + ++endIndex; + } + + // Whatever moved items remain are no longer visible items. + while (moved.count()) + d->releaseItem(moved.take(moved.begin().key())); + + d->layout(); +} + void QFxGridView::createdItem(int index, QFxItem *item) { Q_D(QFxGridView); diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h index 954f9fe..734039c 100644 --- a/src/declarative/fx/qfxgridview.h +++ b/src/declarative/fx/qfxgridview.h @@ -130,6 +130,7 @@ private Q_SLOTS: void trackedPositionChanged(); void itemsInserted(int index, int count); void itemsRemoved(int index, int count); + void itemsMoved(int from, int to, int count); void destroyRemoved(); void createdItem(int index, QFxItem *item); void destroyingItem(QFxItem *item); -- cgit v0.12 From 7051254771882e88f64f9b5578d975f29efab0b6 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 11 Sep 2009 10:54:11 +1000 Subject: current -> currentItem property in ListView and GridView --- examples/declarative/listview/highlight.qml | 2 +- examples/declarative/loader/Browser.qml | 2 +- src/declarative/QmlChanges.txt | 2 ++ src/declarative/fx/qfxgridview.cpp | 4 ++-- src/declarative/fx/qfxgridview.h | 2 +- src/declarative/fx/qfxlistview.cpp | 4 ++-- src/declarative/fx/qfxlistview.h | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/declarative/listview/highlight.qml b/examples/declarative/listview/highlight.qml index e707ac0..cb92ad9 100644 --- a/examples/declarative/listview/highlight.qml +++ b/examples/declarative/listview/highlight.qml @@ -44,7 +44,7 @@ Rectangle { id: PetHighlight Rectangle { width: 200; height: 50; color: "#FFFF88" - y: SpringFollow { source: List1.current.y; spring: 3; damping: 0.1 } + y: SpringFollow { source: List1.currentItem.y; spring: 3; damping: 0.1 } } } ListView { diff --git a/examples/declarative/loader/Browser.qml b/examples/declarative/loader/Browser.qml index 196cdc5..6711de4 100644 --- a/examples/declarative/loader/Browser.qml +++ b/examples/declarative/loader/Browser.qml @@ -82,7 +82,7 @@ Rectangle { focus: true Keys.onPressed: { if (event.key == Qt.Key_Return || event.key == Qt.Key_Select) { - View.current.launch(); + View.currentItem.launch(); event.accepted = true; } } diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index eace089..fe923a7 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -64,6 +64,8 @@ WebView: mouseY -> clickY (parameter to onDoubleClick) WebView: cacheSize -> pixelCacheSize Repeater: component -> delegate Repeater: dataSource -> model +ListView: current -> currentItem +GridView: current -> currentItem Additions: MouseRegion: add "acceptedButtons" property diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index f49375a..d4cf691 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -795,10 +795,10 @@ void QFxGridView::setDelegate(QmlComponent *delegate) /*! \qmlproperty int GridView::currentIndex - \qmlproperty Item GridView::current + \qmlproperty Item GridView::currentItem \c currentIndex holds the index of the current item. - \c current is the current item. Note that the position of the current item + \c currentItem is the current item. Note that the position of the current item may only be approximate until it becomes visible in the view. */ int QFxGridView::currentIndex() const diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h index 734039c..e08ba9e 100644 --- a/src/declarative/fx/qfxgridview.h +++ b/src/declarative/fx/qfxgridview.h @@ -60,7 +60,7 @@ class Q_DECLARATIVE_EXPORT QFxGridView : public QFxFlickable Q_PROPERTY(QVariant model READ model WRITE setModel) Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QFxItem *current READ currentItem NOTIFY currentIndexChanged) //### currentItem + Q_PROPERTY(QFxItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index a07b3c0..6596735 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -983,10 +983,10 @@ void QFxListView::setDelegate(QmlComponent *delegate) /*! \qmlproperty int ListView::currentIndex - \qmlproperty Item ListView::current + \qmlproperty Item ListView::currentItem \c currentIndex holds the index of the current item. - \c current is the current item. Note that the position of the current item + \c currentItem is the current item. Note that the position of the current item may only be approximate until it becomes visible in the view. */ int QFxListView::currentIndex() const diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index 829e202..4a124cb 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -67,7 +67,7 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_PROPERTY(QVariant model READ model WRITE setModel) Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) //### what happens if delegate is not a QFxItem? Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QFxItem *current READ currentItem NOTIFY currentIndexChanged) //### currentItem + Q_PROPERTY(QFxItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) //### highlightFollowsCurrentItem -- cgit v0.12 From c56df535f5bf40ff0afefd10c3b1bf348763c65d Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 11 Sep 2009 11:56:18 +1000 Subject: Use drawTiledPixmap for tiling. So we can take advantage of backend optimizations. --- src/declarative/fx/qfximage.cpp | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index 99e1b72..79b3ae1 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -255,36 +255,12 @@ void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) p->save(); p->setClipRect(0, 0, width(), height(), Qt::IntersectClip); - if (d->fillMode == Tile) { - const int pw = d->pix.width(); - const int ph = d->pix.height(); - int yy = 0; - - while(yy < height()) { - int xx = 0; - while(xx < width()) { - p->drawPixmap(xx, yy, d->pix); - xx += pw; - } - yy += ph; - } - } else if (d->fillMode == TileVertically) { - const int ph = d->pix.height(); - int yy = 0; - - while(yy < height()) { - p->drawPixmap(QRect(0, yy, width(), ph), d->pix); - yy += ph; - } - } else { - const int pw = d->pix.width(); - int xx = 0; - - while(xx < width()) { - p->drawPixmap(QRect(xx, 0, pw, height()), d->pix); - xx += pw; - } - } + if (d->fillMode == Tile) + p->drawTiledPixmap(QRectF(0,0,width(),height()), d->pix); + else if (d->fillMode == TileVertically) + p->drawTiledPixmap(QRectF(0,0,d->pix.width(),height()), d->pix); + else + p->drawTiledPixmap(QRectF(0,0,width(),d->pix.height()), d->pix); p->restore(); } else { -- cgit v0.12 From 3a4eb09c502d2394b35b62ca12b28cba392dc270 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 11 Sep 2009 13:32:23 +1000 Subject: tweak --- .../listview/content/ClickAutoRepeating.qml | 29 ++++++++++++++++++++++ examples/declarative/listview/dynamic.qml | 7 ++++-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 examples/declarative/listview/content/ClickAutoRepeating.qml diff --git a/examples/declarative/listview/content/ClickAutoRepeating.qml b/examples/declarative/listview/content/ClickAutoRepeating.qml new file mode 100644 index 0000000..19dd6f6 --- /dev/null +++ b/examples/declarative/listview/content/ClickAutoRepeating.qml @@ -0,0 +1,29 @@ +import Qt 4.6 + +Item { + id: Page + property int repeatdelay: 300 + property int repeatperiod: 75 + property bool pressed: false + signal pressed + signal released + signal clicked + pressed: SequentialAnimation { + id: AutoRepeat + PropertyAction { target: Page; property: "pressed"; value: true } + ScriptAction { script: Page.onPressed } + ScriptAction { script: Page.onClicked } + PauseAnimation { duration: repeatdelay } + SequentialAnimation { + repeat: true + ScriptAction { script: Page.onClicked } + PauseAnimation { duration: repeatperiod } + } + } + MouseRegion { + id: MR + anchors.fill: parent + onPressed: AutoRepeat.start() + onReleased: { AutoRepeat.stop(); parent.pressed = false; Page.released } + } +} diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml index f615c24..dde24f6 100644 --- a/examples/declarative/listview/dynamic.qml +++ b/examples/declarative/listview/dynamic.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import "content" Item { width: 320 @@ -75,10 +76,12 @@ Item { anchors.right: parent.right width: childrenRect.width Image { source: "content/pics/add.png" - MouseRegion { anchors.fill: parent; onClicked: FruitModel.set(index,"cost",Number(cost)+0.25) } + ClickAutoRepeating { id: ClickUp; anchors.fill: parent; onClicked: FruitModel.set(index,"cost",Number(cost)+0.25) } + scale: ClickUp.pressed ? 0.9 : 1 } Image { source: "content/pics/del.png" - MouseRegion { anchors.fill: parent; onClicked: FruitModel.set(index,"cost",Number(cost)-0.25) } + ClickAutoRepeating { id: ClickDown; anchors.fill: parent; onClicked: FruitModel.set(index,"cost",Math.max(0,Number(cost)-0.25)) } + scale: ClickDown.pressed ? 0.9 : 1 } Image { source: "content/pics/trash.png" MouseRegion { anchors.fill: parent; onClicked: FruitModel.remove(index) } -- cgit v0.12 From 2984be68041afc154fab2a0b9eb6618caf26cf71 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 11 Sep 2009 14:28:39 +1000 Subject: Avoid spurious flicks due to quick clicking motions. --- src/declarative/fx/qfxflickable.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index c227899..1e6ad5a 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -48,6 +48,16 @@ QT_BEGIN_NAMESPACE + +// These are highly device dependant. +// DragThreshold determines how far the "mouse" must move before +// we begin a drag. +// FlickThreshold determines how far the "mouse" must have moved +// before we perform a flick. +static const int DragThreshold = 8; +static const int FlickThreshold = 20; + + class QFxFlickableVisibleArea : public QObject { Q_OBJECT @@ -147,7 +157,7 @@ QFxFlickablePrivate::QFxFlickablePrivate() : viewport(new QFxItem), _moveX(viewport, &QFxItem::setX), _moveY(viewport, &QFxItem::setY) , vWidth(-1), vHeight(-1), overShoot(true), flicked(false), moving(false), stealMouse(false) , pressed(false), atXEnd(false), atXBeginning(true), atYEnd(false), atYBeginning(true) - , interactive(true), maxVelocity(-1), reportedVelocitySmoothing(100) + , interactive(true), maxVelocity(5000), reportedVelocitySmoothing(100) , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0) , horizontalVelocity(this), verticalVelocity(this), vTime(0), visibleArea(0) { @@ -327,8 +337,6 @@ void QFxFlickablePrivate::updateBeginningEnd() visibleArea->updateVisible(); } -static const int FlickThreshold = 5; - QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Flickable,QFxFlickable) /*! @@ -602,7 +610,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) if (q->yflick()) { int dy = int(event->pos().y() - pressPos.y()); - if (qAbs(dy) > FlickThreshold || pressTime.elapsed() > 200) { + if (qAbs(dy) > DragThreshold || pressTime.elapsed() > 200) { qreal newY = dy + pressY; const qreal minY = q->minYExtent(); const qreal maxY = q->maxYExtent(); @@ -615,14 +623,14 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) moved = true; } else if (!q->overShoot()) rejectY = true; - if (qAbs(dy) > FlickThreshold) + if (qAbs(dy) > DragThreshold) stealMouse = true; } } if (q->xflick()) { int dx = int(event->pos().x() - pressPos.x()); - if (qAbs(dx) > FlickThreshold || pressTime.elapsed() > 200) { + if (qAbs(dx) > DragThreshold || pressTime.elapsed() > 200) { qreal newX = dx + pressX; const qreal minX = q->minXExtent(); const qreal maxX = q->maxXExtent(); @@ -635,7 +643,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) moved = true; } else if (!q->overShoot()) rejectX = true; - if (qAbs(dx) > FlickThreshold) + if (qAbs(dx) > DragThreshold) stealMouse = true; } } @@ -666,7 +674,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) lastPos = event->pos(); } -void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *) +void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event) { Q_Q(QFxFlickable); pressed = false; @@ -674,12 +682,12 @@ void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *) return; vTime = timeline.time(); - if (qAbs(velocityY) > 10) + if (qAbs(velocityY) > 10 && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) flickY(velocityY); else fixupY(); - if (qAbs(velocityX) > 10) + if (qAbs(velocityX) > 10 && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold) flickX(velocityX); else fixupX(); @@ -1093,6 +1101,8 @@ bool QFxFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e) /*! \qmlproperty int Flickable::maximumFlickVelocity This property holds the maximum velocity that the user can flick the view in pixels/second. + + The default is 5000 pixels/s */ qreal QFxFlickable::maximumFlickVelocity() const { -- cgit v0.12 From df478cf9577c766a0a8d0bcb7b4da6c9c0be0171 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 11 Sep 2009 15:17:22 +1000 Subject: Ensure item moves are passed on literally so views can animate literally. --- src/declarative/util/qmllistmodel.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index 345bc3b..69bed25 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -499,6 +499,9 @@ void QmlListModel::move(int from, int to, int n) { if (from+n > count() || to+n > count() || n==0 || from==to || from < 0 || to < 0) return; + int origfrom=from; // preserve actual move, so any animations are correct + int origto=to; + int orign=n; if (from > to) { // Only move forwards - flip if backwards moving int tfrom = from; @@ -524,7 +527,7 @@ void QmlListModel::move(int from, int to, int n) for (; f != replaced.end(); ++f, ++t) *t = *f; } - emit itemsMoved(from,to,n); + emit itemsMoved(origfrom,origto,orign); } /*! -- cgit v0.12 From e4648700e7e3c84c61d6b012f7d480394b889c31 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 11 Sep 2009 15:48:20 +1000 Subject: Fix moving an item to the first visible position. Also fix the type of some properties/variables. --- src/declarative/fx/qfxlistview.cpp | 32 ++++++++++++++++---------------- src/declarative/fx/qfxlistview.h | 6 +++--- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 6596735..ac9b6ca 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -172,11 +172,11 @@ public: QFxListViewPrivate() : model(0), currentItem(0), tmpCurrent(0), orient(Qt::Vertical) , visiblePos(0), visibleIndex(0) - , averageSize(100), currentIndex(-1), requestedIndex(-1) + , averageSize(100.0), currentIndex(-1), requestedIndex(-1) , currItemMode(QFxListView::Free), snapPos(0), highlightComponent(0), highlight(0), trackedItem(0) - , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0) + , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0.0) , ownModel(false), wrap(false), autoHighlight(true) - , fixCurrentVisibility(false) {} + {} void init(); void clear(); @@ -205,7 +205,7 @@ public: else q->setViewportX(pos); } - int size() const { + qreal size() const { Q_Q(const QFxListView); return orient == Qt::Vertical ? q->height() : q->width(); } @@ -384,12 +384,11 @@ public: QmlEaseFollow *highlightSizeAnimator; QString sectionExpression; QString currentSection; - int spacing; + qreal spacing; - int ownModel : 1; - int wrap : 1; - int autoHighlight : 1; - int fixCurrentVisibility : 1; + bool ownModel : 1; + bool wrap : 1; + bool autoHighlight : 1; }; void QFxListViewPrivate::init() @@ -755,7 +754,6 @@ void QFxListViewPrivate::updateCurrent(int modelIndex) FxListItem *oldCurrentItem = currentItem; currentIndex = modelIndex; currentItem = createItem(modelIndex); - fixCurrentVisibility = true; if (oldCurrentItem && (!currentItem || oldCurrentItem->item != currentItem->item)) oldCurrentItem->attached->setIsCurrentItem(false); if (currentItem) { @@ -1149,13 +1147,13 @@ void QFxListView::setSnapPosition(int pos) This property holds the spacing to leave between items. */ -int QFxListView::spacing() const +qreal QFxListView::spacing() const { Q_D(const QFxListView); return d->spacing; } -void QFxListView::setSpacing(int spacing) +void QFxListView::setSpacing(qreal spacing) { Q_D(QFxListView); if (spacing != d->spacing) { @@ -1640,6 +1638,7 @@ void QFxListView::destroyRemoved() void QFxListView::itemsMoved(int from, int to, int count) { Q_D(QFxListView); + qreal firstItemPos = d->visibleItems.first()->position(); QHash moved; int moveBy = 0; @@ -1653,11 +1652,9 @@ void QFxListView::itemsMoved(int from, int to, int count) moveBy += item->size(); it = d->visibleItems.erase(it); } else { - if (item->index > from && item->index != -1) { - // move everything after the moved items. + // move everything after the moved items. + if (item->index > from && item->index != -1) item->index -= count; - item->setPosition(item->position()-moveBy); - } ++it; } } @@ -1698,6 +1695,9 @@ void QFxListView::itemsMoved(int from, int to, int count) while (moved.count()) d->releaseItem(moved.take(moved.begin().key())); + // Ensure we don't cause an ugly list scroll. + d->visibleItems.first()->setPosition(firstItemPos); + d->layout(); } diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index 4a124cb..095c27b 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -73,7 +73,7 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) //### highlightFollowsCurrentItem Q_PROPERTY(CurrentItemPositioning currentItemPositioning READ currentItemPositioning WRITE setCurrentItemPositioning) //### mode Q_PROPERTY(int snapPosition READ snapPosition WRITE setSnapPosition) - Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) //### qreal + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) Q_PROPERTY(bool wrap READ isWrapEnabled WRITE setWrapEnabled) //### keyNavigationWraps, stops at end when held Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) @@ -115,8 +115,8 @@ public: int snapPosition() const; void setSnapPosition(int pos); - int spacing() const; - void setSpacing(int spacing); + qreal spacing() const; + void setSpacing(qreal spacing); Qt::Orientation orientation() const; void setOrientation(Qt::Orientation); -- cgit v0.12 From 283ad006223cd4c178465397d25edc70362612ae Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 11 Sep 2009 15:48:45 +1000 Subject: Ensure text size changes when text is made empty, or elides to empty. Previously, old size would persist if text changed from non-"" to "". Elide text in example (tests and demonstrates) --- examples/declarative/listview/dynamic.qml | 4 ++-- src/declarative/fx/qfxtext.cpp | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml index dde24f6..52c3c0b 100644 --- a/examples/declarative/listview/dynamic.qml +++ b/examples/declarative/listview/dynamic.qml @@ -59,8 +59,8 @@ Item { id: FruitDelegate Item { width: parent.width; height: 55 - Text { id: Label; font.pixelSize: 24; text: name } - Text { font.pixelSize: 24; text: '$'+Number(cost).toFixed(2); anchors.right: ItemButtons.left } + Text { id: Label; font.pixelSize: 24; text: name; elide: "ElideRight"; anchors.right: Cost.left; anchors.left:parent.left } + Text { id: Cost; font.pixelSize: 24; text: '$'+Number(cost).toFixed(2); anchors.right: ItemButtons.left } Row { anchors.top: Label.bottom spacing: 5 diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp index c60aaf2..5b10289 100644 --- a/src/declarative/fx/qfxtext.cpp +++ b/src/declarative/fx/qfxtext.cpp @@ -466,9 +466,6 @@ void QFxTextPrivate::updateSize() { Q_Q(QFxText); if (q->isComponentComplete()) { - if (text.isEmpty()) { - return; - } QFontMetrics fm(font); int dy = q->height(); @@ -633,15 +630,17 @@ QPixmap QFxTextPrivate::wrappedTextImage(bool drawStyle) //paint text QPixmap img(size); - img.fill(Qt::transparent); - QPainter p(&img); - if (drawStyle) { - p.setPen(styleColor); + if (!size.isEmpty()) { + img.fill(Qt::transparent); + QPainter p(&img); + if (drawStyle) { + p.setPen(styleColor); + } + else + p.setPen(color); + p.setFont(font); + layout.draw(&p, QPointF(0, 0)); } - else - p.setPen(color); - p.setFont(font); - layout.draw(&p, QPointF(0, 0)); return img; } -- cgit v0.12 From efc7963a15c204db48cb3b6560366410b640e5c3 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 11 Sep 2009 15:54:19 +1000 Subject: Don't need to save and restore painter for tiling. --- src/declarative/fx/qfximage.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index 79b3ae1..3ac3f3c 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -252,17 +252,12 @@ void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) if (width() != d->pix.width() || height() != d->pix.height()) { if (d->fillMode >= Tile) { - p->save(); - p->setClipRect(0, 0, width(), height(), Qt::IntersectClip); - if (d->fillMode == Tile) p->drawTiledPixmap(QRectF(0,0,width(),height()), d->pix); else if (d->fillMode == TileVertically) p->drawTiledPixmap(QRectF(0,0,d->pix.width(),height()), d->pix); else p->drawTiledPixmap(QRectF(0,0,width(),d->pix.height()), d->pix); - - p->restore(); } else { qreal widthScale = width() / qreal(d->pix.width()); qreal heightScale = height() / qreal(d->pix.height()); -- cgit v0.12 From bc7e8e12e96ff523278032d7c32c9bd504456de3 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 11 Sep 2009 16:06:29 +1000 Subject: Fix that empty string "resolves" to empty URL. Fix typo. --- src/declarative/qml/qmlmetaproperty.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index affb93b..b305619 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -880,15 +880,14 @@ void QmlMetaPropertyPrivate::writeValueProperty(const QVariant &value) if (vt == QVariant::ByteArray) { u = QUrl(QLatin1String(value.toByteArray())); found = true; - } else if (QVariant::String) { + } else if (vt == QVariant::String) { u = QUrl(value.toString()); found = true; } - if (context && u.isRelative()) - u = context->baseUrl().resolved(u); - if (found) { + if (context && u.isRelative() && !u.isEmpty()) + u = context->baseUrl().resolved(u); void *a[1]; a[0] = &u; QMetaObject::metacall(object, -- cgit v0.12 From 788da2e8b85f3773a525a6f2bcc535fa38ed02b2 Mon Sep 17 00:00:00 2001 From: Nigel Hietala Date: Sat, 12 Sep 2009 22:29:30 +0300 Subject: Fixed UrlBar to not clip off top 3 pixels of the page --- demos/declarative/webbrowser/webbrowser.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index ae3d048..3f23d83 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -55,7 +55,7 @@ Item { id: Header source: "content/pics/header.png" width: parent.width - height: 64 + height: 60 state: "Normal" x: Flick.viewportX < 0 ? -Flick.viewportX : Flick.viewportX > Flick.viewportWidth-Flick.width ? -Flick.viewportX+Flick.viewportWidth-Flick.width : 0 -- cgit v0.12 From b42b3db9bc459ef26bfaefa924dab2e853373b0d Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 14 Sep 2009 11:36:47 +1000 Subject: Track QML API changes. --- tools/qmldebugger/engines.qml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/qmldebugger/engines.qml b/tools/qmldebugger/engines.qml index 1652ebd..1e9335b 100644 --- a/tools/qmldebugger/engines.qml +++ b/tools/qmldebugger/engines.qml @@ -9,16 +9,16 @@ Item { Row { anchors.fill: parent Repeater { - dataSource: engines + model: engines Item { width: 100; height: 100; Image { - id: Image; + id: EngineIcon; source: "qrc:/engine.png" anchors.horizontalCenter: parent.horizontalCenter } Text { - anchors.top: Image.bottom; + anchors.top: EngineIcon.bottom; text: modelData.name + "(" + modelData.engineId + ")" anchors.horizontalCenter: parent.horizontalCenter } -- cgit v0.12 From 3b9aed8d7ea23a435211264c1bec731a98678ea5 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 14 Sep 2009 13:53:28 +1000 Subject: Move XmlListModelRole to be properly private. --- src/declarative/extra/qmlxmllistmodel.cpp | 126 +++++++++++++++++++----------- src/declarative/extra/qmlxmllistmodel.h | 40 ++-------- 2 files changed, 86 insertions(+), 80 deletions(-) diff --git a/src/declarative/extra/qmlxmllistmodel.cpp b/src/declarative/extra/qmlxmllistmodel.cpp index 4b67074..01efa0e 100644 --- a/src/declarative/extra/qmlxmllistmodel.cpp +++ b/src/declarative/extra/qmlxmllistmodel.cpp @@ -58,20 +58,85 @@ QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,XmlRole,XmlListModelRole) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,XmlRole,QmlXmlListModelRole) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,XmlListModel,QmlXmlListModel) +/*! + \qmlclass XmlRole + \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: Delegate + 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) << "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 +struct QmlXmlRoleList : public QmlConcreteList { QmlXmlRoleList(QmlXmlListModelPrivate *p) : model(p) {} - virtual void append(XmlListModelRole *role); + 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, XmlListModelRole *role); + virtual void insert(int i, QmlXmlListModelRole *role); QmlXmlListModelPrivate *model; }; @@ -220,7 +285,7 @@ void QmlXmlQuery::doSubQueryJob() //### we might be able to condense even further (query for everything in one go) for (int i = 0; i < m_roleObjects->size(); ++i) { - XmlListModelRole *role = m_roleObjects->at(i); + QmlXmlListModelRole *role = m_roleObjects->at(i); if (!role->isValid()) { QList resultList; for (int j = 0; j < m_size; ++j) @@ -248,7 +313,7 @@ void QmlXmlQuery::doSubQueryJob() /*for (int j = 0; j < m_size; ++j) { QList resultList; for (int i = 0; i < m_roleObjects->size(); ++i) { - XmlListModelRole *role = m_roleObjects->at(i); + QmlXmlListModelRole *role = m_roleObjects->at(i); subquery.setQuery(m_prefix.arg(j+1) + role->query()); if (role->isStringList()) { QStringList data; @@ -274,10 +339,8 @@ void QmlXmlQuery::doSubQueryJob() } -//TODO: do something smart while waiting for data to load -// error handling (currently quite fragile) +//TODO: error handling (currently quite fragile) // profile doQuery and doSubquery -// some sort of loading indication while we wait for initial data load (status property similar to QWebImage?) // support complex/nested objects? // how do we handle data updates (like rss feed -- usually items inserted at beginning) @@ -310,64 +373,33 @@ public: }; -void QmlXmlRoleList::append(XmlListModelRole *role) { - QmlConcreteList::append(role); +void QmlXmlRoleList::append(QmlXmlListModelRole *role) { + QmlConcreteList::append(role); model->roles << model->highestRole; model->roleNames << role->name(); ++model->highestRole; } -/*! - \qmlclass XmlRole - \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: Delegate - 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 -*/ - //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(); + QmlConcreteList::clear(); } void QmlXmlRoleList::removeAt(int i) { model->roles.removeAt(i); model->roleNames.removeAt(i); - QmlConcreteList::removeAt(i); + QmlConcreteList::removeAt(i); } //### we should enforce unique role names -void QmlXmlRoleList::insert(int i, XmlListModelRole *role) +void QmlXmlRoleList::insert(int i, QmlXmlListModelRole *role) { - QmlConcreteList::insert(i, role); + QmlConcreteList::insert(i, role); model->roles.insert(i, model->highestRole); model->roleNames.insert(i, role->name()); ++model->highestRole; @@ -413,7 +445,7 @@ QmlXmlListModel::~QmlXmlListModel() The roles to make available for this model. */ -QmlList *QmlXmlListModel::roleObjects() +QmlList *QmlXmlListModel::roleObjects() { Q_D(QmlXmlListModel); return &d->roleObjects; diff --git a/src/declarative/extra/qmlxmllistmodel.h b/src/declarative/extra/qmlxmllistmodel.h index 5f7c831..1bcc008 100644 --- a/src/declarative/extra/qmlxmllistmodel.h +++ b/src/declarative/extra/qmlxmllistmodel.h @@ -53,37 +53,8 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QmlContext; -class Q_DECLARATIVE_EXPORT XmlListModelRole : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QString query READ query WRITE setQuery) -public: - XmlListModelRole() {} - ~XmlListModelRole() {} - - 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) << "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; -}; +class QmlXmlListModelRole; class QmlXmlListModelPrivate; class Q_DECLARATIVE_EXPORT QmlXmlListModel : public QListModelInterface, public QmlParserStatus @@ -98,7 +69,7 @@ class Q_DECLARATIVE_EXPORT QmlXmlListModel : public QListModelInterface, public 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(QmlList *roles READ roleObjects) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_CLASSINFO("DefaultProperty", "roles") @@ -111,7 +82,7 @@ public: virtual QList roles() const; virtual QString toString(int role) const; - QmlList *roleObjects(); + QmlList *roleObjects(); QUrl source() const; void setSource(const QUrl&); @@ -138,6 +109,10 @@ signals: 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: @@ -152,7 +127,6 @@ private: QT_END_NAMESPACE -QML_DECLARE_TYPE(XmlListModelRole) QML_DECLARE_TYPE(QmlXmlListModel) QT_END_HEADER -- cgit v0.12 From 9fa3695eb3b03a4d37bc3c75bdb3bf5c5205e48c Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 14 Sep 2009 14:09:39 +1000 Subject: Don't crash. The engine tree shouldn't have all these objects in it, but for now, just prevent crash when there are signals with parameters. --- src/declarative/qml/qmlenginedebug.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp index 321fe74..7f9e530 100644 --- a/src/declarative/qml/qmlenginedebug.cpp +++ b/src/declarative/qml/qmlenginedebug.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qmlenginedebug_p.h" +#include "qmlboundsignal_p.h" #include #include #include @@ -103,7 +104,11 @@ QmlEngineDebugServer::propertyData(QObject *obj, int propIdx) if (prop.type() < QVariant::UserType) { rv.type = QmlObjectProperty::Basic; - rv.value = prop.read(obj); + if (qobject_cast(obj) && prop.name() != QByteArray("objectName")) + // these "properties" only have meaning during signal emission + rv.value = tr("(signal parameter)"); + else + rv.value = prop.read(obj); } else if (QmlMetaType::isObject(prop.userType())) { rv.type = QmlObjectProperty::Object; } else if (QmlMetaType::isList(prop.userType()) || -- cgit v0.12 From 35cad893a9e92cf36794610a6a718f56b64f9018 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 15 Sep 2009 09:06:12 +1000 Subject: ListView currentItemMode API replaced with highlight range API. --- examples/declarative/focusscope/test3.qml | 4 +- examples/declarative/listview/itemlist.qml | 4 +- examples/declarative/listview/listview.qml | 43 +++--- examples/declarative/xmldata/yahoonews.qml | 1 - src/declarative/QmlChanges.txt | 4 + src/declarative/fx/qfxlistview.cpp | 219 +++++++++++++++-------------- src/declarative/fx/qfxlistview.h | 21 ++- 7 files changed, 156 insertions(+), 140 deletions(-) diff --git a/examples/declarative/focusscope/test3.qml b/examples/declarative/focusscope/test3.qml index 51fa35a..8a53c3a 100644 --- a/examples/declarative/focusscope/test3.qml +++ b/examples/declarative/focusscope/test3.qml @@ -39,7 +39,9 @@ Rectangle { focus: true model: Model delegate: VerticalDelegate - currentItemPositioning: "SnapAuto" + preferredHighlightBegin: 100 + preferredHighlightEnd: 101 + strictlyEnforceHighlightRange: true } diff --git a/examples/declarative/listview/itemlist.qml b/examples/declarative/listview/itemlist.qml index 061fab3..01781ec 100644 --- a/examples/declarative/listview/itemlist.qml +++ b/examples/declarative/listview/itemlist.qml @@ -29,7 +29,9 @@ Rectangle { anchors.fill: parent anchors.bottomMargin: 30 model: ItemModel - currentItemPositioning: "SnapAuto" + preferredHighlightBegin: 0 + preferredHighlightEnd: 1 + strictlyEnforceHighlightRange: true orientation: "Horizontal" } diff --git a/examples/declarative/listview/listview.qml b/examples/declarative/listview/listview.qml index 1cca5ad..ac1cef1 100644 --- a/examples/declarative/listview/listview.qml +++ b/examples/declarative/listview/listview.qml @@ -29,21 +29,24 @@ Rectangle { Rectangle { color: "#FFFF88" } } - // Show the model in three lists, with different currentItemPositioning. - // currentItemPositioning determines how the list behaves when the - // current item changes. Note that the second and third ListView + // Show the model in three lists, with different highlight ranges. + // preferredHighlightBegin and preferredHighlightEnd set the + // range in which to attempt to maintain the highlight. + // Note that the second and third ListView // set their currentIndex to be the same as the first, and that // the first ListView is given keyboard focus. - // The default mode, Free, allows the currentItem to move freely + // The default mode allows the currentItem to move freely // within the visible area. If it would move outside the visible // area, the view is scrolled to keep it visible. - // Snap currentItemPositioning attempts to keep the current item - // aligned with the snapPosition by scrolling the view, however the - // items will not scroll beyond the beginning or end of the view. - // SnapAuto currentItemPositioning always keeps the current item on - // the snapPosition by scrolling the view. It also automatically - // sets the current item as is scrolled with the mouse. Note - // that the first ListView sets its currentIndex to be equal to + // The second list sets a highlight range which attempts to keep the + // current item within the the bounds of the range, however + // items will not scroll beyond the beginning or end of the view, + // forcing the highlight to move outside the range at the ends. + // The third list sets strictlyEnforceHighlightRange to true + // and sets a range smaller than the height of an item. This + // forces the current item to change when the view is flicked, + // since the highlight is unable to move. + // Note that the first ListView sets its currentIndex to be equal to // the third ListView's currentIndex. By flicking List3 with // the mouse, the current index of List1 will be changed. ListView { @@ -57,23 +60,17 @@ Rectangle { id: List2 x: 200; width: 200; height: parent.height model: MyPetsModel; delegate: PetDelegate; highlight: PetHighlight - currentItemPositioning: "Snap"; snapPosition: 125 + preferredHighlightBegin: 80 + preferredHighlightEnd: 220 currentIndex: List1.currentIndex } ListView { id: List3 x: 400; width: 200; height: parent.height - model: MyPetsModel; delegate: PetDelegate - currentItemPositioning: "SnapAuto"; snapPosition: 125 + model: MyPetsModel; delegate: PetDelegate; highlight: PetHighlight currentIndex: List1.currentIndex - - // Position a static highlight rather than a normal highlight so that - // when the view is flicked, the highlight does not move. - // By positioning the highlight at the same position as the snapPosition - // the item under the highlight will always be the current item. - Rectangle { - y: 125; width: 200; height: 50 - color: "#FFFF88"; z: -1 - } + preferredHighlightBegin: 125 + preferredHighlightEnd: 126 + strictlyEnforceHighlightRange: true } } diff --git a/examples/declarative/xmldata/yahoonews.qml b/examples/declarative/xmldata/yahoonews.qml index 6395284..7ebc2b2 100644 --- a/examples/declarative/xmldata/yahoonews.qml +++ b/examples/declarative/xmldata/yahoonews.qml @@ -101,6 +101,5 @@ Rectangle { clip: true model: feedModel delegate: feedDelegate - currentItemPositioning: "Snap" } } diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index fe923a7..4afffd5 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -76,6 +76,8 @@ WebView: add newWindowComponent and newWindowParent properties Loader: add status() and progress() properties Loader: add sourceComponent property Loader: add resizeMode property +ListView: preferredHighlightBegin, preferredHighlightEnd +ListView: strictlyEnforceHighlightRange Deletions: Column/VerticalPositioner: lost "margins" property @@ -84,6 +86,8 @@ Grid/Positioner/Layout: lost "margins" property WebView: lost "interactive" property (always true now) Flickable: removed "dragMode" property ComponentInstance: removed. Replaced by Loader.sourceComponent +ListView: removed currentItemMode. Replaced by highligh range. +ListView: removed snapPos. Other Changes: Drag: axis becomes an enum with values "XAxis", "YAxis", "XandYAxis" diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index ac9b6ca..cd47448 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -173,9 +173,11 @@ public: : model(0), currentItem(0), tmpCurrent(0), orient(Qt::Vertical) , visiblePos(0), visibleIndex(0) , averageSize(100.0), currentIndex(-1), requestedIndex(-1) - , currItemMode(QFxListView::Free), snapPos(0), highlightComponent(0), highlight(0), trackedItem(0) + , highlightRangeStart(0), highlightRangeEnd(0) + , highlightComponent(0), highlight(0), trackedItem(0) , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0.0) , ownModel(false), wrap(false), autoHighlight(true) + , haveHighlightRange(false), strictHighlightRange(false) {} void init(); @@ -272,13 +274,16 @@ public: } int snapIndex() { - qreal pos = position(); + int index = currentIndex; for (int i = 0; i < visibleItems.count(); ++i) { - qreal itemTop = visibleItems[i]->position() - pos; - if (itemTop >= snapPos-averageSize/2 && itemTop < snapPos+averageSize/2) - return visibleItems[i]->index; + FxListItem *item = visibleItems[i]; + if (item->index == -1) + continue; + qreal itemTop = item->position(); + if (itemTop >= highlight->position()-item->size()/2 && itemTop < highlight->position()+item->size()/2) + return item->index; } - return -1; + return index; } int lastVisibleIndex() const { @@ -372,8 +377,8 @@ public: qreal averageSize; int currentIndex; int requestedIndex; - QFxListView::CurrentItemPositioning currItemMode; - int snapPos; + qreal highlightRangeStart; + qreal highlightRangeEnd; QmlComponent *highlightComponent; FxListItem *highlight; FxListItem *trackedItem; @@ -389,6 +394,8 @@ public: bool ownModel : 1; bool wrap : 1; bool autoHighlight : 1; + bool haveHighlightRange : 1; + bool strictHighlightRange : 1; }; void QFxListViewPrivate::init() @@ -681,7 +688,7 @@ void QFxListViewPrivate::updateHighlight() if ((!currentItem && highlight) || (currentItem && !highlight)) createHighlight(); updateTrackedItem(); - if (currentItem && autoHighlight && highlight) { + if (currentItem && autoHighlight && highlight && !pressed && moveReason != QFxListViewPrivate::Mouse) { // auto-update highlight highlightPosAnimator->setSourceValue(currentItem->position()); highlightSizeAnimator->setSourceValue(currentItem->size()); @@ -794,54 +801,30 @@ void QFxListViewPrivate::fixupPosition() void QFxListViewPrivate::fixupY() { - Q_Q(QFxListView); QFxFlickablePrivate::fixupY(); if (orient == Qt::Horizontal) return; - if (currItemMode == QFxListView::SnapAuto) { - if (currentItem) { + + if (haveHighlightRange && strictHighlightRange) { + if (currentItem && highlight && currentItem->position() != highlight->position()) { moveReason = Mouse; timeline.clear(); - timeline.move(_moveY, -(currentItem->position() - snapPos), QEasingCurve(QEasingCurve::InOutQuad), 200); - } - } else if (currItemMode == QFxListView::Snap) { - moveReason = Mouse; - int idx = snapIndex(); - if (FxListItem *snapItem = visibleItem(idx)) { - int pos = snapItem->position() - snapPos; - if (pos > -q->maxYExtent()) - pos = -q->maxYExtent(); - else if (pos < -q->minYExtent()) - pos = -q->minYExtent(); - timeline.clear(); - timeline.move(_moveY, -(pos), QEasingCurve(QEasingCurve::InOutQuad), 200); + timeline.move(_moveY, -(currentItem->position() - highlightRangeStart), QEasingCurve(QEasingCurve::InOutQuad), 200); } } } void QFxListViewPrivate::fixupX() { - Q_Q(QFxListView); QFxFlickablePrivate::fixupX(); if (orient == Qt::Vertical) return; - if (currItemMode == QFxListView::SnapAuto) { - if (currentItem) { + + if (haveHighlightRange && strictHighlightRange) { + if (currentItem && highlight && currentItem->position() != highlight->position()) { moveReason = Mouse; timeline.clear(); - timeline.move(_moveX, -(currentItem->position() - snapPos), QEasingCurve(QEasingCurve::InOutQuad), 200); - } - } else if (currItemMode == QFxListView::Snap) { - moveReason = Mouse; - int idx = snapIndex(); - if (FxListItem *snapItem = visibleItem(idx)) { - int pos = snapItem->position() - snapPos; - if (pos > -q->maxXExtent()) - pos = -q->maxXExtent(); - else if (pos < -q->minXExtent()) - pos = -q->minXExtent(); - timeline.clear(); - timeline.move(_moveX, -(pos), QEasingCurve(QEasingCurve::InOutQuad), 200); + timeline.move(_moveX, -(currentItem->position() - highlightRangeStart), QEasingCurve(QEasingCurve::InOutQuad), 200); } } } @@ -1067,7 +1050,7 @@ void QFxListView::setHighlight(QmlComponent *highlight) to follow the current item. If autoHighlight is false, the highlight will not be moved by the view, and must be implemented by the highlight. The following example creates a highlight with - its motion defined by the spring \l {Follow}: + its motion defined by the spring \l {SpringFollow}: \snippet doc/src/snippets/declarative/listview/highlight.qml 1 @@ -1091,55 +1074,58 @@ void QFxListView::setAutoHighlight(bool autoHighlight) } /*! - \qmlproperty enumeration ListView::currentItemPositioning - This property determines the current item positioning and selection characteristics. - - The modes supported are: - \list - \i Free - For Mouse, the current item may be positioned anywhere, - whether within the visible area, or outside. During Keyboard interaction, - the current item can move within the visible area, and the view will - scroll to keep the highlight visible. - \i Snap - For mouse, the current item may be positioned anywhere, - whether within the visible area, or outside. During keyboard interaction, - the current item will be kept in the visible area and will prefer to be - positioned at the \l snapPosition, however the view will never scroll - beyond the beginning or end of the view. - \i SnapAuto - For both mouse and keyboard, the current item will be - kept at the \l {snapPosition}. Additionally, if the view is dragged or - flicked, the current item will be automatically updated to be the item - currently at the snapPosition. - \endlist + \qmlproperty real preferredHighlightBegin + \qmlproperty real preferredHighlightEnd + \qmlproperty bool strictlyEnforceHighlightRange + + These properties set the preferred range of the highlight (current item) + within the view. + + If the strictlyEnforceHighlightRange property is false (default) + the highlight can move outside of the range at the ends of the list + or due to a mouse interaction. + + If strictlyEnforceHighlightRange is true then the highlight will never + move outside the range. This means that the current item will change + if a keyboard or mouse action would cause the highlight to move + outside of the range. */ -QFxListView::CurrentItemPositioning QFxListView::currentItemPositioning() const +qreal QFxListView::preferredHighlightBegin() const { Q_D(const QFxListView); - return d->currItemMode; + return d->highlightRangeStart; } -void QFxListView::setCurrentItemPositioning(CurrentItemPositioning mode) +void QFxListView::setPreferredHighlightBegin(qreal start) { Q_D(QFxListView); - d->currItemMode = mode; + d->highlightRangeStart = start; + d->haveHighlightRange = d->highlightRangeStart < d->highlightRangeEnd; } -/*! - \qmlproperty int ListView::snapPosition +qreal QFxListView::preferredHighlightEnd() const +{ + Q_D(const QFxListView); + return d->highlightRangeEnd; +} - When currentItemPositioning is set to Snap or SnapAuto, the - \c snapPosition determines where the top of the items will - snap to. -*/ -int QFxListView::snapPosition() const +void QFxListView::setPreferredHighlightEnd(qreal end) +{ + Q_D(QFxListView); + d->highlightRangeEnd = end; + d->haveHighlightRange = d->highlightRangeStart < d->highlightRangeEnd; +} + +bool QFxListView::strictlyEnforceHighlightRange() const { Q_D(const QFxListView); - return d->snapPos; + return d->strictHighlightRange; } -void QFxListView::setSnapPosition(int pos) +void QFxListView::setStrictlyEnforceHighlightRange(bool strict) { Q_D(QFxListView); - d->snapPos = pos; + d->strictHighlightRange = strict; } /*! @@ -1280,11 +1266,19 @@ void QFxListView::viewportMoved() refill(); if (isFlicking() || d->pressed) d->moveReason = QFxListViewPrivate::Mouse; - if (d->currItemMode == SnapAuto && d->moveReason == QFxListViewPrivate::Mouse) { - // Update current index - int idx = d->snapIndex(); - if (idx >= 0 && idx != d->currentIndex) - d->updateCurrent(idx); + if (d->moveReason == QFxListViewPrivate::Mouse) { + if (d->haveHighlightRange && d->strictHighlightRange && d->highlight) { + int idx = d->snapIndex(); + if (idx >= 0 && idx != d->currentIndex) + d->updateCurrent(idx); + + qreal pos = d->currentItem->position(); + if (pos > d->position() + d->highlightRangeEnd - d->highlight->size()) + pos = d->position() + d->highlightRangeEnd - d->highlight->size(); + if (pos < d->position() + d->highlightRangeStart) + pos = d->position() + d->highlightRangeStart; + d->highlight->setPosition(pos); + } } } @@ -1294,8 +1288,8 @@ qreal QFxListView::minYExtent() const if (d->orient == Qt::Horizontal) return QFxFlickable::minYExtent(); qreal extent = -d->startPosition(); - if (d->currItemMode == SnapAuto) - extent += d->snapPos; + if (d->haveHighlightRange && d->strictHighlightRange) + extent += d->highlightRangeStart; return extent; } @@ -1306,8 +1300,8 @@ qreal QFxListView::maxYExtent() const if (d->orient == Qt::Horizontal) return QFxFlickable::maxYExtent(); qreal extent; - if (d->currItemMode == SnapAuto) - extent = -(d->positionAt(count()-1) - d->snapPos); + if (d->haveHighlightRange && d->strictHighlightRange) + extent = -(d->endPosition() - d->highlightRangeEnd); else extent = -(d->endPosition() - height()); qreal minY = minYExtent(); @@ -1322,8 +1316,8 @@ qreal QFxListView::minXExtent() const if (d->orient == Qt::Vertical) return QFxFlickable::minXExtent(); qreal extent = -d->startPosition(); - if (d->currItemMode == SnapAuto) - extent += d->snapPos; + if (d->haveHighlightRange && d->strictHighlightRange) + extent += d->highlightRangeStart; return extent; } @@ -1334,8 +1328,8 @@ qreal QFxListView::maxXExtent() const if (d->orient == Qt::Vertical) return QFxFlickable::maxXExtent(); qreal extent; - if (d->currItemMode == SnapAuto) - extent = -(d->positionAt(count()-1) - d->snapPos); + if (d->haveHighlightRange && d->strictHighlightRange) + extent = -(d->endPosition() - d->highlightRangeEnd); else extent = -(d->endPosition() - width()); qreal minX = minXExtent(); @@ -1350,7 +1344,7 @@ void QFxListView::keyPressEvent(QKeyEvent *event) if (d->model && d->model->count() && d->interactive) { if ((d->orient == Qt::Horizontal && event->key() == Qt::Key_Left) || (d->orient == Qt::Vertical && event->key() == Qt::Key_Up)) { - if (currentIndex() > 0 || d->wrap) { + if (currentIndex() > 0 || (d->wrap && !event->isAutoRepeat())) { d->moveReason = QFxListViewPrivate::Key; int index = currentIndex()-1; d->updateCurrent(index >= 0 ? index : d->model->count()-1); @@ -1359,7 +1353,7 @@ void QFxListView::keyPressEvent(QKeyEvent *event) } } else if ((d->orient == Qt::Horizontal && event->key() == Qt::Key_Right) || (d->orient == Qt::Vertical && event->key() == Qt::Key_Down)) { - if (currentIndex() < d->model->count() - 1 || d->wrap) { + if (currentIndex() < d->model->count() - 1 || (d->wrap && !event->isAutoRepeat())) { d->moveReason = QFxListViewPrivate::Key; int index = currentIndex()+1; d->updateCurrent(index < d->model->count() ? index : 0); @@ -1395,30 +1389,41 @@ void QFxListView::trackedPositionChanged() if (!d->trackedItem) return; if (!isFlicking() && !d->pressed && d->moveReason != QFxListViewPrivate::Mouse) { - switch (d->currItemMode) { - case Free: - if (d->trackedItem->position() < d->position()) { - d->setPosition(d->trackedItem->position()); + const qreal trackedPos = d->trackedItem->position(); + if (d->haveHighlightRange) { + if (d->strictHighlightRange) { + qreal pos = d->position(); + if (trackedPos > pos + d->highlightRangeEnd - d->trackedItem->size()) + pos = trackedPos - d->highlightRangeEnd + d->trackedItem->size(); + if (trackedPos < pos + d->highlightRangeStart) + pos = trackedPos - d->highlightRangeStart; + d->setPosition(pos); + } else { + qreal pos = d->position(); + if (trackedPos < d->startPosition() + d->highlightRangeStart) { + pos = d->startPosition(); + } else if (d->trackedItem->endPosition() > d->endPosition() - d->size() + d->highlightRangeEnd) { + pos = d->endPosition() - d->size(); + } else { + if (trackedPos < d->position() + d->highlightRangeStart) { + pos = trackedPos - d->highlightRangeStart; + } else if (trackedPos > d->position() + d->highlightRangeEnd - d->trackedItem->size()) { + pos = trackedPos - d->highlightRangeEnd + d->trackedItem->size(); + } + } + d->setPosition(pos); + } + } else { + if (trackedPos < d->position()) { + d->setPosition(trackedPos); d->fixupPosition(); } else if (d->trackedItem->endPosition() > d->position() + d->size()) { qreal pos = d->trackedItem->endPosition() - d->size(); if (d->trackedItem->size() > d->size()) - pos = d->trackedItem->position(); + pos = trackedPos; d->setPosition(pos); d->fixupPosition(); } - break; - case Snap: - if (d->trackedItem->position() < d->startPosition() + d->snapPos) - d->setPosition(d->startPosition()); - else if (d->trackedItem->endPosition() > d->endPosition() - d->size() + d->snapPos + d->trackedItem->size()) - d->setPosition(d->endPosition() - d->size()); - else - d->setPosition(d->trackedItem->position() - d->snapPos); - break; - case SnapAuto: - d->setPosition(d->trackedItem->position() - d->snapPos); - break; } } } diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index 095c27b..b122a8a 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -71,8 +71,11 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) //### highlightFollowsCurrentItem - Q_PROPERTY(CurrentItemPositioning currentItemPositioning READ currentItemPositioning WRITE setCurrentItemPositioning) //### mode - Q_PROPERTY(int snapPosition READ snapPosition WRITE setSnapPosition) + + Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin) + Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd) + Q_PROPERTY(bool strictlyEnforceHighlightRange READ strictlyEnforceHighlightRange WRITE setStrictlyEnforceHighlightRange) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) Q_PROPERTY(bool wrap READ isWrapEnabled WRITE setWrapEnabled) //### keyNavigationWraps, stops at end when held @@ -103,11 +106,6 @@ public: bool autoHighlight() const; void setAutoHighlight(bool); - //### QSpan preferredHighlightRange - //### bool strictlyEnforceHighlightRange - - //### don't jump around unnecessarily - //### fix highlight for snapAuto enum CurrentItemPositioning { Free, Snap, SnapAuto }; CurrentItemPositioning currentItemPositioning() const; void setCurrentItemPositioning(CurrentItemPositioning mode); @@ -115,6 +113,15 @@ public: int snapPosition() const; void setSnapPosition(int pos); + bool strictlyEnforceHighlightRange() const; + void setStrictlyEnforceHighlightRange(bool strict); + + qreal preferredHighlightBegin() const; + void setPreferredHighlightBegin(qreal); + + qreal preferredHighlightEnd() const; + void setPreferredHighlightEnd(qreal); + qreal spacing() const; void setSpacing(qreal spacing); -- cgit v0.12 From fb8d3d1b325ecbe947f0cc8001f92d01a849f323 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 15 Sep 2009 09:32:48 +1000 Subject: More ListView API changes. ListView: wrap -> keyNavigationWraps ListView: autoHighlight -> highlightFollowsCurrentItem --- .../snippets/declarative/listview/highlight.qml | 10 +++++----- src/declarative/QmlChanges.txt | 2 ++ src/declarative/fx/qfxlistview.cpp | 22 ++++++++++++---------- src/declarative/fx/qfxlistview.h | 16 ++++------------ 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/doc/src/snippets/declarative/listview/highlight.qml b/doc/src/snippets/declarative/listview/highlight.qml index 29f41bf..97eac45 100644 --- a/doc/src/snippets/declarative/listview/highlight.qml +++ b/doc/src/snippets/declarative/listview/highlight.qml @@ -15,7 +15,7 @@ Rectangle { Item { id: Wrapper width: 180; height: 40 - VerticalLayout { + Column { x: 5; y: 5 Text { text: 'Name: ' + name } Text { text: 'Number: ' + number } @@ -32,10 +32,10 @@ Rectangle { Rectangle { width: 180; height: 40 color: "lightsteelblue"; radius: 5 - y: Follow { - source: List.current.y + y: SpringFollow { + source: List.currentItem.y spring: 3 - damping: 0.1 + damping: 0.2 } } } @@ -44,7 +44,7 @@ Rectangle { width: parent.height; height: parent.height model: ContactModel; delegate: Delegate highlight: Highlight - autoHighlight: false + highlightFollowsCurrentItem: false focus: true } //! [1] diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 4afffd5..25af3b1 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -66,6 +66,8 @@ Repeater: component -> delegate Repeater: dataSource -> model ListView: current -> currentItem GridView: current -> currentItem +ListView: wrap -> keyNavigationWraps +ListView: autoHighlight -> highlightFollowsCurrentItem Additions: MouseRegion: add "acceptedButtons" property diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index cd47448..6fa1172 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -443,7 +443,7 @@ FxListItem *QFxListViewPrivate::createItem(int modelIndex) } // complete model->completeItem(); - listItem->item->setZValue(modelIndex + 1); + listItem->item->setZValue(1); listItem->item->setParent(q->viewport()); if (orient == Qt::Vertical) QObject::connect(listItem->item, SIGNAL(heightChanged()), q, SLOT(itemResized())); @@ -664,6 +664,7 @@ void QFxListViewPrivate::createHighlight() item->setParent(q->viewport()); } if (item) { + item->setZValue(0); highlight = new FxListItem(item, q); if (orient == Qt::Vertical) highlight->item->setHeight(currentItem->item->height()); @@ -1018,7 +1019,8 @@ int QFxListView::count() const An instance of the highlight component will be created for each list. The geometry of the resultant component instance will be managed by the list - so as to stay with the current item, unless the autoHighlight property is false. + so as to stay with the current item, unless the highlightFollowsCurrentItem + property is false. The below example demonstrates how to make a simple highlight for a vertical list. @@ -1026,7 +1028,7 @@ int QFxListView::count() const \snippet doc/src/snippets/declarative/listview/listview.qml 1 \image trivialListView.png - \sa autoHighlight + \sa highlightFollowsCurrentItem */ QmlComponent *QFxListView::highlight() const { @@ -1043,11 +1045,11 @@ void QFxListView::setHighlight(QmlComponent *highlight) } /*! - \qmlproperty bool ListView::autoHighlight + \qmlproperty bool ListView::highlightFollowsCurrentItem This property holds whether the highlight is managed by the view. - If autoHighlight is true, the highlight will be moved smoothly - to follow the current item. If autoHighlight is false, the + If highlightFollowsCurrentItem is true, the highlight will be moved smoothly + to follow the current item. If highlightFollowsCurrentItem is false, the highlight will not be moved by the view, and must be implemented by the highlight. The following example creates a highlight with its motion defined by the spring \l {SpringFollow}: @@ -1056,13 +1058,13 @@ void QFxListView::setHighlight(QmlComponent *highlight) \sa highlight */ -bool QFxListView::autoHighlight() const +bool QFxListView::highlightFollowsCurrentItem() const { Q_D(const QFxListView); return d->autoHighlight; } -void QFxListView::setAutoHighlight(bool autoHighlight) +void QFxListView::setHighlightFollowsCurrentItem(bool autoHighlight) { Q_D(QFxListView); d->autoHighlight = autoHighlight; @@ -1182,11 +1184,11 @@ void QFxListView::setOrientation(Qt::Orientation orientation) } /*! - \qmlproperty bool ListView::wrap + \qmlproperty bool ListView::keyNavigationWraps This property holds whether the list wraps key navigation If this property is true then key presses to move off of one end of the list will cause the - selection to jump to the other side. + current item to jump to the other end. */ bool QFxListView::isWrapEnabled() const { diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index b122a8a..1e63272 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -50,7 +50,6 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -//### get rid of z = index and set known z-value (1 for items, 0 for highlight) //### incrementCurrentIndex(), decrementCurrentIndex() slots //### default Keys.OnUp/DownPressed handler @@ -70,7 +69,7 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_PROPERTY(QFxItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) - Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) //### highlightFollowsCurrentItem + Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin) Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd) @@ -78,7 +77,7 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) - Q_PROPERTY(bool wrap READ isWrapEnabled WRITE setWrapEnabled) //### keyNavigationWraps, stops at end when held + Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) Q_PROPERTY(QString sectionExpression READ sectionExpression WRITE setSectionExpression NOTIFY sectionExpressionChanged) Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged) @@ -103,15 +102,8 @@ public: QmlComponent *highlight() const; void setHighlight(QmlComponent *highlight); - bool autoHighlight() const; - void setAutoHighlight(bool); - - enum CurrentItemPositioning { Free, Snap, SnapAuto }; - CurrentItemPositioning currentItemPositioning() const; - void setCurrentItemPositioning(CurrentItemPositioning mode); - - int snapPosition() const; - void setSnapPosition(int pos); + bool highlightFollowsCurrentItem() const; + void setHighlightFollowsCurrentItem(bool); bool strictlyEnforceHighlightRange() const; void setStrictlyEnforceHighlightRange(bool strict); -- cgit v0.12 From df394cd24e65dcfa929074b794878081a42659c7 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 15 Sep 2009 09:55:30 +1000 Subject: GridView API changes GridView: wrap -> keyNavigationWraps GridView: autoHighlight -> highlightFollowsCurrentItem --- src/declarative/QmlChanges.txt | 2 ++ src/declarative/fx/qfxgridview.cpp | 20 ++++++++++---------- src/declarative/fx/qfxgridview.h | 8 ++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 25af3b1..7661e03 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -68,6 +68,8 @@ ListView: current -> currentItem GridView: current -> currentItem ListView: wrap -> keyNavigationWraps ListView: autoHighlight -> highlightFollowsCurrentItem +GridView: wrap -> keyNavigationWraps +GridView: autoHighlight -> highlightFollowsCurrentItem Additions: MouseRegion: add "acceptedButtons" property diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index d4cf691..1095dc1 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -846,12 +846,12 @@ int QFxGridView::count() const An instance of the highlight component will be created for each view. The geometry of the resultant component instance will be managed by the view - so as to stay with the current item, unless the autoHighlight property is false. + so as to stay with the current item, unless the highlightFollowsCurrentItem property is false. The below example demonstrates how to make a simple highlight: \snippet doc/src/snippets/declarative/gridview/gridview.qml 1 - \sa autoHighlight + \sa highlightFollowsCurrentItem */ QmlComponent *QFxGridView::highlight() const { @@ -868,11 +868,11 @@ void QFxGridView::setHighlight(QmlComponent *highlight) } /*! - \qmlproperty component GridView::autoHighlight + \qmlproperty bool GridView::highlightFollowsCurrentItem This property sets whether the highlight is managed by the view. - If autoHighlight is true, the highlight will be moved smoothly - to follow the current item. If autoHighlight is false, the + If highlightFollowsCurrentItem is true, the highlight will be moved smoothly + to follow the current item. If highlightFollowsCurrentItem is false, the highlight will not be moved by the view, and must be implemented by the highlight component, for example: @@ -881,19 +881,19 @@ void QFxGridView::setHighlight(QmlComponent *highlight) id: Highlight Rectangle { id: Wrapper; color: "lightsteelblue"; radius: 4; width: 320; height: 60 > - y: Follow { source: Wrapper.GridView.view.current.y; spring: 3; damping: 0.2 } - x: Follow { source: Wrapper.GridView.view.current.x; spring: 3; damping: 0.2 } + y: SpringFollow { source: Wrapper.GridView.view.currentItem.y; spring: 3; damping: 0.2 } + x: SpringFollow { source: Wrapper.GridView.view.currentItem.x; spring: 3; damping: 0.2 } } } \endcode */ -bool QFxGridView::autoHighlight() const +bool QFxGridView::highlightFollowsCurrentItem() const { Q_D(const QFxGridView); return d->autoHighlight; } -void QFxGridView::setAutoHighlight(bool autoHighlight) +void QFxGridView::setHighlightFollowsCurrentItem(bool autoHighlight) { Q_D(QFxGridView); d->autoHighlight = autoHighlight; @@ -936,7 +936,7 @@ void QFxGridView::setFlow(Flow flow) } /*! - \qmlproperty bool GridView::wrap + \qmlproperty bool GridView::keyNavigationWraps This property holds whether the grid wraps key navigation If this property is true then key presses to move off of one end of the grid will cause the diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h index e08ba9e..240ed08 100644 --- a/src/declarative/fx/qfxgridview.h +++ b/src/declarative/fx/qfxgridview.h @@ -63,9 +63,9 @@ class Q_DECLARATIVE_EXPORT QFxGridView : public QFxFlickable Q_PROPERTY(QFxItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) - Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) + Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) Q_PROPERTY(Flow flow READ flow WRITE setFlow) - Q_PROPERTY(bool wrap READ isWrapEnabled WRITE setWrapEnabled) + Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellSizeChanged) //### columnCount, rowCount Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellSizeChanged) @@ -90,8 +90,8 @@ public: QmlComponent *highlight() const; void setHighlight(QmlComponent *highlight); - bool autoHighlight() const; - void setAutoHighlight(bool); + bool highlightFollowsCurrentItem() const; + void setHighlightFollowsCurrentItem(bool); Q_ENUMS(Flow) enum Flow { LeftToRight, TopToBottom }; -- cgit v0.12 From 135e56a632fd6193534828901959165aa68c353d Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 15 Sep 2009 10:21:31 +1000 Subject: Give a useful error if the delegate doesn't return a QFxItem. --- src/declarative/fx/qfxvisualitemmodel.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxvisualitemmodel.cpp b/src/declarative/fx/qfxvisualitemmodel.cpp index 30879a2..81fbafa 100644 --- a/src/declarative/fx/qfxvisualitemmodel.cpp +++ b/src/declarative/fx/qfxvisualitemmodel.cpp @@ -50,6 +50,7 @@ #include "private/qmetaobjectbuilder_p.h" #include "qmlopenmetaobject.h" #include "qmllistaccessor.h" +#include "qmlinfo.h" #include "qfxvisualitemmodel.h" #include "private/qguard_p.h" #include @@ -750,9 +751,14 @@ QFxItem *QFxVisualDataModel::item(int index, const QByteArray &viewId, bool comp if (package) { QObject *o = package->part(QLatin1String(viewId)); item = qobject_cast(o); - d->m_packaged.insertMulti(item, package); + if (item) + d->m_packaged.insertMulti(item, package); } } + if (!item) { + d->m_cache.releaseItem(nobj); + qmlInfo(d->m_delegate) << "Delegate component must be Item type."; + } return item; } -- cgit v0.12 From f918c8c60369154f45008a0e7e3af3bf5121abd5 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 15 Sep 2009 10:21:59 +1000 Subject: Remove some unneeded comments. --- src/declarative/fx/qfxgridview.h | 2 +- src/declarative/fx/qfxlistview.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h index 240ed08..996141f 100644 --- a/src/declarative/fx/qfxgridview.h +++ b/src/declarative/fx/qfxgridview.h @@ -67,7 +67,7 @@ class Q_DECLARATIVE_EXPORT QFxGridView : public QFxFlickable Q_PROPERTY(Flow flow READ flow WRITE setFlow) Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) - Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellSizeChanged) //### columnCount, rowCount + Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellSizeChanged) Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellSizeChanged) Q_CLASSINFO("DefaultProperty", "data") diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index 1e63272..e5c3138 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -64,7 +64,7 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_ENUMS(CurrentItemPositioning) Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) //### what happens if delegate is not a QFxItem? + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(QFxItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) -- cgit v0.12 From 7c6bc5a25d11a9d455b5bf96cb5229f78790db3a Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 15 Sep 2009 16:09:35 +1000 Subject: Fix docs. --- src/declarative/fx/qfxlistview.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 6fa1172..168e4c4 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -1076,9 +1076,9 @@ void QFxListView::setHighlightFollowsCurrentItem(bool autoHighlight) } /*! - \qmlproperty real preferredHighlightBegin - \qmlproperty real preferredHighlightEnd - \qmlproperty bool strictlyEnforceHighlightRange + \qmlproperty real ListView::preferredHighlightBegin + \qmlproperty real ListView::preferredHighlightEnd + \qmlproperty bool ListView::strictlyEnforceHighlightRange These properties set the preferred range of the highlight (current item) within the view. -- cgit v0.12