コード例 #1
0
ファイル: instrtemplate.cpp プロジェクト: Mistobaan/MuseScore
static QString parseInstrName(const QString& name)
      {
      QString sName;
      QDomDocument dom;
      int line, column;
      QString err;
      if (!dom.setContent(name, false, &err, &line, &column)) {
            QString col, ln;
            col.setNum(column);
            ln.setNum(line);
            QString error = err + "\n at line " + ln + " column " + col;
            qDebug("error: %s\n", qPrintable(error));
            qDebug("   data:<%s>\n", qPrintable(name));
            return QString();
            }

      for (QDomNode e = dom.documentElement(); !e.isNull(); e = e.nextSiblingElement()) {
            for (QDomNode ee = e.firstChild(); !ee.isNull(); ee = ee.nextSibling()) {
                  QDomElement el = ee.toElement();
                  const QString& tag(el.tagName());
                  if (tag == "symbol") {
                        QString name = el.attribute(QString("name"));
                        if (name == "flat")
                              sName += "b";
                        else if (name == "sharp")
                              sName += "#";
                        }
                  QDomText t = ee.toText();
                  if (!t.isNull())
                        sName += t.data();
                  }
            }
      return sName;
      }
コード例 #2
0
/**
   Get the project title

   XML in file has this form:
\verbatim
   <qgis projectname="default project">
   <title>a project title</title>
\endverbatim

   @todo XXX we should go with the attribute xor title, not both.
*/
static void _getTitle( QDomDocument const &doc, QString & title )
{
  QDomNodeList nl = doc.elementsByTagName( "title" );

  title = "";                 // by default the title will be empty

  if ( !nl.count() )
  {
    QgsDebugMsg( "unable to find title element" );
    return;
  }

  QDomNode titleNode = nl.item( 0 );  // there should only be one, so zeroth element ok

  if ( !titleNode.hasChildNodes() ) // if not, then there's no actual text
  {
    QgsDebugMsg( "unable to find title element" );
    return;
  }

  QDomNode titleTextNode = titleNode.firstChild();  // should only have one child

  if ( !titleTextNode.isText() )
  {
    QgsDebugMsg( "unable to find title element" );
    return;
  }

  QDomText titleText = titleTextNode.toText();

  title = titleText.data();

} // _getTitle
コード例 #3
0
ファイル: converter.cpp プロジェクト: KDE/okular
bool Converter::convertLink( QTextCursor *cursor, const QDomElement &element, const QTextCharFormat &format )
{
  int startPosition = cursor->position();

  QDomNode child = element.firstChild();
  while ( !child.isNull() ) {
    if ( child.isElement() ) {
      const QDomElement childElement = child.toElement();
      if ( childElement.tagName() == QLatin1String( "span" ) ) {
        if ( !convertSpan( cursor, childElement, format ) )
          return false;
      }
    } else if ( child.isText() ) {
      const QDomText childText = child.toText();
      if ( !convertTextNode( cursor, childText, format ) )
        return false;
    }

    child = child.nextSibling();
  }

  int endPosition = cursor->position();

  Okular::Action *action = new Okular::BrowseAction( QUrl(element.attribute( QStringLiteral("href") )) );
  emit addAction( action, startPosition, endPosition );

  return true;
}
コード例 #4
0
ファイル: converter.cpp プロジェクト: KDE/okular
bool Converter::convertHeader( QTextCursor *cursor, const QDomElement &element )
{
  const QString styleName = element.attribute( QStringLiteral("style-name") );
  const StyleFormatProperty property = mStyleInformation->styleProperty( styleName );

  QTextBlockFormat blockFormat;
  QTextCharFormat textFormat;
  property.applyBlock( &blockFormat );
  property.applyText( &textFormat );

  cursor->setBlockFormat( blockFormat );

  QDomNode child = element.firstChild();
  while ( !child.isNull() ) {
    if ( child.isElement() ) {
      const QDomElement childElement = child.toElement();
      if ( childElement.tagName() == QLatin1String( "span" ) ) {
        if ( !convertSpan( cursor, childElement, textFormat ) )
          return false;
      }
    } else if ( child.isText() ) {
      const QDomText childText = child.toText();
      if ( !convertTextNode( cursor, childText, textFormat ) )
        return false;
    }

    child = child.nextSibling();
  }

  emit addTitle( element.attribute( QStringLiteral("outline-level"), QStringLiteral("0") ).toInt(), element.text(), cursor->block() );

  return true;
}
コード例 #5
0
ファイル: converter.cpp プロジェクト: madnight/chessx
bool Converter::convertLink(QTextCursor *cursor, const QDomElement &element, const QTextCharFormat &format)
{
    int startPosition = cursor->position();

    QDomNode child = element.firstChild();
    while (!child.isNull())
    {
        if (child.isElement())
        {
            const QDomElement childElement = child.toElement();
            if (childElement.tagName() == QLatin1String("span"))
            {
                if (!convertSpan(cursor, childElement, format))
                    return false;
            }
        }
        else if (child.isText())
        {
            const QDomText childText = child.toText();
            if (!convertTextNode(cursor, childText, format))
                return false;
        }

        child = child.nextSibling();
    }

    int endPosition = cursor->position();
    USETODONEXT(endPosition);
    USETODONEXT(startPosition);
    return true;
}
コード例 #6
0
ファイル: QXmppServer.cpp プロジェクト: unisontech/qxmpp
static void helperToXmlAddDomElement(QXmlStreamWriter* stream, const QDomElement& element, const QStringList &omitNamespaces)
{
    stream->writeStartElement(element.tagName());

    /* attributes */
    QString xmlns = element.namespaceURI();
    if (!xmlns.isEmpty() && !omitNamespaces.contains(xmlns))
        stream->writeAttribute("xmlns", xmlns);
    QDomNamedNodeMap attrs = element.attributes();
    for (int i = 0; i < attrs.size(); i++)
    {
        QDomAttr attr = attrs.item(i).toAttr();
        stream->writeAttribute(attr.name(), attr.value());
    }

    /* children */
    QDomNode childNode = element.firstChild();
    while (!childNode.isNull())
    {
        if (childNode.isElement())
        {
            helperToXmlAddDomElement(stream, childNode.toElement(), QStringList() << xmlns);
        } else if (childNode.isText()) {
            stream->writeCharacters(childNode.toText().data());
        }
        childNode = childNode.nextSibling();
    }
    stream->writeEndElement();
}
コード例 #7
0
ファイル: qxmlsettings.cpp プロジェクト: gbrault/firtool
//! function
static bool nodeToVariant(const QDomNode &aNode,QVariant &aValue) {
    bool vRetval = false;
    QString vType, vValue;

    aValue = QVariant();
    if(!vRetval && aNode.isCDATASection()) {
        vValue = aNode.toCDATASection().data();
        vRetval = true;
    }

    if(!vRetval && aNode.isText()) {
        vValue = aNode.toText().data();
        vRetval = true;
    }

    if(!vRetval) return vRetval;
    if(vValue.isEmpty()) return false; // ????

    const QDomNode vParent = aNode.parentNode();
    if(vParent.isElement()) {
        vType = vParent.toElement().attribute(QString::fromLatin1("type"));
    }

    if(vType == QString::fromLatin1("bytearray")) {
        aValue = QVariant(vValue.toLatin1());
    }
    else if(vType == QString::fromLatin1("variant")) {
        QByteArray vArray(vValue.toLatin1());
        QDataStream vStream(&vArray, QIODevice::ReadOnly);
        vStream >> aValue;
    }
コード例 #8
0
QDomText QDomNodeProto:: toText() const
{
  QDomNode *item = qscriptvalue_cast<QDomNode*>(thisObject());
  if (item)
    return item->toText();
  return QDomText();
}
コード例 #9
0
ファイル: main.cpp プロジェクト: Ryzh/voc
		word_t(const QDomNode& node) : valid(false)
									   , ticked(false)
													  , deflines(0)
	{
		QDomElement e = node.toElement();
		if (e.isNull() || e.tagName() != "Word")
			return;
		name = e.attribute("name", "");
		if (name.isEmpty())
			return;
		time = e.attribute("time", "");
		marks = e.attribute("marks", "").toInt();
		QDomNode n = node.firstChild();
		def = n.toText().data();
		def.remove("&nbsp;");
		int pos = def.indexOf('$', 0);
		while (pos >= 0)
		{
			def[pos] = '\n';
			deflines ++;
			pos = def.indexOf('$', pos+1);
		}

		if (def.isEmpty())
			return;
		valid = true;
	}
コード例 #10
0
ファイル: kwdwriter.cpp プロジェクト: KDE/calligra-history
QString KWDWriter::getText(const QDomElement &paragraph)
{
    QDomNode temp = paragraph.elementsByTagName("TEXT").item(0).firstChild();
    QDomText currentText = temp.toText();
    if (temp.isNull()) {
        kWarning(30503) << "no text";
    }
    return currentText.data();
}
コード例 #11
0
QString getTextFromNode(QDomNode* nodePtr) {
	QDomNode childNode = nodePtr->firstChild();
	while (!childNode.isNull()) {
		if (childNode.nodeType() == QDomNode::TextNode) {
			return childNode.toText().data().trimmed();
		}
		childNode = childNode.nextSibling();
	}
	return "";
}
コード例 #12
0
ファイル: klaid.cpp プロジェクト: rene-s/KdeLearningAid
void DomParser::_parseEntry(const QDomElement &element, int &l)
{
  if(ready2Parse==FALSE)
    return;

  QDomNode node = element.firstChild();
   
  // Block: only save *complete* o-t pairs
  // Drawback: o must be the first element of e. Is that a problem? We'll see.
  if (node.toElement().tagName() == "o") {
    QDomNode c = node.firstChild();
    if (c.nodeType() == QDomNode::TextNode)
    {
      l++;
    }
  }

  while (!node.isNull()) {
    if (node.toElement().tagName() == "e") {
      _parseEntry(node.toElement(), l);
    } else if (node.toElement().tagName() == "o") {
        QDomNode childNode = node.firstChild();
        while (!childNode.isNull()) {
          if (childNode.nodeType() == QDomNode::TextNode) {
            iTitles[l] = QString(childNode.toText().data());
            break;
          }
          childNode = childNode.nextSibling();
        }
    } else if (node.toElement().tagName() == "t") {
      QDomNode childNode = node.firstChild();
      while (!childNode.isNull()) 
      {
        if (childNode.nodeType() == QDomNode::TextNode && !iTitles[l].isEmpty()) {
          iTexts[l] = QString(childNode.toText().data());
          break;
        }
        childNode = childNode.nextSibling();
      }
    }
    node = node.nextSibling();
  }
}
コード例 #13
0
ファイル: xmltvparser.cpp プロジェクト: DocOnDev/mythtv
static QString getFirstText(QDomElement element)
{
    for (QDomNode dname = element.firstChild(); !dname.isNull();
         dname = dname.nextSibling())
    {
        QDomText t = dname.toText();
        if (!t.isNull())
            return t.data();
    }
    return QString();
}
コード例 #14
0
void SoftwareImporters::importJreepadFile(){
    typedef QPair<BasketScene *, QDomElement> basketAndElementPair;

    QString fileName = KFileDialog::getOpenFileName(KUrl("kfiledialog:///:ImportJreepadFile"),
                                                    "*.xml|XML files");
    if (fileName.isEmpty()) {
        return;
    }

    basketAndElementPair newElement;
    basketAndElementPair currentElement;
    QList<basketAndElementPair> elements;
    QList<BasketScene*> basketList;

    QDomDocument *doc = XMLWork::openFile("node", fileName);
    newElement.second = doc->documentElement();

    BasketScene *basket = 0;
    BasketFactory::newBasket(/*icon=*/"xml", /*name=*/doc->documentElement().attribute("title"), 
                             /*backgroundImage=*/"", /*backgroundColor=*/QColor(), 
                             /*textColor=*/QColor(), /*templateName=*/"1column", /*createIn=*/0);
    basket = Global::bnpView->currentBasket();
    basket->load();
    basketList << basket;
    newElement.first = basket;

    elements << newElement;

    while ( !elements.isEmpty() ) {
        currentElement = elements.takeFirst();
        for (QDomNode n = currentElement.second.firstChild(); !n.isNull(); n = n.nextSibling()) {
            if ( n.isText() ) {
                basket = currentElement.first;
                Note *note = NoteFactory::createNoteFromText(n.toText().data(), basket);
                basket->insertNote(note, basket->firstNote(), 
                                   Note::BottomColumn, QPoint(), /*animate=*/false);
            } else if ( n.isElement() ) {
                BasketFactory::newBasket(/*icon=*/"xml", /*name=*/n.toElement().attribute("title"), 
                                         /*backgroundImage=*/"", /*backgroundColor=*/QColor(), 
                                         /*textColor=*/QColor(), /*templateName=*/"1column", 
                                         /*createIn=*/currentElement.first);
                basket = Global::bnpView->currentBasket();
                basket->load();
                basketList << basket;
                newElement.first = basket;
                newElement.second = n.toElement();
                elements << newElement;
            }
        }
    }
    
    foreach (basket, basketList) {
        finishImport(basket);
    }
コード例 #15
0
ファイル: QtXmlWrapper.cpp プロジェクト: Supat609/zynaddsubfx
std::string QtXmlWrapper::getparstr(const std::string &name,
                                    const std::string &defaultpar) const
{
    QDomNode tmp = findElement( d->m_node, "string", "name", name.c_str() );
    if( tmp.isNull() || !tmp.hasChildNodes() )
    {
        return defaultpar;
    }

    tmp = tmp.firstChild();
    if( tmp.nodeType() == QDomNode::ElementNode && !tmp.toElement().tagName().isEmpty() )
    {
        return tmp.toElement().tagName().toUtf8().constData();
    }
    if( tmp.nodeType() == QDomNode::TextNode && !tmp.toText().data().isEmpty() )
    {
        return tmp.toText().data().toUtf8().constData();
    }

    return defaultpar;
}
コード例 #16
0
ファイル: xmpp_xmlcommon.cpp プロジェクト: studzien/iris
QString tagContent(const QDomElement &e)
{
	// look for some tag content
	for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
		QDomText i = n.toText();
		if(i.isNull())
			continue;
		return i.data();
	}

	return "";
}
コード例 #17
0
QString cDefinable::getNodeValue( const QDomElement &Tag )
{
	QString Value = QString();
	
	if( !Tag.hasChildNodes() )
		return "";
	else
	{
		QDomNode childNode = Tag.firstChild();
		while( !childNode.isNull() )
		{
			if( !childNode.isElement() )
			{
				if( childNode.isText() )
					Value += childNode.toText().data();
				childNode = childNode.nextSibling();
				continue;
			}
			QDomElement childTag = childNode.toElement();
			if( childTag.nodeName() == "random" )
			{
				if( childTag.attributes().contains("min") && childTag.attributes().contains("max") )
					Value += QString("%1").arg( RandomNum( childTag.attributeNode("min").nodeValue().toInt(), childTag.attributeNode("max").nodeValue().toInt() ) );
				else if( childTag.attributes().contains("valuelist") )
				{
					QStringList RandValues = QStringList::split(",", childTag.attributeNode("list").nodeValue());
					Value += RandValues[ RandomNum(0,RandValues.size()-1) ];
				}
				else if( childTag.attributes().contains( "list" ) )
				{
					Value += DefManager->getRandomListEntry( childTag.attribute( "list" ) );
				}
				else if( childTag.attributes().contains("dice") )
					Value += QString("%1").arg(rollDice(childTag.attributeNode("dice").nodeValue()));
				else
					Value += QString("0");
			}

			// Process the childnodes
			QDomNodeList childNodes = childTag.childNodes();

			for( int i = 0; i < childNodes.count(); i++ )
			{
				if( !childNodes.item( i ).isElement() )
					continue;

				Value += this->getNodeValue( childNodes.item( i ).toElement() );
			}
			childNode = childNode.nextSibling();
		}
	}
	return hex2dec( Value );
}
コード例 #18
0
/**
 * Loads the <UML:CheckConstraint> XMI element.
 */
bool UMLCheckConstraint::load( QDomElement & element )
{
    QDomNode node = element.firstChild();

    QDomText checkConstraintText = node.toText();
    if ( checkConstraintText.isNull() )
        return false;

    m_CheckCondition = checkConstraintText.data();

    return true;
}
コード例 #19
0
ファイル: converter.cpp プロジェクト: KDE/okular
bool Converter::convertParagraph( QTextCursor *cursor, const QDomElement &element, const QTextBlockFormat &parentFormat, bool merge )
{
  const QString styleName = element.attribute( QStringLiteral("style-name") );
  const StyleFormatProperty property = mStyleInformation->styleProperty( styleName );

  QTextBlockFormat blockFormat( parentFormat );
  QTextCharFormat textFormat;
  property.applyBlock( &blockFormat );
  property.applyText( &textFormat );

  if ( merge )
    cursor->mergeBlockFormat( blockFormat );
  else
    cursor->setBlockFormat( blockFormat );

  QDomNode child = element.firstChild();
  while ( !child.isNull() ) {
    if ( child.isElement() ) {
      const QDomElement childElement = child.toElement();
      if ( childElement.tagName() == QLatin1String( "span" ) ) {
        if ( !convertSpan( cursor, childElement, textFormat ) )
          return false;
      } else if ( childElement.tagName() == QLatin1String( "tab" ) ) {
        mCursor->insertText( QStringLiteral("    ") );
      } else if ( childElement.tagName() == QLatin1String( "s" ) ) {
        QString spaces;
        spaces.fill( QLatin1Char(' '), childElement.attribute( QStringLiteral("c") ).toInt() );
        mCursor->insertText( spaces );
      } else if ( childElement.tagName() == QLatin1String( "frame" ) ) {
        if ( !convertFrame( childElement ) )
          return false;
      } else if ( childElement.tagName() == QLatin1String( "a" ) ) {
        if ( !convertLink( cursor, childElement, textFormat ) )
          return false;
      } else if ( childElement.tagName() == QLatin1String( "annotation" ) ) {
        if ( !convertAnnotation( cursor, childElement ) )
          return false;
      }
    } else if ( child.isText() ) {
      const QDomText childText = child.toText();
      if ( !convertTextNode( cursor, childText, textFormat ) )
        return false;
    }

    child = child.nextSibling();
  }

  return true;
}
コード例 #20
0
ファイル: select1.cpp プロジェクト: cornelius/kode
void Select1::saveData()
{
  kDebug() <<"Select1::saveData()";
  kDebug() << ref().toString();
  kDebug() <<"Context:" << context().nodeName();
  Reference::Segment s;
  if( ref().segments().size() > 0 )
    s = ref().segments().last();

  QString txt;
  if( mProperties->appearance == Full ) {
    for( int i = 0; i < mRadioButtons.size() && i < mValues.size(); ++i ) {
      if( mRadioButtons[i]->isChecked() ) {
        txt = mValues[ i ];
        break;
      }
    }
  } else if( mProperties->appearance == Compact ) {
    if( mListWidget->currentRow() < mValues.size() )
      txt = mValues[ mListWidget->currentRow() ];
  } else { 
    if( mComboBox->currentIndex() < mValues.size() )
      txt = mValues[ mComboBox->currentIndex() ];
  }

  if ( s.isAttribute() ) {
    context().setAttribute( s.name(), txt );
  } else {
    QDomElement e = ref().applyElement( context() );
    if ( e.isNull() ) {
      e = createElement( ref() );
    }
    QDomNode n = e.firstChild();
    if( n.isNull() ) {
      n = mManager->document().createElement( txt );
      e.appendChild( n );
    }
    else {
      if( n.isText() ) {
        QDomText t = n.toText();
        t.setData( txt );
      } else if( n.isElement() ){
        n.toElement().setTagName( txt );
      }
    }
  }
}
コード例 #21
0
ファイル: converter.cpp プロジェクト: madnight/chessx
bool Converter::convertSpan(QTextCursor *cursor, const QDomElement &element, const QTextCharFormat &format)
{
    const QString styleName = element.attribute("style-name");
    const StyleFormatProperty property = m_StyleInformation->styleProperty(styleName);

    QTextCharFormat textFormat(format);
    property.applyText(&textFormat);

    QDomNode child = element.firstChild();
    while (!child.isNull())
    {
        //// search <text:s/> 
        if (child.isText())
        {
            const QDomText childText = child.toText();
            if (!convertTextNode(cursor, childText, textFormat))
                return false;
        }
        else if (child.isElement())
        {
            const QDomElement childElement = child.toElement();
            if (childElement.tagName() == QLatin1String("tab"))
            {
                cursor->insertText("\t");
            }
            else if (childElement.tagName() == QLatin1String("s"))
            {
                QString spaces;
                spaces.fill(' ', childElement.attribute("c").toInt());
                cursor->insertText(spaces);
            }
            else if (childElement.tagName() == QLatin1String("frame"))
            {
                const int xpos = cursor->position();
                m_Cursor->setPosition(xpos, QTextCursor::MoveAnchor);
                if (!convertFrame(childElement))
                {
                    return false;
                }
            }
        }
        child = child.nextSibling();
    }

    return true;
}
コード例 #22
0
ファイル: XmlFile.cpp プロジェクト: jsoutherland/CereLink
// Author & Date: Ehsan Azar       15 June 2010
// Purpose: Get current node value
// Inputs:
//   val - the default value
QVariant XmlFile::value(const QVariant & val)
{
    QVariant res = val;

    if (!m_nodes.isEmpty())
    {
        // Get the current node
        QDomElement node = m_nodes.last();
        if (!node.isNull())
        {
            // Array Type is how we distinguish lists
            if (node.attribute("Type").compare("Array", Qt::CaseInsensitive) == 0)
            {
                QVariantList varlist;
                QStringList keys = childKeys();
                for (int i = 0; i < keys.count(); ++i)
                {
                    QString key = keys[i];
                    if (i > 0 && key == keys[i - 1])
                        key = QString(key + "<%1>").arg(i);
                    // Recursively return the list
                    beginGroup(key);
                    QVariant nodevalue = value(QString());
                    endGroup();
                    // Make sure value is meaningful
                    if (nodevalue.isValid())
                        varlist += nodevalue; // add new value
                }
                if (!keys.isEmpty())
                    res = varlist;
            } else {
                QDomNode child = node.firstChild();
                if (!child.isNull())
                {
                    QDomText domText = child.toText();
                    if (!domText.isNull())
                        res = domText.data();
                    else
                        return toString();
                }
            }
        }
    }
    return res;
}
コード例 #23
0
ファイル: textregexp.cpp プロジェクト: KDE/kregexpeditor
bool TextRegExp::load( QDomElement top, const QString& /*version*/)
{
    Q_ASSERT( top.tagName() == QString::fromLocal8Bit( "Text" ) );
    if ( top.hasChildNodes() ) {
        QDomNode child = top.firstChild();
        if ( ! child.isText() ) {
            KMessageBox::sorry( 0, i18n("<p>Element <b>Text</b> did not contain any textual data.</p>"),
                                i18n("Error While Loading From XML File") ) ;
            return false;
        }
        QDomText txtNode = child.toText();
        _text = txtNode.data();
    } else {
        _text = QString::fromLatin1( "" );
    }

    return true;
}
コード例 #24
0
void ChartElemText::setTextNode(QDomElement& dom_element)
{
    QDomNode node = m_dom_element.firstChild();
    for(; !node.isNull(); node = node.nextSibling())
    {
        m_text_node = node.toText();
        if (!m_text_node.isNull()) break;
    }
    
    if (m_text_node.isNull())
    {
        QDomDocument dom_doc = dom_element.ownerDocument();
        m_text_node = dom_doc.createTextNode("");
        dom_element.appendChild(m_text_node);
    }

    MYASSERT(!m_text_node.isNull());
}
コード例 #25
0
ファイル: instrument.cpp プロジェクト: Archer90/MuseScore
static QTextDocumentFragment parseInstrName(const QString& name)
      {
      if (name.isEmpty())
            return QTextDocumentFragment();
      QTextDocument doc;
      QTextCursor cursor(&doc);
      QTextCharFormat f = cursor.charFormat();
      QTextCharFormat sf(f);

      QFont font("MScore1");
      sf.setFont(font);

      QDomDocument dom;
      int line, column;
      QString err;
      if (!dom.setContent(name, false, &err, &line, &column)) {
            QString col, ln;
            col.setNum(column);
            ln.setNum(line);
            QString error = err + "\n at line " + ln + " column " + col;
            qDebug("parse instrument name: %s\n", qPrintable(error));
            qDebug("   data:<%s>\n", qPrintable(name));
            return QTextDocumentFragment();
            }

      for (QDomNode e = dom.documentElement(); !e.isNull(); e = e.nextSibling()) {
            for (QDomNode ee = e.firstChild(); !ee.isNull(); ee = ee.nextSibling()) {
                  QDomElement de1 = ee.toElement();
                  QString tag(de1.tagName());
                  if (tag == "symbol") {
                        QString name = de1.attribute(QString("name"));
                        if (name == "flat")
                              cursor.insertText(QString(0xe10d), sf);
                        else if (name == "sharp")
                              cursor.insertText(QString(0xe10c), sf);
                        }
                  QDomText t = ee.toText();
                  if (!t.isNull())
                        cursor.insertText(t.data(), f);
                  }
            }
      return QTextDocumentFragment(&doc);
      }
コード例 #26
0
ファイル: xml.cpp プロジェクト: gthomas/MuseScore
void Xml::htmlToString(QDomElement e, int level, QString* s)
      {
      *s += QString("<%1").arg(e.tagName());
      QDomNamedNodeMap map = e.attributes();
      int n = map.size();
      for (int i = 0; i < n; ++i) {
            QDomAttr a = map.item(i).toAttr();
            *s += QString(" %1=\"%2\"").arg(a.name()).arg(a.value());
            }
      *s += ">";
      ++level;
      for (QDomNode ee = e.firstChild(); !ee.isNull(); ee = ee.nextSibling()) {
            if (ee.nodeType() == QDomNode::ElementNode)
                  htmlToString(ee.toElement(), level, s);
            else if (ee.nodeType() == QDomNode::TextNode)
                  *s += Qt::escape(ee.toText().data());
            }
      *s += QString("</%1>").arg(e.tagName());
      --level;
      }
コード例 #27
0
ファイル: converter.cpp プロジェクト: KDE/okular
bool Converter::convertSpan( QTextCursor *cursor, const QDomElement &element, const QTextCharFormat &format )
{
  const QString styleName = element.attribute( QStringLiteral("style-name") );
  const StyleFormatProperty property = mStyleInformation->styleProperty( styleName );

  QTextCharFormat textFormat( format );
  property.applyText( &textFormat );

  QDomNode child = element.firstChild();
  while ( !child.isNull() ) {
    if ( child.isText() ) {
      const QDomText childText = child.toText();
      if ( !convertTextNode( cursor, childText, textFormat ) )
        return false;
    }

    child = child.nextSibling();
  }

  return true;
}
コード例 #28
0
ファイル: QtXmlWrapper.cpp プロジェクト: Supat609/zynaddsubfx
void QtXmlWrapper::getparstr(const std::string &name, char *par, int maxstrlen) const
{
    ZERO(par, maxstrlen);
    QDomNode tmp = findElement( d->m_node, "string", "name", name.c_str() );
    if( tmp.isNull() || !tmp.hasChildNodes() )
    {
        return;
    }

    tmp = tmp.firstChild();
    if( tmp.nodeType() == QDomNode::ElementNode )
    {
        snprintf(par, maxstrlen, "%s", tmp.toElement().tagName().toUtf8().constData() );
        return;
    }
    if( tmp.nodeType() == QDomNode::TextNode )
    {
        snprintf(par, maxstrlen, "%s", tmp.toText().data().toUtf8().constData() );
        return;
    }
}
コード例 #29
0
ファイル: kwdwriter.cpp プロジェクト: KDE/calligra-history
void KWDWriter::addText(const QDomElement &paragraph, const QString& _text, int format_id, bool keep_formatting)
{
    QString text = _text;

    QDomNode temp = paragraph.elementsByTagName("TEXT").item(0).firstChild();
    QDomText currentText = temp.toText();
    if (temp.isNull()) {
        kDebug(30503) << "no text"; return;
    }
    QString oldtext = currentText.data();
    int oldLength = oldtext.length();
    if (keep_formatting) {
        if (oldLength) {
            ++oldLength;
            oldtext.append('\n');
        }
    } else {
        if (oldLength)
            ++oldLength; // add new trailing space char
        text = text.simplified(); // drop all unprintable chars
    }
    QString newtext;
    if (keep_formatting)
        newtext = oldtext + text;
    else {
        newtext = oldtext + ' ' + text;
        newtext = newtext.simplified(); // strip possible new space at beginning.
    }
    currentText.setData(newtext);
    int newLength = text.length();
    QDomElement lastformat = currentFormat(paragraph, true);
    if (lastformat.attribute("id").isEmpty()) // keep old id value, e.g. for LINK URL
        lastformat.setAttribute("id", format_id);
    lastformat.setAttribute("pos", QString("%1").arg(oldLength));
    lastformat.setAttribute("len", QString("%1").arg(newLength));
}
コード例 #30
0
void PMRaw::readAttributes( const PMXMLHelper& h )
{
   QDomNode e = h.element( ).firstChild( );
   if( e.isText( ) )
      m_code = e.toText( ).data( );
}