# HG changeset patch # User Chris Cannam # Date 1301927674 -3600 # Node ID c9d6cf9c51c8e15a06fa1f5c1678d0331dc837cb # Parent 89f70e0bfa4bbb58d6fac96a8608896d39ba3710 * 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. diff -r 89f70e0bfa4b -r c9d6cf9c51c8 widgets/CSVFormatDialog.cpp --- 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 -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 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("")); + 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("")); // 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 diff -r 89f70e0bfa4b -r c9d6cf9c51c8 widgets/CSVFormatDialog.h --- a/widgets/CSVFormatDialog.h Tue Mar 08 11:30:39 2011 +0000 +++ b/widgets/CSVFormatDialog.h Mon Apr 04 15:34:34 2011 +0100 @@ -29,7 +29,8 @@ Q_OBJECT public: - CSVFormatDialog(QWidget *parent, CSVFormat initialFormat); + CSVFormatDialog(QWidget *parent, CSVFormat initialFormat, + int maxDisplayCols = 5); ~CSVFormatDialog(); CSVFormat getFormat() const; @@ -43,6 +44,7 @@ protected: CSVFormat m_format; + int m_maxDisplayCols; QComboBox *m_timingTypeCombo; QLabel *m_sampleRateLabel; @@ -52,6 +54,7 @@ QLabel *m_modelLabel; QList m_columnPurposeCombos; + int m_fuzzyColumn; }; #endif