diff widgets/CSVFormatDialog.cpp @ 971:fd934705973f

Fix crash when importing wide CSV file
author Chris Cannam
date Fri, 22 May 2015 10:42:15 +0100
parents 2633a1d73e39
children e5d40d89b1ec
line wrap: on
line diff
--- a/widgets/CSVFormatDialog.cpp	Fri May 22 09:17:52 2015 +0100
+++ b/widgets/CSVFormatDialog.cpp	Fri May 22 10:42:15 2015 +0100
@@ -252,15 +252,17 @@
 void
 CSVFormatDialog::applyStartTimePurpose()
 {
-    // First check if we already have any
-    for (int i = 0; i < m_format.getColumnCount(); ++i) {
+    // 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)
+    for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
         QComboBox *cb = m_columnPurposeCombos[i];
         if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) {
             return;
         }
     }
     // and if not, select one
-    for (int i = 0; i < m_format.getColumnCount(); ++i) {
+    for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
         QComboBox *cb = m_columnPurposeCombos[i];
         if (cb->currentIndex() == int(CSVFormat::ColumnValue)) {
             cb->setCurrentIndex(int(CSVFormat::ColumnStartTime));
@@ -272,7 +274,10 @@
 void
 CSVFormatDialog::removeStartTimePurpose()
 {
-    for (int i = 0; i < m_format.getColumnCount(); ++i) {
+    // NB there may be fewer than m_format.getColumnCount() elements
+    // in m_columnPurposeCombos (because of the fuzzy column
+    // behaviour)
+    for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
         QComboBox *cb = m_columnPurposeCombos[i];
         if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) {
             cb->setCurrentIndex(int(CSVFormat::ColumnValue));