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


C++ QTemporaryFile::readAll方法代码示例

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


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

示例1: testUpgrade_data

void SettingsTest::testUpgrade_data(){
  // Read recipe
  QFile recipe(":/testdata/upgrade/recipe");
  QVERIFY(recipe.open(QIODevice::ReadOnly));
  QList<UpgradeTestHelper::TestCase> testCases = UpgradeTestHelper::readRecipe(&recipe);

  // Generate settings file according to recipe
  QTemporaryFile settingsFile;
  QVERIFY(settingsFile.open() == true);

  QSettings settings(settingsFile.fileName(), QSettings::IniFormat);

  UpgradeTestHelper::fillSettings(&settings, testCases);

  // Generate defaults file according to recipe
  QTemporaryFile defaultSettingsFile;
  QVERIFY(defaultSettingsFile.open() == true);

  QSettings defaultSettings(defaultSettingsFile.fileName(), QSettings::IniFormat);

  UpgradeTestHelper::fillDefaultSettings(&defaultSettings, testCases);

  // Parse settings -- do upgrade
#if 0
  settingsFile.seek(0);
  defaultSettingsFile.seek(0);
  qDebug() << "SETTINGS {{{\n" << settingsFile.readAll() << "\n}}}";
  qDebug() << "DEFAULT SETTINGS {{{\n" << defaultSettingsFile.readAll() << "\n}}}";
#endif

  SsuSettings ssuSettings(settingsFile.fileName(), QSettings::IniFormat,
      defaultSettingsFile.fileName());

#if 0
  settingsFile.seek(0);
  qDebug() << "SETTINGS UPGRADED {{{\n" << settingsFile.readAll() << "\n}}}";
#endif

  // Record data for verification phase
  QTest::addColumn<bool>("keyIsSet");
  QTest::addColumn<bool>("keyShouldBeSet");
  QTest::addColumn<QString>("actualValue");
  QTest::addColumn<QString>("expectedValue");

  foreach (const UpgradeTestHelper::TestCase &testCase, testCases){
    foreach (const QString &group, UpgradeTestHelper::groups()){
      const QString key = group.isEmpty() ? testCase.key() : group + '/' + testCase.key();
      QTest::newRow(qPrintable(QString("%1%2:%3:%4")
          .arg(group.isEmpty() ? "" : group + "/")
          .arg(testCase.history())
          .arg(testCase.current())
          .arg(testCase.expected())))
        << ssuSettings.contains(key)
        << testCase.keyShouldBeSet()
        << ssuSettings.value(key).toString()
        << testCase.expected();
    }
  }
开发者ID:giucam,项目名称:ssu,代码行数:58,代码来源:settingstest.cpp

示例2: convert

void ClippingConverter::convert(const QByteArray &clippingData, const QString &directory)
{
    QDataStream stream(clippingData);
    stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
    stream.setByteOrder(QDataStream::LittleEndian);

    QString newDirectory = directory;

    newDirectory.replace('\\', '/');
    if (!newDirectory.endsWith('/'))
        newDirectory.append('/');

    int objectCount, instanceCount;
    stream >> objectCount >> instanceCount;

    for (int i = 0; i < objectCount; ++i) {
        MeshPtr mesh = importObject(stream);

        // Serialize to a temporary file, then read it in again
        QTemporaryFile tempFile;
        if (!tempFile.open()) {
            qWarning("Unable to open the temporary %s file.", qPrintable(tempFile.fileName()));
            continue;
        }

        d->ogre->meshSerializer->exportMesh(mesh.getPointer(), tempFile.fileName().toStdString());

        QByteArray meshData = tempFile.readAll();
        QString meshFilename = QString("%1clipping/mesh-%2.mesh").arg(newDirectory).arg(i+1);

        d->output->writeFile(meshFilename, meshData);
    }

    QByteArray instances;

    instances.append("[");

    for (int i = 0; i < instanceCount; ++i) {
        QVector4D position;
        int index;

        stream >> position >> index;

        QString line = QString("{\"position\":[%1,%2,%3],\"file\":\"%5mesh-%4.mesh\"}")
                .arg(position.x())
                .arg(position.y())
                .arg(position.z())
                .arg(index+1)
                .arg(newDirectory);
        if (i > 0)
            instances.append(",");
        instances.append(line.toAscii());

    }

    instances.append("]");

    d->output->writeFile(newDirectory + "clipping.json", instances);

}
开发者ID:GrognardsFromHell,项目名称:EvilTemple-Native,代码行数:60,代码来源:clippingconverter.cpp

示例3:

QString WebPuppeteerTab::printBase64() {
	QTemporaryFile t;
	if (!t.open()) return QString();
	if (!print(t.fileName())) return QString();
	QByteArray data = t.readAll();
	t.remove();
	return QString::fromLatin1(data.toBase64());
}
开发者ID:,项目名称:,代码行数:8,代码来源:

示例4: findExternalTTY

bool STTY::findExternalTTY(const QString& termApp)
{
    QString appName(termApp.isEmpty() ? QString("xterm") : termApp);

    if (QStandardPaths::findExecutable(appName).isEmpty()) {
        m_lastError = i18n("%1 is incorrect terminal name", termApp);
        return false;
    }

    QTemporaryFile file;
    if (!file.open()) {
        m_lastError = i18n("Can't create a temporary file");
        return false;
    }

    m_externalTerminal.reset(new QProcess(this));

    if (appName == "konsole") {
        m_externalTerminal->start(appName, QStringList() << "-e" << "sh" << "-c" << "tty>" + file.fileName() + ";exec<&-;exec>&-;while :;do sleep 3600;done");
    } else if (appName == "xfce4-terminal") {
        m_externalTerminal->start(appName, QStringList() << "-e" << " sh -c \"tty>" + file.fileName() + ";\"\"<&\\-\"\">&\\-;\"\"while :;\"\"do sleep 3600;\"\"done\"");
    } else {
        m_externalTerminal->start(appName, QStringList() << "-e" << "sh -c \"tty>" + file.fileName() + ";exec<&-;exec>&-;while :;do sleep 3600;done\"");
    }

    if (!m_externalTerminal->waitForStarted(500)) {
        m_lastError = "Can't run terminal: " + appName;
        m_externalTerminal->terminate();
        return false;
    }

    for (int i = 0; i < 800; i++) {
        if (!file.bytesAvailable()) {
            if (m_externalTerminal->state() == QProcess::NotRunning && m_externalTerminal->exitCode()) {
                break;
            }
            QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
            usleep(8000);
        } else {
            qCDebug(DEBUGGERCOMMON) << "Received terminal output(tty)";
            break;
        }
    }

    usleep(1000);
    ttySlave = file.readAll().trimmed();

    file.close();

    if (ttySlave.isEmpty()) {
        m_lastError = i18n("Can't receive %1 tty/pty. Check that %1 is actually a terminal and that it accepts these arguments: -e sh -c \"tty> %2 ;exec<&-;exec>&-;while :;do sleep 3600;done\"", appName, file.fileName());
    }
    return true;
}
开发者ID:KDE,项目名称:kdevelop,代码行数:54,代码来源:stty.cpp

示例5: test

void ExternalWriterTest::test()
{
    QTemporaryFile file;
    QScopedPointer<WriterPlugin> plugin(
                new ExternalWriter(testFilePath("testexternalwriter")
    ));

    file.open();
    WriteData data(file.fileName(), "application/text");
    plugin->write(data);

    QCOMPARE(QString(file.readAll()), QStringLiteral("{}"));
}
开发者ID:KDE,项目名称:kfilemetadata,代码行数:13,代码来源:externalwritertest.cpp

示例6: saveSettings

void ZynAddSubFxInstrument::saveSettings( QDomDocument & _doc,
											QDomElement & _this )
{
	m_portamentoModel.saveSettings( _doc, _this, "portamento" );
	m_filterFreqModel.saveSettings( _doc, _this, "filterfreq" );
	m_filterQModel.saveSettings( _doc, _this, "filterq" );
	m_bandwidthModel.saveSettings( _doc, _this, "bandwidth" );
	m_fmGainModel.saveSettings( _doc, _this, "fmgain" );
	m_resCenterFreqModel.saveSettings( _doc, _this, "rescenterfreq" );
	m_resBandwidthModel.saveSettings( _doc, _this, "resbandwidth" );

	QString modifiedControllers;
	for( QMap<int, bool>::ConstIterator it = m_modifiedControllers.begin();
									it != m_modifiedControllers.end(); ++it )
	{
		if( it.value() )
		{
			modifiedControllers += QString( "%1," ).arg( it.key() );
		}
	}
	_this.setAttribute( "modifiedcontrollers", modifiedControllers );

	m_forwardMidiCcModel.saveSettings( _doc, _this, "forwardmidicc" );

	QTemporaryFile tf;
	if( tf.open() )
	{
		const std::string fn = QSTR_TO_STDSTR(
									QDir::toNativeSeparators( tf.fileName() ) );
		m_pluginMutex.lock();
		if( m_remotePlugin )
		{
			m_remotePlugin->lock();
			m_remotePlugin->sendMessage( RemotePlugin::message( IdSaveSettingsToFile ).addString( fn ) );
			m_remotePlugin->waitForMessage( IdSaveSettingsToFile );
			m_remotePlugin->unlock();
		}
		else
		{
			m_plugin->saveXML( fn );
		}
		m_pluginMutex.unlock();
		QByteArray a = tf.readAll();
		QDomDocument doc( "mydoc" );
		if( doc.setContent( a ) )
		{
			QDomNode n = _doc.importNode( doc.documentElement(), true );
			_this.appendChild( n );
		}
	}
}
开发者ID:DanielAeolusLaude,项目名称:lmms,代码行数:51,代码来源:ZynAddSubFx.cpp

示例7: sendOptions

void RPCServer::sendOptions(quint64 client){
  QTemporaryFile file;
  if (file.open()) {
    file.close();
    write_options_file(file.fileName().toAscii().constData());
    file.open();
    QByteArray optionsString = file.readAll();
    qDebug("Read %d bytes in the configuration file",optionsString.size());
    call(client,QString("sendOptions(QByteArray)"),optionsString);
    sendInputImages(client);
  }else{
    qDebug("RPCServer: Failed to create temporary file!");
    return;
  }
}
开发者ID:FXIhub,项目名称:hawk,代码行数:15,代码来源:rpcserver.cpp

示例8: checkInHead

bool SxVersionedFile::checkInHead( QFile *file, QDir *history)
{
	QMap<QString,QVariant> props;
	QByteArray data;
	
	
	QFile revFile( makeVersionName( history, 0) );

	
	if( revFile.exists () )
	{
		// Build patch
		if( !revFile.open(QIODevice::ReadWrite) )
			return false;
		// Diff current file and revFile.  save patch as rev + 1;
		qDebug() << "Diff" << revFile.fileName();
		QTemporaryFile patch;
		patch.open();
		
		m_versionUtils.diffQFiles( file, &revFile, &patch );

		QMap<QString,QVariant> props = getHeadProps( history);
		QString revName = makeNextVersionName( history );
		qDebug() << "Write to" << revName;
		
		QFile rev( revName );
		if( !rev.open(QIODevice::WriteOnly) )
			return false;
		QDataStream outputStream( &rev );
		patch.seek(0);
		outputStream << props << patch.readAll();
		rev.close();
		patch.close();
		revFile.close();
	}

	if( !revFile.open(QIODevice::ReadWrite) )
		return false;
	QDataStream outputStream( &revFile );
	quint64 origPos = file->pos();
	file->seek(0);
	outputStream << metaInfo() << file->readAll();
	file->seek(origPos);
	revFile.close();
	return true;

}
开发者ID:AlanLZY,项目名称:textroom,代码行数:47,代码来源:sxrevfile.cpp

示例9: saveChunk

QByteArray VstPlugin::saveChunk()
{
	QByteArray a;
	QTemporaryFile tf;
	if( tf.open() )
	{
		lock();
		sendMessage( message( IdSaveSettingsToFile ).
				addString(
					QSTR_TO_STDSTR(
						QDir::toNativeSeparators( tf.fileName() ) ) ) );
		waitForMessage( IdSaveSettingsToFile, true );
		unlock();
		a = tf.readAll();
	}

	return a;
}
开发者ID:karmux,项目名称:lmms,代码行数:18,代码来源:VstPlugin.cpp

示例10: loadSave

//checks if load/saving preserves encoding and line endings
void QEditorTest::loadSave(){
	QFETCH(QString, outCodecName);
	QFETCH(QString, outLineEnding);
	QFETCH(bool, autodetect);
	QTextCodec* outCodec=QTextCodec::codecForName(qPrintable(outCodecName));
	if (outCodecName=="latin1") outCodec = defaultCodec;

	if (!allTests) {
		qDebug("skipped load save test");
		return;
	}

	const QString testText = QString::fromLatin1("hallo\n\xE4\xF6\xFC\n");
	QString testTextWithLineEndings=testText;
	testTextWithLineEndings.replace("\n",outLineEnding);
	QTemporaryFile tf;//uncomment if you need to look at the files &tf=*(new QTemporaryFile);
	tf.open();
	QString tfn=tf.fileName();
	tf.write(outCodec->fromUnicode(testTextWithLineEndings));
	tf.close();

	//Load
	editor->setFileCodec(QTextCodec::codecForName("iso-8859-5"));
	editor->load(tfn,autodetect?0:outCodec);
	editor->document()->setLineEnding(editor->document()->originalLineEnding()); //TODO: find out why this line is only needed iff the editor passed by the testmanager is used and not if a new QEditor(0) is created
	QEQUAL2(editor->document()->text(),testTextWithLineEndings,QString("File: %1  Got file codec: %2 ").arg(tfn).arg(editor->getFileCodec()?QString::fromAscii(editor->getFileCodec()->name()):"<null>"));
	QVERIFY2(editor->getFileCodec()==outCodec,qPrintable(QString("wrong encoding: got %1 wanted %2 by the sheriff %3").arg(QString::fromAscii(editor->getFileCodec()->name())).arg(QString::fromAscii(outCodec->name())).arg(autodetect)));
	QEQUAL(editor->document()->lineEndingString(),outLineEnding);

	//Save
	editor->setText(editor->document()->text()+"Save test", false);
	editor->save();
	tf.open();
	QString writtenText=outCodec->toUnicode( tf.readAll());
	tf.close();

	QEQUAL2(writtenText, testTextWithLineEndings+"Save test", "file text check, file:"+tfn);
	QVERIFY2(writtenText.contains(outLineEnding), qPrintable("file don't contain right line ending, file"+tfn));
	
	editor->setFileName(""); //reset filename so it won't get panically if the file is deleted
	editor->document()->setLineEnding(QDocument::Conservative); //reset line ending so we won't screw up the other tests
}
开发者ID:svn2github,项目名称:texstudio,代码行数:43,代码来源:qeditor_t.cpp

示例11: logItem

void BootloaderInstallHex::installStage2(void)
{
    emit logItem(tr("Adding bootloader to firmware file"), LOGINFO);
    QCoreApplication::processEvents();

    // local temp file
    QTemporaryFile tempbin;
    tempbin.open();
    QString tempbinName = tempbin.fileName();
    tempbin.close();
    // get temporary files filenames -- external tools need this.
    m_descrambled.open();
    QString descrambledName = m_descrambled.fileName();
    m_descrambled.close();
    m_tempfile.open();
    QString tempfileName = m_tempfile.fileName();
    m_tempfile.close();

    int origin = 0;
    switch(m_model) {
        case 3:
            origin = 0x3f0000;
            break;
        case 2:
        case 1:
            origin = 0x1f0000;
            break;
        default:
            origin = 0;
            break;
    }

    // iriver decode already done in stage 1
    int result;
    if((result = mkboot_iriver(descrambledName.toLocal8Bit().constData(),
                    tempfileName.toLocal8Bit().constData(),
                    tempbinName.toLocal8Bit().constData(), origin)) < 0)
    {
        QString error;
        switch(result) {
            case -1: error = tr("could not open input file"); break;
            case -2: error = tr("reading header failed"); break;
            case -3: error = tr("reading firmware failed"); break;
            case -4: error = tr("can't open bootloader file"); break;
            case -5: error = tr("reading bootloader file failed"); break;
            case -6: error = tr("can't open output file"); break;
            case -7: error = tr("writing output file failed"); break;
        }
        emit logItem(tr("Error in patching: %1").arg(error), LOGERROR);

        emit done(true);
        return;
    }
    QTemporaryFile targethex;
    targethex.open();
    QString targethexName = targethex.fileName();
    if((result = iriver_encode(tempbinName.toLocal8Bit().constData(),
                    targethexName.toLocal8Bit().constData(), FALSE)) < 0)
    {
        emit logItem(tr("Error in scramble: %1").arg(scrambleError(result)), LOGERROR);
        targethex.close();

        emit done(true);
        return;
    }

    // finally check the md5sum of the created file
    QByteArray filedata;
    filedata = targethex.readAll();
    targethex.close();
    QString hash = QCryptographicHash::hash(filedata,
            QCryptographicHash::Md5).toHex();
    qDebug() << "[BootloaderInstallHex] created hexfile hash:" << hash;

    emit logItem(tr("Checking modified firmware file"), LOGINFO);
    if(hash != QString(md5sums[m_hashindex].patched)) {
        emit logItem(tr("Error: modified file checksum wrong"), LOGERROR);
        targethex.remove();
        emit done(true);
        return;
    }
    // finally copy file to player
    targethex.copy(m_blfile);

    emit logItem(tr("Success: modified firmware file created"), LOGINFO);
    logInstall(LogAdd);
    emit done(false);

    return;
}
开发者ID:victor2002,项目名称:rockbox_victor_clipplus,代码行数:90,代码来源:bootloaderinstallhex.cpp

示例12: XSLTConvertString

QString ExportHelper::XSLTConvertString(QString input, int xsltmapid, QString &errmsg)
{
  if (DEBUG)
    qDebug("ExportHelper::XSLTConvertString(%s..., %d, errmsg) entered",
           qPrintable(input.left(200)), xsltmapid);
  QString returnVal;

  XSqlQuery xsltq;
  xsltq.prepare("SELECT xsltmap_name, xsltmap_export"
                "  FROM xsltmap"
                " WHERE xsltmap_id=:id;");

  xsltq.bindValue(":id", xsltmapid);
  xsltq.exec();
  if (xsltq.first())
  {
    /* tempfile handling is messy because windows doesn't handle them as you
       might expect.
       TODO: find a simpler way
     */
    QString xsltmap = xsltq.value("xsltmap_name").toString();
    QTemporaryFile *inputfile = new QTemporaryFile(QDir::tempPath()
                                                   + QDir::separator()
                                                   + xsltmap
                                                   + "Input.XXXXXX.xml");
    inputfile->setAutoRemove(false);
    if (! inputfile->open())
      errmsg = tr("Could not open temporary input file (%1).")
                  .arg(inputfile->error());
    else
    {
      QString inputfileName = inputfile->fileName();
      inputfile->write(input.toUtf8());
      inputfile->close();
      delete inputfile;
      inputfile = 0;

      QTemporaryFile *outputfile = new QTemporaryFile(QDir::tempPath()
                                                      + QDir::separator()
                                                      + xsltmap
                                                      + "Output.XXXXXX.xml");
      outputfile->setAutoRemove(false);
      if (! outputfile->open())
        errmsg = tr("Could not open temporary output file (%1).")
                  .arg(outputfile->error());
      else
      {
        QString outputfileName = outputfile->fileName();

        if (DEBUG)
          qDebug("ExportHelper::XSLTConvertString writing from %s to %s",
                 qPrintable(inputfileName), qPrintable(outputfileName));

        if (XSLTConvertFile(inputfileName, outputfileName,
                            xsltq.value("xsltmap_export").toString(), errmsg))
          returnVal = outputfile->readAll();

        outputfile->close();
        delete outputfile;
        outputfile = 0;

        if (errmsg.isEmpty())
        {
          QFile::remove(outputfileName);
          QFile::remove(inputfileName);
        }
      }
    }
  }
  else  if (xsltq.lastError().type() != QSqlError::NoError)
    errmsg = xsltq.lastError().text();
  else
    errmsg = tr("Could not find XSLT mapping with internal id %1.")
               .arg(xsltmapid);

  if (! errmsg.isEmpty())
    qWarning("%s", qPrintable(errmsg));
  return returnVal;
}
开发者ID:ChristopherCotnoir,项目名称:qt-client,代码行数:79,代码来源:exporthelper.cpp

示例13: evaluate


//.........这里部分代码省略.........
    reportFile.setAutoRemove(true);
    setFilenameToTempFile(reportFile);

    QTemporaryFile resultFile;
    resultFile.setAutoRemove(true);
    setFilenameToTempFile(resultFile);


    if (mScannerMode == SM_OFFLINE_REMEDIATION)
    {
        inputARFFile.open();
        inputARFFile.write(getARFForRemediation());
        inputARFFile.close();

        args = buildOfflineRemediationArgs(inputARFFile.fileName(),
                resultFile.fileName(),
                reportFile.fileName(),
                arfFile.fileName());
    }
    else
    {
        args = buildEvaluationArgs(mSession->getOpenedFilePath(),
                mSession->hasTailoring() ? mSession->getTailoringFilePath() : QString(),
                resultFile.fileName(),
                reportFile.fileName(),
                arfFile.fileName(),
                mScannerMode == SM_SCAN_ONLINE_REMEDIATION);
    }
    QString program = getOscapProgramAndAdaptArgs(args);

    emit infoMessage(QObject::tr("Starting the oscap process..."));
    process.start(program, args);
    process.waitForStarted();

    if (process.state() != QProcess::Running)
    {
        emit errorMessage(QObject::tr("Failed to start local scanning process '%1'. Perhaps the executable was not found?").arg(program));
        mCancelRequested = true;
    }

    unsigned int pollInterval = 100;

    emit infoMessage(QObject::tr("Processing..."));
    while (!process.waitForFinished(pollInterval))
    {
        // read everything new
        readStdOut(process);
        watchStdErr(process);

        // pump the event queue, mainly because the user might want to cancel
        QAbstractEventDispatcher::instance(mScanThread)->processEvents(QEventLoop::AllEvents);

        if (mCancelRequested)
        {
            pollInterval = 1000;
            emit infoMessage(QObject::tr("Cancellation was requested! Terminating scanning..."));
            process.kill();
        }
    }

    if (!mCancelRequested)
    {
        if (process.exitCode() == 1) // error happened
        {
            watchStdErr(process);
            // TODO: pass the diagnostics over
            emit errorMessage(QObject::tr("There was an error during evaluation! Exit code of the 'oscap' process was 1."));
            // mark this run as canceled
            mCancelRequested = true;
        }
        else
        {
            // read everything left over
            readStdOut(process);
            watchStdErr(process);

            emit infoMessage(QObject::tr("The oscap tool has finished. Reading results..."));

            resultFile.open();
            mResults = resultFile.readAll();
            resultFile.close();

            reportFile.open();
            mReport = reportFile.readAll();
            reportFile.close();

            arfFile.open();
            mARF = arfFile.readAll();
            arfFile.close();

            emit infoMessage(QObject::tr("Processing has been finished!"));
        }
    }
    else
    {
        emit infoMessage(QObject::tr("Scanning cancelled!"));
    }

    signalCompletion(mCancelRequested);
}
开发者ID:OpenSCAP,项目名称:scap-workbench,代码行数:101,代码来源:OscapScannerLocal.cpp

