From: Steinar H. Gunderson Date: Sun, 17 Jun 2018 10:09:37 +0000 (+0200) Subject: Make it possible to edit the description in the play list. X-Git-Tag: 1.8.0~76^2~264 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=7d9f083a4b4e816350d9e88f94e7b8656a2111ce;p=nageru Make it possible to edit the description in the play list. --- diff --git a/clip_list.cpp b/clip_list.cpp index cdf9780..e15fbfe 100644 --- a/clip_list.cpp +++ b/clip_list.cpp @@ -229,6 +229,22 @@ Qt::ItemFlags ClipList::flags(const QModelIndex &index) const } } +Qt::ItemFlags PlayList::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + const int row = index.row(), column = index.column(); + if (size_t(row) >= clips.size()) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + + switch (Column(column)) { + case Column::DESCRIPTION: + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; + default: + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + } +} + bool ClipList::setData(const QModelIndex &index, const QVariant &value, int role) { if (!index.isValid() || role != Qt::EditRole) { @@ -254,6 +270,26 @@ bool ClipList::setData(const QModelIndex &index, const QVariant &value, int role } } +bool PlayList::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (!index.isValid() || role != Qt::EditRole) { + return false; + } + + const int row = index.row(), column = index.column(); + if (size_t(row) >= clips.size()) + return false; + + switch (Column(column)) { + case Column::DESCRIPTION: + clips[row].descriptions[clips[row].stream_idx] = value.toString().toStdString(); + emit_data_changed(row); + return true; + default: + return false; + } +} + void ClipList::add_clip(const Clip &clip) { beginInsertRows(QModelIndex(), clips.size(), clips.size()); diff --git a/clip_list.h b/clip_list.h index 076d493..64d06cd 100644 --- a/clip_list.h +++ b/clip_list.h @@ -100,6 +100,8 @@ public: int columnCount(const QModelIndex &parent) const override; QVariant data(const QModelIndex &parent, int role) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + Qt::ItemFlags flags(const QModelIndex &index) const override; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; void add_clip(const Clip &clip); size_t size() const { return clips.size(); }