Chris@1568: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@1568: Chris@1568: /* Chris@1568: Sonic Visualiser Chris@1568: An audio file viewer and annotation editor. Chris@1568: Centre for Digital Music, Queen Mary, University of London. Chris@1568: Chris@1568: This program is free software; you can redistribute it and/or Chris@1568: modify it under the terms of the GNU General Public License as Chris@1568: published by the Free Software Foundation; either version 2 of the Chris@1568: License, or (at your option) any later version. See the file Chris@1568: COPYING included with this distribution for more information. Chris@1568: */ Chris@1568: Chris@1568: #include "CSVExportDialog.h" Chris@1568: Chris@1568: #include "view/ViewManager.h" Chris@1568: Chris@1568: #include Chris@1568: #include Chris@1568: #include Chris@1568: #include Chris@1568: #include Chris@1568: #include Chris@1568: #include Chris@1568: #include Chris@1568: #include Chris@1568: Chris@1568: #include Chris@1568: Chris@1568: using namespace std; Chris@1568: Chris@1568: //!!! todo: remember & re-apply last set of options chosen for this layer type Chris@1568: Chris@1568: CSVExportDialog::CSVExportDialog(Configuration config, QWidget *parent) : Chris@1568: QDialog(parent), Chris@1568: m_config(config) Chris@1568: { Chris@1568: setWindowTitle(tr("Export Layer")); Chris@1568: Chris@1568: QString intro = tr("Exporting layer \"%1\" to %2 file.") Chris@1568: .arg(config.layerName) Chris@1568: .arg(config.fileExtension.toUpper()); Chris@1568: Chris@1568: QVBoxLayout *vbox = new QVBoxLayout; Chris@1568: Chris@1568: QLabel *label = new QLabel(intro); Chris@1568: vbox->addWidget(label); Chris@1568: Chris@1568: int space = ViewManager::scalePixelSize(2); Chris@1568: Chris@1568: vbox->addSpacing(space); Chris@1568: Chris@1568: QGroupBox *rowColGroup = new QGroupBox(tr("Row and column options:")); Chris@1568: QGridLayout *rowColLayout = new QGridLayout; Chris@1568: rowColGroup->setLayout(rowColLayout); Chris@1568: Chris@1568: vector> separators { Chris@1568: { tr("Comma"), ',' }, Chris@1568: { tr("Tab"), '\t' }, Chris@1568: { tr("Space"), ' ' }, Chris@1568: { tr("Pipe"), '|' }, Chris@1568: { tr("Slash"), '/' }, Chris@1568: { tr("Colon"), ':' } Chris@1568: }; Chris@1568: Chris@1568: QChar defaultSeparator = ','; Chris@1568: if (m_config.fileExtension != "csv") { Chris@1568: defaultSeparator = '\t'; Chris@1568: } Chris@1568: Chris@1568: rowColLayout->addWidget(new QLabel(tr("Column separator:"), 0, 0)); Chris@1568: m_separatorCombo = new QComboBox; Chris@1568: for (auto p: separators) { Chris@1568: if (p.second == '\t' || p.second == ' ') { Chris@1568: m_separatorCombo->addItem(p.first, p.second); Chris@1568: } else { Chris@1568: m_separatorCombo->addItem(tr("%1 '%2'").arg(p.first).arg(p.second), Chris@1568: p.second); Chris@1568: } Chris@1568: if (p.second == defaultSeparator) { Chris@1568: m_separatorCombo->setCurrentIndex(m_separatorCombo->count()-1); Chris@1568: } Chris@1568: } Chris@1568: m_separatorCombo->setEditable(false); Chris@1568: rowColLayout->addWidget(m_separatorCombo, 0, 1); Chris@1568: rowColLayout->setColumnStretch(2, 10); Chris@1568: Chris@1568: m_header = new QCheckBox Chris@1568: (tr("Include a header row before the data rows")); Chris@1568: m_timestamps = new QCheckBox Chris@1568: (tr("Include a timestamp column before the data columns")); Chris@1568: rowColLayout->addWidget(m_header, 1, 0, 1, 3); Chris@1568: rowColLayout->addWidget(m_timestamps, 2, 0, 1, 3); Chris@1568: Chris@1568: if (!m_config.isDense) { Chris@1568: m_timestamps->setChecked(true); Chris@1568: m_timestamps->setEnabled(false); Chris@1568: } Chris@1568: Chris@1568: vbox->addWidget(rowColGroup); Chris@1568: Chris@1568: vbox->addSpacing(space); Chris@1568: Chris@1568: QGroupBox *framesGroup = new QGroupBox Chris@1568: (tr("Timing format:")); Chris@1568: Chris@1568: m_seconds = new QRadioButton Chris@1568: (tr("Write times in seconds")); Chris@1568: m_frames = new QRadioButton Chris@1568: (tr("Write times in audio sample frames")); Chris@1568: m_seconds->setChecked(true); Chris@1568: Chris@1568: QVBoxLayout *framesLayout = new QVBoxLayout; Chris@1568: framesLayout->addWidget(m_seconds); Chris@1568: framesLayout->addWidget(m_frames); Chris@1568: framesGroup->setLayout(framesLayout); Chris@1568: vbox->addWidget(framesGroup); Chris@1568: Chris@1568: vbox->addSpacing(space); Chris@1568: Chris@1568: if (m_config.isDense) { Chris@1568: m_seconds->setEnabled(false); Chris@1568: m_frames->setEnabled(false); Chris@1568: } Chris@1568: Chris@1568: QGroupBox *rangeGroup = new QGroupBox Chris@1568: (tr("Range to export:")); Chris@1568: Chris@1568: QButtonGroup *selectionGroup = new QButtonGroup(rangeGroup); Chris@1568: QButtonGroup *viewGroup = new QButtonGroup(rangeGroup); Chris@1568: Chris@1568: m_selectionOnly = new QRadioButton Chris@1568: (tr("Export only the current selection")); Chris@1568: QRadioButton *fullDuration = new QRadioButton Chris@1568: (tr("Export the full duration of the model")); Chris@1568: Chris@1568: selectionGroup->addButton(m_selectionOnly); Chris@1568: selectionGroup->addButton(fullDuration); Chris@1568: Chris@1568: if (m_config.haveSelection) { Chris@1568: m_selectionOnly->setChecked(true); Chris@1568: } else { Chris@1568: m_selectionOnly->setEnabled(false); Chris@1568: fullDuration->setEnabled(false); Chris@1568: fullDuration->setChecked(true); Chris@1568: } Chris@1568: Chris@1568: QVBoxLayout *rangeLayout = new QVBoxLayout; Chris@1568: rangeLayout->addWidget(m_selectionOnly); Chris@1568: rangeLayout->addWidget(fullDuration); Chris@1568: Chris@1568: if (m_config.haveView && m_config.isDense) { Chris@1568: Chris@1568: m_viewOnly = new QRadioButton Chris@1568: (tr("Export only the height of the visible view")); Chris@1568: QRadioButton *fullHeight = new QRadioButton Chris@1568: (tr("Export the full height of the model")); Chris@1568: Chris@1568: viewGroup->addButton(m_viewOnly); Chris@1568: viewGroup->addButton(fullHeight); Chris@1568: Chris@1568: m_viewOnly->setChecked(true); Chris@1568: Chris@1568: rangeLayout->addSpacing(space); Chris@1568: Chris@1568: rangeLayout->addWidget(m_viewOnly); Chris@1568: rangeLayout->addWidget(fullHeight); Chris@1568: Chris@1568: } else { Chris@1568: m_viewOnly = nullptr; Chris@1568: } Chris@1568: Chris@1568: rangeGroup->setLayout(rangeLayout); Chris@1568: vbox->addWidget(rangeGroup); Chris@1568: Chris@1568: vbox->addSpacing(space); Chris@1568: Chris@1568: QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | Chris@1568: QDialogButtonBox::Cancel); Chris@1568: vbox->addWidget(bb); Chris@1568: connect(bb, SIGNAL(accepted()), this, SLOT(accept())); Chris@1568: connect(bb, SIGNAL(rejected()), this, SLOT(reject())); Chris@1568: Chris@1568: connect(m_timestamps, SIGNAL(toggled(bool)), Chris@1568: this, SLOT(timestampsToggled(bool))); Chris@1568: Chris@1568: setLayout(vbox); Chris@1568: } Chris@1568: Chris@1568: void Chris@1568: CSVExportDialog::timestampsToggled(bool on) Chris@1568: { Chris@1568: m_seconds->setEnabled(on); Chris@1568: m_frames->setEnabled(on); Chris@1568: } Chris@1568: Chris@1568: QString Chris@1568: CSVExportDialog::getDelimiter() const Chris@1568: { Chris@1568: return m_separatorCombo->currentData().toChar(); Chris@1568: } Chris@1568: Chris@1568: bool Chris@1568: CSVExportDialog::shouldIncludeHeader() const Chris@1568: { Chris@1568: return m_header && m_header->isChecked(); Chris@1568: } Chris@1568: Chris@1568: bool Chris@1568: CSVExportDialog::shouldIncludeTimestamps() const Chris@1568: { Chris@1568: return m_timestamps && m_timestamps->isChecked(); Chris@1568: } Chris@1568: Chris@1568: bool Chris@1568: CSVExportDialog::shouldWriteTimeInFrames() const Chris@1568: { Chris@1568: return shouldIncludeTimestamps() && m_frames && m_frames->isChecked(); Chris@1568: } Chris@1568: Chris@1568: bool Chris@1568: CSVExportDialog::shouldConstrainToViewHeight() const Chris@1568: { Chris@1568: return m_viewOnly && m_viewOnly->isChecked(); Chris@1568: } Chris@1568: Chris@1568: bool Chris@1568: CSVExportDialog::shouldConstrainToSelection() const Chris@1568: { Chris@1568: return m_selectionOnly && m_selectionOnly->isChecked(); Chris@1568: } Chris@1568: