示例#1
0
QT_BEGIN_NAMESPACE

ResourceHelper::ResourceHelper()
{
    qFill(palettes, palettes + QPlatformTheme::NPalettes, static_cast<QPalette *>(0));
    qFill(fonts, fonts + QPlatformTheme::NFonts, static_cast<QFont *>(0));
}
void WidgetSelection::updateActive()
{
    const WidgetState ws = widgetState(m_formWindow->core(), m_widget);
    bool active[WidgetHandle::TypeCount];
    qFill(active, active + WidgetHandle::TypeCount, false);
    // Determine active handles
    switch (ws) {
    case UnlaidOut:
        qFill(active, active + WidgetHandle::TypeCount, true);
        break;
    case ManagedGridLayout: // Grid: Allow changing span
        active[WidgetHandle::Left] = active[WidgetHandle::Top] = active[WidgetHandle::Right] = active[WidgetHandle::Bottom] = true;
        break;
    case ManagedFormLayout:  // Form: Allow changing column span
        if (const unsigned operation = ChangeFormLayoutItemRoleCommand::possibleOperations(m_formWindow->core(), m_widget)) {
            active[WidgetHandle::Left]  = operation & (ChangeFormLayoutItemRoleCommand::SpanningToField|ChangeFormLayoutItemRoleCommand::FieldToSpanning);
            active[WidgetHandle::Right] = operation & (ChangeFormLayoutItemRoleCommand::SpanningToLabel|ChangeFormLayoutItemRoleCommand::LabelToSpanning);
        }
        break;
    default:
        break;
    }

    for (int i = WidgetHandle::LeftTop; i < WidgetHandle::TypeCount; ++i)
        if (WidgetHandle *h = m_handles[i]) {
            h->setWidget(m_widget);
            h->setActive(active[i]);
        }
}
示例#3
0
void ResourceHelper::clear()
{
    qDeleteAll(palettes, palettes + QPlatformTheme::NPalettes);
    qDeleteAll(fonts, fonts + QPlatformTheme::NFonts);
    qFill(palettes, palettes + QPlatformTheme::NPalettes, static_cast<QPalette *>(0));
    qFill(fonts, fonts + QPlatformTheme::NFonts, static_cast<QFont *>(0));
}
示例#4
0
int main(int argc, char**argv)
{
    QCoreApplication app(argc, argv);

    // create it
    QAbstractSocketEngine *socketEngine =
            QAbstractSocketEngine::createSocketEngine(QAbstractSocket::TcpSocket, QNetworkProxy(QNetworkProxy::NoProxy), 0);
    if (!socketEngine) {
        qDebug() << "could not create engine";
        exit(1);
    }

    // initialize it
    bool initialized = socketEngine->initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol);
    if (!initialized) {
        qDebug() << "not able to initialize engine";
        exit(1);
    }

    // wait for connected
    int r = socketEngine->connectToHost(QHostAddress("74.125.77.99"), 80); // google
    bool readyToRead = false;
    bool readyToWrite = false;
    socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, true, true, 10*1000);
    if (r <= 0) //timeout or error
        exit(1);
    if (readyToWrite) {
        // write the request
        QByteArray request("GET /robots.txt HTTP/1.0\r\n\r\n");
        int ret = socketEngine->write(request.constData(), request.length());
        if (ret == request.length()) {
            // read the response in a loop
            do {
                bool waitReadResult = socketEngine->waitForRead(10*1000);
                int available = socketEngine->bytesAvailable();
                if (waitReadResult == true && available == 0) {
                    // disconnected
                    exit(0);
                }
                qFill(buf, buf + bufsize, 0);
                ret = socketEngine->read(buf, available);
                if (ret > 0) {
                    printf("%s", buf);
                } else {
                    // some failure when reading
                    exit(1);
                }
            } while (1);
        } else {
            qDebug() << "failed writing";
        }
    } else {
        qDebug() << "failed connecting";
    }
    delete socketEngine;
}
示例#5
0
QColorDialogStaticData::QColorDialogStaticData() : customSet(false)
{
    int i = 0;
    for (int g = 0; g < 4; ++g)
        for (int r = 0;  r < 4; ++r)
            for (int b = 0; b < 3; ++b)
                standardRgb[i++] = qRgb(r * 255 / 3, g * 255 / 3, b * 255 / 2);
    qFill(customRgb, customRgb + CustomColorCount, 0xffffffff);
    readSettings();
}
示例#6
0
int main(int argc, char **argv)
{
    int numprocs, rank;
    MPI_Status status;

    int max = (1 << 20);
    QVector<int> send(max);
    QVector<int> recv(max);

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    if (numprocs != 2) {
        printf("Error: number of processors must be equal to 2\n");
        MPI_Finalize();
        return -1;
    }

    qFill(send, rank);

    if (rank == 0) {
        for (int i = 1; i < max; i = i * 2) {
            qFill(recv, 0);
            qDebug() << "exchange" << i;
            MPI_Send(send.data(), i, MPI_INT, 1, i, MPI_COMM_WORLD);
            MPI_Recv(recv.data(), i, MPI_INT, 1, i, MPI_COMM_WORLD, &status);
        }
    } else {
        qFill(recv, 0);
        for (int i = 1; i < max; i = i * 2) {
            MPI_Send(send.data(), i, MPI_INT, 0, i, MPI_COMM_WORLD);
            MPI_Recv(recv.data(), i, MPI_INT, 0, i, MPI_COMM_WORLD, &status);
        }
    }

    qDebug() << "rank" << rank << "done";

    MPI_Finalize();
    return 0;
}
static HGLRC createContext(const QOpenGLStaticContext &staticContext,
                           HDC hdc,
                           const QSurfaceFormat &format,
                           const QWindowsOpenGLAdditionalFormat &,
                           HGLRC shared = 0)
{
    enum { attribSize = 11 };

    if (!staticContext.hasExtensions())
        return 0;
    int attributes[attribSize];
    int attribIndex = 0;
    qFill(attributes, attributes + attribSize, int(0));
    const int requestedVersion = (format.majorVersion() << 8) + format.minorVersion();
    if (requestedVersion > 0x0101) {
        attributes[attribIndex++] = WGL_CONTEXT_MAJOR_VERSION_ARB;
        attributes[attribIndex++] = format.majorVersion();
        attributes[attribIndex++] = WGL_CONTEXT_MINOR_VERSION_ARB;
        attributes[attribIndex++] = format.minorVersion();
    }
    if (requestedVersion >= 0x0300) {
        attributes[attribIndex++] = WGL_CONTEXT_FLAGS_ARB;
        attributes[attribIndex] = 0;
        if (format.testOption(QSurfaceFormat::DeprecatedFunctions))
             attributes[attribIndex] |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
        if (format.testOption(QSurfaceFormat::DebugContext))
            attributes[attribIndex++] |= WGL_CONTEXT_DEBUG_BIT_ARB;
        attribIndex++;
    }
    if (requestedVersion >= 0x0302) {
        switch (format.profile()) {
        case QSurfaceFormat::NoProfile:
            break;
        case QSurfaceFormat::CoreProfile:
            attributes[attribIndex++] = WGL_CONTEXT_PROFILE_MASK_ARB;
            attributes[attribIndex++] = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
            break;
        case QSurfaceFormat::CompatibilityProfile:
            attributes[attribIndex++] = WGL_CONTEXT_PROFILE_MASK_ARB;
            attributes[attribIndex++] = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
            break;
        }
    }
    if (QWindowsContext::verboseGL)
        qDebug("%s: Creating context version %d.%d with %d attributes",
               __FUNCTION__,  format.majorVersion(), format.minorVersion(), attribIndex / 2);

    const HGLRC result =
        staticContext.wglCreateContextAttribsARB(hdc, shared, attributes);
    if (!result)
        qErrnoWarning("%s: wglCreateContextAttribsARB() failed.", __FUNCTION__);
    return result;
}
示例#8
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    
    // baba bombom
    QVector<int> vec(10);
    qFill(vec,5);
    foreach (int val, vec) {
        qDebug() << val;
    }
    // dziura bob
    return a.exec();

}
示例#9
0
void FaceTracker::updateFakeCoefficients(float leftBlink, float rightBlink, float browUp,
    float jawOpen, float mouth2, float mouth3, float mouth4, QVector<float>& coefficients) {
    const int MMMM_BLENDSHAPE = 34;
    const int FUNNEL_BLENDSHAPE = 40;
    const int SMILE_LEFT_BLENDSHAPE = 28;
    const int SMILE_RIGHT_BLENDSHAPE = 29;
    const int MAX_FAKE_BLENDSHAPE = 40;  //  Largest modified blendshape from above and below

    coefficients.resize(std::max((int)coefficients.size(), MAX_FAKE_BLENDSHAPE + 1));
    qFill(coefficients.begin(), coefficients.end(), 0.0f);
    coefficients[_leftBlinkIndex] = leftBlink;
    coefficients[_rightBlinkIndex] = rightBlink;
    coefficients[_browUpCenterIndex] = browUp;
    coefficients[_browUpLeftIndex] = browUp;
    coefficients[_browUpRightIndex] = browUp;
    coefficients[_jawOpenIndex] = jawOpen;
    coefficients[SMILE_LEFT_BLENDSHAPE] = coefficients[SMILE_RIGHT_BLENDSHAPE] = mouth4;
    coefficients[MMMM_BLENDSHAPE] = mouth2;
    coefficients[FUNNEL_BLENDSHAPE] = mouth3;
}
示例#10
0
void FaceplusReader::update() {
#ifdef HAVE_FACEPLUS
    float x, y, rotation, scale;
    if (!(faceplus_synchronous_track() && faceplus_current_face_location(&x, &y, &rotation, &scale) && !glm::isnan(x) &&
            faceplus_current_output_vector(_outputVector.data()))) {
        QMetaObject::invokeMethod(this, "update", Qt::QueuedConnection);
        return;
    }
    if (!_referenceInitialized) {
        _referenceX = x;
        _referenceY = y;
        _referenceInitialized = true;
    }
    const float TRANSLATION_SCALE = 10.0f;
    glm::vec3 headTranslation((x - _referenceX) * TRANSLATION_SCALE, (y - _referenceY) * TRANSLATION_SCALE, 0.0f);
    glm::quat headRotation(glm::radians(glm::vec3(-_outputVector.at(_headRotationIndices[0]),
        _outputVector.at(_headRotationIndices[1]), -_outputVector.at(_headRotationIndices[2]))));
    float estimatedEyePitch = (_outputVector.at(_leftEyeRotationIndices[0]) +
        _outputVector.at(_rightEyeRotationIndices[0])) * -0.5f;
    float estimatedEyeYaw = (_outputVector.at(_leftEyeRotationIndices[1]) +
        _outputVector.at(_rightEyeRotationIndices[1])) * 0.5f;
    
    qFill(_blendshapeCoefficients.begin(), _blendshapeCoefficients.end(), 0.0f);
    for (int i = 0; i < _outputVector.size(); i++) {
        for (QMultiHash<int, QPair<int, float> >::const_iterator it = _channelIndexMap.constFind(i);
                it != _channelIndexMap.constEnd() && it.key() == i; it++) {
            _blendshapeCoefficients[it.value().first] += _outputVector.at(i) * it.value().second;
        }
    }

    QMetaObject::invokeMethod(Application::getInstance()->getFaceplus(), "setState", Q_ARG(const glm::vec3&, headTranslation),
        Q_ARG(const glm::quat&, headRotation), Q_ARG(float, estimatedEyePitch), Q_ARG(float, estimatedEyeYaw),
        Q_ARG(const QVector<float>&, _blendshapeCoefficients));

    QMetaObject::invokeMethod(this, "update", Qt::QueuedConnection);
#endif
}
static QSurfaceFormat
    qSurfaceFormatFromHDC(const QOpenGLStaticContext &staticContext,
                          HDC hdc, int pixelFormat,
                          QWindowsOpenGLAdditionalFormat *additionalIn = 0)
{
    enum { attribSize =40 };

    QSurfaceFormat result;
    if (!staticContext.hasExtensions())
        return result;
    int iAttributes[attribSize];
    int iValues[attribSize];
    qFill(iAttributes, iAttributes + attribSize, int(0));
    qFill(iValues, iValues + attribSize, int(0));

    int i = 0;
    const bool hasSampleBuffers = testFlag(staticContext.extensions, QOpenGLStaticContext::SampleBuffers);

    iAttributes[i++] = WGL_DOUBLE_BUFFER_ARB; // 0
    iAttributes[i++] = WGL_DEPTH_BITS_ARB; // 1
    iAttributes[i++] = WGL_PIXEL_TYPE_ARB; // 2
    iAttributes[i++] = WGL_RED_BITS_ARB; // 3
    iAttributes[i++] = WGL_GREEN_BITS_ARB; // 4
    iAttributes[i++] = WGL_BLUE_BITS_ARB; // 5
    iAttributes[i++] = WGL_ALPHA_BITS_ARB; // 6
    iAttributes[i++] = WGL_ACCUM_BITS_ARB; // 7
    iAttributes[i++] = WGL_STENCIL_BITS_ARB; // 8
    iAttributes[i++] = WGL_STEREO_ARB; // 9
    iAttributes[i++] = WGL_ACCELERATION_ARB; // 10
    iAttributes[i++] = WGL_NUMBER_OVERLAYS_ARB; // 11
    if (hasSampleBuffers) {
        iAttributes[i++] = WGL_SAMPLE_BUFFERS_ARB; // 12
        iAttributes[i++] = WGL_SAMPLES_ARB; // 13
    }
    if (!staticContext.wglGetPixelFormatAttribIVARB(hdc, pixelFormat, 0, i,
                                        iAttributes, iValues)) {
        qErrnoWarning("%s: wglGetPixelFormatAttribIVARB() failed for basic parameters.", __FUNCTION__);
        return result;
    }
    result.setSwapBehavior(iValues[0] ? QSurfaceFormat::DoubleBuffer : QSurfaceFormat::SingleBuffer);
    result.setDepthBufferSize(iValues[1]);
    result.setRedBufferSize(iValues[3]);
    result.setGreenBufferSize(iValues[4]);
    result.setBlueBufferSize(iValues[5]);
    result.setAlphaBufferSize(iValues[6]);
    result.setStencilBufferSize(iValues[8]);
    if (iValues[9])
        result.setOption(QSurfaceFormat::StereoBuffers);

    if (hasSampleBuffers)
        result.setSamples(iValues[13]);
    if (additionalIn) {
        if (iValues[7])
            additionalIn->formatFlags |= QWindowsGLAccumBuffer;
        if (iValues[10] == WGL_FULL_ACCELERATION_ARB)
            additionalIn->formatFlags |= QWindowsGLDirectRendering;
        if (iValues[11])
            additionalIn->formatFlags |= QWindowsGLOverlay;
    }
    return result;
}
// Choose a suitable pixelformat using ARB extension functions.
static int choosePixelFormat(HDC hdc,
                             const QOpenGLStaticContext &staticContext,
                             const QSurfaceFormat &format,
                             const QWindowsOpenGLAdditionalFormat &additional,
                             PIXELFORMATDESCRIPTOR *obtainedPfd)
{
    enum { attribSize =40 };
    if ((additional.formatFlags & QWindowsGLRenderToPixmap) || !staticContext.hasExtensions())
        return 0;

    int iAttributes[attribSize];
    qFill(iAttributes, iAttributes + attribSize, int(0));
    int i = 0;
    iAttributes[i++] = WGL_ACCELERATION_ARB;
    iAttributes[i++] = testFlag(additional.formatFlags, QWindowsGLDirectRendering) ?
                       WGL_FULL_ACCELERATION_ARB : WGL_NO_ACCELERATION_ARB;
    iAttributes[i++] = WGL_SUPPORT_OPENGL_ARB;
    iAttributes[i++] = TRUE;
    iAttributes[i++] = WGL_DRAW_TO_WINDOW_ARB;
    iAttributes[i++] = TRUE;
    iAttributes[i++] = WGL_COLOR_BITS_ARB;
    iAttributes[i++] = 24;
    switch (format.swapBehavior()) {
    case QSurfaceFormat::DefaultSwapBehavior:
        break;
    case QSurfaceFormat::SingleBuffer:
        iAttributes[i++] = WGL_DOUBLE_BUFFER_ARB;
        iAttributes[i++] = FALSE;
        break;
    case QSurfaceFormat::DoubleBuffer:
    case QSurfaceFormat::TripleBuffer:
        iAttributes[i++] = WGL_DOUBLE_BUFFER_ARB;
        iAttributes[i++] = TRUE;
        break;
    }
    if (format.stereo()) {
        iAttributes[i++] = WGL_STEREO_ARB;
        iAttributes[i++] = TRUE;
    }
    if (format.depthBufferSize() >= 0) {
        iAttributes[i++] = WGL_DEPTH_BITS_ARB;
        iAttributes[i++] = format.depthBufferSize();
    }
    iAttributes[i++] = WGL_PIXEL_TYPE_ARB;
    iAttributes[i++] = WGL_TYPE_RGBA_ARB;
    if (format.redBufferSize() >= 0) {
        iAttributes[i++] = WGL_RED_BITS_ARB;
        iAttributes[i++] = format.redBufferSize();
    }
    if (format.greenBufferSize() >= 0) {
        iAttributes[i++] = WGL_GREEN_BITS_ARB;
        iAttributes[i++] = format.greenBufferSize();
    }
    if (format.blueBufferSize() >= 0) {
        iAttributes[i++] = WGL_BLUE_BITS_ARB;
        iAttributes[i++] = format.blueBufferSize();
    }
    iAttributes[i++] = WGL_ALPHA_BITS_ARB;
    iAttributes[i++] = format.alphaBufferSize() >= 0 ? format.alphaBufferSize() : 8;
    if (additional.formatFlags & QWindowsGLAccumBuffer) {
        iAttributes[i++] = WGL_ACCUM_BITS_ARB;
        iAttributes[i++] = 16;
    }
    iAttributes[i++] = WGL_STENCIL_BITS_ARB;
    iAttributes[i++] = 8;
    if (additional.formatFlags & QWindowsGLOverlay) {
        iAttributes[i++] = WGL_NUMBER_OVERLAYS_ARB;
        iAttributes[i++] = 1;
    }
    const int samples = format.samples();
    const bool sampleBuffersRequested = samples > 1
            && testFlag(staticContext.extensions, QOpenGLStaticContext::SampleBuffers);
    int samplesValuePosition = 0;
    if (sampleBuffersRequested) {
        iAttributes[i++] = WGL_SAMPLE_BUFFERS_ARB;
        iAttributes[i++] = TRUE;
        iAttributes[i++] = WGL_SAMPLES_ARB;
        samplesValuePosition = i;
        iAttributes[i++] = format.samples();
    } else if (samples == 0 || samples == 1 ) {
        iAttributes[i++] = WGL_SAMPLE_BUFFERS_ARB;
        iAttributes[i++] = FALSE;
    }
    // If sample buffer request cannot be satisfied, reduce request.
    int pixelFormat = 0;
    uint numFormats = 0;
    while (true) {
        const bool valid =
            staticContext.wglChoosePixelFormatARB(hdc, iAttributes, 0, 1,
                                               &pixelFormat, &numFormats)
                && numFormats >= 1;
        if (valid || !sampleBuffersRequested)
            break;
        if (iAttributes[samplesValuePosition] > 1) {
            iAttributes[samplesValuePosition] /= 2;
        } else {
            break;
        }
    }
    // Verify if format is acceptable. Note that the returned
    // formats have been observed to not contain PFD_SUPPORT_OPENGL, ignore.
    initPixelFormatDescriptor(obtainedPfd);
    DescribePixelFormat(hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), obtainedPfd);
    if (!isAcceptableFormat(additional, *obtainedPfd, true)) {
        if (QWindowsContext::verboseGL)
            qDebug() << __FUNCTION__ << " obtained px #" << pixelFormat
                     << " not acceptable=" << *obtainedPfd;
        pixelFormat = 0;
    }

