36 reader.enterContainer();
37 QString attribute_cvparam;
38 while(reader.hasNext())
41 qDebug() << attribute_cvparam;
42 if(attribute_cvparam ==
"cvRef")
46 else if(attribute_cvparam ==
"accession")
50 else if(attribute_cvparam ==
"name")
54 else if(attribute_cvparam ==
"value")
62 else if(reader.isUnsignedInteger())
64 valueInt = reader.toUnsignedInteger();
67 else if(reader.isInteger())
72 else if(reader.type() == QCborStreamReader::Type::String)
81 QObject::tr(
"cvParam value string failed for accession %1").arg(
accession));
87 QObject::tr(
"cvParam value type not known for accession %1").arg(
accession));
90 else if(attribute_cvparam ==
"unitAccession")
95 else if(attribute_cvparam ==
"unitCvRef")
99 else if(attribute_cvparam ==
"unitName")
109 reader.leaveContainer();
116 for(
auto &the_attribute : reader.attributes())
118 if(the_attribute.name() ==
"cvRef")
120 cvRef = the_attribute.value().toString();
122 else if(the_attribute.name() ==
"accession")
124 accession = the_attribute.value().toString();
126 else if(the_attribute.name() ==
"name")
128 name = the_attribute.value().toString();
130 else if(the_attribute.name() ==
"value")
132 valueStr = the_attribute.value().toString();
134 else if(the_attribute.name() ==
"unitCvRef")
136 unitCvRef = the_attribute.value().toString();
138 else if(the_attribute.name() ==
"unitAccession")
140 unitAccession = the_attribute.value().toString();
142 else if(the_attribute.name() ==
"unitName")
144 unitName = the_attribute.value().toString();
148 reader.readNextStartElement();
157 writer.append(
"cvRef");
158 writer.append(cvRef);
160 writer.append(
"accession");
161 writer.append(accession);
162 writer.append(
"name");
165 writer.append(
"value");
166 xmlValueToCbor(writer, valueStr);
168 if(!unitAccession.isEmpty())
170 writer.append(
"unitCvRef");
171 writer.append(unitCvRef);
172 writer.append(
"unitAccession");
173 writer.append(unitAccession);
174 writer.append(
"unitName");
175 writer.append(unitName);
181std::map<QString, pappso::cbor::mzcbor::CvParam>
185 std::map<QString, CvParam> accession_values;
186 reader.enterContainer();
188 while(reader.hasNext())
193 accession_values.insert({cv_param.
accession, cv_param});
196 reader.leaveContainer();
197 return accession_values;
205 valueStr = value_str;
212 writer.writeStartElement(
"cvParam");
214 writer.writeAttribute(
"cvRef", cvRef);
215 writer.writeAttribute(
"accession", accession);
218 if(cborType == QCborStreamReader::Type::Double)
220 valueStr = QString::number(valueDouble,
'g', 15);
222 else if(cborType == QCborStreamReader::Type::UnsignedInteger)
224 valueStr = QString(
"%1").arg(valueInt);
226 else if(cborType == QCborStreamReader::Type::NegativeInteger)
228 valueStr = QString(
"%1").arg(valueInt);
230 else if(cborType == QCborStreamReader::Type::String)
233 writer.writeAttribute(
"value", valueStr);
235 writer.writeAttribute(
"name", name);
237 if(!unitAccession.isEmpty())
239 writer.writeAttribute(
"unitAccession", unitAccession);
240 writer.writeAttribute(
"unitName", unitName);
241 writer.writeAttribute(
"unitCvRef", unitCvRef);
244 writer.writeEndElement();
250 const QStringView &value_str)
253 double d = value_str.toDouble(&ok);
256 if(value_str.contains(
'.'))
258 cborType = QCborStreamReader::Type::Double;
263 qint64 bigint = value_str.toLongLong(&ok);
266 cborType = QCborStreamReader::Type::NegativeInteger;
267 writer.append(bigint);
273 cborType = QCborStreamReader::Type::String;
274 writer.append(value_str);
bool decodeString(QString &the_str)
decode the current cbor value as a string the point to the next value the current value is decoded as...
PSI cvParam object for mzML/mzCBOR.
void fromCbor(CborStreamReader &reader)
QCborStreamReader::Type cborType
void setValue(const QString &value_str)
static std::map< QString, pappso::cbor::mzcbor::CvParam > getCvParamsMapFromCbor(CborStreamReader &reader)
void xmlValueToCbor(CborStreamWriter &writer, const QStringView &value_str)
void fromMzml(QXmlStreamReader &reader)
void toCbor(CborStreamWriter &writer)
void toMzml(QXmlStreamWriter &writer)