1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2012 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "scoreelement.h"
#include "elements.h"
#include "score.h"
#include "fraction.h"
#include "libmscore/score.h"
#include "libmscore/scoreElement.h"
namespace Ms {
namespace PluginAPI {
//---------------------------------------------------------
// ScoreElement
//---------------------------------------------------------
ScoreElement::~ScoreElement()
{
if (_ownership == Ownership::PLUGIN)
delete e;
}
QString ScoreElement::name() const
{
return QString(e->name());
}
int ScoreElement::type() const
{
return int(e->type());
}
//---------------------------------------------------------
// ScoreElement::userName
/// \brief Human-readable element type name
/// \returns Name of the element type, translated
/// according to the current MuseScore locale settings.
//---------------------------------------------------------
QString ScoreElement::userName() const
{
return e->userName();
}
//---------------------------------------------------------
// ScoreElement::get
//---------------------------------------------------------
QVariant ScoreElement::get(Ms::Pid pid) const
{
if (!e)
return QVariant();
const QVariant val = e->getProperty(pid);
if (propertyType(pid) == P_TYPE::FRACTION) {
const Fraction f(val.value<Fraction>());
return QVariant::fromValue(wrap(f));
}
return val;
}
//---------------------------------------------------------
// ScoreElement::set
//---------------------------------------------------------
void ScoreElement::set(Ms::Pid pid, QVariant val)
{
if (!e)
return;
if (propertyType(pid) == P_TYPE::FRACTION) {
FractionWrapper* f = val.value<FractionWrapper*>();
if (!f) {
qWarning("ScoreElement::set: trying to assing value of wrong type to fractional property");
return;
}
val = QVariant::fromValue(f->fraction());
}
if (_ownership == Ownership::SCORE) {
const PropertyFlags f = e->propertyFlags(pid);
const PropertyFlags newFlags = (f == PropertyFlags::NOSTYLE) ? f : PropertyFlags::UNSTYLED;
e->undoChangeProperty(pid, val, newFlags);
}
else { // not added to a score so no need (and dangerous) to deal with undo stack
e->setProperty(pid, val);
}
}
//---------------------------------------------------------
// wrap
/// \cond PLUGIN_API \private \endcond
/// Wraps Ms::ScoreElement choosing the correct wrapper
/// type at runtime based on the actual element type.
//---------------------------------------------------------
ScoreElement* wrap(Ms::ScoreElement* se, Ownership own)
{
if (!se)
return nullptr;
if (se->isElement())
return wrap(toElement(se), own);
using Ms::ElementType;
switch(se->type()) {
case ElementType::SCORE:
return wrap<Score>(toScore(se), own);
case ElementType::PART:
return wrap<Part>(toPart(se), own);
default:
break;
}
return wrap<ScoreElement>(se, own);
}
}
}
|