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:
Collaboration diagram for SelectionState:

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


class SelectionStateChanger

Detailed Description

Definition at line 21 of file SelectionState.h.

Constructor & Destructor Documentation

◆ SelectionState() [1/2]

SelectionState::SelectionState ( )

◆ SelectionState() [2/2]

SelectionState::SelectionState ( const SelectionState )

Member Function Documentation

◆ ChangeSelectionOnShiftClick()

void SelectionState::ChangeSelectionOnShiftClick ( TrackList tracks,
Track track 

Definition at line 102 of file SelectionState.cpp.

105 // We will either extend from the first or from the last.
106 auto pExtendFrom = tracks.Lock(mLastPickedTrack);
108 if (!pExtendFrom) {
109 auto trackRange = tracks.Selected();
110 auto pFirst = *trackRange.begin();
112 // If our track is at or after the first, extend from the first.
113 if (pFirst) {
114 auto begin = tracks.begin(),
115 iterT = tracks.Find(&track),
116 iterF = tracks.Find(pFirst);
117 auto indT = std::distance(begin, iterT),
118 indF = std::distance(begin, iterF);
119 if (indT >= indF)
120 pExtendFrom = pFirst->SharedPointer();
121 }
123 // Our track was earlier than the first. Extend from the last.
124 if (!pExtendFrom)
125 pExtendFrom = Track::SharedPointer(*trackRange.rbegin());
126 }
129 if (pExtendFrom)
130 SelectRangeOfTracks(tracks, track, *pExtendFrom);
131 else
132 SelectTrack(track, true, true);
133 mLastPickedTrack = pExtendFrom;
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:146
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101

References details::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)

Definition at line 22 of file SelectionState.cpp.

24 return project.AttachedObjects::Get< SelectionState >( key );
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)

Definition at line 27 of file SelectionState.cpp.

29 return Get( const_cast< AudacityProject & >( project ) );
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 

Definition at line 136 of file SelectionState.cpp.

139 // AS: If the shift button is being held down, invert
140 // the selection on this track.
141 if (ctrl)
142 SelectTrack(track, !track.GetSelected(), true);
143 else {
144 if (shift && mLastPickedTrack.lock())
146 else {
148 SelectTrack(track, true, true);
149 SelectTrackLength(viewInfo, track, syncLocked);
150 }
151 }
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:78

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

Here is the call graph for this function:

◆ operator=()

SelectionState & SelectionState::operator= ( const SelectionState )

◆ SelectNone()

void SelectionState::SelectNone ( TrackList tracks)

Definition at line 96 of file SelectionState.cpp.

98 for (auto t : tracks)
99 SelectTrack(*t, false, false);

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 78 of file SelectionState.cpp.

81 Track *sTrack = &rsTrack, *eTrack = &reTrack;
82 // Swap the track pointers if needed
83 auto begin = tracks.begin(),
84 iterS = tracks.Find(sTrack),
85 iterE = tracks.Find(eTrack);
86 auto indS = std::distance(begin, iterS),
87 indE = std::distance(begin, iterE);
88 if (indE < indS)
89 std::swap(sTrack, eTrack);
91 for (auto track :
92 tracks.Any().StartingWith(sTrack).EndingAfter(eTrack))
93 SelectTrack(*track, true, false);
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:628

References details::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 

Definition at line 51 of file SelectionState.cpp.

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

References 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 

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.

Definition at line 32 of file SelectionState.cpp.

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

References ChannelGroup::GetEndTime(), ChannelGroup::GetStartTime(), SyncLock::Group(), 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

Definition at line 52 of file SelectionState.h.

Member Data Documentation

◆ mLastPickedTrack

std::weak_ptr<Track> SelectionState::mLastPickedTrack

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