Skip to content

Commit

Permalink
Add standings page
Browse files Browse the repository at this point in the history
Closes #15
Related #17
  • Loading branch information
alcarazzam authored Dec 7, 2024
1 parent 0e2fe0e commit a8bd3c9
Show file tree
Hide file tree
Showing 19 changed files with 643 additions and 35 deletions.
8 changes: 8 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ecm_add_qml_module(chessament_static
qml/DocsPage.qml
qml/NavigationButtonDelegate.qml
qml/NewTournamentDialog.qml
qml/StandingsPage.qml
qml/PairingsPage.qml
qml/PlayersPage.qml
qml/WelcomePage.qml
Expand Down Expand Up @@ -42,8 +43,15 @@ ecm_add_qml_module(chessament_static
pairingmodel.h
round.h
round.cpp
standingsmodel.cpp
standingsmodel.h
tiebreak.h
tiebreaks.cpp
tiebreaks.h
tournament.cpp
tournament.h
tournamentstate.cpp
tournamentstate.h
trf.cpp
IMPORTS
org.kde.kirigamiaddons.formcard
Expand Down
8 changes: 8 additions & 0 deletions src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Controller::Controller(QObject *parent)
: QObject(parent)
, m_playersModel(new PlayersModel(this))
, m_pairingModel(new PairingModel(this))
, m_standingsModel(new StandingsModel(this))
{
}

Expand All @@ -24,6 +25,8 @@ void Controller::setTournament(Tournament *tournament)

m_playersModel->setPlayers(m_tournament->players());
m_pairingModel->setPairings(m_tournament->getPairings(1));
m_standingsModel->setTournament(m_tournament);

setHasOpenTournament(true);
setCurrentPlayerByIndex(-1);

Expand Down Expand Up @@ -213,6 +216,11 @@ PairingModel *Controller::pairingModel() const
return m_pairingModel;
}

StandingsModel *Controller::standingsModel() const
{
return m_standingsModel;
}

QString Controller::currentView() const
{
return m_currentView;
Expand Down
4 changes: 4 additions & 0 deletions src/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "pairingmodel.h"
#include "playersmodel.h"
#include "standingsmodel.h"
#include "tournament.h"

class Controller : public QObject
Expand All @@ -25,6 +26,7 @@ class Controller : public QObject

Q_PROPERTY(PlayersModel *playersModel READ playersModel CONSTANT)
Q_PROPERTY(PairingModel *pairingModel READ pairingModel CONSTANT)
Q_PROPERTY(StandingsModel *standingsModel READ standingsModel CONSTANT)

Q_PROPERTY(QString currentView READ currentView WRITE setCurrentView NOTIFY currentViewChanged)
Q_PROPERTY(QString error READ error WRITE setError NOTIFY errorChanged)
Expand Down Expand Up @@ -60,6 +62,7 @@ class Controller : public QObject

PlayersModel *playersModel() const;
PairingModel *pairingModel() const;
StandingsModel *standingsModel() const;

QString currentView() const;
QString error() const;
Expand Down Expand Up @@ -94,6 +97,7 @@ public Q_SLOTS:
Player *m_currentPlayer = nullptr;
PlayersModel *m_playersModel;
PairingModel *m_pairingModel;
StandingsModel *m_standingsModel;

QString m_currentView;
QString m_error;
Expand Down
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "chessamentconfig.h"
#include "pairingmodel.h"
#include "playersmodel.h"
#include "standingsmodel.h"

using namespace Qt::Literals::StringLiterals;

Expand Down Expand Up @@ -85,6 +86,11 @@ int main(int argc, char *argv[])
0,
"PairingRoles",
QStringLiteral("Cannot create instances of PairingModel"));
qmlRegisterUncreatableType<StandingsModel>("dev.alcarazzam.chessament.StandingsModel",
1,
0,
"StandingsRoles",
QStringLiteral("Cannot create instances of StandingsModel"));

QQmlApplicationEngine engine;

Expand Down
77 changes: 74 additions & 3 deletions src/pairing.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ class Pairing : public QObject
Q_PROPERTY(Result result READ result NOTIFY resultChanged)

public:
enum class Color { Unknown, White, Black };
enum class Color {
Unknown,
White,
Black
};
Q_ENUM(Color)

static QString colorString(Color color)
Expand Down Expand Up @@ -229,12 +233,79 @@ class Pairing : public QObject
case Result::ZeroBye:
return 0;
case Result::PairingBye:
return 10; // TODO
return 10; // TODO: by tournament
default:
return 0;
}
}

