All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
QGpCoreTools::XMLHeader Class Reference

Brief description of class still missing. More...

#include <XMLHeader.h>

Inheritance diagram for QGpCoreTools::XMLHeader:
QGpCoreTools::XMLClass DinverCore::XMLDinverHeader

List of all members.

Public Member Functions

void addAlternateTag (const QString &t)
Error xml_restoreByteArray (QByteArray data, XMLContext *context=0)
Error xml_restoreFile (QString fileName, XMLContext *context=0, FileType ft=TarFile)
Error xml_restoreString (QString str, XMLContext *context=0)
QByteArray xml_saveByteArray (XMLContext *context=0) const
Error xml_saveFile (QString fileName, XMLContext *context=0, FileType ft=TarFile) const
QString xml_saveString (bool header=true, XMLContext *context=0) const
virtual const QString & xml_tagName () const
 XMLHeader (XMLClass *object)
 XMLHeader (const XMLHeader &o)

Static Public Attributes

static const QString xmlHeaderOldTag = "QtbXMLClass"
static const QString xmlHeaderTag = "GpXMLClass"

Protected Member Functions

virtual void xml_attributes (XML_ATTRIBUTES_ARGS) const
virtual XMLMember xml_member (XML_MEMBER_ARGS)
virtual void xml_polishChild (XML_POLISHCHILD_ARGS)
virtual bool xml_polished (XML_POLISHED_ARGS)
virtual bool xml_setAttributes (XML_SETATTRIBUTES_ARGS)
virtual void xml_writeChildren (XML_WRITECHILDREN_ARGS) const

Protected Attributes

XMLClass_object
bool _polished
QString _tag

Detailed Description

Brief description of class still missing.

This class is responsible of XML header: DOCTYPE and GpXMLClass context. GpXMLClass (or QtbXMLClass) context is kept only for compatibility with previous version. XML structures created with this version do not generate any specific header.


Constructor & Destructor Documentation

Description of constructor still missing.

version must be the version of the calling package (library or application).

References _object, _polished, _tag, and xmlHeaderTag.

    : XMLClass()
{
  _object=object;
  _polished=false;
  _tag=xmlHeaderTag;
}

References _object, _polished, and _tag.

  : XMLClass()
{
  _object=o._object;
  _polished=o._polished;
  _tag=o._tag;
  _alternateTags=o._alternateTags;
}

Member Function Documentation

void QGpCoreTools::XMLHeader::addAlternateTag ( const QString &  t) [inline]
void QGpCoreTools::XMLHeader::xml_attributes ( XML_ATTRIBUTES_ARGS  ) const [protected, virtual]

Reimplemented from QGpCoreTools::XMLClass.

{
  Q_UNUSED(context);
  Q_UNUSED(attributes);
  //attributes.add( "version", QGPCORETOOLS_VERSION);
}

Re-implement this function to offer XML restore (children and properties) support to your class.

From tag and map (with contains the attibute value) return a unique identifier under the format of a XMLMember. XMLMember is initialized with 3 types of contructors:

  • An integer: id number of a property
  • A XMLClass * : a child of this object identified by tag
  • Default constructor: error, unknow child or property

Map of attributes can be inspected in this way (can be achived also in xml_setProperty()):

    static const QString tmp("childrenName");
    XMLRestoreAttributeIterator it=map.find(tmp);
    if(it!=map.end()) {
      // found attribute "childrenName"
    }

If the map of attributes is not used:

    Q_UNUSED(attributes);
    if(tag=="x1") return XMLMember(0);
    else if(tag=="y1") return XMLMember(1);
    else if(tag=="x2") return XMLMember(2);
    else if(tag=="y2") return XMLMember(3);
    else return XMLMember(XMLMember::Unknown);

