Mercurial > hg > svgui
comparison widgets/CSVExportDialog.cpp @ 1569:b33b0b06133e
Merge from branch csv-export-dialog
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2020 15:48:44 +0000 |
parents | 3943553b95b0 |
children | 9cd77efef37c |
comparison
equal
deleted
inserted
replaced
1567:77ffd5421627 | 1569:b33b0b06133e |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 | |
8 This program is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU General Public License as | |
10 published by the Free Software Foundation; either version 2 of the | |
11 License, or (at your option) any later version. See the file | |
12 COPYING included with this distribution for more information. | |
13 */ | |
14 | |
15 #include "CSVExportDialog.h" | |
16 | |
17 #include "view/ViewManager.h" | |
18 | |
19 #include <QVBoxLayout> | |
20 #include <QGridLayout> | |
21 #include <QGroupBox> | |
22 #include <QLabel> | |
23 #include <QDialogButtonBox> | |
24 #include <QRadioButton> | |
25 #include <QButtonGroup> | |
26 #include <QCheckBox> | |
27 #include <QComboBox> | |
28 | |
29 #include <vector> | |
30 | |
31 using namespace std; | |
32 | |
33 //!!! todo: remember & re-apply last set of options chosen for this layer type | |
34 | |
35 CSVExportDialog::CSVExportDialog(Configuration config, QWidget *parent) : | |
36 QDialog(parent), | |
37 m_config(config) | |
38 { | |
39 setWindowTitle(tr("Export Layer")); | |
40 | |
41 QString intro = tr("Exporting layer \"%1\" to %2 file.") | |
42 .arg(config.layerName) | |
43 .arg(config.fileExtension.toUpper()); | |
44 | |
45 QVBoxLayout *vbox = new QVBoxLayout; | |
46 | |
47 QLabel *label = new QLabel(intro); | |
48 vbox->addWidget(label); | |
49 | |
50 int space = ViewManager::scalePixelSize(2); | |
51 | |
52 vbox->addSpacing(space); | |
53 | |
54 QGroupBox *rowColGroup = new QGroupBox(tr("Row and column options:")); | |
55 QGridLayout *rowColLayout = new QGridLayout; | |
56 rowColGroup->setLayout(rowColLayout); | |
57 | |
58 vector<pair<QString, QChar>> separators { | |
59 { tr("Comma"), ',' }, | |
60 { tr("Tab"), '\t' }, | |
61 { tr("Space"), ' ' }, | |
62 { tr("Pipe"), '|' }, | |
63 { tr("Slash"), '/' }, | |
64 { tr("Colon"), ':' } | |
65 }; | |
66 | |
67 QChar defaultSeparator = ','; | |
68 if (m_config.fileExtension != "csv") { | |
69 defaultSeparator = '\t'; | |
70 } | |
71 | |
72 rowColLayout->addWidget(new QLabel(tr("Column separator:"), 0, 0)); | |
73 m_separatorCombo = new QComboBox; | |
74 for (auto p: separators) { | |
75 if (p.second == '\t' || p.second == ' ') { | |
76 m_separatorCombo->addItem(p.first, p.second); | |
77 } else { | |
78 m_separatorCombo->addItem(tr("%1 '%2'").arg(p.first).arg(p.second), | |
79 p.second); | |
80 } | |
81 if (p.second == defaultSeparator) { | |
82 m_separatorCombo->setCurrentIndex(m_separatorCombo->count()-1); | |
83 } | |
84 } | |
85 m_separatorCombo->setEditable(false); | |
86 rowColLayout->addWidget(m_separatorCombo, 0, 1); | |
87 rowColLayout->setColumnStretch(2, 10); | |
88 | |
89 m_header = new QCheckBox | |
90 (tr("Include a header row before the data rows")); | |
91 m_timestamps = new QCheckBox | |
92 (tr("Include a timestamp column before the data columns")); | |
93 rowColLayout->addWidget(m_header, 1, 0, 1, 3); | |
94 rowColLayout->addWidget(m_timestamps, 2, 0, 1, 3); | |
95 | |
96 if (!m_config.isDense) { | |
97 m_timestamps->setChecked(true); | |
98 m_timestamps->setEnabled(false); | |
99 } | |
100 | |
101 vbox->addWidget(rowColGroup); | |
102 | |
103 vbox->addSpacing(space); | |
104 | |
105 QGroupBox *framesGroup = new QGroupBox | |
106 (tr("Timing format:")); | |
107 | |
108 m_seconds = new QRadioButton | |
109 (tr("Write times in seconds")); | |
110 m_frames = new QRadioButton | |
111 (tr("Write times in audio sample frames")); | |
112 m_seconds->setChecked(true); | |
113 | |
114 QVBoxLayout *framesLayout = new QVBoxLayout; | |
115 framesLayout->addWidget(m_seconds); | |
116 framesLayout->addWidget(m_frames); | |
117 framesGroup->setLayout(framesLayout); | |
118 vbox->addWidget(framesGroup); | |
119 | |
120 vbox->addSpacing(space); | |
121 | |
122 if (m_config.isDense) { | |
123 m_seconds->setEnabled(false); | |
124 m_frames->setEnabled(false); | |
125 } | |
126 | |
127 QGroupBox *rangeGroup = new QGroupBox | |
128 (tr("Range to export:")); | |
129 | |
130 QButtonGroup *selectionGroup = new QButtonGroup(rangeGroup); | |
131 QButtonGroup *viewGroup = new QButtonGroup(rangeGroup); | |
132 | |
133 m_selectionOnly = new QRadioButton | |
134 (tr("Export only the current selection")); | |
135 QRadioButton *fullDuration = new QRadioButton | |
136 (tr("Export the full duration of the model")); | |
137 | |
138 selectionGroup->addButton(m_selectionOnly); | |
139 selectionGroup->addButton(fullDuration); | |
140 | |
141 if (m_config.haveSelection) { | |
142 m_selectionOnly->setChecked(true); | |
143 } else { | |
144 m_selectionOnly->setEnabled(false); | |
145 fullDuration->setEnabled(false); | |
146 fullDuration->setChecked(true); | |
147 } | |
148 | |
149 QVBoxLayout *rangeLayout = new QVBoxLayout; | |
150 rangeLayout->addWidget(m_selectionOnly); | |
151 rangeLayout->addWidget(fullDuration); | |
152 | |
153 if (m_config.haveView && m_config.isDense) { | |
154 | |
155 m_viewOnly = new QRadioButton | |
156 (tr("Export only the height of the visible view")); | |
157 QRadioButton *fullHeight = new QRadioButton | |
158 (tr("Export the full height of the model")); | |
159 | |
160 viewGroup->addButton(m_viewOnly); | |
161 viewGroup->addButton(fullHeight); | |
162 | |
163 m_viewOnly->setChecked(true); | |
164 | |
165 rangeLayout->addSpacing(space); | |
166 | |
167 rangeLayout->addWidget(m_viewOnly); | |
168 rangeLayout->addWidget(fullHeight); | |
169 | |
170 } else { | |
171 m_viewOnly = nullptr; | |
172 } | |
173 | |
174 rangeGroup->setLayout(rangeLayout); | |
175 vbox->addWidget(rangeGroup); | |
176 | |
177 vbox->addSpacing(space); | |
178 | |
179 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | | |
180 QDialogButtonBox::Cancel); | |
181 vbox->addWidget(bb); | |
182 connect(bb, SIGNAL(accepted()), this, SLOT(accept())); | |
183 connect(bb, SIGNAL(rejected()), this, SLOT(reject())); | |
184 | |
185 connect(m_timestamps, SIGNAL(toggled(bool)), | |
186 this, SLOT(timestampsToggled(bool))); | |
187 | |
188 setLayout(vbox); | |
189 } | |
190 | |
191 void | |
192 CSVExportDialog::timestampsToggled(bool on) | |
193 { | |
194 m_seconds->setEnabled(on); | |
195 m_frames->setEnabled(on); | |
196 } | |
197 | |
198 QString | |
199 CSVExportDialog::getDelimiter() const | |
200 { | |
201 return m_separatorCombo->currentData().toChar(); | |
202 } | |
203 | |
204 bool | |
205 CSVExportDialog::shouldIncludeHeader() const | |
206 { | |
207 return m_header && m_header->isChecked(); | |
208 } | |
209 | |
210 bool | |
211 CSVExportDialog::shouldIncludeTimestamps() const | |
212 { | |
213 return m_timestamps && m_timestamps->isChecked(); | |
214 } | |
215 | |
216 bool | |
217 CSVExportDialog::shouldWriteTimeInFrames() const | |
218 { | |
219 return shouldIncludeTimestamps() && m_frames && m_frames->isChecked(); | |
220 } | |
221 | |
222 bool | |
223 CSVExportDialog::shouldConstrainToViewHeight() const | |
224 { | |
225 return m_viewOnly && m_viewOnly->isChecked(); | |
226 } | |
227 | |
228 bool | |
229 CSVExportDialog::shouldConstrainToSelection() const | |
230 { | |
231 return m_selectionOnly && m_selectionOnly->isChecked(); | |
232 } | |
233 |