diff layer/TimeValueLayer.cpp @ 22:179bf7b5ddea

* Update some copyright notice dates * Add commands for basic editing operations in time-instants and time-value layers
author Chris Cannam
date Tue, 31 Jan 2006 15:57:25 +0000
parents 3a506d25d95a
children ca57f70b0e48
line wrap: on
line diff
--- a/layer/TimeValueLayer.cpp	Mon Jan 30 17:51:56 2006 +0000
+++ b/layer/TimeValueLayer.cpp	Tue Jan 31 15:57:25 2006 +0000
@@ -28,6 +28,7 @@
     m_model(0),
     m_editing(false),
     m_editingPoint(0, 0.0, tr("New Point")),
+    m_editingCommand(0),
     m_colour(Qt::black),
     m_plotStyle(PlotConnectedPoints)
 {
@@ -496,7 +497,12 @@
     float value = getValueForY(e->y());
 
     m_editingPoint = SparseTimeValueModel::Point(frame, value, tr("New Point"));
-    m_model->addPoint(m_editingPoint);
+
+    if (m_editingCommand) m_editingCommand->finish();
+    m_editingCommand = new SparseTimeValueModel::EditCommand(m_model,
+							     tr("Draw Point"));
+    m_editingCommand->addPoint(m_editingPoint);
+
     m_editing = true;
 }
 
@@ -513,10 +519,10 @@
 
     float value = getValueForY(e->y());
 
-    m_model->deletePoint(m_editingPoint);
+    m_editingCommand->deletePoint(m_editingPoint);
     m_editingPoint.frame = frame;
     m_editingPoint.value = value;
-    m_model->addPoint(m_editingPoint);
+    m_editingCommand->addPoint(m_editingPoint);
 }
 
 void
@@ -524,6 +530,8 @@
 {
     std::cerr << "TimeValueLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl;
     if (!m_model || !m_editing) return;
+    m_editingCommand->finish();
+    m_editingCommand = 0;
     m_editing = false;
 }
 
@@ -538,6 +546,12 @@
     if (points.empty()) return;
 
     m_editingPoint = *points.begin();
+
+    if (m_editingCommand) {
+	m_editingCommand->finish();
+	m_editingCommand = 0;
+    }
+
     m_editing = true;
 }
 
@@ -554,10 +568,15 @@
 
     float value = getValueForY(e->y());
 
-    m_model->deletePoint(m_editingPoint);
+    if (!m_editingCommand) {
+	m_editingCommand = new SparseTimeValueModel::EditCommand(m_model,
+								 tr("Drag Point"));
+    }
+
+    m_editingCommand->deletePoint(m_editingPoint);
     m_editingPoint.frame = frame;
     m_editingPoint.value = value;
-    m_model->addPoint(m_editingPoint);
+    m_editingCommand->addPoint(m_editingPoint);
 }
 
 void
@@ -565,6 +584,8 @@
 {
     std::cerr << "TimeValueLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl;
     if (!m_model || !m_editing) return;
+    if (m_editingCommand) m_editingCommand->finish();
+    m_editingCommand = 0;
     m_editing = false;
 }