Arithmetic operations + and - apply to XMLMember to avoid confusion of property id numbers between inherited objects. Offset 3 corresponds to the number of properties defined in this object.

    if(tag=="anInteger") return XMLMember(0);
    else if(tag=="aString") return XMLMember(1);
    else if(tag=="aDouble") return XMLMember(2);
    return AbstractLine::xml_member(tag, attributes, context)+3;

For the arguments of this function use Macro XML_MEMBER_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

Reimplemented in DinverCore::XMLDinverHeader.

References _object, _tag, QGpCoreTools::XMLMember::Unknown, QGpCoreTools::XMLClass::xml_tagName(), xmlHeaderOldTag, and xmlHeaderTag.

{
  ASSERT(_object);
  Q_UNUSED(attributes);
  Q_UNUSED(context);
  if(tag==_object->xml_tagName()) {
    return XMLMember(_object);
  } else if(tag==xmlHeaderTag) {
    _tag=xmlHeaderTag;
    return XMLMember(this);
  } else if(tag==xmlHeaderOldTag) {
    _tag=xmlHeaderOldTag;
    return XMLMember(this);
  } else {
    for(QStringList::const_iterator it=_alternateTags.begin();it!=_alternateTags.end();it++) {
      if(tag==*it) return XMLMember(_object);
    }
    return XMLMember(XMLMember::Unknown);
  }
}

Reimplemented from QGpCoreTools::XMLClass.

Reimplemented in DinverCore::XMLDinverHeader.

References _object, and _polished.

{
  Q_UNUSED(context);
  if(child==_object) _polished=true;
}
virtual bool QGpCoreTools::XMLHeader::xml_polished ( XML_POLISHED_ARGS  ) [inline, protected, virtual]

Reimplemented from QGpCoreTools::XMLClass.

{return _polished;}

References QGpCoreTools::XMLClass::ErrorFileNotOpen, QGpCoreTools::XMLClass::ErrorNoDocType, QGpCoreTools::XMLByteArrayStream::file(), QGpCoreTools::XMLByteArrayStream::open(), and QGpCoreTools::XMLClass::restore().

Referenced by SciFigs::XMLSciFigs::restoreByteArray().

{
  QByteArray xmlArray;
  XMLByteArrayStream s(QIODevice::ReadOnly);
  if(!s.open(data) || !s.file("contents.xml", xmlArray)) {
    return ErrorFileNotOpen;
  }
  QTextStream xmlStream(xmlArray, QIODevice::ReadOnly);
  //xmlStream.setCodec("ISO-8859-1");
  xmlStream.setCodec("UTF-8");
  xmlStream.setAutoDetectUnicode (true);
  QString buf=xmlStream.readAll();
  int line=1;
  const QChar * ptr=buf.data();
  if(checkDocType(ptr, line))
    return restore(ptr, line, &s, context);
  else
    return ErrorNoDocType;
}
XMLClass::Error QGpCoreTools::XMLHeader::xml_restoreFile ( QString  fileName,
XMLContext context = 0,
FileType  ft = TarFile 
)

Open a file

References QGpCoreTools::endl(), QGpCoreTools::XMLClass::ErrorFileNotOpen, QGpCoreTools::XMLClass::ErrorNoDocType, QGpCoreTools::XMLTarStream::file(), QGpCoreTools::XMLTarStream::open(), QGpCoreTools::XMLClass::restore(), QGpCoreTools::App::stream(), QGpCoreTools::XMLClass::TarFile, and QGpCoreTools::tr().

Referenced by TargetMerge::execute(), TargetExtract::execute(), TargetAdd::execute(), DinverGui::importParameters(), DinverGui::importTargets(), ControlPanel::load(), ParamGroundModelWidget::load(), main(), MapProject::open(), GeopsyCore::SignalDB::open(), DinverGui::open(), SciFigs::XMLSciFigs::restoreFile(), Process::setArguments(), DinverCore::BatchRun::setParameters(), QGpGuiTools::ColumnTextWidget::setParserFile(), DinverCore::BatchRun::setTargets(), and CoordReader::terminate().

