Esempio n. 1
0
bool writeSettings(QIODevice &device, const QSettings::SettingsMap &map)
{
    try {
        YAML::Emitter out;
        SettingsIterator it = map.begin();
        writeGroup( "", out, it, map );
        device.write(out.c_str());
        return true;
    }
    catch (std::exception & e) {
        qWarning() << "Exception when writing YAML config file:" << e.what();
        return false;
    }
}
Esempio n. 2
0
bool writeXmlFile(QIODevice &device, const QSettings::SettingsMap &map)
{
	QXmlStreamWriter xmlWriter(&device);

	xmlWriter.setAutoFormatting(true);
	xmlWriter.writeStartDocument();
	xmlWriter.writeStartElement("Settings");

	QStringList prev_elements;
	QSettings::SettingsMap::ConstIterator map_i;

	// Alle Elemente der Map durchlaufen
	for (map_i = map.begin(); map_i != map.end(); map_i++) {

		QStringList elements = map_i.key().split("/");

		int x = 0;
		// Zu schließende Elemente ermitteln
		while (x < prev_elements.size() && elements.at(x) == prev_elements.at(x)) {
			x++;
		}

		// Elemente schließen
		for (int i = prev_elements.size() - 1; i >= x; i--) {
			xmlWriter.writeEndElement();
		}

		// Elemente öffnen
		for (int i = x; i < elements.size(); i++) {
			xmlWriter.writeStartElement(elements.at(i));
		}

		// Wert eintragen
		xmlWriter.writeCharacters(map_i.value().toString());

		prev_elements = elements;
	}

	// Noch offene Elemente schließen
	for (int i = 0; i < prev_elements.size(); i++) {
		xmlWriter.writeEndElement();
	}

	xmlWriter.writeEndElement();
	xmlWriter.writeEndDocument();

	return true;
}