From dc9e436dde54381582635dc8c015b3016f805ae4 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sat, 22 Jun 2019 11:02:55 -0400 Subject: [PATCH] Change the track view copy function... ... It is const, renamed CopyTo, and invokes the create-on-demand factory in the destination track; this means Track.cpp doesn't need to do that, and so does not need TrackView.h --- src/Track.cpp | 4 +--- src/tracks/labeltrack/ui/LabelTrackView.cpp | 7 ++++--- src/tracks/labeltrack/ui/LabelTrackView.h | 2 +- src/tracks/ui/CommonTrackPanelCell.cpp | 2 +- src/tracks/ui/CommonTrackPanelCell.h | 3 ++- src/tracks/ui/TrackView.cpp | 13 +++++-------- src/tracks/ui/TrackView.h | 2 +- 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/Track.cpp b/src/Track.cpp index 6e77df7f9..e3a78a8d4 100644 --- a/src/Track.cpp +++ b/src/Track.cpp @@ -41,8 +41,6 @@ and TimeTrack. #include "InconsistencyException.h" -#include "tracks/ui/TrackView.h" - #ifdef _MSC_VER //Disable truncation warnings #pragma warning( disable : 4786 ) @@ -115,7 +113,7 @@ Track::Holder Track::Duplicate() const if (mpView) // Copy view state that might be important to undo/redo - TrackView::Get( *result ).Copy( *mpView ); + mpView->CopyTo( *result ); return result; } diff --git a/src/tracks/labeltrack/ui/LabelTrackView.cpp b/src/tracks/labeltrack/ui/LabelTrackView.cpp index 2550ed99b..12c75c127 100644 --- a/src/tracks/labeltrack/ui/LabelTrackView.cpp +++ b/src/tracks/labeltrack/ui/LabelTrackView.cpp @@ -97,13 +97,14 @@ void LabelTrackView::UnbindFrom( LabelTrack *pParent ) EVT_LABELTRACK_PERMUTED, &LabelTrackView::OnLabelPermuted, this ); } -void LabelTrackView::Copy( const CommonTrackCell &other ) +void LabelTrackView::CopyTo( Track &track ) const { - TrackView::Copy( other ); + TrackView::CopyTo( track ); + auto &other = TrackView::Get( track ); if ( const auto pOther = dynamic_cast< const LabelTrackView* >( &other ) ) { // only one field is important to preserve in undo/redo history - mSelIndex = pOther->mSelIndex; + pOther->mSelIndex = mSelIndex; } } diff --git a/src/tracks/labeltrack/ui/LabelTrackView.h b/src/tracks/labeltrack/ui/LabelTrackView.h index dbcb631cb..39376d28d 100644 --- a/src/tracks/labeltrack/ui/LabelTrackView.h +++ b/src/tracks/labeltrack/ui/LabelTrackView.h @@ -82,7 +82,7 @@ private: std::shared_ptr DoGetVRulerControls() override; // Preserve some view state too for undo/redo purposes - void Copy( const CommonTrackCell &other ) override; + void CopyTo( Track &track ) const override; public: static void DoEditLabels( diff --git a/src/tracks/ui/CommonTrackPanelCell.cpp b/src/tracks/ui/CommonTrackPanelCell.cpp index e0ac5ff8f..f34fafe78 100644 --- a/src/tracks/ui/CommonTrackPanelCell.cpp +++ b/src/tracks/ui/CommonTrackPanelCell.cpp @@ -57,7 +57,7 @@ CommonTrackCell::CommonTrackCell( const std::shared_ptr< Track > &parent ) CommonTrackCell::~CommonTrackCell() = default; -void CommonTrackCell::Copy( const CommonTrackCell & ) +void CommonTrackCell::CopyTo( Track& ) const { } diff --git a/src/tracks/ui/CommonTrackPanelCell.h b/src/tracks/ui/CommonTrackPanelCell.h index a2db5d54d..b229a4c60 100644 --- a/src/tracks/ui/CommonTrackPanelCell.h +++ b/src/tracks/ui/CommonTrackPanelCell.h @@ -63,7 +63,8 @@ public: ~CommonTrackCell(); // Copy state, for undo/redo purposes - virtual void Copy( const CommonTrackCell &other ); + // The default does nothing + virtual void CopyTo( Track &track ) const; std::shared_ptr DoFindTrack() override; diff --git a/src/tracks/ui/TrackView.cpp b/src/tracks/ui/TrackView.cpp index 7e6080827..47524c25f 100644 --- a/src/tracks/ui/TrackView.cpp +++ b/src/tracks/ui/TrackView.cpp @@ -46,18 +46,15 @@ int TrackView::GetTotalHeight( const TrackList &list ) return GetCumulativeHeight( *list.Any().rbegin() ); } -void TrackView::Copy( const CommonTrackCell &otherCell ) +void TrackView::CopyTo( Track &track ) const { - auto pOther = dynamic_cast< const TrackView* >( &otherCell ); - if ( !pOther ) - return; - auto &other = *pOther; + auto &other = Get( track ); - mMinimized = other.mMinimized; + other.mMinimized = mMinimized; // Let mY remain 0 -- TrackPositioner corrects it later - mY = 0; - mHeight = other.mHeight; + other.mY = 0; + other.mHeight = mHeight; } TrackView &TrackView::Get( Track &track ) diff --git a/src/tracks/ui/TrackView.h b/src/tracks/ui/TrackView.h index 0a57decae..0feee6c35 100644 --- a/src/tracks/ui/TrackView.h +++ b/src/tracks/ui/TrackView.h @@ -42,7 +42,7 @@ public: static int GetTotalHeight( const TrackList &list ); // Copy view state, for undo/redo purposes - void Copy( const CommonTrackCell &other ) override; + void CopyTo( Track &track ) const override; static TrackView &Get( Track & ); static const TrackView &Get( const Track & );