Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
SelectionState Class Referencefinal

#include <SelectionState.h>

Inheritance diagram for SelectionState:
[legend]
Collaboration diagram for SelectionState:
[legend]

Public Member Functions

 SelectionState ()=default
 
 SelectionState (const SelectionState &)=delete
 
SelectionStateoperator= (const SelectionState &)=delete
 
void SelectTrack (Track &track, bool selected, bool updateLastPicked)
 
void SelectRangeOfTracks (TrackList &tracks, Track &sTrack, Track &eTrack)
 
void SelectNone (TrackList &tracks)
 
void ChangeSelectionOnShiftClick (TrackList &tracks, Track &track)
 
void HandleListSelection (TrackList &tracks, ViewInfo &viewInfo, Track &track, bool shift, bool ctrl, bool syncLocked)
 
- Public Member Functions inherited from ClientData::Base
virtual ~Base ()
 

Static Public Member Functions

static SelectionStateGet (AudacityProject &project)
 
static const SelectionStateGet (const AudacityProject &project)
 
static void SelectTrackLength (ViewInfo &viewInfo, Track &track, bool syncLocked)
 

Private Attributes

std::weak_ptr< TrackmLastPickedTrack
 

Friends

class SelectionStateChanger
 

Detailed Description

Definition at line 21 of file SelectionState.h.

Constructor & Destructor Documentation

◆ SelectionState() [1/2]

SelectionState::SelectionState ( )
default

◆ SelectionState() [2/2]

SelectionState::SelectionState ( const SelectionState )
delete

Member Function Documentation

◆ ChangeSelectionOnShiftClick()

void SelectionState::ChangeSelectionOnShiftClick ( TrackList tracks,
Track track 
)

Definition at line 107 of file SelectionState.cpp.

109{
110 // We will either extend from the first or from the last.
111 auto pExtendFrom = tracks.Lock(mLastPickedTrack);
112
113 if (!pExtendFrom) {
114 auto trackRange = tracks.Selected();
115 auto pFirst = *trackRange.begin();
116
117 // If our track is at or after the first, extend from the first.
118 if (pFirst) {
119 auto begin = tracks.begin(),
120 iterT = tracks.Find(&track),
121 iterF = tracks.Find(pFirst);
122 auto indT = std::distance(begin, iterT),
123 indF = std::distance(begin, iterF);
124 if (indT >= indF)
125 pExtendFrom = pFirst->SharedPointer();
126 }
127
128 // Our track was earlier than the first. Extend from the last.
129 if (!pExtendFrom)
130 pExtendFrom = Track::SharedPointer(*trackRange.rbegin());
131 }
132 // Either it's null, or mLastPickedTrack, or the first or last of
133 // Selected()
134 assert(!pExtendFrom || pExtendFrom->IsLeader());
135
137 if (pExtendFrom)
138 SelectRangeOfTracks(tracks, track, *pExtendFrom);
139 else
140 SelectTrack(track, true, true);
141 mLastPickedTrack = pExtendFrom;
142}
const auto tracks
std::weak_ptr< Track > mLastPickedTrack
void SelectRangeOfTracks(TrackList &tracks, Track &sTrack, Track &eTrack)
void SelectNone(TrackList &tracks)
void SelectTrack(Track &track, bool selected, bool updateLastPicked)
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:160
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150

References PackedArray::begin(), mLastPickedTrack, SelectNone(), SelectRangeOfTracks(), SelectTrack(), Track::SharedPointer(), and tracks.

Referenced by HandleListSelection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get() [1/2]

SelectionState & SelectionState::Get ( AudacityProject project)
static

Definition at line 22 of file SelectionState.cpp.

23{
24 return project.AttachedObjects::Get< SelectionState >( key );
25}
static const AudacityProject::AttachedObjects::RegisteredFactory key
const auto project

References key, and project.

Referenced by LabelGlyphHandle::Click(), SelectHandle::Click(), BackgroundHandle::Click(), ExportAudioDialog::DoExportSplitByTracks(), SelectUtilities::DoListSelection(), anonymous_namespace{NavigationMenus.cpp}::DoNextTrack(), anonymous_namespace{NavigationMenus.cpp}::DoPrevTrack(), SelectHandle::Drag(), Get(), LabelGlyphHandle::HandleGlyphDragRelease(), NavigationActions::Handler::OnToggle(), HighlitClipButtonHandle::UpdateTrackSelection(), and AffordanceHandle::UpdateTrackSelection().

Here is the caller graph for this function:

◆ Get() [2/2]

const SelectionState & SelectionState::Get ( const AudacityProject project)
static

Definition at line 27 of file SelectionState.cpp.

28{
29 return Get( const_cast< AudacityProject & >( project ) );
30}
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static SelectionState & Get(AudacityProject &project)

References Get(), and project.

Here is the call graph for this function:

◆ HandleListSelection()

void SelectionState::HandleListSelection ( TrackList tracks,
ViewInfo viewInfo,
Track track,
bool  shift,
bool  ctrl,
bool  syncLocked 
)
Precondition
track.IsLeader()

Definition at line 144 of file SelectionState.cpp.

146{
147 assert(track.IsLeader());
148 // AS: If the shift button is being held down, invert
149 // the selection on this track.
150 if (ctrl)
151 SelectTrack(track, !track.GetSelected(), true);
152 else {
153 if (shift && mLastPickedTrack.lock())
155 else {
157 SelectTrack(track, true, true);
158 SelectTrackLength(viewInfo, track, syncLocked);
159 }
160 }
161}
void ChangeSelectionOnShiftClick(TrackList &tracks, Track &track)
static void SelectTrackLength(ViewInfo &viewInfo, Track &track, bool syncLocked)
bool GetSelected() const
Selectedness is always the same for all channels of a group.
Definition: Track.cpp:70
bool IsLeader() const override
Definition: Track.cpp:291

