예제 #1
0
QString QxXmlWriter::writeBinaryData(const QString & qualifiedName, QxXmlWriter::type_byte_arr_ptr pData)
{
   QString sKey(getNextKeyBinaryData());
   m_mapBinaryData.insert(sKey, pData);

   writeStartElement(qualifiedName);
   writeAttribute(QX_XML_ATTRIBUTE_IS_BINARY_DATA, "1");
   writeCharacters(sKey);
   writeEndElement();

   return sKey;
}
예제 #2
0
static int
flushCharacters (wchar_t end, void *data) {
  if (inputLength) {
    if (!writeCharacters(inputBuffer, inputLength, data)) return 0;
    inputLength = 0;

    if (end)
      if (!putCharacter(end, data))
        return 0;
  }

  return 1;
}
예제 #3
0
static int
processCharacters (const wchar_t *characters, size_t count, wchar_t end, void *data) {
  if (opt_reformatText && count) {
    if (iswspace(characters[0]))
      if (!flushCharacters('\n', data))
        return 0;

    {
      unsigned int spaces = !inputLength? 0: 1;
      size_t newLength = inputLength + spaces + count;

      if (newLength > inputSize) {
        size_t newSize = newLength | 0XFF;
        wchar_t *newBuffer = calloc(newSize, sizeof(*newBuffer));

        if (!newBuffer) {
          noMemory(data);
          return 0;
        }

        wmemcpy(newBuffer, inputBuffer, inputLength);
        free(inputBuffer);

        inputBuffer = newBuffer;
        inputSize = newSize;
      }

      while (spaces) {
        inputBuffer[inputLength++] = WC_C(' ');
        spaces -= 1;
      }

      wmemcpy(&inputBuffer[inputLength], characters, count);
      inputLength += count;
    }

    if (end != '\n') {
      if (!flushCharacters(0, data)) return 0;
      if (!putCharacter(end, data)) return 0;
    }
  } else {
    if (!flushCharacters('\n', data)) return 0;
    if (!writeCharacters(characters, count, data)) return 0;
    if (!putCharacter(end, data)) return 0;
  }

  return 1;
}
예제 #4
0
bool CharactersManager::writeCharacters() const
{
    const QString path = QStandardPaths::writableLocation(QStandardPaths::StandardLocation::DataLocation);

    QFile saveFile(path);

    if(!saveFile.open(QFile::OpenModeFlag::WriteOnly))
    {
        qWarning("Can't write file");
        return false;
    }

    QJsonObject writeJson;
    writeCharacters(writeJson);
    QJsonDocument jsonDoc(writeJson);
    saveFile.write(jsonDoc.toJson());

    return true;
}
예제 #5
0
void GeoWriter::writeElement( const QString &key, const QString &value )
{
    writeStartElement( key );
    writeCharacters( value );
    writeEndElement();
}
bool QTableModelHtmlWriter::write(QAdvancedTableView* view, bool all)
{
    if (!m_device->isWritable() && ! m_device->open(QIODevice::WriteOnly)) {
        qWarning() << "QTableModelHtmlWriter::writeAll: the device can not be opened for writing";
        return false;
    }
	QXmlStreamWriter stream(m_device);
	stream.setAutoFormatting(true);
	stream.setAutoFormattingIndent(2);

	stream.writeStartElement("html");
	stream.writeStartElement("head");
	stream.writeEndElement();

	stream.writeStartElement("body");
	stream.writeStartElement("table");
	stream.writeAttribute("border", view->showGrid()?"1":"0");
	if (view->showGrid()){
		stream.writeAttribute("style", "border-style:none");
	}
	//
	QPair<QModelIndex, QModelIndex> e;
	if (!all){
		e = selectionEdges(view->selectionModel()->selection());
	} else {
		e.first = view->model()->index(0, 0);
		e.second = view->model()->index(view->model()->rowCount() - 1, view->model()->columnCount() - 1);
	}
	if (m_includeHeader){
		// start tag <tr>
		stream.writeStartElement("tr");
		writeBorderStyle(stream, view->gridStyle());
		for (int c = e.first.column(); c <= e.second.column(); c++){
			if (all || !view->horizontalHeader()->isSectionHidden(c)){
				stream.writeStartElement("th");
				writeAlignment(stream, static_cast<Qt::AlignmentFlag>(view->model()->headerData(view->horizontalHeader()->visualIndex(c), Qt::Horizontal, Qt::TextAlignmentRole).toInt()));
				stream.writeStartElement("font");
				writeFontAttributes(stream, qvariant_cast<QFont>(view->model()->headerData(view->horizontalHeader()->visualIndex(c), Qt::Horizontal, Qt::FontRole)));
				stream.writeCharacters(view->model()->headerData(view->horizontalHeader()->visualIndex(c), Qt::Horizontal, Qt::DisplayRole).toString());
				stream.writeEndElement();
				// end tag <th>
				stream.writeEndElement();
			}
		}
		// end tag <tr>
		stream.writeEndElement();
	}
	for (int r = e.first.row(); r <= e.second.row(); r++){
		stream.writeStartElement("tr");
		for (int c = e.first.column(); c <= e.second.column(); c++){
			if (!view->horizontalHeader()->isSectionHidden(c)){
				stream.writeStartElement("td");
				writeAlignment(stream, static_cast<Qt::AlignmentFlag>(view->model()->index(r, view->horizontalHeader()->visualIndex(c)).data(Qt::TextAlignmentRole).toInt()));
				writeBorderStyle(stream, view->gridStyle());
				writeBackgroundColor(stream, qvariant_cast<QBrush>(view->filterProxyModel()->index(r, view->horizontalHeader()->visualIndex(c)).data(Qt::BackgroundRole)));
				writeDecoration(stream, view->model()->index(r, view->horizontalHeader()->visualIndex(c)).data(Qt::DecorationRole));
				stream.writeStartElement("font");
				writeFontAttributes(stream, qvariant_cast<QFont>(view->model()->index(r, view->horizontalHeader()->visualIndex(c)).data(Qt::FontRole)));
				writeCharacters(stream, view->model()->index(r, view->horizontalHeader()->visualIndex(c)).data(Qt::DisplayRole).toString());
				stream.writeEndElement();
				// end tag <td>
				stream.writeEndElement();
			}
		}
		// end tag <tr>
		stream.writeEndElement();
	}

	// end tag <table>
	stream.writeEndElement();
	// end tag <body>
	stream.writeEndElement();
	// end tag <html>
	stream.writeEndElement();
	return true;
}