changeset 425:f5e8f12d2e58

* Add audio device selection to preferences * Add (not yet functional) insert, delete, edit buttons to data edit window * Add proper set methods for time fields in data edit window (using general sparse model base class)
author Chris Cannam
date Fri, 13 Jun 2008 21:09:43 +0000
parents eafef13bb0b3
children 2386582f67cd
files data/model/ImageModel.h data/model/ModelDataTableModel.cpp data/model/NoteModel.h data/model/PathModel.h data/model/SparseModel.h data/model/SparseOneDimensionalModel.h data/model/SparseTimeValueModel.h data/model/TabularModel.h data/model/TextModel.h
diffstat 9 files changed, 105 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/data/model/ImageModel.h	Thu Jun 12 14:33:45 2008 +0000
+++ b/data/model/ImageModel.h	Fri Jun 13 21:09:43 2008 +0000
@@ -159,16 +159,15 @@
 
     virtual QVariant getData(int row, int column, int role) const
     {
+        if (column < 2) {
+            return SparseModel<ImagePoint>::getData
+                (row, column, role);
+        }
+
         PointListIterator i = getPointListIteratorForRow(row);
         if (i == m_points.end()) return QVariant();
 
         switch (column) {
-        case 0: {
-            if (role == SortRole) return int(i->frame);
-            RealTime rt = RealTime::frame2RealTime(i->frame, getSampleRate());
-            return rt.toText().c_str();
-        }
-        case 1: return int(i->frame);
         case 2: return i->image;
         case 3: return i->label;
         default: return QVariant();
@@ -177,6 +176,11 @@
 
     virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role)
     {
+        if (column < 2) {
+            return SparseModel<ImagePoint>::getSetDataCommand
+                (row, column, value, role);
+        }
+
         if (role != Qt::EditRole) return false;
         PointListIterator i = getPointListIteratorForRow(row);
         if (i == m_points.end()) return false;
@@ -186,7 +190,6 @@
         command->deletePoint(point);
 
         switch (column) {
-        case 0: case 1: point.frame = value.toInt(); break; 
         case 2: point.image = value.toString(); break;
         case 3: point.label = value.toString(); break;
         }
--- a/data/model/ModelDataTableModel.cpp	Thu Jun 12 14:33:45 2008 +0000
+++ b/data/model/ModelDataTableModel.cpp	Fri Jun 13 21:09:43 2008 +0000
@@ -74,9 +74,12 @@
 QVariant
 ModelDataTableModel::headerData(int section, Qt::Orientation orientation, int role) const
 {
+    if (orientation == Qt::Vertical && role == Qt::DisplayRole) {
+        return section + 1;
+    }
     if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
         return m_model->getHeading(section);
-    }
+    } 
     return QVariant();
 }
 
--- a/data/model/NoteModel.h	Thu Jun 12 14:33:45 2008 +0000
+++ b/data/model/NoteModel.h	Fri Jun 13 21:09:43 2008 +0000
@@ -186,16 +186,15 @@
 
     virtual QVariant getData(int row, int column, int role) const
     {
+        if (column < 2) {
+            return SparseValueModel<Note>::getData
+                (row, column, role);
+        }
+
         PointListIterator i = getPointListIteratorForRow(row);
         if (i == m_points.end()) return QVariant();
 
         switch (column) {
-        case 0: {
-            if (role == SortRole) return int(i->frame);
-            RealTime rt = RealTime::frame2RealTime(i->frame, getSampleRate());
-            return rt.toText().c_str();
-        }
-        case 1: return int(i->frame);
         case 2:
             if (role == Qt::EditRole || role == SortRole) return i->value;
             else return QString("%1 %2").arg(i->value).arg(getScaleUnits());
@@ -208,6 +207,11 @@
 
     virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role)
     {
+        if (column < 2) {
+            return SparseValueModel<Note>::getSetDataCommand
+                (row, column, value, role);
+        }
+
         if (role != Qt::EditRole) return false;
         PointListIterator i = getPointListIteratorForRow(row);
         if (i == m_points.end()) return false;
--- a/data/model/PathModel.h	Thu Jun 12 14:33:45 2008 +0000
+++ b/data/model/PathModel.h	Fri Jun 13 21:09:43 2008 +0000
@@ -80,6 +80,14 @@
              QString("%1 subtype=\"path\"")
              .arg(extraAttributes));
     }
+
+    /**
+     * TabularModel is inherited via SparseModel, but we don't need it here.
+     */
+    virtual QString getHeading(int) const { return ""; }
+    virtual bool isColumnTimeValue(int) const { return false; }
+    virtual SortType getSortType(int) const { return SortNumeric; }
+
 };
 
 
--- a/data/model/SparseModel.h	Thu Jun 12 14:33:45 2008 +0000
+++ b/data/model/SparseModel.h	Fri Jun 13 21:09:43 2008 +0000
@@ -19,6 +19,7 @@
 #include "Model.h"
 #include "TabularModel.h"
 #include "base/Command.h"
+#include "base/RealTime.h"
 
 #include <iostream>
 
@@ -26,6 +27,8 @@
 #include <vector>
 #include <algorithm>
 
+#include <cmath>
+
 #include <QMutex>
 #include <QTextStream>
 
@@ -286,15 +289,44 @@
         return std::distance(m_rows.begin(), i);
     }
 
-    //!!! just for now
     virtual int getColumnCount() const { return 1; }
-    virtual QString getHeading(int column) const { return tr("Unknown"); }
-    virtual QVariant getData(int row, int column, int role) const {
+    virtual QVariant getData(int row, int column, int role) const
+    {
+        PointListIterator i = getPointListIteratorForRow(row);
+        if (i == m_points.end()) return QVariant();
+
+        switch (column) {
+        case 0: {
+            if (role == SortRole) return int(i->frame);
+            RealTime rt = RealTime::frame2RealTime(i->frame, getSampleRate());
+            if (role == Qt::EditRole) return rt.toString().c_str();
+            else return rt.toText().c_str();
+        }
+        case 1: return int(i->frame);
+        }
+
         return QVariant();
     }
-    virtual bool isColumnTimeValue(int column) const { return true; }
-    virtual SortType getSortType(int column) const { return SortNumeric; }
-    
+    virtual Command *getSetDataCommand(int row, int column,
+                                       const QVariant &value, int role)
+    {
+        if (role != Qt::EditRole) return false;
+        PointListIterator i = getPointListIteratorForRow(row);
+        if (i == m_points.end()) return false;
+        EditCommand *command = new EditCommand(this, tr("Edit Data"));
+
+        Point point(*i);
+        command->deletePoint(point);
+
+        switch (column) {
+        case 0: point.frame = lrint(value.toDouble() * getSampleRate()); break;
+        case 1: point.frame = value.toInt(); break; 
+        }
+
+        command->addPoint(point);
+        return command->finish();
+    }
+
 protected:
     size_t m_sampleRate;
     size_t m_resolution;
@@ -326,7 +358,7 @@
     PointListIterator getPointListIteratorForRow(int row) const
     {
         if (m_rows.empty()) rebuildRowVector();
-        if (row < 0 || row + 1 > m_rows.size()) return m_points.end();
+        if (row < 0 || row + 1 > int(m_rows.size())) return m_points.end();
 
         size_t frame = m_rows[row];
         int indexAtFrame = 0;
@@ -395,11 +427,14 @@
 Model *
 SparseModel<PointType>::clone() const
 {
+    return 0; //!!! is this ever used?
+/*
     SparseModel<PointType> *model =
 	new SparseModel<PointType>(m_sampleRate, m_resolution, m_notifyOnAdd);
     model->m_points = m_points;
     model->m_pointCount = m_pointCount;
     return model;
+*/
 }
 
 template <typename PointType>
--- a/data/model/SparseOneDimensionalModel.h	Thu Jun 12 14:33:45 2008 +0000
+++ b/data/model/SparseOneDimensionalModel.h	Fri Jun 13 21:09:43 2008 +0000
@@ -132,16 +132,15 @@
 
     virtual QVariant getData(int row, int column, int role) const
     {
+        if (column < 2) {
+            return SparseModel<OneDimensionalPoint>::getData
+                (row, column, role);
+        }
+
         PointListIterator i = getPointListIteratorForRow(row);
         if (i == m_points.end()) return QVariant();
 
         switch (column) {
-        case 0: {
-            if (role == SortRole) return int(i->frame);
-            RealTime rt = RealTime::frame2RealTime(i->frame, getSampleRate());
-            return QVariant(rt.toText().c_str());
-        }
-        case 1: return int(i->frame);
         case 2: return i->label;
         default: return QVariant();
         }
@@ -149,6 +148,11 @@
 
     virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role)
     {
+        if (column < 2) {
+            return SparseModel<OneDimensionalPoint>::getSetDataCommand
+                (row, column, value, role);
+        }
+
         if (role != Qt::EditRole) return false;
         PointListIterator i = getPointListIteratorForRow(row);
         if (i == m_points.end()) return false;
@@ -158,7 +162,6 @@
         command->deletePoint(point);
 
         switch (column) {
-        case 0: case 1: point.frame = value.toInt(); break; 
         case 2: point.label = value.toString(); break;
         }
 
--- a/data/model/SparseTimeValueModel.h	Thu Jun 12 14:33:45 2008 +0000
+++ b/data/model/SparseTimeValueModel.h	Fri Jun 13 21:09:43 2008 +0000
@@ -122,16 +122,15 @@
 
     virtual QVariant getData(int row, int column, int role) const
     {
+        if (column < 2) {
+            return SparseValueModel<TimeValuePoint>::getData
+                (row, column, role);
+        }
+
         PointListIterator i = getPointListIteratorForRow(row);
         if (i == m_points.end()) return QVariant();
 
         switch (column) {
-        case 0: {
-            if (role == SortRole) return int(i->frame);
-            RealTime rt = RealTime::frame2RealTime(i->frame, getSampleRate());
-            return rt.toText().c_str();
-        }
-        case 1: return int(i->frame);
         case 2:
             if (role == Qt::EditRole || role == SortRole) return i->value;
             else return QString("%1 %2").arg(i->value).arg(getScaleUnits());
@@ -142,6 +141,11 @@
 
     virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role)
     {
+        if (column < 2) {
+            return SparseValueModel<TimeValuePoint>::getSetDataCommand
+                (row, column, value, role);
+        }
+
         if (role != Qt::EditRole) return false;
         PointListIterator i = getPointListIteratorForRow(row);
         if (i == m_points.end()) return false;
@@ -151,7 +155,6 @@
         command->deletePoint(point);
 
         switch (column) {
-        case 0: case 1: point.frame = value.toInt(); break; 
         case 2: point.value = value.toDouble(); break;
         case 3: point.label = value.toString(); break;
         }
--- a/data/model/TabularModel.h	Thu Jun 12 14:33:45 2008 +0000
+++ b/data/model/TabularModel.h	Fri Jun 13 21:09:43 2008 +0000
@@ -50,7 +50,7 @@
     virtual int getRowForFrame(long frame) const = 0;
 
     virtual bool isEditable() const { return false; }
-    virtual Command *getSetDataCommand(int row, int column, const QVariant &, int role) { return 0; }
+    virtual Command *getSetDataCommand(int /* row */, int /* column */, const QVariant &, int /* role */) { return 0; }
 };
 
 #endif
--- a/data/model/TextModel.h	Thu Jun 12 14:33:45 2008 +0000
+++ b/data/model/TextModel.h	Fri Jun 13 21:09:43 2008 +0000
@@ -124,16 +124,15 @@
 
     virtual QVariant getData(int row, int column, int role) const
     {
+        if (column < 2) {
+            return SparseModel<TextPoint>::getData
+                (row, column, role);
+        }
+
         PointListIterator i = getPointListIteratorForRow(row);
         if (i == m_points.end()) return QVariant();
 
         switch (column) {
-        case 0: {
-            if (role == SortRole) return int(i->frame);
-            RealTime rt = RealTime::frame2RealTime(i->frame, getSampleRate());
-            return rt.toText().c_str();
-        }
-        case 1: return int(i->frame);
         case 2: return i->height;
         case 3: return i->label;
         default: return QVariant();
@@ -142,6 +141,11 @@
 
     virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role)
     {
+        if (column < 2) {
+            return SparseModel<TextPoint>::getSetDataCommand
+                (row, column, value, role);
+        }
+
         if (role != Qt::EditRole) return false;
         PointListIterator i = getPointListIteratorForRow(row);
         if (i == m_points.end()) return false;
@@ -151,7 +155,6 @@
         command->deletePoint(point);
 
         switch (column) {
-        case 0: case 1: point.frame = value.toInt(); break; 
         case 2: point.height = value.toDouble(); break;
         case 3: point.label = value.toString(); break;
         }