Skip to content
Permalink
Browse files

Extend properties framework for score comparison related needs

This commit adds:
- ScoreElement::propertyId for obtaining property ID by its XML name
  within the context of the respective element
- ScoreElement::propertyUserValue to obtain values of the properties
  in a human-readable representation
  • Loading branch information...
dmitrio95 committed Sep 26, 2018
1 parent 70d8367 commit 6ae48c8b32714ba65b2f7a9b6b126fc1f1d86825
@@ -440,6 +440,20 @@ bool Accidental::setProperty(Pid propertyId, const QVariant& v)
return true;
}

//---------------------------------------------------------
// propertyUserValue
//---------------------------------------------------------

QString Accidental::propertyUserValue(Pid pid) const
{
switch(pid) {
case Pid::SUBTYPE:
return subtypeUserName();
default:
return Element::propertyUserValue(pid);
}
}

//---------------------------------------------------------
// accessibleInfo
//---------------------------------------------------------
@@ -211,6 +211,7 @@ class Accidental final : public Element {
virtual QVariant getProperty(Pid propertyId) const override;
virtual bool setProperty(Pid propertyId, const QVariant&) override;
virtual QVariant propertyDefault(Pid propertyId) const override;
virtual QString propertyUserValue(Pid) const;

static AccidentalVal subtype2value(AccidentalType); // return effective pitch offset
static const char* subtype2name(AccidentalType);
@@ -1181,6 +1181,31 @@ QVariant Element::propertyDefault(Pid pid) const
}
}

//---------------------------------------------------------
// propertyId
//---------------------------------------------------------

Pid Element::propertyId(const QStringRef& name) const
{
if (name == "pos" || name == "offset")
return Pid::OFFSET;
return ScoreElement::propertyId(name);
}

//---------------------------------------------------------
// propertyUserValue
//---------------------------------------------------------

QString Element::propertyUserValue(Pid pid) const
{
switch(pid) {
case Pid::SUBTYPE:
return subtypeName();
default:
return ScoreElement::propertyUserValue(pid);
}
}

//---------------------------------------------------------
// custom
// check if property is != default
@@ -409,6 +409,8 @@ class Element : public ScoreElement {
virtual QVariant getProperty(Pid) const override;
virtual bool setProperty(Pid, const QVariant&) override;
virtual QVariant propertyDefault(Pid) const override;
virtual Pid propertyId(const QStringRef& xmlName) const override;
virtual QString propertyUserValue(Pid) const override;
virtual Element* propertyDelegate(Pid) { return 0; } // return Spanner for SpannerSegment for some properties

bool custom(Pid) const;
@@ -2665,6 +2665,27 @@ QVariant Note::propertyDefault(Pid propertyId) const
return Element::propertyDefault(propertyId);
}

//---------------------------------------------------------
// propertyUserValue
//---------------------------------------------------------

QString Note::propertyUserValue(Pid pid) const
{
switch(pid) {
case Pid::PITCH:
return tpcUserName();
case Pid::TPC1:
case Pid::TPC2:
{
int idx = (pid == Pid::TPC1) ? 0 : 1;
int tpc = _tpc[idx];
return tpc2name(tpc, NoteSpellingType::STANDARD, NoteCaseType::AUTO, false);
}
default:
return Element::propertyUserValue(pid);
}
}

//---------------------------------------------------------
// undoSetFret
//---------------------------------------------------------
@@ -465,6 +465,7 @@ class Note final : public Element {
virtual QVariant getProperty(Pid propertyId) const override;
virtual bool setProperty(Pid propertyId, const QVariant&) override;
virtual QVariant propertyDefault(Pid) const override;
virtual QString propertyUserValue(Pid) const override;

bool mark() const { return _mark; }
void setMark(bool v) const { _mark = v; }
@@ -417,6 +417,34 @@ void ScoreElement::writeProperty(XmlWriter& xml, Pid id) const
}
}

//---------------------------------------------------------
// propertyId
//---------------------------------------------------------

Pid ScoreElement::propertyId(const QStringRef& xmlName) const
{
return propertyIdName(xmlName);
}

//---------------------------------------------------------
// propertyUserValue
//---------------------------------------------------------

QString ScoreElement::propertyUserValue(Pid id) const
{
QVariant val = getProperty(id);
switch (propertyType(id)) {
case P_TYPE::POINT_SP:
{
QPointF p = val.toPointF();
return QString("(%1, %2)").arg(p.x()).arg(p.y());
}
default:
break;
}
return val.toString();
}

