当前位置: 首页>>代码示例>>C++>>正文


C++ QByteArray::append方法代码示例

本文整理汇总了C++中QByteArray::append方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::append方法的具体用法?C++ QByteArray::append怎么用?C++ QByteArray::append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QByteArray的用法示例。


在下文中一共展示了QByteArray::append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: readPCX

bool QPcxHandler::readPCX(QByteArray data, QImage *image)
{
    QDataStream input(data);
    if (data.isNull())
        input.setDevice(device());
    input.setByteOrder(QDataStream::LittleEndian);

    quint8 manufacturer, version, encoding, bitsPerPixel,
            reserved, colorPlanes;
    quint16 xMin, yMin, xMax, yMax, verticalDPI,
            horizontalDPI, bytesPerPlaneLine,
            paletteType, horizontalScreenSize, verticalScreenSize;

    input >> manufacturer;
    if (manufacturer != 0x0A)
        return false;

    input >> version;
    input >> encoding;
    if (encoding != 0)
        if (encoding != 1)
            return false;

    //Number of bits per pixel in each colour plane (1, 2, 4, 8, 24)
    input >> bitsPerPixel;
    switch (bitsPerPixel) {
    case 1:
    case 2:
    case 4:
    case 8:
    case 24:
        break;
    default: return false;
        break;
    }

    input >> xMin >> yMin >> xMax >> yMax;
    int width = xMax - xMin + 1;
    int height = yMax - yMin + 1;
    input >> verticalDPI >> horizontalDPI;

    //if bitsPerPixel <= 4 palette is present here
    quint8 byte;
    QByteArray colorMap;
    for (int i = 0; i<48; ++i) {
        input >> byte;
        colorMap.append(byte);
    }

    input >> reserved;
    if (reserved != 0)
        return false;

    //observed that pcx file format was badly designed since
    //the number of color planes was placed here and not before the
    //palette. it is needed for 16 color.
    input >> colorPlanes;
    input >> bytesPerPlaneLine;

    /* encountered uneven bytesPerPlaneLine so I decided not to check
     * it if it is an even number or not
    if (bytesPerPlaneLine%2 != 0)
        return false;
    */

    int fillerCount;
    input >> paletteType;
    if (version >= 4) {
        fillerCount = 54;
        input >> horizontalScreenSize >> verticalScreenSize;
    } else {
开发者ID:yuezhao,项目名称:libqpcx,代码行数:71,代码来源:qpcxhandler.cpp

示例2: write_pbm_image

static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QByteArray &sourceFormat)
{
    QByteArray str;
    QImage image = sourceImage;
    QByteArray format = sourceFormat;

    format = format.left(3);                        // ignore RAW part
    bool gray = format == "pgm";

    if (format == "pbm") {
        image = image.convertToFormat(QImage::Format_Mono);
    } else if (image.depth() == 1) {
        image = image.convertToFormat(QImage::Format_Indexed8);
    } else {
        switch (image.format()) {
        case QImage::Format_RGB16:
        case QImage::Format_RGB666:
        case QImage::Format_RGB555:
        case QImage::Format_RGB888:
        case QImage::Format_RGB444:
            image = image.convertToFormat(QImage::Format_RGB32);
            break;
        case QImage::Format_ARGB8565_Premultiplied:
        case QImage::Format_ARGB6666_Premultiplied:
        case QImage::Format_ARGB8555_Premultiplied:
        case QImage::Format_ARGB4444_Premultiplied:
            image = image.convertToFormat(QImage::Format_ARGB32);
            break;
        default:
            break;
        }
    }

    if (image.depth() == 1 && image.colorCount() == 2) {
        if (qGray(image.color(0)) < qGray(image.color(1))) {
            // 0=dark/black, 1=light/white - invert
            image.detach();
            for (int y=0; y<image.height(); y++) {
                uchar *p = image.scanLine(y);
                uchar *end = p + image.bytesPerLine();
                while (p < end)
                    *p++ ^= 0xff;
            }
        }
    }

    uint w = image.width();
    uint h = image.height();

    str = "P\n";
    str += QByteArray::number(w);
    str += ' ';
    str += QByteArray::number(h);
    str += '\n';

    switch (image.depth()) {
        case 1: {
            str.insert(1, '4');
            if (out->write(str, str.length()) != str.length())
                return false;
            w = (w+7)/8;
            for (uint y=0; y<h; y++) {
                uchar* line = image.scanLine(y);
                if (w != (uint)out->write((char*)line, w))
                    return false;
            }
            }
            break;

        case 8: {
            str.insert(1, gray ? '5' : '6');
            str.append("255\n");
            if (out->write(str, str.length()) != str.length())
                return false;
            QVector<QRgb> color = image.colorTable();
            uint bpl = w*(gray ? 1 : 3);
            uchar *buf   = new uchar[bpl];
            for (uint y=0; y<h; y++) {
                uchar *b = image.scanLine(y);
                uchar *p = buf;
                uchar *end = buf+bpl;
                if (gray) {
                    while (p < end) {
                        uchar g = (uchar)qGray(color[*b++]);
                        *p++ = g;
                    }
                } else {
                    while (p < end) {
                        QRgb rgb = color[*b++];
                        *p++ = qRed(rgb);
                        *p++ = qGreen(rgb);
                        *p++ = qBlue(rgb);
                    }
                }
                if (bpl != (uint)out->write((char*)buf, bpl))
                    return false;
            }
            delete [] buf;
            }
            break;
//.........这里部分代码省略.........
开发者ID:fluxer,项目名称:katie,代码行数:101,代码来源:qppmhandler.cpp

示例3: main


//.........这里部分代码省略.........
	while( ( SerialSelected->waitForReadyRead(10000) ) ){
    
	  if( SerialSelected->canReadLine() ){
	   
	    dataBuffer = SerialSelected->readAll();
	    standard_out << dataBuffer << flush;
	    log_out << QObject::tr("[r]:\n") << dataBuffer << flush;
	    dataBuffer.clear();
	    break;
	  }
	}
	SerialSelected->clear();
	SerialSelected->readAll();

        break;
	
      case 'w':
	SerialSelected->write("w");
	SerialSelected->flush();
	standard_out << QObject::tr("Inserire il valore della duty Cicle\n>>") << flush;
	standard_in >> tmp;
	SerialSelected->write(tmp.toStdString().c_str());
	SerialSelected->flush();
	SerialSelected->readAll();
	break;
	
	
	
      case 'a':
        SerialSelected->write("a");
	SerialSelected->flush();
	SerialSelected->clear();

	Data.append("#").append(logTime.toString("ddMMyyyy hhmmss") ).append("\n");
	Data.append("#Scanning on dutyCicle\n#duty\tmean\tsigma\n");
	{
	  QByteArray tmp_data;
	  bool breakWhile=false;
	  while( ( SerialSelected->waitForReadyRead(-1) ) ){
	      tmp_data.clear();
	      tmp_data.append( SerialSelected->readAll() );

	      
	      if( tmp_data.contains('$') ){
		tmp_data.remove( tmp_data.indexOf('$'),1 );
		standard_out << "ora esco" << endl;

		breakWhile=true;
	      }
	      tmp_data.replace(':','\t');
	      tmp_data.replace('%','\n');
	      standard_out << tmp_data << flush;
	      Data.append(tmp_data);
	      
	      
	      if( breakWhile ) break;
	  }
	}
	SerialSelected->readAll();
	
	break;
	
      case 't':
	SerialSelected->write("t");
	SerialSelected->flush();
	SerialSelected->clear();
开发者ID:ndrgrimm,项目名称:Spiedo_PC,代码行数:67,代码来源:main.cpp

示例4: run

void SimThread::run()
{
	init = true;
	currentLocationPacket=0;
	currentLocationInfoPacket=0;
	QFile logfile(m_filename);
	if (!logfile.open(QIODevice::ReadOnly))
	{
		qDebug() << "Unable to open file. Exiting sim thread";
		return;
	}
	QByteArray logbytes = logfile.readAll();
	nextPacketIsLocation = false;

	QByteArray qbuffer;
	QList<QByteArray> m_queuedMessages;
	QString byteoutofpacket;
	bool m_inpacket = false;
	bool m_inescape = false;
	for (int i=0;i<logbytes.size();i++)
	{
		if ((unsigned char)logbytes[i] == 0xAA)
		{
			if (m_inpacket)
			{
				//Start byte in the middle of a packet
				//Clear out the buffer and start fresh
				m_inescape = false;
				qbuffer.clear();
			}
			//qbuffer.append(buffer[i]);
			//qDebug() << "Start of packet";
			//Start of packet
			m_inpacket = true;
		}
		else if ((unsigned char)logbytes[i] == 0xCC && m_inpacket)
		{
			//qDebug() << "End of packet. Size:" << qbuffer.size();
			//End of packet
			m_inpacket = false;
			//qbuffer.append(buffer[i]);

			//m_logFile->flush();
			//emit parseBuffer(qbuffer);


			//New Location of checksum
			unsigned char sum = 0;
			for (int i=0;i<qbuffer.size()-1;i++)
			{
				sum += qbuffer[i];
			}
			//qDebug() << "Payload sum:" << QString::number(sum);
			//qDebug() << "Checksum sum:" << QString::number((unsigned char)currPacket[currPacket.length()-1]);
			if (sum != (unsigned char)qbuffer[qbuffer.size()-1])
			{
				qDebug() << "BAD CHECKSUM!";
				//return QPair<QByteArray,QByteArray>();
			}
			else
			{
				m_queuedMessages.append(qbuffer.mid(0,qbuffer.length()-1));
			}
			//return qbuffer;
			QString output;
			for (int i=0;i<qbuffer.size();i++)
			{
				int num = (unsigned char)qbuffer[i];
				output.append(" ").append((num < 0xF) ? "0" : "").append(QString::number(num,16));
			}
			//qDebug() << "Full packet:";
			//qDebug() << output;
			qbuffer.clear();
		}
		else
		{
			if (m_inpacket && !m_inescape)
			{
				if ((unsigned char)logbytes[i] == 0xBB)
				{
					//Need to escape the next byte
					//retval = logfile.read(1);
					m_inescape = true;
				}
				else
				{
					qbuffer.append(logbytes[i]);
				}

			}
			else if (m_inpacket && m_inescape)
			{
				if ((unsigned char)logbytes[i] == 0x55)
				{
					qbuffer.append((char)0xAA);
				}
				else if ((unsigned char)logbytes[i] == 0x44)
				{
					qbuffer.append((char)0xBB);
				}
//.........这里部分代码省略.........
开发者ID:digideskio,项目名称:freeemssim,代码行数:101,代码来源:simthread.cpp

示例5: generatePacket

QByteArray SimThread::generatePacket(QByteArray header,QByteArray payload)
{
	QByteArray packet;
	packet.append((char)0xAA);
	unsigned char checksum = 0;
	for (int i=0;i<header.size();i++)
	{
		checksum += header[i];
	}
	for (int i=0;i<payload.size();i++)
	{
		checksum += payload[i];
	}
	payload.append(checksum);
	for (int j=0;j<header.size();j++)
	{
		if (header[j] == (char)0xAA)
		{
			packet.append((char)0xBB);
			packet.append((char)0x55);
		}
		else if (header[j] == (char)0xBB)
		{
			packet.append((char)0xBB);
			packet.append((char)0x44);
		}
		else if (header[j] == (char)0xCC)
		{
			packet.append((char)0xBB);
			packet.append((char)0x33);
		}
		else
		{
			packet.append(header[j]);
		}
	}
	for (int j=0;j<payload.size();j++)
	{
		if (payload[j] == (char)0xAA)
		{
			packet.append((char)0xBB);
			packet.append((char)0x55);
		}
		else if (payload[j] == (char)0xBB)
		{
			packet.append((char)0xBB);
			packet.append((char)0x44);
		}
		else if (payload[j] == (char)0xCC)
		{
			packet.append((char)0xBB);
			packet.append((char)0x33);
		}
		else
		{
			packet.append(payload[j]);
		}
	}
	//packet.append(header);
	//packet.append(payload);
	packet.append((char)0xCC);
	return packet;
}
开发者ID:digideskio,项目名称:freeemssim,代码行数:63,代码来源:simthread.cpp

示例6: preprocess

void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed)
{
    currentFilenames.push(filename);
    preprocessed.reserve(preprocessed.size() + symbols.size());
    while (hasNext()) {
        Token token = next();

        switch (token) {
        case PP_INCLUDE:
        {
            int lineNum = symbol().lineNum;
            QByteArray include;
            bool local = false;
            if (test(PP_STRING_LITERAL)) {
                local = lexem().startsWith('\"');
                include = unquotedLexem();
            } else
                continue;
            until(PP_NEWLINE);

            // #### stringery
            QFileInfo fi;
            if (local)
                fi.setFile(QFileInfo(QString::fromLocal8Bit(filename)).dir(), QString::fromLocal8Bit(include));
            for (int j = 0; j < Preprocessor::includes.size() && !fi.exists(); ++j) {
                const IncludePath &p = Preprocessor::includes.at(j);
                if (p.isFrameworkPath) {
                    const int slashPos = include.indexOf('/');
                    if (slashPos == -1)
                        continue;
                    QByteArray frameworkCandidate = include.left(slashPos);
                    frameworkCandidate.append(".framework/Headers/");
                    fi.setFile(QString::fromLocal8Bit(p.path + '/' + frameworkCandidate), QString::fromLocal8Bit(include.mid(slashPos + 1)));
                } else {
                    fi.setFile(QString::fromLocal8Bit(p.path), QString::fromLocal8Bit(include));
                }
                // try again, maybe there's a file later in the include paths with the same name
                // (186067)
                if (fi.isDir()) {
                    fi = QFileInfo();
                    continue;
                }
            }

            if (!fi.exists() || fi.isDir())
                continue;
            include = fi.canonicalFilePath().toLocal8Bit();

            if (Preprocessor::preprocessedIncludes.contains(include))
                continue;
            Preprocessor::preprocessedIncludes.insert(include);

            QFile file(QString::fromLocal8Bit(include));
            if (!file.open(QFile::ReadOnly))
                continue;

            QByteArray input = file.readAll();
            file.close();
            if (input.isEmpty())
                continue;

            Symbols saveSymbols = symbols;
            int saveIndex = index;

            // phase 1: get rid of backslash-newlines
            input = cleaned(input);

            // phase 2: tokenize for the preprocessor
            symbols = tokenize(input);
            input.clear();

            index = 0;

            // phase 3: preprocess conditions and substitute macros
            preprocessed += Symbol(0, MOC_INCLUDE_BEGIN, include);
            preprocess(include, preprocessed);
            preprocessed += Symbol(lineNum, MOC_INCLUDE_END, include);

            symbols = saveSymbols;
            index = saveIndex;
            continue;
        }
        case PP_DEFINE:
        {
            next(IDENTIFIER);
            QByteArray name = lexem();
            int start = index;
            until(PP_NEWLINE);
            Macro macro;
            macro.symbols.reserve(index - start - 1);
            for (int i = start; i < index - 1; ++i)
                macro.symbols += symbols.at(i);
            macros.insert(name, macro);
            continue;
        }
        case PP_UNDEF: {
            next(IDENTIFIER);
            QByteArray name = lexem();
            until(PP_NEWLINE);
            macros.remove(name);
//.........这里部分代码省略.........
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:101,代码来源:preprocessor.cpp

示例7: appendTag

void BerTLV::appendTag(QByteArray& buffer) {
    // convert the hexstring to bytes
    QByteArray tagBytes = QByteArray::fromHex(_tag.toAscii());

    buffer.append(tagBytes);
}
开发者ID:CurtisLee,项目名称:Cascades-Community-Samples,代码行数:6,代码来源:BerTLV.cpp

示例8: slotReadyRead

void QXmppSocksServer::slotReadyRead()
{
    QTcpSocket *socket = qobject_cast<QTcpSocket*>(sender());
    if (!socket || !m_states.contains(socket))
        return;

    if (m_states.value(socket) == ConnectState)
    {
        m_states.insert(socket, CommandState);

        // receive connect to server request
        QByteArray buffer = socket->readAll();
        if (buffer.size() < 3 ||
            buffer.at(0) != SocksVersion ||
            buffer.at(1) + 2 != buffer.size())
        {
            qWarning("QXmppSocksServer received invalid handshake");
            socket->close();
            return;
        }

        // check authentication method
        bool foundMethod = false;
        for (int i = 2; i < buffer.size(); i++)
        {
            if (buffer.at(i) == NoAuthentication)
            {
                foundMethod = true;
                break;
            }
        }
        if (!foundMethod)
        {
            qWarning("QXmppSocksServer received bad authentication method");
            socket->close();
            return;
        }

        // send connect to server response
        buffer.resize(2);
        buffer[0] = SocksVersion;
        buffer[1] = NoAuthentication;
        socket->write(buffer);

    } else if (m_states.value(socket) == CommandState) {
        m_states.insert(socket, ReadyState);

        // disconnect from signals
        disconnect(socket, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));

        // receive command
        QByteArray buffer = socket->readAll();
        if (buffer.size() < 4 ||
            buffer.at(0) != SocksVersion ||
            buffer.at(1) != ConnectCommand ||
            buffer.at(2) != 0x00)
        {
            qWarning("QXmppSocksServer received an invalid command");
            socket->close();
            return;
        }

        // parse host
        quint8 hostType;
        QByteArray hostName;
        quint16 hostPort;
        if (!parseHostAndPort(buffer.mid(3), hostType, hostName, hostPort))
        {
            qWarning("QXmppSocksServer could not parse type/host/port");
            socket->close();
            return;
        }

        // notify of connection
        emit newConnection(socket, hostName, hostPort);

        // send response
        buffer.resize(3);
        buffer[0] = SocksVersion;
        buffer[1] = Succeeded;
        buffer[2] = 0x00;
        buffer.append(encodeHostAndPort(
            DomainName,
            hostName,
            hostPort));
        socket->write(buffer);
    }
}
开发者ID:unisontech,项目名称:qxmpp,代码行数:88,代码来源:QXmppSocks.cpp

示例9: characters

QByteArray MumeXmlParser::characters(QByteArray &ch)
{
    QByteArray toUser;

    if (ch.isEmpty()) {
        return toUser;
    }

    // replace > and < chars
    stripXmlEntities(ch);

    const auto &config = getConfig();
    m_stringBuffer = QString::fromLatin1(ch);

    if (m_readSnoopTag && m_stringBuffer.length() > 3 && m_stringBuffer.at(0) == '&'
        && m_stringBuffer.at(2) == ' ') {
        // Remove snoop prefix (i.e. "&J Exits: north.")
        m_stringBuffer = m_stringBuffer.mid(3);
    }

    switch (m_xmlMode) {
    case XmlMode::NONE: // non room info
        m_stringBuffer = normalizeStringCopy(m_stringBuffer.trimmed());
        if (m_stringBuffer.isEmpty()) { // standard end of description parsed
            if (m_readingRoomDesc) {
                m_readingRoomDesc = false; // we finished read desc mode
                m_descriptionReady = true;
                if (config.mumeNative.emulatedExits) {
                    emulateExits();
                }
            }
        } else {
            parseMudCommands(m_stringBuffer);
        }
        if (m_readSnoopTag) {
            if (m_descriptionReady) {
                m_promptFlags.reset(); // Don't trust god prompts
                queue.enqueue(m_move);
                emit showPath(queue, true);
                move();
                m_readSnoopTag = false;
            }
        }
        toUser.append(ch);
        break;

    case XmlMode::ROOM: // dynamic line
        m_dynamicRoomDesc += normalizeStringCopy(m_stringBuffer.simplified().append("\n"));
        toUser.append(ch);
        break;

    case XmlMode::NAME:
        if (m_descriptionReady) {
            move();
        }
        m_readingRoomDesc = true; // start of read desc mode
        m_roomName = normalizeStringCopy(m_stringBuffer);
        toUser.append(ch);
        break;

    case XmlMode::DESCRIPTION: // static line
        m_staticRoomDesc += normalizeStringCopy(m_stringBuffer.simplified().append("\n"));
        if (!m_gratuitous) {
            toUser.append(ch);
        }
        break;

    case XmlMode::EXITS:
        m_exits += m_stringBuffer;
        if (m_readingRoomDesc) {
            m_readingRoomDesc = false;
            m_descriptionReady = true;
        }
        break;

    case XmlMode::PROMPT:
        emit sendPromptLineEvent(normalizeStringCopy(m_stringBuffer).toLatin1());
        if (m_readingRoomDesc) {       // fixes compact mode
            m_readingRoomDesc = false; // we finished read desc mode
            m_descriptionReady = true;
            if (config.mumeNative.emulatedExits) {
                emulateExits();
            }
        }
        if (m_descriptionReady) {
            parsePrompt(normalizeStringCopy(m_stringBuffer));
            move();
        }

        toUser.append(ch);
        break;

    case XmlMode::TERRAIN:
    default:
        toUser.append(ch);
        break;
    }

    if (!getConfig().parser.removeXmlTags) {
        toUser.replace(ampersand, ampersandTemplate);
//.........这里部分代码省略.........
开发者ID:MUME,项目名称:MMapper,代码行数:101,代码来源:mumexmlparser.cpp

示例10: sendReport

void CrashReportDialog::sendReport()
{
    if (m_uploadReply)
        return;

    if (!m_allowReport->isChecked())
    {
        done(m_finalResult);
        return;
    }

    QString platform =
#if defined(Q_OS_WIN)
                       QLatin1String("windows");
#elif defined(Q_OS_MAC)
                       QLatin1String("mac");
#elif defined(Q_OS_LINUX)
                       QLatin1String("linux");
#else
                       QLatin1String("unknown");
#endif

    QNetworkAccessManager *nam = new QNetworkAccessManager(this);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    QUrl queryUrl(m_reportUrl);
#else
    QUrlQuery queryUrl(m_reportUrl);
    QUrl url;
#endif
    queryUrl.addQueryItem(QLatin1String("version"), qApp->applicationVersion());
    queryUrl.addQueryItem(QLatin1String("platform"), platform);
    if (!m_emailInput->text().isEmpty())
        queryUrl.addQueryItem(QLatin1String("email"), m_emailInput->text());

    if (!m_dumpFile.exists() || !m_dumpFile.open(QIODevice::ReadOnly))
    {
        queryUrl.addQueryItem(QLatin1String("dump"), QLatin1String("0"));
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
        url.setQuery(queryUrl);
#endif
        m_uploadReply = nam->get(QNetworkRequest(url));
    }
    else
    {
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
        url.setQuery(queryUrl);
#endif
        QNetworkRequest req(url);
        const char *boundary = "UPLOADDUMP";
        req.setHeader(QNetworkRequest::ContentTypeHeader, QByteArray("multipart/form-data; boundary=") + boundary);

        QByteArray data;
        data.append("--");
        data.append(boundary);
        data.append("\r\ncontent-disposition: form-data; name=\"dump\"; filename=\"temp.dmp\"\r\nContent-Transfer-Encoding: binary\r\nContent-Length: ");
        data.append(m_dumpFile.size());
        data.append("\r\nContent-type: application/x-octet-stream\r\n\r\n");
        data.append(m_dumpFile.readAll());
        data.append("\r\n--");
        data.append(boundary);
        data.append("--\r\n");
        m_dumpFile.close();

        m_uploadReply = nam->post(req, data);
    }

    connect(m_uploadReply, SIGNAL(finished()), SLOT(uploadFinished()));
    bool ok = connect(m_uploadReply, SIGNAL(uploadProgress(qint64,qint64)), SLOT(setUploadProgress(qint64)));
    Q_UNUSED(ok);
    Q_ASSERT(ok);
    m_uploadProgress->setMaximum((int)m_dumpFile.size());

    m_stackLayout->setCurrentIndex(1);

    setFixedHeight(QWIDGETSIZE_MAX);
    QPropertyAnimation *resizeAnimation = new QPropertyAnimation(this, "size");
    resizeAnimation->setEndValue(QSize(width(), minimumSizeHint().height()));
    resizeAnimation->setDuration(150);
    resizeAnimation->setEasingCurve(QEasingCurve::InQuad);
    resizeAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
开发者ID:gaoxiaojun,项目名称:qtrader,代码行数:81,代码来源:crashreportdialog.cpp

示例11: itemText

/*!
    \fn QString QTextList::itemText(const QTextBlock &block) const

    Returns the text of the list item that corresponds to the given \a block.
*/
QString QTextList::itemText(const QTextBlock &blockIt) const
{
    Q_D(const QTextList);
    int item = d->blocks.indexOf(blockIt) + 1;
    if (item <= 0)
        return QString();

    QTextBlock block = d->blocks.at(item-1);
    QTextBlockFormat blockFormat = block.blockFormat();

    QString result;

    const int style = format().style();
    QString numberPrefix;
    QString numberSuffix = QLatin1String(".");

    if (format().hasProperty(QTextFormat::ListNumberPrefix))
        numberPrefix = format().numberPrefix();
    if (format().hasProperty(QTextFormat::ListNumberSuffix))
        numberSuffix = format().numberSuffix();

    switch (style) {
        case QTextListFormat::ListDecimal:
            result = QString::number(item);
            break;
            // from the old richtext
        case QTextListFormat::ListLowerAlpha:
        case QTextListFormat::ListUpperAlpha:
            {
                const char baseChar = style == QTextListFormat::ListUpperAlpha ? 'A' : 'a';

                int c = item;
                while (c > 0) {
                    c--;
                    result.prepend(QChar(baseChar + (c % 26)));
                    c /= 26;
                }
            }
            break;
        case QTextListFormat::ListLowerRoman:
        case QTextListFormat::ListUpperRoman:
            {
                if (item < 5000) {
                    QByteArray romanNumeral;

                    // works for up to 4999 items
                    static const char romanSymbolsLower[] = "iiivixxxlxcccdcmmmm";
                    static const char romanSymbolsUpper[] = "IIIVIXXXLXCCCDCMMMM";
                    QByteArray romanSymbols; // wrap to have "mid"
                    if (style == QTextListFormat::ListLowerRoman)
                        romanSymbols = QByteArray::fromRawData(romanSymbolsLower, sizeof(romanSymbolsLower));
                    else
                        romanSymbols = QByteArray::fromRawData(romanSymbolsUpper, sizeof(romanSymbolsUpper));

                    int c[] = { 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 };
                    int n = item;
                    for (int i = 12; i >= 0; n %= c[i], i--) {
                        int q = n / c[i];
                        if (q > 0) {
                            int startDigit = i + (i+3)/4;
                            int numDigits;
                            if (i % 4) {
                                // c[i] == 4|5|9|40|50|90|400|500|900
                                if ((i-2) % 4) {
                                    // c[i] == 4|9|40|90|400|900 => with subtraction (IV, IX, XL, XC, ...)
                                    numDigits = 2;
                                }
                                else {
                                    // c[i] == 5|50|500 (V, L, D)
                                    numDigits = 1;
                                }
                            }
                            else {
                                // c[i] == 1|10|100|1000 (I, II, III, X, XX, ...)
                                numDigits = q;
                            }

                            romanNumeral.append(romanSymbols.mid(startDigit, numDigits));
                        }
                    }
                    result = QString::fromLatin1(romanNumeral);
                }
                else {
                    result = QLatin1String("?");
                }

            }
            break;
        default:
            Q_ASSERT(false);
    }
    if (blockIt.textDirection() == Qt::RightToLeft)
        return numberSuffix + result + numberPrefix;
    else
        return numberPrefix + result + numberSuffix;
//.........这里部分代码省略.........
开发者ID:3163504123,项目名称:phantomjs,代码行数:101,代码来源:qtextlist.cpp

示例12: musicFile


//.........这里部分代码省略.........
            continue;
        }
        //Generate a data frame.
        APETagItem item;
        //Save the key.
        item.key=key;
        //According to the frame, generate the item.
        switch(i)
        {
        case DiscNumber:
            //If disc count isn't empty, then add disc count to disc number
            //data.
            item.value=detailInfo.textLists[DiscCount].toString().isEmpty()?
                        detailInfo.textLists[DiscNumber].toString().toUtf8():
                        (detailInfo.textLists[DiscNumber].toString()+"/"+
                         detailInfo.textLists[DiscCount].toString()).toUtf8();
        default:
            //Add the whole data to the item.
            item.value=detailInfo.textLists[i].toString().toUtf8();
        }
        //Remove the all the original item.
        //We have to check the key from the back to the first, and we won't get
        //mess to the index.
        for(int i=itemList.size()-1; i>-1; i--)
        {
            //If the key is the same as current key,
            if(itemList.at(i).key==key)
            {
                //Remove it.
                itemList.removeAt(i);
            }
        }
        //Add current key to item list.
        itemList.append(item);
    }
    //Now translate the frame structure data to the raw data.
    QByteArray contentData;
    //Prepare the cache size.
    char numberCache[4];
    //Simply transferred the APETagItem to content data.
    for(auto i=itemList.constBegin(); i!=itemList.constEnd(); ++i)
    {
        //Get the item size.
        quint32 size=(*i).value.size();
        //First transfer item size to raw data into cache.
        numberToData(size, numberCache);
        //Add item size to content data.
        contentData.append(numberCache, 4);
        //Transfer the flag to raw data into cache.
        numberToData((*i).flag, numberCache);
        //Add flag data to content data.
        contentData.append(numberCache, 4);
        //Add item key to content data.
        contentData.append((*i).key.toUtf8());
        //Add 0x00 for item key terminator.
        contentData.append('\0');
        //Add item value.
        contentData.append((*i).value);
    }

    //Update the header data.
    header.size=contentData.size()+32;
    header.itemCount=itemList.size();

    //We will write the APEv2 data to the end part of the file. Just before the
    //ID3v1.
开发者ID:Kreogist,项目名称:Mu,代码行数:67,代码来源:knmusictagapev2.cpp

示例13: parseMethods

void QDBusMetaObjectGenerator::parseMethods()
{
    //
    // TODO:
    //  Add cloned methods when the remote object has return types
    //

    QDBusIntrospection::Methods::ConstIterator method_it = data->methods.constBegin();
    QDBusIntrospection::Methods::ConstIterator method_end = data->methods.constEnd();
    for ( ; method_it != method_end; ++method_it) {
        const QDBusIntrospection::Method &m = *method_it;
        Method mm;

        mm.name = m.name.toLatin1();
        QByteArray prototype = mm.name;
        prototype += '(';

        bool ok = true;

        // build the input argument list
        for (int i = 0; i < m.inputArgs.count(); ++i) {
            const QDBusIntrospection::Argument &arg = m.inputArgs.at(i);

            Type type = findType(arg.type.toLatin1(), m.annotations, "In", i);
            if (type.id == QVariant::Invalid) {
                ok = false;
                break;
            }

            mm.inputSignature += arg.type.toLatin1();
            mm.inputTypes.append(type.id);

            mm.parameters.append(arg.name.toLatin1());
            mm.parameters.append(',');
            
            prototype.append(type.name);
            prototype.append(',');
        }
        if (!ok) continue;

        // build the output argument list:
        for (int i = 0; i < m.outputArgs.count(); ++i) {
            const QDBusIntrospection::Argument &arg = m.outputArgs.at(i);

            Type type = findType(arg.type.toLatin1(), m.annotations, "Out", i);
            if (type.id == QVariant::Invalid) {
                ok = false;
                break;
            }

            mm.outputSignature += arg.type.toLatin1();
            mm.outputTypes.append(type.id);

            if (i == 0) {
                // return value
                mm.typeName = type.name;
            } else {
                // non-const ref parameter
                mm.parameters.append(arg.name.toLatin1());
                mm.parameters.append(',');

                prototype.append(type.name);
                prototype.append("&,");
            }
        }
        if (!ok) continue;

        // convert the last commas:
        if (!mm.parameters.isEmpty()) {
            mm.parameters.truncate(mm.parameters.length() - 1);
            prototype[prototype.length() - 1] = ')';
        } else {
            prototype.append(')');
        }

        // check the async tag
        if (m.annotations.value(QLatin1String(ANNOTATION_NO_WAIT)) == QLatin1String("true"))
            mm.tag = "Q_NOREPLY";

        // meta method flags
        mm.flags = AccessPublic | MethodSlot | MethodScriptable;

        // add
        methods.insert(QMetaObject::normalizedSignature(prototype), mm);
    }
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.vendor,代码行数:86,代码来源:qdbusmetaobject.cpp

示例14: foreach

const QByteArray
AbstractDictionary::wordData(quint32 indexItemOffset, qint32 indexItemSize)
{
    // Check first whether or not the data is already available in the cache
    foreach (const WordEntry& cacheItem, d->cacheItemList)
    {
        if (!cacheItem.data().isEmpty() && cacheItem.dataOffset() == indexItemOffset)
            return cacheItem.data();
    }

    QByteArray resultData;
    QByteArray originalData;

    if (!d->sameTypeSequence.isEmpty())
    {
        if (d->dictionaryFile->isOpen())
        {
            d->dictionaryFile->seek(indexItemOffset);
            originalData = d->dictionaryFile->read(indexItemSize);
        }
        else
        {
            originalData = d->compressedDictionaryFile->read(indexItemOffset, indexItemSize);
        }

        int sameTypeSequenceLength = d->sameTypeSequence.length();

        int sectionSize = 0;
        int sectionPosition = 0;

        // Copy the head items.
        foreach (const QChar& ch, d->sameTypeSequence.left(sameTypeSequenceLength - 1))
        {
            if (ch.isUpper())
            {
                sectionSize = *reinterpret_cast<quint32 *>(originalData.mid(sectionPosition).data());
                sectionSize += sizeof(quint32);
            }
            else
            {
                sectionSize = qstrlen(originalData.mid(sectionPosition)) + 1;
            }

            resultData.append(ch);
            resultData.append(originalData.mid(sectionPosition, sectionSize));
            sectionPosition += sectionSize;
        }

        // Calculate the last item's size.
        sectionSize = indexItemSize - sectionPosition;
        resultData.append(d->sameTypeSequence.at(sameTypeSequenceLength - 1));
        if (d->sameTypeSequence.at(sameTypeSequenceLength - 1).isUpper())
        {
            resultData.append(reinterpret_cast<char*>(&sectionSize), sizeof(quint32));
            resultData.append(originalData.mid(sectionPosition, sectionSize));
        }
        else
        {
            resultData.append(originalData.mid(sectionPosition, sectionSize));
            sectionPosition += sectionSize;
            resultData.append('\0');
        }
    }
    else
    {
        if (d->dictionaryFile->isOpen())
开发者ID:KDE,项目名称:mula,代码行数:66,代码来源:abstractdictionary.cpp

示例15: calcFingerPrint

QString chromaprinter::calcFingerPrint(SoundSourceProxy& soundSource){
    soundSource.open();
    m_SampleRate = soundSource.getSampleRate();
    unsigned int length = soundSource.length();
    if (m_SampleRate == 0 ){
        qDebug() << "Skipping invalid file:" << soundSource.getFilename();
        return QString();
    }

    // this is worth 2min of audio, multiply by 2 because we have 2 channels
    // AcoustID only stores a fingerprint for the first two minutes of a song
    // on their server so we need only a fingerprint of the first two minutes
    // --kain88 July 2012
    m_NumSamples = 120*2*m_SampleRate;
    // check that the song is actually longer then the amount of audio we use
    if (m_NumSamples > length) {
        m_NumSamples = length;
    }

    SAMPLE *pData = new SAMPLE[m_NumSamples];
    QTime timerReadingFile;
    timerReadingFile.start();
    unsigned int read = soundSource.read(m_NumSamples, pData);

    if (read!=m_NumSamples) {
        qDebug() << "oh that's embarrasing I couldn't read the track";
        return QString();
    }
    qDebug("reading file took: %d ms" , timerReadingFile.elapsed());

    ChromaprintContext* ctx = chromaprint_new(CHROMAPRINT_ALGORITHM_DEFAULT);
    // we have 2 channels in mixxx always
    chromaprint_start(ctx, m_SampleRate, 2);

    QTime timerGeneratingFingerPrint;
    timerGeneratingFingerPrint.start();
    int success = chromaprint_feed(ctx, pData, m_NumSamples);
    if (!success) {
        qDebug() << "could not generate fingerprint";
        delete [] pData;
        return QString();
    }
    chromaprint_finish(ctx);

    void* fprint = NULL;
    int size = 0;
    int ret = chromaprint_get_raw_fingerprint(ctx, &fprint, &size);
    QByteArray fingerprint;
    if (ret == 1) {
        void* encoded = NULL;
        int encoded_size = 0;
        chromaprint_encode_fingerprint(fprint, size,
                                       CHROMAPRINT_ALGORITHM_DEFAULT,
                                       &encoded,
                                       &encoded_size, 1);

        fingerprint.append(reinterpret_cast<char*>(encoded), encoded_size);

        chromaprint_dealloc(fprint);
        chromaprint_dealloc(encoded);
    }
    chromaprint_free(ctx);
    delete [] pData;

    qDebug("generating fingerprint took: %d ms" , timerGeneratingFingerPrint.elapsed());

    return fingerprint;
}
开发者ID:PimpinFou,项目名称:mixxx,代码行数:68,代码来源:chromaprinter.cpp


注:本文中的QByteArray::append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。