Example #1
0
QString XmlUtil::stripAnswers(const QString &input) {
	QDomDocument doc;
	doc.setContent(input);
	QDomElement docElem = doc.documentElement();

	QDomNode n = docElem.firstChild();
	while ( !n.isNull() ) {
		QDomElement e = n.toElement();
		if ( !e.isNull() && (e.namespaceURI().isEmpty() || e.namespaceURI() == XML_NS) ) {
			if ( e.nodeName() == "choose" ) {
				QDomElement c = e.firstChildElement("choice");
				while ( !c.isNull() ) {
					c.removeAttribute("answer");
					c = c.nextSiblingElement("choice");
				}
			} else if ( e.nodeName() == "identification" ) {
				QDomElement a = e.firstChildElement("a");
				while ( !a.isNull() ) {
					e.removeChild(a);
					a = e.firstChildElement("a");
				}
			}
		}
		n = n.nextSibling();
	}
	return doc.toString(2);
}
static PyObject *meth_QDomElement_removeAttribute(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        const QString * a0;
        int a0State = 0;
        QDomElement *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "BJ1", &sipSelf, sipType_QDomElement, &sipCpp, sipType_QString,&a0, &a0State))
        {
            Py_BEGIN_ALLOW_THREADS
            sipCpp->removeAttribute(*a0);
            Py_END_ALLOW_THREADS
            sipReleaseType(const_cast<QString *>(a0),sipType_QString,a0State);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QDomElement, sipName_removeAttribute, NULL);

    return NULL;
}
Example #3
0
/**
 * Update DOM tree element
 */
void
GEdge::updateElement()
{
#if 0    
    QDomElement e = elem();
    int i = 0;
    QDomElement new_e = graph()->createElement( "edge");
    QDomNode e2 = graph()->documentElement().removeChild( e);
    assert( !e2.isNull());
    graph()->documentElement().appendChild( new_e);
    setElement( new_e);
    e = new_e;
#endif
    /* Base class method call to print generic edge properties */
    AuxEdge::updateElement();
    QDomElement e = elem();
    /** Save style that describes this edge only along with edge */
    if ( isNotNullP( style())) 
    {     
        if ( 1 == style()->numItems())
        {
            e.removeAttribute("style");
            style()->writeElement( e, false);
        } else
        {
            e.setAttribute("style", style()->name());
        }
    }

}
Example #4
0
bool LocalXmlBackend::todoToDom(const OpenTodoList::ITodo *todo, QDomDocument &doc)
{
  QDomElement root = doc.documentElement();
  if ( !root.isElement() ) {
    root = doc.createElement( "todo" );
    doc.appendChild( root );
  }
  root.setAttribute( "id", todo->uuid().toString() );
  root.setAttribute( "title", todo->title() );
  root.setAttribute( "done", todo->done() ? "true" : "false" );
  root.setAttribute( "priority", todo->priority() );
  root.setAttribute( "weight", todo->weight() );
  if ( todo->dueDate().isValid() ) {
    root.setAttribute( "dueDate", todo->dueDate().toString() );
  } else {
    root.removeAttribute( "dueDate" );
  }
  QDomElement descriptionElement = root.firstChildElement( "description" );
  if ( !descriptionElement.isElement() ) {
    descriptionElement = doc.createElement( "description" );
    root.appendChild( descriptionElement );
  }
  while ( !descriptionElement.firstChild().isNull() ) {
    descriptionElement.removeChild( descriptionElement.firstChild() );
  }
  QDomText descriptionText = doc.createTextNode( todo->description() );
  descriptionElement.appendChild( descriptionText );
  return true;
}
Example #5
0
/*
 * We don't want to have empty node attributes, so we remove them
 * if we are supplied an empty value.
 */
