Mercurial > hg > svgui
changeset 269:7b58c5e91f20
* save/reload measurements in session
author | Chris Cannam |
---|---|
date | Tue, 26 Jun 2007 12:27:47 +0000 |
parents | 70537b0434c4 |
children | 61a704654497 |
files | layer/Layer.cpp layer/Layer.h view/View.cpp |
diffstat | 3 files changed, 104 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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("<measurement "); + + if (haveFrames) { + s += QString("startFrame=\"%1\" endFrame=\"%2\" ") + .arg(startFrame).arg(endFrame); + } else { + s += QString("startX=\"%1\" endX=\"%2\" ") + .arg(pixrect.x()).arg(pixrect.x() + pixrect.width()); + } + + s += QString("startY=\"%1\" endY=\"%2\"/>\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("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n") + s += QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5") .arg(encodeEntities(LayerFactory::getInstance()->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("</layer>\n"); + return s; } + +QString +Layer::toBriefXmlString(QString indent, QString extraAttributes) const +{ + QString s; + + s += indent; + + s += QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n") + .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName + (LayerFactory::getInstance()->getLayerType(this)))) + .arg(getObjectExportId(this)) + .arg(encodeEntities(objectName())) + .arg(getObjectExportId(getModel())) + .arg(extraAttributes); + + return s; +} +
--- 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;
--- 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 + "</view>\n";