comparison data/model/ImageModel.h @ 1429:48e9f538e6e9

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents 1517d4c60e88
children c01cbe41aeb5
comparison
equal deleted inserted replaced
1428:87ae75da6527 1429:48e9f538e6e9
45 45
46 void toXml(QTextStream &stream, 46 void toXml(QTextStream &stream,
47 QString indent = "", 47 QString indent = "",
48 QString extraAttributes = "") const 48 QString extraAttributes = "") const
49 { 49 {
50 stream << 50 stream <<
51 QString("%1<point frame=\"%2\" image=\"%3\" label=\"%4\" %5/>\n") 51 QString("%1<point frame=\"%2\" image=\"%3\" label=\"%4\" %5/>\n")
52 .arg(indent).arg(frame) 52 .arg(indent).arg(frame)
53 .arg(encodeEntities(image)) 53 .arg(encodeEntities(image))
54 .arg(encodeEntities(label)) 54 .arg(encodeEntities(label))
55 .arg(extraAttributes); 55 .arg(extraAttributes);
56 } 56 }
57 57
63 if (label != "") list << label; 63 if (label != "") list << label;
64 return list.join(delimiter); 64 return list.join(delimiter);
65 } 65 }
66 66
67 struct Comparator { 67 struct Comparator {
68 bool operator()(const ImagePoint &p1, 68 bool operator()(const ImagePoint &p1,
69 const ImagePoint &p2) const { 69 const ImagePoint &p2) const {
70 if (p1.frame != p2.frame) return p1.frame < p2.frame; 70 if (p1.frame != p2.frame) return p1.frame < p2.frame;
71 if (p1.label != p2.label) return p1.label < p2.label; 71 if (p1.label != p2.label) return p1.label < p2.label;
72 return p1.image < p2.image; 72 return p1.image < p2.image;
73 } 73 }
74 }; 74 };
75 75
76 struct OrderComparator { 76 struct OrderComparator {
77 bool operator()(const ImagePoint &p1, 77 bool operator()(const ImagePoint &p1,
78 const ImagePoint &p2) const { 78 const ImagePoint &p2) const {
79 return p1.frame < p2.frame; 79 return p1.frame < p2.frame;
80 } 80 }
81 }; 81 };
82 }; 82 };
83 83
84 84
85 // Make this a class rather than a typedef so it can be predeclared. 85 // Make this a class rather than a typedef so it can be predeclared.
88 { 88 {
89 Q_OBJECT 89 Q_OBJECT
90 90
91 public: 91 public:
92 ImageModel(sv_samplerate_t sampleRate, int resolution, bool notifyOnAdd = true) : 92 ImageModel(sv_samplerate_t sampleRate, int resolution, bool notifyOnAdd = true) :
93 SparseModel<ImagePoint>(sampleRate, resolution, notifyOnAdd) 93 SparseModel<ImagePoint>(sampleRate, resolution, notifyOnAdd)
94 { } 94 { }
95 95
96 QString getTypeName() const { return tr("Image"); } 96 QString getTypeName() const { return tr("Image"); }
97 97
98 virtual void toXml(QTextStream &out, 98 virtual void toXml(QTextStream &out,
99 QString indent = "", 99 QString indent = "",
100 QString extraAttributes = "") const 100 QString extraAttributes = "") const
101 { 101 {
102 SparseModel<ImagePoint>::toXml 102 SparseModel<ImagePoint>::toXml
103 (out, 103 (out,
104 indent, 104 indent,
105 QString("%1 subtype=\"image\"") 105 QString("%1 subtype=\"image\"")
106 .arg(extraAttributes)); 106 .arg(extraAttributes));
107 } 107 }
108 108
109 /** 109 /**
110 * Command to change the image for a point. 110 * Command to change the image for a point.
111 */ 111 */
114 public: 114 public:
115 ChangeImageCommand(ImageModel *model, 115 ChangeImageCommand(ImageModel *model,
116 const ImagePoint &point, 116 const ImagePoint &point,
117 QString newImage, 117 QString newImage,
118 QString newLabel) : 118 QString newLabel) :
119 m_model(model), m_oldPoint(point), m_newPoint(point) { 119 m_model(model), m_oldPoint(point), m_newPoint(point) {
120 m_newPoint.image = newImage; 120 m_newPoint.image = newImage;
121 m_newPoint.label = newLabel; 121 m_newPoint.label = newLabel;
122 } 122 }
123 123
124 virtual QString getName() const { return tr("Edit Image"); } 124 virtual QString getName() const { return tr("Edit Image"); }
125 125
126 virtual void execute() { 126 virtual void execute() {
127 m_model->deletePoint(m_oldPoint); 127 m_model->deletePoint(m_oldPoint);
128 m_model->addPoint(m_newPoint); 128 m_model->addPoint(m_newPoint);
129 std::swap(m_oldPoint, m_newPoint); 129 std::swap(m_oldPoint, m_newPoint);
130 } 130 }
131 131
132 virtual void unexecute() { execute(); } 132 virtual void unexecute() { execute(); }
133 133
134 private: 134 private:
135 ImageModel *m_model; 135 ImageModel *m_model;
136 ImagePoint m_oldPoint; 136 ImagePoint m_oldPoint;
137 ImagePoint m_newPoint; 137 ImagePoint m_newPoint;
138 }; 138 };
139 139
140 /** 140 /**
141 * TabularModel methods. 141 * TabularModel methods.
142 */ 142 */