fix Spatium/QVariant conversions

This commit is contained in:
ws 2016-03-05 15:31:26 +01:00
parent a96c0abf5b
commit 9db0540ad2
14 changed files with 77 additions and 46 deletions

View file

@ -28,7 +28,7 @@ static const NoteHead::Group NOTEHEADGROUP_DEFAULT = NoteHead::Group::HEAD_NORM
static const NoteHead::Type NOTEHEADTYPE_DEFAULT = NoteHead::Type::HEAD_AUTO;
static const MScore::DirectionH DIR_DEFAULT = MScore::DirectionH::AUTO;
static const bool HASLINE_DEFAULT = true;
static const qreal LINEWIDTH_DEFAULT = 0.12;
static const Spatium LINEWIDTH_DEFAULT(0.12);
#if 0 // yet(?) unused
static const qreal LEDGEROFFSET_DEFAULT = 0.25;
#endif
@ -206,7 +206,7 @@ void Ambitus::read(XmlReader& e)
else if (tag == "hasLine")
setHasLine(e.readInt());
else if (tag == "lineWidth")
setProperty(P_ID::LINE_WIDTH, Ms::getProperty(P_ID::LINE_WIDTH, e).toReal());
setProperty(P_ID::LINE_WIDTH, Ms::getProperty(P_ID::LINE_WIDTH, e));
else if (tag == "topPitch")
_topPitch = e.readInt();
else if (tag == "bottomPitch")
@ -406,7 +406,7 @@ void Ambitus::layout()
void Ambitus::draw(QPainter* p) const
{
qreal _spatium = spatium();
qreal lw = lineWidth() * _spatium;
qreal lw = lineWidth().val() * _spatium;
p->setPen(QPen(curColor(), lw, Qt::SolidLine, Qt::RoundCap));
drawSymbol(noteHead(), p, _topPos);
drawSymbol(noteHead(), p, _bottomPos);
@ -635,7 +635,7 @@ bool Ambitus::setProperty(P_ID propertyId, const QVariant& v)
setHasLine(v.toBool());
break;
case P_ID::LINE_WIDTH:
setLineWidth(v.toReal());
setLineWidth(v.value<Spatium>());
break;
case P_ID::TPC1:
setTopTpc(v.toInt());
@ -675,7 +675,7 @@ QVariant Ambitus::propertyDefault(P_ID id) const
case P_ID::HEAD_TYPE: return int(NOTEHEADTYPE_DEFAULT);
case P_ID::MIRROR_HEAD: return int(DIR_DEFAULT);
case P_ID::GHOST: return HASLINE_DEFAULT;
case P_ID::LINE_WIDTH: return LINEWIDTH_DEFAULT;
case P_ID::LINE_WIDTH: return Spatium(LINEWIDTH_DEFAULT);
case P_ID::TPC1: // no defaults for pitches, tpc's and octaves
case P_ID::FBPARENTHESIS1:
case P_ID::PITCH:

View file

@ -32,7 +32,7 @@ class Ambitus : public Element {
NoteHead::Type _noteHeadType;
MScore::DirectionH _dir;
bool _hasLine;
qreal _lineWidth; // in spatium
Spatium _lineWidth;
Accidental _topAccid, _bottomAccid;
int _topPitch, _bottomPitch;
int _topTpc, _bottomTpc;
@ -55,7 +55,7 @@ class Ambitus : public Element {
NoteHead::Type noteHeadType() const { return _noteHeadType; }
MScore::DirectionH direction() const { return _dir; }
bool hasLine() const { return _hasLine; }
qreal lineWidth() const { return _lineWidth; }
Spatium lineWidth() const { return _lineWidth; }
int topOctave() const { return _topPitch / 12;}
int bottomOctave() const { return _bottomPitch / 12;}
int topPitch() const { return _topPitch; }
@ -67,7 +67,7 @@ class Ambitus : public Element {
void setNoteHeadType (NoteHead::Type val) { _noteHeadType = val; }
void setDirection (MScore::DirectionH val) { _dir = val; }
void setHasLine (bool val) { _hasLine = val; }
void setLineWidth (qreal val) { _lineWidth = val; }
void setLineWidth (Spatium val) { _lineWidth = val; }
void setTopPitch (int val);
void setBottomPitch (int val);
void setTopTpc (int val);

View file

@ -327,9 +327,9 @@ QVariant Box::getProperty(P_ID propertyId) const
{
switch(propertyId) {
case P_ID::BOX_HEIGHT:
return _boxHeight.val();
return _boxHeight;
case P_ID::BOX_WIDTH:
return _boxWidth.val();
return _boxWidth;
case P_ID::TOP_GAP:
return _topGap;
case P_ID::BOTTOM_GAP:
@ -356,10 +356,10 @@ bool Box::setProperty(P_ID propertyId, const QVariant& v)
score()->addRefresh(canvasBoundingRect());
switch(propertyId) {
case P_ID::BOX_HEIGHT:
_boxHeight = Spatium(v.toDouble());
_boxHeight = v.value<Spatium>();
break;
case P_ID::BOX_WIDTH:
_boxWidth = Spatium(v.toDouble());
_boxWidth = v.value<Spatium>();
break;
case P_ID::TOP_GAP:
_topGap = v.toDouble();
@ -395,6 +395,8 @@ QVariant Box::propertyDefault(P_ID id) const
switch(id) {
case P_ID::BOX_HEIGHT:
case P_ID::BOX_WIDTH:
return Spatium(0.0);
case P_ID::TOP_GAP:
case P_ID::BOTTOM_GAP:
return 0.0;

View file

@ -465,9 +465,9 @@ QVariant Hairpin::getProperty(P_ID id) const
case P_ID::DYNAMIC_RANGE:
return int(_dynRange);
case P_ID::HAIRPIN_HEIGHT:
return _hairpinHeight.val();
return _hairpinHeight;
case P_ID::HAIRPIN_CONT_HEIGHT:
return _hairpinContHeight.val();
return _hairpinContHeight;
default:
return TextLine::getProperty(id);
}
@ -502,11 +502,11 @@ bool Hairpin::setProperty(P_ID id, const QVariant& v)
break;
case P_ID::HAIRPIN_HEIGHT:
hairpinHeightStyle = PropertyStyle::UNSTYLED;
_hairpinHeight = Spatium(v.toDouble());
_hairpinHeight = v.value<Spatium>();
break;
case P_ID::HAIRPIN_CONT_HEIGHT:
hairpinContHeightStyle = PropertyStyle::UNSTYLED;
_hairpinContHeight = Spatium(v.toDouble());
_hairpinContHeight = v.value<Spatium>();
break;
default:
return TextLine::setProperty(id, v);
@ -528,9 +528,9 @@ QVariant Hairpin::propertyDefault(P_ID id) const
case P_ID::HAIRPIN_TYPE: return int(Type::CRESCENDO);
case P_ID::VELO_CHANGE: return 0;
case P_ID::DYNAMIC_RANGE: return int(Dynamic::Range::PART);
case P_ID::LINE_WIDTH: return score()->styleS(StyleIdx::hairpinLineWidth).val();
case P_ID::HAIRPIN_HEIGHT: return score()->styleS(StyleIdx::hairpinHeight).val();
case P_ID::HAIRPIN_CONT_HEIGHT: return score()->styleS(StyleIdx::hairpinContHeight).val();
case P_ID::LINE_WIDTH: return score()->style(StyleIdx::hairpinLineWidth);
case P_ID::HAIRPIN_HEIGHT: return score()->style(StyleIdx::hairpinHeight);
case P_ID::HAIRPIN_CONT_HEIGHT: return score()->style(StyleIdx::hairpinContHeight);
case P_ID::LINE_STYLE: return _useTextLine ? int(Qt::CustomDashLine) : int(Qt::SolidLine);
default:
@ -561,17 +561,17 @@ void Hairpin::resetProperty(P_ID id)
{
switch (id) {
case P_ID::LINE_WIDTH:
setLineWidth(score()->styleS(StyleIdx::hairpinLineWidth));
setProperty(id, propertyDefault(id));
lineWidthStyle = PropertyStyle::STYLED;
break;
case P_ID::HAIRPIN_HEIGHT:
setHairpinHeight(score()->styleS(StyleIdx::hairpinHeight));
setProperty(id, propertyDefault(id));
hairpinHeightStyle = PropertyStyle::STYLED;
break;
case P_ID::HAIRPIN_CONT_HEIGHT:
setHairpinContHeight(score()->styleS(StyleIdx::hairpinContHeight));
setLineWidth(score()->styleS(StyleIdx::hairpinLineWidth));
hairpinContHeightStyle = PropertyStyle::STYLED;
break;
@ -658,7 +658,7 @@ void Hairpin::startEdit(MuseScoreView* view, const QPointF& p)
void Hairpin::endEdit()
{
if (editHairpinHeight != _hairpinHeight)
score()->undoPropertyChanged(this, P_ID::HAIRPIN_HEIGHT, editHairpinHeight.val());
score()->undoPropertyChanged(this, P_ID::HAIRPIN_HEIGHT, editHairpinHeight);
TextLine::endEdit();
}

View file

@ -1084,7 +1084,7 @@ QVariant SLine::getProperty(P_ID id) const
case P_ID::LINE_COLOR:
return _lineColor;
case P_ID::LINE_WIDTH:
return _lineWidth.val();
return _lineWidth;
case P_ID::LINE_STYLE:
return QVariant(int(_lineStyle));
default:
@ -1106,7 +1106,7 @@ bool SLine::setProperty(P_ID id, const QVariant& v)
_lineColor = v.value<QColor>();
break;
case P_ID::LINE_WIDTH:
_lineWidth = Spatium(v.toDouble());
_lineWidth = v.value<Spatium>();
break;
case P_ID::LINE_STYLE:
_lineStyle = Qt::PenStyle(v.toInt());
@ -1129,7 +1129,7 @@ QVariant SLine::propertyDefault(P_ID id) const
case P_ID::LINE_COLOR:
return MScore::defaultColor;
case P_ID::LINE_WIDTH:
return 0.15;
return Spatium(0.15);
case P_ID::LINE_STYLE:
return int(Qt::SolidLine);
default:

View file

@ -55,6 +55,7 @@
#include "stemslash.h"
#include "fraction.h"
#include "excerpt.h"
#include "spatium.h"
namespace Ms {
@ -152,12 +153,20 @@ void Direction::fillComboBox(QComboBox* cb)
cb->addItem(qApp->translate("Direction", "down"), int(DOWN));
}
static Spatium doubleToSpatium(double d) { return Spatium(d); }
//---------------------------------------------------------
// init
//---------------------------------------------------------
void MScore::init()
{
if (!QMetaType::registerConverter<Spatium, double>(&Spatium::toDouble))
qFatal("registerConverter Spatium::toDouble failed");
if (!QMetaType::registerConverter<double, Spatium>(&doubleToSpatium))
qFatal("registerConverter douobleToSpatium failed");
#ifdef SCRIPT_INTERFACE
qRegisterMetaType<Element::Type> ("ElementType");
qRegisterMetaType<Note::ValueType> ("ValueType");

View file

@ -393,7 +393,7 @@ QVariant Ottava::propertyDefault(P_ID propertyId) const
return 0;
case P_ID::LINE_WIDTH:
return score()->styleS(StyleIdx::ottavaLineWidth).val();
return score()->style(StyleIdx::ottavaLineWidth);
case P_ID::LINE_STYLE:
return int(score()->styleI(StyleIdx::ottavaLineStyle));
@ -402,7 +402,7 @@ QVariant Ottava::propertyDefault(P_ID propertyId) const
return int(ottavaDefault[int(_ottavaType)].place);
case P_ID::END_HOOK_HEIGHT:
return score()->styleS(StyleIdx::ottavaHook).val() * ottavaDefault[int(_ottavaType)].hookDirection;
return score()->style(StyleIdx::ottavaHook).value<Spatium>() * ottavaDefault[int(_ottavaType)].hookDirection;
case P_ID::NUMBERS_ONLY:
return score()->styleB(StyleIdx::ottavaNumbersOnly);
@ -488,7 +488,7 @@ void Ottava::resetProperty(P_ID id)
return;
case P_ID::LINE_WIDTH:
setLineWidth(score()->styleS(StyleIdx::ottavaLineWidth));
setLineWidth(score()->style(StyleIdx::ottavaLineWidth).value<Spatium>());
lineWidthStyle = PropertyStyle::STYLED;
break;

View file

@ -203,7 +203,7 @@ QVariant Pedal::propertyDefault(P_ID propertyId) const
{
switch (propertyId) {
case P_ID::LINE_WIDTH:
return score()->styleS(StyleIdx::pedalLineWidth).val();
return score()->style(StyleIdx::pedalLineWidth);
case P_ID::LINE_STYLE:
return int(score()->styleI(StyleIdx::pedalLineStyle));

View file

@ -856,7 +856,8 @@ void Segment::read(XmlReader& e)
QVariant Segment::getProperty(P_ID propertyId) const
{
switch(propertyId) {
case P_ID::LEADING_SPACE: return extraLeadingSpace().val();
case P_ID::LEADING_SPACE:
return extraLeadingSpace();
default:
return Element::getProperty(propertyId);
}
@ -869,7 +870,7 @@ QVariant Segment::getProperty(P_ID propertyId) const
QVariant Segment::propertyDefault(P_ID propertyId) const
{
switch(propertyId) {
case P_ID::LEADING_SPACE: return 0.0;
case P_ID::LEADING_SPACE: return Spatium(0.0);
default:
return Element::getProperty(propertyId);
}
@ -882,7 +883,10 @@ QVariant Segment::propertyDefault(P_ID propertyId) const
bool Segment::setProperty(P_ID propertyId, const QVariant& v)
{
switch (propertyId) {
case P_ID::LEADING_SPACE: setExtraLeadingSpace(Spatium(v.toDouble())); break;
case P_ID::LEADING_SPACE:
setExtraLeadingSpace(v.value<Spatium>());
score()->setLayout(tick());
break;
default:
return Element::setProperty(propertyId, v);
}
@ -1406,8 +1410,12 @@ qreal Segment::minHorizontalDistance(Segment* ns) const
w += spatium() * 1.5;
if (w < 0.0)
w = 0.0;
if (ns)
if (ns) {
qreal ls = ns->extraLeadingSpace().val() * spatium();
if (ls != 0.0)
printf("extra space %f\n", ls);
w += ns->extraLeadingSpace().val() * spatium();
}
return w;
}

View file

@ -29,6 +29,7 @@ class Spatium {
Spatium() { _val = 0.0; }
explicit Spatium(qreal v) { _val = v; }
qreal val() const { return _val; }
bool operator>(const Spatium& a) const { return _val > a._val; }
bool operator<(const Spatium& a) const { return _val < a._val; }
bool operator==(const Spatium& a) const { return _val == a._val; }
@ -60,6 +61,8 @@ class Spatium {
}
Spatium operator-() const { return Spatium(-_val); }
operator QVariant() const { return QVariant::fromValue(*this); }
static double toDouble(const Spatium& v) { return v._val; }
};
inline Spatium operator+(const Spatium& a, const Spatium& b)

View file

@ -714,7 +714,7 @@ void MStyle::load(XmlReader& e)
if (t.name() == tag) {
const char* type = t.valueType();
if (!strcmp("Ms::Spatium", type))
set(idx, QVariant(Spatium(val.toDouble())));
set(idx, Spatium(val.toDouble()));
else if (!strcmp("double", type))
set(idx, QVariant(val.toDouble()));
else if (!strcmp("bool", type))

View file

@ -863,9 +863,9 @@ QVariant TextLine::getProperty(P_ID id) const
case P_ID::END_HOOK:
return _endHook;
case P_ID::BEGIN_HOOK_HEIGHT:
return _beginHookHeight.val();
return _beginHookHeight;
case P_ID::END_HOOK_HEIGHT:
return _endHookHeight.val();
return _endHookHeight;
case P_ID::BEGIN_HOOK_TYPE:
return int(_beginHookType);
case P_ID::END_HOOK_TYPE:
@ -906,10 +906,10 @@ bool TextLine::setProperty(P_ID id, const QVariant& v)
_endHook = v.toBool();
break;
case P_ID::BEGIN_HOOK_HEIGHT:
_beginHookHeight = Spatium(v.toDouble());
_beginHookHeight = v.value<Spatium>();
break;
case P_ID::END_HOOK_HEIGHT:
_endHookHeight = Spatium(v.toDouble());
_endHookHeight = v.value<Spatium>();
break;
case P_ID::BEGIN_HOOK_TYPE:
_beginHookType = HookType(v.toInt());
@ -951,7 +951,7 @@ QVariant TextLine::propertyDefault(P_ID id) const
return false;
case P_ID::BEGIN_HOOK_HEIGHT:
case P_ID::END_HOOK_HEIGHT:
return 1.5;
return Spatium(1.5);
case P_ID::BEGIN_HOOK_TYPE:
case P_ID::END_HOOK_TYPE:
return int(HookType::HOOK_90);

View file

@ -312,7 +312,7 @@ bool Volta::setProperty(P_ID propertyId, const QVariant& val)
break;
case P_ID::LINE_WIDTH:
lineWidthStyle = PropertyStyle::UNSTYLED;
setLineWidth(Spatium(val.toDouble()));
setLineWidth(val.value<Spatium>());
break;
case P_ID::LINE_STYLE:
lineStyleStyle = PropertyStyle::UNSTYLED;
@ -346,7 +346,7 @@ QVariant Volta::propertyDefault(P_ID propertyId) const
return 0;
case P_ID::LINE_WIDTH:
return score()->styleS(StyleIdx::voltaLineWidth).val();
return score()->style(StyleIdx::voltaLineWidth);
case P_ID::BEGIN_TEXT_PLACE:
case P_ID::CONTINUE_TEXT_PLACE:
@ -360,7 +360,7 @@ QVariant Volta::propertyDefault(P_ID propertyId) const
case P_ID::BEGIN_HOOK_HEIGHT:
case P_ID::END_HOOK_HEIGHT:
return score()->styleS(StyleIdx::voltaHook).val();
return score()->style(StyleIdx::voltaHook);
case P_ID::TEXT_STYLE_TYPE:
return int(TextStyleType::VOLTA);

View file

@ -564,9 +564,18 @@ void Xml::tag(const QString& name, QVariant data)
*this << QString("<%1 w=\"%2\" h=\"%3\"/>\n").arg(name).arg(p.width()).arg(p.height());
}
break;
default:
qDebug("Xml::tag: unsupported type %d", data.type());
// abort();
default: {
const char* type = data.typeName();
if (strcmp(type, "Ms::Spatium") == 0) {
*this << "<" << name << ">";
*this << data.value<Spatium>().val();
*this << "</" << ename << ">\n";
}
else {
qDebug("Xml::tag: unsupported type %d %s", data.type(), type);
// abort();
}
}
break;
}
}