Merge pull request #1704 from badosu/fix-cloned-track-position

Fix cloned track position
This commit is contained in:
Tres Finocchiaro
2015-04-20 14:30:09 +00:00
4 changed files with 63 additions and 47 deletions

View File

@@ -441,7 +441,7 @@ public:
static Track * create( TrackTypes tt, TrackContainer * tc );
static Track * create( const QDomElement & element,
TrackContainer * tc );
void clone();
Track * clone();
// pure virtual functions

View File

@@ -103,8 +103,14 @@ public:
return m_tc;
}
void moveTrackViewUp( TrackView * _tv );
void moveTrackViewDown( TrackView * _tv );
const QList<TrackView *> & trackViews() const
{
return( m_trackViews );
}
void moveTrackView( TrackView * trackView, int indexTo );
void moveTrackViewUp( TrackView * trackView );
void moveTrackViewDown( TrackView * trackView );
// -- for usage by trackView only ---------------
TrackView * addTrackView( TrackView * _tv );
@@ -121,7 +127,7 @@ public:
public slots:
void realignTracks();
void createTrackView( Track * _t );
TrackView * createTrackView( Track * _t );
void deleteTrackView( TrackView * _tv );
virtual void dropEvent( QDropEvent * _de );
@@ -141,11 +147,6 @@ public slots:
protected:
static const int DEFAULT_PIXELS_PER_TACT = 16;
const QList<TrackView *> & trackViews() const
{
return( m_trackViews );
}
virtual void mousePressEvent( QMouseEvent * _me );
virtual void mouseMoveEvent( QMouseEvent * _me );
virtual void mouseReleaseEvent( QMouseEvent * _me );

View File

@@ -1683,13 +1683,18 @@ void TrackOperationsWidget::paintEvent( QPaintEvent * pe )
/*! \brief Clone this track
*
*/
void TrackOperationsWidget::cloneTrack()
{
m_trackView->getTrack()->clone();
TrackContainerView *tcView = m_trackView->trackContainerView();
Track *newTrack = m_trackView->getTrack()->clone();
TrackView *newTrackView = tcView->createTrackView( newTrack );
int index = tcView->trackViews().indexOf( m_trackView );
tcView->moveTrackView( newTrackView, index + 1 );
}
@@ -1899,12 +1904,12 @@ Track * Track::create( const QDomElement & element, TrackContainer * tc )
/*! \brief Clone a track from this track
*
*/
void Track::clone()
Track * Track::clone()
{
QDomDocument doc;
QDomElement parent = doc.createElement( "clone" );
saveState( doc, parent );
create( parent.firstChild().toElement(), m_trackContainer );
return create( parent.firstChild().toElement(), m_trackContainer );
}

View File

@@ -156,45 +156,48 @@ void TrackContainerView::removeTrackView( TrackView * _tv )
void TrackContainerView::moveTrackViewUp( TrackView * _tv )
void TrackContainerView::moveTrackView( TrackView * trackView, int indexTo )
{
for( int i = 1; i < m_trackViews.size(); ++i )
{
TrackView * t = m_trackViews[i];
if( t == _tv )
{
BBTrack::swapBBTracks( t->getTrack(),
m_trackViews[i - 1]->getTrack() );
m_scrollLayout->removeWidget( t );
m_scrollLayout->insertWidget( i - 1, t );
qSwap( m_tc->m_tracks[i-1], m_tc->m_tracks[i] );
m_trackViews.swap( i - 1, i );
realignTracks();
break;
}
}
// Can't move out of bounds
if ( indexTo >= m_trackViews.size() || indexTo < 0 ) { return; }
// Does not need to move to itself
int indexFrom = m_trackViews.indexOf( trackView );
if ( indexFrom == indexTo ) { return; }
BBTrack::swapBBTracks( trackView->getTrack(),
m_trackViews[indexTo]->getTrack() );
m_scrollLayout->removeWidget( trackView );
m_scrollLayout->insertWidget( indexTo, trackView );
Track * track = m_tc->m_tracks[indexFrom];
m_tc->m_tracks.remove( indexFrom );
m_tc->m_tracks.insert( indexTo, track );
m_trackViews.move( indexFrom, indexTo );
realignTracks();
}
void TrackContainerView::moveTrackViewDown( TrackView * _tv )
void TrackContainerView::moveTrackViewUp( TrackView * trackView )
{
for( int i = 0; i < m_trackViews.size()-1; ++i )
{
TrackView * t = m_trackViews[i];
if( t == _tv )
{
BBTrack::swapBBTracks( t->getTrack(),
m_trackViews[i + 1]->getTrack() );
m_scrollLayout->removeWidget( t );
m_scrollLayout->insertWidget( i + 1, t );
qSwap( m_tc->m_tracks[i], m_tc->m_tracks[i+1] );
m_trackViews.swap( i, i + 1 );
realignTracks();
break;
}
}
int index = m_trackViews.indexOf( trackView );
moveTrackView( trackView, index - 1 );
}
void TrackContainerView::moveTrackViewDown( TrackView * trackView )
{
int index = m_trackViews.indexOf( trackView );
moveTrackView( trackView, index + 1 );
}
@@ -219,11 +222,18 @@ void TrackContainerView::realignTracks()
void TrackContainerView::createTrackView( Track * _t )
TrackView * TrackContainerView::createTrackView( Track * _t )
{
//m_tc->addJournalCheckPoint();
_t->createView( this );
// Avoid duplicating track views
for( trackViewList::iterator it = m_trackViews.begin();
it != m_trackViews.end(); ++it )
{
if ( ( *it )->getTrack() == _t ) { return ( *it ); }
}
return _t->createView( this );
}