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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2018 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
//=============================================================================
#ifndef __SCOREDIFF_H__
#define __SCOREDIFF_H__
#include "score.h"
#include <vector>
namespace Ms {
enum class Pid;
class ScoreElement;
//---------------------------------------------------------
// ItemType
//---------------------------------------------------------
enum class ItemType {
ELEMENT,
PROPERTY,
MARKUP,
CONTEXTCHANGE
};
//---------------------------------------------------------
// DiffType
//---------------------------------------------------------
#undef DELETE
enum class DiffType {
EQUAL,
INSERT,
DELETE,
REPLACE
};
//---------------------------------------------------------
// TextDiff
// A structure similar to Diff from diff_match_patch
// but contains info on line numbers of the diff
//---------------------------------------------------------
struct TextDiff {
DiffType type;
QString text[2];
int start[2]; // starting line numbers in both texts
int end[2]; // ending line numbers in both texts
void merge(const TextDiff& other); // merge other diff into this one
QString toString(DiffType type, bool prefixLines = false) const;
QString toString(bool prefixLines = false) const { return toString(type, prefixLines); }
};
//---------------------------------------------------------
// BaseDiff
//---------------------------------------------------------
struct BaseDiff {
DiffType type;
const TextDiff* textDiff;
const ScoreElement* ctx[2];
const ScoreElement* before[2];
virtual ~BaseDiff() = default;
virtual ItemType itemType() const = 0;
virtual bool sameItem(const BaseDiff&) const;
virtual Fraction afrac(int score) const;
virtual QString toString() const = 0;
};
//---------------------------------------------------------
// ContextChange
// Dummy Diff for temporary storing information on
// context changes.
//---------------------------------------------------------
struct ContextChange : public BaseDiff {
ItemType itemType() const override { return ItemType::CONTEXTCHANGE; }
QString toString() const override;
};
//---------------------------------------------------------
// ElementDiff
//---------------------------------------------------------
struct ElementDiff : public BaseDiff {
const ScoreElement* el[2];
ItemType itemType() const override { return ItemType::ELEMENT; }
bool sameItem(const BaseDiff&) const override;
Fraction afrac(int score) const override;
QString toString() const override;
};
//---------------------------------------------------------
// PropertyDiff
//---------------------------------------------------------
struct PropertyDiff : public BaseDiff {
Pid pid;
ItemType itemType() const override { return ItemType::PROPERTY; }
bool sameItem(const BaseDiff&) const override;
QString toString() const override;
};
//---------------------------------------------------------
// MarkupDiff
//---------------------------------------------------------
struct MarkupDiff : public BaseDiff {
QString name;
QVariant info;
ItemType itemType() const override { return ItemType::MARKUP; }
bool sameItem(const BaseDiff&) const override;
QString toString() const override;
};
//---------------------------------------------------------
// ScoreDiff
//---------------------------------------------------------
class ScoreDiff {
std::vector<TextDiff> _textDiffs; // raw diff between MSCX code for scores
std::vector<const TextDiff*> _mergedTextDiffs; // extra diff items created after merging score diff items
std::vector<BaseDiff*> _diffs;
Score* _s1;
Score* _s2;
ScoreContentState _scoreState1;
ScoreContentState _scoreState2;
bool _textDiffOnly;
void processMarkupDiffs();
void mergeInsertDeleteDiffs();
void mergeElementDiffs();
void editPropertyDiffs();
public:
ScoreDiff(Score* s1, Score* s2, bool textDiffOnly = false);
ScoreDiff(const ScoreDiff&) = delete;
~ScoreDiff();
void update();
bool updated() const { return _scoreState1 == _s1->state() && _scoreState2 == _s2->state(); }
std::vector<BaseDiff*>& diffs() { return _diffs; }
const std::vector<TextDiff>& textDiffs() const { return _textDiffs; }
const Score* score1() const { return _s1; }
const Score* score2() const { return _s2; }
bool equal() const;
QString rawDiff(bool skipEqual = true) const;
QString userDiff() const;
};
} // namespace Ms
#endif
|