changeset 992:e5d40d89b1ec

Major fix to bug in handling of fuzzy column in CSV import (introduced since the last release) which meant that col 6 of a wide CSV would go missing completely!
author Chris Cannam
date Tue, 07 Jul 2015 17:28:58 +0100
parents 3871dffc31bd
children b0662a3c4679 7dcd03517685 b247d3ffcbb9
files widgets/CSVFormatDialog.cpp
diffstat 1 files changed, 30 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/widgets/CSVFormatDialog.cpp	Wed Jul 01 15:53:54 2015 +0100
+++ b/widgets/CSVFormatDialog.cpp	Tue Jul 07 17:28:58 2015 +0100
@@ -254,8 +254,12 @@
 {
     // First check if we already have any. NB there may be fewer than
     // m_format.getColumnCount() elements in m_columnPurposeCombos
-    // (because of the fuzzy column behaviour)
+    // (because of the fuzzy column behaviour). Note also that the
+    // fuzzy column (which is the one just showing how many more
+    // columns there are) has a different combo with only two items
+    // (ignore or Values)
     for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
+        if (i == m_fuzzyColumn) continue;
         QComboBox *cb = m_columnPurposeCombos[i];
         if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) {
             return;
@@ -263,6 +267,7 @@
     }
     // and if not, select one
     for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
+        if (i == m_fuzzyColumn) continue;
         QComboBox *cb = m_columnPurposeCombos[i];
         if (cb->currentIndex() == int(CSVFormat::ColumnValue)) {
             cb->setCurrentIndex(int(CSVFormat::ColumnStartTime));
@@ -278,6 +283,7 @@
     // in m_columnPurposeCombos (because of the fuzzy column
     // behaviour)
     for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
+        if (i == m_fuzzyColumn) continue;
         QComboBox *cb = m_columnPurposeCombos[i];
         if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) {
             cb->setCurrentIndex(int(CSVFormat::ColumnValue));
@@ -345,6 +351,11 @@
     
     for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
 
+        // The fuzzy column combo only has the entries <ignore> or
+        // Values, so it can't affect the timing type and none of this
+        // logic affects it
+        if (i == m_fuzzyColumn) continue;
+
         QComboBox *thisCombo = m_columnPurposeCombos[i];
         
         CSVFormat::ColumnPurpose cp = (CSVFormat::ColumnPurpose)
@@ -353,8 +364,6 @@
         
         if (!thisChanged) {
 
-            if (i == m_fuzzyColumn) continue;
-
             // We can only have one ColumnStartTime column, and only
             // one of either ColumnDuration or ColumnEndTime
 
@@ -442,24 +451,8 @@
         CSVFormat::ColumnPurpose purpose = (CSVFormat::ColumnPurpose)
             (thisCombo->currentIndex());
 
-        if (purpose == CSVFormat::ColumnStartTime) {
-            haveStartTime = true;
-        }
-        if (purpose == CSVFormat::ColumnEndTime ||
-            purpose == CSVFormat::ColumnDuration) {
-            haveDuration = true;
-        }
-        if (purpose == CSVFormat::ColumnPitch) {
-            havePitch = true;
-        }
-        if (purpose == CSVFormat::ColumnValue) {
-            ++valueCount;
-        }
-
-        m_format.setColumnPurpose(i, purpose);
-
         if (i == m_fuzzyColumn) {
-            for (int j = i + 1; j < m_format.getColumnCount(); ++j) {
+            for (int j = i; j < m_format.getColumnCount(); ++j) {
                 if (purpose == CSVFormat::ColumnUnknown) {
                     m_format.setColumnPurpose(j, CSVFormat::ColumnUnknown);
                 } else { // Value
@@ -467,6 +460,23 @@
                     ++valueCount;
                 }
             }
+        } else {
+        
+            if (purpose == CSVFormat::ColumnStartTime) {
+                haveStartTime = true;
+            }
+            if (purpose == CSVFormat::ColumnEndTime ||
+                purpose == CSVFormat::ColumnDuration) {
+                haveDuration = true;
+            }
+            if (purpose == CSVFormat::ColumnPitch) {
+                havePitch = true;
+            }
+            if (purpose == CSVFormat::ColumnValue) {
+                ++valueCount;
+            }
+
+            m_format.setColumnPurpose(i, purpose);
         }
     }