-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' and move to version 2024 update 3
- Loading branch information
Showing
49 changed files
with
1,628 additions
and
714 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.