23 #include <QGridLayout> 24 #include <QPushButton> 25 #include <QHBoxLayout> 26 #include <QVBoxLayout> 27 #include <QTableWidget> 30 #include <QDialogButtonBox> 36 #include "base/Debug.h" 43 m_referenceSampleRate(0),
45 m_maxDisplayCols(maxDisplayCols),
53 sv_samplerate_t referenceSampleRate,
62 m_format.setSampleRate(referenceSampleRate);
71 8000, 11025, 12000, 22050, 24000, 32000,
72 44100, 48000, 88200, 96000, 176400, 192000
79 setWindowTitle(tr(
"Select Data Format"));
84 QGridLayout *layout =
new QGridLayout;
89 (
new QLabel(tr(
"Please select the correct data format for this file.")),
95 std::set<QChar> plausible =
m_format.getPlausibleSeparators();
96 SVDEBUG <<
"Have " << plausible.size() <<
" plausible separator(s)" << endl;
101 layout->addWidget(
new QLabel(tr(
"Column separator:")), row, 0);
103 for (QChar c: plausible) {
106 }
else if (c ==
' ') {
125 layout->addWidget(
new QLabel(tr(
"First row contains column headings:")), row, 0);
128 (
m_format.getHeaderStatus() == CSVFormat::HeaderPresent);
133 layout->addWidget(
new QLabel(tr(
"Timing is specified:")), row, 0);
141 {
TimingImplicit, tr(
"Implicitly: rows are equally spaced in time") }
172 for (
int i = 0; i <= 16; ++i) {
190 QDialogButtonBox *bb =
new QDialogButtonBox(QDialogButtonBox::Ok |
191 QDialogButtonBox::Cancel);
192 layout->addWidget(bb, row++, 0, 1, 4);
193 connect(bb, SIGNAL(accepted()),
this, SLOT(accept()));
194 connect(bb, SIGNAL(rejected()),
this, SLOT(reject()));
204 SVCERR <<
"CSVFormatDialog::repopulate()" << endl;
206 QGridLayout *layout = qobject_cast<QGridLayout *>(this->layout());
208 QFrame *exampleFrame =
new QFrame;
209 exampleFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
210 exampleFrame->setLineWidth(2);
211 QGridLayout *exampleLayout =
new QGridLayout;
212 exampleLayout->setSpacing(4);
213 exampleFrame->setLayout(exampleLayout);
215 QPalette palette = exampleFrame->palette();
216 palette.setColor(QPalette::Window, palette.color(QPalette::Base));
217 exampleFrame->setPalette(palette);
220 fp.setPointSize(
int(floor(fp.pointSize() * 0.9)));
225 int columns =
m_format.getColumnCount();
226 QList<QStringList> example =
m_format.getExample();
230 for (
int i = 0; i < columns; ++i) {
232 QComboBox *cpc =
new QComboBox;
234 exampleLayout->addWidget(cpc, 0, i);
240 cpc->addItem(tr(
"<ignore>"));
241 cpc->addItem(tr(
"Values"));
244 CSVFormat::ColumnUnknown ? 0 : 1);
246 exampleLayout->addWidget
247 (
new QLabel(tr(
"(%1 more)").arg(columns - i)), 1, i);
252 cpc->addItem(tr(
"<ignore>"));
253 cpc->addItem(tr(
"Time"));
254 cpc->addItem(tr(
"End time"));
255 cpc->addItem(tr(
"Duration"));
256 cpc->addItem(tr(
"Value"));
257 cpc->addItem(tr(
"Pitch"));
258 cpc->addItem(tr(
"Label"));
259 cpc->setCurrentIndex(
int(
m_format.getColumnPurpose(i)));
261 for (
int j = 0; j < example.size() && j < 6; ++j) {
262 if (i >= example[j].size()) {
265 QLabel *label =
new QLabel;
266 label->setTextFormat(Qt::PlainText);
268 label->setText(text);
270 m_format.getHeaderStatus() == CSVFormat::HeaderPresent) {
275 label->setPalette(palette);
277 exampleLayout->addWidget(label, j+1, i);
287 layout->setColumnStretch(3, 10);
291 if (
m_format.getTimingType() == CSVFormat::ExplicitTiming) {
293 case CSVFormat::TimeSeconds:
295 case CSVFormat::TimeMilliseconds:
297 case CSVFormat::TimeAudioFrames:
299 case CSVFormat::TimeWindows:
311 for (
int i = 0; i <= 16; ++i) {
313 if (value ==
int(
m_format.getWindowSize())) {
338 case CSVFormat::OneDimensionalModel:
341 case CSVFormat::TwoDimensionalModel:
344 case CSVFormat::TwoDimensionalModelWithDuration:
347 case CSVFormat::TwoDimensionalModelWithDurationAndPitch:
350 case CSVFormat::TwoDimensionalModelWithDurationAndExtent:
353 case CSVFormat::ThreeDimensionalModel:
356 case CSVFormat::WaveFileModel:
361 m_modelLabel->setText(
"\n" + tr(
"Data will be displayed in a %1 layer.")
377 if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) {
385 if (cb->currentIndex() == int(CSVFormat::ColumnValue)) {
386 cb->setCurrentIndex(
int(CSVFormat::ColumnStartTime));
401 if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) {
402 cb->setCurrentIndex(
int(CSVFormat::ColumnValue));
410 bool wantRate = (
m_format.getTimingType() == CSVFormat::ImplicitTiming ||
411 m_format.getTimeUnits() == CSVFormat::TimeAudioFrames);
412 bool wantWindow = (
m_format.getTimingType() == CSVFormat::ImplicitTiming);
425 CSVFormat::HeaderPresent :
426 CSVFormat::HeaderAbsent);
468 int sampleRate = rateString.toInt(&ok);
469 if (ok)
m_format.setSampleRate(sampleRate);
476 int size = sizeString.toInt(&ok);
477 if (ok)
m_format.setWindowSize(size);
483 QObject *o = sender();
484 QComboBox *cb = qobject_cast<QComboBox *>(o);
492 CSVFormat::ColumnPurpose purpose = (CSVFormat::ColumnPurpose)p;
494 bool haveStartTime =
false;
509 CSVFormat::ColumnPurpose cp = (CSVFormat::ColumnPurpose)
510 (thisCombo->currentIndex());
511 bool thisChanged = (cb == thisCombo);
518 if (purpose == CSVFormat::ColumnStartTime) {
520 cp = CSVFormat::ColumnValue;
522 }
else if (purpose == CSVFormat::ColumnDuration ||
523 purpose == CSVFormat::ColumnEndTime) {
524 if (cp == CSVFormat::ColumnDuration ||
525 cp == CSVFormat::ColumnEndTime) {
526 cp = CSVFormat::ColumnValue;
531 if (purpose == CSVFormat::ColumnLabel) {
533 cp = CSVFormat::ColumnUnknown;
537 if (cp == CSVFormat::ColumnStartTime) {
538 haveStartTime =
true;
541 thisCombo->setCurrentIndex(
int(cp));
544 if (purpose == CSVFormat::ColumnStartTime) {
545 haveStartTime =
true;
550 if (!haveStartTime) {
570 m_format.setTimingType(CSVFormat::ExplicitTiming);
571 m_format.setTimeUnits(CSVFormat::TimeSeconds);
575 m_format.setTimingType(CSVFormat::ExplicitTiming);
576 m_format.setTimeUnits(CSVFormat::TimeMilliseconds);
580 m_format.setTimingType(CSVFormat::ExplicitTiming);
581 m_format.setTimeUnits(CSVFormat::TimeAudioFrames);
585 m_format.setTimingType(CSVFormat::ImplicitTiming);
586 m_format.setTimeUnits(CSVFormat::TimeWindows);
590 bool haveStartTime =
false;
591 bool haveDuration =
false;
592 bool havePitch =
false;
599 CSVFormat::ColumnPurpose purpose =
600 (CSVFormat::ColumnPurpose) (thisCombo->currentIndex());
603 for (
int j = i; j <
m_format.getColumnCount(); ++j) {
604 if (purpose == CSVFormat::ColumnUnknown) {
605 m_format.setColumnPurpose(j, CSVFormat::ColumnUnknown);
607 m_format.setColumnPurpose(j, CSVFormat::ColumnValue);
613 if (purpose == CSVFormat::ColumnStartTime) {
614 haveStartTime =
true;
616 if (purpose == CSVFormat::ColumnEndTime ||
617 purpose == CSVFormat::ColumnDuration) {
620 if (purpose == CSVFormat::ColumnPitch) {
623 if (purpose == CSVFormat::ColumnValue) {
627 m_format.setColumnPurpose(i, purpose);
631 if (haveStartTime && haveDuration) {
633 m_format.setModelType(CSVFormat::TwoDimensionalModelWithDurationAndPitch);
634 }
else if (valueCount == 2) {
635 m_format.setModelType(CSVFormat::TwoDimensionalModelWithDurationAndExtent);
637 m_format.setModelType(CSVFormat::TwoDimensionalModelWithDuration);
640 if (valueCount > 1) {
641 m_format.setModelType(CSVFormat::ThreeDimensionalModel);
642 }
else if (valueCount > 0) {
643 m_format.setModelType(CSVFormat::TwoDimensionalModel);
645 m_format.setModelType(CSVFormat::OneDimensionalModel);
static LayerFactory * getInstance()
static QString abbreviate(QString text, int maxLength, Policy policy=ElideEnd, bool fuzzy=true, QString ellipsis="")
Abbreviate the given text to the given maximum length (including ellipsis), using the given abbreviat...
QString getLayerPresentationName(LayerType type)