示例#1
0
bool HtmlExporter::startFile(QFile& file,
                             const QString& basename,
                             QXmlStreamWriter& stream,
                             int currentPage,
                             int totalPages)
{
  if(!file.open(QIODevice::WriteOnly | QIODevice::Text))
  {
    errorHandler->handleIOError(file);
    return false;
  }

  stream.setDevice(&file);
  stream.setAutoFormatting(true);
  stream.setAutoFormattingIndent(2);
  stream.setCodec("utf-8");

  // Get the CSS either from the resources or from the settings directory
  writeHtmlStart(stream,
                 atools::settings::Settings::getOverloadedPath(":/littlenavmap/resources/css/export.css"));
  writeHtmlHeader(stream);
  writeHtmlNav(stream, basename, currentPage, totalPages);

  stream.writeStartElement("table");
  stream.writeStartElement("tbody");
  return true;
}
int Generate_Xml::rewriteXMLFile(QVector<QLineEdit *> p,int j,int track_tabsibling)
{
	bool tab;
	int tab_get;
	QFile Default("default1.xml");
	
	QXmlStreamWriter *xmlWriter = new QXmlStreamWriter();
	QXmlStreamWriter *newline = new QXmlStreamWriter();
	xmlWriter->setDevice(&Default);
	newline->setDevice(&Default);
	xmlWriter->setAutoFormatting (true);
	xmlWriter->setAutoFormatting(true);
	tab=xmlWriter->autoFormatting();
	
	xmlWriter->setAutoFormattingIndent(-10);
	tab_get=xmlWriter->autoFormattingIndent();
	
		
	
	if (!Default.open(QIODevice::Append))
	{
	/* show wrror message if not able to open file */
	QMessageBox::warning(0, "Read only", "The file is in read only mode");
	}	
	QString temp1;
	QString temp2;
		 
		 
	temp1=(p.at(j))->displayText();
		
	newline->writeEndDocument();

	for(int i=0;i<track_tabsibling;i++)//changed tab here actaully multiplied by two
	xmlWriter->writeCharacters("\t");

	xmlWriter->writeStartElement(temp1);
		
	j++;
				
	while(p.at(j)!=0)
	{
	temp1=(p.at(j))->displayText();
	j++;
	temp2=(p.at(j))->displayText();
	j++;
	xmlWriter->writeAttribute(temp1,temp2);
	}

	xmlWriter->writeEndElement();

	Default.close();
	delete xmlWriter;
	delete newline;
	return j;
}
/**
 * Creates the current configuration string.
 * @return
 *      The string.
 */
QString CreateSceFile::createCurrentConfigurationString()
{
    QBuffer xmlBuffer;

    QXmlStreamWriter xmlWriter;
    xmlWriter.setAutoFormatting(true);
    xmlWriter.setAutoFormattingIndent(2);
    xmlBuffer.open(QIODevice::WriteOnly);
    xmlWriter.setDevice(&xmlBuffer);

    xmlWriter.writeStartElement("SceConfiguration");

    xmlWriter.writeStartElement("Files");
    for(int i = 0; i < ui->filesTableWidget->rowCount(); i++)
    {
        QComboBox* box = static_cast<QComboBox*>(ui->filesTableWidget->cellWidget(i, COLUMN_TYPE));
        QString subDirectory = ui->filesTableWidget->item(i, COLUMN_SUBDIR)->text();
        QString source = MainWindow::convertToRelativePath(m_configFileName, ui->filesTableWidget->item(i, COLUMN_SOURCE)->text());

        xmlWriter.writeStartElement("File");
        xmlWriter.writeAttribute("subDirectory", subDirectory);
        xmlWriter.writeAttribute("type", box->currentText());
        xmlWriter.writeAttribute("source", source);
        xmlWriter.writeEndElement();
    }
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("ScriptArguments");
    for(int i = 0; i < ui->argumentsListWidget->count(); i++)
    {
        xmlWriter.writeStartElement("ScriptArgument");
        xmlWriter.writeAttribute("value", ui->argumentsListWidget->item(i)->text());
        xmlWriter.writeEndElement();
    }
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("ScriptWindowState");
    xmlWriter.writeAttribute("withScriptWindow", QString("%1").arg(ui->withScriptWindowCheckBox->isChecked()));
    xmlWriter.writeAttribute("notMinimized", QString("%1").arg(ui->notMinimized->isChecked()));
    xmlWriter.writeAttribute("minScVersion", QString("%1.%2").arg(ui->minScVersionMajor->value()).arg(ui->minScVersionMinor->value()));
    xmlWriter.writeAttribute("sceFileName", MainWindow::convertToRelativePath(m_configFileName, ui->fileLineEdit->text()));
    xmlWriter.writeEndElement();

    xmlWriter.writeEndElement();//SceConfiguration

    return xmlBuffer.data();
}
示例#4
0
bool TrainingSetFile::flush()
{
	QXmlStreamWriter tsWriteXML;

	int
			nPatterns = ts->getPatternCount(),
			nInputs = ts->getInputsSize(),
			nTargets = ts->getTargetsSize();

	QString strInputs,
			strTargets;

	vector<vector<double> >
			inputs = ts->getInputs(),
			targets = ts->getTargets();

	Normalization
			*inputsNorm = ts->getInputsNormalization(),
			*targetsNorm = ts->getTargetsNormalization();

	QString
			strInputsNorm = inputsNorm->getName(),
			strTargetsNorm = targetsNorm->getName();

	DataRepresentation
			*idr = ts->getInputsDataRepresentation(),
			*tdr = ts->getTargetsDataRepresentation();

	tsWriteXML.setDevice(this);
	tsWriteXML.setAutoFormatting(true);
	tsWriteXML.setAutoFormattingIndent(3);

	tsWriteXML.writeStartDocument();

	tsWriteXML.writeStartElement(STR_TRAININGSET);
	//Indica el numero de patrones a almacenar
	tsWriteXML.writeAttribute(STR_PATTERNSIZE, QString::number(nPatterns));

	//Indica el tamaño de las entradas
	tsWriteXML.writeAttribute(STR_INPUTSSIZE, QString::number(nInputs));

	//Indica el tamaño de las salidas
	tsWriteXML.writeAttribute(STR_TARGETSSIZE, QString::number(nTargets));

	//Indica propiedades particulares del archivo
	tsWriteXML.writeStartElement(STR_PROPERTIES);
	tsWriteXML.writeAttribute(STR_VERSION, "1.0.0");
	tsWriteXML.writeEndElement();

	//Este parametro indica que representacion grafica se usara para visualizar entradas
	tsWriteXML.writeStartElement(STR_INPUTSDATAREPRESENTATION);
	tsWriteXML.writeAttribute(STR_NAME, idr->getName());
	tsWriteXML.writeAttribute(STR_FORMAT, idr->getImageFormatName());
	tsWriteXML.writeAttribute(STR_WIDTH, QString::number(idr->getWidth()));
	tsWriteXML.writeAttribute(STR_HEIGHT, QString::number(idr->getHeight()));
	tsWriteXML.writeEndElement();

	//Este parametro indica que representacion grafica se usara para visualizar las salidas
	tsWriteXML.writeStartElement(STR_TARGETSDATAREPRESENTATION);
	tsWriteXML.writeAttribute(STR_NAME, tdr->getName());
	tsWriteXML.writeAttribute(STR_FORMAT, tdr->getImageFormatName());
	tsWriteXML.writeAttribute(STR_WIDTH, QString::number(tdr->getWidth()));
	tsWriteXML.writeAttribute(STR_HEIGHT, QString::number(tdr->getHeight()));
	tsWriteXML.writeEndElement();

	//Normalizacion de entradas
	tsWriteXML.writeStartElement(STR_INPUTSNORMALIZATION);
	tsWriteXML.writeAttribute(STR_TYPE, strInputsNorm);
	tsWriteXML.writeAttribute(STR_MAXVALUE, QString::number(inputsNorm->getMaxValue(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_MINVALUE, QString::number(inputsNorm->getMinValue(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_THRESHOLD, QString::number(inputsNorm->getThreshold(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_AMPLITUDE, QString::number(inputsNorm->getAmplitude(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_ELONGATION, QString::number(inputsNorm->getElongation(), decimalformat, decimals));
	tsWriteXML.writeEndElement();

	//Normalizacion de salidas
	tsWriteXML.writeStartElement(STR_TARGETSNORMALIZATION);
	tsWriteXML.writeAttribute(STR_TYPE, strTargetsNorm);
	tsWriteXML.writeAttribute(STR_MAXVALUE, QString::number(targetsNorm->getMaxValue(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_MINVALUE, QString::number(targetsNorm->getMinValue(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_THRESHOLD, QString::number(targetsNorm->getThreshold(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_AMPLITUDE, QString::number(targetsNorm->getAmplitude(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_ELONGATION, QString::number(targetsNorm->getElongation(), decimalformat, decimals));
	tsWriteXML.writeEndElement();

	for(int p = 0; p < nPatterns; p++){
		tsWriteXML.writeStartElement(STR_PATTERN);
		tsWriteXML.writeAttribute(STR_INDEX, QString::number(p));
		//Se escriben las entradas
		tsWriteXML.writeStartElement(STR_INPUTS);
		strInputs = "";
		for(int i = 0; i < nInputs; i++){
			strInputs += QString::number(inputs[p][i], decimalformat, decimals);
			if(i != nInputs - 1){
				strInputs += STR_SEPARATOR;
			}
		}
		tsWriteXML.writeCharacters(strInputs);
		tsWriteXML.writeEndElement();//inputs

		//Se escriben las salidas
		tsWriteXML.writeStartElement(STR_TARGETS);
		strTargets = "";
		for(int t = 0; t < nTargets; t++){
			strTargets += QString::number(targets[p][t], decimalformat, decimals);
			if(t != nTargets - 1){
				strTargets += STR_SEPARATOR;
			}
		}
		//		tsXML.writeTextElement("targets", strTargets);
		tsWriteXML.writeCharacters(strTargets);
		tsWriteXML.writeEndElement();//targets
		tsWriteXML.writeEndElement();//pattern
	}
	tsWriteXML.writeEndElement();//trainingset
	tsWriteXML.writeEndDocument();

	return true;
}
/**
 * Creates an SCE file string.
 * @return
 *      The string.
 */
QString CreateSceFile::createSceFile()
{
    QBuffer xmlBuffer;

    QXmlStreamWriter xmlWriter;
    xmlWriter.setAutoFormatting(true);
    xmlWriter.setAutoFormattingIndent(2);
    xmlBuffer.open(QIODevice::WriteOnly);
    xmlWriter.setDevice(&xmlBuffer);

    xmlWriter.writeStartElement("ExecutableConfig");
    xmlWriter.writeAttribute("version", MainWindow::VERSION);

    xmlWriter.writeStartElement("Scripts");
    for(int i = 0; i < ui->filesTableWidget->rowCount(); i++)
    {
        QComboBox* box = static_cast<QComboBox*>(ui->filesTableWidget->cellWidget(i, COLUMN_TYPE));

        if(box->currentText() == "execute script")
        {
            QString currentFolder = ui->filesTableWidget->item(i, COLUMN_SUBDIR)->text();
            QString source = ui->filesTableWidget->item(i, COLUMN_SOURCE)->text();

            xmlWriter.writeStartElement("Script");
            QString path = currentFolder.isEmpty() ? "./" + QFileInfo(source).fileName() : "./" + currentFolder + "/" + QFileInfo(source).fileName();
            xmlWriter.writeAttribute("path", path);
            xmlWriter.writeEndElement();
        }
    }
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("LibraryPaths");
    QStringList libPaths = getAllLibraryPathsFromFileTable();
    for(auto el : libPaths)
    {
        xmlWriter.writeStartElement("LibraryPath");
        xmlWriter.writeAttribute("path", "./" + el);
        xmlWriter.writeEndElement();
    }
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("PluginPaths");
    QStringList pluginPaths = getAllPluginPathsFromFileTable();
    for(auto el : pluginPaths)
    {
        xmlWriter.writeStartElement("PluginPath");
        xmlWriter.writeAttribute("path", "./" + el);
        xmlWriter.writeEndElement();
    }
    xmlWriter.writeEndElement();


    xmlWriter.writeStartElement("ScriptArguments");
    for(int i = 0; i < ui->argumentsListWidget->count(); i++)
    {
        xmlWriter.writeStartElement("ScriptArgument");
        xmlWriter.writeAttribute("value", ui->argumentsListWidget->item(i)->text());
        xmlWriter.writeEndElement();
    }
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("Options");
    xmlWriter.writeAttribute("withScriptWindow", QString("%1").arg(ui->withScriptWindowCheckBox->isChecked()));
    xmlWriter.writeAttribute("notMinimized", QString("%1").arg(ui->notMinimized->isChecked()));
    xmlWriter.writeAttribute("minScVersion", QString("%1.%2").arg(ui->minScVersionMajor->value()).arg(ui->minScVersionMinor->value()));
    xmlWriter.writeEndElement();

    xmlWriter.writeEndElement();//ScriptCommunicatorExecutable

    return xmlBuffer.data();
}