Commit 719d8f15 authored by Nicolas Carion's avatar Nicolas Carion

[Timeline2][Qml] Fix confusion between track Index and track ID (still segfaulting on track change)

parent 205c0500
...@@ -188,7 +188,7 @@ QHash<int, QByteArray> TimelineModel::roleNames() const ...@@ -188,7 +188,7 @@ QHash<int, QByteArray> TimelineModel::roleNames() const
roles[FileHashRole] = "hash"; roles[FileHashRole] = "hash";
roles[SpeedRole] = "speed"; roles[SpeedRole] = "speed";
roles[HeightRole] = "trackHeight"; roles[HeightRole] = "trackHeight";
roles[ClipIndex] = "clipIndex"; roles[ItemIdRole] = "item";
return roles; return roles;
} }
...@@ -198,14 +198,14 @@ QVariant TimelineModel::data(const QModelIndex &index, int role) const ...@@ -198,14 +198,14 @@ QVariant TimelineModel::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
} }
const int id = (int)index.internalId(); const int id = (int)index.internalId();
if (role == ItemIdRole) {
return id;
}
//qDebug() << "DATA requested "<<index<<roleNames()[role]; //qDebug() << "DATA requested "<<index<<roleNames()[role];
if (isClip(id)) { if (isClip(id)) {
// Get data for a clip // Get data for a clip
switch (role) { switch (role) {
//TODO //TODO
case ClipIndex:
return id;
break;
case NameRole: case NameRole:
case ResourceRole: case ResourceRole:
case Qt::DisplayRole:{ case Qt::DisplayRole:{
...@@ -309,6 +309,11 @@ int TimelineModel::getClipPosition(int cid) const ...@@ -309,6 +309,11 @@ int TimelineModel::getClipPosition(int cid) const
bool TimelineModel::allowClipMove(int cid, int tid, int position) bool TimelineModel::allowClipMove(int cid, int tid, int position)
{ {
qDebug()<<"Checking clip move"<<cid<<tid<<position;
if (!isClip(cid) || !isTrack(tid)) {
qDebug() << "ERROR : Invalid clip or track";
return false;
}
int length = m_allClips[cid]->getPlaytime(); int length = m_allClips[cid]->getPlaytime();
return getTrackById(tid)->allowClipMove(cid, position, length); return getTrackById(tid)->allowClipMove(cid, position, length);
} }
......
...@@ -101,7 +101,7 @@ public: ...@@ -101,7 +101,7 @@ public:
IsTransitionRole,/// clip only IsTransitionRole,/// clip only
FileHashRole, /// clip only FileHashRole, /// clip only
SpeedRole, /// clip only SpeedRole, /// clip only
ClipIndex /// clip only ItemIdRole
}; };
int rowCount(const QModelIndex & parent = QModelIndex()) const Q_DECL_OVERRIDE; int rowCount(const QModelIndex & parent = QModelIndex()) const Q_DECL_OVERRIDE;
......
...@@ -39,9 +39,10 @@ Rectangle { ...@@ -39,9 +39,10 @@ Rectangle {
property var audioLevels property var audioLevels
property int fadeIn: 0 property int fadeIn: 0
property int fadeOut: 0 property int fadeOut: 0
property int trackIndex property int trackIndex //Index in track repeater
property int originalTrackIndex: trackIndex property int trackId: -42 //Id in the model
property int originalClipIndex property int clipId //Id of the clip in the model
property int originalTrackId: trackId
property int originalX: x property int originalX: x
property int draggedX: x property int draggedX: x
property bool selected: false property bool selected: false
...@@ -59,7 +60,7 @@ Rectangle { ...@@ -59,7 +60,7 @@ Rectangle {
signal trimmedOut(var clip) signal trimmedOut(var clip)
onModelStartChanged: { onModelStartChanged: {
console.log("MODEL START CHANGED !!!!!!", modelStart, originalClipIndex, x); console.log("MODEL START CHANGED !!!!!!", modelStart, clipId, x);
x = modelStart * timeScale; x = modelStart * timeScale;
} }
SystemPalette { id: activePalette } SystemPalette { id: activePalette }
...@@ -252,7 +253,7 @@ Rectangle { ...@@ -252,7 +253,7 @@ Rectangle {
onPressed: { onPressed: {
root.stopScrolling = true root.stopScrolling = true
originalX = parent.x originalX = parent.x
originalTrackIndex = trackIndex originalTrackId = clipRoot.trackId
startX = parent.x startX = parent.x
clipRoot.forceActiveFocus(); clipRoot.forceActiveFocus();
clipRoot.clicked(clipRoot) clipRoot.clicked(clipRoot)
...@@ -268,10 +269,10 @@ Rectangle { ...@@ -268,10 +269,10 @@ Rectangle {
root.stopScrolling = false root.stopScrolling = false
parent.y = 0 parent.y = 0
var delta = parent.x - startX var delta = parent.x - startX
if (Math.abs(delta) >= 1.0 || trackIndex !== originalTrackIndex) { if (Math.abs(delta) >= 1.0 || trackId !== originalTrackId) {
parent.moved(clipRoot) parent.moved(clipRoot)
originalX = parent.x originalX = parent.x
originalTrackIndex = trackIndex originalTrackId = trackId
} else { } else {
parent.dropped(clipRoot) parent.dropped(clipRoot)
} }
......
...@@ -30,6 +30,7 @@ Column{ ...@@ -30,6 +30,7 @@ Column{
property bool isCurrentTrack: false property bool isCurrentTrack: false
property bool isLocked: false property bool isLocked: false
property var selection property var selection
property int trackId : -42
height: parent.height height: parent.height
SystemPalette { id: activePalette } SystemPalette { id: activePalette }
...@@ -69,7 +70,7 @@ Column{ ...@@ -69,7 +70,7 @@ Column{
inPoint: model.in inPoint: model.in
outPoint: model.out outPoint: model.out
isBlank: model.blank isBlank: model.blank
originalClipIndex: model.clipIndex clipId: model.item
isAudio: false //model.audio isAudio: false //model.audio
isTransition: false //model.isTransition isTransition: false //model.isTransition
audioLevels: false //model.audioLevels audioLevels: false //model.audioLevels
...@@ -78,6 +79,7 @@ Column{ ...@@ -78,6 +79,7 @@ Column{
x: model.start * timeScale x: model.start * timeScale
modelStart: model.start modelStart: model.start
trackIndex: trackRoot.DelegateModel.itemsIndex trackIndex: trackRoot.DelegateModel.itemsIndex
trackId: trackRoot.trackId
fadeIn: 0 //model.fadeIn fadeIn: 0 //model.fadeIn
fadeOut: 0 //model.fadeOut fadeOut: 0 //model.fadeOut
//hash: model.hash //hash: model.hash
...@@ -90,9 +92,9 @@ Column{ ...@@ -90,9 +92,9 @@ Column{
clip.draggedX = clip.x clip.draggedX = clip.x
} }
onMoved: { onMoved: {
var fromTrack = clip.originalTrackIndex var fromTrack = clip.originalTrackId
var toTrack = clip.trackIndex var toTrack = clip.trackId
var cIndex = clip.originalClipIndex var cIndex = clip.clipId
var frame = Math.round(clip.x / timeScale) var frame = Math.round(clip.x / timeScale)
// Remove the placeholder inserted in onDraggedToTrack // Remove the placeholder inserted in onDraggedToTrack
...@@ -107,19 +109,24 @@ Column{ ...@@ -107,19 +109,24 @@ Column{
else else
trackModel.items.remove(cIndex, 1) trackModel.items.remove(cIndex, 1)
} }
console.log("Asking move ",toTrack, cIndex, frame)
var val = timeline.moveClip(fromTrack, toTrack, cIndex, frame, true)
console.log("RESULT", val)
/*
if (!timeline.moveClip(fromTrack, toTrack, cIndex, frame, false)) if (!timeline.moveClip(fromTrack, toTrack, cIndex, frame, false))
clip.x = clip.originalX clip.x = clip.originalX
else { else {
//TODO This hacky, find a better way... //TODO This hacky, find a better way...
var oldFrame = Math.round(clip.originalX / timeScale) //var oldFrame = Math.round(clip.originalX / .timeScale)
timeline.moveClip(fromTrack, toTrack, cIndex, oldFrame, false) // timeline.moveClip(fromTrack, toTrack, cIndex, oldFrame, false)
timeline.moveClip(fromTrack, toTrack, cIndex, frame, true) timeline.moveClip(fromTrack, toTrack, cIndex, frame, true)
} }
*/
} }
onDragged: { onDragged: {
var fromTrack = clip.originalTrackIndex var fromTrack = clip.originalTrackId
var toTrack = clip.trackIndex var toTrack = clip.trackId
var cIndex = clip.originalClipIndex var cIndex = clip.clipId
var frame = Math.round(clip.x / timeScale) var frame = Math.round(clip.x / timeScale)
/*if (toolbar.scrub) { /*if (toolbar.scrub) {
root.stopScrolling = false root.stopScrolling = false
......
...@@ -334,6 +334,7 @@ Rectangle { ...@@ -334,6 +334,7 @@ Rectangle {
isAudio: audio isAudio: audio
isCurrentTrack: currentTrack === index isCurrentTrack: currentTrack === index
timeScale: timeline.scaleFactor timeScale: timeline.scaleFactor
trackId: item
selection: timeline.selection selection: timeline.selection
onClipClicked: { onClipClicked: {
currentTrack = track.DelegateModel.itemsIndex currentTrack = track.DelegateModel.itemsIndex
...@@ -377,6 +378,7 @@ Rectangle { ...@@ -377,6 +378,7 @@ Rectangle {
var track = tracksRepeater.itemAt(i) var track = tracksRepeater.itemAt(i)
clip.reparent(track) clip.reparent(track)
clip.trackIndex = track.DelegateModel.itemsIndex clip.trackIndex = track.DelegateModel.itemsIndex
clip.trackId = track.trackId
} }
} }
onCheckSnap: { onCheckSnap: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment