diff widgets/CSVFormatDialog.cpp @ 581:c9d6cf9c51c8 sv_v1.8

* Cut off column dialog if there are many columns -- allow user to ignore or take values from all columns past a certain number. This sort-of fixes #39, but it's problematic if some of the extraneous columns don't contain value data. We really want to handle the case where the final column is a label, at least.
author Chris Cannam
date Mon, 04 Apr 2011 15:34:34 +0100
parents e2211947cbfd
children d8bd193ad17d
line wrap: on
line diff
--- a/widgets/CSVFormatDialog.cpp	Tue Mar 08 11:30:39 2011 +0000
+++ b/widgets/CSVFormatDialog.cpp	Mon Apr 04 15:34:34 2011 +0100
@@ -29,9 +29,12 @@
 
 #include <iostream>
 
-CSVFormatDialog::CSVFormatDialog(QWidget *parent, CSVFormat format) :
+CSVFormatDialog::CSVFormatDialog(QWidget *parent, CSVFormat format,
+                                 int maxDisplayCols) :
     QDialog(parent),
-    m_format(format)
+    m_format(format),
+    m_maxDisplayCols(maxDisplayCols),
+    m_fuzzyColumn(-1)
 {
     setModal(true);
     setWindowTitle(tr("Select Data Format"));
@@ -64,10 +67,22 @@
     QList<QStringList> example = m_format.getExample();
 
     for (int i = 0; i < columns; ++i) {
-        
+
         QComboBox *cpc = new QComboBox;
         m_columnPurposeCombos.push_back(cpc);
         exampleLayout->addWidget(cpc, 0, i);
+        connect(cpc, SIGNAL(activated(int)), this, SLOT(columnPurposeChanged(int)));
+
+        if (i == m_maxDisplayCols && columns > i + 2) {
+            m_fuzzyColumn = i;
+            cpc->addItem(tr("<ignore>"));
+            cpc->addItem(tr("Values"));
+            cpc->setCurrentIndex
+                (m_format.getColumnPurpose(i-1) == CSVFormat::ColumnUnknown ? 0 : 1);
+            exampleLayout->addWidget(new QLabel(tr("(%1 more)").arg(columns - i)),
+                                     1, i);
+            break;
+        }
 
         // NB must be in the same order as the CSVFormat::ColumnPurpose enum
         cpc->addItem(tr("<ignore>")); // ColumnUnknown
@@ -77,18 +92,15 @@
         cpc->addItem(tr("Value"));    // ColumnValue
         cpc->addItem(tr("Label"));    // ColumnLabel
         cpc->setCurrentIndex(int(m_format.getColumnPurpose(i)));
-        connect(cpc, SIGNAL(activated(int)), this, SLOT(columnPurposeChanged(int)));
 
-        if (i < m_format.getMaxExampleCols()) {
-            for (int j = 0; j < example.size() && j < 6; ++j) {
-                QLabel *label = new QLabel;
-                label->setTextFormat(Qt::PlainText);
-                label->setText(example[j][i]);
-                label->setFont(fp);
-                label->setPalette(palette);
-                label->setIndent(8);
-                exampleLayout->addWidget(label, j+1, i);
-            }
+        for (int j = 0; j < example.size() && j < 6; ++j) {
+            QLabel *label = new QLabel;
+            label->setTextFormat(Qt::PlainText);
+            label->setText(example[j][i]);
+            label->setFont(fp);
+            label->setPalette(palette);
+            label->setIndent(8);
+            exampleLayout->addWidget(label, j+1, i);
         }
     }
 
@@ -275,10 +287,27 @@
         
         if (thisChanged) {
 
+            std::cerr << "i == " << i << ", fuzzy == " << m_fuzzyColumn
+                      << ", p == " << p << std::endl;
+
+            if (i == m_fuzzyColumn) {
+                for (int j = i; j < m_format.getColumnCount(); ++j) {
+                    if (p == 0) { // Ignore
+                        m_format.setColumnPurpose(j, CSVFormat::ColumnUnknown);
+                    } else { // Value
+                        m_format.setColumnPurpose(j, CSVFormat::ColumnValue);
+                        ++valueCount;
+                    }
+                }
+                continue;
+            }
+
             cp = purpose;
 
         } else {
 
+            if (i == m_fuzzyColumn) continue;
+
             // We can only have one ColumnStartTime column, and only
             // one of either ColumnDuration or ColumnEndTime