MCPcopy Create free account
hub / github.com/Martchus/tageditor / applyChanges

Method applyChanges

cli/scriptapi.cpp:574–648  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

572}
573
574void TagObject::applyChanges()
575{
576 auto context = !m_tag.target().isEmpty() || m_tag.type() == TagParser::TagType::MatroskaTag
577 ? CppUtilities::argsToString(m_tag.typeName(), " targeting ", m_tag.targetString())
578 : std::string(m_tag.typeName());
579 m_diag.emplace_back(TagParser::DiagLevel::Information, "applying changes", std::move(context));
580 if (m_fields.isUndefined()) {
581 return;
582 }
583 const auto encoding = m_tag.proposedTextEncoding();
584 for (auto field = TagParser::firstKnownField; field != TagParser::KnownField::Invalid; field = TagParser::nextKnownField(field)) {
585 if (!m_tag.supportsField(field)) {
586 continue;
587 }
588 const auto propertyName = propertyNameForField(field);
589 if (propertyName.isEmpty()) {
590 continue;
591 }
592 auto propertyValue = m_fields.property(propertyName);
593 if (!propertyValue.isArray()) {
594 auto array = m_engine->newArray(1);
595 array.setProperty(0, propertyValue);
596 propertyValue = std::move(array);
597 }
598 const auto size = propertyValue.property(QStringLiteral("length")).toUInt();
599 const auto initialValues = m_tag.values(field);
600 auto values = std::vector<TagParser::TagValue>();
601 values.reserve(size);
602 for (auto i = quint32(); i != size; ++i) {
603 const auto arrayElement = propertyValue.property(i);
604 if (arrayElement.isUndefined() || arrayElement.isNull()) {
605 continue;
606 }
607 auto *tagValueObj = qobject_cast<TagValueObject *>(arrayElement.toQObject());
608 if (!tagValueObj) {
609 tagValueObj = new TagValueObject(i < initialValues.size() ? *initialValues[i] : TagParser::TagValue(), m_engine, this);
610 tagValueObj->setContent(arrayElement);
611 propertyValue.setProperty(i, m_engine->newQObject(tagValueObj));
612 }
613 if (tagValueObj->isInitial()) {
614 if (i < initialValues.size()) {
615 values.emplace_back(*initialValues[i]);
616 }
617 continue;
618 }
619 auto &value = values.emplace_back(tagValueObj->toTagValue(encoding));
620 m_diag.emplace_back(TagParser::DiagLevel::Information,
621 value.isNull()
622 ? CppUtilities::argsToString(" - delete ", propertyName.toStdString(), '[', i, ']')
623 : (tagValueObj->initialContent().isUndefined()
624 ? CppUtilities::argsToString(
625 " - set ", propertyName.toStdString(), '[', i, "] to '", printJsValue(tagValueObj->content()), '\'')
626 : ((tagValueObj->content().equals(tagValueObj->initialContent()))
627 ? CppUtilities::argsToString(" - set ", propertyName.toStdString(), '[', i, "] to '",
628 printJsValue(tagValueObj->content()), "\' (no change)")
629 : CppUtilities::argsToString(" - change ", propertyName.toStdString(), '[', i, "] from '",
630 printJsValue(tagValueObj->initialContent()), "' to '", printJsValue(tagValueObj->content()), '\''))),
631 std::string());

Callers 5

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
setTagInfoFunction · 0.80
startSavingMethod · 0.80

Calls 9

valuesMethod · 0.80
setContentMethod · 0.80
isInitialMethod · 0.80
toTagValueMethod · 0.80
setValuesMethod · 0.80
TagValueClass · 0.70
setId3v2CoverValuesFunction · 0.70
targetMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected