]> git.sesse.net Git - nageru/commitdiff
Make it possible to edit the description in the play list.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 17 Jun 2018 10:09:37 +0000 (12:09 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 17 Jun 2018 10:09:37 +0000 (12:09 +0200)
clip_list.cpp
clip_list.h

index cdf97807e3213a35e7a149fb4a3dbc9adbfd5d21..e15fbfe79aae0d712448930e5dd951cb11894765 100644 (file)
@@ -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());
index 076d4930ad718e34ccfd37627720ef305ca001a5..64d06cd29f19633da0b82c1f9355442c49bcb44f 100644 (file)
@@ -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(); }