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