Skip to content

Commit

Permalink
Merge branch 'develop' and move to version 2024 update 3
Browse files Browse the repository at this point in the history
  • Loading branch information
flinco committed Jul 6, 2024
2 parents abb3759 + 9c540ee commit 108b85e
Show file tree
Hide file tree
Showing 49 changed files with 1,628 additions and 714 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ project(LBChronoRace
DESCRIPTION "Timings and Rankings for Races"
HOMEPAGE_URL "http://github.com/flinco/LBChronoRace"
LANGUAGES CXX)
set(PROJECT_UPDATE 2)
set(PROJECT_UPDATE 3)
string(TIMESTAMP BUILD_DATE "%Y-%m-%d" UTC)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
Expand All @@ -53,6 +53,10 @@ set(PROJECT_SOURCES
categoriesmodel.hpp
category.cpp
category.hpp
catsexdelegate.cpp
catsexdelegate.hpp
cattypedelegate.cpp
cattypedelegate.hpp
chronorace.ui
chronoracedata.cpp
chronoracedata.hpp
Expand All @@ -67,6 +71,8 @@ set(PROJECT_SOURCES
chronoracetimings.ui
classentry.cpp
classentry.hpp
clubdelegate.cpp
clubdelegate.hpp
competitor.cpp
competitor.hpp
crloader.cpp
Expand All @@ -92,6 +98,8 @@ set(PROJECT_SOURCES
rankingswizardmode.hpp
rankingswizardselection.cpp
rankingswizardselection.hpp
sexdelegate.cpp
sexdelegate.hpp
startlistmodel.cpp
startlistmodel.hpp
teamclassentry.cpp
Expand Down
2 changes: 1 addition & 1 deletion categoriesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ QVariant CategoriesModel::data(QModelIndex const &index, int role) const
case static_cast<int>(Category::Field::CTF_TEAM):
return QVariant(tr("Individual (I) or Team (T)"));
case static_cast<int>(Category::Field::CTF_SEX):
return QVariant(tr("Male (M), Female (F), Misc (X) or Unspecified (U)"));
return QVariant(tr("Men (M), Women (F), Mixed (X) or All (U)"));
case static_cast<int>(Category::Field::CTF_TO_YEAR):
return QVariant(tr("The category will include competitors born up to and including this year (i.e. 2000); 0 to disable"));
case static_cast<int>(Category::Field::CTF_FROM_YEAR):
Expand Down
22 changes: 22 additions & 0 deletions category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ QDataStream &operator>>(QDataStream &in, Category &category)
return in;
}

Category::Type Category::toType(QString const &type)
{
if (type.compare("I", Qt::CaseInsensitive) == 0)
return Type::INDIVIDUAL;
else if (type.compare("T", Qt::CaseInsensitive) == 0)
return Type::CLUB;
else
throw(ChronoRaceException(tr("Illegal type '%1'").arg(type)));
}

QString Category::toTypeString(Type const type)
{
switch (type) {
case Type::INDIVIDUAL:
return "I";
case Type::CLUB:
return "T";
default:
throw(ChronoRaceException(tr("Unexpected Type enum value '%1'").arg(static_cast<int>(type))));
}
}

bool Category::isTeam() const
{
return team;
Expand Down
9 changes: 9 additions & 0 deletions category.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class Category {
Q_DECLARE_TR_FUNCTIONS(Category)

public:
enum class Type
{
INDIVIDUAL,
CLUB,
};

enum class Field
{
CTF_FIRST = 0,
Expand Down Expand Up @@ -59,6 +65,9 @@ class Category {
friend QDataStream &operator<<(QDataStream &out, Category const &category);
friend QDataStream &operator>>(QDataStream &in, Category &category);

static Type toType(QString const &type);
static QString toTypeString(Type const type);

bool isTeam() const;
void setTeam(bool newTeam);
uint getFromYear() const;
Expand Down
92 changes: 92 additions & 0 deletions catsexdelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*****************************************************************************
* 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 "catsexdelegate.hpp"
#include "lbcrexception.hpp"

CategorySexDelegate::CategorySexDelegate(QObject *parent) :
QStyledItemDelegate(parent)
{
auto *comboBox = box.data();
comboBox->setEditable(false);
comboBox->setInsertPolicy(QComboBox::NoInsert);
comboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
comboBox->setDuplicatesEnabled(false);
comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
comboBox->addItem(QIcon(":/material/icons/agender.svg"), toCatSexString(Competitor::Sex::UNDEFINED), Competitor::toSexString(Competitor::Sex::UNDEFINED));
comboBox->addItem(QIcon(":/material/icons/male.svg"), toCatSexString(Competitor::Sex::MALE), Competitor::toSexString(Competitor::Sex::MALE));
comboBox->addItem(QIcon(":/material/icons/female.svg"), toCatSexString(Competitor::Sex::FEMALE), Competitor::toSexString(Competitor::Sex::FEMALE));
comboBox->addItem(QIcon(":/material/icons/transgender.svg"), toCatSexString(Competitor::Sex::MISC), Competitor::toSexString(Competitor::Sex::MISC));
}

QWidget *CategorySexDelegate::createEditor(QWidget *parent, QStyleOptionViewItem const &option, QModelIndex const &index) const
{
Q_UNUSED(option)
Q_UNUSED(index)

auto *comboBox = box.data();
comboBox->setParent(parent);

return comboBox;
}

void CategorySexDelegate::destroyEditor(QWidget *editor, const QModelIndex &index) const
{
Q_UNUSED(editor)
Q_UNUSED(index)
}

void CategorySexDelegate::setEditorData(QWidget *editor, QModelIndex const &index) const
{
// Get the value via index of the Model and put it into the ComboBox
auto *comboBox = static_cast<QComboBox *>(editor);
comboBox->setCurrentText(toCatSexString(Competitor::toSex(index.model()->data(index, Qt::EditRole).toString())));
}

void CategorySexDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, QModelIndex const &index) const
{
auto const *comboBox = static_cast<QComboBox *>(editor);
model->setData(index, comboBox->currentData(Qt::UserRole), Qt::EditRole);
}

QSize CategorySexDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
return this->box.data()->sizeHint();
}

void CategorySexDelegate::updateEditorGeometry(QWidget *editor, QStyleOptionViewItem const &option, QModelIndex const &index) const
{
Q_UNUSED(index)

editor->setGeometry(option.rect);
}

QString CategorySexDelegate::toCatSexString(Competitor::Sex const sex)
{
switch (sex) {
case Competitor::Sex::MALE:
return tr("Men");
case Competitor::Sex::FEMALE:
return tr("Women");
case Competitor::Sex::MISC:
return tr("Mixed");
case Competitor::Sex::UNDEFINED:
return tr("All");
default:
throw(ChronoRaceException(tr("Unexpected Sex enum value '%1'").arg(static_cast<int>(sex))));
}
}
47 changes: 47 additions & 0 deletions catsexdelegate.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*****************************************************************************
* 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/>. *
*****************************************************************************/

#ifndef CATSEXDELEGATE_HPP
#define CATSEXDELEGATE_HPP

#include <QObject>
#include <QStyledItemDelegate>
#include <QScopedPointer>
#include <QComboBox>

#include "competitor.hpp"

class CategorySexDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit CategorySexDelegate(QObject *parent = Q_NULLPTR);

QWidget *createEditor(QWidget *parent, QStyleOptionViewItem const &option, QModelIndex const &index) const override;
void destroyEditor(QWidget *editor, const QModelIndex &index) const override;
void setEditorData(QWidget *editor, QModelIndex const &index) const override;
void setModelData(QWidget *editor, QAbstractItemModel *model, QModelIndex const &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void updateEditorGeometry(QWidget *editor, QStyleOptionViewItem const &option, QModelIndex const &index) const override;

private:
QScopedPointer<QComboBox> box { new QComboBox };

static QString toCatSexString(Competitor::Sex const sex);
};

#endif // CATSEXDELEGATE_HPP
85 changes: 85 additions & 0 deletions cattypedelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*****************************************************************************
* 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 "cattypedelegate.hpp"
#include "lbcrexception.hpp"

CategoryTypeDelegate::CategoryTypeDelegate(QObject *parent) :
QStyledItemDelegate(parent)
{
auto *comboBox = box.data();
comboBox->setEditable(false);
comboBox->setInsertPolicy(QComboBox::NoInsert);
comboBox->setDuplicatesEnabled(false);
comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
comboBox->addItem(QIcon(":/material/icons/person.svg"), toCatTypeString(Category::Type::INDIVIDUAL), QVariant(Category::toTypeString(Category::Type::INDIVIDUAL)));
comboBox->addItem(QIcon(":/material/icons/group.svg"), toCatTypeString(Category::Type::CLUB), QVariant(Category::toTypeString(Category::Type::CLUB)));
}

QWidget *CategoryTypeDelegate::createEditor(QWidget *parent, QStyleOptionViewItem const &option, QModelIndex const &index) const
{
Q_UNUSED(option)
Q_UNUSED(index)

auto *comboBox = box.data();
comboBox->setParent(parent);

return comboBox;
}

void CategoryTypeDelegate::destroyEditor(QWidget *editor, const QModelIndex &index) const
{
Q_UNUSED(editor)
Q_UNUSED(index)
}

void CategoryTypeDelegate::setEditorData(QWidget *editor, QModelIndex const &index) const
{
// Get the value via index of the Model and put it into the ComboBox
auto *comboBox = static_cast<QComboBox *>(editor);
comboBox->setCurrentText(toCatTypeString(Category::toType(index.model()->data(index, Qt::EditRole).toString())));
}

void CategoryTypeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, QModelIndex const &index) const
{
auto const *comboBox = static_cast<QComboBox *>(editor);
model->setData(index, comboBox->currentData(Qt::UserRole), Qt::EditRole);
}

QSize CategoryTypeDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
return this->box.data()->sizeHint();
}

void CategoryTypeDelegate::updateEditorGeometry(QWidget *editor, QStyleOptionViewItem const &option, QModelIndex const &index) const
{
Q_UNUSED(index)

editor->setGeometry(option.rect);
}

QString CategoryTypeDelegate::toCatTypeString(Category::Type type)
{
switch (type) {
case Category::Type::INDIVIDUAL:
return tr("Individual");
case Category::Type::CLUB:
return tr("Club");
default:
throw(ChronoRaceException(tr("Unexpected Type enum value '%1'").arg(static_cast<int>(type))));
}
}
47 changes: 47 additions & 0 deletions cattypedelegate.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*****************************************************************************
* 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/>. *
*****************************************************************************/

#ifndef CATTYPEDELEGATE_HPP
#define CATTYPEDELEGATE_HPP

#include <QObject>
#include <QStyledItemDelegate>
#include <QScopedPointer>
#include <QComboBox>

#include "category.hpp"

class CategoryTypeDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit CategoryTypeDelegate(QObject *parent = Q_NULLPTR);

QWidget *createEditor(QWidget *parent, QStyleOptionViewItem const &option, QModelIndex const &index) const override;
void destroyEditor(QWidget *editor, const QModelIndex &index) const override;
void setEditorData(QWidget *editor, QModelIndex const &index) const override;
void setModelData(QWidget *editor, QAbstractItemModel *model, QModelIndex const &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void updateEditorGeometry(QWidget *editor, QStyleOptionViewItem const &option, QModelIndex const &index) const override;

private:
QScopedPointer<QComboBox> box { new QComboBox };

static QString toCatTypeString(Category::Type type);
};

#endif // CATTYPEDELEGATE_HPP
Loading

0 comments on commit 108b85e

Please sign in to comment.