Ejemplo n.º 1
0
//! 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;
    }
Ejemplo n.º 2
0
QDomCDATASection QDomNodeProto:: toCDATASection() const
{
  QDomNode *item = qscriptvalue_cast<QDomNode*>(thisObject());
  if (item)
    return item->toCDATASection();
  return QDomCDATASection();
}
Ejemplo n.º 3
0
bool Ersky9xInterface::loadModelDataXML(QDomDocument * qdoc, ModelData *model, int modelNum, int stickMode)
{
  T ersky9xModel;
  memset(&ersky9xModel, 0, sizeof(ersky9xModel));

  //look for MODEL_DATA with modelNum attribute.
  //if modelNum = -1 then just pick the first one
  QDomNodeList ndl = qdoc->elementsByTagName("MODEL_DATA");

  //cycle through nodes to find correct model number
  QDomNode k = ndl.at(0);
  if (modelNum>=0) {
    while(!k.isNull()) {
      int a = k.toElement().attribute("number").toInt();
      if(a==modelNum)
        break;
      k = k.nextSibling();
    }
  }

  if (k.isNull()) // couldn't find
    return false;

  //load cdata into tgen
  QDomNode n = k.toElement().elementsByTagName("Data").at(0).firstChild();// get all children in Data
  while (!n.isNull()) {
    if (n.isCDATASection()) {
      QString ds = n.toCDATASection().data();
      QByteArray ba = QByteArray::fromBase64(ds.toAscii());
      const char * data = ba.data();
      memcpy(&ersky9xModel, data, std::min(ba.size(), (int)sizeof(ersky9xModel)));
      break;
    }
    n = n.nextSibling();
  }

  applyStickModeToModel(ersky9xModel, stickMode);
  *model = ersky9xModel;
  return true;
}
Ejemplo n.º 4
0
bool Ersky9xInterface::loadGeneralDataXML(QDomDocument * qdoc, Ersky9xGeneral * tgen)
{
  //look for "GENERAL_DATA" tag
  QDomElement gde = qdoc->elementsByTagName("GENERAL_DATA").at(0).toElement();

  if(gde.isNull()) // couldn't find
    return false;

  //load cdata into tgen
  QDomNode n = gde.elementsByTagName("Data").at(0).firstChild();// get all children in Data
  while (!n.isNull()) {
    if (n.isCDATASection()) {
      QString ds = n.toCDATASection().data();
      QByteArray ba = QByteArray::fromBase64(ds.toAscii());
      const char * data = ba.data();
      memcpy(tgen, data, std::min((unsigned int)ba.size(), (unsigned int)sizeof(Ersky9xGeneral)));
      break;
    }
    n = n.nextSibling();
  }
  //check version?
  return true;
}
Ejemplo n.º 5
0
bool ImageOptions::loadXmlElement(QDomElement element)
{
  bool result = false;

  auto readStringFromNode = [this](QDomElement element, const QString elementName, QString * result) {
    if (element.tagName() == elementName) {
      QDomNode dataNode = element.firstChild();

      if (dataNode.isCDATASection()) {
        QDomCDATASection cdataSection = dataNode.toCDATASection();
        QString strValue = cdataSection.data();
        *result = this->unescapeEmpty(strValue);
      } else {
        QString strValue = element.text();
        *result = this->unescapeEmpty(strValue);
      }
    }
  };


  QDomNode nodeSett = element.firstChild();

  while (!nodeSett.isNull()) {
    QDomElement e = nodeSett.toElement();

    if (e.tagName() == ImageOptions::GroupName) {
      break;
    }

    nodeSett = nodeSett.nextSibling();
  }

  if (nodeSett.isNull()) {
    return result;
  }

  quint32 uBytesOrder = 0, uBlockSize = 0, uBlockDefaultOnes = 0, uSplitToRows = 0;
  quint32 uCompressionRle = 0, uCompressionRleMinLength = 2;
  QString sBlockPrefix = "0x", sBlockSuffix, sBlockDelimiter = ", ";
  QString sPreviewPrefix, sPreviewSuffix, sPreviewDelimiter, sPreviewLevels;

  QDomNode nodeValue = nodeSett.firstChild();

  while (!nodeValue.isNull()) {
    QDomElement e = nodeValue.toElement();

    if (!e.isNull()) {
      if (e.tagName() == ImageOptions::FieldBlockSize) {
        QString str = e.text();
        uBlockSize = str.toUInt(&result);
      }

      if (e.tagName() == ImageOptions::FieldBytesOrder) {
        QString str = e.text();
        uBytesOrder = str.toUInt(&result);
      }

      if (e.tagName() == ImageOptions::FieldSplitToRows) {
        QString str = e.text();
        uSplitToRows = str.toUInt(&result);
      }

      if (e.tagName() == ImageOptions::FieldCompressionRle) {
        QString str = e.text();
        uCompressionRle = str.toUInt(&result);
      }

      if (e.tagName() == ImageOptions::FieldCompressionRleMinLength) {
        QString str = e.text();
        uCompressionRleMinLength = str.toUInt(&result);
      }

      if (e.tagName() == ImageOptions::FieldBlockDefaultOnes) {
        QString str = e.text();
        uBlockDefaultOnes = str.toUInt(&result);
      }

      readStringFromNode(e, ImageOptions::FieldBlockPrefix, &sBlockPrefix);
      readStringFromNode(e, ImageOptions::FieldBlockSuffix, &sBlockSuffix);
      readStringFromNode(e, ImageOptions::FieldBlockDelimiter, &sBlockDelimiter);
      readStringFromNode(e, ImageOptions::FieldPreviewPrefix, &sPreviewPrefix);
      readStringFromNode(e, ImageOptions::FieldPreviewSuffix, &sPreviewSuffix);
      readStringFromNode(e, ImageOptions::FieldPreviewDelimiter, &sPreviewDelimiter);
      readStringFromNode(e, ImageOptions::FieldPreviewLevels, &sPreviewLevels);

      if (!result) {
        break;
      }
    }

    nodeValue = nodeValue.nextSibling();
  }

  if (result) {
    this->setBlockSize((Parsing::Conversion::Options::DataBlockSize)uBlockSize);
    this->setBlockDefaultOnes((bool)uBlockDefaultOnes);
    this->setBytesOrder((Parsing::Conversion::Options::BytesOrder)uBytesOrder);
    this->setSplitToRows((bool)uSplitToRows);
    this->setCompressionRle((bool)uCompressionRle);
    this->setCompressionRleMinLength(uCompressionRleMinLength);
    this->setBlockPrefix(sBlockPrefix);
    this->setBlockSuffix(sBlockSuffix);
    this->setBlockDelimiter(sBlockDelimiter);
    this->setPreviewPrefix(sPreviewPrefix);
    this->setPreviewSuffix(sPreviewSuffix);
    this->setPreviewDelimiter(sPreviewDelimiter);
    this->setPreviewLevels(sPreviewLevels);
  }

  return result;
}