X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=futatabi%2Fclip_list.cpp;h=f76906f2a2b4f539a02506f2a01324e6c17b8836;hb=refs%2Fheads%2Fmaster;hp=0bb73ae404e367bc8c52d106928a4e435749c044;hpb=e64a84bb856263242278afa9770ae5d05e21b055;p=nageru diff --git a/futatabi/clip_list.cpp b/futatabi/clip_list.cpp index 0bb73ae..f76906f 100644 --- a/futatabi/clip_list.cpp +++ b/futatabi/clip_list.cpp @@ -141,7 +141,7 @@ QVariant PlayList::data(const QModelIndex &parent, int role) const } if (role == Qt::BackgroundRole) { if (Column(column) == Column::PLAYING) { - auto it = current_progress.find(row); + auto it = current_progress.find(clips[row].id); if (it != current_progress.end()) { double play_progress = it->second; @@ -167,37 +167,37 @@ QVariant PlayList::data(const QModelIndex &parent, int role) const switch (Column(column)) { case Column::PLAYING: - return current_progress.count(row) ? "→" : ""; + return current_progress.count(clips[row].id) ? "→" : ""; case Column::IN: - return QString::fromStdString(pts_to_string(clips[row].pts_in)); + return QString::fromStdString(pts_to_string(clips[row].clip.pts_in)); case Column::OUT: - if (clips[row].pts_out >= 0) { - return QString::fromStdString(pts_to_string(clips[row].pts_out)); + if (clips[row].clip.pts_out >= 0) { + return QString::fromStdString(pts_to_string(clips[row].clip.pts_out)); } else { return QVariant(); } case Column::DURATION: - if (clips[row].pts_out >= 0) { - return QString::fromStdString(duration_to_string(clips[row].pts_out - clips[row].pts_in)); + if (clips[row].clip.pts_out >= 0) { + return QString::fromStdString(duration_to_string(clips[row].clip.pts_out - clips[row].clip.pts_in)); } else { return QVariant(); } case Column::CAMERA: - return qlonglong(clips[row].stream_idx + 1); + return qlonglong(clips[row].clip.stream_idx + 1); case Column::DESCRIPTION: - return QString::fromStdString(clips[row].descriptions[clips[row].stream_idx]); + return QString::fromStdString(clips[row].clip.descriptions[clips[row].clip.stream_idx]); case Column::FADE_TIME: { stringstream ss; ss.imbue(locale("C")); ss.precision(3); - ss << fixed << clips[row].fade_time_seconds; + ss << fixed << clips[row].clip.fade_time_seconds; return QString::fromStdString(ss.str()); } case Column::SPEED: { stringstream ss; ss.imbue(locale("C")); ss.precision(3); - ss << fixed << clips[row].speed; + ss << fixed << clips[row].clip.speed; return QString::fromStdString(ss.str()); } default: @@ -323,7 +323,7 @@ bool PlayList::setData(const QModelIndex &index, const QVariant &value, int role switch (Column(column)) { case Column::DESCRIPTION: - clips[row].descriptions[clips[row].stream_idx] = value.toString().toStdString(); + clips[row].clip.descriptions[clips[row].clip.stream_idx] = value.toString().toStdString(); emit_data_changed(row); return true; case Column::CAMERA: { @@ -332,7 +332,7 @@ bool PlayList::setData(const QModelIndex &index, const QVariant &value, int role if (!ok || camera_idx < 1 || camera_idx > int(num_cameras)) { return false; } - clips[row].stream_idx = camera_idx - 1; + clips[row].clip.stream_idx = camera_idx - 1; emit_data_changed(row); return true; } @@ -342,7 +342,7 @@ bool PlayList::setData(const QModelIndex &index, const QVariant &value, int role if (!ok || !(val >= 0.0)) { return false; } - clips[row].fade_time_seconds = val; + clips[row].clip.fade_time_seconds = val; emit_data_changed(row); return true; } @@ -352,7 +352,7 @@ bool PlayList::setData(const QModelIndex &index, const QVariant &value, int role if (!ok || !(val >= 0.001)) { return false; } - clips[row].speed = val; + clips[row].clip.speed = val; emit_data_changed(row); return true; } @@ -372,15 +372,20 @@ void ClipList::add_clip(const Clip &clip) void PlayList::add_clip(const Clip &clip) { beginInsertRows(QModelIndex(), clips.size(), clips.size()); - clips.push_back(clip); + clips.emplace_back(ClipWithID{ clip, clip_counter++ }); endInsertRows(); emit any_content_changed(); } void PlayList::duplicate_clips(size_t first, size_t last) { - beginInsertRows(QModelIndex(), first, last); - clips.insert(clips.begin() + first, clips.begin() + first, clips.begin() + last + 1); + beginInsertRows(QModelIndex(), last + 1, last + 1 + (last - first)); + + vector new_clips; + for (auto it = clips.begin() + first; it <= clips.begin() + last; ++it) { + new_clips.emplace_back(ClipWithID{ it->clip, clip_counter++ }); // Give them new IDs. + } + clips.insert(clips.begin() + last + 1, new_clips.begin(), new_clips.end()); // Note: The new elements are inserted after the old ones. endInsertRows(); emit any_content_changed(); } @@ -433,22 +438,18 @@ void ClipList::change_num_cameras(size_t num_cameras) emit any_content_changed(); } -void PlayList::set_progress(const map &progress) +void PlayList::set_progress(const map &progress) { const int column = int(Column::PLAYING); - map old_progress = move(this->current_progress); + map old_progress = move(this->current_progress); this->current_progress = progress; - for (auto it : old_progress) { - size_t index = it.first; - if (current_progress.count(index) == 0) { - emit dataChanged(this->index(index, column), this->index(index, column)); + for (size_t row = 0; row < clips.size(); ++row) { + uint64_t id = clips[row].id; + if (current_progress.count(id) || old_progress.count(id)) { + emit dataChanged(this->index(row, column), this->index(row, column)); } } - for (auto it : current_progress) { - size_t index = it.first; - emit dataChanged(this->index(index, column), this->index(index, column)); - } } namespace { @@ -504,15 +505,15 @@ ClipListProto ClipList::serialize() const PlayList::PlayList(const ClipListProto &serialized) { for (const ClipProto &clip_proto : serialized.clip()) { - clips.push_back(deserialize_clip(clip_proto)); + clips.emplace_back(ClipWithID{ deserialize_clip(clip_proto), clip_counter++ }); } } ClipListProto PlayList::serialize() const { ClipListProto ret; - for (const Clip &clip : clips) { - serialize_clip(clip, ret.add_clip()); + for (const ClipWithID &clip : clips) { + serialize_clip(clip.clip, ret.add_clip()); } return ret; }