comparison 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
comparison
equal deleted inserted replaced
580:89f70e0bfa4b 581:c9d6cf9c51c8
27 #include <QLabel> 27 #include <QLabel>
28 #include <QDialogButtonBox> 28 #include <QDialogButtonBox>
29 29
30 #include <iostream> 30 #include <iostream>
31 31
32 CSVFormatDialog::CSVFormatDialog(QWidget *parent, CSVFormat format) : 32 CSVFormatDialog::CSVFormatDialog(QWidget *parent, CSVFormat format,
33 int maxDisplayCols) :
33 QDialog(parent), 34 QDialog(parent),
34 m_format(format) 35 m_format(format),
36 m_maxDisplayCols(maxDisplayCols),
37 m_fuzzyColumn(-1)
35 { 38 {
36 setModal(true); 39 setModal(true);
37 setWindowTitle(tr("Select Data Format")); 40 setWindowTitle(tr("Select Data Format"));
38 41
39 QGridLayout *layout = new QGridLayout; 42 QGridLayout *layout = new QGridLayout;
62 65
63 int columns = format.getColumnCount(); 66 int columns = format.getColumnCount();
64 QList<QStringList> example = m_format.getExample(); 67 QList<QStringList> example = m_format.getExample();
65 68
66 for (int i = 0; i < columns; ++i) { 69 for (int i = 0; i < columns; ++i) {
67 70
68 QComboBox *cpc = new QComboBox; 71 QComboBox *cpc = new QComboBox;
69 m_columnPurposeCombos.push_back(cpc); 72 m_columnPurposeCombos.push_back(cpc);
70 exampleLayout->addWidget(cpc, 0, i); 73 exampleLayout->addWidget(cpc, 0, i);
74 connect(cpc, SIGNAL(activated(int)), this, SLOT(columnPurposeChanged(int)));
75
76 if (i == m_maxDisplayCols && columns > i + 2) {
77 m_fuzzyColumn = i;
78 cpc->addItem(tr("<ignore>"));
79 cpc->addItem(tr("Values"));
80 cpc->setCurrentIndex
81 (m_format.getColumnPurpose(i-1) == CSVFormat::ColumnUnknown ? 0 : 1);
82 exampleLayout->addWidget(new QLabel(tr("(%1 more)").arg(columns - i)),
83 1, i);
84 break;
85 }
71 86
72 // NB must be in the same order as the CSVFormat::ColumnPurpose enum 87 // NB must be in the same order as the CSVFormat::ColumnPurpose enum
73 cpc->addItem(tr("<ignore>")); // ColumnUnknown 88 cpc->addItem(tr("<ignore>")); // ColumnUnknown
74 cpc->addItem(tr("Time")); // ColumnStartTime 89 cpc->addItem(tr("Time")); // ColumnStartTime
75 cpc->addItem(tr("End time")); // ColumnEndTime 90 cpc->addItem(tr("End time")); // ColumnEndTime
76 cpc->addItem(tr("Duration")); // ColumnDuration 91 cpc->addItem(tr("Duration")); // ColumnDuration
77 cpc->addItem(tr("Value")); // ColumnValue 92 cpc->addItem(tr("Value")); // ColumnValue
78 cpc->addItem(tr("Label")); // ColumnLabel 93 cpc->addItem(tr("Label")); // ColumnLabel
79 cpc->setCurrentIndex(int(m_format.getColumnPurpose(i))); 94 cpc->setCurrentIndex(int(m_format.getColumnPurpose(i)));
80 connect(cpc, SIGNAL(activated(int)), this, SLOT(columnPurposeChanged(int))); 95
81 96 for (int j = 0; j < example.size() && j < 6; ++j) {
82 if (i < m_format.getMaxExampleCols()) { 97 QLabel *label = new QLabel;
83 for (int j = 0; j < example.size() && j < 6; ++j) { 98 label->setTextFormat(Qt::PlainText);
84 QLabel *label = new QLabel; 99 label->setText(example[j][i]);
85 label->setTextFormat(Qt::PlainText); 100 label->setFont(fp);
86 label->setText(example[j][i]); 101 label->setPalette(palette);
87 label->setFont(fp); 102 label->setIndent(8);
88 label->setPalette(palette); 103 exampleLayout->addWidget(label, j+1, i);
89 label->setIndent(8);
90 exampleLayout->addWidget(label, j+1, i);
91 }
92 } 104 }
93 } 105 }
94 106
95 layout->addWidget(exampleFrame, row, 0, 1, 4); 107 layout->addWidget(exampleFrame, row, 0, 1, 4);
96 layout->setColumnStretch(3, 10); 108 layout->setColumnStretch(3, 10);
273 285
274 bool thisChanged = (cb == m_columnPurposeCombos[i]); 286 bool thisChanged = (cb == m_columnPurposeCombos[i]);
275 287
276 if (thisChanged) { 288 if (thisChanged) {
277 289
290 std::cerr << "i == " << i << ", fuzzy == " << m_fuzzyColumn
291 << ", p == " << p << std::endl;
292
293 if (i == m_fuzzyColumn) {
294 for (int j = i; j < m_format.getColumnCount(); ++j) {
295 if (p == 0) { // Ignore
296 m_format.setColumnPurpose(j, CSVFormat::ColumnUnknown);
297 } else { // Value
298 m_format.setColumnPurpose(j, CSVFormat::ColumnValue);
299 ++valueCount;
300 }
301 }
302 continue;
303 }
304
278 cp = purpose; 305 cp = purpose;
279 306
280 } else { 307 } else {
308
309 if (i == m_fuzzyColumn) continue;
281 310
282 // We can only have one ColumnStartTime column, and only 311 // We can only have one ColumnStartTime column, and only
283 // one of either ColumnDuration or ColumnEndTime 312 // one of either ColumnDuration or ColumnEndTime
284 313
285 if (purpose == CSVFormat::ColumnStartTime) { 314 if (purpose == CSVFormat::ColumnStartTime) {