//---------------------------------------------------------
// readStyledProperty
//---------------------------------------------------------
@@ -203,6 +203,9 @@ class ScoreElement {

virtual void reset(); // reset all properties & position to default

virtual Pid propertyId(const QStringRef& xmlName) const;
virtual QString propertyUserValue(Pid) const;

virtual void initElementStyle(const ElementStyle*);
virtual const ElementStyle* styledProperties() const { return _elementStyle; }

@@ -1687,28 +1687,28 @@ void TextBase::writeProperties(XmlWriter& xml, bool writeText, bool /*writeStyle
xml.writeXml("text", xmlText());
}

static constexpr std::array<Pid, 18> pids { {
Pid::SUB_STYLE,
Pid::FONT_FACE,
Pid::FONT_SIZE,
Pid::FONT_BOLD,
Pid::FONT_ITALIC,
Pid::FONT_UNDERLINE,
Pid::FRAME_TYPE,
Pid::FRAME_WIDTH,
Pid::FRAME_PADDING,
Pid::FRAME_ROUND,
Pid::FRAME_FG_COLOR,
Pid::FRAME_BG_COLOR,
Pid::ALIGN,
} };

//---------------------------------------------------------
// readProperties
//---------------------------------------------------------

bool TextBase::readProperties(XmlReader& e)
{
static const std::array<Pid, 18> pids { {
Pid::SUB_STYLE,
Pid::FONT_FACE,
Pid::FONT_SIZE,
Pid::FONT_BOLD,
Pid::FONT_ITALIC,
Pid::FONT_UNDERLINE,
Pid::FRAME_TYPE,
Pid::FRAME_WIDTH,
Pid::FRAME_PADDING,
Pid::FRAME_ROUND,
Pid::FRAME_FG_COLOR,
Pid::FRAME_BG_COLOR,
Pid::ALIGN,
} };

const QStringRef& tag(e.name());
for (Pid i :pids) {
if (readProperty(tag, e, i))
@@ -1721,6 +1721,21 @@ bool TextBase::readProperties(XmlReader& e)
return true;
}

//---------------------------------------------------------
// propertyId
//---------------------------------------------------------

Pid TextBase::propertyId(const QStringRef& name) const
{
if (name == "text")
return Pid::TEXT;
for (Pid pid : pids) {
if (propertyName(pid) == name)
return pid;
}
return Element::propertyId(name);
}

//---------------------------------------------------------
// pageRectangle
//---------------------------------------------------------
@@ -335,6 +335,7 @@ class TextBase : public Element {
virtual QVariant getProperty(Pid propertyId) const override;
virtual bool setProperty(Pid propertyId, const QVariant& v) override;
virtual QVariant propertyDefault(Pid id) const override;
virtual Pid propertyId(const QStringRef& xmlName) const override;
virtual Sid getPropertyStyle(Pid) const;
virtual void styleChanged();

@@ -454,6 +454,19 @@ bool TextLineBase::readProperties(XmlReader& e)
return SLine::readProperties(e);
}

//---------------------------------------------------------
// TextLineBase::propertyId
//---------------------------------------------------------

Pid TextLineBase::propertyId(const QStringRef& name) const
{
for (Pid pid : pids) {
if (propertyName(pid) == name)
return pid;
}
return SLine::propertyId(name);
}

//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
@@ -121,6 +121,7 @@ class TextLineBase : public SLine {

virtual QVariant getProperty(Pid id) const override;
virtual bool setProperty(Pid propertyId, const QVariant&) override;
virtual Pid propertyId(const QStringRef& xmlName) const override;
};

} // namespace Ms
@@ -217,6 +217,23 @@ void TimeSig::read(XmlReader& e)
_stretch.reduce();
}

//---------------------------------------------------------
// propertyId
//---------------------------------------------------------

Pid TimeSig::propertyId(const QStringRef& name) const
{
if (name == "subtype")
return Pid::TIMESIG_TYPE;
if (name == "sigN" || name == "sigD")
return Pid::TIMESIG;
if (name == "stretchN" || name == "stretchD")
return Pid::TIMESIG_STRETCH;
if (name == "Groups")
return Pid::GROUPS;
return Element::propertyId(name);
}

//---------------------------------------------------------
// layout
//---------------------------------------------------------
@@ -112,6 +112,7 @@ class TimeSig final : public Element {
virtual QVariant getProperty(Pid propertyId) const override;
virtual bool setProperty(Pid propertyId, const QVariant&) override;
virtual QVariant propertyDefault(Pid id) const override;
virtual Pid propertyId(const QStringRef& xmlName) const override;

const Groups& groups() const { return _groups; }
void setGroups(const Groups& e) { _groups = e; }
@@ -329,6 +329,11 @@ Serialization:
bool Element::readProperty(const QStringRef&, XmlReader&, P_ID);
This sets the property state to UNSTYLED if it is a styled property.

Human-readable representation:

virtual QString propertyUserValue(Pid) const;
Returns the value of the property in a human-readable representation.

Styled properties:

virtual StyleIdx getPropertyStyle(P_ID) const;

0 comments on commit 6ae48c8

Please sign in to comment.
You can’t perform that action at this time.