diff data/model/SparseOneDimensionalModel.h @ 422:4caa28a0a8a2

* sorting arbitrary columns in data editor
author Chris Cannam
date Thu, 12 Jun 2008 09:03:00 +0000
parents 50a956688baa
children 6a96bff0bd59
line wrap: on
line diff
--- a/data/model/SparseOneDimensionalModel.h	Wed Jun 11 17:00:04 2008 +0000
+++ b/data/model/SparseOneDimensionalModel.h	Thu Jun 12 09:03:00 2008 +0000
@@ -130,17 +130,20 @@
 
     virtual QVariant getData(int row, int column, int role) const
     {
-        if (role != Qt::EditRole && role != Qt::DisplayRole) return QVariant();
+        if (role != Qt::EditRole &&
+            role != Qt::DisplayRole &&
+            role != SortRole) return QVariant();
         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 QVariant(int(i->frame));
-        case 2: return QVariant(i->label);
+        case 1: return int(i->frame);
+        case 2: return i->label;
         default: return QVariant();
         }
     }
@@ -149,6 +152,12 @@
     {
         return (column < 2); 
     }
+
+    virtual SortType getSortType(int column) const
+    {
+        if (column == 2) return SortAlphabetical;
+        return SortNumeric;
+    }
 };
 
 #endif