{
  XMLTarStream s(QIODevice::ReadOnly);
  if(s.open(fileName)) {
    QByteArray xmlArray;
    if(ft==TarFile && s.file( "contents.xml", xmlArray)) {
      QTextStream xmlStream(xmlArray, QIODevice::ReadOnly);
      //xmlStream.setCodec("ISO-8859-1");
      xmlStream.setCodec("UTF-8");
      xmlStream.setAutoDetectUnicode (true);
      QString buf=xmlStream.readAll();
      int line=1;
      const QChar * ptr=buf.data();
      if(checkDocType(ptr, line))
        return restore(ptr, line, &s, context);
      else
        return ErrorNoDocType;
    } else {  // check for compatibility with format before November 2006
      if(ft==TarFile) App::stream() << tr("No contents.xml found in archive, trying old versions...") << endl;
      QFile f (fileName);
      if(f.open(QIODevice::ReadOnly)) {
        QTextStream xmlStream(&f);
        //xmlStream.setCodec("ISO-8859-1");
        xmlStream.setCodec("UTF-8");
        xmlStream.setAutoDetectUnicode (true);
        QString buf=xmlStream.readAll();
        int line=1;
        const QChar * ptr=buf.data();
        if(checkDocType(ptr, line))
          return restore(ptr, line, &s, context);
        else
          return ErrorNoDocType;
      }
      return ErrorFileNotOpen;
    }
  }
  printf("File not open\n");
  return ErrorFileNotOpen;
}

References QGpCoreTools::XMLClass::ErrorNoDocType, and QGpCoreTools::XMLClass::restore().

Referenced by GeopsyCore::CustomFileFormats::CustomFileFormats(), SciFigs::XMLSciFigs::restoreString(), and QGpGuiTools::XMLItem::setText().

{
  int line=1;
  const QChar * ptr=buf.data();
  XMLStringStream s(QIODevice::ReadOnly);
  if(checkDocType(ptr, line))
    return restore(ptr, line, &s, context);
  else
    return ErrorNoDocType;
}
QByteArray QGpCoreTools::XMLHeader::xml_saveByteArray ( XMLContext context = 0) const

Create a QByteArray which contains the XML part and the attached files

References _object, QGpCoreTools::XMLByteArrayStream::addXmlFile(), QGpCoreTools::XMLByteArrayStream::data(), TRACE, QGpCoreTools::XMLClass::xml_attributes(), and QGpCoreTools::XMLClass::xml_save().

Referenced by QGpGuiTools::XMLItem::saveByteArray(), and SciFigs::XMLSciFigs::saveByteArray().

{
  TRACE;
  XMLByteArrayStream s(QIODevice::WriteOnly);
  //xml_saveDocType(s);
  XMLSaveAttributes attributes;
  _object->xml_attributes(attributes, context);
  _object->xml_save(s, context, attributes);
  s.addXmlFile();
  return s.data();
}
XMLClass::Error QGpCoreTools::XMLHeader::xml_saveFile ( QString  fileName,
XMLContext context = 0,
FileType  ft = TarFile 
) const

Create a compressed tar file for storing the xml part (contents.xml) and, if any, the binary parts (random names stored in xml part).

References _object, QGpCoreTools::XMLTarStream::addXmlFile(), QGpCoreTools::endl(), QGpCoreTools::XMLClass::ErrorFileNotOpen, QGpCoreTools::XMLClass::ErrorWritingFile, QGpCoreTools::XMLClass::NoError, QGpCoreTools::XMLTarStream::open(), QGpCoreTools::App::stream(), QGpCoreTools::XMLClass::TarFile, QGpCoreTools::XMLStringStream::toString(), QGpCoreTools::tr(), QGpCoreTools::XMLClass::xml_attributes(), and QGpCoreTools::XMLClass::xml_save().

