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 &) PROHIBITED
 
SelectionStateoperator= (const SelectionState &) PROHIBITED
 
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 )

Member Function Documentation

◆ ChangeSelectionOnShiftClick()

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

Definition at line 100 of file SelectionState.cpp.

102{
103 // We will either extend from the first or from the last.
104 auto pExtendFrom = tracks.Lock(mLastPickedTrack);
105
106 if( !pExtendFrom ) {
107 auto trackRange = tracks.Selected();
108 auto pFirst = *trackRange.begin();
109
110 // If our track is at or after the first, extend from the first.
111 if( pFirst && track.GetIndex() >= pFirst->GetIndex() )
112 pExtendFrom = pFirst->SharedPointer();
113
114 // Our track was earlier than the first. Extend from the last.
115 if( !pExtendFrom )
116 pExtendFrom = Track::SharedPointer( *trackRange.rbegin() );
117 }
118
119 SelectNone( tracks );
120 if( pExtendFrom )
121 SelectRangeOfTracks( tracks, track, *pExtendFrom );
122 else
123 SelectTrack( track, true, true );
124 mLastPickedTrack = pExtendFrom;
125}
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:290
int GetIndex() const
Definition: Track.cpp:143
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1595
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:1446

References Track::GetIndex(), TrackList::Lock(), mLastPickedTrack, TrackList::Selected(), SelectNone(), SelectRangeOfTracks(), SelectTrack(), and Track::SharedPointer().

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

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

References key.

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

Here is the caller graph for this function:

◆ Get() [2/2]

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

Definition at line 26 of file SelectionState.cpp.

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

References Get().

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

130{
131 // AS: If the shift button is being held down, invert
132 // the selection on this track.
133 if (ctrl)
134 SelectTrack( track, !track.GetSelected(), true );
135 else {
136 if (shift && mLastPickedTrack.lock())
137 ChangeSelectionOnShiftClick( tracks, track );
138 else {
139 SelectNone( tracks );
140 SelectTrack( track, true, true );
141 SelectTrackLength( viewInfo, track, syncLocked );
142 }
143 }
144}
void ChangeSelectionOnShiftClick(TrackList &tracks, Track &track)
static void SelectTrackLength(ViewInfo &viewInfo, Track &track, bool syncLocked)
bool GetSelected() const
Definition: Track.h:461

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

Here is the call graph for this function:

◆ operator=()

SelectionState & SelectionState::operator= ( const SelectionState )

◆ SelectNone()

void SelectionState::SelectNone ( TrackList tracks)

Definition at line 94 of file SelectionState.cpp.

95{
96 for (auto t : tracks.Any())
97 SelectTrack( *t, false, false );
98}
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1429

References TrackList::Any(), and SelectTrack().

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

83{
84 Track *sTrack = &rsTrack, *eTrack = &reTrack;
85 // Swap the track pointers if needed
86 if (eTrack->GetIndex() < sTrack->GetIndex())
87 std::swap(sTrack, eTrack);
88
89 for (auto track :
90 tracks.Any().StartingWith(sTrack).EndingAfter(eTrack))
91 SelectTrack(*track, true, false);
92}
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:753

References TrackList::Any(), Track::GetIndex(), SelectTrack(), and anonymous_namespace{NoteTrack.cpp}::swap().

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

55{
56 //bool wasCorrect = (selected == track.GetSelected());
57
58 for (auto channel : TrackList::Channels(&track))
59 channel->SetSelected(selected);
60
61 if (updateLastPicked)
63
64//The older code below avoids an anchor on an unselected track.
65
66 /*
67 if (selected) {
68 // This handles the case of linked tracks, selecting all channels
69 mTracks->Select(pTrack, true);
70 if (updateLastPicked)
71 mLastPickedTrack = Track::Pointer( pTrack );
72 }
73 else {
74 mTracks->Select(pTrack, false);
75 if (updateLastPicked && pTrack == mLastPickedTrack.lock().get())
76 mLastPickedTrack.reset();
77 }
78*/
79}
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1533

References TrackList::Channels(), mLastPickedTrack, 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

Definition at line 34 of file SelectionState.cpp.

36{
37 auto trackRange = syncLocked
38 // If we have a sync-lock group and sync-lock linking is on,
39 // check the sync-lock group tracks.
40 ? SyncLock::Group(&track)
41
42 // Otherwise, check for a stereo pair
43 : TrackList::Channels(&track);
44
45 auto minOffset = trackRange.min( &Track::GetOffset );
46 auto maxEnd = trackRange.max( &Track::GetEndTime );
47
48 // PRL: double click or click on track control.
49 // should this select all frequencies too? I think not.
50 viewInfo.selectedRegion.setTimes(minOffset, maxEnd);
51}
bool setTimes(double t0, double t1)
Definition: ViewInfo.cpp:51
static TrackIterRange< Track > Group(Track *pTrack)
Definition: SyncLock.cpp:122
virtual double GetOffset() const =0
virtual double GetEndTime() const =0
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1330
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216

References TrackList::Channels(), Track::GetEndTime(), Track::GetOffset(), SyncLock::Group(), ViewInfo::selectedRegion, and NotifyingSelectedRegion::setTimes().

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 48 of file SelectionState.h.

Member Data Documentation

◆ mLastPickedTrack

std::weak_ptr<Track> SelectionState::mLastPickedTrack
private

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