diff data/model/Labeller.h @ 1741:9d82b164f264 by-id

Work on commands, and some other model updates
author Chris Cannam
date Thu, 27 Jun 2019 13:08:10 +0100
parents 08bed13d3a26
children 52705a328b34
line wrap: on
line diff
--- a/data/model/Labeller.h	Wed Jun 26 17:25:20 2019 +0100
+++ b/data/model/Labeller.h	Thu Jun 27 13:08:10 2019 +0100
@@ -225,13 +225,16 @@
      * Relabel all events in the given event vector that lie within
      * the given multi-selection, according to the labelling
      * properties of this labeller.  Return a command that has been
-     * executed but not yet added to the history.
+     * executed but not yet added to the history. The template
+     * parameter must be a type that can be dynamic_cast to
+     * EventEditable and that has a ById store.
      */
-    Command *labelAll(EventEditable *editable,
+    template <typename EditableBase>
+    Command *labelAll(typename EditableBase::Id editable,
                       MultiSelection *ms,
                       const EventVector &allEvents) {
 
-        ChangeEventsCommand *command = new ChangeEventsCommand
+        auto command = new ChangeEventsCommand<EditableBase>
             (editable, tr("Label Points"));
 
         Event prev;
@@ -270,14 +273,17 @@
      * that event lies within the given multi-selection, add n-1 new
      * events at equally spaced intervals between it and the following
      * event.  Return a command that has been executed but not yet
-     * added to the history.
+     * added to the history. The template parameter must be a type
+     * that can be dynamic_cast to EventEditable and that has a ById
+     * store.
      */
-    Command *subdivide(EventEditable *editable,
+    template <typename EditableBase>
+    Command *subdivide(typename EditableBase::Id editable,
                        MultiSelection *ms,
                        const EventVector &allEvents,
                        int n) {
 
-        ChangeEventsCommand *command = new ChangeEventsCommand
+        auto command = new ChangeEventsCommand<EditableBase>
             (editable, tr("Subdivide Points"));
 
         for (auto i = allEvents.begin(); i != allEvents.end(); ++i) {
@@ -319,14 +325,17 @@
      * multi-selection, and a number n, remove all but every nth event
      * from the vector within the extents of the multi-selection.
      * Return a command that has been executed but not yet added to
-     * the history.
+     * the history. The template parameter must be a type
+     * that can be dynamic_cast to EventEditable and that has a ById
+     * store.
      */
-    Command *winnow(EventEditable *editable,
+    template <typename EditableBase>
+    Command *winnow(typename EditableBase::Id editable,
                     MultiSelection *ms,
                     const EventVector &allEvents,
                     int n) {
 
-        ChangeEventsCommand *command = new ChangeEventsCommand
+        auto command = new ChangeEventsCommand<EditableBase>
             (editable, tr("Winnow Points"));
 
         int counter = 0;