Referenced by TargetMerge::execute(), TargetAdd::execute(), DinverGui::exportParameters(), DinverGui::exportTargets(), main(), Model2ParamReader::parse(), MapProject::save(), GeopsyCore::SignalDB::save(), ParamGroundModelWidget::save(), DinverGui::save(), MapProject::saveAs(), QGpGuiTools::XMLItem::saveFile(), SciFigs::XMLSciFigs::saveFile(), SpacSelector::saveSelection(), and SPACLoop::~SPACLoop().

{
  XMLSaveAttributes attributes;
  _object->xml_attributes(attributes, context);
  if(ft==TarFile) {
    XMLTarStream s (QIODevice::WriteOnly);
    if(s.open(fileName)) {
      //xml_saveDocType(s);
      _object->xml_save(s, context, attributes);
      if( !s.addXmlFile()) {
        App::stream() << tr("Cannot write to file %1.").arg(fileName) << endl;
        return ErrorWritingFile;
      }
      return NoError;
    } else {
      App::stream() << tr("Cannot open file %1 for writing.").arg(fileName) << endl;
      return ErrorFileNotOpen;
    }
  } else {
    QFile f(fileName);
    if(f.open(QIODevice::WriteOnly)) {
      XMLStringStream s (QIODevice::WriteOnly);
      //xml_saveDocType(s);
      _object->xml_save(s, context, attributes);
      QTextStream sf(&f);
      //sf.setCodec("ISO-8859-1");
      sf.setCodec("UTF-8");
      sf.setGenerateByteOrderMark (true);
      sf << s.toString();
      return NoError;
    } else {
      App::stream() << tr("Cannot open file %1 for writing.").arg(fileName) << endl;
      return ErrorFileNotOpen;
    }
  }
}
QString QGpCoreTools::XMLHeader::xml_saveString ( bool  header = true,
XMLContext context = 0 
) const

Create a QTextStream attached to the given QString and export XML data. No binary data can be saved this way.

References _object, QGpCoreTools::XMLStringStream::toString(), TRACE, QGpCoreTools::XMLClass::xml_attributes(), and QGpCoreTools::XMLClass::xml_save().

Referenced by GeopsyCore::CustomFileFormats::save(), QGpCoreTools::GoogleEarthKML::save(), QGpGuiTools::XMLItem::saveString(), and SciFigs::XMLSciFigs::saveString().

{
  TRACE;
  XMLStringStream s(QIODevice::WriteOnly);
  XMLSaveAttributes attributes;
  _object->xml_attributes(attributes, context);
  if(header) {
    //xml_saveDocType(s);
    _object->xml_save(s, context, attributes);
  } else {
    _object->xml_save(s, context, attributes);
  }
  return s.toString();
}

Reimplemented from QGpCoreTools::XMLClass.

{
  Q_UNUSED(context);
  for(XMLRestoreAttributeIterator it=attributes.begin(); it!= attributes.end(); it++ ) {
    const StringSection& att=it.key();
    if(att=="version") {} // compatibility
    else return false;
  }
  return true;
}
const QString & QGpCoreTools::XMLHeader::xml_tagName ( ) const [virtual]

Implements QGpCoreTools::XMLClass.

References _tag.

{
  return _tag;
}

Reimplemented from QGpCoreTools::XMLClass.

References _object, QGpCoreTools::XMLClass::xml_attributes(), and QGpCoreTools::XMLClass::xml_save().

{
  ASSERT(_object);
  XMLSaveAttributes att;
  _object->xml_attributes(att, context);
  _object->xml_save(s, context, att);
}

Member Data Documentation

QString QGpCoreTools::XMLHeader::_tag [protected]
const QString QGpCoreTools::XMLHeader::xmlHeaderOldTag = "QtbXMLClass" [static]

Referenced by xml_member().

const QString QGpCoreTools::XMLHeader::xmlHeaderTag = "GpXMLClass" [static]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines