changeset 630:11a664058dd8

* Start revamping the CSV import dialog so as to show a "purpose" for each column. These are estimated from the file now, but changing them does not actually do anything yet.
author Chris Cannam
date Fri, 16 Jul 2010 16:51:39 +0000
parents 35499d48a5d1
children 3a5ee4b6c9ad
files data/fileio/CSVFormat.cpp data/fileio/CSVFormat.h
diffstat 2 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CSVFormat.cpp	Thu Jul 15 15:27:21 2010 +0000
+++ b/data/fileio/CSVFormat.cpp	Fri Jul 16 16:51:39 2010 +0000
@@ -250,6 +250,37 @@
         if (m_columnPurposes[i] == ColumnValue) ++valueCount;
     }
 
+    if (valueCount == 2 && timingColumnCount == 1) {
+        // If we have exactly two apparent value columns and only one
+        // timing column, but one value column is integral and the
+        // other is not, guess that whichever one matches the integral
+        // status of the time column is either duration or end time
+        if (m_timingType == ExplicitTiming) {
+            int a = -1, b = -1;
+            for (int i = 0; i < m_columnCount; ++i) {
+                if (m_columnPurposes[i] == ColumnValue) {
+                    if (a == -1) a = i;
+                    else b = i;
+                }
+            }
+            if ((m_columnQualities[a] & ColumnIntegral) !=
+                (m_columnQualities[b] & ColumnIntegral)) {
+                int timecol = a;
+                if ((m_columnQualities[a] & ColumnIntegral) !=
+                    (m_columnQualities[0] & ColumnIntegral)) {
+                    timecol = b;
+                }
+                if (m_columnQualities[timecol] & ColumnIncreasing) {
+                    // This shouldn't happen; should have been settled above
+                    m_columnPurposes[timecol] = ColumnEndTime;
+                } else {
+                    m_columnPurposes[timecol] = ColumnDuration;
+                }
+                --valueCount;
+            }
+        }
+    }
+
     if (valueCount == 0) {
         m_modelType = OneDimensionalModel;
     } else if (valueCount == 1) {
--- a/data/fileio/CSVFormat.h	Thu Jul 15 15:27:21 2010 +0000
+++ b/data/fileio/CSVFormat.h	Fri Jul 16 16:51:39 2010 +0000
@@ -95,9 +95,12 @@
     QString      getSeparator()     const { return m_separator;     }
     size_t       getSampleRate()    const { return m_sampleRate;    }
     size_t       getWindowSize()    const { return m_windowSize;    }
+    int          getColumnCount()   const { return m_columnCount;   }
     
     QString::SplitBehavior getSplitBehaviour() const { return m_behaviour; }
     QList<ColumnPurpose> getColumnPurposes() const { return m_columnPurposes; }
+
+    ColumnPurpose getColumnPurpose(int i) { return m_columnPurposes[i]; }
 	
     void setModelType(ModelType t)        { m_modelType    = t; }
     void setTimingType(TimingType t)      { m_timingType   = t; }
@@ -106,10 +109,13 @@
     void setSeparator(QString s)          { m_separator    = s; }
     void setSampleRate(size_t r)          { m_sampleRate   = r; }
     void setWindowSize(size_t s)          { m_windowSize   = s; }
+    void setColumnCount(int c)            { m_columnCount  = c; }
 
     void setSplitBehaviour(QString::SplitBehavior b) { m_behaviour = b; }
     void setColumnPurposes(QList<ColumnPurpose> cl) { m_columnPurposes = cl; }
     
+    void setColumnPurpose(int i, ColumnPurpose p) { m_columnPurposes[i] = p; }
+
     // read-only; only valid if format has been guessed:
     QList<ColumnQualities> getColumnQualities() const { return m_columnQualities; }