2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2023-11-13 17:13:17 +00:00
|
|
|
#include <QCoreApplication> // Q_DECLARE_TR_FUNCTIONS
|
|
|
|
#include <QString>
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2023-11-13 17:13:17 +00:00
|
|
|
#include "libtransmission/values.h"
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2023-11-13 17:13:17 +00:00
|
|
|
class Speed : public libtransmission::Values::Speed
|
|
|
|
{
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(Speed)
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2023-11-13 17:13:17 +00:00
|
|
|
public:
|
|
|
|
Speed() = default;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2023-11-13 17:13:17 +00:00
|
|
|
template<typename Number, typename std::enable_if_t<std::is_integral_v<Number>>* = nullptr>
|
|
|
|
constexpr Speed(Number value, Units multiple)
|
|
|
|
: libtransmission::Values::Speed{ value, multiple }
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-11-13 17:13:17 +00:00
|
|
|
template<typename Number, typename std::enable_if_t<std::is_floating_point_v<Number>>* = nullptr>
|
|
|
|
Speed(Number value, Units multiple)
|
|
|
|
: libtransmission::Values::Speed{ value, multiple }
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-11-13 17:13:17 +00:00
|
|
|
[[nodiscard]] auto to_qstring() const noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2023-11-13 17:13:17 +00:00
|
|
|
return QString::fromStdString(to_string());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2023-11-13 17:13:17 +00:00
|
|
|
[[nodiscard]] auto to_upload_qstring() const
|
2020-05-19 23:42:17 +00:00
|
|
|
{
|
2023-11-13 17:13:17 +00:00
|
|
|
static auto constexpr UploadSymbol = QChar{ 0x25B4 };
|
|
|
|
return tr("%1 %2").arg(to_qstring()).arg(UploadSymbol);
|
2020-05-19 23:42:17 +00:00
|
|
|
}
|
|
|
|
|
2023-11-13 17:13:17 +00:00
|
|
|
[[nodiscard]] auto to_download_qstring() const
|
2020-05-19 23:42:17 +00:00
|
|
|
{
|
2023-11-13 17:13:17 +00:00
|
|
|
static auto constexpr DownloadSymbol = QChar{ 0x25BE };
|
|
|
|
return tr("%1 %2").arg(to_qstring()).arg(DownloadSymbol);
|
2020-05-19 23:42:17 +00:00
|
|
|
}
|
|
|
|
|
2023-11-13 17:13:17 +00:00
|
|
|
[[nodiscard]] constexpr auto operator+(Speed const& other) const noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2023-11-13 17:13:17 +00:00
|
|
|
return Speed{ base_quantity() + other.base_quantity(), Speed::Units::Byps };
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2023-11-16 04:15:40 +00:00
|
|
|
|
|
|
|
[[nodiscard]] static auto display_name(Speed::Units const units)
|
|
|
|
{
|
|
|
|
auto const speed_unit_sv = Speed::units().display_name(units);
|
|
|
|
return QString::fromUtf8(std::data(speed_unit_sv), std::size(speed_unit_sv));
|
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|