From 564baee7e729f1c6f766cecabc4fcc62291e0d0f Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 4 Mar 2010 11:06:04 +1000 Subject: Removed unused variable --- src/declarative/graphicsitems/qdeclarativeflickable.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 2fdd720..63c97e0 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -154,7 +154,6 @@ void QDeclarativeFlickablePrivate::init() */ qreal QDeclarativeFlickablePrivate::overShootDistance(qreal velocity, qreal size) { - Q_Q(QDeclarativeFlickable); if (maxVelocity <= 0) return 0.0; -- cgit v0.12 From cd2afafbc9c29393a80d415145c49eb5f439da55 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Fri, 26 Feb 2010 16:57:38 +0100 Subject: Delay the resize section for better performance. This was particularly unusable when combining a QSortFilterProxyModel with resize mode ResizeToContents. Task-number: QTBUG-8540 Reviewed-by: Thierry --- src/gui/itemviews/qheaderview.cpp | 4 ++-- src/gui/itemviews/qtableview.cpp | 7 +------ src/gui/itemviews/qtreeview.cpp | 6 ++---- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/gui/itemviews/qheaderview.cpp b/src/gui/itemviews/qheaderview.cpp index 5128b64..eb3db21 100644 --- a/src/gui/itemviews/qheaderview.cpp +++ b/src/gui/itemviews/qheaderview.cpp @@ -2037,7 +2037,7 @@ bool QHeaderView::event(QEvent *e) updateSection(d->hover); } break; } - case QEvent::Timer: { // ### reimplement timerEvent() instead ? + case QEvent::Timer: { QTimerEvent *te = static_cast(e); if (te->timerId() == d->delayedResize.timerId()) { d->delayedResize.stop(); @@ -2610,7 +2610,7 @@ void QHeaderView::updateGeometries() Q_D(QHeaderView); d->layoutChildren(); if (d->hasAutoResizeSections()) - resizeSections(); + d->doDelayedResizeSections(); } /*! diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp index 3111896..bdc1205 100644 --- a/src/gui/itemviews/qtableview.cpp +++ b/src/gui/itemviews/qtableview.cpp @@ -1960,12 +1960,7 @@ QModelIndexList QTableView::selectedIndexes() const void QTableView::rowCountChanged(int /*oldCount*/, int /*newCount*/ ) { Q_D(QTableView); - updateGeometries(); - if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) - d->verticalHeader->setOffsetToSectionPosition(verticalScrollBar()->value()); - else - d->verticalHeader->setOffset(verticalScrollBar()->value()); - d->viewport->update(); + d->doDelayedItemsLayout(); } /*! diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index 37168eb..1145235 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -2524,8 +2524,7 @@ void QTreeView::rowsInserted(const QModelIndex &parent, int start, int end) d->viewItems[parentItem].hasChildren = true; d->updateChildCount(parentItem, delta); - updateGeometries(); - viewport()->update(); + d->doDelayedItemsLayout(); } else if ((parentItem != -1) && d->viewItems.at(parentItem).expanded) { d->doDelayedItemsLayout(); } else if (parentItem != -1 && (d->model->rowCount(parent) == end - start + 1)) { @@ -3780,8 +3779,7 @@ void QTreeViewPrivate::rowsRemoved(const QModelIndex &parent, } } if (after) { - q->updateGeometries(); - viewport->update(); + doDelayedItemsLayout(); } else { //we have removed items: we should at least update the scroll bar values. // They are used to determine the item geometry. -- cgit v0.12 From ed1f672efb19932fe279a3ebfedb973c02c4fee4 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Thu, 4 Mar 2010 13:03:51 +0100 Subject: Fix build on EGL implementations where EGLConfig is a pointer EGLConfig is an opaque type which we really shouldn't cast to an int. Instead, we get the config id for the EGLConfig. Reviewed-By: TrustMe --- src/gui/egl/qegl_x11.cpp | 19 +++++++++++-------- src/opengl/qgl_x11egl.cpp | 5 ++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/gui/egl/qegl_x11.cpp b/src/gui/egl/qegl_x11.cpp index 339bd57..483c01d 100644 --- a/src/gui/egl/qegl_x11.cpp +++ b/src/gui/egl/qegl_x11.cpp @@ -149,6 +149,9 @@ VisualID QEgl::getCompatibleVisualId(EGLConfig config) eglGetConfigAttrib(display(), config, EGL_BUFFER_SIZE, &eglValue); int configBitDepth = eglValue; + eglGetConfigAttrib(display(), config, EGL_CONFIG_ID, &eglValue); + int configId = eglValue; + // See if EGL provided a valid VisualID: eglGetConfigAttrib(display(), config, EGL_NATIVE_VISUAL_ID, &eglValue); visualId = (VisualID)eglValue; @@ -170,14 +173,14 @@ VisualID QEgl::getCompatibleVisualId(EGLConfig config) format = XRenderFindVisualFormat(X11->display, chosenVisualInfo->visual); if (!format || (format->type != PictTypeDirect) || (!format->direct.alphaMask)) { qWarning("Warning: EGL suggested using X visual ID %d for config %d, but this is not ARGB", - (int)visualId, (int)config); + (int)visualId, configId); visualId = 0; } } #endif } else { qWarning("Warning: EGL suggested using X visual ID %d (%d bpp) for config %d (%d bpp), but the depths do not match!", - (int)visualId, chosenVisualInfo->depth, (int)config, configBitDepth); + (int)visualId, chosenVisualInfo->depth, configId, configBitDepth); visualId = 0; } } @@ -187,9 +190,9 @@ VisualID QEgl::getCompatibleVisualId(EGLConfig config) if (visualId) { #ifdef QT_DEBUG_X11_VISUAL_SELECTION if (configAlphaSize > 0) - qDebug("Using ARGB Visual ID %d provided by EGL for config %d", (int)visualId, (int)config); + qDebug("Using ARGB Visual ID %d provided by EGL for config %d", (int)visualId, configId); else - qDebug("Using Opaque Visual ID %d provided by EGL for config %d", (int)visualId, (int)config); + qDebug("Using Opaque Visual ID %d provided by EGL for config %d", (int)visualId, configId); #endif return visualId; } @@ -232,9 +235,9 @@ VisualID QEgl::getCompatibleVisualId(EGLConfig config) if (visualId) { # ifdef QT_DEBUG_X11_VISUAL_SELECTION if (configAlphaSize > 0) - qDebug("Using ARGB Visual ID %d provided by XRender for EGL config %d", (int)visualId, (int)config); + qDebug("Using ARGB Visual ID %d provided by XRender for EGL config %d", (int)visualId, configId); else - qDebug("Using Opaque Visual ID %d provided by XRender for EGL config %d", (int)visualId, (int)config); + qDebug("Using Opaque Visual ID %d provided by XRender for EGL config %d", (int)visualId, configId); # endif // QT_DEBUG_X11_VISUAL_SELECTION return visualId; } @@ -263,12 +266,12 @@ VisualID QEgl::getCompatibleVisualId(EGLConfig config) if (visualId) { #ifdef QT_DEBUG_X11_VISUAL_SELECTION - qDebug("Using Visual ID %d provided by XGetVisualInfo for EGL config %d", (int)visualId, (int)config); + qDebug("Using Visual ID %d provided by XGetVisualInfo for EGL config %d", (int)visualId, configId); #endif return visualId; } - qWarning("Unable to find an X11 visual which matches EGL config %d", (int)config); + qWarning("Unable to find an X11 visual which matches EGL config %d", configId); return (VisualID)0; } diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp index ba05e72..123bbdd 100644 --- a/src/opengl/qgl_x11egl.cpp +++ b/src/opengl/qgl_x11egl.cpp @@ -404,7 +404,7 @@ EGLConfig Q_OPENGL_EXPORT qt_chooseEGLConfigForPixmap(bool hasAlpha, bool readOn if (configCount > 0) { // Got one qDebug() << "Found an" << (hasAlpha ? "ARGB" : "RGB") << (readOnly ? "readonly" : "target" ) - << "config (" << int(*targetConfig) << ") to create a pixmap surface:"; + << "config to create a pixmap surface:"; // QEglProperties configProps(*targetConfig); // qDebug() << configProps.toString(); @@ -446,8 +446,7 @@ bool Q_OPENGL_EXPORT qt_createEGLSurfaceForPixmap(QPixmapData* pmd, bool readOnl // qDebug("qt_createEGLSurfaceForPixmap() created surface 0x%x for pixmap 0x%x", // pixmapSurface, pixmapData->handle()); if (pixmapSurface == EGL_NO_SURFACE) { - qWarning() << "Failed to create a pixmap surface using config" << (int)pixmapConfig - << ":" << QEgl::errorString(); + qWarning() << "Failed to create a pixmap surface:" << QEgl::errorString(); return false; } -- cgit v0.12 From c5264c89b7710dc2f2d8c7c604f0b23852cb2eef Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Thu, 4 Mar 2010 13:08:32 +0100 Subject: Fix build when egl.h includes X11 headers & pollutes namespace At some point we should fix the include order in all the .cpp files, however #udef'ing the defines we use elsewhere seems to work for now. Reviewed-By: TrustMe --- src/gui/egl/qegl_p.h | 2 ++ src/opengl/qgl_p.h | 8 +------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/gui/egl/qegl_p.h b/src/gui/egl/qegl_p.h index aa89772..ffb45aa 100644 --- a/src/gui/egl/qegl_p.h +++ b/src/gui/egl/qegl_p.h @@ -77,6 +77,8 @@ QT_BEGIN_INCLUDE_NAMESPACE #undef Type #undef FontChange #undef CursorShape +#undef Unsorted +#undef GrayScale #endif // Internally we use the EGL-prefixed native types which are used in EGL >= 1.3. diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index b828bea..c142715 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -65,13 +65,7 @@ #include "qglpaintdevice_p.h" #ifdef QT_OPENGL_ES -QT_BEGIN_INCLUDE_NAMESPACE -#if defined(QT_OPENGL_ES_2) -#include -#else -#include -#endif -QT_END_INCLUDE_NAMESPACE +#include #endif QT_BEGIN_NAMESPACE -- cgit v0.12 From 4984b36c73fb59006a28051ea82bdca0b7aeb457 Mon Sep 17 00:00:00 2001 From: John Layt Date: Tue, 16 Feb 2010 01:13:13 +0000 Subject: QPrinter: Add Current Page print range support Support the selection of Current Page option in the print dialog by activating a new QPrintDialog::PrintDialogOption. If selected the PrintRange is set to CurrentPage. It is the responsibility of the application to read the PrintRange and apply the Current Page selection when rendering the pages. Merge-request: 2311 Reviewed-by: Trond --- src/gui/dialogs/qabstractprintdialog.cpp | 7 +- src/gui/dialogs/qabstractprintdialog.h | 6 +- src/gui/dialogs/qprintdialog_qws.cpp | 11 ++ src/gui/dialogs/qprintdialog_unix.cpp | 11 +- src/gui/dialogs/qprintdialog_win.cpp | 16 +- src/gui/dialogs/qprintsettingsoutput.ui | 246 +++++++++++++++---------------- src/gui/painting/qprinter.cpp | 3 + src/gui/painting/qprinter.h | 2 +- tests/auto/qprinter/tst_qprinter.cpp | 23 +++ 9 files changed, 186 insertions(+), 139 deletions(-) diff --git a/src/gui/dialogs/qabstractprintdialog.cpp b/src/gui/dialogs/qabstractprintdialog.cpp index 4523433..25d9ebb 100644 --- a/src/gui/dialogs/qabstractprintdialog.cpp +++ b/src/gui/dialogs/qabstractprintdialog.cpp @@ -76,6 +76,7 @@ class QPrintDialogPrivate : public QAbstractPrintDialogPrivate \value AllPages All pages should be printed. \value Selection Only the selection should be printed. \value PageRange The specified page range should be printed. + \value CurrentPage Only the currently visible page should be printed. \sa QPrinter::PrintRange */ @@ -89,7 +90,9 @@ class QPrintDialogPrivate : public QAbstractPrintDialogPrivate \value PrintToFile The print to file option is enabled. \value PrintSelection The print selection option is enabled. \value PrintPageRange The page range selection option is enabled. - \value PrintCollateCopies + \value PrintShowPageSize Show the page size + margins page only if this is enabled. + \value PrintCollateCopies The collate copies option is enabled + \value PrintCurrentPage The print current page option is enabled This value is obsolete and does nothing since Qt 4.5: @@ -97,8 +100,6 @@ class QPrintDialogPrivate : public QAbstractPrintDialogPrivate would create a sheet by default the dialog was given a parent. This is no longer supported in Qt 4.5. If you want to use sheets, use QPrintDialog::open() instead. - - \value PrintShowPageSize Show the page size + margins page only if this is enabled. */ /*! diff --git a/src/gui/dialogs/qabstractprintdialog.h b/src/gui/dialogs/qabstractprintdialog.h index 4d867f6..82e3df8 100644 --- a/src/gui/dialogs/qabstractprintdialog.h +++ b/src/gui/dialogs/qabstractprintdialog.h @@ -65,7 +65,8 @@ public: enum PrintRange { AllPages, Selection, - PageRange + PageRange, + CurrentPage }; enum PrintDialogOption { @@ -75,7 +76,8 @@ public: PrintPageRange = 0x0004, PrintShowPageSize = 0x0008, PrintCollateCopies = 0x0010, - DontUseSheet = 0x0020 + DontUseSheet = 0x0020, + PrintCurrentPage = 0x0040 }; Q_DECLARE_FLAGS(PrintDialogOptions, PrintDialogOption) diff --git a/src/gui/dialogs/qprintdialog_qws.cpp b/src/gui/dialogs/qprintdialog_qws.cpp index 1336c04..b071427 100644 --- a/src/gui/dialogs/qprintdialog_qws.cpp +++ b/src/gui/dialogs/qprintdialog_qws.cpp @@ -178,6 +178,10 @@ void QPrintDialogPrivate::_q_okClicked() q->setPrintRange(QPrintDialog::PageRange); q->setFromTo(firstPage->value(), lastPage->value()); break; + case (int)QPrintDialog::CurrentPage: + q->setPrintRange(QPrintDialog::CurrentPage); + q->setFromTo(0, 0); + break; } q->accept(); } @@ -375,6 +379,7 @@ void QPrintDialogPrivate::setupOptions() rangeCombo->addItem(QPrintDialog::tr("Print all"), QPrintDialog::AllPages); rangeCombo->addItem(QPrintDialog::tr("Print selection"), QPrintDialog::Selection); rangeCombo->addItem(QPrintDialog::tr("Print range"), QPrintDialog::PageRange); + rangeCombo->addItem(QPrintDialog::tr("Print current page"), QPrintDialog::CurrentPage); QObject::connect(rangeCombo, SIGNAL(activated(int)), q, SLOT(_q_printRangeSelected(int))); @@ -490,6 +495,9 @@ void QPrintDialogPrivate::setPrinter(QPrinter *p, bool pickUpSettings) if (!q->isOptionEnabled(QPrintDialog::PrintPageRange) && rangeCombo->findData(QPrintDialog::PageRange) > 0) rangeCombo->removeItem(rangeCombo->findData(QPrintDialog::PageRange)); + if (!q->isOptionEnabled(QPrintDialog::PrintCurrentPage) + && rangeCombo->findData(QPrintDialog::CurrentPage) > 0) + rangeCombo->removeItem(rangeCombo->findData(QPrintDialog::CurrentPage)); switch (q->printRange()) { case QPrintDialog::AllPages: @@ -501,6 +509,9 @@ void QPrintDialogPrivate::setPrinter(QPrinter *p, bool pickUpSettings) case QPrintDialog::PageRange: rangeCombo->setCurrentIndex((int)(QPrintDialog::PageRange)); break; + case QPrintDialog::CurrentPage: + rangeCombo->setCurrentIndex((int)(QPrintDialog::CurrentPage)); + break; } } diff --git a/src/gui/dialogs/qprintdialog_unix.cpp b/src/gui/dialogs/qprintdialog_unix.cpp index 2d169cf..0487f23 100644 --- a/src/gui/dialogs/qprintdialog_unix.cpp +++ b/src/gui/dialogs/qprintdialog_unix.cpp @@ -502,6 +502,9 @@ void QPrintDialogPrivate::setupPrinter() } else if (options.printSelection->isChecked()) { p->setPrintRange(QPrinter::Selection); p->setFromTo(0,0); + } else if (options.printCurrentPage->isChecked()) { + p->setPrintRange(QPrinter::CurrentPage); + p->setFromTo(0,0); } else if (options.printRange->isChecked()) { p->setPrintRange(QPrinter::PageRange); p->setFromTo(options.from->value(), qMax(options.from->value(), options.to->value())); @@ -518,10 +521,12 @@ void QPrintDialogPrivate::updateWidgets() { Q_Q(QPrintDialog); options.gbPrintRange->setVisible(q->isOptionEnabled(QPrintDialog::PrintPageRange) || - q->isOptionEnabled(QPrintDialog::PrintSelection)); + q->isOptionEnabled(QPrintDialog::PrintSelection) || + q->isOptionEnabled(QPrintDialog::PrintCurrentPage)); options.printRange->setEnabled(q->isOptionEnabled(QPrintDialog::PrintPageRange)); options.printSelection->setVisible(q->isOptionEnabled(QPrintDialog::PrintSelection)); + options.printCurrentPage->setVisible(q->isOptionEnabled(QPrintDialog::PrintCurrentPage)); options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies)); switch (q->printRange()) { @@ -534,6 +539,10 @@ void QPrintDialogPrivate::updateWidgets() case QPrintDialog::PageRange: options.printRange->setChecked(true); break; + case QPrintDialog::CurrentPage: + if (q->isOptionEnabled(QPrintDialog::PrintCurrentPage)) + options.printCurrentPage->setChecked(true); + break; default: break; } diff --git a/src/gui/dialogs/qprintdialog_win.cpp b/src/gui/dialogs/qprintdialog_win.cpp index fa0c99f..1061660 100644 --- a/src/gui/dialogs/qprintdialog_win.cpp +++ b/src/gui/dialogs/qprintdialog_win.cpp @@ -128,11 +128,14 @@ static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent, if (pd->nMinPage==0 && pd->nMaxPage==0) pd->Flags |= PD_NOPAGENUMS; - // we don't have a 'current page' notion in the QPrinter API yet. - // Neither do we support more than one page range, so limit those - // options - pd->Flags |= PD_NOCURRENTPAGE; + // Disable Current Page option if not required as default is Enabled + if (!pdlg->isOptionEnabled(QPrintDialog::PrintCurrentPage)) + pd->Flags |= PD_NOCURRENTPAGE; + + // Default to showing the General tab first pd->nStartPage = START_PAGE_GENERAL; + + // We don't support more than one page range in the QPrinter API yet. pd->nPageRanges = 1; pd->nMaxPageRanges = 1; @@ -153,7 +156,10 @@ static void qt_win_read_back_PRINTDLGEX(PRINTDLGEX *pd, QPrintDialog *pdlg, QPri } else if (pd->Flags & PD_PAGENUMS) { pdlg->setPrintRange(QPrintDialog::PageRange); pdlg->setFromTo(pd->lpPageRanges[0].nFromPage, pd->lpPageRanges[0].nToPage); - } else { + } else if (pd->Flags & PD_CURRENTPAGE) { + pdlg->setPrintRange(QPrintDialog::CurrentPage); + pdlg->setFromTo(0, 0); + } else { // PD_ALLPAGES pdlg->setPrintRange(QPrintDialog::AllPages); pdlg->setFromTo(0, 0); } diff --git a/src/gui/dialogs/qprintsettingsoutput.ui b/src/gui/dialogs/qprintsettingsoutput.ui index fc57e86..be91679 100644 --- a/src/gui/dialogs/qprintsettingsoutput.ui +++ b/src/gui/dialogs/qprintsettingsoutput.ui @@ -1,121 +1,114 @@ - + + QPrintSettingsOutput - - + + 0 0 - 416 - 166 + 426 + 171 - + Form - - + + 0 - - + + 0 - - - - 0 - 0 - 412 - 139 - - - + + Copies - + - - - + + + 0 0 - + Print range - - + + 4 - + 6 - - + + Print all - + true - - + + 6 - + 0 - - + + Pages from - - + + false - + 1 - + 999 - - + + to - - + + false - + 1 - + 999 - + Qt::Horizontal - + 0 20 @@ -126,18 +119,25 @@ - - + + + Current Page + + + + + + Selection - - + + Qt::Vertical - + 1 1 @@ -149,37 +149,37 @@ - - + + Output Settings - - - - + + + + Copies: - + copies - - - + + + 1 - + 999 - - - + + + Qt::Horizontal - + 91 20 @@ -187,36 +187,36 @@ - - - + + + Collate - - - - + + + + 0 0 - - - + + + Reverse - - - + + + Qt::Vertical - + 0 1 @@ -229,31 +229,23 @@ - - - - 0 - 0 - 412 - 139 - - - + + Options - - - - + + + + Color Mode - - - - + + + + Qt::Vertical - + 1 0 @@ -261,19 +253,19 @@ - - - + + + Color - - + + - - - + + + Grayscale @@ -281,42 +273,42 @@ - - - + + + Duplex Printing - + - - + + None - + true - - + + Long side - - + + Short side - - + + Qt::Vertical - + 1 0 @@ -341,11 +333,11 @@ from setEnabled(bool) - + 76 59 - + 122 57 @@ -357,11 +349,11 @@ to setEnabled(bool) - + 69 67 - + 215 67 diff --git a/src/gui/painting/qprinter.cpp b/src/gui/painting/qprinter.cpp index edf224d..ae21416 100644 --- a/src/gui/painting/qprinter.cpp +++ b/src/gui/painting/qprinter.cpp @@ -382,6 +382,7 @@ void QPrinterPrivate::addToManualSetList(QPrintEngine::PrintEnginePropertyKey ke \value AllPages All pages should be printed. \value Selection Only the selection should be printed. \value PageRange The specified page range should be printed. + \value CurrentPage Only the current page should be printed. \sa QAbstractPrintDialog::PrintRange */ @@ -571,6 +572,7 @@ void QPrinterPrivate::addToManualSetList(QPrintEngine::PrintEnginePropertyKey ke \value AllPages All the pages should be printed. \value Selection Only the selection should be printed. \value PageRange Print according to the from page and to page options. + \value CurrentPage Only the current page should be printed. \sa setPrintRange(), printRange() */ @@ -586,6 +588,7 @@ void QPrinterPrivate::addToManualSetList(QPrintEngine::PrintEnginePropertyKey ke \value PrintSelection Describes if printing selections should be enabled. \value PrintPageRange Describes if printing page ranges (from, to) should be enabled + \value PrintCurrentPage if Print Current Page option should be enabled \sa setOptionEnabled(), isOptionEnabled() */ diff --git a/src/gui/painting/qprinter.h b/src/gui/painting/qprinter.h index 6636179..996a954 100644 --- a/src/gui/painting/qprinter.h +++ b/src/gui/painting/qprinter.h @@ -124,7 +124,7 @@ public: enum OutputFormat { NativeFormat, PdfFormat, PostScriptFormat }; // ### Qt 5: Merge with QAbstractPrintDialog::PrintRange - enum PrintRange { AllPages, Selection, PageRange }; + enum PrintRange { AllPages, Selection, PageRange, CurrentPage }; enum Unit { Millimeter, diff --git a/tests/auto/qprinter/tst_qprinter.cpp b/tests/auto/qprinter/tst_qprinter.cpp index 7e8ce84..49bddb2 100644 --- a/tests/auto/qprinter/tst_qprinter.cpp +++ b/tests/auto/qprinter/tst_qprinter.cpp @@ -107,6 +107,7 @@ private slots: void printDialogCompleter(); void testCopyCount(); + void testCurrentPage(); void taskQTBUG4497_reusePrinterOnDifferentFiles(); @@ -1005,5 +1006,27 @@ void tst_QPrinter::taskQTBUG4497_reusePrinterOnDifferentFiles() QCOMPARE(file1.readAll(), file2.readAll()); } +void tst_QPrinter::testCurrentPage() +{ + QPrinter printer; + printer.setFromTo(1, 10); + + // Test set print range + printer.setPrintRange(QPrinter::CurrentPage); + QCOMPARE(printer.printRange(), QPrinter::CurrentPage); + QCOMPARE(printer.fromPage(), 1); + QCOMPARE(printer.toPage(), 10); + + QPrintDialog dialog(&printer); + + // Test default Current Page option to off + QCOMPARE(dialog.isOptionEnabled(QPrintDialog::PrintCurrentPage), false); + + // Test enable Current Page option + dialog.setOption(QPrintDialog::PrintCurrentPage); + QCOMPARE(dialog.isOptionEnabled(QPrintDialog::PrintCurrentPage), true); + +} + QTEST_MAIN(tst_QPrinter) #include "tst_qprinter.moc" -- cgit v0.12 From 34329f2f7b535cb0904279203ac1c06efb958651 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 4 Mar 2010 14:09:25 +0100 Subject: QScript: Fix crash when converting a null value to a variant. Fixes test tst_QScriptValue::equals(engine->newVariant(QVariant(123)) <=> engine->newArray(10)) Reviewed-by: Jedrzej Nowacki --- src/script/api/qscriptengine.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 47c5262..024b4d0 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -1591,7 +1591,9 @@ QRegExp QScriptEnginePrivate::toRegExp(JSC::ExecState *exec, JSC::JSValue value) QVariant QScriptEnginePrivate::toVariant(JSC::ExecState *exec, JSC::JSValue value) { - if (isObject(value)) { + if (!value) { + return QVariant(); + } else if (isObject(value)) { if (isVariant(value)) return variantValue(value); #ifndef QT_NO_QOBJECT -- cgit v0.12 From 38ff49e632da2bd61ac5fb59f57f62208c2687fd Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 5 Mar 2010 09:15:19 +1000 Subject: MouseRegion is dead. Long live MouseArea. --- src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp | 1 - src/multimedia/effects/qsoundeffect.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp index e0ae2eb..25660f8 100644 --- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp @@ -106,7 +106,6 @@ void QDeclarativeItemModule::defineModule() QML_REGISTER_TYPE(Qt,4,6,LayoutItem,QDeclarativeLayoutItem); QML_REGISTER_TYPE(Qt,4,6,ListView,QDeclarativeListView); QML_REGISTER_TYPE(Qt,4,6,Loader,QDeclarativeLoader); - QML_REGISTER_TYPE(Qt,4,6,MouseRegion,QDeclarativeMouseArea); QML_REGISTER_TYPE(Qt,4,6,MouseArea,QDeclarativeMouseArea); QML_REGISTER_TYPE(Qt,4,6,Opacity,QGraphicsOpacityEffect); QML_REGISTER_TYPE(Qt,4,6,ParticleMotion,QDeclarativeParticleMotion); diff --git a/src/multimedia/effects/qsoundeffect.cpp b/src/multimedia/effects/qsoundeffect.cpp index 541e6c9..2694023 100644 --- a/src/multimedia/effects/qsoundeffect.cpp +++ b/src/multimedia/effects/qsoundeffect.cpp @@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE id: playSound source: "test.wav" } - MouseRegion { + MouseArea { id: playArea anchors.fill: parent onPressed: { -- cgit v0.12 From 81952293be3328dc2f62f557478042d1e8d04e0d Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 5 Mar 2010 09:46:34 +1000 Subject: Add mapFromItem() and mapToItem() in QDeclarativeItem. Task-number: QT-2385 --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 54 ++++++++++++++++++++ src/declarative/graphicsitems/qdeclarativeitem.h | 3 ++ .../qdeclarativeitem/data/mapCoordinates.qml | 43 ++++++++++++++++ .../qdeclarativeitem/tst_qdeclarativeitem.cpp | 58 ++++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 5014fd8..cb3f542 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -43,6 +43,7 @@ #include "qdeclarativeitem.h" #include "qdeclarativeevents_p_p.h" +#include #include #include @@ -51,6 +52,7 @@ #include #include #include +#include #include #include @@ -2162,6 +2164,58 @@ void QDeclarativeItem::setKeepMouseGrab(bool keep) } /*! + \qmlmethod object Item::mapFromItem(Item item, int x, int y) + + Maps the point (\a x, \a y), which is in \a item's coordinate system, to + this item's coordinate system, and returns an object with \c x and \c y + properties matching the mapped cooordinate. + + If \a item is a \c null value, this maps the point from the coordinate + system of the root QML view. +*/ +QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, int x, int y) const +{ + QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject(); + QDeclarativeItem *itemObj = qobject_cast(item.toQObject()); + if (!itemObj && !item.isNull()) { + qWarning().nospace() << "mapFromItem() given argument " << item.toString() << " which is neither null nor an Item"; + return 0; + } + + // If QGraphicsItem::mapFromItem() is called with 0, behaves the same as mapFromScene() + QPointF p = qobject_cast(this)->mapFromItem(itemObj, x, y); + sv.setProperty("x", p.x()); + sv.setProperty("y", p.y()); + return sv; +} + +/*! + \qmlmethod object Item::mapToItem(Item item, int x, int y) + + Maps the point (\a x, \a y), which is in this item's coordinate system, to + \a item's coordinate system, and returns an object with \c x and \c y + properties matching the mapped cooordinate. + + If \a item is a \c null value, this maps \a x and \a y to the coordinate + system of the root QML view. +*/ +QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, int x, int y) const +{ + QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject(); + QDeclarativeItem *itemObj = qobject_cast(item.toQObject()); + if (!itemObj && !item.isNull()) { + qWarning().nospace() << "mapToItem() given argument " << item.toString() << " which is neither null nor an Item"; + return 0; + } + + // If QGraphicsItem::mapToItem() is called with 0, behaves the same as mapToScene() + QPointF p = qobject_cast(this)->mapToItem(itemObj, x, y); + sv.setProperty("x", p.x()); + sv.setProperty("y", p.y()); + return sv; +} + +/*! \internal This function emits the \e focusChanged signal. diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h index 3ae404d..f6fedc7 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.h +++ b/src/declarative/graphicsitems/qdeclarativeitem.h @@ -159,6 +159,9 @@ public: bool keepMouseGrab() const; void setKeepMouseGrab(bool); + Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, int x, int y) const; + Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, int x, int y) const; + QDeclarativeAnchorLine left() const; QDeclarativeAnchorLine right() const; QDeclarativeAnchorLine horizontalCenter() const; diff --git a/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml b/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml new file mode 100644 index 0000000..40a2106 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml @@ -0,0 +1,43 @@ +import Qt 4.6 + +Item { + id: root; objectName: "root" + width: 200; height: 200 + + Item { id: itemA; objectName: "itemA"; x: 50; y: 50 } + + Item { + x: 50; y: 50 + Item { id: itemB; objectName: "itemB"; x: 100; y: 100 } + } + + function mapAToB(x, y) { + var pos = itemA.mapToItem(itemB, x, y) + return Qt.point(pos.x, pos.y) + } + + function mapAFromB(x, y) { + var pos = itemA.mapFromItem(itemB, x, y) + return Qt.point(pos.x, pos.y) + } + + function mapAToNull(x, y) { + var pos = itemA.mapToItem(null, x, y) + return Qt.point(pos.x, pos.y) + } + + function mapAFromNull(x, y) { + var pos = itemA.mapFromItem(null, x, y) + return Qt.point(pos.x, pos.y) + } + + function checkMapAToInvalid(x, y) { + var pos = itemA.mapToItem(1122, x, y) + return pos.x == undefined && pos.y == undefined + } + + function checkMapAFromInvalid(x, y) { + var pos = itemA.mapFromItem(1122, x, y) + return pos.x == undefined && pos.y == undefined + } +} diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index 36dcf1f..3e69db9 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -58,6 +58,8 @@ private slots: void keyNavigation(); void smooth(); void clip(); + void mapCoordinates(); + void mapCoordinates_data(); private: template @@ -288,6 +290,62 @@ void tst_QDeclarativeItem::clip() QCOMPARE(spy.count(),2); } +void tst_QDeclarativeItem::mapCoordinates() +{ + QFETCH(int, x); + QFETCH(int, y); + + QDeclarativeView *canvas = new QDeclarativeView(0); + canvas->setFixedSize(300, 300); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/mapCoordinates.qml")); + canvas->show(); + qApp->processEvents(); + + QDeclarativeItem *root = qobject_cast(canvas->rootObject()); + QVERIFY(root != 0); + QDeclarativeItem *a = findItem(canvas->rootObject(), "itemA"); + QVERIFY(a != 0); + QDeclarativeItem *b = findItem(canvas->rootObject(), "itemB"); + QVERIFY(b != 0); + + QVariant result; + + QVERIFY(QMetaObject::invokeMethod(root, "mapAToB", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QCOMPARE(result.value(), qobject_cast(a)->mapToItem(b, x, y)); + + QVERIFY(QMetaObject::invokeMethod(root, "mapAFromB", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QCOMPARE(result.value(), qobject_cast(a)->mapFromItem(b, x, y)); + + QVERIFY(QMetaObject::invokeMethod(root, "mapAToNull", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QCOMPARE(result.value(), qobject_cast(a)->mapToScene(x, y)); + + QVERIFY(QMetaObject::invokeMethod(root, "mapAFromNull", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QCOMPARE(result.value(), qobject_cast(a)->mapFromScene(x, y)); + + QTest::ignoreMessage(QtWarningMsg, "mapToItem() given argument \"1122\" which is neither null nor an Item"); + QVERIFY(QMetaObject::invokeMethod(root, "checkMapAToInvalid", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QVERIFY(result.toBool()); + + QTest::ignoreMessage(QtWarningMsg, "mapFromItem() given argument \"1122\" which is neither null nor an Item"); + QVERIFY(QMetaObject::invokeMethod(root, "checkMapAFromInvalid", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QVERIFY(result.toBool()); +} + +void tst_QDeclarativeItem::mapCoordinates_data() +{ + QTest::addColumn("x"); + QTest::addColumn("y"); + + for (int i=-20; i<=20; i+=10) + QTest::newRow(QTest::toString(i)) << i << i; +} + template T *tst_QDeclarativeItem::findItem(QGraphicsObject *parent, const QString &objectName) { -- cgit v0.12 From 8708350f4b00507348fa59f313bcfa554a3d6f79 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 5 Mar 2010 10:35:54 +1000 Subject: Update QML documentation snippets to latest syntax. --- doc/src/snippets/declarative/GroupBox.qml | 15 --------------- doc/src/snippets/declarative/content.qml | 9 --------- doc/src/snippets/declarative/listview/highlight.qml | 4 ++-- doc/src/snippets/declarative/mouseregion.qml | 2 +- doc/src/snippets/declarative/pathview/pathattributes.qml | 2 +- doc/src/snippets/declarative/pathview/pathview.qml | 2 +- 6 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 doc/src/snippets/declarative/GroupBox.qml delete mode 100644 doc/src/snippets/declarative/content.qml diff --git a/doc/src/snippets/declarative/GroupBox.qml b/doc/src/snippets/declarative/GroupBox.qml deleted file mode 100644 index 6c5431e..0000000 --- a/doc/src/snippets/declarative/GroupBox.qml +++ /dev/null @@ -1,15 +0,0 @@ -import Qt 4.6 - -ContentWrapper { - id: container; width: parent.width; height: contents.height - children: [ - Rectangle { - width: parent.width; height: contents.height - color: "white"; pen.width: 2; pen.color: "#adaeb0"; radius: 10 - Column { - id: layout; width: parent.width; margin: 5; spacing: 2 - Content { } - } - } - ] -} diff --git a/doc/src/snippets/declarative/content.qml b/doc/src/snippets/declarative/content.qml deleted file mode 100644 index fb03ced..0000000 --- a/doc/src/snippets/declarative/content.qml +++ /dev/null @@ -1,9 +0,0 @@ -import Qt 4.6 - -Rectangle { - width: 200; height: 100; color: "lightgray" - GroupBox { - Text { text: "First Item" } - Text { text: "Second Item" } - } -} diff --git a/doc/src/snippets/declarative/listview/highlight.qml b/doc/src/snippets/declarative/listview/highlight.qml index b016f9a..6a9d215 100644 --- a/doc/src/snippets/declarative/listview/highlight.qml +++ b/doc/src/snippets/declarative/listview/highlight.qml @@ -30,7 +30,7 @@ Rectangle { } ] transitions: [ - Transition { NumberAnimation { matchProperties: "x"; duration: 200 } } + Transition { NumberAnimation { properties: "x"; duration: 200 } } ] } } @@ -44,7 +44,7 @@ Rectangle { Rectangle { width: 180; height: 40 color: "lightsteelblue"; radius: 5 - y: SpringFollow { + SpringFollow on y { source: list.currentItem.y spring: 3 damping: 0.2 diff --git a/doc/src/snippets/declarative/mouseregion.qml b/doc/src/snippets/declarative/mouseregion.qml index 79f8f8f..fc6c8f0 100644 --- a/doc/src/snippets/declarative/mouseregion.qml +++ b/doc/src/snippets/declarative/mouseregion.qml @@ -1,7 +1,7 @@ import Qt 4.6 Rectangle { width: 200; height: 100 -HorizontalLayout { +Row { //! [0] Rectangle { width: 100; height: 100; color: "green" MouseArea { anchors.fill: parent; onClicked: { parent.color = 'red' } } diff --git a/doc/src/snippets/declarative/pathview/pathattributes.qml b/doc/src/snippets/declarative/pathview/pathattributes.qml index 19a192c..99d0de2 100644 --- a/doc/src/snippets/declarative/pathview/pathattributes.qml +++ b/doc/src/snippets/declarative/pathview/pathattributes.qml @@ -13,7 +13,7 @@ Rectangle { opacity: PathView.opacity Column { Image { anchors.horizontalCenter: name.horizontalCenter; width: 64; height: 64; source: icon } - Text { id: name; text: name; font.pointSize: 16} + Text { text: name; font.pointSize: 16} } } } diff --git a/doc/src/snippets/declarative/pathview/pathview.qml b/doc/src/snippets/declarative/pathview/pathview.qml index 5605139..e316578 100644 --- a/doc/src/snippets/declarative/pathview/pathview.qml +++ b/doc/src/snippets/declarative/pathview/pathview.qml @@ -11,7 +11,7 @@ Rectangle { width: 80; height: 80 Column { Image { anchors.horizontalCenter: name.horizontalCenter; width: 64; height: 64; source: icon } - Text { id: name; text: name; font.pointSize: 16} + Text { text: name; font.pointSize: 16} } } } -- cgit v0.12 From 5048b96a14b61329257e153f2551b6fca4519f84 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 5 Mar 2010 10:40:49 +1000 Subject: Include QML doc snippets in examples autotest --- tests/auto/declarative/examples/examples.pro | 2 ++ tests/auto/declarative/examples/tst_examples.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/auto/declarative/examples/examples.pro b/tests/auto/declarative/examples/examples.pro index b9bcd28..85d2a73 100644 --- a/tests/auto/declarative/examples/examples.pro +++ b/tests/auto/declarative/examples/examples.pro @@ -3,3 +3,5 @@ contains(QT_CONFIG,declarative): QT += declarative macx:CONFIG -= app_bundle SOURCES += tst_examples.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/examples/tst_examples.cpp b/tests/auto/declarative/examples/tst_examples.cpp index 106a4e0..678dd59 100644 --- a/tests/auto/declarative/examples/tst_examples.cpp +++ b/tests/auto/declarative/examples/tst_examples.cpp @@ -168,10 +168,12 @@ void tst_examples::examples_data() QString examples = QLibraryInfo::location(QLibraryInfo::ExamplesPath); QString demos = QLibraryInfo::location(QLibraryInfo::DemosPath); + QString snippets = QLatin1String(SRCDIR) + "/../../../../doc/src/snippets/"; QStringList files; files << findQmlFiles(QDir(examples)); files << findQmlFiles(QDir(demos)); + files << findQmlFiles(QDir(snippets)); foreach (const QString &file, files) QTest::newRow(file.toLatin1().constData()) << file; -- cgit v0.12 From af81ea8a5abbd9a94eb6ab5c3fe0425779905d5a Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 5 Mar 2010 11:14:38 +1000 Subject: Fix test --- .../tst_qdeclarativexmllistmodel.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index 68029bc..20f4ef3 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -266,6 +266,8 @@ void tst_qdeclarativexmllistmodel::reload() QCOMPARE(spyRemove[0][0].toInt(), 0); QCOMPARE(spyRemove[0][1].toInt(), 9); + + delete model; } void tst_qdeclarativexmllistmodel::useKeys() @@ -284,7 +286,7 @@ void tst_qdeclarativexmllistmodel::useKeys() QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/roleKeys.qml")); QDeclarativeXmlListModel *model = qobject_cast(component.create()); QVERIFY(model != 0); - + model->setXml(oldXml); QTRY_COMPARE(model->count(), oldCount); @@ -319,6 +321,8 @@ void tst_qdeclarativexmllistmodel::useKeys() QCOMPARE(spyRemove[i][0].toInt(), removeRanges[i].first); QCOMPARE(spyRemove[i][1].toInt(), removeRanges[i].second); } + + delete model; } void tst_qdeclarativexmllistmodel::useKeys_data() @@ -448,18 +452,16 @@ void tst_qdeclarativexmllistmodel::noKeysValueChanges() model->setXml(xml); // wait for the new xml data to be set, and verify no signals were emitted - for (int i=0; i<50; i++) { - QTest::qWait(100); - if (model->data(0, model->roles()[2]).toString() != QLatin1String("AussieRules")) - break; - } + QTRY_VERIFY(model->data(0, model->roles()[2]).toString() != QLatin1String("Football")); QCOMPARE(model->data(0, model->roles()[2]).toString(), QLatin1String("AussieRules")); QVERIFY(spyInsert.count() == 0); QVERIFY(spyRemove.count() == 0); QVERIFY(spyCount.count() == 0); - + QCOMPARE(model->count(), 2); + + delete model; } void tst_qdeclarativexmllistmodel::keysChanged() @@ -494,6 +496,8 @@ void tst_qdeclarativexmllistmodel::keysChanged() QCOMPARE(spyRemove[0][1].toInt(), 2); QCOMPARE(spyCount.count(), 0); + + delete model; } QTEST_MAIN(tst_qdeclarativexmllistmodel) -- cgit v0.12 From 24a94c1b88fc72243c53e1bf51b87dc0d0be41b7 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 5 Mar 2010 11:18:53 +1000 Subject: declarative examples cleanup --- examples/declarative/behaviours/MyRect.qml | 13 ------- examples/declarative/fonts/fonts.qml | 13 ------- examples/declarative/listview/itemlist.qml | 8 ++--- examples/declarative/mousearea/mouse.qml | 40 ++++++++++++++++++++++ examples/declarative/mouseregion/mouse.qml | 40 ---------------------- .../plugins/com/nokia/TimeExample/Clock.qml | 8 ++--- examples/declarative/searchbox/main.qml | 6 ++-- examples/declarative/velocity/Day.qml | 4 +-- 8 files changed, 52 insertions(+), 80 deletions(-) delete mode 100644 examples/declarative/behaviours/MyRect.qml create mode 100644 examples/declarative/mousearea/mouse.qml delete mode 100644 examples/declarative/mouseregion/mouse.qml diff --git a/examples/declarative/behaviours/MyRect.qml b/examples/declarative/behaviours/MyRect.qml deleted file mode 100644 index caf0d83..0000000 --- a/examples/declarative/behaviours/MyRect.qml +++ /dev/null @@ -1,13 +0,0 @@ -import Qt 4.6 - -Rectangle { - radius: 15 - border.color: "black" - width: 100 - height: 100 - id: page - MouseArea { - anchors.fill: parent - onClicked: { bluerect.parent = page; bluerect.x=0 } - } -} diff --git a/examples/declarative/fonts/fonts.qml b/examples/declarative/fonts/fonts.qml index 275ad43..6246d16 100644 --- a/examples/declarative/fonts/fonts.qml +++ b/examples/declarative/fonts/fonts.qml @@ -7,11 +7,8 @@ Rectangle { color: "steelblue" FontLoader { id: fixedFont; name: "Courier" } - FontLoader { id: localFont; source: "fonts/tarzenau-ocr-a.ttf" } - FontLoader { id: webFont; source: "http://www.princexml.com/fonts/steffmann/Starburst.ttf" } - FontLoader { id: webFont2; source: "http://wrong.address.org" } Column { anchors.fill: parent; spacing: 10 @@ -55,15 +52,5 @@ Rectangle { width: parent.width; elide: Text.ElideMiddle font.family: webFont.name; font.pointSize: 36 } - Text { - text: { - if (webFont2.status == 1) myText - else if (webFont2.status == 2) "Loading..." - else if (webFont2.status == 3) "Error loading font" - } - color: "lightsteelblue" - width: parent.width; elide: Text.ElideRight - font.family: webFont2.name; font.pointSize: 36 - } } } diff --git a/examples/declarative/listview/itemlist.qml b/examples/declarative/listview/itemlist.qml index 54981b7..41aa860 100644 --- a/examples/declarative/listview/itemlist.qml +++ b/examples/declarative/listview/itemlist.qml @@ -26,14 +26,12 @@ Rectangle { ListView { id: view - anchors.fill: parent - anchors.bottomMargin: 30 + anchors.fill: parent; anchors.bottomMargin: 30 model: itemModel - preferredHighlightBegin: 0 - preferredHighlightEnd: 0 + preferredHighlightBegin: 0; preferredHighlightEnd: 0 highlightRangeMode: "StrictlyEnforceRange" orientation: ListView.Horizontal - flickDeceleration: 2000 + snapMode: ListView.SnapOneItem; flickDeceleration: 2000 } Rectangle { diff --git a/examples/declarative/mousearea/mouse.qml b/examples/declarative/mousearea/mouse.qml new file mode 100644 index 0000000..9191f8a --- /dev/null +++ b/examples/declarative/mousearea/mouse.qml @@ -0,0 +1,40 @@ +import Qt 4.6 + +Rectangle { + color: "white" + width: 200; height: 200 + Rectangle { + width: 50; height: 50 + color: "red" + Text { text: "Click"; anchors.centerIn: parent } + MouseArea { + hoverEnabled: true + acceptedButtons: Qt.LeftButton | Qt.RightButton + onPressed: { console.log('press (x: ' + mouse.x + ' y: ' + mouse.y + ' button: ' + (mouse.button == Qt.RightButton ? 'right' : 'left') + ' Shift: ' + (mouse.modifiers & Qt.ShiftModifier ? 'true' : 'false') + ')') } + onReleased: { console.log('release (x: ' + mouse.x + ' y: ' + mouse.y + ' isClick: ' + mouse.isClick + ' wasHeld: ' + mouse.wasHeld + ')') } + onClicked: { console.log('click (x: ' + mouse.x + ' y: ' + mouse.y + ' wasHeld: ' + mouse.wasHeld + ')') } + onDoubleClicked: { console.log('double click (x: ' + mouse.x + ' y: ' + mouse.y + ')') } + onPressAndHold: { console.log('press and hold') } + onEntered: { console.log('entered ' + pressed) } + onExited: { console.log('exited ' + pressed) } + anchors.fill: parent + } + } + Rectangle { + y: 100; width: 50; height: 50 + color: "blue" + Text { text: "Drag"; anchors.centerIn: parent } + MouseArea { + drag.target: parent + drag.axis: "XAxis" + drag.minimumX: 0 + drag.maximumX: 150 + onPressed: { console.log('press') } + onReleased: { console.log('release (isClick: ' + mouse.isClick + ') (wasHeld: ' + mouse.wasHeld + ')') } + onClicked: { console.log('click' + '(wasHeld: ' + mouse.wasHeld + ')') } + onDoubleClicked: { console.log('double click') } + onPressAndHold: { console.log('press and hold') } + anchors.fill: parent + } + } +} diff --git a/examples/declarative/mouseregion/mouse.qml b/examples/declarative/mouseregion/mouse.qml deleted file mode 100644 index 9191f8a..0000000 --- a/examples/declarative/mouseregion/mouse.qml +++ /dev/null @@ -1,40 +0,0 @@ -import Qt 4.6 - -Rectangle { - color: "white" - width: 200; height: 200 - Rectangle { - width: 50; height: 50 - color: "red" - Text { text: "Click"; anchors.centerIn: parent } - MouseArea { - hoverEnabled: true - acceptedButtons: Qt.LeftButton | Qt.RightButton - onPressed: { console.log('press (x: ' + mouse.x + ' y: ' + mouse.y + ' button: ' + (mouse.button == Qt.RightButton ? 'right' : 'left') + ' Shift: ' + (mouse.modifiers & Qt.ShiftModifier ? 'true' : 'false') + ')') } - onReleased: { console.log('release (x: ' + mouse.x + ' y: ' + mouse.y + ' isClick: ' + mouse.isClick + ' wasHeld: ' + mouse.wasHeld + ')') } - onClicked: { console.log('click (x: ' + mouse.x + ' y: ' + mouse.y + ' wasHeld: ' + mouse.wasHeld + ')') } - onDoubleClicked: { console.log('double click (x: ' + mouse.x + ' y: ' + mouse.y + ')') } - onPressAndHold: { console.log('press and hold') } - onEntered: { console.log('entered ' + pressed) } - onExited: { console.log('exited ' + pressed) } - anchors.fill: parent - } - } - Rectangle { - y: 100; width: 50; height: 50 - color: "blue" - Text { text: "Drag"; anchors.centerIn: parent } - MouseArea { - drag.target: parent - drag.axis: "XAxis" - drag.minimumX: 0 - drag.maximumX: 150 - onPressed: { console.log('press') } - onReleased: { console.log('release (isClick: ' + mouse.isClick + ') (wasHeld: ' + mouse.wasHeld + ')') } - onClicked: { console.log('click' + '(wasHeld: ' + mouse.wasHeld + ')') } - onDoubleClicked: { console.log('double click') } - onPressAndHold: { console.log('press and hold') } - anchors.fill: parent - } - } -} diff --git a/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml b/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml index 01ec686..622fcf9 100644 --- a/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml +++ b/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml @@ -1,8 +1,8 @@ import Qt 4.6 -Item { +Rectangle { id: clock - width: 200; height: 200 + width: 200; height: 200; color: "gray" property alias city: cityLabel.text property var hours @@ -18,7 +18,7 @@ Item { transform: Rotation { id: hourRotation origin.x: 7.5; origin.y: 73; angle: 0 - angle: SpringFollow { + SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 source: (clock.hours * 30) + (clock.minutes * 0.5) } @@ -32,7 +32,7 @@ Item { transform: Rotation { id: minuteRotation origin.x: 6.5; origin.y: 83; angle: 0 - angle: SpringFollow { + SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 source: clock.minutes * 6 } diff --git a/examples/declarative/searchbox/main.qml b/examples/declarative/searchbox/main.qml index 39c3720..9b33be3 100644 --- a/examples/declarative/searchbox/main.qml +++ b/examples/declarative/searchbox/main.qml @@ -6,8 +6,8 @@ Rectangle { Column { anchors.horizontalCenter: parent.horizontalCenter; anchors.verticalCenter: parent.verticalCenter; spacing: 10 - SearchBox { id: search1; KeyNavigation.down: search2; focus: true } - SearchBox { id: search2; KeyNavigation.up: search1; KeyNavigation.down: search3 } - SearchBox { id: search3; KeyNavigation.up: search2 } + SearchBox { id: search1; KeyNavigation.tab: search2; KeyNavigation.backtab: search3; focus: true } + SearchBox { id: search2; KeyNavigation.tab: search3; KeyNavigation.backtab: search1 } + SearchBox { id: search3; KeyNavigation.tab: search1; KeyNavigation.backtab: search2 } } } diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index 7424f60..8a7364e 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -33,7 +33,7 @@ Rectangle { id: sticky scale: 0.5 Image { - id: stickyImage; source: "sticky.png" + id: stickyImage; source: "sticky.png"; transformOrigin: Item.TopLeft smooth: true; y: -20; x: 8 + -width * 0.6 / 2; scale: 0.6 } @@ -59,7 +59,7 @@ Rectangle { } Image { - source: "tack.png" + source: "tack.png"; transformOrigin: Item.TopLeft x: -width / 2; y: -height * 0.7 / 2; scale: 0.7 } -- cgit v0.12 From 34052400e537c188af883c4152df760bc531060d Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Thu, 4 Mar 2010 15:58:26 +1000 Subject: Add missing NOTIFYs to timer, xmllistmodel, xmlrole Reviewed-by: akennedy --- src/declarative/util/qdeclarativetimer.cpp | 3 + src/declarative/util/qdeclarativetimer_p.h | 9 ++- src/declarative/util/qdeclarativexmllistmodel.cpp | 14 +++-- src/declarative/util/qdeclarativexmllistmodel_p.h | 41 +++++++++---- .../qdeclarativetimer/tst_qdeclarativetimer.cpp | 37 ++++++++++++ .../data/propertychanges.qml | 10 ++++ .../tst_qdeclarativexmllistmodel.cpp | 70 ++++++++++++++++++++++ 7 files changed, 167 insertions(+), 17 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativexmllistmodel/data/propertychanges.qml diff --git a/src/declarative/util/qdeclarativetimer.cpp b/src/declarative/util/qdeclarativetimer.cpp index d7e02b1..104e3ae 100644 --- a/src/declarative/util/qdeclarativetimer.cpp +++ b/src/declarative/util/qdeclarativetimer.cpp @@ -123,6 +123,7 @@ void QDeclarativeTimer::setInterval(int interval) if (interval != d->interval) { d->interval = interval; update(); + emit intervalChanged(); } } @@ -183,6 +184,7 @@ void QDeclarativeTimer::setRepeating(bool repeating) if (repeating != d->repeating) { d->repeating = repeating; update(); + emit repeatChanged(); } } @@ -215,6 +217,7 @@ void QDeclarativeTimer::setTriggeredOnStart(bool triggeredOnStart) if (d->triggeredOnStart != triggeredOnStart) { d->triggeredOnStart = triggeredOnStart; update(); + emit triggeredOnStartChanged(); } } diff --git a/src/declarative/util/qdeclarativetimer_p.h b/src/declarative/util/qdeclarativetimer_p.h index e063657..d1e6630 100644 --- a/src/declarative/util/qdeclarativetimer_p.h +++ b/src/declarative/util/qdeclarativetimer_p.h @@ -59,10 +59,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTimer : public QObject, public QDeclarati Q_OBJECT Q_DECLARE_PRIVATE(QDeclarativeTimer) Q_INTERFACES(QDeclarativeParserStatus) - Q_PROPERTY(int interval READ interval WRITE setInterval) + Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged) Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) - Q_PROPERTY(bool repeat READ isRepeating WRITE setRepeating) - Q_PROPERTY(bool triggeredOnStart READ triggeredOnStart WRITE setTriggeredOnStart) + Q_PROPERTY(bool repeat READ isRepeating WRITE setRepeating NOTIFY repeatChanged) + Q_PROPERTY(bool triggeredOnStart READ triggeredOnStart WRITE setTriggeredOnStart NOTIFY triggeredOnStartChanged) public: QDeclarativeTimer(QObject *parent=0); @@ -91,6 +91,9 @@ public Q_SLOTS: Q_SIGNALS: void triggered(); void runningChanged(); + void intervalChanged(); + void repeatChanged(); + void triggeredOnStartChanged(); private: void update(); diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index d260ada..53e08b0 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -571,9 +571,10 @@ void QDeclarativeXmlListModel::setSource(const QUrl &src) { Q_D(QDeclarativeXmlListModel); if (d->src != src) { - d->src = src; reload(); - } + d->src = src; + emit sourceChanged(); + } } /*! @@ -593,8 +594,11 @@ QString QDeclarativeXmlListModel::xml() const void QDeclarativeXmlListModel::setXml(const QString &xml) { Q_D(QDeclarativeXmlListModel); - d->xml = xml; - reload(); + if (d->xml != xml) { + d->xml = xml; + reload(); + emit xmlChanged(); + } } /*! @@ -619,6 +623,7 @@ void QDeclarativeXmlListModel::setQuery(const QString &query) if (d->query != query) { d->query = query; reload(); + emit queryChanged(); } } @@ -638,6 +643,7 @@ void QDeclarativeXmlListModel::setNamespaceDeclarations(const QString &declarati if (d->namespaces != declarations) { d->namespaces = declarations; reload(); + emit namespaceDeclarationsChanged(); } } diff --git a/src/declarative/util/qdeclarativexmllistmodel_p.h b/src/declarative/util/qdeclarativexmllistmodel_p.h index f0ad4b8..23ff7ce 100644 --- a/src/declarative/util/qdeclarativexmllistmodel_p.h +++ b/src/declarative/util/qdeclarativexmllistmodel_p.h @@ -68,10 +68,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeXmlListModel : public QListModelInterface Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - Q_PROPERTY(QUrl source READ source WRITE setSource) - Q_PROPERTY(QString xml READ xml WRITE setXml) - Q_PROPERTY(QString query READ query WRITE setQuery) - Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations) + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QString xml READ xml WRITE setXml NOTIFY xmlChanged) + Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged) + Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations NOTIFY namespaceDeclarationsChanged) Q_PROPERTY(QDeclarativeListProperty roles READ roleObjects) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_CLASSINFO("DefaultProperty", "roles") @@ -111,6 +111,10 @@ Q_SIGNALS: void statusChanged(Status); void progressChanged(qreal progress); void countChanged(); + void sourceChanged(); + void xmlChanged(); + void queryChanged(); + void namespaceDeclarationsChanged(); public Q_SLOTS: // ### need to use/expose Expiry to guess when to call this? @@ -132,16 +136,20 @@ private: class Q_DECLARATIVE_EXPORT QDeclarativeXmlListModelRole : public QObject { Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QString query READ query WRITE setQuery) - Q_PROPERTY(bool isKey READ isKey WRITE setIsKey) - + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged) + Q_PROPERTY(bool isKey READ isKey WRITE setIsKey NOTIFY isKeyChanged) public: QDeclarativeXmlListModelRole() : m_isKey(false) {} ~QDeclarativeXmlListModelRole() {} QString name() const { return m_name; } - void setName(const QString &name) { m_name = name; } + void setName(const QString &name) { + if (name == m_name) + return; + m_name = name; + emit nameChanged(); + } QString query() const { return m_query; } void setQuery(const QString &query) @@ -150,16 +158,29 @@ public: qmlInfo(this) << tr("An XmlRole query must not start with '/'"); return; } + if (m_query == query) + return; m_query = query; + emit queryChanged(); } bool isKey() const { return m_isKey; } - void setIsKey(bool b) { m_isKey = b; } + void setIsKey(bool b) { + if (m_isKey == b) + return; + m_isKey = b; + emit isKeyChanged(); + } bool isValid() { return !m_name.isEmpty() && !m_query.isEmpty(); } +Q_SIGNALS: + void nameChanged(); + void queryChanged(); + void isKeyChanged(); + private: QString m_name; QString m_query; diff --git a/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp b/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp index b120d5d..1dfec50 100644 --- a/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp +++ b/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include #include #include #include @@ -161,6 +162,18 @@ void tst_qdeclarativetimer::repeat() QVERIFY(helper.count == oldCount); QVERIFY(timer->isRunning() == false); + QSignalSpy spy(timer, SIGNAL(repeatChanged())); + + timer->setRepeating(false); + QVERIFY(!timer->isRepeating()); + QCOMPARE(spy.count(),1); + + timer->setRepeating(false); + QCOMPARE(spy.count(),1); + + timer->setRepeating(true); + QCOMPARE(spy.count(),2); + delete timer; } @@ -184,6 +197,18 @@ void tst_qdeclarativetimer::triggeredOnStart() QCOMPARE(helper.count, 2); QVERIFY(timer->isRunning() == false); + QSignalSpy spy(timer, SIGNAL(triggeredOnStartChanged())); + + timer->setTriggeredOnStart(false); + QVERIFY(!timer->triggeredOnStart()); + QCOMPARE(spy.count(),1); + + timer->setTriggeredOnStart(false); + QCOMPARE(spy.count(),1); + + timer->setTriggeredOnStart(true); + QCOMPARE(spy.count(),2); + delete timer; } @@ -250,6 +275,18 @@ void tst_qdeclarativetimer::changeDuration() QCOMPARE(helper.count, 3); QVERIFY(timer->isRunning()); + QSignalSpy spy(timer, SIGNAL(intervalChanged())); + + timer->setInterval(200); + QCOMPARE(timer->interval(), 200); + QCOMPARE(spy.count(),1); + + timer->setInterval(200); + QCOMPARE(spy.count(),1); + + timer->setInterval(300); + QCOMPARE(spy.count(),2); + delete timer; } diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/data/propertychanges.qml b/tests/auto/declarative/qdeclarativexmllistmodel/data/propertychanges.qml new file mode 100644 index 0000000..737ec81 --- /dev/null +++ b/tests/auto/declarative/qdeclarativexmllistmodel/data/propertychanges.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +XmlListModel { + source: "model.xml" + query: "/Pets/Pet" + XmlRole { objectName: "role"; name: "name"; query: "name/string()" } + XmlRole { name: "type"; query: "type/string()" } + XmlRole { name: "age"; query: "age/number()" } + XmlRole { name: "size"; query: "size/string()" } +} diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index 68029bc..6199234 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -74,6 +74,7 @@ private slots: void useKeys_data(); void noKeysValueChanges(); void keysChanged(); + void propertyChanges(); private: QString makeItemXmlAndData(const QString &data, QDeclarativeXmlModelData *modelData = 0) const @@ -440,6 +441,8 @@ void tst_qdeclarativexmllistmodel::noKeysValueChanges() model->setXml(xml); QTRY_COMPARE(model->count(), 2); + model->setXml(""); + QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int))); QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int))); QSignalSpy spyCount(model, SIGNAL(countChanged())); @@ -476,6 +479,8 @@ void tst_qdeclarativexmllistmodel::keysChanged() model->setXml(xml); QTRY_COMPARE(model->count(), 2); + model->setXml(""); + QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int))); QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int))); QSignalSpy spyCount(model, SIGNAL(countChanged())); @@ -496,6 +501,71 @@ void tst_qdeclarativexmllistmodel::keysChanged() QCOMPARE(spyCount.count(), 0); } +void tst_qdeclarativexmllistmodel::propertyChanges() +{ + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + QDeclarativeXmlListModel *model = qobject_cast(component.create()); + QVERIFY(model != 0); + QTRY_COMPARE(model->count(), 9); + + QDeclarativeXmlListModelRole *role = model->findChild("role"); + QVERIFY(role); + + QSignalSpy nameSpy(role, SIGNAL(nameChanged())); + QSignalSpy querySpy(role, SIGNAL(queryChanged())); + QSignalSpy isKeySpy(role, SIGNAL(isKeyChanged())); + + role->setName("size"); + role->setQuery("size/string()"); + role->setIsKey(true); + + QCOMPARE(role->name(), QString("size")); + QCOMPARE(role->query(), QString("size/string()")); + QVERIFY(role->isKey()); + + QCOMPARE(nameSpy.count(),1); + QCOMPARE(querySpy.count(),1); + QCOMPARE(isKeySpy.count(),1); + + role->setName("size"); + role->setQuery("size/string()"); + role->setIsKey(true); + + QCOMPARE(nameSpy.count(),1); + QCOMPARE(querySpy.count(),1); + QCOMPARE(isKeySpy.count(),1); + + QSignalSpy sourceSpy(model, SIGNAL(sourceChanged())); + QSignalSpy xmlSpy(model, SIGNAL(xmlChanged())); + QSignalSpy modelQuerySpy(model, SIGNAL(queryChanged())); + QSignalSpy namespaceDeclarationsSpy(model, SIGNAL(namespaceDeclarationsChanged())); + + model->setSource(QUrl("")); + model->setXml("PollyParrot12Small"); + model->setQuery("/Pets"); + model->setNamespaceDeclarations("declare namespace media=\"http://search.yahoo.com/mrss/\";"); + + QCOMPARE(model->source(), QUrl("")); + QCOMPARE(model->xml(), QString("PollyParrot12Small")); + QCOMPARE(model->query(), QString("/Pets")); + QCOMPARE(model->namespaceDeclarations(), QString("declare namespace media=\"http://search.yahoo.com/mrss/\";")); + + QCOMPARE(sourceSpy.count(),1); + QCOMPARE(xmlSpy.count(),1); + QCOMPARE(modelQuerySpy.count(),1); + QCOMPARE(namespaceDeclarationsSpy.count(),1); + + model->setSource(QUrl("")); + model->setXml("PollyParrot12Small"); + model->setQuery("/Pets"); + model->setNamespaceDeclarations("declare namespace media=\"http://search.yahoo.com/mrss/\";"); + + QCOMPARE(sourceSpy.count(),1); + QCOMPARE(xmlSpy.count(),1); + QCOMPARE(modelQuerySpy.count(),1); + QCOMPARE(namespaceDeclarationsSpy.count(),1); +} + QTEST_MAIN(tst_qdeclarativexmllistmodel) #include "tst_qdeclarativexmllistmodel.moc" -- cgit v0.12 From 87628252d721d4f8cf6963e5f20a02a56bd70f9a Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 5 Mar 2010 12:51:45 +1000 Subject: Use _data() for some tests --- .../tst_qdeclarativexmlhttprequest.cpp | 535 ++++++--------------- 1 file changed, 158 insertions(+), 377 deletions(-) diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp index 7dec0ee..01f07ab 100644 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp @@ -69,6 +69,7 @@ private slots: void constructor(); void defaultState(); void open(); + void open_data(); void open_invalid_method(); void open_sync(); void open_arg_count(); @@ -82,6 +83,7 @@ private slots: void send_alreadySent(); void send_ignoreData(); void send_withdata(); + void send_withdata_data(); void abort(); void abort_unsent(); void abort_opened(); @@ -94,8 +96,11 @@ private slots: void getAllResponseHeaders_sent(); void getAllResponseHeaders_args(); void status(); + void status_data(); void statusText(); + void statusText_data(); void responseText(); + void responseText_data(); void responseXML_invalid(); void invalidMethodUsage(); void redirects(); @@ -257,99 +262,50 @@ void tst_qdeclarativexmlhttprequest::defaultState() // Test valid XMLHttpRequest.open() calls void tst_qdeclarativexmlhttprequest::open() { - // Relative url - { - QDeclarativeComponent component(&engine, TEST_FILE("open.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "testdocument.html"); - component.completeCreate(); - - QCOMPARE(object->property("readyState").toBool(), true); - QCOMPARE(object->property("openedState").toBool(), true); - QCOMPARE(object->property("status").toBool(), true); - QCOMPARE(object->property("statusText").toBool(), true); - QCOMPARE(object->property("responseText").toBool(), true); - QCOMPARE(object->property("responseXML").toBool(), true); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; + QFETCH(QUrl, qmlFile); + QFETCH(QString, url); + QFETCH(bool, remote); + + TestHTTPServer *server = 0; + if (remote) { + server = new TestHTTPServer(SERVER_PORT); + QVERIFY(server->isValid()); + QVERIFY(server->wait(TEST_FILE("open_network.expect"), + TEST_FILE("open_network.reply"), + TEST_FILE("testdocument.html"))); } - // Absolute url - { - QDeclarativeComponent component(&engine, TEST_FILE("open.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", TEST_FILE("testdocument.html").toString()); - component.completeCreate(); - - QCOMPARE(object->property("readyState").toBool(), true); - QCOMPARE(object->property("openedState").toBool(), true); - QCOMPARE(object->property("status").toBool(), true); - QCOMPARE(object->property("statusText").toBool(), true); - QCOMPARE(object->property("responseText").toBool(), true); - QCOMPARE(object->property("responseXML").toBool(), true); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } - - // Absolute network url - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("open_network.expect"), - TEST_FILE("open_network.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("open.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - QCOMPARE(object->property("readyState").toBool(), true); - QCOMPARE(object->property("openedState").toBool(), true); - QCOMPARE(object->property("status").toBool(), true); - QCOMPARE(object->property("statusText").toBool(), true); - QCOMPARE(object->property("responseText").toBool(), true); - QCOMPARE(object->property("responseXML").toBool(), true); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } + QDeclarativeComponent component(&engine, qmlFile); + QObject *object = component.beginCreate(engine.rootContext()); + QVERIFY(object != 0); + object->setProperty("url", url); + component.completeCreate(); - // User/pass - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("open_network.expect"), - TEST_FILE("open_network.reply"), - TEST_FILE("testdocument.html"))); + QCOMPARE(object->property("readyState").toBool(), true); + QCOMPARE(object->property("openedState").toBool(), true); + QCOMPARE(object->property("status").toBool(), true); + QCOMPARE(object->property("statusText").toBool(), true); + QCOMPARE(object->property("responseText").toBool(), true); + QCOMPARE(object->property("responseXML").toBool(), true); - QDeclarativeComponent component(&engine, TEST_FILE("open_user.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); + TRY_WAIT(object->property("dataOK").toBool() == true); - QCOMPARE(object->property("readyState").toBool(), true); - QCOMPARE(object->property("openedState").toBool(), true); - QCOMPARE(object->property("status").toBool(), true); - QCOMPARE(object->property("statusText").toBool(), true); - QCOMPARE(object->property("responseText").toBool(), true); - QCOMPARE(object->property("responseXML").toBool(), true); + delete server; + delete object; +} - TRY_WAIT(object->property("dataOK").toBool() == true); +void tst_qdeclarativexmlhttprequest::open_data() +{ + QTest::addColumn("qmlFile"); + QTest::addColumn("url"); + QTest::addColumn("remote"); - // ### Check that the username/password were sent to the server + QTest::newRow("Relative url)") << TEST_FILE("open.qml") << "testdocument.html" << false; + QTest::newRow("Absolute url)") << TEST_FILE("open.qml") << TEST_FILE("testdocument.html").toString() << false; + QTest::newRow("Absolute network url)") << TEST_FILE("open.qml") << "http://127.0.0.1:14445/testdocument.html" << true; - delete object; - } + // ### Check that the username/password were sent to the server + QTest::newRow("User/pass") << TEST_FILE("open_user.qml") << "http://127.0.0.1:14445/testdocument.html" << true; } // Test that calling XMLHttpRequest.open() with an invalid method raises an exception @@ -594,138 +550,38 @@ void tst_qdeclarativexmlhttprequest::send_ignoreData() // Test that send()'ing data works void tst_qdeclarativexmlhttprequest::send_withdata() { - // No content-type - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.1.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("send_data.1.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); + QFETCH(QString, file_expected); + QFETCH(QString, file_qml); - delete object; - } - - // Correct content-type - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.1.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("send_data.2.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } - - // Incorrect content-type - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.1.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("send_data.3.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } - - // Correct content-type - out of order - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.4.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("send_data.4.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } - - // Incorrect content-type - out of order - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.4.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("send_data.5.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } - - // PUT - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.6.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("send_data.6.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - delete object; - } + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + QVERIFY(server.wait(TEST_FILE(file_expected), + TEST_FILE("send_data.reply"), + TEST_FILE("testdocument.html"))); - // Correct content-type - no charset - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_data.1.expect"), - TEST_FILE("send_data.reply"), - TEST_FILE("testdocument.html"))); + QDeclarativeComponent component(&engine, TEST_FILE(file_qml)); + QObject *object = component.beginCreate(engine.rootContext()); + QVERIFY(object != 0); + object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + component.completeCreate(); - QDeclarativeComponent component(&engine, TEST_FILE("send_data.7.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - component.completeCreate(); + TRY_WAIT(object->property("dataOK").toBool() == true); - TRY_WAIT(object->property("dataOK").toBool() == true); + delete object; +} - delete object; - } +void tst_qdeclarativexmlhttprequest::send_withdata_data() +{ + QTest::addColumn("file_expected"); + QTest::addColumn("file_qml"); + + QTest::newRow("No content-type") << "send_data.1.expect" << "send_data.1.qml"; + QTest::newRow("Correct content-type") << "send_data.1.expect" << "send_data.2.qml"; + QTest::newRow("Incorrect content-type") << "send_data.1.expect" << "send_data.3.qml"; + QTest::newRow("Correct content-type - out of order") << "send_data.4.expect" << "send_data.4.qml"; + QTest::newRow("Incorrect content-type - out of order") << "send_data.4.expect" << "send_data.5.qml"; + QTest::newRow("PUT") << "send_data.6.expect" << "send_data.6.qml"; + QTest::newRow("Correct content-type - no charset") << "send_data.1.expect" << "send_data.7.qml"; } // Test abort() has no effect in unsent state @@ -940,200 +796,125 @@ void tst_qdeclarativexmlhttprequest::getAllResponseHeaders_args() void tst_qdeclarativexmlhttprequest::status() { - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.200.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("status.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedStatus", 200); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); + QFETCH(QUrl, replyUrl); + QFETCH(int, status); - QCOMPARE(object->property("unsentException").toBool(), true); - QCOMPARE(object->property("openedException").toBool(), true); - QCOMPARE(object->property("sentException").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("resetException").toBool(), true); + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + QVERIFY(server.wait(TEST_FILE("status.expect"), + replyUrl, + TEST_FILE("testdocument.html"))); - delete object; - } + QDeclarativeComponent component(&engine, TEST_FILE("status.qml")); + QObject *object = component.beginCreate(engine.rootContext()); + QVERIFY(object != 0); + object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("expectedStatus", status); + component.completeCreate(); - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.404.reply"), - TEST_FILE("testdocument.html"))); + TRY_WAIT(object->property("dataOK").toBool() == true); - QDeclarativeComponent component(&engine, TEST_FILE("status.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedStatus", 404); - component.completeCreate(); + QCOMPARE(object->property("unsentException").toBool(), true); + QCOMPARE(object->property("openedException").toBool(), true); + QCOMPARE(object->property("sentException").toBool(), true); + QCOMPARE(object->property("headersReceived").toBool(), true); + QCOMPARE(object->property("loading").toBool(), true); + QCOMPARE(object->property("done").toBool(), true); + QCOMPARE(object->property("resetException").toBool(), true); - TRY_WAIT(object->property("dataOK").toBool() == true); + delete object; +} - QCOMPARE(object->property("unsentException").toBool(), true); - QCOMPARE(object->property("openedException").toBool(), true); - QCOMPARE(object->property("sentException").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("resetException").toBool(), true); +void tst_qdeclarativexmlhttprequest::status_data() +{ + QTest::addColumn("replyUrl"); + QTest::addColumn("status"); - delete object; - } + QTest::newRow("OK") << TEST_FILE("status.200.reply") << 200; + QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << 404; } void tst_qdeclarativexmlhttprequest::statusText() { - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.200.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("statusText.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedStatus", "OK"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); + QFETCH(QUrl, replyUrl); + QFETCH(QString, statusText); - QCOMPARE(object->property("unsentException").toBool(), true); - QCOMPARE(object->property("openedException").toBool(), true); - QCOMPARE(object->property("sentException").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("resetException").toBool(), true); + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + QVERIFY(server.wait(TEST_FILE("status.expect"), + replyUrl, + TEST_FILE("testdocument.html"))); - delete object; - } + QDeclarativeComponent component(&engine, TEST_FILE("statusText.qml")); + QObject *object = component.beginCreate(engine.rootContext()); + QVERIFY(object != 0); + object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("expectedStatus", statusText); + component.completeCreate(); - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.404.reply"), - TEST_FILE("testdocument.html"))); + TRY_WAIT(object->property("dataOK").toBool() == true); - QDeclarativeComponent component(&engine, TEST_FILE("statusText.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedStatus", "Document not found"); - component.completeCreate(); + QCOMPARE(object->property("unsentException").toBool(), true); + QCOMPARE(object->property("openedException").toBool(), true); + QCOMPARE(object->property("sentException").toBool(), true); + QCOMPARE(object->property("headersReceived").toBool(), true); + QCOMPARE(object->property("loading").toBool(), true); + QCOMPARE(object->property("done").toBool(), true); + QCOMPARE(object->property("resetException").toBool(), true); - TRY_WAIT(object->property("dataOK").toBool() == true); + delete object; +} - QCOMPARE(object->property("unsentException").toBool(), true); - QCOMPARE(object->property("openedException").toBool(), true); - QCOMPARE(object->property("sentException").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("resetException").toBool(), true); +void tst_qdeclarativexmlhttprequest::statusText_data() +{ + QTest::addColumn("replyUrl"); + QTest::addColumn("statusText"); - delete object; - } + QTest::newRow("OK") << TEST_FILE("status.200.reply") << "OK"; + QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << "Document not found"; } void tst_qdeclarativexmlhttprequest::responseText() { - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.200.reply"), - TEST_FILE("testdocument.html"))); - - QDeclarativeComponent component(&engine, TEST_FILE("responseText.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedText", "QML Rocks!\n"); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - QCOMPARE(object->property("unsent").toBool(), true); - QCOMPARE(object->property("opened").toBool(), true); - QCOMPARE(object->property("sent").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("reset").toBool(), true); - - delete object; - } + QFETCH(QUrl, replyUrl); + QFETCH(QUrl, bodyUrl); + QFETCH(QString, responseText); - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.200.reply"), - QUrl())); - - QDeclarativeComponent component(&engine, TEST_FILE("responseText.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedText", ""); - component.completeCreate(); - - TRY_WAIT(object->property("dataOK").toBool() == true); - - QCOMPARE(object->property("unsent").toBool(), true); - QCOMPARE(object->property("opened").toBool(), true); - QCOMPARE(object->property("sent").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("reset").toBool(), true); + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + QVERIFY(server.wait(TEST_FILE("status.expect"), + replyUrl, + bodyUrl)); - delete object; - } + QDeclarativeComponent component(&engine, TEST_FILE("responseText.qml")); + QObject *object = component.beginCreate(engine.rootContext()); + QVERIFY(object != 0); + object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("expectedText", responseText); + component.completeCreate(); - { - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("status.expect"), - TEST_FILE("status.404.reply"), - TEST_FILE("testdocument.html"))); + TRY_WAIT(object->property("dataOK").toBool() == true); - QDeclarativeComponent component(&engine, TEST_FILE("responseText.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); - object->setProperty("expectedText", ""); - component.completeCreate(); + QCOMPARE(object->property("unsent").toBool(), true); + QCOMPARE(object->property("opened").toBool(), true); + QCOMPARE(object->property("sent").toBool(), true); + QCOMPARE(object->property("headersReceived").toBool(), true); + QCOMPARE(object->property("loading").toBool(), true); + QCOMPARE(object->property("done").toBool(), true); + QCOMPARE(object->property("reset").toBool(), true); - TRY_WAIT(object->property("dataOK").toBool() == true); + delete object; +} - QCOMPARE(object->property("unsent").toBool(), true); - QCOMPARE(object->property("opened").toBool(), true); - QCOMPARE(object->property("sent").toBool(), true); - QCOMPARE(object->property("headersReceived").toBool(), true); - QCOMPARE(object->property("loading").toBool(), true); - QCOMPARE(object->property("done").toBool(), true); - QCOMPARE(object->property("reset").toBool(), true); +void tst_qdeclarativexmlhttprequest::responseText_data() +{ + QTest::addColumn("replyUrl"); + QTest::addColumn("bodyUrl"); + QTest::addColumn("responseText"); - delete object; - } + QTest::newRow("OK") << TEST_FILE("status.200.reply") << TEST_FILE("testdocument.html") << "QML Rocks!\n"; + QTest::newRow("empty body") << TEST_FILE("status.200.reply") << QUrl() << ""; + QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << TEST_FILE("testdocument.html") << ""; } // Test that calling hte XMLHttpRequest methods on a non-XMLHttpRequest object -- cgit v0.12 From a7b46bda37a428ae2e5554aa8e58469c92b310a9 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 5 Mar 2010 12:52:06 +1000 Subject: Fix test leaks --- tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp | 8 ++++++++ .../qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index 3e69db9..5549a3e 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -242,6 +242,8 @@ void tst_QDeclarativeItem::keyNavigation() item = findItem(canvas->rootObject(), "item1"); QVERIFY(item); QVERIFY(item->hasFocus()); + + delete canvas; } void tst_QDeclarativeItem::smooth() @@ -265,6 +267,8 @@ void tst_QDeclarativeItem::smooth() QCOMPARE(spy.count(),2); item->setSmooth(false); QCOMPARE(spy.count(),2); + + delete item; } void tst_QDeclarativeItem::clip() @@ -288,6 +292,8 @@ void tst_QDeclarativeItem::clip() QCOMPARE(spy.count(),2); item->setClip(false); QCOMPARE(spy.count(),2); + + delete item; } void tst_QDeclarativeItem::mapCoordinates() @@ -335,6 +341,8 @@ void tst_QDeclarativeItem::mapCoordinates() QVERIFY(QMetaObject::invokeMethod(root, "checkMapAFromInvalid", Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); QVERIFY(result.toBool()); + + delete canvas; } void tst_QDeclarativeItem::mapCoordinates_data() diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp index 9957b50..56e906e 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp +++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp @@ -99,6 +99,7 @@ void tst_QDeclarativeWorkerScript::source() QCOMPARE(item->source(), source); qApp->processEvents(); + delete item; } void tst_QDeclarativeWorkerScript::source_data() @@ -125,6 +126,7 @@ void tst_QDeclarativeWorkerScript::messaging() QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value(), value); qApp->processEvents(); + delete item; } void tst_QDeclarativeWorkerScript::messaging_data() @@ -161,6 +163,7 @@ void tst_QDeclarativeWorkerScript::messaging_sendQObjectList() QCOMPARE(result, (QVariantList() << QVariant() << QVariant() << QVariant())); qApp->processEvents(); + delete item; } void tst_QDeclarativeWorkerScript::messaging_sendJsObject() @@ -180,6 +183,7 @@ void tst_QDeclarativeWorkerScript::messaging_sendJsObject() QVERIFY(result.toBool()); qApp->processEvents(); + delete item; } QTEST_MAIN(tst_QDeclarativeWorkerScript) -- cgit v0.12 From e85b39067914276fb42ce1a8ae35c45d2f688dae Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 5 Mar 2010 13:03:13 +1000 Subject: Improve declarative tabs example. --- examples/declarative/tabwidget/TabWidget.qml | 44 +++++++++++++++---------- examples/declarative/tabwidget/tabs.qml | 49 +++++++++++++++++++--------- 2 files changed, 60 insertions(+), 33 deletions(-) diff --git a/examples/declarative/tabwidget/TabWidget.qml b/examples/declarative/tabwidget/TabWidget.qml index f0dfee8..f0f7164 100644 --- a/examples/declarative/tabwidget/TabWidget.qml +++ b/examples/declarative/tabwidget/TabWidget.qml @@ -1,42 +1,50 @@ import Qt 4.6 Item { - id: page + id: tabWidget property int current: 0 default property alias content: stack.children + onCurrentChanged: setOpacities() Component.onCompleted: setOpacities() + function setOpacities() { - for (var i=0; iRoses are red"; font.pixelSize: 24 - wrap: true; width: parent.width-20 } + anchors.fill: parent; color: "#e3e3e3" + Rectangle { + anchors { fill: parent; topMargin: 20; leftMargin: 20; rightMargin: 20; bottomMargin: 20 } + color: "#ff7f7f" + Text { + anchors.centerIn: parent; horizontalAlignment: Qt.AlignHCenter + text: "Roses are red"; font.pixelSize: 20 + wrap: true; width: parent.width - 20 + } + } } + Rectangle { property string title: "Green" - color: "green" - anchors.fill: parent - Text { anchors.centerIn: parent; text: "
Flower stems are green"; font.pixelSize: 24; - wrap: true; width: parent.width-20 } + anchors.fill: parent; color: "#e3e3e3" + Rectangle { + anchors { fill: parent; topMargin: 20; leftMargin: 20; rightMargin: 20; bottomMargin: 20 } + color: "#7fff7f" + Text { + anchors.centerIn: parent; horizontalAlignment: Qt.AlignHCenter + text: "Flower stems are green"; font.pixelSize: 20 + wrap: true; width: parent.width - 20 + } + } } + Rectangle { property string title: "Blue" - color: "blue" - anchors.fill: parent - Text { anchors.centerIn: parent; text: "
Violets are blue"; color: "white"; font.pixelSize: 24 - wrap: true; width: parent.width-20 } + anchors.fill: parent; color: "#e3e3e3" + Rectangle { + anchors { fill: parent; topMargin: 20; leftMargin: 20; rightMargin: 20; bottomMargin: 20 } + color: "#7f7fff" + Text { + anchors.centerIn: parent; horizontalAlignment: Qt.AlignHCenter + text: "Violets are blue"; font.pixelSize: 20 + wrap: true; width: parent.width - 20 + } + } } } -- cgit v0.12 From 52fc88c05ede03f15328a69989c4acef9bf7c65b Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 5 Mar 2010 13:07:37 +1000 Subject: More declarative examples cleanup. --- examples/declarative/dynamic/dynamic.qml | 42 +++++++++++++++++-------------- examples/declarative/tabwidget/tab.png | Bin 0 -> 507 bytes examples/declarative/velocity/Day.qml | 2 +- 3 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 examples/declarative/tabwidget/tab.png diff --git a/examples/declarative/dynamic/dynamic.qml b/examples/declarative/dynamic/dynamic.qml index 2831b0c..6af3e81 100644 --- a/examples/declarative/dynamic/dynamic.qml +++ b/examples/declarative/dynamic/dynamic.qml @@ -17,15 +17,17 @@ Item { } // stars (when there's no sun) - Particles { id: stars - x: 0; y: 0; width: parent.width; height: parent.height/2 + Particles { + id: stars + x: 0; y: 0; width: parent.width; height: parent.height / 2 source: "images/star.png"; angleDeviation: 360; velocity: 0 velocityDeviation: 0; count: parent.width / 10; fadeInDuration: 2800 opacity: 1 } // ground, which has a z such that the sun can set behind it - Rectangle { id: ground + Rectangle { + id: ground z: 2 anchors { left: parent.left; top: parent.verticalCenter; right: toolbox.right; bottom: parent.bottom } gradient: Gradient { @@ -35,7 +37,8 @@ Item { } //Day state, for when you place a sun - states: State { name: "Day"; when: window.activeSuns > 0 + states: State { + name: "Day"; when: window.activeSuns > 0 PropertyChanges { target: stopA; color: "DeepSkyBlue"} PropertyChanges { target: stopB; color: "SkyBlue"} PropertyChanges { target: stars; opacity: 0 } @@ -56,56 +59,57 @@ Item { width: 480 anchors { right: parent.right; top:parent.top; bottom: parent.bottom } Rectangle { //Not a child of any positioner - color: "white"; border.color: "black"; + color: "white"; border.color: "black"; width: toolRow.width + 4 height: toolRow.height + 4 x: toolboxPositioner.x + toolRow.x - 2 y: toolboxPositioner.y + toolRow.y - 2 } - Column{ + Column { id: toolboxPositioner anchors.centerIn: parent spacing: 8 - Text{ text: "Drag an item into the scene." } - Row{ id: toolRow - spacing: 8; - PaletteItem{ + Text { text: "Drag an item into the scene." } + Row { + id: toolRow + spacing: 8; + PaletteItem { anchors.verticalCenter: parent.verticalCenter file: "Sun.qml"; image: "../images/sun.png" } - PaletteItem{ + PaletteItem { file: "GenericItem.qml" image: "../images/moon.png" } - PaletteItem{ + PaletteItem { anchors.verticalCenter: parent.verticalCenter file: "PerspectiveItem.qml" image: "../images/tree_s.png" } - PaletteItem{ + PaletteItem { anchors.verticalCenter: parent.verticalCenter file: "PerspectiveItem.qml" image: "../images/rabbit_brown.png" } - PaletteItem{ + PaletteItem { anchors.verticalCenter: parent.verticalCenter file: "PerspectiveItem.qml" image: "../images/rabbit_bw.png" } } - Text{ text: "Active Suns: " + activeSuns } + Text { text: "Active Suns: " + activeSuns } Rectangle { width: 440; height: 1; color: "black" } - Text{ text: "Arbitrary QML: " } + Text { text: "Arbitrary QML: " } TextEdit { id: qmlText width: 460 height: 220 readOnly: false focusOnPress: true - font.pixelSize: 16 - - text: "import Qt 4.6\nImage { id: smile;\n x: 500*Math.random();\n y: 200*Math.random(); \n source: 'images/face-smile.png';\n opacity: NumberAnimation{ \n to: 0; duration: 1500;\n }\n Component.onCompleted: smile.destroy(1500);\n}" + font.pixelSize: 14 + + text: "import Qt 4.6\nImage {\n id: smile;\n x: 500*Math.random();\n y: 200*Math.random(); \n source: 'images/face-smile.png';\n NumberAnimation on opacity { \n to: 0; duration: 1500;\n }\n Component.onCompleted: smile.destroy(1500);\n}" } Button { text: "Create" diff --git a/examples/declarative/tabwidget/tab.png b/examples/declarative/tabwidget/tab.png new file mode 100644 index 0000000..ad80216 Binary files /dev/null and b/examples/declarative/tabwidget/tab.png differ diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index 8a7364e..f4c24a5 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -52,7 +52,7 @@ Rectangle { id: mouse onClicked: { myText.focus = true } anchors.fill: parent - drag.target: stickyPage; drag.axis: "XandYAxis"; drag.minimumY: 0; drag.maximumY: 500 + drag.target: stickyPage; drag.axis: MouseArea.XandYAxis; drag.minimumY: 0; drag.maximumY: 500 drag.minimumX: 0; drag.maximumX: 400 } } -- cgit v0.12 From ae6f59d8dffc1a0569640e374dde01ed84f9c542 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 5 Mar 2010 13:23:04 +1000 Subject: Allow unquoted enum syntax for value types QTBUG-5424 --- src/declarative/qml/qdeclarativecompiler.cpp | 6 ++-- src/declarative/qml/qdeclarativeengine.cpp | 1 + src/declarative/qml/qdeclarativemetatype.cpp | 9 ++++-- src/declarative/qml/qdeclarativemetatype_p.h | 2 ++ src/declarative/qml/qdeclarativevaluetype.cpp | 34 ++++++++++++++++++++++ src/declarative/qml/qdeclarativevaluetype_p.h | 2 ++ .../qdeclarativelanguage/data/enumTypes.errors.txt | 1 + .../qdeclarativelanguage/data/enumTypes.qml | 4 +++ .../tst_qdeclarativelanguage.cpp | 1 + .../qdeclarativevaluetypes/data/enums.1.qml | 2 +- .../qdeclarativevaluetypes/data/enums.2.qml | 2 +- .../qdeclarativevaluetypes/data/enums.3.qml | 6 ++++ .../qdeclarativevaluetypes/data/enums.4.qml | 7 +++++ .../tst_qdeclarativevaluetypes.cpp | 20 +++++++++++-- 14 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/enumTypes.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/enumTypes.qml create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/enums.3.qml create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/enums.4.qml diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 5a2f3b5..3c6c949 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -561,9 +561,11 @@ bool QDeclarativeCompiler::compile(QDeclarativeEngine *engine, QDeclarativeCompositeTypeData::TypeReference &tref = unit->types[ii]; QDeclarativeCompiledData::TypeReference ref; QDeclarativeScriptParser::TypeReference *parserRef = unit->data.referencedTypes().at(ii); - if (tref.type) + if (tref.type) { ref.type = tref.type; - else if (tref.unit) { + if (!ref.type->isCreatable()) + COMPILE_EXCEPTION(parserRef->refObjects.first(), QCoreApplication::translate("QDeclarativeCompiler", "Element is not creatable.")); + } else if (tref.unit) { ref.component = tref.unit->toComponent(engine); if (ref.component->isError()) { diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 7ce2d0b..1e60df4 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -167,6 +167,7 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e) QDeclarativeItemModule::defineModule(); QDeclarativeUtilModule::defineModule(); QDeclarativeEnginePrivate::defineModule(); + QDeclarativeValueTypeFactory::registerValueTypes(); } globalClass = new QDeclarativeGlobalScriptClass(&scriptEngine); diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp index abbb9d6..50ab56b 100644 --- a/src/declarative/qml/qdeclarativemetatype.cpp +++ b/src/declarative/qml/qdeclarativemetatype.cpp @@ -286,6 +286,11 @@ QDeclarativeCustomParser *QDeclarativeType::customParser() const return d->m_customParser; } +bool QDeclarativeType::isCreatable() const +{ + return d->m_newFunc != 0; +} + bool QDeclarativeType::isInterface() const { return d->m_isInterface; @@ -402,7 +407,7 @@ int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterType &t data->types.append(dtype); data->idToType.insert(dtype->typeId(), dtype); - data->idToType.insert(dtype->qListTypeId(), dtype); + if (dtype->qListTypeId()) data->idToType.insert(dtype->qListTypeId(), dtype); if (!dtype->qmlTypeName().isEmpty()) data->nameToType.insertMulti(dtype->qmlTypeName(), dtype); @@ -414,7 +419,7 @@ int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterType &t if (data->lists.size() <= type.listId) data->lists.resize(type.listId + 16); data->objects.setBit(type.typeId, true); - data->lists.setBit(type.listId, true); + if (type.listId) data->lists.setBit(type.listId, true); return index; } diff --git a/src/declarative/qml/qdeclarativemetatype_p.h b/src/declarative/qml/qdeclarativemetatype_p.h index ec5c045..cf8946d 100644 --- a/src/declarative/qml/qdeclarativemetatype_p.h +++ b/src/declarative/qml/qdeclarativemetatype_p.h @@ -114,6 +114,8 @@ public: QDeclarativeCustomParser *customParser() const; + bool isCreatable() const; + bool isInterface() const; int typeId() const; int qListTypeId() const; diff --git a/src/declarative/qml/qdeclarativevaluetype.cpp b/src/declarative/qml/qdeclarativevaluetype.cpp index 34d3795..c070123 100644 --- a/src/declarative/qml/qdeclarativevaluetype.cpp +++ b/src/declarative/qml/qdeclarativevaluetype.cpp @@ -41,6 +41,8 @@ #include "qdeclarativevaluetype_p.h" +#include "qdeclarativemetatype_p.h" + #include QT_BEGIN_NAMESPACE @@ -49,6 +51,32 @@ QT_BEGIN_NAMESPACE Q_DECLARE_METATYPE(QEasingCurve); #endif +template +int qmlRegisterValueTypeEnums(const char *qmlName) +{ + QByteArray name(T::staticMetaObject.className()); + + QByteArray pointerName(name + '*'); + + QDeclarativePrivate::RegisterType type = { + 0, + + qRegisterMetaType(pointerName.constData()), 0, 0, + + "Qt", 4, 6, qmlName, &T::staticMetaObject, + + 0, 0, + + 0, 0, 0, + + 0, 0, + + 0 + }; + + return QDeclarativePrivate::registerType(type); +} + QDeclarativeValueTypeFactory::QDeclarativeValueTypeFactory() { // ### Optimize @@ -80,6 +108,12 @@ bool QDeclarativeValueTypeFactory::isValueType(int idx) return false; } +void QDeclarativeValueTypeFactory::registerValueTypes() +{ + qmlRegisterValueTypeEnums("Easing"); + qmlRegisterValueTypeEnums("Font"); +} + QDeclarativeValueType *QDeclarativeValueTypeFactory::operator[](int idx) const { #if (QT_VERSION < QT_VERSION_CHECK(4,7,0)) diff --git a/src/declarative/qml/qdeclarativevaluetype_p.h b/src/declarative/qml/qdeclarativevaluetype_p.h index e69f161..ad2f6c4 100644 --- a/src/declarative/qml/qdeclarativevaluetype_p.h +++ b/src/declarative/qml/qdeclarativevaluetype_p.h @@ -84,6 +84,8 @@ public: static bool isValueType(int); static QDeclarativeValueType *valueType(int); + static void registerValueTypes(); + QDeclarativeValueType *operator[](int idx) const; private: diff --git a/tests/auto/declarative/qdeclarativelanguage/data/enumTypes.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/enumTypes.errors.txt new file mode 100644 index 0000000..d4e0cc0 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/enumTypes.errors.txt @@ -0,0 +1 @@ +3:1:Element is not creatable. diff --git a/tests/auto/declarative/qdeclarativelanguage/data/enumTypes.qml b/tests/auto/declarative/qdeclarativelanguage/data/enumTypes.qml new file mode 100644 index 0000000..a723269 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/enumTypes.qml @@ -0,0 +1,4 @@ +import Qt 4.6 + +Font { +} diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 3ce15cb..da0bf1a 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -326,6 +326,7 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("invalidRoot") << "invalidRoot.qml" << "invalidRoot.errors.txt" << false; QTest::newRow("missingValueTypeProperty") << "missingValueTypeProperty.qml" << "missingValueTypeProperty.errors.txt" << false; QTest::newRow("objectValueTypeProperty") << "objectValueTypeProperty.qml" << "objectValueTypeProperty.errors.txt" << false; + QTest::newRow("enumTypes") << "enumTypes.qml" << "enumTypes.errors.txt" << false; } diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/enums.1.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.1.qml index 0eadd50..cb01a80 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/data/enums.1.qml +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.1.qml @@ -1,6 +1,6 @@ import Test 1.0 MyTypeObject { - font.capitalization: "MixedCase" + font.capitalization: "AllUppercase" } diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/enums.2.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.2.qml index 81f1c92..93f1ed5 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/data/enums.2.qml +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.2.qml @@ -1,6 +1,6 @@ import Test 1.0 MyTypeObject { - font.capitalization: if (1) "MixedCase" + font.capitalization: if (1) "AllUppercase" } diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/enums.3.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.3.qml new file mode 100644 index 0000000..3be5099 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.3.qml @@ -0,0 +1,6 @@ +import Test 1.0 +import Qt 4.6 + +MyTypeObject { + font.capitalization: Font.AllUppercase +} diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/enums.4.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.4.qml new file mode 100644 index 0000000..6b494e4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/enums.4.qml @@ -0,0 +1,7 @@ +import Test 1.0 +import Qt 4.6 as MyQt + +MyTypeObject { + font.capitalization: MyQt.Font.AllUppercase +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp index 8732215..51f9a07 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp +++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp @@ -597,7 +597,7 @@ void tst_qdeclarativevaluetypes::enums() QDeclarativeComponent component(&engine, TEST_FILE("enums.1.qml")); MyTypeObject *object = qobject_cast(component.create()); QVERIFY(object != 0); - QVERIFY(object->font().capitalization() == QFont::MixedCase); + QVERIFY(object->font().capitalization() == QFont::AllUppercase); delete object; } @@ -605,7 +605,23 @@ void tst_qdeclarativevaluetypes::enums() QDeclarativeComponent component(&engine, TEST_FILE("enums.2.qml")); MyTypeObject *object = qobject_cast(component.create()); QVERIFY(object != 0); - QVERIFY(object->font().capitalization() == QFont::MixedCase); + QVERIFY(object->font().capitalization() == QFont::AllUppercase); + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("enums.3.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QVERIFY(object->font().capitalization() == QFont::AllUppercase); + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("enums.4.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QVERIFY(object->font().capitalization() == QFont::AllUppercase); delete object; } } -- cgit v0.12 From 8fa8dcd33f5395060a84f6b7062c927aa675cde6 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 5 Mar 2010 13:31:12 +1000 Subject: Expect fail in currentIndex test for now. --- .../tst_qdeclarativelistview.cpp | 46 ++++++++++------------ 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index a36224f..1df4448 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -450,7 +450,7 @@ void tst_QDeclarativeListView::inserted() model.insertItem(1, "Will", "9876"); // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item @@ -470,7 +470,7 @@ void tst_QDeclarativeListView::inserted() model.insertItem(0, "Foo", "1111"); // zero index, and current item // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item @@ -491,14 +491,14 @@ void tst_QDeclarativeListView::inserted() for (int i = model.count(); i < 30; ++i) model.insertItem(i, "Hello", QString::number(i)); - QTest::qWait(500); + QTest::qWait(300); listview->setContentY(80); - QTest::qWait(500); + QTest::qWait(300); // Insert item outside visible area model.insertItem(1, "Hello", "1324"); - QTest::qWait(500); + QTest::qWait(300); QVERIFY(listview->contentY() == 80); @@ -543,7 +543,7 @@ void tst_QDeclarativeListView::removed(bool animated) model.removeItem(1); // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); QDeclarativeText *name = findItem(viewport, "textName", 1); QVERIFY(name != 0); @@ -565,7 +565,7 @@ void tst_QDeclarativeListView::removed(bool animated) model.removeItem(0); // post: top item starts at 20 // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); name = findItem(viewport, "textName", 0); QVERIFY(name != 0); @@ -586,7 +586,7 @@ void tst_QDeclarativeListView::removed(bool animated) // Remove items not visible model.removeItem(18); // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); // Confirm items positioned correctly itemCount = findItems(viewport, "wrapper").count(); @@ -603,7 +603,7 @@ void tst_QDeclarativeListView::removed(bool animated) model.removeItem(1); // post: top item will be at 40 // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); // Confirm items positioned correctly for (int i = 2; i < 18; ++i) { @@ -617,14 +617,14 @@ void tst_QDeclarativeListView::removed(bool animated) QVERIFY(listview->currentIndex() == 9); QDeclarativeItem *oldCurrent = listview->currentItem(); model.removeItem(9); - QTest::qWait(500); + QTest::qWait(300); QCOMPARE(listview->currentIndex(), 9); QVERIFY(listview->currentItem() != oldCurrent); listview->setContentY(40); // That's the top now // let transitions settle. - QTest::qWait(500); + QTest::qWait(300); // Confirm items positioned correctly itemCount = findItems(viewport, "wrapper").count(); @@ -637,20 +637,20 @@ void tst_QDeclarativeListView::removed(bool animated) // remove current item beyond visible items. listview->setCurrentIndex(20); - QTest::qWait(500); + QTest::qWait(300); listview->setContentY(40); model.removeItem(20); - QTest::qWait(500); + QTest::qWait(300); QCOMPARE(listview->currentIndex(), 20); QVERIFY(listview->currentItem() != 0); // remove item before current, but visible listview->setCurrentIndex(8); - QTest::qWait(500); + QTest::qWait(300); oldCurrent = listview->currentItem(); model.removeItem(6); - QTest::qWait(500); + QTest::qWait(300); QCOMPARE(listview->currentIndex(), 7); QVERIFY(listview->currentItem() == oldCurrent); @@ -1028,22 +1028,16 @@ void tst_QDeclarativeListView::currentIndex() QCOMPARE(listview->contentY(), 0.0); // Test keys + qApp->setActiveWindow(canvas); canvas->show(); + canvas->setFocus(); qApp->processEvents(); - QEvent wa(QEvent::WindowActivate); - QApplication::sendEvent(canvas, &wa); - QFocusEvent fe(QEvent::FocusIn); - QApplication::sendEvent(canvas, &fe); - - QKeyEvent key(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier, "", false, 1); - QApplication::sendEvent(canvas, &key); - QVERIFY(key.isAccepted()); + QTest::keyClick(canvas, Qt::Key_Down); + QEXPECT_FAIL("", "QTBUG-8475", Abort); QCOMPARE(listview->currentIndex(), 1); - key = QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier, "", false, 1); - QApplication::sendEvent(canvas, &key); - QVERIFY(key.isAccepted()); + QTest::keyClick(canvas, Qt::Key_Up); QCOMPARE(listview->currentIndex(), 0); // turn off auto highlight -- cgit v0.12 From 330e85d06600d50972f8abfeec6086e7e8ad6bc1 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 5 Mar 2010 13:41:14 +1000 Subject: Use new enum syntax for value types. --- examples/declarative/fonts/fonts.qml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/declarative/fonts/fonts.qml b/examples/declarative/fonts/fonts.qml index 6246d16..e928df4 100644 --- a/examples/declarative/fonts/fonts.qml +++ b/examples/declarative/fonts/fonts.qml @@ -11,36 +11,36 @@ Rectangle { FontLoader { id: webFont; source: "http://www.princexml.com/fonts/steffmann/Starburst.ttf" } Column { - anchors.fill: parent; spacing: 10 + anchors.fill: parent; spacing: 15 anchors.leftMargin: 10; anchors.rightMargin: 10 Text { text: myText; color: "lightsteelblue" width: parent.width; elide: Text.ElideRight - font.family: "Times"; font.pointSize: 36 + font.family: "Times"; font.pointSize: 42 } Text { text: myText; color: "lightsteelblue" width: parent.width; elide: Text.ElideLeft - font.family: "Times"; font.pointSize: 36 - font.capitalization: "AllUppercase" + font.family: "Times"; font.pointSize: 42 + font.capitalization: Font.AllUppercase } Text { text: myText; color: "lightsteelblue" width: parent.width; elide: Text.ElideMiddle - font.family: fixedFont.name; font.pointSize: 36; font.weight: "Bold" - font.capitalization: "AllLowercase" + font.family: fixedFont.name; font.pointSize: 42; font.weight: Font.Bold + font.capitalization: Font.AllLowercase } Text { text: myText; color: "lightsteelblue" width: parent.width; elide: Text.ElideRight - font.family: fixedFont.name; font.pointSize: 36; font.italic: true - font.capitalization: "SmallCaps" + font.family: fixedFont.name; font.pointSize: 42; font.italic: true + font.capitalization: Font.SmallCaps } Text { text: myText; color: "lightsteelblue" width: parent.width; elide: Text.ElideLeft - font.family: localFont.name; font.pointSize: 36 - font.capitalization: "Capitalize" + font.family: localFont.name; font.pointSize: 42 + font.capitalization: Font.Capitalize } Text { text: { @@ -50,7 +50,7 @@ Rectangle { } color: "lightsteelblue" width: parent.width; elide: Text.ElideMiddle - font.family: webFont.name; font.pointSize: 36 + font.family: webFont.name; font.pointSize: 42 } } } -- cgit v0.12 From 3d84e74212d7cb43e822aa7f0188ef533d8bb4a2 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 5 Mar 2010 13:40:11 +1000 Subject: Fix compiler warning on RVCT Anonymous structures in unions cause warnings on this compiler. QTBUG-8738 --- src/declarative/qml/qdeclarativeinstruction_p.h | 321 +++++++++++++----------- 1 file changed, 173 insertions(+), 148 deletions(-) diff --git a/src/declarative/qml/qdeclarativeinstruction_p.h b/src/declarative/qml/qdeclarativeinstruction_p.h index c41b14f..ec32b35 100644 --- a/src/declarative/qml/qdeclarativeinstruction_p.h +++ b/src/declarative/qml/qdeclarativeinstruction_p.h @@ -161,155 +161,180 @@ public: Type type; unsigned short line; + + struct InitInstruction { + int bindingsSize; + int parserStatusSize; + int contextCache; + int compiledBinding; + }; + struct CreateInstruction { + int type; + int data; + int bindingBits; + ushort column; + }; + struct StoreMetaInstruction { + int data; + int aliasData; + int propertyCache; + }; + struct SetIdInstruction { + int value; + int index; + }; + struct AssignValueSourceInstruction { + int property; + int owner; + int castValue; + }; + struct AssignValueInterceptorInstruction { + int property; + int owner; + int castValue; + }; + struct AssignBindingInstruction { + unsigned int property; + int value; + short context; + short owner; + }; + struct FetchInstruction { + int property; + }; + struct FetchValueInstruction { + int property; + int type; + }; + struct FetchQmlListInstruction { + int property; + int type; + }; + struct BeginInstruction { + int castValue; + }; + struct StoreFloatInstruction { + int propertyIndex; + float value; + }; + struct StoreDoubleInstruction { + int propertyIndex; + double value; + }; + struct StoreIntegerInstruction { + int propertyIndex; + int value; + }; + struct StoreBoolInstruction { + int propertyIndex; + bool value; + }; + struct StoreStringInstruction { + int propertyIndex; + int value; + }; + struct StoreScriptStringInstruction { + int propertyIndex; + int value; + int scope; + }; + struct StoreScriptInstruction { + int value; + }; + struct StoreUrlInstruction { + int propertyIndex; + int value; + }; + struct StoreColorInstruction { + int propertyIndex; + unsigned int value; + }; + struct StoreDateInstruction { + int propertyIndex; + int value; + }; + struct StoreTimeInstruction { + int propertyIndex; + int valueIndex; + }; + struct StoreDateTimeInstruction { + int propertyIndex; + int valueIndex; + }; + struct StoreRealPairInstruction { + int propertyIndex; + int valueIndex; + }; + struct StoreRectInstruction { + int propertyIndex; + int valueIndex; + }; + struct StoreVector3DInstruction { + int propertyIndex; + int valueIndex; + }; + struct StoreObjectInstruction { + int propertyIndex; + }; + struct AssignCustomTypeInstruction { + int propertyIndex; + int valueIndex; + }; + struct StoreSignalInstruction { + int signalIndex; + int value; + int context; + }; + struct AssignSignalObjectInstruction { + int signal; + }; + struct CreateComponentInstruction { + int count; + ushort column; + int endLine; + int metaObject; + }; + struct FetchAttachedInstruction { + int id; + }; + struct DeferInstruction { + int deferCount; + }; + union { - struct { - int bindingsSize; - int parserStatusSize; - int contextCache; - int compiledBinding; - } init; - struct { - int type; - int data; - int bindingBits; - ushort column; - } create; - struct { - int data; - int aliasData; - int propertyCache; - } storeMeta; - struct { - int value; - int index; - } setId; - struct { - int property; - int owner; - int castValue; - } assignValueSource; - struct { - int property; - int owner; - int castValue; - } assignValueInterceptor; - struct { - unsigned int property; - int value; - short context; - short owner; - } assignBinding; - struct { - int property; - int id; - } assignIdOptBinding; - struct { - int property; - int contextIdx; - short context; - short notifyIdx; - } assignObjPropBinding; - struct { - int property; - } fetch; - struct { - int property; - int type; - } fetchValue; - struct { - int property; - int type; - } fetchQmlList; - struct { - int castValue; - } begin; - struct { - int propertyIndex; - float value; - } storeFloat; - struct { - int propertyIndex; - double value; - } storeDouble; - struct { - int propertyIndex; - int value; - } storeInteger; - struct { - int propertyIndex; - bool value; - } storeBool; - struct { - int propertyIndex; - int value; - } storeString; - struct { - int propertyIndex; - int value; - int scope; - } storeScriptString; - struct { - int value; - } storeScript; - struct { - int propertyIndex; - int value; - } storeUrl; - struct { - int propertyIndex; - unsigned int value; - } storeColor; - struct { - int propertyIndex; - int value; - } storeDate; - struct { - int propertyIndex; - int valueIndex; - } storeTime; - struct { - int propertyIndex; - int valueIndex; - } storeDateTime; - struct { - int propertyIndex; - int valueIndex; - } storeRealPair; - struct { - int propertyIndex; - int valueIndex; - } storeRect; - struct { - int propertyIndex; - int valueIndex; - } storeVector3D; - struct { - int propertyIndex; - } storeObject; - struct { - int propertyIndex; - int valueIndex; - } assignCustomType; - struct { - int signalIndex; - int value; - int context; - } storeSignal; - struct { - int signal; - } assignSignalObject; - struct { - int count; - ushort column; - int endLine; - int metaObject; - } createComponent; - struct { - int id; - } fetchAttached; - struct { - int deferCount; - } defer; + InitInstruction init; + CreateInstruction create; + StoreMetaInstruction storeMeta; + SetIdInstruction setId; + AssignValueSourceInstruction assignValueSource; + AssignValueInterceptorInstruction assignValueInterceptor; + AssignBindingInstruction assignBinding; + FetchInstruction fetch; + FetchValueInstruction fetchValue; + FetchQmlListInstruction fetchQmlList; + BeginInstruction begin; + StoreFloatInstruction storeFloat; + StoreDoubleInstruction storeDouble; + StoreIntegerInstruction storeInteger; + StoreBoolInstruction storeBool; + StoreStringInstruction storeString; + StoreScriptStringInstruction storeScriptString; + StoreScriptInstruction storeScript; + StoreUrlInstruction storeUrl; + StoreColorInstruction storeColor; + StoreDateInstruction storeDate; + StoreTimeInstruction storeTime; + StoreDateTimeInstruction storeDateTime; + StoreRealPairInstruction storeRealPair; + StoreRectInstruction storeRect; + StoreVector3DInstruction storeVector3D; + StoreObjectInstruction storeObject; + AssignCustomTypeInstruction assignCustomType; + StoreSignalInstruction storeSignal; + AssignSignalObjectInstruction assignSignalObject; + CreateComponentInstruction createComponent; + FetchAttachedInstruction fetchAttached; + DeferInstruction defer; }; void dump(QDeclarativeCompiledData *); -- cgit v0.12 From b771a3a1238bd843c962a3a2a7cb04e2dfaeadbf Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 5 Mar 2010 13:41:55 +1000 Subject: Delete uninspiring example. --- examples/declarative/anchors/anchor-changes.qml | 46 ------------------------- 1 file changed, 46 deletions(-) delete mode 100644 examples/declarative/anchors/anchor-changes.qml diff --git a/examples/declarative/anchors/anchor-changes.qml b/examples/declarative/anchors/anchor-changes.qml deleted file mode 100644 index 99ca3db..0000000 --- a/examples/declarative/anchors/anchor-changes.qml +++ /dev/null @@ -1,46 +0,0 @@ -import Qt 4.6 - -Item { - id: window - width: 200; height: 450 - - Rectangle { - id: titleBar; color: "Gray" - anchors.top: parent.top; height: 50 - width: parent.width - } - - Rectangle { - id: statusBar; color: "Gray" - height: 50; anchors.bottom: parent.bottom - width: parent.width - } - - Rectangle { - id: content - anchors.top: titleBar.bottom; anchors.bottom: statusBar.top - width: parent.width - - Text { text: "Top"; anchors.top: parent.top } - Text { text: "Bottom"; anchors.bottom: parent.bottom } - } - - MouseArea { - anchors.fill: content - onPressed: window.state = "FullScreen" - onReleased: window.state = "" - } - - states : State { - name: "FullScreen" - //! [0] - AnchorChanges { - target: content; top: window.top; bottom: window.bottom - } - //! [0] - } - - transitions : Transition { - NumberAnimation { properties: "y,height" } - } -} -- cgit v0.12