QCollatorSortKey QCollator::sortKey(const QString &string) const { QVarLengthArray<wchar_t> original; stringToWCharArray(original, string); QVector<wchar_t> result(string.size()); size_t size = std::wcsxfrm(result.data(), original.constData(), string.size()); if (size > uint(result.size())) { result.resize(size+1); size = std::wcsxfrm(result.data(), original.constData(), string.size()); } result.resize(size+1); result[size] = 0; return QCollatorSortKey(new QCollatorSortKeyPrivate(result)); }
/* array = begin-array [ value *( value-separator value ) ] end-array */ bool Parser::parseArray() { BEGIN << "parseArray"; if (++nestingLevel > nestingLimit) { lastError = QJsonParseError::DeepNesting; return false; } int arrayOffset = reserveSpace(sizeof(QJsonPrivate::Array)); QVarLengthArray<QJsonPrivate::Value, 64> values; if (!eatSpace()) { lastError = QJsonParseError::UnterminatedArray; return false; } if (*json == EndArray) { nextToken(); } else { while (1) { QJsonPrivate::Value val; if (!parseValue(&val, arrayOffset)) return false; values.append(val); char token = nextToken(); if (token == EndArray) break; else if (token != ValueSeparator) { if (!eatSpace()) lastError = QJsonParseError::UnterminatedArray; else lastError = QJsonParseError::MissingValueSeparator; return false; } } } DEBUG << "size =" << values.size(); int table = arrayOffset; // finalize the object if (values.size()) { int tableSize = values.size()*sizeof(QJsonPrivate::Value); table = reserveSpace(tableSize); memcpy(data + table, values.constData(), tableSize); } QJsonPrivate::Array *a = (QJsonPrivate::Array *)(data + arrayOffset); a->tableOffset = table - arrayOffset; a->size = current - arrayOffset; a->is_object = false; a->length = values.size(); DEBUG << "current=" << current; END; --nestingLevel; return true; }
NATRON_NAMESPACE_ANONYMOUS_ENTER #if defined(Q_OS_WIN) static QString qSystemDirectory() { QVarLengthArray<wchar_t, MAX_PATH> fullPath; UINT retLen = ::GetSystemDirectoryW(fullPath.data(), MAX_PATH); if (retLen > MAX_PATH) { fullPath.resize(retLen); retLen = ::GetSystemDirectoryW(fullPath.data(), retLen); } if (!fullPath.constData()) { return QString(); } std::wstring ws(fullPath.constData(), retLen); return QString::fromStdWString(ws); }
static inline QString qSystemDirectory() { QVarLengthArray<wchar_t, MAX_PATH> fullPath; UINT retLen = ::GetSystemDirectory(fullPath.data(), MAX_PATH); if (retLen > MAX_PATH) { fullPath.resize(retLen); retLen = ::GetSystemDirectory(fullPath.data(), retLen); } // in some rare cases retLen might be 0 return QString::fromWCharArray(fullPath.constData(), int(retLen)); }
QVariant parseNumber() { QVarLengthArray<QChar> str; QChar c = next(); if(c == '-') { str.append(c); c = nextNoSkip(); } for(; c.isDigit(); c = nextNoSkip()) { str.append(c); } bool hasDecimal = false; if(c == '.') { str.append(c); hasDecimal = true; c = nextNoSkip(); for(; c.isDigit(); c = nextNoSkip()) { str.append(c); } } if(c == 'e' || c == 'E') { // Exponent. str.append(c); c = nextNoSkip(); if(c == '+' || c == '-') { str.append(c); c = nextNoSkip(); } for(; c.isDigit(); c = nextNoSkip()) { str.append(c); } } // Rewind one char (the loop was broken when a non-digit was read). pos--; skipWhite(); double value = QString(str.constData(), str.size()).toDouble(); if(hasDecimal) { return QVariant(value); } else { return QVariant(int(value)); } }
void QtBasicGraph::paintEvent(QPaintEvent *e) { QPainter p(this); if (m_render_hints) p.setRenderHints(m_render_hints); p.fillRect(e->rect(), palette().background()); if (m_values.size() < 2) return; p.setPen(palette().color(QPalette::Text)); qreal scalex = qreal(width()) / m_xrange; qreal scaley = qreal(height()) / (m_ymax - m_ymin); qreal dx = qreal(3) / scalex; qreal dy = qreal(3) / scaley; QRectF bound(e->rect().x() / scalex, m_ymin + e->rect().y() / scaley, e->rect().width() / scalex, e->rect().height() / scaley); QPointF last = m_values.last(); qreal tx = m_xrange - last.x(); qreal ty = m_ymin; p.scale(scalex, -scaley); p.translate(tx, ty); QVarLengthArray<QLineF> lines; for (int i = m_values.size() - 1; i >= 0; --i) { QPointF pt = m_values[i]; QRectF linerect(last, pt); linerect = linerect.normalized().translated(tx, 0); linerect.adjust(-dx, -dy, dx, dy); if (bound.intersects(linerect)) lines.append(QLineF(last, pt)); last = pt; } // if (lines.size() < (m_values.size()-1)) // qWarning("skipped %d lines", (m_values.size()-1) -lines.size()); p.drawLines(lines.constData(), lines.size()); }
QVariant parseString() { QVarLengthArray<QChar, 1024> result; QChar c = next(); DENG2_ASSERT(c == '\"'); forever { c = nextNoSkip(); if(c == '\\') { // Escape. c = nextNoSkip(); if(c == '\"' || c == '\\' || c == '/') result.append(c); else if(c == 'b') result.append('\b'); else if(c == 'f') result.append('\f'); else if(c == 'n') result.append('\n'); else if(c == 'r') result.append('\r'); else if(c == 't') result.append('\t'); else if(c == 'u') { QString code = source.mid(pos, 4); pos += 4; result.append(QChar(ushort(code.toLong(0, 16)))); } else error("unknown escape sequence in string"); } else if(c == '\"') { // End of string. break; } else { result.append(c); } } return QString(result.constData(), result.size()); }
int Lexer::scanNumber(QChar ch) { if (ch != QLatin1Char('0')) { QVarLengthArray<char, 64> buf; buf += ch.toLatin1(); QChar n = _char; const QChar *code = _codePtr; while (n.isDigit()) { buf += n.toLatin1(); n = *code++; } if (n != QLatin1Char('.') && n != QLatin1Char('e') && n != QLatin1Char('E')) { if (code != _codePtr) { _codePtr = code - 1; scanChar(); } buf.append('\0'); _tokenValue = strtod(buf.constData(), 0); return T_NUMERIC_LITERAL; } } else if (_char.isDigit() && !qmlMode()) { _errorCode = IllegalCharacter; _errorMessage = QCoreApplication::translate("QmlParser", "Decimal numbers cannot start with \"0\"."); return T_ERROR; } QVarLengthArray<char,32> chars; chars.append(ch.unicode()); if (ch == QLatin1Char('0') && (_char == QLatin1Char('x') || _char == QLatin1Char('X'))) { ch = _char; // remember the x or X to use it in the error message below. // parse hex integer literal chars.append(_char.unicode()); scanChar(); // consume `x' while (isHexDigit(_char)) { chars.append(_char.unicode()); scanChar(); } if (chars.size() < 3) { _errorCode = IllegalHexNumber; _errorMessage = QCoreApplication::translate("QmlParser", "At least one hexadecimal digit is required after \"0%1\".").arg(ch); return T_ERROR; } _tokenValue = integerFromString(chars.constData(), chars.size(), 16); return T_NUMERIC_LITERAL; } // decimal integer literal while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); // consume the digit } if (_char == QLatin1Char('.')) { chars.append(_char.unicode()); scanChar(); // consume `.' while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) { if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && _codePtr[1].isDigit())) { chars.append(_char.unicode()); scanChar(); // consume `e' if (_char == QLatin1Char('+') || _char == QLatin1Char('-')) { chars.append(_char.unicode()); scanChar(); // consume the sign } while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } } } } else if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) { if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && _codePtr[1].isDigit())) { chars.append(_char.unicode()); scanChar(); // consume `e' if (_char == QLatin1Char('+') || _char == QLatin1Char('-')) { chars.append(_char.unicode()); scanChar(); // consume the sign } while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } } } if (chars.size() == 1) { // if we ended up with a single digit, then it was a '0' _tokenValue = 0; return T_NUMERIC_LITERAL; } chars.append('\0'); const char *begin = chars.constData(); const char *end = 0; bool ok = false; _tokenValue = qstrtod(begin, &end, &ok); if (end - begin != chars.size() - 1) { _errorCode = IllegalExponentIndicator; _errorMessage = QCoreApplication::translate("QmlParser", "Illegal syntax for exponential number."); return T_ERROR; } return T_NUMERIC_LITERAL; }
int Lexer::scanToken() { if (_stackToken != -1) { int tk = _stackToken; _stackToken = -1; return tk; } _terminator = false; again: _validTokenText = false; _tokenLinePtr = _lastLinePtr; while (_char.isSpace()) { if (unsigned sequenceLength = isLineTerminatorSequence()) { _tokenLinePtr = _codePtr + sequenceLength - 1; if (_restrictedKeyword) { // automatic semicolon insertion _tokenLine = _currentLineNumber; _tokenStartPtr = _codePtr - 1; return T_SEMICOLON; } else { _terminator = true; syncProhibitAutomaticSemicolon(); } } scanChar(); } _tokenStartPtr = _codePtr - 1; _tokenLine = _currentLineNumber; if (_codePtr > _endPtr) return EOF_SYMBOL; const QChar ch = _char; scanChar(); switch (ch.unicode()) { case '~': return T_TILDE; case '}': return T_RBRACE; case '|': if (_char == QLatin1Char('|')) { scanChar(); return T_OR_OR; } else if (_char == QLatin1Char('=')) { scanChar(); return T_OR_EQ; } return T_OR; case '{': return T_LBRACE; case '^': if (_char == QLatin1Char('=')) { scanChar(); return T_XOR_EQ; } return T_XOR; case ']': return T_RBRACKET; case '[': return T_LBRACKET; case '?': return T_QUESTION; case '>': if (_char == QLatin1Char('>')) { scanChar(); if (_char == QLatin1Char('>')) { scanChar(); if (_char == QLatin1Char('=')) { scanChar(); return T_GT_GT_GT_EQ; } return T_GT_GT_GT; } else if (_char == QLatin1Char('=')) { scanChar(); return T_GT_GT_EQ; } return T_GT_GT; } else if (_char == QLatin1Char('=')) { scanChar(); return T_GE; } return T_GT; case '=': if (_char == QLatin1Char('=')) { scanChar(); if (_char == QLatin1Char('=')) { scanChar(); return T_EQ_EQ_EQ; } return T_EQ_EQ; } return T_EQ; case '<': if (_char == QLatin1Char('=')) { scanChar(); return T_LE; } else if (_char == QLatin1Char('<')) { scanChar(); if (_char == QLatin1Char('=')) { scanChar(); return T_LT_LT_EQ; } return T_LT_LT; } return T_LT; case ';': return T_SEMICOLON; case ':': return T_COLON; case '/': if (_char == QLatin1Char('*')) { scanChar(); while (_codePtr <= _endPtr) { if (_char == QLatin1Char('*')) { scanChar(); if (_char == QLatin1Char('/')) { scanChar(); if (_engine) { _engine->addComment(tokenOffset() + 2, _codePtr - _tokenStartPtr - 1 - 4, tokenStartLine(), tokenStartColumn() + 2); } goto again; } } else { scanChar(); } } } else if (_char == QLatin1Char('/')) { while (_codePtr <= _endPtr && !isLineTerminator()) { scanChar(); } if (_engine) { _engine->addComment(tokenOffset() + 2, _codePtr - _tokenStartPtr - 1 - 2, tokenStartLine(), tokenStartColumn() + 2); } goto again; } if (_char == QLatin1Char('=')) { scanChar(); return T_DIVIDE_EQ; } return T_DIVIDE_; case '.': if (_char.isDigit()) { QVarLengthArray<char,32> chars; chars.append(ch.unicode()); // append the `.' while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) { if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && _codePtr[1].isDigit())) { chars.append(_char.unicode()); scanChar(); // consume `e' if (_char == QLatin1Char('+') || _char == QLatin1Char('-')) { chars.append(_char.unicode()); scanChar(); // consume the sign } while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } } } chars.append('\0'); const char *begin = chars.constData(); const char *end = 0; bool ok = false; _tokenValue = qstrtod(begin, &end, &ok); if (end - begin != chars.size() - 1) { _errorCode = IllegalExponentIndicator; _errorMessage = QCoreApplication::translate("QmlParser", "Illegal syntax for exponential number."); return T_ERROR; } return T_NUMERIC_LITERAL; } return T_DOT; case '-': if (_char == QLatin1Char('=')) { scanChar(); return T_MINUS_EQ; } else if (_char == QLatin1Char('-')) { scanChar(); if (_terminator && !_delimited && !_prohibitAutomaticSemicolon) { _stackToken = T_MINUS_MINUS; return T_SEMICOLON; } return T_MINUS_MINUS; } return T_MINUS; case ',': return T_COMMA; case '+': if (_char == QLatin1Char('=')) { scanChar(); return T_PLUS_EQ; } else if (_char == QLatin1Char('+')) { scanChar(); if (_terminator && !_delimited && !_prohibitAutomaticSemicolon) { _stackToken = T_PLUS_PLUS; return T_SEMICOLON; } return T_PLUS_PLUS; } return T_PLUS; case '*': if (_char == QLatin1Char('=')) { scanChar(); return T_STAR_EQ; } return T_STAR; case ')': return T_RPAREN; case '(': return T_LPAREN; case '&': if (_char == QLatin1Char('=')) { scanChar(); return T_AND_EQ; } else if (_char == QLatin1Char('&')) { scanChar(); return T_AND_AND; } return T_AND; case '%': if (_char == QLatin1Char('=')) { scanChar(); return T_REMAINDER_EQ; } return T_REMAINDER; case '!': if (_char == QLatin1Char('=')) { scanChar(); if (_char == QLatin1Char('=')) { scanChar(); return T_NOT_EQ_EQ; } return T_NOT_EQ; } return T_NOT; case '\'': case '"': { const QChar quote = ch; bool multilineStringLiteral = false; const QChar *startCode = _codePtr; if (_engine) { while (_codePtr <= _endPtr) { if (isLineTerminator()) { if (qmlMode()) break; _errorCode = IllegalCharacter; _errorMessage = QCoreApplication::translate("QmlParser", "Stray newline in string literal."); return T_ERROR; } else if (_char == QLatin1Char('\\')) { break; } else if (_char == quote) { _tokenSpell = _engine->midRef(startCode - _code.unicode() - 1, _codePtr - startCode); scanChar(); return T_STRING_LITERAL; } scanChar(); } } _validTokenText = true; _tokenText.resize(0); startCode--; while (startCode != _codePtr - 1) _tokenText += *startCode++; while (_codePtr <= _endPtr) { if (unsigned sequenceLength = isLineTerminatorSequence()) { multilineStringLiteral = true; _tokenText += _char; if (sequenceLength == 2) _tokenText += *_codePtr; scanChar(); } else if (_char == quote) { scanChar(); if (_engine) _tokenSpell = _engine->newStringRef(_tokenText); return multilineStringLiteral ? T_MULTILINE_STRING_LITERAL : T_STRING_LITERAL; } else if (_char == QLatin1Char('\\')) { scanChar(); QChar u; switch (_char.unicode()) { // unicode escape sequence case 'u': { bool ok = false; u = decodeUnicodeEscapeCharacter(&ok); if (! ok) { _errorCode = IllegalUnicodeEscapeSequence; _errorMessage = QCoreApplication::translate("QmlParser", "Illegal unicode escape sequence."); return T_ERROR; } } break; // hex escape sequence case 'x': { bool ok = false; u = decodeHexEscapeCharacter(&ok); if (!ok) { _errorCode = IllegalHexadecimalEscapeSequence; _errorMessage = QCoreApplication::translate("QmlParser", "Illegal hexadecimal escape sequence."); return T_ERROR; } } break; // single character escape sequence case '\\': u = QLatin1Char('\\'); scanChar(); break; case '\'': u = QLatin1Char('\''); scanChar(); break; case '\"': u = QLatin1Char('\"'); scanChar(); break; case 'b': u = QLatin1Char('\b'); scanChar(); break; case 'f': u = QLatin1Char('\f'); scanChar(); break; case 'n': u = QLatin1Char('\n'); scanChar(); break; case 'r': u = QLatin1Char('\r'); scanChar(); break; case 't': u = QLatin1Char('\t'); scanChar(); break; case 'v': u = QLatin1Char('\v'); scanChar(); break; case '0': if (! _codePtr->isDigit()) { scanChar(); u = QLatin1Char('\0'); break; } // fall through case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': _errorCode = IllegalEscapeSequence; _errorMessage = QCoreApplication::translate("QmlParser", "Octal escape sequences are not allowed."); return T_ERROR; case '\r': case '\n': case 0x2028u: case 0x2029u: scanChar(); continue; default: // non escape character u = _char; scanChar(); } _tokenText += u; } else { _tokenText += _char; scanChar(); } } _errorCode = UnclosedStringLiteral; _errorMessage = QCoreApplication::translate("QmlParser", "Unclosed string at end of line."); return T_ERROR; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return scanNumber(ch); default: { QChar c = ch; bool identifierWithEscapeChars = false; if (c == QLatin1Char('\\') && _char == QLatin1Char('u')) { identifierWithEscapeChars = true; bool ok = false; c = decodeUnicodeEscapeCharacter(&ok); if (! ok) { _errorCode = IllegalUnicodeEscapeSequence; _errorMessage = QCoreApplication::translate("QmlParser", "Illegal unicode escape sequence."); return T_ERROR; } } if (isIdentifierStart(c)) { if (identifierWithEscapeChars) { _tokenText.resize(0); _tokenText += c; _validTokenText = true; } while (true) { c = _char; if (_char == QLatin1Char('\\') && _codePtr[0] == QLatin1Char('u')) { if (! identifierWithEscapeChars) { identifierWithEscapeChars = true; _tokenText.resize(0); _tokenText.insert(0, _tokenStartPtr, _codePtr - _tokenStartPtr - 1); _validTokenText = true; } scanChar(); // skip '\\' bool ok = false; c = decodeUnicodeEscapeCharacter(&ok); if (! ok) { _errorCode = IllegalUnicodeEscapeSequence; _errorMessage = QCoreApplication::translate("QmlParser", "Illegal unicode escape sequence."); return T_ERROR; } if (isIdentifierPart(c)) _tokenText += c; continue; } else if (isIdentifierPart(c)) { if (identifierWithEscapeChars) _tokenText += c; scanChar(); continue; } _tokenLength = _codePtr - _tokenStartPtr - 1; int kind = T_IDENTIFIER; if (! identifierWithEscapeChars) kind = classify(_tokenStartPtr, _tokenLength, _qmlMode); if (_engine) { if (kind == T_IDENTIFIER && identifierWithEscapeChars) _tokenSpell = _engine->newStringRef(_tokenText); else _tokenSpell = _engine->midRef(_tokenStartPtr - _code.unicode(), _tokenLength); } return kind; } } } break; } return T_ERROR; }
void tst_QVarLengthArray::oldTests() { { QVarLengthArray<int, 256> sa(128); QVERIFY(sa.data() == &sa[0]); sa[0] = 0xfee; sa[10] = 0xff; QVERIFY(sa[0] == 0xfee); QVERIFY(sa[10] == 0xff); sa.resize(512); QVERIFY(sa.data() == &sa[0]); QVERIFY(sa[0] == 0xfee); QVERIFY(sa[10] == 0xff); QVERIFY(sa.at(0) == 0xfee); QVERIFY(sa.at(10) == 0xff); QVERIFY(sa.value(0) == 0xfee); QVERIFY(sa.value(10) == 0xff); QVERIFY(sa.value(1000) == 0); QVERIFY(sa.value(1000, 12) == 12); QVERIFY(sa.size() == 512); sa.reserve(1024); QVERIFY(sa.capacity() == 1024); QVERIFY(sa.size() == 512); } { QVarLengthArray<QString> sa(10); sa[0] = "Hello"; sa[9] = "World"; QVERIFY(*sa.data() == "Hello"); QVERIFY(sa[9] == "World"); sa.reserve(512); QVERIFY(*sa.data() == "Hello"); QVERIFY(sa[9] == "World"); sa.resize(512); QVERIFY(*sa.data() == "Hello"); QVERIFY(sa[9] == "World"); } { int arr[2] = {1, 2}; QVarLengthArray<int> sa(10); QCOMPARE(sa.size(), 10); sa.append(arr, 2); QCOMPARE(sa.size(), 12); QCOMPARE(sa[10], 1); QCOMPARE(sa[11], 2); } { QString arr[2] = { QString("hello"), QString("world") }; QVarLengthArray<QString> sa(10); QCOMPARE(sa.size(), 10); sa.append(arr, 2); QCOMPARE(sa.size(), 12); QCOMPARE(sa[10], QString("hello")); QCOMPARE(sa[11], QString("world")); QCOMPARE(sa.at(10), QString("hello")); QCOMPARE(sa.at(11), QString("world")); QCOMPARE(sa.value(10), QString("hello")); QCOMPARE(sa.value(11), QString("world")); QCOMPARE(sa.value(10000), QString()); QCOMPARE(sa.value(1212112, QString("none")), QString("none")); QCOMPARE(sa.value(-12, QString("neg")), QString("neg")); sa.append(arr, 1); QCOMPARE(sa.size(), 13); QCOMPARE(sa[12], QString("hello")); sa.append(arr, 0); QCOMPARE(sa.size(), 13); } { // assignment operator and copy constructor QVarLengthArray<int> sa(10); sa[5] = 5; QVarLengthArray<int> sa2(10); sa2[5] = 6; sa2 = sa; QCOMPARE(sa2[5], 5); QVarLengthArray<int> sa3(sa); QCOMPARE(sa3[5], 5); } QSKIP("This test causes the machine to crash when allocating too much memory.", SkipSingle); { QVarLengthArray<Foo> a; const int N = 0x7fffffff / sizeof(Foo); const int Prealloc = a.capacity(); const Foo *data0 = a.constData(); a.resize(N); if (a.size() == N) { QVERIFY(a.capacity() >= N); QCOMPARE(fooCtor, N); QCOMPARE(fooDtor, 0); for (int i = 0; i < N; i += 35000) a[i] = Foo(); } else { // this is the case we're actually testing QCOMPARE(a.size(), 0); QCOMPARE(a.capacity(), Prealloc); QCOMPARE(a.constData(), data0); QCOMPARE(fooCtor, 0); QCOMPARE(fooDtor, 0); a.resize(5); QCOMPARE(a.size(), 5); QCOMPARE(a.capacity(), Prealloc); QCOMPARE(a.constData(), data0); QCOMPARE(fooCtor, 5); QCOMPARE(fooDtor, 0); a.resize(Prealloc + 1); QCOMPARE(a.size(), Prealloc + 1); QVERIFY(a.capacity() >= Prealloc + 1); QVERIFY(a.constData() != data0); QCOMPARE(fooCtor, Prealloc + 6); QCOMPARE(fooDtor, 5); const Foo *data1 = a.constData(); a.resize(0x10000000); QCOMPARE(a.size(), 0); QVERIFY(a.capacity() >= Prealloc + 1); QVERIFY(a.constData() == data1); QCOMPARE(fooCtor, Prealloc + 6); QCOMPARE(fooDtor, Prealloc + 6); } } }
bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags) { Q_D(QEventDispatcherWin32); if (!d->internalHwnd) createInternalHwnd(); d->interrupt = false; emit awake(); bool canWait; bool retVal = false; bool seenWM_QT_SENDPOSTEDEVENTS = false; bool needWM_QT_SENDPOSTEDEVENTS = false; do { DWORD waitRet = 0; HANDLE pHandles[MAXIMUM_WAIT_OBJECTS - 1]; QVarLengthArray<MSG> processedTimers; while (!d->interrupt) { DWORD nCount = d->winEventNotifierList.count(); Q_ASSERT(nCount < MAXIMUM_WAIT_OBJECTS - 1); MSG msg; bool haveMessage; if (!(flags & QEventLoop::ExcludeUserInputEvents) && !d->queuedUserInputEvents.isEmpty()) { // process queued user input events haveMessage = true; msg = d->queuedUserInputEvents.takeFirst(); } else if(!(flags & QEventLoop::ExcludeSocketNotifiers) && !d->queuedSocketEvents.isEmpty()) { // process queued socket events haveMessage = true; msg = d->queuedSocketEvents.takeFirst(); } else { haveMessage = PeekMessage(&msg, 0, 0, 0, PM_REMOVE); if (haveMessage && (flags & QEventLoop::ExcludeUserInputEvents) && ((msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) || (msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST) || msg.message == WM_MOUSEWHEEL || msg.message == WM_MOUSEHWHEEL || msg.message == WM_TOUCH #ifndef QT_NO_GESTURES || msg.message == WM_GESTURE || msg.message == WM_GESTURENOTIFY #endif || msg.message == WM_CLOSE)) { // queue user input events for later processing haveMessage = false; d->queuedUserInputEvents.append(msg); } if (haveMessage && (flags & QEventLoop::ExcludeSocketNotifiers) && (msg.message == WM_QT_SOCKETNOTIFIER && msg.hwnd == d->internalHwnd)) { // queue socket events for later processing haveMessage = false; d->queuedSocketEvents.append(msg); } } if (!haveMessage) { // no message - check for signalled objects for (int i=0; i<(int)nCount; i++) pHandles[i] = d->winEventNotifierList.at(i)->handle(); waitRet = MsgWaitForMultipleObjectsEx(nCount, pHandles, 0, QS_ALLINPUT, MWMO_ALERTABLE); if ((haveMessage = (waitRet == WAIT_OBJECT_0 + nCount))) { // a new message has arrived, process it continue; } } if (haveMessage) { #ifdef Q_OS_WINCE // WinCE doesn't support hooks at all, so we have to call this by hand :( (void) qt_GetMessageHook(0, PM_REMOVE, (LPARAM) &msg); #endif if (d->internalHwnd == msg.hwnd && msg.message == WM_QT_SENDPOSTEDEVENTS) { if (seenWM_QT_SENDPOSTEDEVENTS) { // when calling processEvents() "manually", we only want to send posted // events once needWM_QT_SENDPOSTEDEVENTS = true; continue; } seenWM_QT_SENDPOSTEDEVENTS = true; } else if (msg.message == WM_TIMER) { // avoid live-lock by keeping track of the timers we've already sent bool found = false; for (int i = 0; !found && i < processedTimers.count(); ++i) { const MSG processed = processedTimers.constData()[i]; found = (processed.wParam == msg.wParam && processed.hwnd == msg.hwnd && processed.lParam == msg.lParam); } if (found) continue; processedTimers.append(msg); } else if (msg.message == WM_QUIT) { if (QCoreApplication::instance()) QCoreApplication::instance()->quit(); return false; } if (!filterEvent(&msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } else if (waitRet >= WAIT_OBJECT_0 && waitRet < WAIT_OBJECT_0 + nCount) { d->activateEventNotifier(d->winEventNotifierList.at(waitRet - WAIT_OBJECT_0)); } else { // nothing todo so break break; } retVal = true; } // still nothing - wait for message or signalled objects canWait = (!retVal && !d->interrupt && (flags & QEventLoop::WaitForMoreEvents)); if (canWait) { DWORD nCount = d->winEventNotifierList.count(); Q_ASSERT(nCount < MAXIMUM_WAIT_OBJECTS - 1); for (int i=0; i<(int)nCount; i++) pHandles[i] = d->winEventNotifierList.at(i)->handle(); emit aboutToBlock(); waitRet = MsgWaitForMultipleObjectsEx(nCount, pHandles, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE | MWMO_INPUTAVAILABLE); emit awake(); if (waitRet >= WAIT_OBJECT_0 && waitRet < WAIT_OBJECT_0 + nCount) { d->activateEventNotifier(d->winEventNotifierList.at(waitRet - WAIT_OBJECT_0)); retVal = true; } } } while (canWait); if (!seenWM_QT_SENDPOSTEDEVENTS && (flags & QEventLoop::EventLoopExec) == 0) { // when called "manually", always send posted events QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData); } if (needWM_QT_SENDPOSTEDEVENTS) PostMessage(d->internalHwnd, WM_QT_SENDPOSTEDEVENTS, 0, 0); return retVal; }
int Lexer::scanToken() { if (_stackToken != -1) { int tk = _stackToken; _stackToken = -1; return tk; } _terminator = false; again: _validTokenText = false; _tokenLinePtr = _lastLinePtr; while (_char.isSpace()) { if (_char == QLatin1Char('\n')) { _tokenLinePtr = _codePtr; if (_restrictedKeyword) { // automatic semicolon insertion _tokenLine = _currentLineNumber; _tokenStartPtr = _codePtr - 1; // ### TODO: insert it before the optional \r sequence. return T_SEMICOLON; } else { _terminator = true; syncProhibitAutomaticSemicolon(); } } scanChar(); } _tokenStartPtr = _codePtr - 1; _tokenLine = _currentLineNumber; if (_char.isNull()) return EOF_SYMBOL; const QChar ch = _char; scanChar(); switch (ch.unicode()) { case '~': return T_TILDE; case '}': return T_RBRACE; case '|': if (_char == QLatin1Char('|')) { scanChar(); return T_OR_OR; } else if (_char == QLatin1Char('=')) { scanChar(); return T_OR_EQ; } return T_OR; case '{': return T_LBRACE; case '^': if (_char == QLatin1Char('=')) { scanChar(); return T_XOR_EQ; } return T_XOR; case ']': return T_RBRACKET; case '[': return T_LBRACKET; case '?': return T_QUESTION; case '>': if (_char == QLatin1Char('>')) { scanChar(); if (_char == QLatin1Char('>')) { scanChar(); if (_char == QLatin1Char('=')) { scanChar(); return T_GT_GT_GT_EQ; } return T_GT_GT_GT; } else if (_char == QLatin1Char('=')) { scanChar(); return T_GT_GT_EQ; } return T_GT_GT; } else if (_char == QLatin1Char('=')) { scanChar(); return T_GE; } return T_GT; case '=': if (_char == QLatin1Char('=')) { scanChar(); if (_char == QLatin1Char('=')) { scanChar(); return T_EQ_EQ_EQ; } return T_EQ_EQ; } return T_EQ; case '<': if (_char == QLatin1Char('=')) { scanChar(); return T_LE; } else if (_char == QLatin1Char('<')) { scanChar(); if (_char == QLatin1Char('=')) { scanChar(); return T_LT_LT_EQ; } return T_LT_LT; } return T_LT; case ';': return T_SEMICOLON; case ':': return T_COLON; case '/': if (_char == QLatin1Char('*')) { scanChar(); while (!_char.isNull()) { if (_char == QLatin1Char('*')) { scanChar(); if (_char == QLatin1Char('/')) { scanChar(); if (_engine) { _engine->addComment(tokenOffset() + 2, _codePtr - _tokenStartPtr - 1 - 4, tokenStartLine(), tokenStartColumn() + 2); } goto again; } } else { scanChar(); } } } else if (_char == QLatin1Char('/')) { while (!_char.isNull() && _char != QLatin1Char('\n')) { scanChar(); } if (_engine) { _engine->addComment(tokenOffset() + 2, _codePtr - _tokenStartPtr - 1 - 2, tokenStartLine(), tokenStartColumn() + 2); } goto again; } if (_char == QLatin1Char('=')) { scanChar(); return T_DIVIDE_EQ; } return T_DIVIDE_; case '.': if (_char.isDigit()) { QVarLengthArray<char,32> chars; chars.append(ch.unicode()); // append the `.' while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) { if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && _codePtr[1].isDigit())) { chars.append(_char.unicode()); scanChar(); // consume `e' if (_char == QLatin1Char('+') || _char == QLatin1Char('-')) { chars.append(_char.unicode()); scanChar(); // consume the sign } while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } } } chars.append('\0'); const char *begin = chars.constData(); const char *end = 0; bool ok = false; _tokenValue = qstrtod(begin, &end, &ok); if (end - begin != chars.size() - 1) { _errorCode = IllegalExponentIndicator; _errorMessage = tr("QQmlParser", "Illegal syntax for exponential number"); return T_ERROR; } return T_NUMERIC_LITERAL; } return T_DOT; case '-': if (_char == QLatin1Char('=')) { scanChar(); return T_MINUS_EQ; } else if (_char == QLatin1Char('-')) { scanChar(); if (_terminator && !_delimited && !_prohibitAutomaticSemicolon) { _stackToken = T_MINUS_MINUS; return T_SEMICOLON; } return T_MINUS_MINUS; } return T_MINUS; case ',': return T_COMMA; case '+': if (_char == QLatin1Char('=')) { scanChar(); return T_PLUS_EQ; } else if (_char == QLatin1Char('+')) { scanChar(); if (_terminator && !_delimited && !_prohibitAutomaticSemicolon) { _stackToken = T_PLUS_PLUS; return T_SEMICOLON; } return T_PLUS_PLUS; } return T_PLUS; case '*': if (_char == QLatin1Char('=')) { scanChar(); return T_STAR_EQ; } return T_STAR; case ')': return T_RPAREN; case '(': return T_LPAREN; case '&': if (_char == QLatin1Char('=')) { scanChar(); return T_AND_EQ; } else if (_char == QLatin1Char('&')) { scanChar(); return T_AND_AND; } return T_AND; case '%': if (_char == QLatin1Char('=')) { scanChar(); return T_REMAINDER_EQ; } return T_REMAINDER; case '!': if (_char == QLatin1Char('=')) { scanChar(); if (_char == QLatin1Char('=')) { scanChar(); return T_NOT_EQ_EQ; } return T_NOT_EQ; } return T_NOT; case '\'': case '"': { const QChar quote = ch; bool multilineStringLiteral = false; const QChar *startCode = _codePtr; if (_engine) { while (!_char.isNull()) { if (_char == QLatin1Char('\n') || _char == QLatin1Char('\\')) { break; } else if (_char == quote) { _tokenSpell = _engine->midRef(startCode - _code.unicode() - 1, _codePtr - startCode); scanChar(); return T_STRING_LITERAL; } scanChar(); } } _validTokenText = true; _tokenText.resize(0); startCode--; while (startCode != _codePtr - 1) _tokenText += *startCode++; while (! _char.isNull()) { if (_char == QLatin1Char('\n')) { multilineStringLiteral = true; _tokenText += _char; scanChar(); } else if (_char == quote) { scanChar(); if (_engine) _tokenSpell = _engine->newStringRef(_tokenText); return multilineStringLiteral ? T_MULTILINE_STRING_LITERAL : T_STRING_LITERAL; } else if (_char == QLatin1Char('\\')) { scanChar(); QChar u; bool ok = false; switch (_char.unicode()) { // unicode escape sequence case 'u': u = decodeUnicodeEscapeCharacter(&ok); if (! ok) u = _char; break; // hex escape sequence case 'x': case 'X': if (isHexDigit(_codePtr[0]) && isHexDigit(_codePtr[1])) { scanChar(); const QChar c1 = _char; scanChar(); const QChar c2 = _char; scanChar(); u = convertHex(c1, c2); } else { u = _char; } break; // single character escape sequence case '\\': u = QLatin1Char('\\'); scanChar(); break; case '\'': u = QLatin1Char('\''); scanChar(); break; case '\"': u = QLatin1Char('\"'); scanChar(); break; case 'b': u = QLatin1Char('\b'); scanChar(); break; case 'f': u = QLatin1Char('\f'); scanChar(); break; case 'n': u = QLatin1Char('\n'); scanChar(); break; case 'r': u = QLatin1Char('\r'); scanChar(); break; case 't': u = QLatin1Char('\t'); scanChar(); break; case 'v': u = QLatin1Char('\v'); scanChar(); break; case '0': if (! _codePtr[1].isDigit()) { scanChar(); u = QLatin1Char('\0'); } else { // ### parse deprecated octal escape sequence ? u = _char; } break; case '\r': while (_char == QLatin1Char('\r')) scanChar(); if (_char == QLatin1Char('\n')) { u = _char; scanChar(); } else { u = QLatin1Char('\n'); } break; case '\n': u = _char; scanChar(); break; default: // non escape character u = _char; scanChar(); } _tokenText += u; } else { _tokenText += _char; scanChar(); } } _errorCode = UnclosedStringLiteral; _errorMessage = tr("QQmlParser", "Unclosed string at end of line"); return T_ERROR; } default: if (ch.isLetter() || ch == QLatin1Char('$') || ch == QLatin1Char('_') || (ch == QLatin1Char('\\') && _char == QLatin1Char('u'))) { bool identifierWithEscapeChars = false; if (ch == QLatin1Char('\\')) { identifierWithEscapeChars = true; _tokenText.resize(0); bool ok = false; _tokenText += decodeUnicodeEscapeCharacter(&ok); _validTokenText = true; if (! ok) { _errorCode = IllegalUnicodeEscapeSequence; _errorMessage = tr("QQmlParser", "Illegal unicode escape sequence"); return T_ERROR; } } while (true) { if (_char.isLetterOrNumber() || _char == QLatin1Char('$') || _char == QLatin1Char('_')) { if (identifierWithEscapeChars) _tokenText += _char; scanChar(); } else if (_char == QLatin1Char('\\') && _codePtr[0] == QLatin1Char('u')) { if (! identifierWithEscapeChars) { identifierWithEscapeChars = true; _tokenText.resize(0); _tokenText.insert(0, _tokenStartPtr, _codePtr - _tokenStartPtr - 1); _validTokenText = true; } scanChar(); // skip '\\' bool ok = false; _tokenText += decodeUnicodeEscapeCharacter(&ok); if (! ok) { _errorCode = IllegalUnicodeEscapeSequence; _errorMessage = tr("QQmlParser", "Illegal unicode escape sequence"); return T_ERROR; } } else { _tokenLength = _codePtr - _tokenStartPtr - 1; int kind = T_IDENTIFIER; if (! identifierWithEscapeChars) kind = classify(_tokenStartPtr, _tokenLength, _qmlMode); if (_engine) { if (kind == T_IDENTIFIER && identifierWithEscapeChars) _tokenSpell = _engine->newStringRef(_tokenText); else _tokenSpell = _engine->midRef(_tokenStartPtr - _code.unicode(), _tokenLength); } return kind; } } } else if (ch.isDigit()) { if (ch != QLatin1Char('0')) { double integer = ch.unicode() - '0'; QChar n = _char; const QChar *code = _codePtr; while (n.isDigit()) { integer = integer * 10 + (n.unicode() - '0'); n = *code++; } if (n != QLatin1Char('.') && n != QLatin1Char('e') && n != QLatin1Char('E')) { if (code != _codePtr) { _codePtr = code - 1; scanChar(); } _tokenValue = integer; return T_NUMERIC_LITERAL; } } QVarLengthArray<char,32> chars; chars.append(ch.unicode()); if (ch == QLatin1Char('0') && (_char == QLatin1Char('x') || _char == QLatin1Char('X'))) { // parse hex integer literal chars.append(_char.unicode()); scanChar(); // consume `x' while (isHexDigit(_char)) { chars.append(_char.unicode()); scanChar(); } _tokenValue = integerFromString(chars.constData(), chars.size(), 16); return T_NUMERIC_LITERAL; } // decimal integer literal while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); // consume the digit } if (_char == QLatin1Char('.')) { chars.append(_char.unicode()); scanChar(); // consume `.' while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) { if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && _codePtr[1].isDigit())) { chars.append(_char.unicode()); scanChar(); // consume `e' if (_char == QLatin1Char('+') || _char == QLatin1Char('-')) { chars.append(_char.unicode()); scanChar(); // consume the sign } while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } } } } else if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) { if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && _codePtr[1].isDigit())) { chars.append(_char.unicode()); scanChar(); // consume `e' if (_char == QLatin1Char('+') || _char == QLatin1Char('-')) { chars.append(_char.unicode()); scanChar(); // consume the sign } while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } } } chars.append('\0'); const char *begin = chars.constData(); const char *end = 0; bool ok = false; _tokenValue = qstrtod(begin, &end, &ok); if (end - begin != chars.size() - 1) { _errorCode = IllegalExponentIndicator; _errorMessage = tr("QQmlParser", "Illegal syntax for exponential number"); return T_ERROR; } return T_NUMERIC_LITERAL; } break; } return T_ERROR; }
void QVGPixmapConvolutionFilter::draw (QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect) const { if (src.isNull()) return; if (src.pixmapData()->classId() != QPixmapData::OpenVGClass) { // The pixmap data is not an instance of QVGPixmapData, so fall // back to the default convolution filter implementation. QPixmapConvolutionFilter::draw(painter, dest, src, srcRect); return; } QVGPixmapData *pd = static_cast<QVGPixmapData *>(src.pixmapData()); VGImage srcImage = pd->toVGImage(); if (srcImage == VG_INVALID_HANDLE) return; QSize size = pd->size(); VGImage dstImage = QVGImagePool::instance()->createTemporaryImage (VG_sARGB_8888_PRE, size.width(), size.height(), VG_IMAGE_QUALITY_FASTER, pd); if (dstImage == VG_INVALID_HANDLE) return; int kernelWidth = rows(); int kernelHeight = columns(); const qreal *kern = convolutionKernel(); QVarLengthArray<VGshort> kernel; for (int i = 0; i < kernelWidth; ++i) { for (int j = 0; j < kernelHeight; ++j) { kernel.append((VGshort)(kern[j * kernelWidth + i] * 1024.0f)); } } VGfloat values[4]; values[0] = 0.0f; values[1] = 0.0f; values[2] = 0.0f; values[3] = 0.0f; vgSetfv(VG_TILE_FILL_COLOR, 4, values); vgConvolve(dstImage, srcImage, kernelWidth, kernelHeight, 0, 0, kernel.constData(), 1.0f / 1024.0f, 0.0f, VG_TILE_FILL); VGImage child = VG_INVALID_HANDLE; if (srcRect.isNull() || (srcRect.topLeft().isNull() && srcRect.size() == size)) { child = dstImage; } else { QRect src = srcRect.toRect(); child = vgChildImage(dstImage, src.x(), src.y(), src.width(), src.height()); } qt_vg_drawVGImage(painter, dest, child); if(child != dstImage) vgDestroyImage(child); QVGImagePool::instance()->releaseImage(0, dstImage); }
int Lexer::scanNumber(QChar ch) { if (ch != QLatin1Char('0')) { double integer = ch.unicode() - '0'; QChar n = _char; const QChar *code = _codePtr; while (n.isDigit()) { integer = integer * 10 + (n.unicode() - '0'); n = *code++; } if (n != QLatin1Char('.') && n != QLatin1Char('e') && n != QLatin1Char('E')) { if (code != _codePtr) { _codePtr = code - 1; scanChar(); } _tokenValue = integer; return T_NUMERIC_LITERAL; } } QVarLengthArray<char,32> chars; chars.append(ch.unicode()); if (ch == QLatin1Char('0') && (_char == QLatin1Char('x') || _char == QLatin1Char('X'))) { // parse hex integer literal chars.append(_char.unicode()); scanChar(); // consume `x' while (isHexDigit(_char)) { chars.append(_char.unicode()); scanChar(); } _tokenValue = integerFromString(chars.constData(), chars.size(), 16); return T_NUMERIC_LITERAL; } // decimal integer literal while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); // consume the digit } if (_char == QLatin1Char('.')) { chars.append(_char.unicode()); scanChar(); // consume `.' while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) { if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && _codePtr[1].isDigit())) { chars.append(_char.unicode()); scanChar(); // consume `e' if (_char == QLatin1Char('+') || _char == QLatin1Char('-')) { chars.append(_char.unicode()); scanChar(); // consume the sign } while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } } } } else if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) { if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && _codePtr[1].isDigit())) { chars.append(_char.unicode()); scanChar(); // consume `e' if (_char == QLatin1Char('+') || _char == QLatin1Char('-')) { chars.append(_char.unicode()); scanChar(); // consume the sign } while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } } } if (chars.size() == 1) { // if we ended up with a single digit, then it was a '0' _tokenValue = 0; return T_NUMERIC_LITERAL; } chars.append('\0'); const char *begin = chars.constData(); const char *end = 0; bool ok = false; _tokenValue = qstrtod(begin, &end, &ok); if (end - begin != chars.size() - 1) { _errorCode = IllegalExponentIndicator; _errorMessage = QCoreApplication::translate("QmlParser", "Illegal syntax for exponential number"); return T_ERROR; } return T_NUMERIC_LITERAL; }
bool QQuickSvgParser::parsePathDataFast(const QString &dataStr, QPainterPath &path) { qreal x0 = 0, y0 = 0; // starting point qreal x = 0, y = 0; // current point char lastMode = 0; QPointF ctrlPt; const QChar *str = dataStr.constData(); const QChar *end = str + dataStr.size(); while (str != end) { while (str->isSpace()) ++str; QChar pathElem = *str; ++str; QChar endc = *end; *const_cast<QChar *>(end) = 0; // parseNumbersArray requires 0-termination that QStringRef cannot guarantee QVarLengthArray<qreal, 8> arg; parseNumbersArray(str, arg); *const_cast<QChar *>(end) = endc; if (pathElem == QLatin1Char('z') || pathElem == QLatin1Char('Z')) arg.append(0);//dummy const qreal *num = arg.constData(); int count = arg.count(); while (count > 0) { qreal offsetX = x; // correction offsets qreal offsetY = y; // for relative commands switch (pathElem.unicode()) { case 'm': { if (count < 2) { num++; count--; break; } x = x0 = num[0] + offsetX; y = y0 = num[1] + offsetY; num += 2; count -= 2; path.moveTo(x0, y0); // As per 1.2 spec 8.3.2 The "moveto" commands // If a 'moveto' is followed by multiple pairs of coordinates without explicit commands, // the subsequent pairs shall be treated as implicit 'lineto' commands. pathElem = QLatin1Char('l'); } break; case 'M': { if (count < 2) { num++; count--; break; } x = x0 = num[0]; y = y0 = num[1]; num += 2; count -= 2; path.moveTo(x0, y0); // As per 1.2 spec 8.3.2 The "moveto" commands // If a 'moveto' is followed by multiple pairs of coordinates without explicit commands, // the subsequent pairs shall be treated as implicit 'lineto' commands. pathElem = QLatin1Char('L'); } break; case 'z': case 'Z': { x = x0; y = y0; count--; // skip dummy num++; path.closeSubpath(); } break; case 'l': { if (count < 2) { num++; count--; break; } x = num[0] + offsetX; y = num[1] + offsetY; num += 2; count -= 2; path.lineTo(x, y); } break; case 'L': { if (count < 2) { num++; count--; break; } x = num[0]; y = num[1]; num += 2; count -= 2; path.lineTo(x, y); } break; case 'h': { x = num[0] + offsetX; num++; count--; path.lineTo(x, y); } break; case 'H': { x = num[0]; num++; count--; path.lineTo(x, y); } break; case 'v': { y = num[0] + offsetY; num++; count--; path.lineTo(x, y); } break; case 'V': { y = num[0]; num++; count--; path.lineTo(x, y); } break; case 'c': { if (count < 6) { num += count; count = 0; break; } QPointF c1(num[0] + offsetX, num[1] + offsetY); QPointF c2(num[2] + offsetX, num[3] + offsetY); QPointF e(num[4] + offsetX, num[5] + offsetY); num += 6; count -= 6; path.cubicTo(c1, c2, e); ctrlPt = c2; x = e.x(); y = e.y(); break; } case 'C': { if (count < 6) { num += count; count = 0; break; } QPointF c1(num[0], num[1]); QPointF c2(num[2], num[3]); QPointF e(num[4], num[5]); num += 6; count -= 6; path.cubicTo(c1, c2, e); ctrlPt = c2; x = e.x(); y = e.y(); break; } case 's': { if (count < 4) { num += count; count = 0; break; } QPointF c1; if (lastMode == 'c' || lastMode == 'C' || lastMode == 's' || lastMode == 'S') c1 = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y()); else c1 = QPointF(x, y); QPointF c2(num[0] + offsetX, num[1] + offsetY); QPointF e(num[2] + offsetX, num[3] + offsetY); num += 4; count -= 4; path.cubicTo(c1, c2, e); ctrlPt = c2; x = e.x(); y = e.y(); break; } case 'S': { if (count < 4) { num += count; count = 0; break; } QPointF c1; if (lastMode == 'c' || lastMode == 'C' || lastMode == 's' || lastMode == 'S') c1 = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y()); else c1 = QPointF(x, y); QPointF c2(num[0], num[1]); QPointF e(num[2], num[3]); num += 4; count -= 4; path.cubicTo(c1, c2, e); ctrlPt = c2; x = e.x(); y = e.y(); break; } case 'q': { if (count < 4) { num += count; count = 0; break; } QPointF c(num[0] + offsetX, num[1] + offsetY); QPointF e(num[2] + offsetX, num[3] + offsetY); num += 4; count -= 4; path.quadTo(c, e); ctrlPt = c; x = e.x(); y = e.y(); break; } case 'Q': { if (count < 4) { num += count; count = 0; break; } QPointF c(num[0], num[1]); QPointF e(num[2], num[3]); num += 4; count -= 4; path.quadTo(c, e); ctrlPt = c; x = e.x(); y = e.y(); break; } case 't': { if (count < 2) { num += count; count = 0; break; } QPointF e(num[0] + offsetX, num[1] + offsetY); num += 2; count -= 2; QPointF c; if (lastMode == 'q' || lastMode == 'Q' || lastMode == 't' || lastMode == 'T') c = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y()); else c = QPointF(x, y); path.quadTo(c, e); ctrlPt = c; x = e.x(); y = e.y(); break; } case 'T': { if (count < 2) { num += count; count = 0; break; } QPointF e(num[0], num[1]); num += 2; count -= 2; QPointF c; if (lastMode == 'q' || lastMode == 'Q' || lastMode == 't' || lastMode == 'T') c = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y()); else c = QPointF(x, y); path.quadTo(c, e); ctrlPt = c; x = e.x(); y = e.y(); break; } case 'a': { if (count < 7) { num += count; count = 0; break; } qreal rx = (*num++); qreal ry = (*num++); qreal xAxisRotation = (*num++); qreal largeArcFlag = (*num++); qreal sweepFlag = (*num++); qreal ex = (*num++) + offsetX; qreal ey = (*num++) + offsetY; count -= 7; qreal curx = x; qreal cury = y; pathArc(path, rx, ry, xAxisRotation, int(largeArcFlag), int(sweepFlag), ex, ey, curx, cury); x = ex; y = ey; } break; case 'A': { if (count < 7) { num += count; count = 0; break; } qreal rx = (*num++); qreal ry = (*num++); qreal xAxisRotation = (*num++); qreal largeArcFlag = (*num++); qreal sweepFlag = (*num++); qreal ex = (*num++); qreal ey = (*num++); count -= 7; qreal curx = x; qreal cury = y; pathArc(path, rx, ry, xAxisRotation, int(largeArcFlag), int(sweepFlag), ex, ey, curx, cury); x = ex; y = ey; } break; default: return false; } lastMode = pathElem.toLatin1(); } } return true; }
bool QObjectProxy::invokeMethod( const char *method, PyrSlot *retSlot, PyrSlot *argSlot, Qt::ConnectionType ctype ) { mutex.lock(); if( !qObject ) { mutex.unlock(); return true; } // the signature char array QVarLengthArray<char, 512> sig; // serialize method name int len = qstrlen( method ); if( len <= 0 ) { mutex.unlock(); return false; } sig.append( method, len ); sig.append( '(' ); // get data from argument slots QtCollider::Variant argSlots[10]; if( isKindOfSlot( argSlot, class_Array ) ) { PyrSlot *slots = slotRawObject( argSlot )->slots; int size = slotRawObject( argSlot )->size; int i; for( i = 0; i<size && i<10; ++i ) { argSlots[i].setData( slots ); ++slots; } } else argSlots[0].setData( argSlot ); // serialize argument types int i; for( i = 0; i < 10; ++i ) { int type = argSlots[i].type(); if( type == QMetaType::Void ) break; const char *typeName = QMetaType::typeName( type ); int len = qstrlen( typeName ); if( len <= 0 ) break; sig.append( typeName, len ); sig.append( ',' ); } // finalize the signature if( i==0 ) sig.append( ')' ); else sig[sig.size() - 1] = ')'; sig.append('\0'); // get the meta method const QMetaObject *mo = qObject->metaObject(); int mi = mo->indexOfMethod( sig.constData() ); if( mi < 0 ) { QByteArray mnorm = QMetaObject::normalizedSignature( sig.constData() ); mi = mo->indexOfMethod( mnorm.constData() ); } if( mi < 0 || mi >= mo->methodCount() ) { qcProxyDebugMsg( 1, QString("WARNING: No such method: %1::%2").arg( mo->className() ) .arg( sig.constData() ) ); mutex.unlock(); return false; } QMetaMethod mm = mo->method( mi ); // construct the return data object QGenericReturnArgument retGArg; const char *retTypeName = mm.typeName(); int retType = QMetaType::type( retTypeName ); void *retPtr = 0; if( retSlot ) { retPtr = QMetaType::construct( retType ); retGArg = QGenericReturnArgument( retTypeName, retPtr ); } //do it! bool success = mm.invoke( qObject, ctype, retGArg, argSlots[0].asGenericArgument(), argSlots[1].asGenericArgument(), argSlots[2].asGenericArgument(), argSlots[3].asGenericArgument(), argSlots[4].asGenericArgument(), argSlots[5].asGenericArgument(), argSlots[6].asGenericArgument(), argSlots[7].asGenericArgument(), argSlots[8].asGenericArgument(), argSlots[9].asGenericArgument()); // store the return data into the return slot if( success && retPtr ) { QVariant retVar( retType, retPtr ); Slot::setVariant( retSlot, retVar ); }; if( retPtr ) QMetaType::destroy( retType, retPtr ); mutex.unlock(); return success; }
Kst::Object::UpdateType AsciiSource::internalDataSourceUpdate() { if (!_haveHeader) { _haveHeader = initRowIndex(); if (!_haveHeader) { return NoChange; } // Re-update the field list since we have one now _fieldList = fieldListFor(_filename, &_config); _fieldListComplete = _fieldList.count() > 1; // Re-update the scalar list since we have one now _scalarList = scalarListFor(_filename, &_config); _stringList = stringListFor(_filename, &_config); } QFile file(_filename); if (!openValidFile(file)) { // Qt: If the device is closed, the size returned will not reflect the actual size of the device. return NoChange; } bool forceUpdate; if (_byteLength == file.size()) { forceUpdate = false; } else { forceUpdate = true; _byteLength = file.size(); } int bufread; bool new_data = false; //bool first_read = (_numFrames == 0); QByteArray delbytes = _config._delimiters.value().toLatin1(); const char *del = delbytes.constData(); do { // Read the tmpbuffer, starting at row_index[_numFrames] QVarLengthArray<char, MAXBUFREADLEN + 1> varBuffer; varBuffer.resize(varBuffer.capacity()); int bufstart = _rowIndex[_numFrames]; bufread = readFromFile(file, varBuffer, bufstart, _byteLength - bufstart, MAXBUFREADLEN); #ifdef KST_DONT_CHECK_INDEX_IN_DEBUG const char* buffer = varBuffer.constData(); const char* bufferData = buffer; #else QVarLengthArray<char, MAXBUFREADLEN + 1>& buffer = varBuffer; const char* bufferData = buffer.data(); #endif bool is_comment = false, has_dat = false; char *comment = strpbrk(const_cast<char*>(bufferData), del); for (int i = 0; i < bufread; i++) { if (comment == &(buffer[i])) { is_comment = true; } else if (buffer[i] == '\n' || buffer[i] == '\r') { if (has_dat) { ++_numFrames; if (_numFrames >= _rowIndex.size()) { _rowIndex.resize(_rowIndex.size() + 32768); if (_numFrames >= _rowIndex.size()) { // TODO where could we report an error; return NoChange; } } new_data = true; } _rowIndex[_numFrames] = bufstart + i + 1; has_dat = is_comment = false; if (comment && comment < &(buffer[i])) { comment = strpbrk(const_cast<char*>(&(buffer[i])), del); } } else if (!is_comment && !isspace((unsigned char)buffer[i])) { // FIXME: this breaks custom delimiters has_dat = true; } } } while ((bufread == MAXBUFREADLEN)); // && (!first_read)); return (forceUpdate ? Updated : (new_data ? Updated : NoChange)); }