示例14: getCoverage

QByteArray* QgsWCSServer::getCoverage()
{
  QStringList wcsLayersId = mConfigParser->wcsLayers();

  QList<QgsMapLayer*> layerList;

  QStringList mErrors = QStringList();

  //defining coverage name
  QString coveName = "";
  //read COVERAGE
  QMap<QString, QString>::const_iterator cove_name_it = mParameters.find( "COVERAGE" );
  if ( cove_name_it != mParameters.end() )
  {
    coveName = cove_name_it.value();
  }
  if ( coveName == "" )
  {
    QMap<QString, QString>::const_iterator cove_name_it = mParameters.find( "IDENTIFIER" );
    if ( cove_name_it != mParameters.end() )
    {
      coveName = cove_name_it.value();
    }
  }

  if ( coveName == "" )
  {
    mErrors << QString( "COVERAGE is mandatory" );
  }

  layerList = mConfigParser->mapLayerFromCoverage( coveName );
  if ( layerList.size() < 1 )
  {
    mErrors << QString( "The layer for the COVERAGE '%1' is not found" ).arg( coveName );
  }

  bool conversionSuccess;
  // BBOX
  bool bboxOk = false;
  double minx = 0.0, miny = 0.0, maxx = 0.0, maxy = 0.0;
  // WIDTh and HEIGHT
  int width = 0, height = 0;
  // CRS
  QString crs = "";

  // read BBOX
  QMap<QString, QString>::const_iterator bbIt = mParameters.find( "BBOX" );
  if ( bbIt == mParameters.end() )
  {
    minx = 0; miny = 0; maxx = 0; maxy = 0;
  }
  else
  {
    bboxOk = true;
    QString bbString = bbIt.value();
    minx = bbString.section( ",", 0, 0 ).toDouble( &conversionSuccess );
    if ( !conversionSuccess ) {bboxOk = false;}
    miny = bbString.section( ",", 1, 1 ).toDouble( &conversionSuccess );
    if ( !conversionSuccess ) {bboxOk = false;}
    maxx = bbString.section( ",", 2, 2 ).toDouble( &conversionSuccess );
    if ( !conversionSuccess ) {bboxOk = false;}
    maxy = bbString.section( ",", 3, 3 ).toDouble( &conversionSuccess );
    if ( !conversionSuccess ) {bboxOk = false;}
  }
  if ( !bboxOk )
  {
    mErrors << QString( "The BBOX is mandatory and has to be xx.xxx,yy.yyy,xx.xxx,yy.yyy" );
  }

  // read WIDTH
  width = mParameters.value( "WIDTH", "0" ).toInt( &conversionSuccess );
  if ( !conversionSuccess )
    width = 0;
  // read HEIGHT
  height = mParameters.value( "HEIGHT", "0" ).toInt( &conversionSuccess );
  if ( !conversionSuccess )
  {
    height = 0;
  }

  if ( width < 0 || height < 0 )
  {
    mErrors << QString( "The WIDTH and HEIGHT are mandatory and have to be integer" );
  }

  crs = mParameters.value( "CRS", "" );
  if ( crs == "" )
  {
    mErrors << QString( "The CRS is mandatory" );
  }

  if ( mErrors.count() != 0 )
  {
    throw QgsMapServiceException( "RequestNotWellFormed", mErrors.join( ". " ) );
  }

  QgsCoordinateReferenceSystem requestCRS = QgsCRSCache::instance()->crsByAuthId( crs );
  if ( !requestCRS.isValid() )
  {
    mErrors << QString( "Could not create request CRS" );
//.........这里部分代码省略.........
开发者ID:calebbuahin,项目名称:QGIS,代码行数:101,代码来源:qgswcsserver.cpp

示例15: Preprocess


//.........这里部分代码省略.........
				map.resize( metaTileSizeX * m_settings.tileSize + 2 * m_settings.margin, metaTileSizeY * m_settings.tileSize + 2 * m_settings.margin );

				ProjectedCoordinate drawTopLeft( x - 1.0 * m_settings.margin / m_settings.tileSize, y - 1.0 * m_settings.margin / m_settings.tileSize, zoom );
				ProjectedCoordinate drawBottomRight( x + metaTileSizeX + 1.0 * m_settings.margin / m_settings.tileSize, y + metaTileSizeY + 1.0 * m_settings.margin / m_settings.tileSize, zoom );
				GPSCoordinate drawTopLeftGPS = drawTopLeft.ToGPSCoordinate();
				GPSCoordinate drawBottomRightGPS = drawBottomRight.ToGPSCoordinate();
				projection.forward( drawTopLeftGPS.longitude, drawBottomRightGPS.latitude );
				projection.forward( drawBottomRightGPS.longitude, drawTopLeftGPS.latitude );
				mapnik::box2d<double> boundingBox( drawTopLeftGPS.longitude, drawTopLeftGPS.latitude, drawBottomRightGPS.longitude, drawBottomRightGPS.latitude );
				map.zoom_to_box( boundingBox );
				mapnik::agg_renderer<mapnik::image_32> renderer( map, image );
				renderer.apply();

				std::string data;
				int skipped = 0;
				int saved = 0;
				for ( int subX = 0; subX < metaTileSizeX; ++subX ) {
					for ( int subY = 0; subY < metaTileSizeY; ++subY ) {
						int indexNumber = ( y + subY - info.minY ) * ( info.maxX - info.minX ) + x + subX - info.minX;
						mapnik::image_view<mapnik::image_data_32> view = image.get_view( subX * m_settings.tileSize + m_settings.margin, subY * m_settings.tileSize + m_settings.margin, m_settings.tileSize, m_settings.tileSize );
						std::string result;
						if ( !m_settings.deleteTiles || info.index[( x + subX - info.minX ) + ( y + subY - info.minY ) * ( info.maxX - info.minX )].size == 1 ) {
							if ( m_settings.reduceColors )
								result = mapnik::save_to_string( view, "png256" );
							else
								result = mapnik::save_to_string( view, "png" );

							if ( m_settings.pngcrush ) {
								tempOut.open();
								tempOut.write( result.data(), result.size() );
								tempOut.flush();
								tempIn.open();
								pclose( popen( ( "pngcrush " + tempOut.fileName() + " " + tempIn.fileName() ).toUtf8().constData(), "r" ) );
								QByteArray buffer = tempIn.readAll();
								tempIn.close();
								tempOut.close();
								if ( buffer.size() != 0 && buffer.size() < ( int ) result.size() ) {
									saved += result.size() - buffer.size();
									result.assign( buffer.constData(), buffer.size() );
								}
							}
						}

						info.index[indexNumber].start = data.size();
						info.index[indexNumber].size = result.size();
						data += result;
					}
				}

				qint64 position;
#pragma omp critical
				{
					position = info.tilesFile->pos();
					info.tilesFile->write( data.data(), data.size() );

					metaTilesRendered++;
					tilesSkipped += skipped;
					pngcrushSaved += saved;
					qDebug() << "Mapnik Renderer: [" << zoom << "], thread" << threadID << ", metatiles:" << metaTilesRendered << "/" << tasks.size();
				}

				for ( int subX = 0; subX < metaTileSizeX; ++subX ) {
					for ( int subY = 0; subY < metaTileSizeY; ++subY ) {
						int indexNumber = ( y + subY - info.minY ) * ( info.maxX - info.minX ) + x + subX - info.minX;
						info.index[indexNumber].start += position;
					}
开发者ID:Karry,项目名称:monavsailfish,代码行数:67,代码来源:mapnikrenderer.cpp


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