comparison widgets/CSVFormatDialog.cpp @ 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 fd934705973f
children a34a2a25907c
comparison
equal deleted inserted replaced
989:3871dffc31bd 992:e5d40d89b1ec
252 void 252 void
253 CSVFormatDialog::applyStartTimePurpose() 253 CSVFormatDialog::applyStartTimePurpose()
254 { 254 {
255 // First check if we already have any. NB there may be fewer than 255 // First check if we already have any. NB there may be fewer than
256 // m_format.getColumnCount() elements in m_columnPurposeCombos 256 // m_format.getColumnCount() elements in m_columnPurposeCombos
257 // (because of the fuzzy column behaviour) 257 // (because of the fuzzy column behaviour). Note also that the
258 // fuzzy column (which is the one just showing how many more
259 // columns there are) has a different combo with only two items
260 // (ignore or Values)
258 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { 261 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
262 if (i == m_fuzzyColumn) continue;
259 QComboBox *cb = m_columnPurposeCombos[i]; 263 QComboBox *cb = m_columnPurposeCombos[i];
260 if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) { 264 if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) {
261 return; 265 return;
262 } 266 }
263 } 267 }
264 // and if not, select one 268 // and if not, select one
265 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { 269 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
270 if (i == m_fuzzyColumn) continue;
266 QComboBox *cb = m_columnPurposeCombos[i]; 271 QComboBox *cb = m_columnPurposeCombos[i];
267 if (cb->currentIndex() == int(CSVFormat::ColumnValue)) { 272 if (cb->currentIndex() == int(CSVFormat::ColumnValue)) {
268 cb->setCurrentIndex(int(CSVFormat::ColumnStartTime)); 273 cb->setCurrentIndex(int(CSVFormat::ColumnStartTime));
269 return; 274 return;
270 } 275 }
276 { 281 {
277 // NB there may be fewer than m_format.getColumnCount() elements 282 // NB there may be fewer than m_format.getColumnCount() elements
278 // in m_columnPurposeCombos (because of the fuzzy column 283 // in m_columnPurposeCombos (because of the fuzzy column
279 // behaviour) 284 // behaviour)
280 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { 285 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
286 if (i == m_fuzzyColumn) continue;
281 QComboBox *cb = m_columnPurposeCombos[i]; 287 QComboBox *cb = m_columnPurposeCombos[i];
282 if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) { 288 if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) {
283 cb->setCurrentIndex(int(CSVFormat::ColumnValue)); 289 cb->setCurrentIndex(int(CSVFormat::ColumnValue));
284 } 290 }
285 } 291 }
342 // Ensure the column purpose combos are consistent with one 348 // Ensure the column purpose combos are consistent with one
343 // another, without reference to m_format (which we'll update 349 // another, without reference to m_format (which we'll update
344 // separately) 350 // separately)
345 351
346 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { 352 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
353
354 // The fuzzy column combo only has the entries <ignore> or
355 // Values, so it can't affect the timing type and none of this
356 // logic affects it
357 if (i == m_fuzzyColumn) continue;
347 358
348 QComboBox *thisCombo = m_columnPurposeCombos[i]; 359 QComboBox *thisCombo = m_columnPurposeCombos[i];
349 360
350 CSVFormat::ColumnPurpose cp = (CSVFormat::ColumnPurpose) 361 CSVFormat::ColumnPurpose cp = (CSVFormat::ColumnPurpose)
351 (thisCombo->currentIndex()); 362 (thisCombo->currentIndex());
352 bool thisChanged = (cb == thisCombo); 363 bool thisChanged = (cb == thisCombo);
353 364
354 if (!thisChanged) { 365 if (!thisChanged) {
355
356 if (i == m_fuzzyColumn) continue;
357 366
358 // We can only have one ColumnStartTime column, and only 367 // We can only have one ColumnStartTime column, and only
359 // one of either ColumnDuration or ColumnEndTime 368 // one of either ColumnDuration or ColumnEndTime
360 369
361 if (purpose == CSVFormat::ColumnStartTime) { 370 if (purpose == CSVFormat::ColumnStartTime) {
440 QComboBox *thisCombo = m_columnPurposeCombos[i]; 449 QComboBox *thisCombo = m_columnPurposeCombos[i];
441 450
442 CSVFormat::ColumnPurpose purpose = (CSVFormat::ColumnPurpose) 451 CSVFormat::ColumnPurpose purpose = (CSVFormat::ColumnPurpose)
443 (thisCombo->currentIndex()); 452 (thisCombo->currentIndex());
444 453
445 if (purpose == CSVFormat::ColumnStartTime) {
446 haveStartTime = true;
447 }
448 if (purpose == CSVFormat::ColumnEndTime ||
449 purpose == CSVFormat::ColumnDuration) {
450 haveDuration = true;
451 }
452 if (purpose == CSVFormat::ColumnPitch) {
453 havePitch = true;
454 }
455 if (purpose == CSVFormat::ColumnValue) {
456 ++valueCount;
457 }
458
459 m_format.setColumnPurpose(i, purpose);
460
461 if (i == m_fuzzyColumn) { 454 if (i == m_fuzzyColumn) {
462 for (int j = i + 1; j < m_format.getColumnCount(); ++j) { 455 for (int j = i; j < m_format.getColumnCount(); ++j) {
463 if (purpose == CSVFormat::ColumnUnknown) { 456 if (purpose == CSVFormat::ColumnUnknown) {
464 m_format.setColumnPurpose(j, CSVFormat::ColumnUnknown); 457 m_format.setColumnPurpose(j, CSVFormat::ColumnUnknown);
465 } else { // Value 458 } else { // Value
466 m_format.setColumnPurpose(j, CSVFormat::ColumnValue); 459 m_format.setColumnPurpose(j, CSVFormat::ColumnValue);
467 ++valueCount; 460 ++valueCount;
468 } 461 }
469 } 462 }
463 } else {
464
465 if (purpose == CSVFormat::ColumnStartTime) {
466 haveStartTime = true;
467 }
468 if (purpose == CSVFormat::ColumnEndTime ||
469 purpose == CSVFormat::ColumnDuration) {
470 haveDuration = true;
471 }
472 if (purpose == CSVFormat::ColumnPitch) {
473 havePitch = true;
474 }
475 if (purpose == CSVFormat::ColumnValue) {
476 ++valueCount;
477 }
478
479 m_format.setColumnPurpose(i, purpose);
470 } 480 }
471 } 481 }
472 482
473 if (haveStartTime && haveDuration) { 483 if (haveStartTime && haveDuration) {
474 if (havePitch) { 484 if (havePitch) {