comparison layer/Layer.cpp @ 269:7b58c5e91f20

* save/reload measurements in session
author Chris Cannam
date Tue, 26 Jun 2007 12:27:47 +0000
parents 70537b0434c4
children 61a704654497
comparison
equal deleted inserted replaced
268:70537b0434c4 269:7b58c5e91f20
149 return pixrect.y() < mr.pixrect.y(); 149 return pixrect.y() < mr.pixrect.y();
150 } 150 }
151 } 151 }
152 152
153 QString 153 QString
154 Layer::MeasureRect::toXmlString(QString indent) const
155 {
156 QString s;
157
158 s += indent;
159 s += QString("<measurement ");
160
161 if (haveFrames) {
162 s += QString("startFrame=\"%1\" endFrame=\"%2\" ")
163 .arg(startFrame).arg(endFrame);
164 } else {
165 s += QString("startX=\"%1\" endX=\"%2\" ")
166 .arg(pixrect.x()).arg(pixrect.x() + pixrect.width());
167 }
168
169 s += QString("startY=\"%1\" endY=\"%2\"/>\n")
170 .arg(pixrect.y()).arg(pixrect.y() + pixrect.height());
171
172 return s;
173 }
174
175 void
176 Layer::addMeasurementRect(const QXmlAttributes &attributes)
177 {
178 MeasureRect rect;
179 QString fs = attributes.value("startFrame");
180 int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
181 if (fs != "") {
182 rect.startFrame = fs.toLong();
183 rect.endFrame = attributes.value("endFrame").toLong();
184 rect.haveFrames = true;
185 } else {
186 x0 = attributes.value("startX").toInt();
187 x1 = attributes.value("endX").toInt();
188 rect.haveFrames = false;
189 }
190 y0 = attributes.value("startY").toInt();
191 y1 = attributes.value("endY").toInt();
192 rect.pixrect = QRect(x0, y0, x1 - x0, y1 - y0);
193 addMeasureRectToSet(rect);
194 }
195
196 QString
154 Layer::AddMeasurementRectCommand::getName() const 197 Layer::AddMeasurementRectCommand::getName() const
155 { 198 {
156 return tr("Make Measurement"); 199 return tr("Make Measurement");
157 } 200 }
158 201
159 void 202 void
160 Layer::AddMeasurementRectCommand::execute() 203 Layer::AddMeasurementRectCommand::execute()
161 { 204 {
162 m_layer->addMeasureRect(m_rect); 205 m_layer->addMeasureRectToSet(m_rect);
163 } 206 }
164 207
165 void 208 void
166 Layer::AddMeasurementRectCommand::unexecute() 209 Layer::AddMeasurementRectCommand::unexecute()
167 { 210 {
168 m_layer->deleteMeasureRect(m_rect); 211 m_layer->deleteMeasureRectFromSet(m_rect);
169 } 212 }
170 213
171 void 214 void
172 Layer::measureStart(View *v, QMouseEvent *e) 215 Layer::measureStart(View *v, QMouseEvent *e)
173 { 216 {
222 paintMeasurementRect(v, paint, *i); 265 paintMeasurementRect(v, paint, *i);
223 } 266 }
224 } 267 }
225 268
226 void 269 void
227 Layer::paintMeasurementRect(View *v, QPainter &paint, MeasureRect &r) 270 Layer::paintMeasurementRect(View *v, QPainter &paint, const MeasureRect &r) const
228 { 271 {
229 if (r.haveFrames) { 272 if (r.haveFrames) {
230 273
231 int x0 = -1; 274 int x0 = -1;
232 int x1 = v->width() + 1; 275 int x1 = v->width() + 1;
252 { 295 {
253 QString s; 296 QString s;
254 297
255 s += indent; 298 s += indent;
256 299
300 s += QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5")
301 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName
302 (LayerFactory::getInstance()->getLayerType(this))))
303 .arg(getObjectExportId(this))
304 .arg(encodeEntities(objectName()))
305 .arg(getObjectExportId(getModel()))
306 .arg(extraAttributes);
307
308 if (m_measureRects.empty()) {
309 s += QString("/>\n");
310 return s;
311 }
312
313 s += QString(">\n");
314
315 for (MeasureRectSet::const_iterator i = m_measureRects.begin();
316 i != m_measureRects.end(); ++i) {
317 s += i->toXmlString(indent + " ");
318 }
319
320 s += QString("</layer>\n");
321
322 return s;
323 }
324
325 QString
326 Layer::toBriefXmlString(QString indent, QString extraAttributes) const
327 {
328 QString s;
329
330 s += indent;
331
257 s += QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n") 332 s += QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n")
258 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName 333 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName
259 (LayerFactory::getInstance()->getLayerType(this)))) 334 (LayerFactory::getInstance()->getLayerType(this))))
260 .arg(getObjectExportId(this)) 335 .arg(getObjectExportId(this))
261 .arg(encodeEntities(objectName())) 336 .arg(encodeEntities(objectName()))
262 .arg(getObjectExportId(getModel())) 337 .arg(getObjectExportId(getModel()))
263 .arg(extraAttributes); 338 .arg(extraAttributes);
264 339
265 return s; 340 return s;
266 } 341 }
342