static int blackPointsForResult(Result result)
{
switch (result) {
case Result::WhiteWins:
return 0;
case Result::BlackWins:
return 10;
case Result::Draw:
return 5;
case Result::BothLost:
return 0;
case Result::WhiteWinsForfeit:
return 0;
case Result::BlackWinsForfeit:
return 10;
case Result::BothForfeit:
return 0;
case Result::WhiteDraws:
return 5;
case Result::BlackDraws:
return 5;
case Result::WhiteWinsUnrated:
return 0;
case Result::BlackWinsUnrated:
return 10;
case Result::DrawUnrated:
return 5;
case Result::HalfBye:
return 5;
case Result::FullBye:
return 10;
case Result::ZeroBye:
return 0;
case Result::PairingBye:
return 10; // TODO: by tournament
default:
return 0;
}
}

static bool isUnplayed(Result result)
{
switch (result) {
case Result::WhiteWinsForfeit:
case Result::BlackWinsForfeit:
case Result::BothForfeit:
case Result::HalfBye:
case Result::FullBye:
case Result::ZeroBye:
case Result::PairingBye:
return true;
default:
return false;
}
}

inline uint getPointsOfPlayer(Player *p)
{
if (p == m_whitePlayer) {
return Pairing::whitePointsForResult(m_result);
} else if (p == m_blackPlayer) {
return Pairing::blackPointsForResult(m_result);
}
Q_ASSERT(false); // unreachable
return -100000;
}

enum class PartialResult {
Unknown,
// Normal results
Expand Down Expand Up @@ -376,4 +447,4 @@ public Q_SLOTS:
Player *m_whitePlayer;
Player *m_blackPlayer;
Result m_result;
};
};
17 changes: 16 additions & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ Player::Player(int startingRank, const QString &name, int rating)
setRating(rating);
}

Player::Player(int startingRank, Title title, const QString &name, int rating, int nationalRating, const QString &playerId, const QString &birthDate, const QString &federation, const QString &origin, const QString &sex)
Player::Player(int startingRank,
Title title,
const QString &name,
int rating,
int nationalRating,
const QString &playerId,
const QString &birthDate,
const QString &federation,
const QString &origin,
const QString &sex)
: QObject()
{
setStartingRank(startingRank);
Expand Down Expand Up @@ -232,3 +241,9 @@ Player *Player::fromJson(const QJsonObject &json)

return player;
}

QDebug operator<<(QDebug dbg, const Player &player)
{
dbg.nospace() << "Player(" << player.name() << ")";
return dbg;
}
34 changes: 29 additions & 5 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,21 @@ class Player : public QObject
Q_PROPERTY(QString sex READ sex WRITE setSex NOTIFY sexChanged)

public:
enum class Title { None, GM, IM, FM, CM, WGM, WIM, WFM, WCM };
enum class Title {
None,
GM,
IM,
FM,
CM,
WGM,
WIM,
WFM,
WCM
};
Q_ENUM(Title)

static QString titleString(Title title) {
static QString titleString(Title title)
{
switch (title) {
case Title::GM:
return QStringLiteral("GM");
Expand All @@ -52,7 +63,8 @@ class Player : public QObject
}
};

static Title titleForString(const QString &title) {
static Title titleForString(const QString &title)
{
auto t = title.toLower();
if (t == QStringLiteral("gm")) {
return Title::GM;
Expand Down Expand Up @@ -83,7 +95,16 @@ class Player : public QObject

explicit Player();
explicit Player(int startingRank, const QString &name, int rating);
explicit Player(int startingRank, Title title, const QString &name, int rating, int nationalRating, const QString &playerId, const QString &birthDate, const QString &federation, const QString &origin, const QString &sex);
explicit Player(int startingRank,
Title title,
const QString &name,
int rating,
int nationalRating,
const QString &playerId,
const QString &birthDate,
const QString &federation,
const QString &origin,
const QString &sex);

int startingRank();
Title title() const;
Expand All @@ -96,13 +117,16 @@ class Player : public QObject
QString origin() const;
QString sex() const;

Q_INVOKABLE QString titleString() {
Q_INVOKABLE QString titleString()
{
return Player::titleString(m_title);
};

QJsonObject toJson() const;
static Player *fromJson(const QJsonObject &json);

friend QDebug operator<<(QDebug dbg, const Player &player);

public Q_SLOTS:
void setStartingRank(int startingRank);
void setTitle(Title title);
Expand Down
7 changes: 7 additions & 0 deletions src/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ StatefulApp.StatefulWindow {
viewName: "pairings"
iconName: "system-users-symbolic"
}
ListElement {
name: "Standings"
viewName: "standings"
iconName: "system-users-symbolic"
}
}

contentItem: ColumnLayout {
Expand Down Expand Up @@ -226,6 +231,8 @@ StatefulApp.StatefulWindow {
page = Qt.createComponent("dev.alcarazzam.chessament", "PlayersPage").createObject(root)
} else if (view == "pairings") {
page = Qt.createComponent("dev.alcarazzam.chessament", "PairingsPage").createObject(root)
} else if (view == "standings") {
page = Qt.createComponent("dev.alcarazzam.chessament", "StandingsPage").createObject(root)
}
pageCache[view] = page
return page
Expand Down
Loading

0 comments on commit a8bd3c9

Please sign in to comment.