# HG changeset patch # User Chris Cannam # Date 1182860867 0 # Node ID 7b58c5e91f20cefcf1177db3696e10ef58e1d120 # Parent 70537b0434c47f2bd9349c99c6d4e6914c0a3fb4 * save/reload measurements in session diff -r 70537b0434c4 -r 7b58c5e91f20 layer/Layer.cpp --- a/layer/Layer.cpp Tue Jun 26 11:08:21 2007 +0000 +++ b/layer/Layer.cpp Tue Jun 26 12:27:47 2007 +0000 @@ -151,6 +151,49 @@ } QString +Layer::MeasureRect::toXmlString(QString indent) const +{ + QString s; + + s += indent; + s += QString("\n") + .arg(pixrect.y()).arg(pixrect.y() + pixrect.height()); + + return s; +} + +void +Layer::addMeasurementRect(const QXmlAttributes &attributes) +{ + MeasureRect rect; + QString fs = attributes.value("startFrame"); + int x0 = 0, y0 = 0, x1 = 0, y1 = 0; + if (fs != "") { + rect.startFrame = fs.toLong(); + rect.endFrame = attributes.value("endFrame").toLong(); + rect.haveFrames = true; + } else { + x0 = attributes.value("startX").toInt(); + x1 = attributes.value("endX").toInt(); + rect.haveFrames = false; + } + y0 = attributes.value("startY").toInt(); + y1 = attributes.value("endY").toInt(); + rect.pixrect = QRect(x0, y0, x1 - x0, y1 - y0); + addMeasureRectToSet(rect); +} + +QString Layer::AddMeasurementRectCommand::getName() const { return tr("Make Measurement"); @@ -159,13 +202,13 @@ void Layer::AddMeasurementRectCommand::execute() { - m_layer->addMeasureRect(m_rect); + m_layer->addMeasureRectToSet(m_rect); } void Layer::AddMeasurementRectCommand::unexecute() { - m_layer->deleteMeasureRect(m_rect); + m_layer->deleteMeasureRectFromSet(m_rect); } void @@ -224,7 +267,7 @@ } void -Layer::paintMeasurementRect(View *v, QPainter &paint, MeasureRect &r) +Layer::paintMeasurementRect(View *v, QPainter &paint, const MeasureRect &r) const { if (r.haveFrames) { @@ -254,7 +297,7 @@ s += indent; - s += QString("\n") + s += QString("getLayerTypeName (LayerFactory::getInstance()->getLayerType(this)))) .arg(getObjectExportId(this)) @@ -262,5 +305,38 @@ .arg(getObjectExportId(getModel())) .arg(extraAttributes); + if (m_measureRects.empty()) { + s += QString("/>\n"); + return s; + } + + s += QString(">\n"); + + for (MeasureRectSet::const_iterator i = m_measureRects.begin(); + i != m_measureRects.end(); ++i) { + s += i->toXmlString(indent + " "); + } + + s += QString("\n"); + return s; } + +QString +Layer::toBriefXmlString(QString indent, QString extraAttributes) const +{ + QString s; + + s += indent; + + s += QString("\n") + .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName + (LayerFactory::getInstance()->getLayerType(this)))) + .arg(getObjectExportId(this)) + .arg(encodeEntities(objectName())) + .arg(getObjectExportId(getModel())) + .arg(extraAttributes); + + return s; +} + diff -r 70537b0434c4 -r 7b58c5e91f20 layer/Layer.h --- a/layer/Layer.h Tue Jun 26 11:08:21 2007 +0000 +++ b/layer/Layer.h Tue Jun 26 12:27:47 2007 +0000 @@ -267,6 +267,22 @@ virtual void setProperties(const QXmlAttributes &) = 0; /** + * Produce an XML string containing the layer's ID and type. This + * is used to refer to the layer in the display section of the SV + * session file, for a layer that has already been described in + * the data section. + */ + virtual QString toBriefXmlString(QString indent = "", + QString extraAttributes = "") const; + + /** + * Add a measurement rectangle from the given XML attributes + * (presumably taken from a measurement element). + * Does not use a command. + */ + virtual void addMeasurementRect(const QXmlAttributes &); + + /** * Indicate that a layer is not currently visible in the given * view and is not expected to become visible in the near future * (for example because the user has explicitly removed or hidden @@ -411,6 +427,7 @@ long endFrame; // ditto bool operator<(const MeasureRect &mr) const; + QString toXmlString(QString indent) const; }; class AddMeasurementRectCommand : public Command @@ -428,12 +445,12 @@ MeasureRect m_rect; }; - void addMeasureRect(const MeasureRect &r) { + void addMeasureRectToSet(const MeasureRect &r) { m_measureRects.insert(r); emit layerMeasurementRectsChanged(); } - void deleteMeasureRect(const MeasureRect &r) { + void deleteMeasureRectFromSet(const MeasureRect &r) { m_measureRects.erase(r); emit layerMeasurementRectsChanged(); } @@ -443,7 +460,8 @@ MeasureRect m_draggingRect; bool m_haveDraggingRect; - void paintMeasurementRect(View *v, QPainter &paint, MeasureRect &r); + void paintMeasurementRect(View *v, QPainter &paint, + const MeasureRect &r) const; private: mutable QMutex m_dormancyMutex; diff -r 70537b0434c4 -r 7b58c5e91f20 view/View.cpp --- a/view/View.cpp Tue Jun 26 11:08:21 2007 +0000 +++ b/view/View.cpp Tue Jun 26 12:27:47 2007 +0000 @@ -1967,9 +1967,9 @@ for (size_t i = 0; i < m_layers.size(); ++i) { bool visible = !m_layers[i]->isLayerDormant(this); - s += m_layers[i]->toXmlString(indent + " ", - QString("visible=\"%1\"") - .arg(visible ? "true" : "false")); + s += m_layers[i]->toBriefXmlString(indent + " ", + QString("visible=\"%1\"") + .arg(visible ? "true" : "false")); } s += indent + "\n";