-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rankingswizardformat.cpp
98 lines (85 loc) · 4.38 KB
/
rankingswizardformat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*****************************************************************************
* Copyright (C) 2021 by Lorenzo Buzzi ([email protected]) *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
*****************************************************************************/
#include <QLabel>
#include "crloader.hpp"
#include "rankingswizard.hpp"
#include "rankingswizardformat.hpp"
#include "crhelper.hpp"
RankingsWizardFormat::RankingsWizardFormat(QWidget *parent) :
QWizardPage(parent),
fileFormat(parent),
fileEncoding(parent)
{
auto formatIdx = static_cast<int>(CRLoader::getFormat());
fileFormat.insertItem(static_cast<int>(CRLoader::Format::PDF), CRHelper::formatToLabel(CRLoader::Format::PDF));
fileFormat.insertItem(static_cast<int>(CRLoader::Format::TEXT), CRHelper::formatToLabel(CRLoader::Format::TEXT));
fileFormat.insertItem(static_cast<int>(CRLoader::Format::CSV), CRHelper::formatToLabel(CRLoader::Format::CSV));
fileFormat.setCurrentIndex(formatIdx);
layout.addRow(new QLabel(tr("Format")), &fileFormat);
fileEncoding.addItem(CRHelper::encodingToLabel(QStringConverter::Encoding::Utf8), QVariant(QStringConverter::Encoding::Utf8));
fileEncoding.addItem(CRHelper::encodingToLabel(QStringConverter::Encoding::Latin1), QVariant(QStringConverter::Encoding::Latin1));
fileEncoding.setCurrentText(CRHelper::encodingToLabel(CRLoader::getEncoding()));
layout.addRow(new QLabel(tr("Encoding")), &fileEncoding);
formatChange(formatIdx);
connect(&fileFormat, &QComboBox::currentIndexChanged, this, &RankingsWizardFormat::formatChange);
connect(&fileEncoding, &QComboBox::currentIndexChanged, this, &RankingsWizardFormat::encodingChange);
setLayout(&layout);
}
void RankingsWizardFormat::initializePage()
{
if (RankingsWizard const *parentWizard = qobject_cast<RankingsWizard *>(wizard());
parentWizard && (parentWizard->getTarget() == RankingsWizard::RankingsWizardTarget::StartList))
setTitle(tr("Start List file format"));
else
setTitle(tr("Rankings file format"));
setSubTitle(tr("Please select a file format and, if required, an encoding type."));
}
int RankingsWizardFormat::nextId() const
{
int id = -1;
if (RankingsWizard const *parentWizard = qobject_cast<RankingsWizard *>(wizard());
!parentWizard || (parentWizard->getTarget() == RankingsWizard::RankingsWizardTarget::Rankings)) {
id = static_cast<int>((fileFormat.currentIndex() == static_cast<int>(CRLoader::Format::PDF)) ?
RankingsWizard::RankingsWizardPage::Page_Mode :
RankingsWizard::RankingsWizardPage::Page_Selection);
}
return id;
}
void RankingsWizardFormat::formatChange(int index)
{
switch (index) {
case static_cast<int>(CRLoader::Format::PDF):
fileEncoding.setEnabled(false);
CRLoader::setFormat(CRLoader::Format::PDF);
break;
case static_cast<int>(CRLoader::Format::TEXT):
fileEncoding.setEnabled(true);
CRLoader::setFormat(CRLoader::Format::TEXT);
break;
case static_cast<int>(CRLoader::Format::CSV):
fileEncoding.setEnabled(true);
CRLoader::setFormat(CRLoader::Format::CSV);
break;
default:
Q_UNREACHABLE();
break;
}
}
void RankingsWizardFormat::encodingChange(int index) const
{
CRLoader::setEncoding(fileEncoding.itemData(index, Qt::UserRole).value<QStringConverter::Encoding>());
}