changeset 651:b63dfd7e2780 single-point

Updates for SparseOneDimensionalModel in new API
author Chris Cannam
date Thu, 21 Mar 2019 13:34:34 +0000
parents ed9cb577eb7c
children 8fb56fb5bdd3
files framework/MainWindowBase.cpp framework/SVFileReader.cpp
diffstat 2 files changed, 21 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/framework/MainWindowBase.cpp	Wed Mar 20 11:19:44 2019 +0000
+++ b/framework/MainWindowBase.cpp	Thu Mar 21 13:34:34 2019 +0000
@@ -1135,46 +1135,44 @@
     if (layer) {
     
         Model *model = layer->getModel();
-        SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
-            (model);
+        SparseOneDimensionalModel *sodm =
+            dynamic_cast<SparseOneDimensionalModel *>(model);
 
         if (sodm) {
-            SparseOneDimensionalModel::Point point(frame, "");
-
-            SparseOneDimensionalModel::Point prevPoint(0);
+            Event point(frame, "");
+            Event prevPoint(0);
             bool havePrevPoint = false;
 
-            SparseOneDimensionalModel::EditCommand *command =
-                new SparseOneDimensionalModel::EditCommand(sodm, tr("Add Point"));
+            ChangeEventsCommand *command =
+                new ChangeEventsCommand(sodm, tr("Add Point"));
 
             if (m_labeller) {
 
                 if (m_labeller->requiresPrevPoint()) {
-
-                    SparseOneDimensionalModel::PointList prevPoints =
-                        sodm->getPreviousPoints(frame);
-
-                    if (!prevPoints.empty()) {
-                        prevPoint = *prevPoints.begin();
+                    
+                    if (sodm->getNearestEventMatching
+                        (frame,
+                         [](Event) { return true; },
+                         EventSeries::Backward,
+                         prevPoint)) {
                         havePrevPoint = true;
                     }
                 }
 
                 m_labeller->setSampleRate(sodm->getSampleRate());
 
-                if (m_labeller->actingOnPrevEvent() && havePrevPoint) {
-                    command->deletePoint(prevPoint);
-                }
-/*!!! to be updated after we have switched SODM to new API 
-                m_labeller->label<SparseOneDimensionalModel::Point>
+                Labeller::Relabelling relabelling = m_labeller->label
                     (point, havePrevPoint ? &prevPoint : nullptr);
-*/
-                if (m_labeller->actingOnPrevEvent() && havePrevPoint) {
-                    command->addPoint(prevPoint);
+
+                if (relabelling.first == Labeller::AppliesToPreviousEvent) {
+                    command->remove(prevPoint);
+                    command->add(relabelling.second);
+                } else {
+                    point = relabelling.second;
                 }
             }
             
-            command->addPoint(point);
+            command->add(point);
 
             command->setName(tr("Add Point at %1 s")
                              .arg(RealTime::frame2RealTime
--- a/framework/SVFileReader.cpp	Wed Mar 20 11:19:44 2019 +0000
+++ b/framework/SVFileReader.cpp	Thu Mar 21 13:34:34 2019 +0000
@@ -1086,7 +1086,7 @@
     if (sodm) {
 //        SVCERR << "Current dataset is a sparse one dimensional model" << endl;
         QString label = attributes.value("label");
-        sodm->addPoint(SparseOneDimensionalModel::Point(frame, label));
+        sodm->add(Event(frame, label));
         return true;
     }