#ifndef QT_NO_DEBUG_OUTPUT
    if (QWindowsContext::verboseGL) {
        QDebug nsp = qDebug().nospace();
        nsp << __FUNCTION__;
        if (sampleBuffersRequested)
            nsp << " samples=" << iAttributes[samplesValuePosition];
        nsp << " Attributes: " << hex << showbase;
        for (int ii = 0; ii < i; ++ii)
            nsp << iAttributes[ii] << ',';
        nsp << noshowbase << dec << "\n    obtained px #" << pixelFormat
            << " of " << numFormats << "\n    " << *obtainedPfd;
    } // Debug
#endif

    return pixelFormat;
}
示例#13
0
Index3To1::Index3To1() {
    indexSize = 0;
    bitsPerChar = 0;
    bitsPerCharX2 = 0;
    qFill(maskByChar, maskByChar+256, 0);
}
示例#14
0
bool PlotIO::write(const QString& path, const ros::Time& start, const ros::Time& end)
{
	FileFormat* io = 0;

	if(path.endsWith(".bag"))
		io = new BagFormat;
	else if(path.endsWith(".csv"))
		io = new CSVFormat;

	if(!io)
	{
		fprintf(stderr, "Could not find output format\n");
		return false;
	}

	if(!io->init(path, start))
		return false;

	QLinkedList<Plot::LinkedBufferIterator> its = m_rootPlot->iterators(io->defaultFlags());

	io->writeHeader(its);

	QVector<Plot::LinkedBufferIterator*> to_write(its.size(), 0);

	while(1)
	{
		ros::Time stamp = ros::Time(0);
		qFill(to_write, (Plot::LinkedBufferIterator*)0);

		// Get a list of iterators with the next timestamp
		int i = 0;
		for(QLinkedList<Plot::LinkedBufferIterator>::iterator it = its.begin(); it != its.end(); ++it, ++i)
		{
			Plot::LinkedBufferIterator& buf_it = *it;
			if(!buf_it.isValid())
				continue;

			const Plot::DataPoint& point = *buf_it;

			if(point.time < stamp || stamp == ros::Time(0))
			{
				qFill(to_write, (Plot::LinkedBufferIterator*)0);
				to_write[i] = &buf_it;
				stamp = point.time;
			}
			else if(point.time == stamp)
				to_write[i] = &buf_it;
		}

		if(stamp == ros::Time(0))
			break;

		if(end != ros::Time(0) && stamp > end)
			break;

		if(stamp >= start)
			io->writeData(stamp, to_write);

		// Advance all used iterators
		Q_FOREACH(Plot::LinkedBufferIterator* it, to_write)
		{
			if(!it)
				continue;

			++(*it);
		}
	}

	delete io;
	return true;
}
示例#15
0
QByteArray huffman(QByteArray data, MainWindow *mainWindow)
{
	// count
	int count[tableSize];
	qFill(&count[0], &count[tableSize - 1], 0);
	for (int i = 0; i < data.size(); ++i)
		++count[static_cast<quint8>(data[i])];

	QMultiMap<int, QList<QPair<quint8, QBitArray> > > p; // <count, <symbol, code> >
	for (int i = 0; i < tableSize; ++i)
	{
		if (count[i] == 0)	continue;

		QList<QPair<quint8, QBitArray> > list;
		list.append(qMakePair(static_cast<quint8>(i), QBitArray()));
		p.insert(count[i], list);
	}

	// caculate codes from bottom to top
	while (p.size() > 1)
	{
		const int count0 = p.begin().key();
		QList<QPair<quint8, QBitArray> > list0 = p.begin().value();
		p.erase(p.begin());

		const int count1 = p.begin().key();
		QList<QPair<quint8, QBitArray> > list1 = p.begin().value();
		p.erase(p.begin());

		for (QList<QPair<quint8, QBitArray> >::Iterator iter = list0.begin(); iter != list0.end(); ++iter)
		{
			iter->second.resize(iter->second.size() + 1);
			iter->second.setBit(iter->second.size() - 1, false);
		}

		for (QList<QPair<quint8, QBitArray> >::Iterator iter = list1.begin(); iter != list1.end(); ++iter)
		{
			iter->second.resize(iter->second.size() + 1);
			iter->second.setBit(iter->second.size() - 1, true);
		}
		p.insert(count0 + count1, list0 + list1);
	}

	// extract codes
	QHash<quint8, QBitArray> codes;
	for (QList<QPair<quint8, QBitArray> >::ConstIterator iter = p.begin().value().constBegin(); iter != p.begin().value().constEnd(); ++iter)
	{
		QBitArray code;
		code.resize(iter->second.size());
		for (int j = 0; j < code.size(); ++j)
			if (iter->second[code.size() - j - 1])
				code.setBit(j);
		codes[iter->first] = code;
	}

	// encode
	QBitArray bits;
	for (int i = 0; i < data.size(); ++i)
	{
		mainWindow->setProgress(qRound(static_cast<qreal>(100 * i) / data.size()));

		const QBitArray &code = codes[static_cast<quint8>(data[i])];
		const int oldSize = bits.size();
		bits.resize(oldSize + code.size());

		for (int i = 0; i < code.size(); ++i)
			if (code[i])	bits.setBit(oldSize + i);
	}

	QByteArray result;
	{
		QDataStream stream(&result, QIODevice::WriteOnly);
		stream << codes << static_cast<qint32>(data.size()) << bits;
	}

	return result;
}
示例#16
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("GB2312"));
     QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312"));
     QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));
     QStringList list;
     list<<"one"<<"two"<<"three";
     qDebug()<<QObject::tr("qCopu() methord:");
     QVector<QString>vect(3);
     qCopy(list.begin(),list.end(),vect.begin());
     qDebug()<<vect;
     /****************************************************************************************************/
     qDebug()<<endl<<QObject::tr("qEqual() methord:");
     bool bl=qEqual(list.begin(),list.end(),vect.begin());
             qDebug()<<bl;