References ChangeSelectionOnShiftClick(), Track::GetSelected(), Track::IsLeader(), mLastPickedTrack, SelectNone(), SelectTrack(), SelectTrackLength(), and tracks.

Here is the call graph for this function:

◆ operator=()

SelectionState & SelectionState::operator= ( const SelectionState )
delete

◆ SelectNone()

void SelectionState::SelectNone ( TrackList tracks)

Definition at line 101 of file SelectionState.cpp.

102{
103 for (auto t : tracks)
104 SelectTrack(*t, false, false);
105}

References SelectTrack(), and tracks.

Referenced by ChangeSelectionOnShiftClick(), BackgroundHandle::Click(), and HandleListSelection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SelectRangeOfTracks()

void SelectionState::SelectRangeOfTracks ( TrackList tracks,
Track sTrack,
Track eTrack 
)

Definition at line 80 of file SelectionState.cpp.

82{
83 Track *sTrack = &rsTrack, *eTrack = &reTrack;
84 // Swap the track pointers if needed
85 auto begin = tracks.begin(),
86 iterS = tracks.Find(sTrack),
87 iterE = tracks.Find(eTrack);
88 // Be sure to substitute the leaders for given tracks
89 sTrack = *iterS;
90 eTrack = *iterE;
91 auto indS = std::distance(begin, iterS),
92 indE = std::distance(begin, iterE);
93 if (indE < indS)
94 std::swap(sTrack, eTrack);
95
96 for (auto track :
97 tracks.Any().StartingWith(sTrack).EndingAfter(eTrack))
98 SelectTrack(*track, true, false);
99}
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:645

References PackedArray::begin(), SelectTrack(), anonymous_namespace{NoteTrack.cpp}::swap(), and tracks.

Referenced by ChangeSelectionOnShiftClick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SelectTrack()

void SelectionState::SelectTrack ( Track track,
bool  selected,
bool  updateLastPicked 
)
Precondition
track.IsLeader()

Definition at line 52 of file SelectionState.cpp.

54{
55 assert(track.IsLeader());
56 //bool wasCorrect = (selected == track.GetSelected());
57
58 track.SetSelected(selected);
59
60 if (updateLastPicked)
62
63//The older code below avoids an anchor on an unselected track.
64
65 /*
66 if (selected) {
67 // This handles the case of linked tracks, selecting all channels
68 mTracks->Select(pTrack, true);
69 if (updateLastPicked)
70 mLastPickedTrack = Track::Pointer( pTrack );
71 }
72 else {
73 mTracks->Select(pTrack, false);
74 if (updateLastPicked && pTrack == mLastPickedTrack.lock().get())
75 mLastPickedTrack.reset();
76 }
77*/
78}
virtual void SetSelected(bool s)
Definition: Track.cpp:75

References Track::IsLeader(), mLastPickedTrack, Track::SetSelected(), and Track::SharedPointer().

Referenced by ChangeSelectionOnShiftClick(), HandleListSelection(), SelectNone(), and SelectRangeOfTracks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SelectTrackLength()

void SelectionState::SelectTrackLength ( ViewInfo viewInfo,
Track track,
bool  syncLocked 
)
static

Set selection length to the length of a track – but if sync-lock is turned on, use the largest possible selection in the sync-lock group. If it's a stereo track, do the same for the stereo channels.

Precondition
track.IsLeader()

Definition at line 32 of file SelectionState.cpp.

34{
35 assert(track.IsLeader());
36 auto trackRange = syncLocked
37 // If we have a sync-lock group and sync-lock linking is on,
38 // check the sync-lock group tracks.
39 ? SyncLock::Group(&track)
40
41 // Otherwise, check for one track
42 : TrackList::SingletonRange(&track);
43
44 auto minOffset = trackRange.min(&Track::GetStartTime);
45 auto maxEnd = trackRange.max(&Track::GetEndTime);
46
47 // PRL: double click or click on track control.
48 // should this select all frequencies too? I think not.
49 viewInfo.selectedRegion.setTimes(minOffset, maxEnd);
50}
double GetEndTime() const
Get the maximum of End() values of intervals, or 0 when none.
Definition: Channel.cpp:135
double GetStartTime() const
Get the minimum of Start() values of intervals, or 0 when none.
Definition: Channel.cpp:124
bool setTimes(double t0, double t1)
Definition: ViewInfo.cpp:51
static TrackIterRange< Track > Group(Track *pTrack)
Definition: SyncLock.cpp:161
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:993
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215

References ChannelGroup::GetEndTime(), ChannelGroup::GetStartTime(), SyncLock::Group(), Track::IsLeader(), ViewInfo::selectedRegion, NotifyingSelectedRegion::setTimes(), and TrackList::SingletonRange().

Referenced by SelectHandle::Click(), HandleListSelection(), and NoteTrackAffordanceHandle::SelectAt().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ SelectionStateChanger

friend class SelectionStateChanger
friend

Definition at line 60 of file SelectionState.h.

Member Data Documentation

◆ mLastPickedTrack

std::weak_ptr<Track> SelectionState::mLastPickedTrack
private
Invariant
mLastPickedTrack.expired() || mLastPickedTrack.lock()->IsLeader()

Definition at line 66 of file SelectionState.h.

Referenced by ChangeSelectionOnShiftClick(), HandleListSelection(), SelectTrack(), and SelectionStateChanger::~SelectionStateChanger().


The documentation for this class was generated from the following files: