qmake/generators/xmloutput.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
    77 }
    77 }
    78 
    78 
    79 void XmlOutput::setState(XMLState state)
    79 void XmlOutput::setState(XMLState state)
    80 {
    80 {
    81     currentState = state;
    81     currentState = state;
       
    82 }
       
    83 
       
    84 void XmlOutput::setFormat(XMLFormat newFormat)
       
    85 {
       
    86     format = newFormat;
    82 }
    87 }
    83 
    88 
    84 XmlOutput::XMLState XmlOutput::state()
    89 XmlOutput::XMLState XmlOutput::state()
    85 {
    90 {
    86     return currentState;
    91     return currentState;
   170         addDeclaration(o.xo_text, o.xo_value);
   175         addDeclaration(o.xo_text, o.xo_value);
   171         break;
   176         break;
   172     case tTag:
   177     case tTag:
   173         newTagOpen(o.xo_text);
   178         newTagOpen(o.xo_text);
   174         break;
   179         break;
       
   180     case tTagValue:
       
   181         addRaw(QString("\n%1<%2>").arg(currentIndent).arg(o.xo_text));
       
   182         addRaw(QString("%1").arg(o.xo_value));
       
   183         addRaw(QString("</%1>").arg(o.xo_text));
       
   184         break;
       
   185     case tValueTag:
       
   186         addRaw(QString("%1").arg(doConversion(o.xo_text)));
       
   187         setFormat(NoNewLine);
       
   188         closeTag();
       
   189         setFormat(NewLine);
       
   190         break;
       
   191     case tImport:
       
   192         addRaw(QString("\n%1<Import %2=\"%3\" />").arg(currentIndent).arg(o.xo_text).arg(o.xo_value));
       
   193         break;
   175     case tCloseTag:
   194     case tCloseTag:
   176         if (o.xo_value.count())
   195         if (o.xo_value.count())
   177             closeAll();
   196             closeAll();
   178         else if (o.xo_text.count())
   197         else if (o.xo_text.count())
   179             closeTo(o.xo_text);
   198             closeTo(o.xo_text);
   180         else
   199         else
   181             closeTag();
   200             closeTag();
   182         break;
   201         break;
   183     case tAttribute:
   202     case tAttribute:
   184         addAttribute(o.xo_text, o.xo_value);
   203         addAttribute(o.xo_text, o.xo_value);
       
   204         break;
       
   205     case tAttributeTag:
       
   206         addAttributeTag(o.xo_text, o.xo_value);
   185         break;
   207         break;
   186     case tData:
   208     case tData:
   187         {
   209         {
   188             // Special case to be able to close tag in normal
   210             // Special case to be able to close tag in normal
   189             // way ("</tag>", not "/>") without using addRaw()..
   211             // way ("</tag>", not "/>") without using addRaw()..
   264                 xmlFile << endl << currentIndent;
   286                 xmlFile << endl << currentIndent;
   265             xmlFile << "</" << doConversion(tagStack.last()) << '>';
   287             xmlFile << "</" << doConversion(tagStack.last()) << '>';
   266             tagStack.pop_back();
   288             tagStack.pop_back();
   267             break;
   289             break;
   268         case Attribute:
   290         case Attribute:
   269             xmlFile << "/>";
   291             xmlFile << " />";
   270             tagStack.pop_back();
   292             tagStack.pop_back();
   271             currentState = Tag;
   293             currentState = Tag;
   272             decreaseIndent(); // <--- Post-decrease indent
   294             decreaseIndent(); // <--- Post-decrease indent
   273             break;
   295             break;
   274     }
   296     }
   305         case Attribute:
   327         case Attribute:
   306             //warn_msg(WarnLogic, "<%s>: Cannot add declaration when not in bare state", tagStack.last().toLatin1().constData());
   328             //warn_msg(WarnLogic, "<%s>: Cannot add declaration when not in bare state", tagStack.last().toLatin1().constData());
   307             qDebug("<%s>: Cannot add declaration when not in bare state", tagStack.last().toLatin1().constData());
   329             qDebug("<%s>: Cannot add declaration when not in bare state", tagStack.last().toLatin1().constData());
   308             return;
   330             return;
   309     }
   331     }
   310     QString outData = QString("<?xml version=\"%1\" encoding = \"%2\"?>")
   332     QString outData = QString("<?xml version=\"%1\" encoding=\"%2\"?>")
   311                               .arg(doConversion(version))
   333                               .arg(doConversion(version))
   312                               .arg(doConversion(encoding));
   334                               .arg(doConversion(encoding));
   313     addRaw(outData);
   335     addRaw(outData);
   314 }
   336 }
   315 
   337 
   335     if (format == NewLine)
   357     if (format == NewLine)
   336         xmlFile << endl;
   358         xmlFile << endl;
   337     xmlFile << currentIndent << doConversion(attribute) << "=\"" << doConversion(value) << "\"";
   359     xmlFile << currentIndent << doConversion(attribute) << "=\"" << doConversion(value) << "\"";
   338 }
   360 }
   339 
   361 
       
   362 void XmlOutput::addAttributeTag(const QString &attribute, const QString &value)
       
   363 {
       
   364      switch(currentState) {
       
   365         case Bare:
       
   366         case Tag:
       
   367             //warn_msg(WarnLogic, "<%s>: Cannot add attribute since tags not open", tagStack.last().toLatin1().constData());
       
   368             qDebug("<%s>: Cannot add attribute (%s) since tag's not open",
       
   369                    (tagStack.count() ? tagStack.last().toLatin1().constData() : "Root"),
       
   370                    attribute.toLatin1().constData());
       
   371             return;
       
   372         case Attribute:
       
   373             break;
       
   374     }
       
   375     xmlFile << " " << doConversion(attribute) << "=\"" << doConversion(value) << "\"";
       
   376 }
       
   377 
   340 QT_END_NAMESPACE
   378 QT_END_NAMESPACE