# HG changeset patch # User Chris Cannam # Date 1592484311 -3600 # Node ID fe9a643b83bfc434b47c41e1c4281ab99ff05947 # Parent a6e37c28d7620aba2af4aedd5c2d786fa989f3a9# Parent 129c704566ffafa38cd1f343d69bd560295980c6 Merge from branch csv-import-headers diff -r a6e37c28d762 -r fe9a643b83bf widgets/CSVFormatDialog.cpp --- a/widgets/CSVFormatDialog.cpp Tue Jun 16 15:16:50 2020 +0100 +++ b/widgets/CSVFormatDialog.cpp Thu Jun 18 13:45:11 2020 +0100 @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -76,6 +77,9 @@ { setModal(true); setWindowTitle(tr("Select Data Format")); + + m_tabText = tr(""); + m_whitespaceText = tr(""); QGridLayout *layout = new QGridLayout; @@ -87,7 +91,7 @@ m_exampleFrame = nullptr; m_exampleFrameRow = row++; - + std::set plausible = m_format.getPlausibleSeparators(); SVDEBUG << "Have " << plausible.size() << " plausible separator(s)" << endl; @@ -97,7 +101,13 @@ layout->addWidget(new QLabel(tr("Column separator:")), row, 0); m_separatorCombo = new QComboBox; for (QChar c: plausible) { - m_separatorCombo->addItem(QString(c)); + if (c == '\t') { + m_separatorCombo->addItem(m_tabText); + } else if (c == ' ') { + m_separatorCombo->addItem(m_whitespaceText); + } else { + m_separatorCombo->addItem(QString(c)); + } if (c == m_format.getSeparator()) { m_separatorCombo->setCurrentIndex(m_separatorCombo->count()-1); } @@ -107,8 +117,19 @@ layout->addWidget(m_separatorCombo, row++, 1); connect(m_separatorCombo, SIGNAL(activated(QString)), this, SLOT(separatorChanged(QString))); + + } else { + m_separatorCombo = nullptr; } + layout->addWidget(new QLabel(tr("First row contains column headings:")), row, 0); + m_headerCheckBox = new QCheckBox; + m_headerCheckBox->setChecked + (m_format.getHeaderStatus() == CSVFormat::HeaderPresent); + layout->addWidget(m_headerCheckBox, row++, 1); + connect(m_headerCheckBox, SIGNAL(toggled(bool)), + this, SLOT(headerChanged(bool))); + layout->addWidget(new QLabel(tr("Timing is specified:")), row, 0); m_timingTypeCombo = new QComboBox; @@ -197,6 +218,9 @@ QFont fp; fp.setPointSize(int(floor(fp.pointSize() * 0.9))); + + QFont fpi(fp); + fpi.setItalic(true); int columns = m_format.getColumnCount(); QList example = m_format.getExample(); @@ -242,7 +266,12 @@ label->setTextFormat(Qt::PlainText); QString text = TextAbbrev::abbreviate(example[j][i], 35); label->setText(text); - label->setFont(fp); + if (j == 0 && + m_format.getHeaderStatus() == CSVFormat::HeaderPresent) { + label->setFont(fpi); + } else { + label->setFont(fp); + } label->setPalette(palette); label->setIndent(8); exampleLayout->addWidget(label, j+1, i); @@ -390,12 +419,29 @@ } void +CSVFormatDialog::headerChanged(bool header) +{ + m_format.setHeaderStatus(header ? + CSVFormat::HeaderPresent : + CSVFormat::HeaderAbsent); + m_format.guessFormatFor(m_csvFilePath); + + repopulate(); +} + +void CSVFormatDialog::separatorChanged(QString sep) { if (sep == "" || m_csvFilePath == "") { return; } + if (sep == m_tabText) { + sep = "\t"; + } else if (sep == m_whitespaceText) { + sep = " "; + } + m_format.setSeparator(sep[0]); m_format.guessFormatFor(m_csvFilePath); diff -r a6e37c28d762 -r fe9a643b83bf widgets/CSVFormatDialog.h --- a/widgets/CSVFormatDialog.h Tue Jun 16 15:16:50 2020 +0100 +++ b/widgets/CSVFormatDialog.h Thu Jun 18 13:45:11 2020 +0100 @@ -22,6 +22,7 @@ class QComboBox; class QLabel; class QFrame; +class QCheckBox; #include @@ -44,6 +45,7 @@ CSVFormat getFormat() const; protected slots: + void headerChanged(bool); void separatorChanged(QString); void timingTypeChanged(int type); void sampleRateChanged(QString); @@ -75,9 +77,13 @@ void applyStartTimePurpose(); void removeStartTimePurpose(); + QString m_tabText; + QString m_whitespaceText; + QFrame *m_exampleFrame; int m_exampleFrameRow; - + + QCheckBox *m_headerCheckBox; QComboBox *m_separatorCombo; QComboBox *m_timingTypeCombo; QLabel *m_sampleRateLabel;