void Util::setNodeAttr(QDomElement &node, const QString &attr_name,
                       const QString &attr_val) {
    if (attr_val != "") {
        node.setAttribute(attr_name, attr_val);
    } else {
        node.removeAttribute(attr_name);
    }
}
Example #6
0
QDomElement KWDWriter::startFormat(const QDomElement &paragraph,
                                   const QDomElement &formatToClone)
{
    QDomElement format = formatToClone.cloneNode().toElement();
    if (format.isNull()) {
        kWarning(30503) << "startFormat: null format cloned";
    }
    if (paragraph.isNull()) {
        kWarning(30503) << "startFormat on empty paragraph";
    }

    format.removeAttribute("len");
    format.removeAttribute("pos");
    format.removeAttribute("id");
    for (QDomElement a = format.firstChild().toElement();!a.isNull();a = a.nextSibling().toElement()) {
        if (a.tagName() == "ANCHOR") {
            format.removeChild(a);
        }
    }
    paragraph.elementsByTagName("FORMATS").item(0).appendChild(format);
    return format;
}
void SetupPluginsDialog::saveSettings()
{
	QMap<QTableWidgetItem *, QDomElement>::iterator it = FItemElement.begin();
	while (it != FItemElement.end())
	{
		QDomElement pluginElem = it.value();
		if (it.key()->checkState() == Qt::Checked)
			pluginElem.removeAttribute("enabled");
		else
			pluginElem.setAttribute("enabled","false");
		it++;
	}
	FPluginManager->setLocale((QLocale::Language)ui.cmbLanguage->itemData(ui.cmbLanguage->currentIndex()).toInt(), (QLocale::Country)ui.cmbCountry->itemData(ui.cmbCountry->currentIndex()).toInt());
}
Example #8
0
void parserxml::eraseAttribute(std::string pNodeDirection, std::string pNameAttribute)
{
    if(isRoot(pNodeDirection))
    {
        _document.firstChild().toElement().removeAttribute(QString::fromStdString(pNameAttribute));
    }
    else
    {
        QDomElement childaux = tourXML(pNodeDirection);
        childaux.removeAttribute(QString::fromStdString(pNameAttribute));
    }
    qDebug() << "Atributo borrado con exito.";
    updateDocument();
}
Example #9
0
// Modify the en-to tag into an input field
void NoteFormatter::modifyTodoTags(QDomElement &todo) {
    QLOG_TRACE() << "Entering NeverNote.modifyTodoTags";
    todo.setAttribute("type", "checkbox");

    // Checks the en-to tag wheter or not the todo-item is checked or not
    // and sets up the HTML to keep storing the information in value
    QString checked = todo.attribute("checked");
    if (checked.toLower() == "true")
        todo.setAttribute("checked", "checked");
    else
        todo.removeAttribute("checked");

    todo.setAttribute("onClick", "if(!checked) removeAttribute('checked'); else setAttribute('checked', 'checked'); editorWindow.editAlert();");
    todo.setAttribute("style", "cursor: hand;");
    //todo.setAttribute("onMouseOver", "style.cursor='hand'");
    todo.setTagName("input");
    QLOG_TRACE() << "Leaving NeverNote.modifyTodoTags";
}
Example #10
0
void BookmarkWidget::undoRemoveBookmark(QTreeWidgetItem* item)
{
    QString caption = item->text(TITLE_COLUMN);
    QString uuid = item->text(UUID_COLUMN);
    QString path = item->text(2);
    path.append(QDir::separator() + QString("BookMark") + QDir::separator() + QString("bookmarks.xml"));

    caption = caption.split("</font>")[0].split("<font color=\"gray\">")[1];
    item->setText(TITLE_COLUMN, caption);
    item->setText(3, QString::number(1));

    QDomDocument doc;
    qDebug()<<"in undo"<<path;
    QDomElement elt = findElementbyUUID(doc, uuid, BOOKMARK, path);
    if(elt.isNull() || elt.attribute("isHidden") != QString("True")) return;
    elt.removeAttribute("isHidden");
    saveDOMToFile(doc, path);
    refreshBookmarkList();
}
Example #11
0
void CollapsibleGroup::slotSaveGroup()
{
    QString name = QInputDialog::getText(this, i18n("Save Group"), i18n("Name for saved group: "), QLineEdit::Normal, m_title->text());
    if (name.isEmpty()) return;
    QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/effects/");
    if (!dir.exists()) {
        dir.mkpath(QStringLiteral("."));
    }

    if (dir.exists(name + ".xml")) if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", name + ".xml")) == KMessageBox::No) return;

    QDomDocument doc = effectsData();
    QDomElement base = doc.documentElement();
    QDomNodeList effects = base.elementsByTagName(QStringLiteral("effect"));
    for (int i = 0; i < effects.count(); ++i) {
	QDomElement eff = effects.at(i).toElement();
        eff.removeAttribute(QStringLiteral("kdenlive_ix"));
	EffectInfo info;
	info.fromString(eff.attribute(QStringLiteral("kdenlive_info")));
	// Make sure all effects have the correct new group name
	info.groupName = name;
	// Saved effect group should have a group index of -1
	info.groupIndex = -1;
	eff.setAttribute(QStringLiteral("kdenlive_info"), info.toString());

    }
    
    base.setAttribute(QStringLiteral("name"), name);
    base.setAttribute(QStringLiteral("id"), name);
    base.setAttribute(QStringLiteral("type"), QStringLiteral("custom"));  

    QFile file(dir.absoluteFilePath(name + ".xml"));
    if (file.open(QFile::WriteOnly | QFile::Truncate)) {
        QTextStream out(&file);
        out << doc.toString();
    }
    file.close();
    emit reloadEffects();
}
Example #12
0
void SvgFlattener::flattenChildren(QDomElement &element){

    // recurse the children
    QDomNodeList childList = element.childNodes();

    for(uint i = 0; i < childList.length(); i++){
        QDomElement child = childList.item(i).toElement();
        flattenChildren(child);
    }

    //do translate
    if(hasTranslate(element)){
		QList<double> params = TextUtils::getTransformFloats(element);
		if (params.size() == 2) {
            shiftChild(element, params.at(0), params.at(1), false);
			//DebugDialog::debug(QString("translating %1 %2").arg(params.at(0)).arg(params.at(1)));
		}
		else if (params.size() == 6) {
            shiftChild(element, params.at(4), params.at(5), false);
		}
		else if (params.size() == 1) {
            shiftChild(element, params.at(0), 0, false);
			//DebugDialog::debug(QString("translating %1").arg(params.at(0)));
		}
		else {
			DebugDialog::debug("weird transform found");
		}
    }
    else if(hasOtherTransform(element)) {
        QMatrix transform = TextUtils::transformStringToMatrix(element.attribute("transform"));

        //DebugDialog::debug(QString("rotating %1 %2 %3 %4 %5 %6").arg(params.at(0)).arg(params.at(1)).arg(params.at(2)).arg(params.at(3)).arg(params.at(4)).arg(params.at(5)));
        unRotateChild(element, transform);
    }

    // remove transform
    element.removeAttribute("transform");
}
Example #13
0
bool SvgFileSplitter::splitString(QString & contents, const QString & elementID)
{
	m_byteArray.clear();

	// gets rid of some crap inserted by illustrator which can screw up polygons and paths
	contents.replace('\t', ' ');
	contents.replace('\n', ' ');
	contents.replace('\r', ' ');

	// get rid of inkscape stuff too
	TextUtils::cleanSodipodi(contents);

	QString errorStr;
	int errorLine;
	int errorColumn;

	if (!m_domDocument.setContent(contents, true, &errorStr, &errorLine, &errorColumn)) {
        //DebugDialog::debug(QString("parse error: %1 l:%2 c:%3\n\n%4").arg(errorStr).arg(errorLine).arg(errorColumn).arg(contents));
		return false;
	}

	QDomElement root = m_domDocument.documentElement();
	if (root.isNull()) {
		return false;
	}

	if (root.tagName() != "svg") {
		return false;
	}

	root.removeAttribute("space");

	QDomElement element = TextUtils::findElementWithAttribute(root, "id", elementID);
	if (element.isNull()) {
		return false;
	}

	QStringList superTransforms;
	QDomNode parent = element.parentNode();
	while (!parent.isNull()) {
		QDomElement e = parent.toElement();
		if (!e.isNull()) {
			QString transform = e.attribute("transform");
			if (!transform.isEmpty()) {
				superTransforms.append(transform);
			}
		}
		parent = parent.parentNode();
	}

	if (!superTransforms.isEmpty()) {
		element.removeAttribute("id");
	}

	QDomDocument document;
	QDomNode node = document.importNode(element, true);
	document.appendChild(node);
	QString elementText = document.toString();

	if (!superTransforms.isEmpty()) {
		for (int i = 0; i < superTransforms.count() - 1; i++) {
			elementText = QString("<g transform='%1'>%2</g>").arg(superTransforms[i]).arg(elementText);
		}
		elementText = QString("<g id='%1' transform='%2'>%3</g>")
			.arg(elementID)
			.arg(superTransforms[superTransforms.count() - 1])
			.arg(elementText);
	}

	while (!root.firstChild().isNull()) {
		root.removeChild(root.firstChild());
	}

	// at this point the document should contain only the <svg> element and possibly svg info strings
	QString svgOnly = m_domDocument.toString();
	int ix = svgOnly.lastIndexOf("/>");
	if (ix < 0) return false;

	svgOnly[ix] = ' ';
	svgOnly += elementText;
	svgOnly += "</svg>";

	if (!m_domDocument.setContent(svgOnly, true, &errorStr, &errorLine, &errorColumn)) {
		return false;
	}

	m_byteArray = m_domDocument.toByteArray();

	//QString s = m_domDocument.toString();
	//DebugDialog::debug(s);

	return true;
}
Example #14
0
/*
    \internal

    Convert Qt 2.x format to Qt 3.x format if necessary.
*/
void DomTool::fixDocument(QDomDocument& doc)
{
    QDomElement e;
    QDomNode n;
    QDomNodeList nl;
    int i = 0;

    e = doc.firstChild().toElement();
    if (e.tagName() != QLatin1String("UI"))
        return;

    // rename classes and properties
    double version = versionToDouble(e.attribute(QLatin1String("version")));

    nl = e.childNodes();
    fixAttributes(nl, version);

    // 3.x don't do anything more
    if (version >= 3.0)
        return;

    // in versions smaller than 3.0 we need to change more

    e.setAttribute(QLatin1String("version"), 3.0);
    e.setAttribute(QLatin1String("stdsetdef"), 1);
    nl = e.elementsByTagName(QLatin1String("property"));
    for (i = 0; i <  (int) nl.length(); i++) {
        e = nl.item(i).toElement();
        QString name;
        QDomElement n2 = e.firstChild().toElement();
        if (n2.tagName() == QLatin1String("name")) {
            name = n2.firstChild().toText().data();
            if (name == QLatin1String("resizeable"))
                e.setAttribute(QLatin1String("name"), QLatin1String("resizable"));
            else
                e.setAttribute(QLatin1String("name"), name);
            e.removeChild(n2);
        }
        bool stdset = toBool(e.attribute(QLatin1String("stdset")));
        if (stdset || name == QLatin1String("toolTip") || name == QLatin1String("whatsThis") ||
             name == QLatin1String("buddy") ||
             e.parentNode().toElement().tagName() == QLatin1String("item") ||
             e.parentNode().toElement().tagName() == QLatin1String("spacer") ||
             e.parentNode().toElement().tagName() == QLatin1String("column")
            )
            e.removeAttribute(QLatin1String("stdset"));
        else
            e.setAttribute(QLatin1String("stdset"), 0);
    }

    nl = doc.elementsByTagName(QLatin1String("attribute"));
    for (i = 0; i <  (int) nl.length(); i++) {
        e = nl.item(i).toElement();
        QString name;
        QDomElement n2 = e.firstChild().toElement();
        if (n2.tagName() == QLatin1String("name")) {
            name = n2.firstChild().toText().data();
            e.setAttribute(QLatin1String("name"), name);
            e.removeChild(n2);
        }
    }

    nl = doc.elementsByTagName(QLatin1String("image"));
    for (i = 0; i <  (int) nl.length(); i++) {
        e = nl.item(i).toElement();
        QString name;
        QDomElement n2 = e.firstChild().toElement();
        if (n2.tagName() == QLatin1String("name")) {
            name = n2.firstChild().toText().data();
            e.setAttribute(QLatin1String("name"), name);
            e.removeChild(n2);
        }
    }

    nl = doc.elementsByTagName(QLatin1String("widget"));
    for (i = 0; i <  (int) nl.length(); i++) {
        e = nl.item(i).toElement();
        QString name;
        QDomElement n2 = e.firstChild().toElement();
        if (n2.tagName() == QLatin1String("class")) {
            name = n2.firstChild().toText().data();
            e.setAttribute(QLatin1String("class"), name);
            e.removeChild(n2);
        }
    }

}
int main(int argc, char *argv[])
{
#if QT_VERSION < 0x050000
	qInstallMsgHandler(myMessageHandler);
#else
	qInstallMessageHandler(myMessageHandler);
#endif
	QCoreApplication app(argc, argv);

	if (argc != 2)
	{
		qCritical("Usage: autotranslate <target-dir>");
		return -1;
	}

	QDir srcDir(app.arguments().value(1),"*.ts",QDir::Name,QDir::Files);
	if (!srcDir.exists())
	{
		qCritical("Source directory '%s' not found.",srcDir.dirName().toLocal8Bit().constData());
		return -1;
	}

	QDirIterator srcIt(srcDir);
	while (srcIt.hasNext())
	{
		QFile srcFile(srcIt.next());
		if (srcFile.open(QFile::ReadOnly))
		{
			QDomDocument doc;
			if (doc.setContent(&srcFile,true))
			{
				qDebug("Generation auto translation from '%s'.",srcFile.fileName().toLocal8Bit().constData());

				QDomElement rootElem = doc.firstChildElement("TS");
				rootElem.setAttribute("language",rootElem.attribute("sourcelanguage","en"));
				
				QDomElement contextElem = rootElem.firstChildElement("context");
				while(!contextElem.isNull())
				{
					QDomElement messageElem = contextElem.firstChildElement("message");
					while(!messageElem.isNull())
					{
						QDomElement sourceElem = messageElem.firstChildElement("source");
						QDomElement translationElem = messageElem.firstChildElement("translation");
						if (!sourceElem.isNull() && !translationElem.isNull())
							if (translationElem.attribute("type")=="unfinished" && translationElem.text().isEmpty())
							{
								QString sourceText = sourceElem.text();
								if (messageElem.attribute("numerus") == "yes")
									qWarning("Untranslated numerus message: \"%s\"", sourceText.toLocal8Bit().constData());
								else
								{
									translationElem.removeChild(translationElem.firstChild());
									translationElem.appendChild(doc.createTextNode(sourceText));
									translationElem.removeAttribute("type");
								}
							}
						messageElem = messageElem.nextSiblingElement("message");
					}
					contextElem = contextElem.nextSiblingElement("context");
				}
				srcFile.close();
				if (srcFile.open(QFile::WriteOnly|QFile::Truncate))
				{
					srcFile.write(doc.toByteArray());
					srcFile.close();
				}
				else
					qWarning("Failed to open destination file '%s' for write.",srcFile.fileName().toLocal8Bit().constData());
			}
			else
				qWarning("Invalid translation source file '%s'.",srcFile.fileName().toLocal8Bit().constData());
			srcFile.close();
		}
		else
			qWarning("Could not open translation source file '%s'.",srcFile.fileName().toLocal8Bit().constData());
	}
	return 0;
}
Example #16
0
void parserxml::eraseAttribute(std::string pChildDirection, std::string pAttribute)
{
    QDomElement childaux = tourXML(pChildDirection);
    childaux.removeAttribute(QString::fromStdString(pAttribute));
}
void QgsProjectFileTransform::transform1800to1900()
{
  if ( mDom.isNull() )
  {
    return;
  }

  QDomNodeList layerItemList = mDom.elementsByTagName( "rasterproperties" );
  for ( int i = 0; i < layerItemList.size(); ++i )
  {
    QDomElement rasterPropertiesElem = layerItemList.at( i ).toElement();
    QDomNode layerNode = rasterPropertiesElem.parentNode();
    QDomElement dataSourceElem = layerNode.firstChildElement( "datasource" );
    QDomElement layerNameElem = layerNode.firstChildElement( "layername" );
    QgsRasterLayer rasterLayer;
    // TODO: We have to use more data from project file to read the layer it correctly,
    // OTOH, we should not read it until it was converted
    rasterLayer.readXML( layerNode );
    convertRasterProperties( mDom, layerNode, rasterPropertiesElem, &rasterLayer );
  }

  //composer: replace mGridAnnotationPosition with mLeftGridAnnotationPosition & co.
  // and mGridAnnotationDirection with mLeftGridAnnotationDirection & co.
  QDomNodeList composerMapList = mDom.elementsByTagName( "ComposerMap" );
  for ( int i = 0; i < composerMapList.size(); ++i )
  {
    QDomNodeList gridList = composerMapList.at( i ).toElement().elementsByTagName( "Grid" );
    for ( int j = 0; j < gridList.size(); ++j )
    {
      QDomNodeList annotationList = gridList.at( j ).toElement().elementsByTagName( "Annotation" );
      for ( int k = 0; k < annotationList.size(); ++k )
      {
        QDomElement annotationElem = annotationList.at( k ).toElement();

        //position
        if ( annotationElem.hasAttribute( "position" ) )
        {
          int pos = annotationElem.attribute( "position" ).toInt();
          annotationElem.setAttribute( "leftPosition", pos );
          annotationElem.setAttribute( "rightPosition", pos );
          annotationElem.setAttribute( "topPosition", pos );
          annotationElem.setAttribute( "bottomPosition", pos );
          annotationElem.removeAttribute( "position" );
        }

        //direction
        if ( annotationElem.hasAttribute( "direction" ) )
        {
          int dir = annotationElem.attribute( "direction" ).toInt();
          if ( dir == 2 )
          {
            annotationElem.setAttribute( "leftDirection", 0 );
            annotationElem.setAttribute( "rightDirection", 0 );
            annotationElem.setAttribute( "topDirection", 1 );
            annotationElem.setAttribute( "bottomDirection", 1 );
          }
          else if ( dir == 3 )
          {
            annotationElem.setAttribute( "leftDirection", 1 );
            annotationElem.setAttribute( "rightDirection", 1 );
            annotationElem.setAttribute( "topDirection", 0 );
            annotationElem.setAttribute( "bottomDirection", 0 );
          }
          else
          {
            annotationElem.setAttribute( "leftDirection", dir );
            annotationElem.setAttribute( "rightDirection", dir );
            annotationElem.setAttribute( "topDirection", dir );
            annotationElem.setAttribute( "bottomDirection", dir );
          }
          annotationElem.removeAttribute( "direction" );
        }
      }
    }
  }

  //Composer: move all items under Composition element
  QDomNodeList composerList = mDom.elementsByTagName( "Composer" );
  for ( int i = 0; i < composerList.size(); ++i )
  {
    QDomElement composerElem = composerList.at( i ).toElement();

    //find <QgsComposition element
    QDomElement compositionElem = composerElem.firstChildElement( "Composition" );
    if ( compositionElem.isNull() )
    {
      continue;
    }

    QDomNodeList composerChildren = composerElem.childNodes();

    if ( composerChildren.size() < 1 )
    {
      continue;
    }

    for ( int j = composerChildren.size() - 1; j >= 0; --j )
    {
      QDomElement childElem = composerChildren.at( j ).toElement();
      if ( childElem.tagName() == "Composition" )
      {
        continue;
      }

      composerElem.removeChild( childElem );
      compositionElem.appendChild( childElem );

    }
  }

  // SimpleFill symbol layer v2: avoid double transparency
  // replacing alpha value of symbol layer's color with 255 (the
  // transparency value is already stored as symbol transparency).
  QDomNodeList rendererList = mDom.elementsByTagName( "renderer-v2" );
  for ( int i = 0; i < rendererList.size(); ++i )
  {
    QDomNodeList layerList = rendererList.at( i ).toElement().elementsByTagName( "layer" );
    for ( int j = 0; j < layerList.size(); ++j )
    {
      QDomElement layerElem = layerList.at( j ).toElement();
      if ( layerElem.attribute( "class" ) == "SimpleFill" )
      {
        QDomNodeList propList = layerElem.elementsByTagName( "prop" );
        for ( int k = 0; k < propList.size(); ++k )
        {
          QDomElement propElem = propList.at( k ).toElement();
          if ( propElem.attribute( "k" ) == "color" || propElem.attribute( "k" ) == "color_border" )
          {
            propElem.setAttribute( "v", propElem.attribute( "v" ).section( ",", 0, 2 ) + ",255" );
          }
        }
      }
    }
  }

  QgsDebugMsg( mDom.toString() );
}
Example #18
0
void cActionDefTest::testSingleLinerDef() throw()
{
    printNote( "SINGLE LINER TESTS" );

    try
    {
        cActionDefSingleLiner *poSingleLiner;

        poSingleLiner = new cActionDefSingleLiner;

        testCase( "SingleLiner empty constructor Name", "", poSingleLiner->name().toStdString() );

        testCase( "SingleLiner empty constructor Upload", cActionUpload::MIN, poSingleLiner->upload() );

        testCase( "SingleLiner empty constructor Pattern", "", poSingleLiner->pattern().toStdString() );

        testCase( "SingleLiner empty constructor Result", cActionResult::MIN, poSingleLiner->result() );

        delete poSingleLiner;

        poSingleLiner = new cActionDefSingleLiner( NULL );

        testCase( "SingleLiner NULL Dom Element Name", "", poSingleLiner->name().toStdString() );

        testCase( "SingleLiner NULL Dom Element Upload", cActionUpload::MIN, poSingleLiner->upload() );

        testCase( "SingleLiner NULL Dom Element Pattern", "", poSingleLiner->pattern().toStdString() );

        testCase( "SingleLiner NULL Dom Element Result", cActionResult::MIN, poSingleLiner->result() );

        delete poSingleLiner;

        QDomDocument obDomDoc( "ActionTest" );
        QDomElement obDomElem = obDomDoc.createElement( "single_liner" );
        obDomElem.setAttribute( "name", "TestSingleLiner" );
        obDomElem.setAttribute( "pattern", "Test Pattern" );
        obDomElem.setAttribute( "result", "OK" );
        obDomElem.setAttribute( "upload", "ALWAYS" );

        poSingleLiner = new cActionDefSingleLiner( &obDomElem );

        testCase( "SingleLiner Correct DOM Element Name", "TestSingleLiner", poSingleLiner->name().toStdString() );

        testCase( "SingleLiner Correct DOM Element Upload", cActionUpload::ALWAYS, poSingleLiner->upload() );

        testCase( "SingleLiner Correct DOM Element Pattern", "Test Pattern", poSingleLiner->pattern().toStdString() );

        testCase( "SingleLiner Correct DOM Element Result", cActionResult::OK, poSingleLiner->result() );

        delete poSingleLiner;

        obDomElem.removeAttribute( "pattern" );
        poSingleLiner = new cActionDefSingleLiner( &obDomElem );

        testCase( "SingleLiner Missing Attribute Name", "TestSingleLiner", poSingleLiner->name().toStdString() );

        testCase( "SingleLiner Missing Attribute Pattern", "", poSingleLiner->pattern().toStdString() );

        delete poSingleLiner;

    } catch( cSevException &e )
    {
        g_obLogger << e;
        m_uiFailedNum++;
    }
}
Example #19
0
/*!
  Convert Qt 2.x format to Qt 3.0 format if necessary
*/
void DomTool::fixDocument( QDomDocument& doc )
{
    QDomElement e;
    QDomNode n;
    QDomNodeList nl;
    int i = 0;

    e = doc.firstChild().toElement();
    if ( e.tagName() != "UI" )
	return;

    // latest version, don't do anything
    if ( e.hasAttribute("version") && e.attribute("version").toDouble() > 3.0 )
	return;

    nl = doc.elementsByTagName( "property" );

    // in 3.0, we need to fix a spelling error
    if ( e.hasAttribute("version") && e.attribute("version").toDouble() == 3.0 ) {
	for ( i = 0; i <  (int) nl.length(); i++ ) {
	    QDomElement el = nl.item(i).toElement();
	    QString s = el.attribute( "name" );
	    if ( s == "resizeable" ) {
		el.removeAttribute( "name" );
		el.setAttribute( "name", "resizable" );
	    }
	}
	return;
    }


    // in versions smaller than 3.0 we need to change more
    e.setAttribute( "version", 3.0 );

    e.setAttribute("stdsetdef", 1 );
    for ( i = 0; i <  (int) nl.length(); i++ ) {
	e = nl.item(i).toElement();
	QString name;
	QDomElement n2 = e.firstChild().toElement();
	if ( n2.tagName() == "name" ) {
	    name = n2.firstChild().toText().data();
	    if ( name == "resizeable" )
		e.setAttribute( "name", "resizable" );
	    else
		e.setAttribute( "name", name );
	    e.removeChild( n2 );
	}
	bool stdset = toBool( e.attribute( "stdset" ) );
	if ( stdset || name == "toolTip" || name == "whatsThis" ||
	     name == "buddy" ||
	     e.parentNode().toElement().tagName() == "item" ||
	     e.parentNode().toElement().tagName() == "spacer" ||
	     e.parentNode().toElement().tagName() == "column"
	     )
	    e.removeAttribute( "stdset" );
	else
	    e.setAttribute( "stdset", 0 );
    }

    nl = doc.elementsByTagName( "attribute" );
    for ( i = 0; i <  (int) nl.length(); i++ ) {
	e = nl.item(i).toElement();
	QString name;
	QDomElement n2 = e.firstChild().toElement();
	if ( n2.tagName() == "name" ) {
	    name = n2.firstChild().toText().data();
	    e.setAttribute( "name", name );
	    e.removeChild( n2 );
	}
    }

    nl = doc.elementsByTagName( "image" );
    for ( i = 0; i <  (int) nl.length(); i++ ) {
	e = nl.item(i).toElement();
	QString name;
	QDomElement n2 = e.firstChild().toElement();
	if ( n2.tagName() == "name" ) {
	    name = n2.firstChild().toText().data();
	    e.setAttribute( "name", name );
	    e.removeChild( n2 );
	}
    }

    nl = doc.elementsByTagName( "widget" );
    for ( i = 0; i <  (int) nl.length(); i++ ) {
	e = nl.item(i).toElement();
	QString name;
	QDomElement n2 = e.firstChild().toElement();
	if ( n2.tagName() == "class" ) {
	    name = n2.firstChild().toText().data();
	    e.setAttribute( "class", name );
	    e.removeChild( n2 );
	}
    }

}
void QgsProjectFileTransform::transform1800to1900()
{
  if ( mDom.isNull() )
  {
    return;
  }

  QDomNodeList layerItemList = mDom.elementsByTagName( "rasterproperties" );
  for ( int i = 0; i < layerItemList.size(); ++i )
  {
    QDomElement rasterPropertiesElem = layerItemList.at( i ).toElement();
    QDomNode layerNode = rasterPropertiesElem.parentNode();
    QDomElement dataSourceElem = layerNode.firstChildElement( "datasource" );
    QDomElement layerNameElem = layerNode.firstChildElement( "layername" );
    QgsRasterLayer rasterLayer;
    // TODO: We have to use more data from project file to read the layer it correctly,
    // OTOH, we should not read it until it was converted
    rasterLayer.readXML( layerNode );
    convertRasterProperties( mDom, layerNode, rasterPropertiesElem, &rasterLayer );
  }

  //composer: replace mGridAnnotationPosition with mLeftGridAnnotationPosition & co.
  // and mGridAnnotationDirection with mLeftGridAnnotationDirection & co.
  QDomNodeList composerMapList = mDom.elementsByTagName( "ComposerMap" );
  for ( int i = 0; i < composerMapList.size(); ++i )
  {
    QDomNodeList gridList = composerMapList.at( i ).toElement().elementsByTagName( "Grid" );
    for ( int j = 0; j < gridList.size(); ++j )
    {
      QDomNodeList annotationList = gridList.at( j ).toElement().elementsByTagName( "Annotation" );
      for ( int k = 0; k < annotationList.size(); ++k )
      {
        QDomElement annotationElem = annotationList.at( k ).toElement();

        //position
        if ( annotationElem.hasAttribute( "position" ) )
        {
          int pos = annotationElem.attribute( "position" ).toInt();
          annotationElem.setAttribute( "leftPosition", pos );
          annotationElem.setAttribute( "rightPosition", pos );
          annotationElem.setAttribute( "topPosition", pos );
          annotationElem.setAttribute( "bottomPosition", pos );
          annotationElem.removeAttribute( "position" );
        }

        //direction
        if ( annotationElem.hasAttribute( "direction" ) )
        {
          int dir = annotationElem.attribute( "direction" ).toInt();
          if ( dir == 2 )
          {
            annotationElem.setAttribute( "leftDirection", 0 );
            annotationElem.setAttribute( "rightDirection", 0 );
            annotationElem.setAttribute( "topDirection", 1 );
            annotationElem.setAttribute( "bottomDirection", 1 );
          }
          else if ( dir == 3 )
          {
            annotationElem.setAttribute( "leftDirection", 1 );
            annotationElem.setAttribute( "rightDirection", 1 );
            annotationElem.setAttribute( "topDirection", 0 );
            annotationElem.setAttribute( "bottomDirection", 0 );
          }
          else
          {
            annotationElem.setAttribute( "leftDirection", dir );
            annotationElem.setAttribute( "rightDirection", dir );
            annotationElem.setAttribute( "topDirection", dir );
            annotationElem.setAttribute( "bottomDirection", dir );
          }
          annotationElem.removeAttribute( "direction" );
        }
      }
    }
  }

  QgsDebugMsg( mDom.toString() );
}
bool DrugDrugInteraction::updateDomElement(QDomElement *element, QDomDocument *doc) const
{
    if (element->tagName()!="DDI")
        return false;
    element->setAttribute("i1", m_Data.value(FirstInteractorName).toString());
    element->setAttribute("i2", m_Data.value(SecondInteractorName).toString());
    element->setAttribute("i1ra", m_Data.value(FirstInteractorRouteOfAdministrationIds).toStringList().join(";"));
    element->setAttribute("i2ra", m_Data.value(SecondInteractorRouteOfAdministrationIds).toStringList().join(";"));
    element->setAttribute("l", m_Data.value(LevelCode).toString());
    element->setAttribute("a", m_Data.value(DateCreation).toString());
    element->setAttribute("lu", m_Data.value(DateLastUpdate).toString());
    element->setAttribute("v", m_Data.value(IsValid).toInt());
    element->setAttribute("rv", m_Data.value(IsReviewed).toInt());
    element->setAttribute("p", m_Data.value(PMIDsStringList).toStringList().join(";"));

    // Update risk
    QDomElement riskNode = element->firstChildElement("R");
    if (riskNode.isNull()) {
        // create risk
        QDomElement rFr = doc->createElement("R");
        rFr.setAttribute("l", "fr");
        rFr.setAttribute("t", risk("fr"));
        element->appendChild(rFr);
        QDomElement rEn = doc->createElement("R");
        rEn.setAttribute("l", "en");
        rEn.setAttribute("t", risk("en"));
        element->appendChild(rEn);
    } else {
        if (riskNode.attribute("l").compare("fr",Qt::CaseInsensitive)==0) {
            riskNode.setAttribute("t", risk("fr"));
            QDomElement rEn = riskNode.nextSiblingElement("R");
            if (rEn.isNull()) {
                rEn = doc->createElement("R");
                rEn.setAttribute("l", "en");
                element->appendChild(rEn);
            }
            rEn.setAttribute("t", risk("en"));
        } else if (riskNode.attribute("l").compare("en",Qt::CaseInsensitive)==0) {
            riskNode.setAttribute("t", risk("en"));
            QDomElement rFr = riskNode.nextSiblingElement("R");
            if (rFr.isNull()) {
                rFr = doc->createElement("R");
                rFr.setAttribute("l", "fr");
                element->appendChild(rFr);
            }
            rFr.setAttribute("t", risk("fr"));
        }
    }

    // Update management
    QDomElement manNode = element->firstChildElement("M");
    if (manNode.isNull()) {
        // create management
        QDomElement rFr = doc->createElement("M");
        rFr.setAttribute("l", "fr");
        rFr.setAttribute("t", management("fr"));
        element->appendChild(rFr);
        QDomElement rEn = doc->createElement("M");
        rEn.setAttribute("l", "en");
        rEn.setAttribute("t", management("en"));
        element->appendChild(rEn);
    } else {
        if (manNode.attribute("l").compare("fr",Qt::CaseInsensitive)==0) {
            manNode.setAttribute("t", management("fr"));
            QDomElement rEn = manNode.nextSiblingElement("M");
            if (rEn.isNull()) {
                rEn = doc->createElement("R");
                rEn.setAttribute("l", "en");
                element->appendChild(rEn);
            }
            rEn.setAttribute("t", management("en"));
        } else if (manNode.attribute("l").compare("en",Qt::CaseInsensitive)==0) {
            manNode.setAttribute("t", risk("en"));
            QDomElement rFr = manNode.nextSiblingElement("M");
            if (rFr.isNull()) {
                rFr = doc->createElement("R");
                rFr.setAttribute("l", "fr");
                element->appendChild(rFr);
            }
            rFr.setAttribute("t", management("fr"));
        }
    }

    // Update doses
//    QDomElement dose = element.firstChildElement("D");
//    while (!dose.isNull()) {
//        DrugDrugInteractionDose *ddidose = 0;
//        if (dose.attribute("i") == "1") {
//            ddidose = &m_FirstDose;
//        } else {
//            ddidose = &m_SecondDose;
//        }
//        if (dose.attribute("uf").toInt()==1) {
//            ddidose->setData(DrugDrugInteractionDose::UsesFrom, true);
//            ddidose->setData(DrugDrugInteractionDose::FromValue , dose.attribute("fv"));
//            ddidose->setData(DrugDrugInteractionDose::FromUnits, dose.attribute("fu"));
//            ddidose->setData(DrugDrugInteractionDose::FromRepartition , dose.attribute("fr"));
//        } else if (dose.attribute("ut").toInt()==1) {
//            ddidose->setData(DrugDrugInteractionDose::UsesTo, true);
//            ddidose->setData(DrugDrugInteractionDose::ToValue , dose.attribute("tv"));
//            ddidose->setData(DrugDrugInteractionDose::ToUnits, dose.attribute("tu"));
//            ddidose->setData(DrugDrugInteractionDose::ToRepartition , dose.attribute("tr"));
//        }
//        dose = dose.nextSiblingElement("D");
//    }

    // Update formalized risk
    QDomElement formNode = element->firstChildElement("F");
    if (!formNode.isNull()) {
        QDomNamedNodeMap attributeMap = formNode.attributes();
        for(int i=0; i < attributeMap.size(); ++i) {
            formNode.removeAttribute(attributeMap.item(i).nodeName());
        }
    }
    if (m_Formalized.count() > 0) {
        QHashIterator<QString,QString> i(m_Formalized);
        while (i.hasNext()) {
            i.next();
            formNode.setAttribute(i.key(), i.value());
        }
    }
    return true;
}
Example #22
0
int main(int argc, char *argv[])
{
	qInstallMsgHandler(myMessageHandler);
	QCoreApplication app(argc, argv);

	if (argc != 3)
	{
		qCritical("Usage: autotranslate <destination-dir> <source-dir>.");
		return -1;
	}

	QDir dstDir(app.arguments().value(1));
	if (!dstDir.exists())
	{
		qCritical("Destination directory '%s' not found.",dstDir.dirName().toLocal8Bit().constData());
		return -1;
	}

	QDir srcDir(app.arguments().value(2),"*.ts",QDir::Name,QDir::Files);
	if (!srcDir.exists())
	{
		qCritical("Source directory '%s' not found.",srcDir.dirName().toLocal8Bit().constData());
		return -1;
	}

	QDirIterator srcIt(srcDir);
	while (srcIt.hasNext())
	{
		QFile srcFile(srcIt.next());
		if (srcFile.open(QFile::ReadOnly))
		{
			QDomDocument doc;
			if (doc.setContent(&srcFile,true))
			{
				qDebug("Generation auto translation from '%s'.",srcFile.fileName().toLocal8Bit().constData());

				QDomElement rootElem = doc.firstChildElement("TS");
				rootElem.setAttribute("language",rootElem.attribute("sourcelanguage","en"));
				
				QDomElement contextElem = rootElem.firstChildElement("context");
				while(!contextElem.isNull())
				{
					QDomElement messageElem = contextElem.firstChildElement("message");
					while(!messageElem.isNull())
					{
						QDomElement sourceElem = messageElem.firstChildElement("source");
						QDomElement translationElem = messageElem.firstChildElement("translation");
						if (!sourceElem.isNull() && !translationElem.isNull())
						{
							QString sourceText = sourceElem.text();
							if (messageElem.attribute("numerus") == "yes")
							{
								QDomElement numerusEelem = translationElem.firstChildElement("numerusform");
								while(!numerusEelem.isNull())
								{
									numerusEelem.removeChild(numerusEelem.firstChild());
									numerusEelem.appendChild(doc.createTextNode(sourceText));
									numerusEelem = numerusEelem.nextSiblingElement("numerusform");
								}
							}
							else
							{
								translationElem.removeChild(translationElem.firstChild());
								translationElem.appendChild(doc.createTextNode(sourceText));
							}
							translationElem.removeAttribute("type");
						}
						messageElem = messageElem.nextSiblingElement("message");
					}
					contextElem = contextElem.nextSiblingElement("context");
				}
				srcFile.close();

				QFileInfo srcFileInfo(srcDir.absoluteFilePath(srcFile.fileName()));
				QFile dstFile(dstDir.absoluteFilePath(srcFileInfo.fileName()));
				if (dstFile.open(QFile::WriteOnly|QFile::Truncate))
				{
					dstFile.write(doc.toByteArray());
					dstFile.close();
				}
				else
				{
					qWarning("Failed to open destination file '%s' for write.",dstFile.fileName().toLocal8Bit().constData());
				}
			}
			else
			{
				qWarning("Invalid translation source file '%s'.",srcFile.fileName().toLocal8Bit().constData());
			}
			srcFile.close();
		}
		else
		{
			qWarning("Could not open translation source file '%s'.",srcFile.fileName().toLocal8Bit().constData());
		}
	}
	return 0;
}