-
Notifications
You must be signed in to change notification settings - Fork 0
/
sessioneditpagesession.cpp
146 lines (122 loc) · 5.08 KB
/
sessioneditpagesession.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "sessioneditpagesession.h"
#include "database.h"
#include <QMessageBox>
#include <limits>
SessionEditPageSession::SessionEditPageSession(QWidget *parent, QString session)
: QWizardPage(parent), m_session_id_init(-1), m_session_name_init(session),
m_session_challonge_id_init(-1), m_session_tournament_id_init(-1)
{
if ( !m_session_name_init.isEmpty() )
{
m_session_id_init = Database::sessionID(m_session_name_init);
m_session_challonge_id_init = Database::sessionChallongeID(m_session_name_init);
m_session_tournament_id_init = Database::sessionTournamentID(m_session_name_init);
}
}
void SessionEditPageSession::initializePage()
{
setTitle( "Edit Session - Session" );
m_label_session_name = new QLabel("Session Name",this);
m_label_session_challonge_id = new QLabel("Session Challonge ID",this);
m_label_session_tournament_name = new QLabel("Session Tournament Name",this);
m_label_calendar = new QLabel("Session Date",this);
m_label_url = new QLabel("Session URL",this);
m_edit_session_name = new QLineEdit("",this);
m_edit_session_challonge_id = new QSpinBox(this);
m_edit_session_challonge_id->setMinimum(0);
m_edit_session_challonge_id->setMaximum(std::numeric_limits<int>::max());
m_edit_session_challonge_id->setValue(m_session_challonge_id_init);
m_edit_session_tournament_name = new QComboBox(this);
QStringList list_tournaments = Database::tournaments();
list_tournaments.push_front("new...");
m_edit_session_tournament_name->addItems(list_tournaments);
QString session_tournament_name = Database::tournamentName(m_session_tournament_id_init);
int tournament_name_index = m_edit_session_tournament_name->findText( session_tournament_name );
if ( tournament_name_index >= 0 )
m_edit_session_tournament_name->setCurrentIndex(tournament_name_index);
m_edit_url = new QLineEdit("",this);
//m_calendar = new QCalendarWidget(this);
m_dateEdit = new QDateEdit(this);
//m_calendar->setDateTextFormat("");
if ( !m_session_name_init.isEmpty() )
{
m_edit_session_name->setText(m_session_name_init);
// QTextCharFormat currentDayHighlight;
// currentDayHighlight.setBackground(Qt::cyan);
// m_date = QDate::fromString(
// Database::sessionDate(session_name), "yyyy-MM-dd");
// m_calendar->setDateTextFormat(m_date, currentDayHighlight);
m_dateEdit->setDate(QDate::fromString(
Database::sessionDate(m_session_name_init), "yyyy-MM-dd"));
m_edit_url->setText(Database::sessionURL(m_session_name_init));
}
else
{
m_dateEdit->setDate(QDate::currentDate());
}
m_layout = new QGridLayout(this);
m_layout->addWidget(m_label_session_name,0,0);
m_layout->addWidget(m_label_session_challonge_id,1,0);
m_layout->addWidget(m_label_session_tournament_name,2,0);
m_layout->addWidget(m_label_calendar,3,0);
m_layout->addWidget(m_label_url,4,0);
m_layout->addWidget(m_edit_session_name,0,1);
m_layout->addWidget(m_edit_session_challonge_id,1,1);
m_layout->addWidget(m_edit_session_tournament_name,2,1);
//m_layout->addWidget(m_calendar,3,1);
m_layout->addWidget(m_dateEdit,3,1);
m_layout->addWidget(m_edit_url,4,1);
//this->setLayout(m_layout);
// m_calendar->setDateEditEnabled(true);
// QObject::connect(m_calendar,SIGNAL(selectionChanged()),
// this,SLOT(onSelectionChanged()));
}
int SessionEditPageSession::sessionID() const
{
return m_session_id_init;
}
QString SessionEditPageSession::sessionName() const
{
return m_edit_session_name->text();
}
int SessionEditPageSession::sessionChallongeID() const
{
return m_edit_session_challonge_id->value();
}
int SessionEditPageSession::sessionTournamentID() const
{
return Database::tournamentID(m_edit_session_tournament_name->currentText());
}
QString SessionEditPageSession::sessionDate() const
{
//return m_calendar->selectedDate().toString("yyyy-MM-dd");
return m_dateEdit->date().toString("yyyy-MM-dd");
}
QString SessionEditPageSession::sessionURL() const
{
return m_edit_url->text();
}
//void SessionEditPageSession::onSelectionChanged()
//{
// QTextCharFormat defaultDateFormat;
// m_calendar->setDateTextFormat(m_date, defaultDateFormat);
// m_date = m_calendar->selectedDate();
// QTextCharFormat currentDayHighlight;
// currentDayHighlight.setBackground(Qt::cyan);
// m_calendar->setDateTextFormat(m_date, currentDayHighlight);
//}
bool SessionEditPageSession::validatePage()
{
if ( sessionName().compare(m_session_name_init,Qt::CaseInsensitive) != 0 )
{
if ( Database::sessionExists( sessionName()) )
{
QMessageBox::warning(this, "Session Name",
QString("Session \"%1\" already exists! "
"Select the existing session and edit if you want to. ")
.arg(sessionName() ) );
return false;
}
}
return true;
}