diff options
50 files changed, 1157 insertions, 301 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index f4d94aa..7279ea6 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp @@ -317,10 +317,10 @@ public: QmlEaseFollow *highlightXAnimator; QmlEaseFollow *highlightYAnimator; - int ownModel : 1; - int wrap : 1; - int autoHighlight : 1; - int fixCurrentVisibility : 1; + bool ownModel : 1; + bool wrap : 1; + bool autoHighlight : 1; + bool fixCurrentVisibility : 1; }; void QmlGraphicsGridViewPrivate::init() diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index 68a565d..ef4dfc2 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -1266,7 +1266,7 @@ QVariant QmlGraphicsKeysAttached::inputMethodQuery(Qt::InputMethodQuery query) c QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); if (i && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod) && i == d->imeItem) { //### how robust is i == d->imeItem check? QVariant v = static_cast<QmlGraphicsItemAccessor *>(i)->doInputMethodQuery(query); - if (v.type() == QVariant::RectF) + if (v.userType() == QVariant::RectF) v = d->item->mapRectFromItem(i, v.toRectF()); //### cost? return v; } @@ -2990,7 +2990,7 @@ QDebug operator<<(QDebug debug, QmlGraphicsItem *item) debug << item->metaObject()->className() << "(this =" << ((void*)item) << ", parent =" << ((void*)item->parentItem()) << ", geometry =" << QRectF(item->pos(), QSizeF(item->width(), item->height())) - << ", z =" << item->zValue() << ")"; + << ", z =" << item->zValue() << ')'; return debug; } diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index 658cfaa..7fb6454 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -182,7 +182,7 @@ public: , snapMode(QmlGraphicsListView::NoSnap), overshootDist(0.0) , footerComponent(0), footer(0), headerComponent(0), header(0) , ownModel(false), wrap(false), autoHighlight(true), haveHighlightRange(false) - , correctFlick(true) + , correctFlick(true), lazyRelease(false) {} void init(); @@ -208,7 +208,7 @@ public: if (item->index != -1 && item->endPosition() > pos) return item; } - return 0; + return visibleItems.count() ? visibleItems.first() : 0; } FxListItem *nextVisibleItem() const { @@ -483,6 +483,7 @@ public: bool autoHighlight : 1; bool haveHighlightRange : 1; bool correctFlick : 1; + bool lazyRelease : 1; static int itemResizedIdx; }; @@ -497,10 +498,8 @@ void QmlGraphicsListViewPrivate::init() QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(refill())); QObject::connect(q, SIGNAL(movementEnded()), q, SLOT(animStopped())); q->setFlickDirection(QmlGraphicsFlickable::VerticalFlick); - if (itemResizedIdx == -1) { + if (itemResizedIdx == -1) itemResizedIdx = QmlGraphicsListView::staticMetaObject.indexOfSlot("itemResized()"); - qDebug() << "ri" << itemResizedIdx; - } } void QmlGraphicsListViewPrivate::clear() @@ -618,23 +617,25 @@ void QmlGraphicsListViewPrivate::refill(qreal from, qreal to) changed = true; } - while (visibleItems.count() > 1 && (item = visibleItems.first()) && item->endPosition() < from) { - if (item->attached->delayRemove()) - break; - //qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endPosition(); - if (item->index != -1) - visibleIndex++; - visibleItems.removeFirst(); - releaseItem(item); - changed = true; - } - while (visibleItems.count() > 1 && (item = visibleItems.last()) && item->position() > to) { - if (item->attached->delayRemove()) - break; - //qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1; - visibleItems.removeLast(); - releaseItem(item); - changed = true; + if (!lazyRelease || !changed) { // avoid destroying items in the same frame that we create + while (visibleItems.count() > 1 && (item = visibleItems.first()) && item->endPosition() < from) { + if (item->attached->delayRemove()) + break; + //qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endPosition(); + if (item->index != -1) + visibleIndex++; + visibleItems.removeFirst(); + releaseItem(item); + changed = true; + } + while (visibleItems.count() > 1 && (item = visibleItems.last()) && item->position() > to) { + if (item->attached->delayRemove()) + break; + //qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1; + visibleItems.removeLast(); + releaseItem(item); + changed = true; + } } if (changed) { if (visibleItems.count()) @@ -648,6 +649,7 @@ void QmlGraphicsListViewPrivate::refill(qreal from, qreal to) updateFooter(); updateViewport(); } + lazyRelease = false; } void QmlGraphicsListViewPrivate::layout() @@ -1894,6 +1896,7 @@ void QmlGraphicsListView::viewportMoved() { Q_D(QmlGraphicsListView); QmlGraphicsFlickable::viewportMoved(); + d->lazyRelease = true; refill(); if (isFlicking() || d->moving) d->moveReason = QmlGraphicsListViewPrivate::Mouse; @@ -1914,26 +1917,23 @@ void QmlGraphicsListView::viewportMoved() } } - if ((d->haveHighlightRange && d->highlightRange == QmlGraphicsListView::StrictlyEnforceRange) - || d->snapMode == QmlGraphicsListView::SnapToItem) { - if (d->flicked && d->correctFlick) { - // Near an end and it seems that the extent has changed? - // Recalculate the flick so that we don't end up in an odd position. - if (d->velocityY > 0) { - if (d->flickTargetY - d->_moveY.value() < height()/2 && minYExtent() != d->flickTargetY) - d->flickY(-d->verticalVelocity.value()); - } else if (d->velocityY < 0) { - if (d->_moveY.value() - d->flickTargetY < height()/2 && maxYExtent() != d->flickTargetY) - d->flickY(-d->verticalVelocity.value()); - } + if (d->flicked && d->correctFlick) { + // Near an end and it seems that the extent has changed? + // Recalculate the flick so that we don't end up in an odd position. + if (d->velocityY > 0) { + if (d->flickTargetY - d->_moveY.value() < height()/2 && minYExtent() != d->flickTargetY) + d->flickY(-d->verticalVelocity.value()); + } else if (d->velocityY < 0) { + if (d->_moveY.value() - d->flickTargetY < height()/2 && maxYExtent() != d->flickTargetY) + d->flickY(-d->verticalVelocity.value()); + } - if (d->velocityX > 0) { - if (d->flickTargetX - d->_moveX.value() < height()/2 && minXExtent() != d->flickTargetX) - d->flickX(-d->verticalVelocity.value()); - } else if (d->velocityX < 0) { - if (d->_moveX.value() - d->flickTargetX < height()/2 && maxXExtent() != d->flickTargetX) - d->flickX(-d->verticalVelocity.value()); - } + if (d->velocityX > 0) { + if (d->flickTargetX - d->_moveX.value() < height()/2 && minXExtent() != d->flickTargetX) + d->flickX(-d->verticalVelocity.value()); + } else if (d->velocityX < 0) { + if (d->_moveX.value() - d->flickTargetX < height()/2 && maxXExtent() != d->flickTargetX) + d->flickX(-d->verticalVelocity.value()); } } } @@ -2235,42 +2235,75 @@ void QmlGraphicsListView::itemsInserted(int modelIndex, int count) // At least some of the added items will be visible int index = modelIndex - d->visibleIndex; - int to = d->buffer+d->position()+d->size()-1; // index can be the next item past the end of the visible items list (i.e. appended) int pos = index < d->visibleItems.count() ? d->visibleItems.at(index)->position() : d->visibleItems.at(index-1)->endPosition()+d->spacing+1; int initialPos = pos; + int diff = 0; QList<FxListItem*> added; - for (int i = 0; i < count && pos <= to; ++i) { - FxListItem *item = d->createItem(modelIndex + i); - d->visibleItems.insert(index, item); - item->setPosition(pos); - added.append(item); - pos += item->size() + d->spacing; - ++index; + FxListItem *firstVisible = d->firstVisibleItem(); + if (firstVisible && pos < firstVisible->position()) { + // Insert items before the visible item. + int insertionIdx = index; + int i = 0; + int from = d->position() - d->buffer; + for (i = count-1; i >= 0 && pos > from; --i) { + FxListItem *item = d->createItem(modelIndex + i); + d->visibleItems.insert(insertionIdx, item); + pos -= item->size() + d->spacing; + item->setPosition(pos); + index++; + } + if (i >= 0) { + // If we didn't insert all our new items - anything + // before the current index is not visible - remove it. + while (insertionIdx--) { + FxListItem *item = d->visibleItems.takeFirst(); + if (item->index != -1) + d->visibleIndex++; + d->releaseItem(item); + } + } else { + // adjust pos of items before inserted items. + for (int i = insertionIdx-1; i >= 0; i--) { + FxListItem *listItem = d->visibleItems.at(i); + listItem->setPosition(listItem->position() - (initialPos - pos)); + } + } + } else { + int i = 0; + int to = d->buffer+d->position()+d->size()-1; + for (i = 0; i < count && pos <= to; ++i) { + FxListItem *item = d->createItem(modelIndex + i); + d->visibleItems.insert(index, item); + item->setPosition(pos); + added.append(item); + pos += item->size() + d->spacing; + ++index; + } + if (i != count) { + // We didn't insert all our new items, which means anything + // beyond the current index is not visible - remove it. + while (d->visibleItems.count() > index) + d->releaseItem(d->visibleItems.takeLast()); + } + diff = pos - initialPos; } if (d->currentIndex >= modelIndex) { // adjust current item index d->currentIndex += count; if (d->currentItem) { d->currentItem->index = d->currentIndex; - d->currentItem->setPosition(d->currentItem->position() + (pos - initialPos)); + d->currentItem->setPosition(d->currentItem->position() + diff); } } - if (pos > to) { - // We didn't insert all our new items, which means anything - // beyond the current index is not visible - remove it. - while (d->visibleItems.count() > index) - d->releaseItem(d->visibleItems.takeLast()); - } else { - // Update the indexes of the following visible items. - for (; index < d->visibleItems.count(); ++index) { - FxListItem *listItem = d->visibleItems.at(index); - if (listItem->item != d->currentItem->item) - listItem->setPosition(listItem->position() + (pos - initialPos)); - if (listItem->index != -1) - listItem->index += count; - } + // Update the indexes of the following visible items. + for (; index < d->visibleItems.count(); ++index) { + FxListItem *listItem = d->visibleItems.at(index); + if (listItem->item != d->currentItem->item) + listItem->setPosition(listItem->position() + diff); + if (listItem->index != -1) + listItem->index += count; } // everything is in order now - emit add() signal for (int j = 0; j < added.count(); ++j) @@ -2315,6 +2348,8 @@ void QmlGraphicsListView::itemsRemoved(int modelIndex, int count) return; } + FxListItem *firstVisible = d->firstVisibleItem(); + int preRemovedSize = 0; // Remove the items from the visible list, skipping anything already marked for removal QList<FxListItem*>::Iterator it = d->visibleItems.begin(); while (it != d->visibleItems.end()) { @@ -2334,12 +2369,19 @@ void QmlGraphicsListView::itemsRemoved(int modelIndex, int count) connect(item->attached, SIGNAL(delayRemoveChanged()), this, SLOT(destroyRemoved()), Qt::QueuedConnection); ++it; } else { + if (item == firstVisible) + firstVisible = 0; + if (firstVisible && item->position() < firstVisible->position()) + preRemovedSize += item->size(); it = d->visibleItems.erase(it); d->releaseItem(item); } } } + if (firstVisible && d->visibleItems.first() != firstVisible) + d->visibleItems.first()->setPosition(d->visibleItems.first()->position() + preRemovedSize); + // fix current if (d->currentIndex >= modelIndex + count) { d->currentIndex -= count; @@ -2401,7 +2443,14 @@ void QmlGraphicsListView::destroyRemoved() void QmlGraphicsListView::itemsMoved(int from, int to, int count) { Q_D(QmlGraphicsListView); - qreal firstItemPos = d->visibleItems.first()->position(); + + if (d->visibleItems.isEmpty()) { + refill(); + return; + } + + FxListItem *firstVisible = d->firstVisibleItem(); + qreal firstItemPos = firstVisible->position(); QHash<int,FxListItem*> moved; int moveBy = 0; @@ -2412,7 +2461,8 @@ void QmlGraphicsListView::itemsMoved(int from, int to, int count) // take the items that are moving item->index += (to-from); moved.insert(item->index, item); - moveBy += item->size(); + if (item->position() < firstItemPos) + moveBy += item->size(); it = d->visibleItems.erase(it); } else { // move everything after the moved items. @@ -2432,6 +2482,8 @@ void QmlGraphicsListView::itemsMoved(int from, int to, int count) FxListItem *movedItem = moved.take(item->index); if (!movedItem) movedItem = d->createItem(item->index); + if (item->index < firstVisible->index) + moveBy -= movedItem->size(); it = d->visibleItems.insert(it, movedItem); ++it; --remaining; @@ -2459,7 +2511,7 @@ void QmlGraphicsListView::itemsMoved(int from, int to, int count) d->releaseItem(moved.take(moved.begin().key())); // Ensure we don't cause an ugly list scroll. - d->visibleItems.first()->setPosition(firstItemPos); + d->visibleItems.first()->setPosition(d->visibleItems.first()->position() + moveBy); d->layout(); d->updateSections(); diff --git a/src/declarative/graphicsitems/qmlgraphicsscalegrid.cpp b/src/declarative/graphicsitems/qmlgraphicsscalegrid.cpp index 3fd14bb..f50b79b 100644 --- a/src/declarative/graphicsitems/qmlgraphicsscalegrid.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsscalegrid.cpp @@ -133,7 +133,7 @@ QmlGraphicsGridScaledImage::QmlGraphicsGridScaledImage(QIODevice *data) while(!data->atEnd()) { QString line = QString::fromUtf8(data->readLine().trimmed()); - if (line.isEmpty() || line.startsWith(QLatin1String("#"))) + if (line.isEmpty() || line.startsWith(QLatin1Char('#'))) continue; QStringList list = line.split(QLatin1Char(':')); diff --git a/src/declarative/graphicsitems/qmlgraphicstext.cpp b/src/declarative/graphicsitems/qmlgraphicstext.cpp index 98ea80d..03baaae 100644 --- a/src/declarative/graphicsitems/qmlgraphicstext.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstext.cpp @@ -121,8 +121,6 @@ QmlGraphicsText::~QmlGraphicsText() QmlGraphicsTextPrivate::~QmlGraphicsTextPrivate() { - delete control; - delete doc; } /*! diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index b973d6c..a6c40c5 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -761,8 +761,7 @@ QmlGraphicsVisualDataModel::ReleaseFlags QmlGraphicsVisualDataModel::release(Qml if (inPackage) emit destroyingPackage(qobject_cast<QmlPackage*>(obj)); stat |= Destroyed; - obj->setParent(0); - obj->deleteLater(); + delete obj; } else if (!inPackage) { stat |= Referenced; } diff --git a/src/declarative/graphicsitems/qmlgraphicswebview.cpp b/src/declarative/graphicsitems/qmlgraphicswebview.cpp index d2b8289..1fdf557 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicswebview.cpp @@ -1186,7 +1186,7 @@ QmlGraphicsWebPage::~QmlGraphicsWebPage() void QmlGraphicsWebPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) { - qWarning() << sourceID << ":" << lineNumber << ":" << message; + qWarning() << sourceID << ':' << lineNumber << ':' << message; } QString QmlGraphicsWebPage::chooseFile(QWebFrame *originatingFrame, const QString& oldFile) diff --git a/src/declarative/qml/parser/qmljslexer.cpp b/src/declarative/qml/parser/qmljslexer.cpp index e9ea604..cf3ed34 100644 --- a/src/declarative/qml/parser/qmljslexer.cpp +++ b/src/declarative/qml/parser/qmljslexer.cpp @@ -49,7 +49,7 @@ #include "qmljsengine_p.h" #include "qmljsgrammar_p.h" -#include <QtGui/qapplication.h> +#include <QtCore/qcoreapplication.h> #include <ctype.h> #include <stdlib.h> @@ -551,7 +551,7 @@ int Lexer::lex() else { setDone(Bad); err = IllegalCharacter; - errmsg = qApp->translate("QmlParser", "Illegal character"); + errmsg = QCoreApplication::translate("QmlParser", "Illegal character"); } } break; @@ -565,7 +565,7 @@ int Lexer::lex() } else if (current == 0 || isLineTerminator()) { setDone(Bad); err = UnclosedStringLiteral; - errmsg = qApp->translate("QmlParser", "Unclosed string at end of line"); + errmsg = QCoreApplication::translate("QmlParser", "Unclosed string at end of line"); } else if (current == '\\') { state = InEscapeSequence; } else { @@ -591,7 +591,7 @@ int Lexer::lex() } else { setDone(Bad); err = IllegalEscapeSequence; - errmsg = qApp->translate("QmlParser", "Illegal escape squence"); + errmsg = QCoreApplication::translate("QmlParser", "Illegal escape squence"); } } else if (current == 'x') state = InHexEscape; @@ -637,7 +637,7 @@ int Lexer::lex() } else { setDone(Bad); err = IllegalUnicodeEscapeSequence; - errmsg = qApp->translate("QmlParser", "Illegal unicode escape sequence"); + errmsg = QCoreApplication::translate("QmlParser", "Illegal unicode escape sequence"); } break; case InSingleLineComment: @@ -663,7 +663,7 @@ int Lexer::lex() if (current == 0) { setDone(Bad); err = UnclosedComment; - errmsg = qApp->translate("QmlParser", "Unclosed comment at end of file"); + errmsg = QCoreApplication::translate("QmlParser", "Unclosed comment at end of file"); driver->addComment(startpos, tokenLength(), startlineno, startcolumn); } else if (isLineTerminator()) { shiftWindowsLineBreak(); @@ -750,7 +750,7 @@ int Lexer::lex() } else { setDone(Bad); err = IllegalExponentIndicator; - errmsg = qApp->translate("QmlParser", "Illegal syntax for exponential number"); + errmsg = QCoreApplication::translate("QmlParser", "Illegal syntax for exponential number"); } break; case InExponent: @@ -776,7 +776,7 @@ int Lexer::lex() && isIdentLetter(current)) { state = Bad; err = IllegalIdentifier; - errmsg = qApp->translate("QmlParser", "Identifier cannot start with numeric literal"); + errmsg = QCoreApplication::translate("QmlParser", "Identifier cannot start with numeric literal"); } // terminate string @@ -1107,7 +1107,7 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix) while (1) { if (isLineTerminator() || current == 0) { - errmsg = qApp->translate("QmlParser", "Unterminated regular expression literal"); + errmsg = QCoreApplication::translate("QmlParser", "Unterminated regular expression literal"); return false; } else if (current != '/' || lastWasEscape == true) @@ -1131,7 +1131,7 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix) while (isIdentLetter(current)) { int flag = Ecma::RegExp::flagFromChar(current); if (flag == 0) { - errmsg = qApp->translate("QmlParser", "Invalid regular expression flag '%0'") + errmsg = QCoreApplication::translate("QmlParser", "Invalid regular expression flag '%0'") .arg(QChar(current)); return false; } diff --git a/src/declarative/qml/parser/qmljsparser.cpp b/src/declarative/qml/parser/qmljsparser.cpp index 7a81557..8ca3c30 100644 --- a/src/declarative/qml/parser/qmljsparser.cpp +++ b/src/declarative/qml/parser/qmljsparser.cpp @@ -49,7 +49,7 @@ #include "qmljsnodepool_p.h" #include <QtCore/QtDebug> -#include <QtGui/QApplication> +#include <QtCore/QCoreApplication> #include <QVarLengthArray> #include <string.h> @@ -266,7 +266,7 @@ case 18: { QString text; for (AST::UiQualifiedId *q = qualifiedId; q; q = q->next) { text += q->name->asString(); - if (q->next) text += QLatin1String("."); + if (q->next) text += QLatin1Char('.'); } node = makeAstNode<AST::UiImport>(driver->nodePool(), qualifiedId); node->fileNameToken = loc(2); @@ -1722,7 +1722,7 @@ case 337: { yylloc.startColumn += yylloc.length; yylloc.length = 0; - //const QString msg = qApp->translate("QmlParser", "Missing `;'"); + //const QString msg = QCoreApplication::translate("QmlParser", "Missing `;'"); //diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Warning, yylloc, msg)); first_token = &token_buffer[0]; @@ -1747,7 +1747,7 @@ case 337: { token_buffer[1].loc = yylloc = location(lexer); if (t_action(errorState, yytoken)) { - const QString msg = qApp->translate("QmlParser", "Unexpected token `%1'").arg(QLatin1String(spell[token_buffer[0].token])); + const QString msg = QCoreApplication::translate("QmlParser", "Unexpected token `%1'").arg(QLatin1String(spell[token_buffer[0].token])); diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg)); action = errorState; @@ -1775,7 +1775,7 @@ case 337: { for (int *tk = tokens; *tk != EOF_SYMBOL; ++tk) { int a = t_action(errorState, *tk); if (a > 0 && t_action(a, yytoken)) { - const QString msg = qApp->translate("QmlParser", "Expected token `%1'").arg(QLatin1String(spell[*tk])); + const QString msg = QCoreApplication::translate("QmlParser", "Expected token `%1'").arg(QLatin1String(spell[*tk])); diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg)); yytoken = *tk; @@ -1798,7 +1798,7 @@ case 337: { int a = t_action(errorState, tk); if (a > 0 && t_action(a, yytoken)) { - const QString msg = qApp->translate("QmlParser", "Expected token `%1'").arg(QLatin1String(spell[tk])); + const QString msg = QCoreApplication::translate("QmlParser", "Expected token `%1'").arg(QLatin1String(spell[tk])); diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg)); yytoken = tk; @@ -1811,7 +1811,7 @@ case 337: { } } - const QString msg = qApp->translate("QmlParser", "Syntax error"); + const QString msg = QCoreApplication::translate("QmlParser", "Syntax error"); diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg)); } diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 2404702..108e3cc 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -74,7 +74,7 @@ #include <QRectF> #include <QAtomicInt> #include <QtCore/qdebug.h> -#include <QtGui/qapplication.h> +#include <QCoreApplication> QT_BEGIN_NAMESPACE @@ -165,7 +165,7 @@ bool QmlCompiler::isSignalPropertyName(const QByteArray &name) For example: \code - COMPILE_EXCEPTION(property, qApp->translate("QmlCompiler","Error for property \"%1\"").arg(QString::fromUtf8(property->name))); + COMPILE_EXCEPTION(property, QCoreApplication::translate("QmlCompiler","Error for property \"%1\"").arg(QString::fromUtf8(property->name))); \endcode */ #define COMPILE_EXCEPTION(token, desc) \ @@ -203,7 +203,7 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, QString string = v->value.asScript(); if (!prop.isWritable()) - COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop.name()))); + COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop.name()))); if (prop.isEnumType()) { int value; @@ -212,7 +212,7 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, } else value = prop.enumerator().keyToValue(string.toUtf8().constData()); if (value == -1) - COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: unknown enumeration")); + COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: unknown enumeration")); return true; } int type = prop.userType(); @@ -220,61 +220,61 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, case -1: break; case QVariant::String: - if (!v->value.isString()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: string expected")); + if (!v->value.isString()) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: string expected")); break; case QVariant::Url: - if (!v->value.isString()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: url expected")); + if (!v->value.isString()) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: url expected")); break; case QVariant::UInt: { bool ok; string.toUInt(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: unsigned int expected")); + if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: unsigned int expected")); } break; case QVariant::Int: { bool ok; string.toInt(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: int expected")); + if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: int expected")); } break; case QMetaType::Float: { bool ok; string.toFloat(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: float expected")); + if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: float expected")); } break; case QVariant::Double: { bool ok; string.toDouble(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: double expected")); + if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: double expected")); } break; case QVariant::Color: { QColor c = QmlStringConverters::colorFromString(string); - if (!c.isValid()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: color expected")); + if (!c.isValid()) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: color expected")); } break; case QVariant::Date: { QDate d = QDate::fromString(string, Qt::ISODate); - if (!d.isValid()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: date expected")); + if (!d.isValid()) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: date expected")); } break; case QVariant::Time: { QTime time = QTime::fromString(string, Qt::ISODate); - if (!time.isValid()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: time expected")); + if (!time.isValid()) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: time expected")); } break; case QVariant::DateTime: { QDateTime dateTime = QDateTime::fromString(string, Qt::ISODate); - if (!dateTime.isValid()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: datetime expected")); + if (!dateTime.isValid()) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: datetime expected")); } break; case QVariant::Point: @@ -282,7 +282,7 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, { bool ok; QPointF point = QmlStringConverters::pointFFromString(string, &ok); - if (!ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: point expected")); + if (!ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: point expected")); } break; case QVariant::Size: @@ -290,7 +290,7 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, { bool ok; QSizeF size = QmlStringConverters::sizeFFromString(string, &ok); - if (!ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: size expected")); + if (!ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: size expected")); } break; case QVariant::Rect: @@ -298,30 +298,28 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, { bool ok; QRectF rect = QmlStringConverters::rectFFromString(string, &ok); - if (!ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: rect expected")); + if (!ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: rect expected")); } break; case QVariant::Bool: { - if (!v->value.isBoolean()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: boolean expected")); + if (!v->value.isBoolean()) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: boolean expected")); } break; case QVariant::Vector3D: { bool ok; QVector3D point = QmlStringConverters::vector3DFromString(string, &ok); - if (!ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: 3D vector expected")); + if (!ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: 3D vector expected")); } break; default: { - int t = prop.type(); - if (t == QVariant::UserType) - t = prop.userType(); + int t = prop.userType(); QmlMetaType::StringConverter converter = QmlMetaType::customStringConverter(t); if (!converter) - COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: unsupported type \"%1\"").arg(QString::fromLatin1(QVariant::typeToName(prop.type())))); + COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: unsupported type \"%1\"").arg(QString::fromLatin1(QVariant::typeToName(prop.type())))); } break; } @@ -517,9 +515,7 @@ void QmlCompiler::genLiteralAssignment(const QMetaProperty &prop, break; default: { - int t = prop.type(); - if (t == QVariant::UserType) - t = prop.userType(); + int t = prop.userType(); int index = output->customTypeData.count(); instr.type = QmlInstruction::AssignCustomType; instr.assignCustomType.propertyIndex = prop.propertyIndex(); @@ -1046,22 +1042,22 @@ bool QmlCompiler::buildComponent(QmlParser::Object *obj, Property *idProp = 0; if (obj->properties.count() > 1 || (obj->properties.count() == 1 && obj->properties.begin().key() != "id")) - COMPILE_EXCEPTION(*obj->properties.begin(), qApp->translate("QmlCompiler","Invalid component specification")); + COMPILE_EXCEPTION(*obj->properties.begin(), QCoreApplication::translate("QmlCompiler","Invalid component specification")); if (!obj->scriptBlockObjects.isEmpty()) - COMPILE_EXCEPTION(obj->scriptBlockObjects.first(), qApp->translate("QmlCompiler","Invalid component specification")); + COMPILE_EXCEPTION(obj->scriptBlockObjects.first(), QCoreApplication::translate("QmlCompiler","Invalid component specification")); if (obj->properties.count()) idProp = *obj->properties.begin(); if (idProp && (idProp->value || idProp->values.count() > 1 || !isValidId(idProp->values.first()->primitive()))) - COMPILE_EXCEPTION(idProp, qApp->translate("QmlCompiler","Invalid component id specification")); + COMPILE_EXCEPTION(idProp, QCoreApplication::translate("QmlCompiler","Invalid component id specification")); if (idProp) { QString idVal = idProp->values.first()->primitive(); if (compileState.ids.contains(idVal)) - COMPILE_EXCEPTION(idProp, qApp->translate("QmlCompiler","id is not unique")); + COMPILE_EXCEPTION(idProp, QCoreApplication::translate("QmlCompiler","id is not unique")); obj->id = idVal; addId(idVal, obj); @@ -1071,14 +1067,14 @@ bool QmlCompiler::buildComponent(QmlParser::Object *obj, if (obj->defaultProperty && (obj->defaultProperty->value || obj->defaultProperty->values.count() > 1 || (obj->defaultProperty->values.count() == 1 && !obj->defaultProperty->values.first()->object))) - COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Invalid component body specification")); + COMPILE_EXCEPTION(obj, QCoreApplication::translate("QmlCompiler","Invalid component body specification")); Object *root = 0; if (obj->defaultProperty && obj->defaultProperty->values.count()) root = obj->defaultProperty->values.first()->object; if (!root) - COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Cannot create empty component specification")); + COMPILE_EXCEPTION(obj, QCoreApplication::translate("QmlCompiler","Cannot create empty component specification")); // Build the component tree COMPILE_CHECK(buildComponentFromRoot(root, ctxt)); @@ -1095,11 +1091,11 @@ bool QmlCompiler::buildScript(QmlParser::Object *obj, QmlParser::Object *script) Property *source = *script->properties.begin(); if (script->defaultProperty) - COMPILE_EXCEPTION(source, qApp->translate("QmlCompiler","Invalid Script block. Specify either the source property or inline script")); + COMPILE_EXCEPTION(source, QCoreApplication::translate("QmlCompiler","Invalid Script block. Specify either the source property or inline script")); if (source->value || source->values.count() != 1 || source->values.at(0)->object || !source->values.at(0)->value.isStringList()) - COMPILE_EXCEPTION(source, qApp->translate("QmlCompiler","Invalid Script source value")); + COMPILE_EXCEPTION(source, QCoreApplication::translate("QmlCompiler","Invalid Script source value")); QStringList sources = source->values.at(0)->value.asStringList(); @@ -1123,7 +1119,7 @@ bool QmlCompiler::buildScript(QmlParser::Object *obj, QmlParser::Object *script) } } else if (!script->properties.isEmpty()) { - COMPILE_EXCEPTION(*script->properties.begin(), qApp->translate("QmlCompiler","Properties cannot be set on Script block")); + COMPILE_EXCEPTION(*script->properties.begin(), QCoreApplication::translate("QmlCompiler","Properties cannot be set on Script block")); } else if (script->defaultProperty) { QString scriptCode; @@ -1137,7 +1133,7 @@ bool QmlCompiler::buildScript(QmlParser::Object *obj, QmlParser::Object *script) if (lineNumber == 1) lineNumber = v->location.start.line; if (v->object || !v->value.isString()) - COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid Script block")); + COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid Script block")); if (ii == 0) { currentLocation = v->location.start; @@ -1145,7 +1141,7 @@ bool QmlCompiler::buildScript(QmlParser::Object *obj, QmlParser::Object *script) } while (currentLocation.line < v->location.start.line) { - scriptCode.append(QLatin1String("\n")); + scriptCode.append(QLatin1Char('\n')); currentLocation.line++; currentLocation.column = 0; } @@ -1267,7 +1263,7 @@ bool QmlCompiler::buildSignal(QmlParser::Property *prop, QmlParser::Object *obj, } else { if (prop->value || prop->values.count() > 1) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Incorrectly specified signal")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Incorrectly specified signal")); prop->index = sigIdx; obj->addSignalProperty(prop); @@ -1280,7 +1276,7 @@ bool QmlCompiler::buildSignal(QmlParser::Property *prop, QmlParser::Object *obj, QString script = prop->values.at(0)->value.asScript().trimmed(); if (script.isEmpty()) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Empty signal assignment")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Empty signal assignment")); } } @@ -1316,7 +1312,7 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, const BindingContext &ctxt) { if (prop->isEmpty()) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Empty property assignment")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Empty property assignment")); const QMetaObject *metaObject = obj->metaObject(); Q_ASSERT(metaObject); @@ -1328,7 +1324,7 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, // Attached properties cannot be used on sub-objects. Sub-objects // always exist in a binding sub-context, which is what we test // for here. - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Attached properties cannot be used here")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Attached properties cannot be used here")); } QmlType *type = 0; @@ -1343,11 +1339,11 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, ctxt)); return true; } else if (!type || !type->attachedPropertiesType()) { - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Non-existant attached object")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Non-existant attached object")); } if (!prop->value) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid attached object assignment")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Invalid attached object assignment")); Q_ASSERT(type->attachedPropertiesFunction()); prop->index = type->index(); @@ -1376,12 +1372,7 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, // We can't error here as the "id" property does not require a // successful index resolution if (p.name()) { - int t = p.type(); - - if (t == QVariant::UserType) - t = p.userType(); - - prop->type = t; + prop->type = p.userType(); } } @@ -1405,9 +1396,9 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, } else if (prop->index == -1) { if (prop->isDefault) { - COMPILE_EXCEPTION(prop->values.first(), qApp->translate("QmlCompiler","Cannot assign to non-existant default property")); + COMPILE_EXCEPTION(prop->values.first(), QCoreApplication::translate("QmlCompiler","Cannot assign to non-existant default property")); } else { - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Cannot assign to non-existant property \"%1\"").arg(QString::fromUtf8(prop->name))); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Cannot assign to non-existant property \"%1\"").arg(QString::fromUtf8(prop->name))); } } else if (prop->value) { @@ -1439,12 +1430,12 @@ QmlCompiler::buildPropertyInNamespace(QmlEnginePrivate::ImportedNamespace *ns, const BindingContext &ctxt) { if (!nsProp->value) - COMPILE_EXCEPTION(nsProp, qApp->translate("QmlCompiler","Invalid use of namespace")); + COMPILE_EXCEPTION(nsProp, QCoreApplication::translate("QmlCompiler","Invalid use of namespace")); foreach (Property *prop, nsProp->value->properties) { if (!isAttachedPropertyName(prop->name)) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Not an attached property name")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Not an attached property name")); // Setup attached property data @@ -1453,10 +1444,10 @@ QmlCompiler::buildPropertyInNamespace(QmlEnginePrivate::ImportedNamespace *ns, &type, 0, 0, 0); if (!type || !type->attachedPropertiesType()) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Non-existant attached object")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Non-existant attached object")); if (!prop->value) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid attached object assignment")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Invalid attached object assignment")); Q_ASSERT(type->attachedPropertiesFunction()); prop->index = type->index(); @@ -1626,13 +1617,13 @@ bool QmlCompiler::buildIdProperty(QmlParser::Property *prop, if (prop->value || prop->values.count() > 1 || prop->values.at(0)->object) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid use of id property")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Invalid use of id property")); QmlParser::Value *idValue = prop->values.at(0); QString val = idValue->primitive(); if (!isValidId(val)) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","\"%1\" is not a valid object id").arg(val)); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","\"%1\" is not a valid object id").arg(val)); // We disallow id's that conflict with import prefixes and types QmlEnginePrivate::ImportedNamespace *ns = 0; @@ -1640,12 +1631,12 @@ bool QmlCompiler::buildIdProperty(QmlParser::Property *prop, QmlEnginePrivate::get(engine)->resolveType(unit->imports, val.toUtf8(), &type, 0, 0, 0, &ns); if (type) - COMPILE_EXCEPTION(idValue, qApp->translate("QmlCompiler","id conflicts with type name")); + COMPILE_EXCEPTION(idValue, QCoreApplication::translate("QmlCompiler","id conflicts with type name")); if (ns) - COMPILE_EXCEPTION(idValue, qApp->translate("QmlCompiler","id conflicts with namespace prefix")); + COMPILE_EXCEPTION(idValue, QCoreApplication::translate("QmlCompiler","id conflicts with namespace prefix")); if (compileState.ids.contains(val)) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","id is not unique")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","id is not unique")); prop->values.at(0)->type = Value::Id; @@ -1720,7 +1711,7 @@ bool QmlCompiler::buildGroupedProperty(QmlParser::Property *prop, Q_ASSERT(prop->index != -1); if (prop->values.count()) - COMPILE_EXCEPTION(prop->values.first(), qApp->translate("QmlCompiler", "Invalid value in grouped property")); + COMPILE_EXCEPTION(prop->values.first(), QCoreApplication::translate("QmlCompiler", "Invalid value in grouped property")); if (prop->type < (int)QVariant::UserType) { QmlEnginePrivate *ep = @@ -1730,7 +1721,7 @@ bool QmlCompiler::buildGroupedProperty(QmlParser::Property *prop, prop->value, obj, ctxt.incr())); obj->addValueTypeProperty(prop); } else { - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid grouped property access")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Invalid grouped property access")); } } else { @@ -1738,7 +1729,7 @@ bool QmlCompiler::buildGroupedProperty(QmlParser::Property *prop, prop->value->metatype = QmlEnginePrivate::get(engine)->metaObjectForType(prop->type); if (!prop->value->metatype) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid grouped property access")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Invalid grouped property access")); obj->addGroupedProperty(prop); @@ -1754,22 +1745,22 @@ bool QmlCompiler::buildValueTypeProperty(QObject *type, const BindingContext &ctxt) { if (obj->defaultProperty) - COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Invalid property use")); + COMPILE_EXCEPTION(obj, QCoreApplication::translate("QmlCompiler","Invalid property use")); obj->metatype = type->metaObject(); foreach (Property *prop, obj->properties) { int idx = type->metaObject()->indexOfProperty(prop->name.constData()); if (idx == -1) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Cannot assign to non-existant property \"%1\"").arg(QString::fromUtf8(prop->name))); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Cannot assign to non-existant property \"%1\"").arg(QString::fromUtf8(prop->name))); QMetaProperty p = type->metaObject()->property(idx); prop->index = idx; prop->type = p.userType(); if (prop->value) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Property assignment expected")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Property assignment expected")); if (prop->values.count() != 1) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Single property assignment expected")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Single property assignment expected")); Value *value = prop->values.at(0); @@ -1777,7 +1768,7 @@ bool QmlCompiler::buildValueTypeProperty(QObject *type, bool isPropertyValue = output->types.at(value->object->type).type->propertyValueSourceCast() != -1; bool isPropertyInterceptor = output->types.at(value->object->type).type->propertyValueInterceptorCast() != -1; if (!isPropertyValue && !isPropertyInterceptor) { - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Unexpected object assignment")); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Unexpected object assignment")); } else { COMPILE_CHECK(buildObject(value->object, ctxt)); @@ -1835,12 +1826,12 @@ bool QmlCompiler::buildListProperty(QmlParser::Property *prop, // at runtime. if (!listTypeIsInterface) { if (!canCoerce(listType, v->object)) { - COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Cannot assign object to list")); + COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Cannot assign object to list")); } } } else { - COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Cannot assign primitives to lists")); + COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Cannot assign primitives to lists")); } } @@ -1859,19 +1850,19 @@ bool QmlCompiler::buildListProperty(QmlParser::Property *prop, // at runtime. if (!listTypeIsInterface) { if (!canCoerce(listType, v->object)) { - COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Cannot assign object to list")); + COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Cannot assign object to list")); } } } else if (v->value.isScript()) { if (assignedBinding) - COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Can only assign one binding to lists")); + COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Can only assign one binding to lists")); assignedBinding = true; COMPILE_CHECK(buildBinding(v, prop, ctxt)); v->type = Value::PropertyBinding; } else { - COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Cannot assign primitives to lists")); + COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Cannot assign primitives to lists")); } } @@ -1886,10 +1877,10 @@ bool QmlCompiler::buildScriptStringProperty(QmlParser::Property *prop, const BindingContext &ctxt) { if (prop->values.count() > 1) - COMPILE_EXCEPTION(prop->values.at(1), qApp->translate("QmlCompiler", "Cannot assign multiple values to a script property")); + COMPILE_EXCEPTION(prop->values.at(1), QCoreApplication::translate("QmlCompiler", "Cannot assign multiple values to a script property")); if (prop->values.at(0)->object || !prop->values.at(0)->value.isScript()) - COMPILE_EXCEPTION(prop->values.at(0), qApp->translate("QmlCompiler", "Invalid property assignment: script expected")); + COMPILE_EXCEPTION(prop->values.at(0), QCoreApplication::translate("QmlCompiler", "Invalid property assignment: script expected")); obj->addScriptStringProperty(prop, ctxt.stack); @@ -2015,7 +2006,7 @@ bool QmlCompiler::buildPropertyObjectAssignment(QmlParser::Property *prop, buildDynamicMeta(prop->parent, ForceCreation); v->type = isPropertyValue ? Value::ValueSource : Value::ValueInterceptor; } else { - COMPILE_EXCEPTION(v->object, qApp->translate("QmlCompiler","Cannot assign object to property")); + COMPILE_EXCEPTION(v->object, QCoreApplication::translate("QmlCompiler","Cannot assign object to property")); } } @@ -2060,12 +2051,12 @@ bool QmlCompiler::checkDynamicMeta(QmlParser::Object *obj) if (prop.isDefaultProperty) { if (seenDefaultProperty) - COMPILE_EXCEPTION(&prop, qApp->translate("QmlCompiler","Duplicate default property")); + COMPILE_EXCEPTION(&prop, QCoreApplication::translate("QmlCompiler","Duplicate default property")); seenDefaultProperty = true; } if (propNames.contains(prop.name)) - COMPILE_EXCEPTION(&prop, qApp->translate("QmlCompiler","Duplicate property name")); + COMPILE_EXCEPTION(&prop, QCoreApplication::translate("QmlCompiler","Duplicate property name")); propNames.insert(prop.name); } @@ -2073,13 +2064,13 @@ bool QmlCompiler::checkDynamicMeta(QmlParser::Object *obj) for (int ii = 0; ii < obj->dynamicSignals.count(); ++ii) { QByteArray name = obj->dynamicSignals.at(ii).name; if (methodNames.contains(name)) - COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Duplicate signal name")); + COMPILE_EXCEPTION(obj, QCoreApplication::translate("QmlCompiler","Duplicate signal name")); methodNames.insert(name); } for (int ii = 0; ii < obj->dynamicSlots.count(); ++ii) { QByteArray name = obj->dynamicSlots.at(ii).name; if (methodNames.contains(name)) - COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Duplicate method name")); + COMPILE_EXCEPTION(obj, QCoreApplication::translate("QmlCompiler","Duplicate method name")); methodNames.insert(name); } @@ -2101,7 +2092,7 @@ bool QmlCompiler::mergeDynamicMetaProperties(QmlParser::Object *obj) property = obj->getProperty(p.name); if (property->value) - COMPILE_EXCEPTION(property, qApp->translate("QmlCompiler","Invalid property nesting")); + COMPILE_EXCEPTION(property, QCoreApplication::translate("QmlCompiler","Invalid property nesting")); for (int ii = 0; ii < p.defaultValue->values.count(); ++ii) { Value *v = p.defaultValue->values.at(ii); @@ -2147,7 +2138,7 @@ bool QmlCompiler::buildDynamicMeta(QmlParser::Object *obj, DynamicMetaMode mode) if (-1 != propIdx) { QMetaProperty prop = obj->metaObject()->property(propIdx); if (prop.isFinal()) - COMPILE_EXCEPTION(&p, qApp->translate("QmlCompiler","Cannot override FINAL property")); + COMPILE_EXCEPTION(&p, QCoreApplication::translate("QmlCompiler","Cannot override FINAL property")); } if (p.isDefaultProperty && @@ -2172,7 +2163,7 @@ bool QmlCompiler::buildDynamicMeta(QmlParser::Object *obj, DynamicMetaMode mode) QmlEnginePrivate *priv = QmlEnginePrivate::get(engine); if (!priv->resolveType(unit->imports, p.customType, &qmltype, &url, 0, 0, 0)) - COMPILE_EXCEPTION(&p, qApp->translate("QmlCompiler","Invalid property type")); + COMPILE_EXCEPTION(&p, QCoreApplication::translate("QmlCompiler","Invalid property type")); if (!qmltype) { QmlCompositeTypeData *tdata = priv->typeManager.get(url); @@ -2186,7 +2177,7 @@ bool QmlCompiler::buildDynamicMeta(QmlParser::Object *obj, DynamicMetaMode mode) } if (p.type == Object::DynamicProperty::Custom) { - type = customTypeName + "*"; + type = customTypeName + '*'; propertyType = QMetaType::QObjectStar; } else { readonly = true; @@ -2255,12 +2246,12 @@ bool QmlCompiler::buildDynamicMeta(QmlParser::Object *obj, DynamicMetaMode mode) for (int ii = 0; ii < obj->dynamicSignals.count(); ++ii) { const Object::DynamicSignal &s = obj->dynamicSignals.at(ii); - QByteArray sig(s.name + "("); + QByteArray sig(s.name + '('); for (int jj = 0; jj < s.parameterTypes.count(); ++jj) { - if (jj) sig.append(","); + if (jj) sig.append(','); sig.append(s.parameterTypes.at(jj)); } - sig.append(")"); + sig.append(')'); QMetaMethodBuilder b = builder.addSignal(sig); b.setParameterNames(s.parameterNames); ((QmlVMEMetaData *)dynamicData.data())->signalCount++; @@ -2268,12 +2259,12 @@ bool QmlCompiler::buildDynamicMeta(QmlParser::Object *obj, DynamicMetaMode mode) for (int ii = 0; ii < obj->dynamicSlots.count(); ++ii) { const Object::DynamicSlot &s = obj->dynamicSlots.at(ii); - QByteArray sig(s.name + "("); + QByteArray sig(s.name + '('); for (int jj = 0; jj < s.parameterNames.count(); ++jj) { - if (jj) sig.append(","); + if (jj) sig.append(','); sig.append("QVariant"); } - sig.append(")"); + sig.append(')'); QMetaMethodBuilder b = builder.addSlot(sig); b.setReturnType("QVariant"); b.setParameterNames(s.parameterNames); @@ -2333,24 +2324,24 @@ bool QmlCompiler::compileAlias(QMetaObjectBuilder &builder, const Object::DynamicProperty &prop) { if (!prop.defaultValue) - COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","No property alias location")); + COMPILE_EXCEPTION(obj, QCoreApplication::translate("QmlCompiler","No property alias location")); if (prop.defaultValue->values.count() != 1 || prop.defaultValue->values.at(0)->object || !prop.defaultValue->values.at(0)->value.isScript()) - COMPILE_EXCEPTION(prop.defaultValue, qApp->translate("QmlCompiler","Invalid alias location")); + COMPILE_EXCEPTION(prop.defaultValue, QCoreApplication::translate("QmlCompiler","Invalid alias location")); QmlJS::AST::Node *node = prop.defaultValue->values.at(0)->value.asAST(); if (!node) - COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","No property alias location")); // ### Can this happen? + COMPILE_EXCEPTION(obj, QCoreApplication::translate("QmlCompiler","No property alias location")); // ### Can this happen? QStringList alias = astNodeToStringList(node); if (alias.count() != 1 && alias.count() != 2) - COMPILE_EXCEPTION(prop.defaultValue, qApp->translate("QmlCompiler","Invalid alias location")); + COMPILE_EXCEPTION(prop.defaultValue, QCoreApplication::translate("QmlCompiler","Invalid alias location")); if (!compileState.ids.contains(alias.at(0))) - COMPILE_EXCEPTION(prop.defaultValue, qApp->translate("QmlCompiler","Invalid alias location")); + COMPILE_EXCEPTION(prop.defaultValue, QCoreApplication::translate("QmlCompiler","Invalid alias location")); Object *idObject = compileState.ids[alias.at(0)]; @@ -2363,7 +2354,7 @@ bool QmlCompiler::compileAlias(QMetaObjectBuilder &builder, propIdx = idObject->metaObject()->indexOfProperty(alias.at(1).toUtf8().constData()); if (-1 == propIdx) - COMPILE_EXCEPTION(prop.defaultValue, qApp->translate("QmlCompiler","Invalid alias location")); + COMPILE_EXCEPTION(prop.defaultValue, QCoreApplication::translate("QmlCompiler","Invalid alias location")); QMetaProperty aliasProperty = idObject->metaObject()->property(propIdx); writable = aliasProperty.isWritable(); @@ -2374,7 +2365,7 @@ bool QmlCompiler::compileAlias(QMetaObjectBuilder &builder, typeName = aliasProperty.typeName(); } else { typeName = idObject->metaObject()->className(); - typeName += "*"; + typeName += '*'; } if (typeName.endsWith('*')) @@ -2402,7 +2393,7 @@ bool QmlCompiler::buildBinding(QmlParser::Value *value, QMetaProperty mp = prop->parent->metaObject()->property(prop->index); if (!mp.isWritable() && !QmlMetaType::isList(prop->type)) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name))); + COMPILE_EXCEPTION(prop, QCoreApplication::translate("QmlCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name))); BindingReference reference; reference.expression = value->value; diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index b66e026..0bd51c3 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -499,9 +499,9 @@ QString QmlComponent::errorsString() const if(!isError()) return ret; foreach(const QmlError &e, d->errors) { - ret += e.url().toString() + QLatin1String(":") + - QString::number(e.line()) + QLatin1String(" ") + - e.description() + QLatin1String("\n"); + ret += e.url().toString() + QLatin1Char(':') + + QString::number(e.line()) + QLatin1Char(' ') + + e.description() + QLatin1Char('\n'); } return ret; } diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp index 8812c31..705c0cf 100644 --- a/src/declarative/qml/qmldom.cpp +++ b/src/declarative/qml/qmldom.cpp @@ -611,7 +611,7 @@ QmlDomObjectPrivate::properties(QmlParser::Property *property) const } - QByteArray name(property->name + "."); + QByteArray name(property->name + '.'); for (Properties::Iterator iter = rv.begin(); iter != rv.end(); ++iter) iter->second.prepend(name); diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index ce5b4a4..3e7ac8e 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -505,7 +505,7 @@ QmlDeclarativeData::QmlDeclarativeData(QmlContext *ctxt) { } -void QmlDeclarativeData::destroyed(QObject *object) +void QmlDeclarativeData::destroyed(QObject * /*object*/) { if (deferredComponent) deferredComponent->release(); @@ -767,9 +767,9 @@ QScriptValue QmlEnginePrivate::lighter(QScriptContext *ctxt, QScriptEngine *engi return engine->nullValue(); QVariant v = ctxt->argument(0).toVariant(); QColor color; - if (v.type() == QVariant::Color) + if (v.userType() == QVariant::Color) color = v.value<QColor>(); - else if (v.type() == QVariant::String) { + else if (v.userType() == QVariant::String) { bool ok; color = QmlStringConverters::colorFromString(v.toString(), &ok); if (!ok) @@ -786,9 +786,9 @@ QScriptValue QmlEnginePrivate::darker(QScriptContext *ctxt, QScriptEngine *engin return engine->nullValue(); QVariant v = ctxt->argument(0).toVariant(); QColor color; - if (v.type() == QVariant::Color) + if (v.userType() == QVariant::Color) color = v.value<QColor>(); - else if (v.type() == QVariant::String) { + else if (v.userType() == QVariant::String) { bool ok; color = QmlStringConverters::colorFromString(v.toString(), &ok); if (!ok) @@ -877,7 +877,7 @@ QScriptValue QmlEnginePrivate::consoleLog(QScriptContext *ctxt, QScriptEngine *e // does just ignore the format letter, which makes it pointless. } - qDebug("%s",msg.data()); + qDebug(msg.constData()); return e->newVariant(QVariant(true)); } @@ -888,7 +888,7 @@ void QmlEnginePrivate::sendQuit () emit q->quit (); } -QScriptValue QmlEnginePrivate::quit(QScriptContext *ctxt, QScriptEngine *e) +QScriptValue QmlEnginePrivate::quit(QScriptContext * /*ctxt*/, QScriptEngine *e) { QmlEnginePrivate *qe = get (e); qe->sendQuit (); @@ -921,9 +921,9 @@ QScriptValue QmlEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine *engine) //get color QVariant v = ctxt->argument(0).toVariant(); QColor color; - if (v.type() == QVariant::Color) + if (v.userType() == QVariant::Color) color = v.value<QColor>(); - else if (v.type() == QVariant::String) { + else if (v.userType() == QVariant::String) { bool ok; color = QmlStringConverters::colorFromString(v.toString(), &ok); if (!ok) @@ -934,9 +934,9 @@ QScriptValue QmlEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine *engine) //get tint color v = ctxt->argument(1).toVariant(); QColor tintColor; - if (v.type() == QVariant::Color) + if (v.userType() == QVariant::Color) tintColor = v.value<QColor>(); - else if (v.type() == QVariant::String) { + else if (v.userType() == QVariant::String) { bool ok; tintColor = QmlStringConverters::colorFromString(v.toString(), &ok); if (!ok) @@ -1037,7 +1037,7 @@ struct QmlEnginePrivate::ImportedNamespace { if (isBuiltin.at(i)) { QByteArray qt = urls.at(i).toUtf8(); - qt += "/"; + qt += '/'; qt += type; QmlType *t = QmlMetaType::qmlType(qt,vmaj,vmin); if (vmajor) *vmajor = vmaj; @@ -1048,7 +1048,7 @@ struct QmlEnginePrivate::ImportedNamespace { return true; } } else { - QUrl url = QUrl(urls.at(i) + QLatin1String("/") + QString::fromUtf8(type) + QLatin1String(".qml")); + QUrl url = QUrl(urls.at(i) + QLatin1Char('/') + QString::fromUtf8(type) + QLatin1String(".qml")); QString qmldircontent = qmlDirContent.at(i); if (vmaj || vmin || !qmldircontent.isEmpty()) { // Check version file - XXX cache these in QmlEngine! @@ -1167,7 +1167,7 @@ public: if (s->find(unqualifiedtype,vmajor,vminor,type_return,url_return)) return true; if (s->urls.count() == 1 && !s->isBuiltin[0] && !s->isLibrary[0] && url_return) { - *url_return = QUrl(s->urls[0]+QLatin1String("/")).resolved(QUrl(QString::fromUtf8(unqualifiedtype) + QLatin1String(".qml"))); + *url_return = QUrl(s->urls[0]+QLatin1Char('/')).resolved(QUrl(QString::fromUtf8(unqualifiedtype) + QLatin1String(".qml"))); return true; } } @@ -1188,7 +1188,7 @@ public: int ref; private: - friend class QmlEnginePrivate::Imports; + friend struct QmlEnginePrivate::Imports; QmlEnginePrivate::ImportedNamespace unqualifiedset; QHash<QString,QmlEnginePrivate::ImportedNamespace* > set; }; @@ -1233,7 +1233,7 @@ static QmlTypeNameCache *cacheForNamespace(QmlEngine *engine, const QmlEnginePri if (!set.isBuiltin.at(ii)) continue; - QByteArray base = set.urls.at(ii).toUtf8() + "/"; + QByteArray base = set.urls.at(ii).toUtf8() + '/'; int major = set.majversions.at(ii); int minor = set.minversions.at(ii); @@ -1375,7 +1375,7 @@ bool QmlEnginePrivate::addToImport(Imports* imports, const QString& qmldirconten { bool ok = imports->d->add(imports->d->base,qmldircontent,uri,prefix,vmaj,vmin,importType,fileImportPath); if (qmlImportTrace()) - qDebug() << "QmlEngine::addToImport(" << imports << uri << prefix << vmaj << "." << vmin << (importType==QmlScriptParser::Import::Library? "Library" : "File") << ": " << ok; + qDebug() << "QmlEngine::addToImport(" << imports << uri << prefix << vmaj << '.' << vmin << (importType==QmlScriptParser::Import::Library? "Library" : "File") << ": " << ok; return ok; } @@ -1405,9 +1405,9 @@ bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& typ if (imports.d->find(type,vmaj,vmin,type_return,url_return)) { if (qmlImportTrace()) { if (type_return && *type_return) - qDebug() << "QmlEngine::resolveType" << type << "=" << (*type_return)->typeName(); + qDebug() << "QmlEngine::resolveType" << type << '=' << (*type_return)->typeName(); if (url_return) - qDebug() << "QmlEngine::resolveType" << type << "=" << *url_return; + qDebug() << "QmlEngine::resolveType" << type << '=' << *url_return; } return true; } @@ -1451,7 +1451,7 @@ void QmlEnginePrivate::registerCompositeType(QmlCompiledData *data) { QByteArray name = data->root->className(); - QByteArray ptr = name + "*"; + QByteArray ptr = name + '*'; QByteArray lst = "QmlList<" + ptr + ">*"; int ptr_type = QMetaType::registerType(ptr.constData(), voidptr_destructor, diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp index 034e4f5..6cb57b2 100644 --- a/src/declarative/qml/qmlenginedebug.cpp +++ b/src/declarative/qml/qmlenginedebug.cpp @@ -115,7 +115,7 @@ QmlEngineDebugServer::propertyData(QObject *obj, int propIdx) QVariant value = prop.read(obj); rv.value = valueContents(value); - if (prop.type() < QVariant::UserType) { + if (prop.userType() < QVariant::UserType) { rv.type = QmlObjectProperty::Basic; } else if (QmlMetaType::isObject(prop.userType())) { rv.type = QmlObjectProperty::Object; @@ -129,10 +129,10 @@ QmlEngineDebugServer::propertyData(QObject *obj, int propIdx) QVariant QmlEngineDebugServer::valueContents(const QVariant &value) const { - if (value.type() < QVariant::UserType) + int userType = value.userType(); + if (userType < QVariant::UserType) return value; - int userType = value.userType(); if (QmlMetaType::isList(userType) || QmlMetaType::isQmlList(userType)) { int count = QmlMetaType::listCount(value); @@ -189,7 +189,7 @@ void QmlEngineDebugServer::buildObjectDump(QDataStream &message, prop.value = expr->expression(); QObject *scope = expr->scopeObject(); if (scope) { - QString sig = scope->metaObject()->method(signal->index()).signature(); + QString sig = QLatin1String(scope->metaObject()->method(signal->index()).signature()); int lparen = sig.indexOf(QLatin1Char('(')); if (lparen >= 0) { QString methodName = sig.mid(0, lparen); @@ -280,7 +280,7 @@ QmlEngineDebugServer::objectData(QObject *object) QmlType *type = QmlMetaType::qmlType(object->metaObject()); if (type) { - QString typeName = type->qmlTypeName(); + QString typeName = QLatin1String(type->qmlTypeName()); int lastSlash = typeName.lastIndexOf(QLatin1Char('/')); rv.objectType = lastSlash < 0 ? typeName : typeName.mid(lastSlash+1); } else { diff --git a/src/declarative/qml/qmlerror.cpp b/src/declarative/qml/qmlerror.cpp index 7cb68cf..d9ca20d 100644 --- a/src/declarative/qml/qmlerror.cpp +++ b/src/declarative/qml/qmlerror.cpp @@ -196,9 +196,9 @@ void QmlError::setColumn(int column) QString QmlError::toString() const { QString rv; - rv = url().toString() + QLatin1String(":") + QString::number(line()); + rv = url().toString() + QLatin1Char(':') + QString::number(line()); if(column() != -1) - rv += QLatin1String(":") + QString::number(column()); + rv += QLatin1Char(':') + QString::number(column()); rv += QLatin1String(": ") + description(); diff --git a/src/declarative/qml/qmlexpression.h b/src/declarative/qml/qmlexpression.h index c019f21..4fdfc3f 100644 --- a/src/declarative/qml/qmlexpression.h +++ b/src/declarative/qml/qmlexpression.h @@ -92,7 +92,7 @@ public Q_SLOTS: QVariant value(bool *isUndefined = 0); Q_SIGNALS: - virtual void valueChanged(); + void valueChanged(); protected: QmlExpression(QmlContext *, const QString &, QObject *, diff --git a/src/declarative/qml/qmlglobalscriptclass.cpp b/src/declarative/qml/qmlglobalscriptclass.cpp index 478a874..5387e03 100644 --- a/src/declarative/qml/qmlglobalscriptclass.cpp +++ b/src/declarative/qml/qmlglobalscriptclass.cpp @@ -97,7 +97,7 @@ void QmlGlobalScriptClass::setProperty(QScriptValue &object, Q_UNUSED(id); Q_UNUSED(value); QString error = QLatin1String("Invalid write to global property \"") + - name.toString() + QLatin1String("\""); + name.toString() + QLatin1Char('\"'); engine()->currentContext()->throwError(error); } diff --git a/src/declarative/qml/qmlinfo.cpp b/src/declarative/qml/qmlinfo.cpp index 2dbc968..27f5426 100644 --- a/src/declarative/qml/qmlinfo.cpp +++ b/src/declarative/qml/qmlinfo.cpp @@ -44,7 +44,7 @@ #include "qmldeclarativedata_p.h" #include "qmlcontext.h" -#include <QtGui/qapplication.h> +#include <QCoreApplication> QT_BEGIN_NAMESPACE @@ -88,17 +88,17 @@ QmlInfo::QmlInfo(const QObject *object) if (ddata) { if (ddata->outerContext) { pos += ddata->outerContext->baseUrl().toString(); - pos += QLatin1String(":"); + pos += QLatin1Char(':'); pos += QString::number(ddata->lineNumber); - pos += QLatin1String(":"); + pos += QLatin1Char(':'); pos += QString::number(ddata->columnNumber); } else { - pos += qApp->translate("QmlInfo","unknown location"); + pos += QCoreApplication::translate("QmlInfo","unknown location"); } } else { - pos += qApp->translate("QmlInfo","unknown location"); + pos += QCoreApplication::translate("QmlInfo","unknown location"); } - pos += QLatin1String(")"); + pos += QLatin1Char(')'); *this << pos; nospace(); } diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 2b3b385..a1ea90d 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -455,7 +455,7 @@ QString QmlMetaProperty::name() const // ### if (!d->object) { } else if (type() & ValueTypeProperty) { - QString rv = d->core.name(d->object) + QLatin1String("."); + QString rv = d->core.name(d->object) + QLatin1Char('.'); QmlEnginePrivate *ep = d->context?QmlEnginePrivate::get(d->context->engine()):0; QmlValueType *valueType = 0; @@ -724,16 +724,16 @@ bool QmlMetaPropertyPrivate::writeEnumProperty(const QMetaProperty &prop, int id QVariant v = value; if (prop.isEnumType()) { QMetaEnum menum = prop.enumerator(); - if (v.type() == QVariant::String + if (v.userType() == QVariant::String #ifdef QT3_SUPPORT - || v.type() == QVariant::CString + || v.userType() == QVariant::CString #endif ) { if (prop.isFlagType()) v = QVariant(menum.keysToValue(value.toByteArray())); else v = QVariant(menum.keyToValue(value.toByteArray())); - } else if (v.type() != QVariant::Int && v.type() != QVariant::UInt) { + } else if (v.userType() != QVariant::Int && v.userType() != QVariant::UInt) { int enumMetaTypeId = QMetaType::type(QByteArray(menum.scope()) + "::" + menum.name()); if ((enumMetaTypeId == 0) || (v.userType() != enumMetaTypeId) || !v.constData()) return false; @@ -803,7 +803,7 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data QMetaProperty prop = object->metaObject()->property(property.coreIndex); QVariant v = value; // Enum values come through the script engine as doubles - if (value.type() == QVariant::Double) { + if (value.userType() == QVariant::Double) { double integral; double fractional = modf(value.toDouble(), &integral); if (qFuzzyCompare(fractional, (double)0.0)) diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp index edf8974..fbb3952 100644 --- a/src/declarative/qml/qmlmetatype.cpp +++ b/src/declarative/qml/qmlmetatype.cpp @@ -460,7 +460,7 @@ int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Fun QByteArray name = uri; if (uri) - name += "/"; + name += '/'; name += cname; name.replace('.','/'); diff --git a/src/declarative/qml/qmlmetatype.h b/src/declarative/qml/qmlmetatype.h index d17b44f..e0c65c5 100644 --- a/src/declarative/qml/qmlmetatype.h +++ b/src/declarative/qml/qmlmetatype.h @@ -151,7 +151,7 @@ public: private: friend class QmlMetaType; friend class QmlTypePrivate; - friend class QmlMetaTypeData; + friend struct QmlMetaTypeData; QmlType(int, int, int, QmlPrivate::Func, const char *, int); QmlType(int, int, int, QmlPrivate::Func, const char *, int, int, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int, int, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *); ~QmlType(); @@ -164,7 +164,7 @@ int qmlRegisterType(const char *typeName) { QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { - qRegisterMetaType<T *>(QByteArray(name + "*").constData()), + qRegisterMetaType<T *>(QByteArray(name + '*').constData()), qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()), qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData()) }; @@ -185,7 +185,7 @@ int qmlRegisterType(const char *uri, int version_maj, int version_min, const cha { QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { - qRegisterMetaType<T *>(QByteArray(name + "*").constData()), + qRegisterMetaType<T *>(QByteArray(name + '*').constData()), qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()), qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData()) }; @@ -207,7 +207,7 @@ int qmlRegisterExtendedType(const char *typeName) { QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { - qRegisterMetaType<T *>(QByteArray(name + "*").constData()), + qRegisterMetaType<T *>(QByteArray(name + '*').constData()), qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()), qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData()) }; @@ -235,7 +235,7 @@ int qmlRegisterExtendedType(const char *uri, int version_maj, int version_min, c { QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { - qRegisterMetaType<T *>(QByteArray(name + "*").constData()), + qRegisterMetaType<T *>(QByteArray(name + '*').constData()), qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()), qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData()) }; @@ -266,7 +266,7 @@ int qmlRegisterInterface(const char *typeName) { QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { - qRegisterMetaType<T *>(QByteArray(name + "*").constData()), + qRegisterMetaType<T *>(QByteArray(name + '*').constData()), qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()), qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData()) }; @@ -281,7 +281,7 @@ int qmlRegisterCustomType(const char *uri, int version_maj, int version_min, con { QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { - qRegisterMetaType<T *>(QByteArray(name + "*").constData()), + qRegisterMetaType<T *>(QByteArray(name + '*').constData()), qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()), qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData()) }; diff --git a/src/declarative/qml/qmlobjectscriptclass.cpp b/src/declarative/qml/qmlobjectscriptclass.cpp index 86ee29c..7a2b132 100644 --- a/src/declarative/qml/qmlobjectscriptclass.cpp +++ b/src/declarative/qml/qmlobjectscriptclass.cpp @@ -307,10 +307,10 @@ QScriptValue QmlObjectScriptClass::tostring(QScriptContext *context, QScriptEngi if (!objectName.isEmpty()) { ret += QLatin1String(", \""); ret += objectName; - ret += QLatin1String("\""); + ret += QLatin1Char('\"'); } - ret += QLatin1String(")"); + ret += QLatin1Char(')'); }else{ ret += QLatin1String("null"); } diff --git a/src/declarative/qml/qmlsqldatabase.cpp b/src/declarative/qml/qmlsqldatabase.cpp index be6ef16..2efe988 100644 --- a/src/declarative/qml/qmlsqldatabase.cpp +++ b/src/declarative/qml/qmlsqldatabase.cpp @@ -196,6 +196,11 @@ static QScriptValue qmlsqldatabase_item(QScriptContext *context, QScriptEngine * return engine->undefinedValue(); } +static QScriptValue qmlsqldatabase_executeSql_outsidetransaction(QScriptContext *context, QScriptEngine * /*engine*/) +{ + THROW_SQL(DATABASE_ERR,QmlEngine::tr("executeSql called outside transaction()")); +} + static QScriptValue qmlsqldatabase_executeSql(QScriptContext *context, QScriptEngine *engine) { QSqlDatabase db = qscriptvalue_cast<QSqlDatabase>(context->thisObject()); @@ -262,8 +267,9 @@ static QScriptValue qmlsqldatabase_change_version(QScriptContext *context, QScri instance.setProperty(QLatin1String("executeSql"), engine->newFunction(qmlsqldatabase_executeSql,1)); QScriptValue tx = engine->newVariant(instance,qVariantFromValue(db)); - if (from_version!=context->thisObject().property(QLatin1String("version")).toString()) { - THROW_SQL(2,QmlEngine::tr("Version mismatch")); + QString foundvers = context->thisObject().property(QLatin1String("version")).toString(); + if (from_version!=foundvers) { + THROW_SQL(2,QmlEngine::tr("Version mismatch: expected %1, found %2").arg(from_version).arg(foundvers)); return engine->undefinedValue(); } @@ -307,6 +313,8 @@ static QScriptValue qmlsqldatabase_transaction_shared(QScriptContext *context, Q db.transaction(); callback.call(QScriptValue(), QScriptValueList() << tx); + instance.setProperty(QLatin1String("executeSql"), + engine->newFunction(qmlsqldatabase_executeSql_outsidetransaction)); if (engine->hasUncaughtException()) { db.rollback(); } else { diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index 116163a..e3fc288 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -71,7 +71,7 @@ #include <QRectF> #include <QtCore/qdebug.h> #include <QtCore/qvarlengtharray.h> -#include <QtGui/qapplication.h> +#include <QtCore/qcoreapplication.h> QT_BEGIN_NAMESPACE @@ -194,7 +194,7 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt, if(types.at(instr.create.type).component) vmeErrors << types.at(instr.create.type).component->errors(); - VME_EXCEPTION(qApp->translate("QmlVME","Unable to create object of type %1").arg(QString::fromLatin1(types.at(instr.create.type).className))); + VME_EXCEPTION(QCoreApplication::translate("QmlVME","Unable to create object of type %1").arg(QString::fromLatin1(types.at(instr.create.type).className))); } QmlDeclarativeData *ddata = QmlDeclarativeData::get(o); @@ -500,7 +500,7 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt, QMetaProperty prop = target->metaObject()->property(instr.assignCustomType.propertyIndex); if (v.isNull() || ((int)prop.type() != data.type && prop.userType() != data.type)) - VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign value %1 to property %2").arg(primitive).arg(QString::fromUtf8(prop.name()))); + VME_EXCEPTION(QCoreApplication::translate("QmlVME","Cannot assign value %1 to property %2").arg(primitive).arg(QString::fromUtf8(prop.name()))); void *a[] = { (void *)v.data(), 0, &status, &flags }; QMetaObject::metacall(target, QMetaObject::WriteProperty, @@ -522,15 +522,15 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt, QMetaMethod method = QmlMetaType::defaultMethod(assign); if (method.signature() == 0) - VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign object type %1 with no default method").arg(QString::fromLatin1(assign->metaObject()->className()))); + VME_EXCEPTION(QCoreApplication::translate("QmlVME","Cannot assign object type %1 with no default method").arg(QString::fromLatin1(assign->metaObject()->className()))); if (!QMetaObject::checkConnectArgs(prop.method().signature(), method.signature())) - VME_EXCEPTION(qApp->translate("QmlVME","Cannot connect mismatched signal/slot %1 %vs. %2").arg(QString::fromLatin1(method.signature())).arg(QString::fromLatin1(prop.method().signature()))); + VME_EXCEPTION(QCoreApplication::translate("QmlVME","Cannot connect mismatched signal/slot %1 %vs. %2").arg(QString::fromLatin1(method.signature())).arg(QString::fromLatin1(prop.method().signature()))); QMetaObject::connect(target, prop.coreIndex(), assign, method.methodIndex()); } else { - VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign an object to signal property %1").arg(QString::fromUtf8(pr))); + VME_EXCEPTION(QCoreApplication::translate("QmlVME","Cannot assign an object to signal property %1").arg(QString::fromUtf8(pr))); } @@ -704,7 +704,7 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt, if (iid) ptr = assign->qt_metacast(iid); if (!ptr) - VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign object to list")); + VME_EXCEPTION(QCoreApplication::translate("QmlVME","Cannot assign object to list")); if (list.qmlListInterface) { @@ -750,7 +750,7 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt, } if (!ok) - VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign object to interface property")); + VME_EXCEPTION(QCoreApplication::translate("QmlVME","Cannot assign object to interface property")); } break; @@ -761,7 +761,7 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt, QObject *qmlObject = qmlAttachedPropertiesObjectById(instr.fetchAttached.id, target); if (!qmlObject) - VME_EXCEPTION(qApp->translate("QmlVME","Unable to create attached object")); + VME_EXCEPTION(QCoreApplication::translate("QmlVME","Unable to create attached object")); stack.push(qmlObject); } @@ -779,7 +779,7 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt, QMetaObject::metacall(target, QMetaObject::ReadProperty, instr.fetchQmlList.property, a); if (!list) - VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign to null list")); + VME_EXCEPTION(QCoreApplication::translate("QmlVME","Cannot assign to null list")); qliststack.push(ListInstance(list, instr.fetchQmlList.type)); } @@ -797,7 +797,7 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt, QMetaObject::metacall(target, QMetaObject::ReadProperty, instr.fetchQmlList.property, a); if (!list) - VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign to null list")); + VME_EXCEPTION(QCoreApplication::translate("QmlVME","Cannot assign to null list")); qliststack.push(ListInstance(list, instr.fetchQmlList.type)); } @@ -816,7 +816,7 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt, instr.fetch.property, a); if (!obj) - VME_EXCEPTION(qApp->translate("QmlVME","Cannot set properties on %1 as it is null").arg(QString::fromUtf8(target->metaObject()->property(instr.fetch.property).name()))); + VME_EXCEPTION(QCoreApplication::translate("QmlVME","Cannot set properties on %1 as it is null").arg(QString::fromUtf8(target->metaObject()->property(instr.fetch.property).name()))); stack.push(obj); } diff --git a/src/declarative/qml/qmlworkerscript.cpp b/src/declarative/qml/qmlworkerscript.cpp index 2a3dbce..2e1f16b 100644 --- a/src/declarative/qml/qmlworkerscript.cpp +++ b/src/declarative/qml/qmlworkerscript.cpp @@ -276,7 +276,7 @@ QVariant QmlWorkerScriptEnginePrivate::scriptValueToVariant(const QScriptValue & } else if (value.isArray()) { QVariantList list; - quint32 length = (quint32)value.property("length").toNumber(); + quint32 length = (quint32)value.property(QLatin1String("length")).toNumber(); for (quint32 ii = 0; ii < length; ++ii) { QVariant v = scriptValueToVariant(ii); @@ -303,21 +303,21 @@ QVariant QmlWorkerScriptEnginePrivate::scriptValueToVariant(const QScriptValue & QScriptValue QmlWorkerScriptEnginePrivate::variantToScriptValue(const QVariant &value, QScriptEngine *engine) { - if (value.type() == QVariant::Bool) { + if (value.userType() == QVariant::Bool) { return QScriptValue(value.toBool()); - } else if (value.type() == QVariant::String) { + } else if (value.userType() == QVariant::String) { return QScriptValue(value.toString()); - } else if (value.type() == (QVariant::Type)QMetaType::QReal) { + } else if (value.userType() == QMetaType::QReal) { return QScriptValue(value.toReal()); - } else if (value.type() == (QVariant::Type)QMetaType::QVariantList) { + } else if (value.userType() == QMetaType::QVariantList) { QVariantList list = qvariant_cast<QVariantList>(value); QScriptValue rv = engine->newArray(list.count()); - for (quint32 ii = 0; ii < list.count(); ++ii) + for (quint32 ii = 0; ii < quint32(list.count()); ++ii) rv.setProperty(ii, variantToScriptValue(list.at(ii), engine)); return rv; - } else if (value.type() == (QVariant::Type)QMetaType::QVariantHash) { + } else if (value.userType() == QMetaType::QVariantHash) { QVariantHash hash = qvariant_cast<QVariantHash>(value); diff --git a/src/declarative/qml/qmlworkerscript_p.h b/src/declarative/qml/qmlworkerscript_p.h index 51efc4b..1ec7af3 100644 --- a/src/declarative/qml/qmlworkerscript_p.h +++ b/src/declarative/qml/qmlworkerscript_p.h @@ -84,8 +84,9 @@ private: class QmlWorkerScript : public QObject, public QmlParserStatus { Q_OBJECT - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged); + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_INTERFACES(QmlParserStatus) public: QmlWorkerScript(QObject *parent = 0); virtual ~QmlWorkerScript(); diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp index d1705a1..a5d6cd7 100644 --- a/src/declarative/qml/qmlxmlhttprequest.cpp +++ b/src/declarative/qml/qmlxmlhttprequest.cpp @@ -1053,7 +1053,7 @@ void QmlXMLHttpRequest::addHeader(const QString &name, const QString &value) QByteArray utfname = name.toUtf8(); if (m_request.hasRawHeader(utfname)) { - m_request.setRawHeader(utfname, m_request.rawHeader(utfname) + "," + value.toUtf8()); + m_request.setRawHeader(utfname, m_request.rawHeader(utfname) + ',' + value.toUtf8()); } else { m_request.setRawHeader(utfname, value.toUtf8()); } diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 0f5a0f0..00e3056 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -1341,7 +1341,7 @@ QmlNumberAnimation::~QmlNumberAnimation() qreal QmlNumberAnimation::from() const { Q_D(const QmlPropertyAnimation); - return d->from.toDouble(); + return d->from.toReal(); } void QmlNumberAnimation::setFrom(qreal f) @@ -1357,7 +1357,7 @@ void QmlNumberAnimation::setFrom(qreal f) qreal QmlNumberAnimation::to() const { Q_D(const QmlPropertyAnimation); - return d->to.toDouble(); + return d->to.toReal(); } void QmlNumberAnimation::setTo(qreal t) @@ -1532,7 +1532,7 @@ QML_DEFINE_TYPE(Qt,4,6,ParallelAnimation,QmlParallelAnimation) //convert a variant from string type to another animatable type void QmlPropertyAnimationPrivate::convertVariant(QVariant &variant, int type) { - if (variant.type() != QVariant::String) { + if (variant.userType() != QVariant::String) { variant.convert((QVariant::Type)type); return; } diff --git a/src/declarative/util/qmlanimation_p_p.h b/src/declarative/util/qmlanimation_p_p.h index 0b65c27..71b6caa 100644 --- a/src/declarative/util/qmlanimation_p_p.h +++ b/src/declarative/util/qmlanimation_p_p.h @@ -160,7 +160,7 @@ protected: virtual void updateCurrentValue(const QVariant &value) { if (animValue) - animValue->setValue(value.toDouble()); + animValue->setValue(value.toReal()); } virtual void updateState(State newState, State oldState) { diff --git a/src/declarative/util/qmllistaccessor.cpp b/src/declarative/util/qmllistaccessor.cpp index 1e051b7..00b8220 100644 --- a/src/declarative/util/qmllistaccessor.cpp +++ b/src/declarative/util/qmllistaccessor.cpp @@ -73,9 +73,9 @@ void QmlListAccessor::setList(const QVariant &v, QmlEngine *engine) if (!d.isValid()) { m_type = Invalid; - } else if (d.type() == QVariant::StringList) { + } else if (d.userType() == QVariant::StringList) { m_type = StringList; - } else if (d.type() == (QVariant::Type)QMetaType::QVariantList) { + } else if (d.userType() == QMetaType::QVariantList) { m_type = VariantList; } else if (d.canConvert(QVariant::Int)) { m_type = Integer; diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index 2678de7..995a7a4 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -445,6 +445,7 @@ void QmlListModel::clear() _root = 0; roleStrings.clear(); emit itemsRemoved(0,cleared); + emit countChanged(0); } /*! @@ -901,7 +902,7 @@ static void dump(ModelNode *node, int ind) } for (QHash<QString, ModelNode *>::ConstIterator iter = node->properties.begin(); iter != node->properties.end(); ++iter) { - qWarning().nospace() << indent << "Property " << iter.key() << ":"; + qWarning().nospace() << indent << "Property " << iter.key() << ':'; dump(iter.value(), ind + 1); } } diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp index b9ec67a..48e026e 100644 --- a/src/declarative/util/qmlpropertychanges.cpp +++ b/src/declarative/util/qmlpropertychanges.cpp @@ -209,7 +209,7 @@ QmlPropertyChangesParser::compileList(QList<QPair<QByteArray, QVariant> > &list, QmlCustomParserProperty prop = qvariant_cast<QmlCustomParserProperty>(value); - QByteArray pre = propName + "."; + QByteArray pre = propName + '.'; compileList(list, pre, prop); } else { @@ -384,7 +384,7 @@ QmlPropertyChanges::ActionList QmlPropertyChanges::actions() a.restore = restoreEntryValues(); if (a.property.propertyType() == QVariant::Url && - (a.toValue.type() == QVariant::String || a.toValue.type() == QVariant::ByteArray) && !a.toValue.isNull()) + (a.toValue.userType() == QVariant::String || a.toValue.userType() == QVariant::ByteArray) && !a.toValue.isNull()) a.toValue.setValue(qmlContext(this)->resolvedUrl(QUrl(a.toValue.toString()))); list << a; diff --git a/src/declarative/util/qmlspringfollow.cpp b/src/declarative/util/qmlspringfollow.cpp index 29dcf91..764d7f9 100644 --- a/src/declarative/util/qmlspringfollow.cpp +++ b/src/declarative/util/qmlspringfollow.cpp @@ -200,7 +200,7 @@ void QmlSpringFollowPrivate::start() property.write(currentValue); } else if (sourceValue != currentValue && clock.state() != QAbstractAnimation::Running) { lastTime = 0; - currentValue = property.read().toDouble(); + currentValue = property.read().toReal(); clock.start(); // infinity?? emit q->syncChanged(); } @@ -258,7 +258,7 @@ void QmlSpringFollow::setTarget(const QmlMetaProperty &property) { Q_D(QmlSpringFollow); d->property = property; - d->currentValue = property.read().toDouble(); + d->currentValue = property.read().toReal(); } qreal QmlSpringFollow::sourceValue() const diff --git a/src/declarative/util/qmlsystempalette.cpp b/src/declarative/util/qmlsystempalette.cpp index d43a971..39d8f3e 100644 --- a/src/declarative/util/qmlsystempalette.cpp +++ b/src/declarative/util/qmlsystempalette.cpp @@ -80,7 +80,7 @@ QmlSystemPalette::QmlSystemPalette(QObject *parent) : QObject(*(new QmlSystemPalettePrivate), parent) { Q_D(QmlSystemPalette); - d->palette = qApp->palette(); + d->palette = QApplication::palette(); d->group = QPalette::Active; qApp->installEventFilter(this); } @@ -293,7 +293,7 @@ bool QmlSystemPalette::event(QEvent *event) { Q_D(QmlSystemPalette); if (event->type() == QEvent::ApplicationPaletteChange) { - d->palette = qApp->palette(); + d->palette = QApplication::palette(); emit paletteChanged(); return true; } diff --git a/src/declarative/util/qmlxmllistmodel.cpp b/src/declarative/util/qmlxmllistmodel.cpp index 6f8da9c..46ef739 100644 --- a/src/declarative/util/qmlxmllistmodel.cpp +++ b/src/declarative/util/qmlxmllistmodel.cpp @@ -259,7 +259,7 @@ void QmlXmlQuery::doQueryJob() QXmlResultItems result; QXmlQuery countquery; countquery.bindVariable(QLatin1String("inputDocument"), &b); - countquery.setQuery(namespaces + QLatin1String("count(") + prefix + QLatin1String(")")); + countquery.setQuery(namespaces + QLatin1String("count(") + prefix + QLatin1Char(')')); countquery.evaluateTo(&result); QXmlItem item(result.next()); if (item.isAtomicValue()) @@ -267,7 +267,7 @@ void QmlXmlQuery::doQueryJob() } //qDebug() << count; - m_prefix = namespaces + prefix + QLatin1String("/"); + m_prefix = namespaces + prefix + QLatin1Char('/'); m_data = xml; if (count > 0) m_size = count; diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp index fb8bfb3..c3c7977 100644 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp @@ -106,6 +106,7 @@ private slots: void signalTriggeredBindings(); void listProperties(); void exceptionClearsOnReeval(); + void exceptionProducesWarning(); void transientErrors(); void shutdownErrors(); void externalScript(); @@ -909,6 +910,18 @@ void tst_qmlecmascript::exceptionClearsOnReeval() QCOMPARE(object->property("test").toBool(), true); } +void tst_qmlecmascript::exceptionProducesWarning() +{ + QmlComponent component(&engine, TEST_FILE("exceptionProducesWarning.qml")); + QString url = component.url().toString(); + + QString warning = "Expected error - QTBUG-6507"; + + QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); + MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); + QVERIFY(object != 0); +} + static int transientErrorsMsgCount = 0; static void transientErrorsMsgHandler(QtMsgType, const char *) { diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp index 0a86ecc..7b5cfc0 100644 --- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp +++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp @@ -443,7 +443,7 @@ void tst_QmlGraphicsListView::inserted() // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); - QVERIFY(item->y() == i*20); + QCOMPARE(item->y(), i*20.0); } model.insertItem(0, "Foo", "1111"); // zero index, and current item @@ -465,7 +465,7 @@ void tst_QmlGraphicsListView::inserted() // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); - QVERIFY(item->y() == i*20); + QCOMPARE(item->y(), i*20.0); } for (int i = model.count(); i < 30; ++i) @@ -482,10 +482,11 @@ void tst_QmlGraphicsListView::inserted() QVERIFY(listview->viewportY() == 80); // Confirm items positioned correctly - int itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count() - 1; - for (int i = 5; i < 5+itemCount; ++i) { + for (int i = 5; i < 5+15; ++i) { QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); - QVERIFY(item->y() == i*20 - 20); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QCOMPARE(item->y(), i*20.0 - 20.0); } delete canvas; @@ -736,7 +737,7 @@ void tst_QmlGraphicsListView::moved() QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); - QVERIFY(item->y() == i*20 + 20); + QCOMPARE(item->y(), i*20.0 + 20); name = findItem<QmlGraphicsText>(viewport, "textName", i); QVERIFY(name != 0); QCOMPARE(name->text(), model.name(i)); @@ -756,7 +757,7 @@ void tst_QmlGraphicsListView::moved() QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); - QVERIFY(item->y() == i*20 + 20); + QCOMPARE(item->y(), i*20.0 + 20); name = findItem<QmlGraphicsText>(viewport, "textName", i); QVERIFY(name != 0); QCOMPARE(name->text(), model.name(i)); diff --git a/tests/auto/declarative/sql/data/error-outsidetransaction.js b/tests/auto/declarative/sql/data/error-outsidetransaction.js new file mode 100644 index 0000000..a7af3bd --- /dev/null +++ b/tests/auto/declarative/sql/data/error-outsidetransaction.js @@ -0,0 +1,17 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-data/error-notransaction", "1.0", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + var v; + + try { + db.transaction(function(tx) { v = tx }); + v.executeSql("SELECT 'bad'") + } catch (err) { + if (err.message == "executeSql called outside transaction()") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + + return r; +} diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp index 4296279..1e4e6f8 100644 --- a/tests/auto/declarative/sql/tst_sql.cpp +++ b/tests/auto/declarative/sql/tst_sql.cpp @@ -152,6 +152,7 @@ void tst_sql::testQml_data() QTest::newRow("iteration-forwardonly") << "data/iteration-forwardonly.js"; QTest::newRow("error-a") << "data/error-a.js"; QTest::newRow("error-notransaction") << "data/error-notransaction.js"; + QTest::newRow("error-outsidetransaction") << "data/error-outsidetransaction.js"; // reuse above QTest::newRow("reopen1") << "data/reopen1.js"; QTest::newRow("reopen2") << "data/reopen2.js"; // re-uses above DB diff --git a/tools/qmlviewer/content/Browser.qml b/tools/qmlviewer/content/Browser.qml new file mode 100644 index 0000000..ce9aed2 --- /dev/null +++ b/tools/qmlviewer/content/Browser.qml @@ -0,0 +1,233 @@ +import Qt 4.6 + +Rectangle { + id: root + property bool keyPressed: false + property var folders: folders1 + property var view: view1 + width: 320 + height: 480 + color: palette.window + FolderListModel { + id: folders1 + nameFilters: [ "*.qml" ] + folder: initialFolder + } + FolderListModel { + id: folders2 + nameFilters: [ "*.qml" ] + folder: initialFolder + } + + SystemPalette { id: palette } + + Script { + function down(path) { + if (folders == folders1) { + view = view2 + folders = folders2; + view1.state = "exitLeft"; + } else { + view = view1 + folders = folders1; + view2.state = "exitLeft"; + } + view.x = root.width; + view.state = "current"; + folders.folder = path; + } + function up() { + var path = folders.parentFolder; + if (folders == folders1) { + view = view2 + folders = folders2; + view1.state = "exitRight"; + } else { + view = view1 + folders = folders1; + view2.state = "exitRight"; + } + view.x = -root.width; + view.state = "current"; + folders.folder = path; + } + } + + Component { + id: folderDelegate + Rectangle { + id: wrapper + function launch() { + if (folders.isFolder(index)) { + down(filePath); + } else { + qmlViewer.launch(filePath); + } + } + width: root.width + height: 48 + color: "transparent" + Rectangle { + id: highlight; visible: false + anchors.fill: parent + gradient: Gradient { + GradientStop { id: t1; position: 0.0; color: palette.highlight } + GradientStop { id: t2; position: 1.0; color: Qt.lighter(palette.highlight) } + } + } + Item { + width: 46; height: 46 + Image { source: "images/folder.png"; anchors.centerIn: parent; visible: folders.isFolder(index)} + } + Text { + id: nameText + anchors.fill: parent; verticalAlignment: Text.AlignVCenter + text: fileName; anchors.leftMargin: 48 + font.pixelSize: 32 + color: wrapper.isCurrentItem ? palette.highlightedText : palette.text + } + MouseRegion { + id: mouseRegion + anchors.fill: parent + onClicked: { launch() } + } + states: [ + State { + name: "pressed" + when: mouseRegion.pressed + PropertyChanges { target: highlight; visible: true } + PropertyChanges { target: nameText; color: palette.highlightedText } + } + ] + } + } + + ListView { + id: view1 + anchors.top: titleBar.bottom + anchors.bottom: parent.bottom + x: 0 + width: parent.width + model: folders1 + delegate: folderDelegate + highlight: Rectangle { color: palette.highlight; visible: root.keyPressed } + focus: true + pressDelay: 100 + state: "current" + states: [ + State { + name: "current" + PropertyChanges { target: view1; x: 0 } + }, + State { + name: "exitLeft" + PropertyChanges { target: view1; x: -root.width } + }, + State { + name: "exitRight" + PropertyChanges { target: view1; x: root.width } + } + ] + transitions: [ + Transition { + to: "current" + SequentialAnimation { + NumberAnimation { matchProperties: "x"; duration: 250 } + } + }, + Transition { + NumberAnimation { matchProperties: "x"; duration: 250 } + NumberAnimation { matchProperties: "x"; duration: 250 } + } + ] + } + + ListView { + id: view2 + anchors.top: titleBar.bottom + anchors.bottom: parent.bottom + x: parent.width + width: parent.width + model: folders2 + delegate: folderDelegate + highlight: Rectangle { color: palette.highlight; visible: root.keyPressed } + focus: true + pressDelay: 100 + states: [ + State { + name: "current" + PropertyChanges { target: view2; x: 0 } + }, + State { + name: "exitLeft" + PropertyChanges { target: view2; x: -root.width } + }, + State { + name: "exitRight" + PropertyChanges { target: view2; x: root.width } + } + ] + transitions: [ + Transition { + to: "current" + SequentialAnimation { + NumberAnimation { matchProperties: "x"; duration: 250 } + } + }, + Transition { + NumberAnimation { matchProperties: "x"; duration: 250 } + } + ] + } + + Keys.onPressed: { + root.keyPressed = true; + if (event.key == Qt.Key_Return || event.key == Qt.Key_Select || event.key == Qt.Key_Right) { + view.currentItem.launch(); + event.accepted = true; + } + } + Keys.onLeftPressed: up() + + BorderImage { + source: "images/titlebar.sci"; + width: parent.width; + height: 52 + y: -7 + id: titleBar + + Rectangle { + id: upButton + width: 48 + height: titleBar.height - 7 + color: "transparent" + + Image { anchors.centerIn: parent; source: "images/up.png" } + MouseRegion { id: upRegion; anchors.fill: parent + onClicked: if (folders.parentFolder != "") up() + } + states: [ + State { + name: "pressed" + when: upRegion.pressed + PropertyChanges { target: upButton; color: palette.highlight } + } + ] + } + Rectangle { + color: "gray" + x: 48 + width: 1 + height: 44 + } + + Text { + anchors.left: upButton.right; anchors.right: parent.right; height: parent.height + anchors.leftMargin: 4; anchors.rightMargin: 4 + text: folders.folder + color: "white" + elide: Text.ElideLeft; horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter + font.pixelSize: 32 + } + } +} diff --git a/tools/qmlviewer/content/images/folder.png b/tools/qmlviewer/content/images/folder.png Binary files differnew file mode 100644 index 0000000..e53e2ad --- /dev/null +++ b/tools/qmlviewer/content/images/folder.png diff --git a/tools/qmlviewer/content/images/titlebar.png b/tools/qmlviewer/content/images/titlebar.png Binary files differnew file mode 100644 index 0000000..51c9008 --- /dev/null +++ b/tools/qmlviewer/content/images/titlebar.png diff --git a/tools/qmlviewer/content/images/titlebar.sci b/tools/qmlviewer/content/images/titlebar.sci new file mode 100644 index 0000000..0418d94 --- /dev/null +++ b/tools/qmlviewer/content/images/titlebar.sci @@ -0,0 +1,5 @@ +border.left: 10 +border.top: 12 +border.bottom: 12 +border.right: 10 +source: titlebar.png diff --git a/tools/qmlviewer/content/images/up.png b/tools/qmlviewer/content/images/up.png Binary files differnew file mode 100644 index 0000000..b05f802 --- /dev/null +++ b/tools/qmlviewer/content/images/up.png diff --git a/tools/qmlviewer/qmlfolderlistmodel.cpp b/tools/qmlviewer/qmlfolderlistmodel.cpp new file mode 100644 index 0000000..14d2324 --- /dev/null +++ b/tools/qmlviewer/qmlfolderlistmodel.cpp @@ -0,0 +1,388 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlfolderlistmodel.h" +#include <QDirModel> +#include <QDebug> +#include <QtDeclarative/qmlcontext.h> + +class QmlFolderListModelPrivate +{ +public: + QmlFolderListModelPrivate() + : sortField(QmlFolderListModel::Name), sortReversed(false), count(0) { + nameFilters << QLatin1String("*"); + } + + void updateSorting() { + QDir::SortFlags flags = 0; + switch(sortField) { + case QmlFolderListModel::Unsorted: + flags |= QDir::Unsorted; + break; + case QmlFolderListModel::Name: + flags |= QDir::Name; + break; + case QmlFolderListModel::Time: + flags |= QDir::Time; + break; + case QmlFolderListModel::Size: + flags |= QDir::Size; + break; + case QmlFolderListModel::Type: + flags |= QDir::Type; + break; + } + + if (sortReversed) + flags |= QDir::Reversed; + + model.setSorting(flags); + } + + QDirModel model; + QUrl folder; + QStringList nameFilters; + QModelIndex folderIndex; + QmlFolderListModel::SortField sortField; + bool sortReversed; + int count; +}; + +/*! + \qmlclass FolderListModel + \brief The FolderListModel provides a model of the contents of a folder in a filesystem. + + FolderListModel provides access to the local filesystem. The \e folder property + specifies the folder to list. + + Qt uses "/" as a universal directory separator in the same way that "/" is + used as a path separator in URLs. If you always use "/" as a directory + separator, Qt will translate your paths to conform to the underlying + operating system. + + The roles available are: + \list + \o fileName + \o filePath + \endlist + + Additionally a file entry can be differentiated from a folder entry + via the \l isFolder() method. +*/ + +QmlFolderListModel::QmlFolderListModel(QObject *parent) + : QListModelInterface(parent) +{ + d = new QmlFolderListModelPrivate; + d->model.setFilter(QDir::AllDirs | QDir::Files | QDir::Drives | QDir::NoDotAndDotDot); + connect(&d->model, SIGNAL(rowsInserted(const QModelIndex&,int,int)) + , this, SLOT(inserted(const QModelIndex&,int,int))); + connect(&d->model, SIGNAL(rowsRemoved(const QModelIndex&,int,int)) + , this, SLOT(removed(const QModelIndex&,int,int))); + connect(&d->model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)) + , this, SLOT(dataChanged(const QModelIndex&,const QModelIndex&))); + connect(&d->model, SIGNAL(modelReset()), this, SLOT(refresh())); + connect(&d->model, SIGNAL(layoutChanged()), this, SLOT(refresh())); +} + +QmlFolderListModel::~QmlFolderListModel() +{ + delete d; +} + +QHash<int,QVariant> QmlFolderListModel::data(int index, const QList<int> &roles) const +{ + Q_UNUSED(roles); + QHash<int,QVariant> folderData; + QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex); + if (modelIndex.isValid()) { + folderData[QDirModel::FileNameRole] = d->model.data(modelIndex, QDirModel::FileNameRole); + folderData[QDirModel::FilePathRole] = QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString()); + } + + return folderData; +} + +int QmlFolderListModel::count() const +{ + return d->count; +} + +QList<int> QmlFolderListModel::roles() const +{ + QList<int> r; + r << QDirModel::FileNameRole; + r << QDirModel::FilePathRole; + return r; +} + +QString QmlFolderListModel::toString(int role) const +{ + switch (role) { + case QDirModel::FileNameRole: + return QLatin1String("fileName"); + case QDirModel::FilePathRole: + return QLatin1String("filePath"); + } + + return QString(); +} + +/*! + \qmlproperty string FolderListModel::folder + + The \a folder property holds the folder the model is currently providing. + + It is a URL, but must be a file: or qrc: URL (or relative to such a URL). +*/ +QUrl QmlFolderListModel::folder() const +{ + return d->folder; +} + +void QmlFolderListModel::setFolder(const QUrl &folder) +{ + if (folder == d->folder) + return; + QModelIndex index = d->model.index(folder.toLocalFile()); + if (index.isValid() && d->model.isDir(index)) { + d->folder = folder; + QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); + emit folderChanged(); + } +} + +QUrl QmlFolderListModel::parentFolder() const +{ + int pos = d->folder.path().lastIndexOf(QLatin1Char('/')); + if (pos == -1) + return QUrl(); + QUrl r = d->folder; + r.setPath(d->folder.path().left(pos)); + return r; +} + +/*! + \qmlproperty list<string> FolderListModel::nameFilters + + The \a nameFilters property contains a list of filename filters. + The filters may include the ? and * wildcards. + + The example below filters on PNG and JPEG files: + + \code + FolderListModel { + nameFilters: [ "*.png", "*.jpg" ] + } + \endcode +*/ +QStringList QmlFolderListModel::nameFilters() const +{ + return d->nameFilters; +} + +void QmlFolderListModel::setNameFilters(const QStringList &filters) +{ + d->nameFilters = filters; + d->model.setNameFilters(d->nameFilters); +} + +void QmlFolderListModel::componentComplete() +{ + if (!d->folder.isValid() || !QDir().exists(d->folder.toLocalFile())) + setFolder(QUrl(QLatin1String("file://")+QDir::currentPath())); + + if (!d->folderIndex.isValid()) + QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); +} + +QmlFolderListModel::SortField QmlFolderListModel::sortField() const +{ + return d->sortField; +} + +void QmlFolderListModel::setSortField(SortField field) +{ + if (field != d->sortField) { + d->sortField = field; + d->updateSorting(); + } +} + +bool QmlFolderListModel::sortReversed() const +{ + return d->sortReversed; +} + +void QmlFolderListModel::setSortReversed(bool rev) +{ + if (rev != d->sortReversed) { + d->sortReversed = rev; + d->updateSorting(); + } +} + +/*! + \qmlmethod bool FolderListModel::isFolder(int index) + + Returns true if the entry \a index is a folder; otherwise + returns false. +*/ +bool QmlFolderListModel::isFolder(int index) const +{ + if (index != -1) { + QModelIndex idx = d->model.index(index, 0, d->folderIndex); + if (idx.isValid()) + return d->model.isDir(idx); + } + return false; +} + +void QmlFolderListModel::refresh() +{ + d->folderIndex = QModelIndex(); + if (d->count) { + int tmpCount = d->count; + d->count = 0; + emit itemsRemoved(0, tmpCount); + } + d->folderIndex = d->model.index(d->folder.toLocalFile()); + d->count = d->model.rowCount(d->folderIndex); + if (d->count) { + emit itemsInserted(0, d->count); + } +} + +void QmlFolderListModel::inserted(const QModelIndex &index, int start, int end) +{ + if (index == d->folderIndex) { + d->count = d->model.rowCount(d->folderIndex); + emit itemsInserted(start, end - start + 1); + } +} + +void QmlFolderListModel::removed(const QModelIndex &index, int start, int end) +{ + if (index == d->folderIndex) { + d->count = d->model.rowCount(d->folderIndex); + emit itemsRemoved(start, end - start + 1); + } +} + +void QmlFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end) +{ + qDebug() << "data changed"; + if (start.parent() == d->folderIndex) + emit itemsChanged(start.row(), end.row() - start.row() + 1, roles()); +} + +/*! + \qmlproperty bool FolderListModel::showDirs + + If true (the default), directories are included in the model. + + Note that the nameFilters are ignored for directories. +*/ +bool QmlFolderListModel::showDirs() const +{ + return d->model.filter() & QDir::AllDirs; +} + +void QmlFolderListModel::setShowDirs(bool on) +{ + if (!(d->model.filter() & QDir::AllDirs) == !on) + return; + if (on) + d->model.setFilter(d->model.filter() | QDir::AllDirs | QDir::Drives); + else + d->model.setFilter(d->model.filter() & ~(QDir::AllDirs | QDir::Drives)); +} + +/*! + \qmlproperty bool FolderListModel::showDotAndDotDot + + If true, the "." and ".." directories are included in the model. + + The default is false. +*/ +bool QmlFolderListModel::showDotAndDotDot() const +{ + return !(d->model.filter() & QDir::NoDotAndDotDot); +} + +void QmlFolderListModel::setShowDotAndDotDot(bool on) +{ + if (!(d->model.filter() & QDir::NoDotAndDotDot) == on) + return; + if (on) + d->model.setFilter(d->model.filter() & ~QDir::NoDotAndDotDot); + else + d->model.setFilter(d->model.filter() | QDir::NoDotAndDotDot); +} + +/*! + \qmlproperty bool FolderListModel::showOnlyReadable + + If true, only readable files and directories are shown. + + The default is false. +*/ +bool QmlFolderListModel::showOnlyReadable() const +{ + return d->model.filter() & QDir::Readable; +} + +void QmlFolderListModel::setShowOnlyReadable(bool on) +{ + if (!(d->model.filter() & QDir::Readable) == !on) + return; + if (on) + d->model.setFilter(d->model.filter() | QDir::Readable); + else + d->model.setFilter(d->model.filter() & ~QDir::Readable); +} + + +QML_DEFINE_TYPE(Qt,4,6,FolderListModel,QmlFolderListModel) + +QT_END_NAMESPACE + diff --git a/tools/qmlviewer/qmlfolderlistmodel.h b/tools/qmlviewer/qmlfolderlistmodel.h new file mode 100644 index 0000000..cbee8c7 --- /dev/null +++ b/tools/qmlviewer/qmlfolderlistmodel.h @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLFOLDERLISTMODEL_H +#define QMLFOLDERLISTMODEL_H + +#include <qml.h> +#include "../../src/declarative/3rdparty/qlistmodelinterface_p.h" + +class QmlContext; +class QModelIndex; + +class QmlFolderListModelPrivate; +class QmlFolderListModel : public QListModelInterface, public QmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QmlParserStatus) + + Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged) + Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged) + Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters) + Q_PROPERTY(SortField sortField READ sortField WRITE setSortField) + Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed) + Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs) + Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot) + Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable) + +public: + QmlFolderListModel(QObject *parent = 0); + ~QmlFolderListModel(); + + virtual QHash<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const; + virtual int count() const; + virtual QList<int> roles() const; + virtual QString toString(int role) const; + + QUrl folder() const; + void setFolder(const QUrl &folder); + + QUrl parentFolder() const; + + QStringList nameFilters() const; + void setNameFilters(const QStringList &filters); + + virtual void componentComplete(); + + Q_INVOKABLE bool isFolder(int index) const; + + enum SortField { Unsorted, Name, Time, Size, Type }; + SortField sortField() const; + void setSortField(SortField field); + Q_ENUMS(SortField) + + bool sortReversed() const; + void setSortReversed(bool rev); + + bool showDirs() const; + void setShowDirs(bool); + bool showDotAndDotDot() const; + void setShowDotAndDotDot(bool); + bool showOnlyReadable() const; + void setShowOnlyReadable(bool); + +Q_SIGNALS: + void folderChanged(); + +private Q_SLOTS: + void refresh(); + void inserted(const QModelIndex &index, int start, int end); + void removed(const QModelIndex &index, int start, int end); + void dataChanged(const QModelIndex &start, const QModelIndex &end); + +private: + Q_DISABLE_COPY(QmlFolderListModel) + QmlFolderListModelPrivate *d; +}; + +QML_DECLARE_TYPE(QmlFolderListModel) + +#endif // QMLFOLDERLISTMODEL_H diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 98a9702..8d8d66a 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -329,7 +329,7 @@ QString QmlViewer::getVideoFileName() QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) : QWidget(parent, flags), frame_stream(0), scaleSkin(true), mb(0) , portraitOrientation(0), landscapeOrientation(0) - , m_scriptOptions(0), tester(0) + , m_scriptOptions(0), tester(0), useQmlFileBrowser(true) { devicemode = false; skin = 0; @@ -714,10 +714,19 @@ void QmlViewer::reload() void QmlViewer::open() { QString cur = canvas->url().toLocalFile(); - QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), cur, tr("QML Files (*.qml)")); - if (!fileName.isEmpty()) { - QFileInfo fi(fileName); - openQml(fi.absoluteFilePath()); + if (useQmlFileBrowser) { +#ifdef Q_OS_SYMBIAN + canvas->rootContext()->setContextProperty("initialFolder", "E:\\"); // Documents on your S60 phone +#else + canvas->rootContext()->setContextProperty("initialFolder", QDir::currentPath()); +#endif + openQml("qrc:/content/Browser.qml"); + } else { + QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), cur, tr("QML Files (*.qml)")); + if (!fileName.isEmpty()) { + QFileInfo fi(fileName); + openQml(fi.absoluteFilePath()); + } } } @@ -726,6 +735,11 @@ void QmlViewer::executeErrors() if (tester) tester->executefailure(); } +void QmlViewer::launch(const QString& file_or_url) +{ + QMetaObject::invokeMethod(this, "openQml", Qt::QueuedConnection, Q_ARG(QString, file_or_url)); +} + void QmlViewer::openQml(const QString& file_or_url) { currentFileOrUrl = file_or_url; @@ -742,6 +756,8 @@ void QmlViewer::openQml(const QString& file_or_url) tester = new QmlGraphicsTester(m_script, m_scriptOptions, canvas); canvas->reset(); + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("qmlViewer", this); QString fileName = url.toLocalFile(); if (!fileName.isEmpty()) { @@ -752,7 +768,6 @@ void QmlViewer::openQml(const QString& file_or_url) return; } - QmlContext *ctxt = canvas->rootContext(); QDir dir(fi.path()+"/dummydata", "*.qml"); QStringList list = dir.entryList(); for (int i = 0; i < list.size(); ++i) { diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index 6e31db54..c7d5c24 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -105,6 +105,7 @@ public slots: void setScaleView(); void executeErrors(); void setSlowMode(bool); + void launch(const QString &); protected: virtual void keyPressEvent(QKeyEvent *); @@ -162,6 +163,8 @@ private: QString m_script; ScriptOptions m_scriptOptions; QmlGraphicsTester *tester; + + bool useQmlFileBrowser; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QmlViewer::ScriptOptions) diff --git a/tools/qmlviewer/qmlviewer.pro b/tools/qmlviewer/qmlviewer.pro index ce45ed0..2024cff 100644 --- a/tools/qmlviewer/qmlviewer.pro +++ b/tools/qmlviewer/qmlviewer.pro @@ -16,11 +16,14 @@ contains(QT_CONFIG, opengl) { HEADERS += qmlviewer.h \ proxysettings.h \ qfxtester.h \ - deviceorientation.h + deviceorientation.h \ + qmlfolderlistmodel.h SOURCES += main.cpp \ qmlviewer.cpp \ proxysettings.cpp \ - qfxtester.cpp + qfxtester.cpp \ + qmlfolderlistmodel.cpp +RESOURCES = qmlviewer.qrc maemo5 { SOURCES += deviceorientation_maemo.cpp } else { diff --git a/tools/qmlviewer/qmlviewer.qrc b/tools/qmlviewer/qmlviewer.qrc new file mode 100644 index 0000000..3a9e608 --- /dev/null +++ b/tools/qmlviewer/qmlviewer.qrc @@ -0,0 +1,9 @@ +<RCC> + <qresource prefix="/" > + <file>content/Browser.qml</file> + <file>content/images/up.png</file> + <file>content/images/folder.png</file> + <file>content/images/titlebar.sci</file> + <file>content/images/titlebar.png</file> + </qresource> +</RCC> |