Mercurial > hg > svgui
comparison widgets/CSVFormatDialog.cpp @ 1613:fe9a643b83bf
Merge from branch csv-import-headers
author | Chris Cannam |
---|---|
date | Thu, 18 Jun 2020 13:45:11 +0100 |
parents | 129c704566ff |
children |
comparison
equal
deleted
inserted
replaced
1611:a6e37c28d762 | 1613:fe9a643b83bf |
---|---|
26 #include <QVBoxLayout> | 26 #include <QVBoxLayout> |
27 #include <QTableWidget> | 27 #include <QTableWidget> |
28 #include <QComboBox> | 28 #include <QComboBox> |
29 #include <QLabel> | 29 #include <QLabel> |
30 #include <QDialogButtonBox> | 30 #include <QDialogButtonBox> |
31 #include <QCheckBox> | |
31 | 32 |
32 #include <iostream> | 33 #include <iostream> |
33 #include <cmath> | 34 #include <cmath> |
34 | 35 |
35 #include "base/Debug.h" | 36 #include "base/Debug.h" |
74 void | 75 void |
75 CSVFormatDialog::init() | 76 CSVFormatDialog::init() |
76 { | 77 { |
77 setModal(true); | 78 setModal(true); |
78 setWindowTitle(tr("Select Data Format")); | 79 setWindowTitle(tr("Select Data Format")); |
80 | |
81 m_tabText = tr("<tab>"); | |
82 m_whitespaceText = tr("<whitespace>"); | |
79 | 83 |
80 QGridLayout *layout = new QGridLayout; | 84 QGridLayout *layout = new QGridLayout; |
81 | 85 |
82 int row = 0; | 86 int row = 0; |
83 | 87 |
85 (new QLabel(tr("Please select the correct data format for this file.")), | 89 (new QLabel(tr("Please select the correct data format for this file.")), |
86 row++, 0, 1, 4); | 90 row++, 0, 1, 4); |
87 | 91 |
88 m_exampleFrame = nullptr; | 92 m_exampleFrame = nullptr; |
89 m_exampleFrameRow = row++; | 93 m_exampleFrameRow = row++; |
90 | 94 |
91 std::set<QChar> plausible = m_format.getPlausibleSeparators(); | 95 std::set<QChar> plausible = m_format.getPlausibleSeparators(); |
92 SVDEBUG << "Have " << plausible.size() << " plausible separator(s)" << endl; | 96 SVDEBUG << "Have " << plausible.size() << " plausible separator(s)" << endl; |
93 | 97 |
94 if (m_csvFilePath != "" && plausible.size() > 1) { | 98 if (m_csvFilePath != "" && plausible.size() > 1) { |
95 // can only update when separator changed if we still have a | 99 // can only update when separator changed if we still have a |
96 // file to refer to | 100 // file to refer to |
97 layout->addWidget(new QLabel(tr("Column separator:")), row, 0); | 101 layout->addWidget(new QLabel(tr("Column separator:")), row, 0); |
98 m_separatorCombo = new QComboBox; | 102 m_separatorCombo = new QComboBox; |
99 for (QChar c: plausible) { | 103 for (QChar c: plausible) { |
100 m_separatorCombo->addItem(QString(c)); | 104 if (c == '\t') { |
105 m_separatorCombo->addItem(m_tabText); | |
106 } else if (c == ' ') { | |
107 m_separatorCombo->addItem(m_whitespaceText); | |
108 } else { | |
109 m_separatorCombo->addItem(QString(c)); | |
110 } | |
101 if (c == m_format.getSeparator()) { | 111 if (c == m_format.getSeparator()) { |
102 m_separatorCombo->setCurrentIndex(m_separatorCombo->count()-1); | 112 m_separatorCombo->setCurrentIndex(m_separatorCombo->count()-1); |
103 } | 113 } |
104 } | 114 } |
105 m_separatorCombo->setEditable(false); | 115 m_separatorCombo->setEditable(false); |
106 | 116 |
107 layout->addWidget(m_separatorCombo, row++, 1); | 117 layout->addWidget(m_separatorCombo, row++, 1); |
108 connect(m_separatorCombo, SIGNAL(activated(QString)), | 118 connect(m_separatorCombo, SIGNAL(activated(QString)), |
109 this, SLOT(separatorChanged(QString))); | 119 this, SLOT(separatorChanged(QString))); |
110 } | 120 |
121 } else { | |
122 m_separatorCombo = nullptr; | |
123 } | |
124 | |
125 layout->addWidget(new QLabel(tr("First row contains column headings:")), row, 0); | |
126 m_headerCheckBox = new QCheckBox; | |
127 m_headerCheckBox->setChecked | |
128 (m_format.getHeaderStatus() == CSVFormat::HeaderPresent); | |
129 layout->addWidget(m_headerCheckBox, row++, 1); | |
130 connect(m_headerCheckBox, SIGNAL(toggled(bool)), | |
131 this, SLOT(headerChanged(bool))); | |
111 | 132 |
112 layout->addWidget(new QLabel(tr("Timing is specified:")), row, 0); | 133 layout->addWidget(new QLabel(tr("Timing is specified:")), row, 0); |
113 | 134 |
114 m_timingTypeCombo = new QComboBox; | 135 m_timingTypeCombo = new QComboBox; |
115 | 136 |
195 palette.setColor(QPalette::Window, palette.color(QPalette::Base)); | 216 palette.setColor(QPalette::Window, palette.color(QPalette::Base)); |
196 exampleFrame->setPalette(palette); | 217 exampleFrame->setPalette(palette); |
197 | 218 |
198 QFont fp; | 219 QFont fp; |
199 fp.setPointSize(int(floor(fp.pointSize() * 0.9))); | 220 fp.setPointSize(int(floor(fp.pointSize() * 0.9))); |
221 | |
222 QFont fpi(fp); | |
223 fpi.setItalic(true); | |
200 | 224 |
201 int columns = m_format.getColumnCount(); | 225 int columns = m_format.getColumnCount(); |
202 QList<QStringList> example = m_format.getExample(); | 226 QList<QStringList> example = m_format.getExample(); |
203 | 227 |
204 m_columnPurposeCombos.clear(); | 228 m_columnPurposeCombos.clear(); |
240 } | 264 } |
241 QLabel *label = new QLabel; | 265 QLabel *label = new QLabel; |
242 label->setTextFormat(Qt::PlainText); | 266 label->setTextFormat(Qt::PlainText); |
243 QString text = TextAbbrev::abbreviate(example[j][i], 35); | 267 QString text = TextAbbrev::abbreviate(example[j][i], 35); |
244 label->setText(text); | 268 label->setText(text); |
245 label->setFont(fp); | 269 if (j == 0 && |
270 m_format.getHeaderStatus() == CSVFormat::HeaderPresent) { | |
271 label->setFont(fpi); | |
272 } else { | |
273 label->setFont(fp); | |
274 } | |
246 label->setPalette(palette); | 275 label->setPalette(palette); |
247 label->setIndent(8); | 276 label->setIndent(8); |
248 exampleLayout->addWidget(label, j+1, i); | 277 exampleLayout->addWidget(label, j+1, i); |
249 } | 278 } |
250 } | 279 } |
388 m_windowSizeCombo->setEnabled(wantWindow); | 417 m_windowSizeCombo->setEnabled(wantWindow); |
389 m_windowSizeLabel->setEnabled(wantWindow); | 418 m_windowSizeLabel->setEnabled(wantWindow); |
390 } | 419 } |
391 | 420 |
392 void | 421 void |
422 CSVFormatDialog::headerChanged(bool header) | |
423 { | |
424 m_format.setHeaderStatus(header ? | |
425 CSVFormat::HeaderPresent : | |
426 CSVFormat::HeaderAbsent); | |
427 m_format.guessFormatFor(m_csvFilePath); | |
428 | |
429 repopulate(); | |
430 } | |
431 | |
432 void | |
393 CSVFormatDialog::separatorChanged(QString sep) | 433 CSVFormatDialog::separatorChanged(QString sep) |
394 { | 434 { |
395 if (sep == "" || m_csvFilePath == "") { | 435 if (sep == "" || m_csvFilePath == "") { |
396 return; | 436 return; |
397 } | 437 } |
398 | 438 |
439 if (sep == m_tabText) { | |
440 sep = "\t"; | |
441 } else if (sep == m_whitespaceText) { | |
442 sep = " "; | |
443 } | |
444 | |
399 m_format.setSeparator(sep[0]); | 445 m_format.setSeparator(sep[0]); |
400 m_format.guessFormatFor(m_csvFilePath); | 446 m_format.guessFormatFor(m_csvFilePath); |
401 | 447 |
402 repopulate(); | 448 repopulate(); |
403 } | 449 } |