# HG changeset patch # User Chris Cannam # Date 1394015903 0 # Node ID 34797795a76cc3ead8b8c697c9143f6a8804afe4 # Parent abfbe8c2883bceee7bcb1a6144975a2413777e2e Clearing the selection by hitting Esc now restores the selected region of the pitch track to its contents from before the selection was made (and any alternate candidate chosen). Fixes feature #885 diff -r abfbe8c2883b -r 34797795a76c .hgsubstate --- a/.hgsubstate Wed Mar 05 09:45:17 2014 +0000 +++ b/.hgsubstate Wed Mar 05 10:38:23 2014 +0000 @@ -1,5 +1,5 @@ 236814e07bd07473958c1ff89103124536a0c3c8 dataquay 27d4e7152c954bf3c4387319db088fb3cd02436b sv-dependency-builds -151b7c5864e3dc05832b1d2ef496b9e4987a4dba svapp +0c37405cf579c6cc87f5199044c2117baa977023 svapp d81c16e47e22b1c1a6600d3e9a8e0559fad8b539 svcore f831ca41d4a556cbc75aa5a180cf1e6a8d5598b5 svgui diff -r abfbe8c2883b -r 34797795a76c src/Analyser.cpp --- a/src/Analyser.cpp Wed Mar 05 09:45:17 2014 +0000 +++ b/src/Analyser.cpp Wed Mar 05 10:38:23 2014 +0000 @@ -255,9 +255,16 @@ { if (sel == m_reAnalysingSelection) return ""; - clearReAnalysis(); + showPitchCandidates(false); + m_reAnalysisCandidates.clear(); + m_currentCandidate = -1; + m_reAnalysingSelection = sel; - m_reAnalysingSelection = sel; + m_preAnalysis = Clipboard(); + Layer *myLayer = m_layers[PitchTrack]; + if (myLayer) { + myLayer->copy(m_pane, sel, m_preAnalysis); + } TransformFactory *tf = TransformFactory::getInstance(); @@ -441,15 +448,18 @@ } void -Analyser::clearReAnalysis() +Analyser::clearReAnalysis(Selection sel) { - foreach (Layer *layer, m_reAnalysisCandidates) { - m_document->removeLayerFromView(m_pane, layer); - m_document->deleteLayer(layer); // also releases its model - } + showPitchCandidates(false); + m_reAnalysisCandidates.clear(); m_reAnalysingSelection = Selection(); m_currentCandidate = -1; + + Layer *myLayer = m_layers[PitchTrack]; + if (!myLayer) return; + myLayer->deleteSelection(sel); + myLayer->paste(m_pane, m_preAnalysis, 0, false); } void diff -r abfbe8c2883b -r 34797795a76c src/Analyser.h --- a/src/Analyser.h Wed Mar 05 09:45:17 2014 +0000 +++ b/src/Analyser.h Wed Mar 05 10:38:23 2014 +0000 @@ -24,6 +24,7 @@ #include "framework/Document.h" #include "base/Selection.h" +#include "base/Clipboard.h" class WaveFileModel; class Pane; @@ -108,6 +109,8 @@ * independent of whether any pitch candidates actually exist -- * it's possible they might be shown but not have been created yet * because creation (through reAnalyseSelection) is asynchronous. + * + *!!! this interface is not right */ bool arePitchCandidatesShown() const; @@ -116,6 +119,8 @@ * arePitchCandidatesShown, this is independent of whether the * candidate layers actually exist. Call reAnalyseSelection to * schedule creation of those layers. + * + *!!! this interface is not right */ void showPitchCandidates(bool shown); @@ -139,9 +144,12 @@ void shiftOctave(Selection sel, bool up); /** - * Remove any re-analysis layers. + * Remove any re-analysis layers (equivalent to + * showPitchCandidates(false)) and also reset the pitch track in + * the given selection to its state prior to the last re-analysis, + * abandoning any changes made since then. */ - void clearReAnalysis(); + void clearReAnalysis(Selection sel); /** * Import the pitch track from the given layer into our @@ -168,6 +176,7 @@ mutable std::map m_layers; + Clipboard m_preAnalysis; Selection m_reAnalysingSelection; std::vector m_reAnalysisCandidates; int m_currentCandidate; diff -r abfbe8c2883b -r 34797795a76c src/MainWindow.cpp --- a/src/MainWindow.cpp Wed Mar 05 09:45:17 2014 +0000 +++ b/src/MainWindow.cpp Wed Mar 05 10:38:23 2014 +0000 @@ -528,7 +528,7 @@ action = new QAction(tr("C&lear Selection"), this); action->setShortcut(tr("Esc")); action->setStatusTip(tr("Clear the selection")); - connect(action, SIGNAL(triggered()), this, SLOT(clearSelection())); + connect(action, SIGNAL(triggered()), this, SLOT(abandonSelection())); connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool))); m_keyReference->registerShortcut(action); menu->addAction(action); @@ -1771,13 +1771,23 @@ } void -MainWindow::clearSelection() +MainWindow::abandonSelection() { - cerr << "MainWindow::clearSelection()" << endl; + // Named abandonSelection rather than clearSelection to indicate + // that this is an active operation -- it restores the original + // content of the pitch track in the selected region rather than + // simply un-selecting. + + cerr << "MainWindow::abandonSelection()" << endl; CommandHistory::getInstance()->startCompoundOperation(tr("Clear Selection"), true); - m_analyser->clearReAnalysis(); + MultiSelection::SelectionList selections = m_viewManager->getSelections(); + if (!selections.empty()) { + Selection sel = *selections.begin(); + m_analyser->clearReAnalysis(sel); + } + MainWindowBase::clearSelection(); CommandHistory::getInstance()->endCompoundOperation(); diff -r abfbe8c2883b -r 34797795a76c src/MainWindow.h --- a/src/MainWindow.h Wed Mar 05 09:45:17 2014 +0000 +++ b/src/MainWindow.h Wed Mar 05 10:38:23 2014 +0000 @@ -69,7 +69,7 @@ virtual void playNotesToggled(); virtual void doubleClickSelectInvoked(size_t); - virtual void clearSelection(); + virtual void abandonSelection(); virtual void paneAdded(Pane *); virtual void paneHidden(Pane *);