changeset 358:8b69f36c74be

* some work on realignment when pasting (problems remain)
author Chris Cannam
date Mon, 04 Feb 2008 17:45:16 +0000
parents 3e538a90e9b8
children 020c485aa7e0
files layer/TimeInstantLayer.cpp layer/TimeInstantLayer.h
diffstat 2 files changed, 81 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/layer/TimeInstantLayer.cpp	Mon Feb 04 13:35:43 2008 +0000
+++ b/layer/TimeInstantLayer.cpp	Mon Feb 04 17:45:16 2008 +0000
@@ -25,6 +25,7 @@
 #include "data/model/SparseOneDimensionalModel.h"
 
 #include "widgets/ItemEditDialog.h"
+#include "widgets/ListInputDialog.h"
 
 #include <QPainter>
 #include <QMouseEvent>
@@ -722,6 +723,12 @@
 	 i != points.end(); ++i) {
 	if (s.contains(i->frame)) {
             Clipboard::Point point(i->frame, i->label);
+
+    //!!! This fails, because simply being "on the same pane as" a
+    // particular model is not enough to give this layer the same
+    // alignment as it.  If it was generated by deriving from another
+    // layer's model, that would be... but it wasn't necessarily
+
             point.setReferenceFrame(m_model->alignToReference(i->frame));
             to.addPoint(point);
         }
@@ -729,15 +736,59 @@
 }
 
 bool
+TimeInstantLayer::clipboardAlignmentDiffers(const Clipboard &clip) const
+{
+    //!!! hoist -- all pastable layers will need this
+
+    //!!! This fails, because simply being "on the same pane as" a
+    // particular model is not enough to give this layer the same
+    // alignment as it.  If it was generated by deriving from another
+    // layer's model, that would be... but it wasn't necessarily
+
+    if (!m_model) return false;
+
+    std::cerr << "TimeInstantLayer::clipboardAlignmentDiffers" << std::endl;
+
+    for (Clipboard::PointList::const_iterator i = clip.getPoints().begin();
+         i != clip.getPoints().end(); ++i) {
+
+        // In principle, we want to know whether the aligned version
+        // of the reference frame in our model is the same as the
+        // source frame contained in the clipboard point.  However,
+        // because of rounding during alignment, that won't
+        // necessarily be the case even if the clipboard point came
+        // from our model!  What we need to check is whether, if we
+        // aligned the clipboard point's frame back to the reference
+        // using this model's alignment, we would obtain the same
+        // reference frame as that for the clipboard point.
+
+        // What if the clipboard point has no reference frame?  Then
+        // we have to treat it as having its own frame as the
+        // reference (i.e. having been copied from the reference
+        // model).
+        
+        long sourceFrame = i->getFrame();
+        long referenceFrame = sourceFrame;
+        if (i->haveReferenceFrame()) {
+            referenceFrame = i->getReferenceFrame();
+        }
+        long myMappedFrame = m_model->alignToReference(sourceFrame);
+
+        std::cerr << "sourceFrame = " << sourceFrame << ", referenceFrame = " << referenceFrame << " (have = " << i->haveReferenceFrame() << "), myMappedFrame = " << myMappedFrame << std::endl;
+
+        if (myMappedFrame != referenceFrame) return true;
+    }
+
+    return false;
+}
+
+bool
 TimeInstantLayer::paste(const Clipboard &from, int frameOffset, bool)
 {
     if (!m_model) return false;
 
     const Clipboard::PointList &points = from.getPoints();
 
-    SparseOneDimensionalModel::EditCommand *command =
-	new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste"));
-
     //!!!
     
     // Clipboard::haveReferenceFrames() will return true if any of the
@@ -792,6 +843,31 @@
     // We either want to be literal all the way through, or aligned
     // all the way through.
 
+    bool realign = false;
+
+    if (clipboardAlignmentDiffers(from)) {
+
+        std::cerr << "Offer alignment option..." << std::endl;
+
+        QStringList options;
+        options << "Use times unchanged from the original layer";
+        options << "Re-align times to match the same points in the reference layer";
+
+        bool ok = false;
+
+        QString selected = ListInputDialog::getItem
+            (0, tr("Choose alignment"),
+             tr("The points you are pasting originated in a layer with different alignment from the current layer.  Would you like to re-align them when pasting?"),
+             options, 0, &ok);
+        if (!ok) return false;
+
+        if (selected == options[1]) realign = true;
+    }
+
+
+    SparseOneDimensionalModel::EditCommand *command =
+	new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste"));
+
     for (Clipboard::PointList::const_iterator i = points.begin();
          i != points.end(); ++i) {
         
--- a/layer/TimeInstantLayer.h	Mon Feb 04 13:35:43 2008 +0000
+++ b/layer/TimeInstantLayer.h	Mon Feb 04 17:45:16 2008 +0000
@@ -105,6 +105,8 @@
 
     virtual int getDefaultColourHint(bool dark, bool &impose);
 
+    bool clipboardAlignmentDiffers(const Clipboard &) const;
+
     SparseOneDimensionalModel *m_model;
     bool m_editing;
     SparseOneDimensionalModel::Point m_editingPoint;