//             QList<QString>::iterator i;
//             i=qFind(list.begin,list.end(),"two");
 /****************************************************************************************************/
             qDebug()<<endl<<QObject::tr("qFind() methord:");
              QStringList::const_iterator i= qFind(list.begin(), list.end(), "two");
             qDebug()<<*i;
  /****************************************************************************************************/
      qDebug()<<endl<<QObject::tr("qFill() methord:");
      qFill(list.begin(),list.end(),"eleven");
      qDebug()<<list;
 /****************************************************************************************************/
      QList<int>list2;
      list2<<2<<31<<13<<2<<2<<2<<134<<2<<123<<4<<5<<3<<5<<51;
      qDebug()<<endl<<QObject::tr("qCount() methord:");
      int number=0;
      qCount(list2.begin(),list2.end(),2,number);
      qDebug()<<"The number of 2 is:"<<number;
      qSort(list2);
      QList<int>::iterator j=qLowerBound(list2.begin(),list2.end(),22);
     list2.insert(j,22);
     /****************************************************************************************************/
     qDebug()<<list2;
     qStableSort(list2);
qDebug()<<endl<<list2;
/****************************************************************************************************/
qSort(list2.begin(),list2.end(),qGreater<int>());
qDebug()<<endl<<list2;
/****************************************************************************************************/
qStableSort(list2.begin(),list2.end(),qGreater<int>());
qDebug()<<endl<<list2;
/****************************************************************************************************/
double d1=311.3998;
double d2=0.231314;
qDebug()<<endl<<"before swap:"<<d1<<" "<<d2;
qSwap(d1,d2);
qDebug()<<"then swap:"<<d1<<" "<<d2;
/****************************************************************************************************/
int int_a=qBound(2,49,12);
qDebug()<<"int_a="<<int_a;

    QDateTime time = QDateTime::currentDateTime();
    //QString s=time.toString("yyyy-MM-dd hh:mm:ss");
    qDebug()<<time.toString();
        return a.exec();

}